AlbumShaper 1.0a3
RecentAlbumMenuItem Class Reference

A custom menu entry, displays album image, name, and number of photos. More...

#include <recentAlbumMenuItem.h>

Inheritance diagram for RecentAlbumMenuItem:
Collaboration diagram for RecentAlbumMenuItem:

Public Member Functions

 RecentAlbumMenuItem (Qt::Key acceleratorKey)
 
void changeItem (QString albumName, QString albumLocation, QString numPhotos)
 updates entry as per arguments passed (used by constructor during intiailization as well)
 
void paint (QPainter *p, const QColorGroup &cg, bool act, bool enabled, int x, int y, int w, int h)
 paints entry
 
QSize sizeHint ()
 returns menu entry size
 
void setMaxWidth (int val)
 after all menu items have been refreshed hint at maximum width so we can adequately position the accelerator text

 
bool fullSpan () const
 no icon necessary since album image painted here
 

Private Attributes

Qt::Key acceleratorKey
 
QImage albumImage
 album image
 
QString albumName
 album name
 
QString numPhotos
 number of photos
 
QSize size
 computed size
 
int maxWidth
 max element width
 
int idealImageWidth
 used for painting purposes
 

Detailed Description

A custom menu entry, displays album image, name, and number of photos.

Definition at line 23 of file recentAlbumMenuItem.h.

Constructor & Destructor Documentation

◆ RecentAlbumMenuItem()

RecentAlbumMenuItem::RecentAlbumMenuItem ( Qt::Key acceleratorKey)

Definition at line 22 of file recentAlbumMenuItem.cpp.

22 : QMenuItem()
23{
25 changeItem( "unitialized", "unitialized", "unitialized" );
26}
void changeItem(QString albumName, QString albumLocation, QString numPhotos)
updates entry as per arguments passed (used by constructor during intiailization as well)

References acceleratorKey, and changeItem().

Member Function Documentation

◆ changeItem()

void RecentAlbumMenuItem::changeItem ( QString albumName,
QString albumLocation,
QString numPhotos )

updates entry as per arguments passed (used by constructor during intiailization as well)

Definition at line 28 of file recentAlbumMenuItem.cpp.

31{
32 //set name, and number of photos
33 this->albumName = albumName;
34 this->numPhotos = numPhotos;
35
36 //compute height
37 QFontMetrics fm( qApp->font() );
38 size.setHeight( 2 + fm.leading() + 2*fm.height() + 2);
39
40 //attempt to set album image
41 QString albumImageLocation = QDir::convertSeparators( albumLocation + "/img/album.jpg" );
42 QDir tempDir;
43 if( tempDir.exists( albumImageLocation ) )
44 {
45 //ideal image width assuming 4:3 aspect ratio
46 idealImageWidth = (4 * (size.height()-4) ) / 3;
47
48 //scale image
49 scaleImage( albumImageLocation, albumImage, idealImageWidth, size.height() );
50 }
51 else
52 {
54 }
55
56 //compute menu entry width
57 size.setWidth( idealImageWidth + 2 + fm.width(albumName) );
58}
int idealImageWidth
used for painting purposes
QString numPhotos
number of photos
QImage albumImage
album image
QString albumName
album name
QSize size
computed size
bool scaleImage(QString fileIn, QString fileOut, int newWidth, int newHeight)
Scale image and save copy to disk.

References albumImage, albumName, idealImageWidth, numPhotos, scaleImage(), and size.

Referenced by RecentAlbumMenuItem(), and TitleWidget::refreshOpenRecentMenu().

◆ fullSpan()

bool RecentAlbumMenuItem::fullSpan ( ) const

no icon necessary since album image painted here

Definition at line 108 of file recentAlbumMenuItem.cpp.

109{ return true; }

◆ paint()

void RecentAlbumMenuItem::paint ( QPainter * p,
const QColorGroup & cg,
bool act,
bool enabled,
int x,
int y,
int w,
int h )

paints entry

Definition at line 60 of file recentAlbumMenuItem.cpp.

64{
65 //move down and right by two for spacing purposes
66 y+=2;
67 x+=2;
68 int xOffset = 0;
69 int yOffset = 0;
70
71 //paint album image first if not null
72 if(!albumImage.isNull())
73 {
74 p->drawImage( x + (idealImageWidth - albumImage.width()) / 2,
75 y + (size.height() - albumImage.height() - 4)/2,
76 albumImage );
77 xOffset+=(idealImageWidth + 2);
78 }
79
80 //paint album name + photo count
81 QFontMetrics fm( qApp->font() );
82 yOffset+=fm.ascent();
83 p->drawText( x+xOffset, y+yOffset, albumName );
84
85 //if photo count available print it as well
86 if(numPhotos.compare("-1") != 0)
87 {
88 yOffset+=fm.descent() + 1 + fm.leading() + fm.ascent();
89 p->drawText( x+xOffset, y+yOffset,
90 qApp->translate("RecentAlbumMenuItem", "%1 Photos").arg(numPhotos) );
91 }
92
93 //paint accelerator key
94 if( acceleratorKey != Qt::Key_unknown )
95 {
96 xOffset = maxWidth + 24;
97 yOffset = fm.ascent() + fm.height()/2;
98 QKeySequence seq( Qt::CTRL+acceleratorKey );
99 QString str = (QString)seq;
100 p->drawText( x+xOffset, y+yOffset,
101 str);
102 }
103}
int maxWidth
max element width

References acceleratorKey, albumImage, albumName, idealImageWidth, maxWidth, numPhotos, and size.

◆ setMaxWidth()

void RecentAlbumMenuItem::setMaxWidth ( int val)

after all menu items have been refreshed hint at maximum width so we can adequately position the accelerator text

Definition at line 111 of file recentAlbumMenuItem.cpp.

112{ maxWidth = val; }

References maxWidth.

Referenced by TitleWidget::refreshOpenRecentMenu().

◆ sizeHint()

QSize RecentAlbumMenuItem::sizeHint ( )

returns menu entry size

Definition at line 105 of file recentAlbumMenuItem.cpp.

106{ return size; }

References size.

Member Data Documentation

◆ acceleratorKey

Qt::Key RecentAlbumMenuItem::acceleratorKey
private

Definition at line 48 of file recentAlbumMenuItem.h.

Referenced by paint(), and RecentAlbumMenuItem().

◆ albumImage

QImage RecentAlbumMenuItem::albumImage
private

album image

Definition at line 51 of file recentAlbumMenuItem.h.

Referenced by changeItem(), and paint().

◆ albumName

QString RecentAlbumMenuItem::albumName
private

album name

Definition at line 54 of file recentAlbumMenuItem.h.

Referenced by changeItem(), and paint().

◆ idealImageWidth

int RecentAlbumMenuItem::idealImageWidth
private

used for painting purposes

Definition at line 66 of file recentAlbumMenuItem.h.

Referenced by changeItem(), and paint().

◆ maxWidth

int RecentAlbumMenuItem::maxWidth
private

max element width

Definition at line 63 of file recentAlbumMenuItem.h.

Referenced by paint(), and setMaxWidth().

◆ numPhotos

QString RecentAlbumMenuItem::numPhotos
private

number of photos

Definition at line 57 of file recentAlbumMenuItem.h.

Referenced by changeItem(), and paint().

◆ size

QSize RecentAlbumMenuItem::size
private

computed size

Definition at line 60 of file recentAlbumMenuItem.h.

Referenced by changeItem(), paint(), and sizeHint().


The documentation for this class was generated from the following files: