00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <qdir.h>
00013 #include <qpainter.h>
00014 #include <qapplication.h>
00015 #include <qkeysequence.h>
00016
00017
00018 #include "recentAlbumMenuItem.h"
00019 #include "../backend/tools/imageTools.h"
00020
00021
00022 RecentAlbumMenuItem::RecentAlbumMenuItem( Key acceleratorKey ) : QCustomMenuItem()
00023 {
00024 this->acceleratorKey = acceleratorKey;
00025 changeItem( "unitialized", "unitialized", "unitialized" );
00026 }
00027
00028 void RecentAlbumMenuItem::changeItem( QString albumName,
00029 QString albumLocation,
00030 QString numPhotos )
00031 {
00032
00033 this->albumName = albumName;
00034 this->numPhotos = numPhotos;
00035
00036
00037 QFontMetrics fm( qApp->font() );
00038 size.setHeight( 2 + fm.leading() + 2*fm.height() + 2);
00039
00040
00041 QString albumImageLocation = QDir::convertSeparators( albumLocation + "/img/album.jpg" );
00042 QDir tempDir;
00043 if( tempDir.exists( albumImageLocation ) )
00044 {
00045
00046 idealImageWidth = (4 * (size.height()-4) ) / 3;
00047
00048
00049 scaleImage( albumImageLocation, albumImage, idealImageWidth, size.height() );
00050 }
00051 else
00052 {
00053 idealImageWidth = 0;
00054 }
00055
00056
00057 size.setWidth( idealImageWidth + 2 + fm.width(albumName) );
00058 }
00059
00060 void RecentAlbumMenuItem::paint( QPainter* p,
00061 const QColorGroup&,
00062 bool, bool,
00063 int x, int y, int, int )
00064 {
00065
00066 y+=2;
00067 x+=2;
00068 int xOffset = 0;
00069 int yOffset = 0;
00070
00071
00072 if(!albumImage.isNull())
00073 {
00074 p->drawImage( x + (idealImageWidth - albumImage.width()) / 2,
00075 y + (size.height() - albumImage.height() - 4)/2,
00076 albumImage );
00077 xOffset+=(idealImageWidth + 2);
00078 }
00079
00080
00081 QFontMetrics fm( qApp->font() );
00082 yOffset+=fm.ascent();
00083 p->drawText( x+xOffset, y+yOffset, albumName );
00084
00085
00086 if(numPhotos.compare("-1") != 0)
00087 {
00088 yOffset+=fm.descent() + 1 + fm.leading() + fm.ascent();
00089 p->drawText( x+xOffset, y+yOffset,
00090 qApp->translate("RecentAlbumMenuItem", "%1 Photos").arg(numPhotos) );
00091 }
00092
00093
00094 if( acceleratorKey != Key_unknown )
00095 {
00096 xOffset = maxWidth + 24;
00097 yOffset = fm.ascent() + fm.height()/2;
00098 QKeySequence seq( CTRL+acceleratorKey );
00099 QString str = (QString)seq;
00100 p->drawText( x+xOffset, y+yOffset,
00101 str);
00102 }
00103 }
00104
00105 QSize RecentAlbumMenuItem::sizeHint ()
00106 { return size; }
00107
00108 bool RecentAlbumMenuItem::fullSpan() const
00109 { return true; }
00110
00111 void RecentAlbumMenuItem::setMaxWidth( int val )
00112 { maxWidth = val; }
00113