AlbumShaper  1.0a3
Public Member Functions | Private Attributes | List of all members
RecentAlbumMenuItem Class Reference

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

#include <recentAlbumMenuItem.h>

Inheritance diagram for RecentAlbumMenuItem:
Inheritance graph
[legend]
Collaboration diagram for RecentAlbumMenuItem:
Collaboration graph
[legend]

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) More...
 
void paint (QPainter *p, const QColorGroup &cg, bool act, bool enabled, int x, int y, int w, int h)
 paints entry More...
 
QSize sizeHint ()
 returns menu entry size More...
 
void setMaxWidth (int val)
 after all menu items have been refreshed hint at maximum width so we can adequately position the accelerator text More...
 
bool fullSpan () const
 no icon necessary since album image painted here More...
 

Private Attributes

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

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.

References acceleratorKey, and changeItem().

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) ...

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.

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

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

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  {
53  idealImageWidth = 0;
54  }
55 
56  //compute menu entry width
57  size.setWidth( idealImageWidth + 2 + fm.width(albumName) );
58 }
int idealImageWidth
used for painting purposes
bool scaleImage(QString fileIn, QString fileOut, int newWidth, int newHeight)
Scale image and save copy to disk.
Definition: imageTools.cpp:157
QString numPhotos
number of photos
QString albumName
album name
QSize size
computed size
QImage albumImage
album image

§ 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.

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

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
int idealImageWidth
used for painting purposes
QString numPhotos
number of photos
QString albumName
album name
QSize size
computed size
QImage albumImage
album image

§ 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.

References maxWidth.

Referenced by TitleWidget::refreshOpenRecentMenu().

112 { maxWidth = val; }
int maxWidth
max element width

§ sizeHint()

QSize RecentAlbumMenuItem::sizeHint ( )

returns menu entry size

Definition at line 105 of file recentAlbumMenuItem.cpp.

References size.

106 { return size; }
QSize size
computed 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: