Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

recentAlbumMenuItem.cpp

Go to the documentation of this file.
00001 //==============================================
00002 //  copyright            : (C) 2003-2005 by Will Stokes
00003 //==============================================
00004 //  This program is free software; you can redistribute it
00005 //  and/or modify it under the terms of the GNU General
00006 //  Public License as published by the Free Software
00007 //  Foundation; either version 2 of the License, or
00008 //  (at your option) any later version.
00009 //==============================================
00010 
00011 //Systemwide includes
00012 #include <qdir.h>
00013 #include <qpainter.h>
00014 #include <qapplication.h>
00015 
00016 //Projectwide includes
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   //set name, and number of photos
00026   this->albumName = albumName;
00027   this->numPhotos = numPhotos;
00028   
00029   //compute height
00030   QFontMetrics fm( qApp->font() );
00031   size.setHeight( 2 + fm.leading() + 2*fm.height() + 2);
00032   
00033   //attempt to set album image   
00034   QString albumImageLocation = QDir::convertSeparators( albumLocation + "/img/album.jpg" );
00035   QDir tempDir;
00036   if( tempDir.exists( albumImageLocation ) )
00037   {       
00038     //ideal image width assuming 4:3 aspect ratio
00039     idealImageWidth = (4 * (size.height()-4) ) / 3;
00040     
00041     //scale image
00042     scaleImage( albumImageLocation, albumImage, idealImageWidth, size.height() );
00043   }
00044   else
00045   {
00046     idealImageWidth = 0;
00047   }
00048   
00049   //compute menu entry width
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   //move down and right by two for spacing purposes
00059   y+=2;
00060   x+=2;
00061 
00062   //paint album image first if not null
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   //paint album name + photo count
00072   QFontMetrics fm( qApp->font() );
00073   y+=fm.ascent();
00074   p->drawText( x, y, albumName ); 
00075 
00076   //if photo count available print it as well
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 //==============================================

Generated on Sat Apr 2 05:44:04 2005 for AlbumShaper by  doxygen 1.3.9.1