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