AlbumShaper  1.0a3
Public Member Functions | Private Attributes
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]

List of all members.

Public Member Functions

 RecentAlbumMenuItem (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

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 ( Key  acceleratorKey)

Definition at line 22 of file recentAlbumMenuItem.cpp.

References acceleratorKey, and changeItem().

                                                             : QCustomMenuItem()
{
  this->acceleratorKey = acceleratorKey;
  changeItem( "unitialized", "unitialized", "unitialized" );
}

Member Function Documentation

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

{
  //set name, and number of photos
  this->albumName = albumName;
  this->numPhotos = numPhotos;
  
  //compute height
  QFontMetrics fm( qApp->font() );
  size.setHeight( 2 + fm.leading() + 2*fm.height() + 2);
  
  //attempt to set album image   
  QString albumImageLocation = QDir::convertSeparators( albumLocation + "/img/album.jpg" );
  QDir tempDir;
  if( tempDir.exists( albumImageLocation ) )
  {       
    //ideal image width assuming 4:3 aspect ratio
    idealImageWidth = (4 * (size.height()-4) ) / 3;
    
    //scale image
    scaleImage( albumImageLocation, albumImage, idealImageWidth, size.height() );
  }
  else
  {
    idealImageWidth = 0;
  }
  
  //compute menu entry width
  size.setWidth( idealImageWidth + 2 + fm.width(albumName) );
}
bool RecentAlbumMenuItem::fullSpan ( ) const

no icon necessary since album image painted here

Definition at line 108 of file recentAlbumMenuItem.cpp.

{ return true; }
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.

{
  //move down and right by two for spacing purposes
  y+=2;
  x+=2;
  int xOffset = 0;
  int yOffset = 0;

  //paint album image first if not null
  if(!albumImage.isNull())
  {
    p->drawImage( x + (idealImageWidth - albumImage.width()) / 2, 
                  y + (size.height() - albumImage.height() - 4)/2, 
                  albumImage );
    xOffset+=(idealImageWidth + 2);
  }
  
  //paint album name + photo count
  QFontMetrics fm( qApp->font() );
  yOffset+=fm.ascent();
  p->drawText( x+xOffset, y+yOffset, albumName ); 

  //if photo count available print it as well
  if(numPhotos.compare("-1") != 0)
  {
    yOffset+=fm.descent() + 1 + fm.leading() + fm.ascent();
    p->drawText( x+xOffset, y+yOffset, 
               qApp->translate("RecentAlbumMenuItem", "%1 Photos").arg(numPhotos) );
  }

  //paint accelerator key
  if( acceleratorKey != Key_unknown )
  {
    xOffset = maxWidth + 24;
    yOffset = fm.ascent() + fm.height()/2;
    QKeySequence seq( CTRL+acceleratorKey );
    QString str = (QString)seq;
    p->drawText( x+xOffset, y+yOffset,
                 str);
  }
}
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().

{ maxWidth = val; }
QSize RecentAlbumMenuItem::sizeHint ( )

returns menu entry size

Definition at line 105 of file recentAlbumMenuItem.cpp.

References size.

{ return size; }

Member Data Documentation

Definition at line 48 of file recentAlbumMenuItem.h.

Referenced by paint(), and RecentAlbumMenuItem().

album image

Definition at line 51 of file recentAlbumMenuItem.h.

Referenced by changeItem(), and paint().

QString RecentAlbumMenuItem::albumName [private]

album name

Definition at line 54 of file recentAlbumMenuItem.h.

Referenced by changeItem(), and paint().

used for painting purposes

Definition at line 66 of file recentAlbumMenuItem.h.

Referenced by changeItem(), and paint().

max element width

Definition at line 63 of file recentAlbumMenuItem.h.

Referenced by paint(), and setMaxWidth().

QString RecentAlbumMenuItem::numPhotos [private]

number of photos

Definition at line 57 of file recentAlbumMenuItem.h.

Referenced by changeItem(), and paint().

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: