PhotoPreviewWidget Class Reference

#include <photoPreviewWidget.h>

Inheritance diagram for PhotoPreviewWidget:

[legend]
Collaboration diagram for PhotoPreviewWidget:
[legend]
List of all members.

Detailed Description

Displays photo thumbnail and description.

Definition at line 32 of file photoPreviewWidget.h.

Public Member Functions

 PhotoPreviewWidget (QIconView *parent, Photo *phto)
 Sets subalbum pointer.
Photo * getPhoto ()
 Returns photo pointer.
void updateImage ()
 Update photo thumbnail from background object.
void updateDescription ()
 Update photo description.
void paint (QPainter *p)
void paintItem (QPainter *p, const QColorGroup &cg)
 Repain iconview item.
void paintFocus (QPainter *p, const QColorGroup &cg)
void setText (const QString &text)
void setPixmap (const QPixmap &p, bool redraw)
bool acceptDrop (const QMimeSource *e) const
int compare (QIconViewItem *i) const
void setMousedOver (bool val)
QRect getPhotoInfoRect ()
QPoint getPhotoPos ()

Private Member Functions

void initializeItemRect ()

Private Attributes

Photo * phto
 Pointer to photo backend object.
int calibratedWidth
bool mousedOver
QRect photoInfoRect
int pixmapXOffset
 offsets used to center pixmap
int pixmapYOffset


Constructor & Destructor Documentation

PhotoPreviewWidget::PhotoPreviewWidget ( QIconView *  parent,
Photo *  phto 
)

Sets subalbum pointer.

Definition at line 29 of file photoPreviewWidget.cpp.

References calibratedWidth, Photo::getDescription(), initializeItemRect(), mousedOver, PHOTO_TEXT_MARGIN, phto, setText(), and THUMBNAIL_WIDTH.

00029                                                                        :
00030                                    QIconViewItem( parent, QString(""), QPixmap(phto->getThumbnailFilename()) )
00031 {
00032   //initially item not moused over, set photo pointer
00033   mousedOver = false;
00034   this->phto = phto;
00035 
00036   //calibrated text width is icon width minus margin + info button size (info button is sized to be a square of height
00037   //equal to text height, aka fm.height)
00038   QFontMetrics fm( qApp->font() );
00039   calibratedWidth = THUMBNAIL_WIDTH - PHOTO_TEXT_MARGIN - fm.height();
00040   
00041   //actually set the items text by clipping it using the calibration width we just computed
00042   setText( phto->getDescription() );
00043 
00044   //update the items rectange which is a function of the text width, icon rect,
00045   //and margins for displaying selection and mouse over ovals
00046   initializeItemRect();
00047 }
//==============================================


Member Function Documentation

Photo * PhotoPreviewWidget::getPhoto (  ) 

Returns photo pointer.

Definition at line 49 of file photoPreviewWidget.cpp.

References phto.

Referenced by PhotoDescEdit::disappear(), PhotoDescEdit::PhotoDescEdit(), PhotosIconView::setAlbumImage(), PhotosIconView::setSubalbumImage(), and Subalbum::syncPhotoList().

00050 {
00051   return phto;
00052 }

void PhotoPreviewWidget::updateImage (  ) 

Update photo thumbnail from background object.

Definition at line 54 of file photoPreviewWidget.cpp.

References Photo::getThumbnailFilename(), phto, and setPixmap().

00055 {
00056   setPixmap( QPixmap(phto->getThumbnailFilename()), false);
00057 }

void PhotoPreviewWidget::updateDescription (  ) 

Update photo description.

Definition at line 66 of file photoPreviewWidget.cpp.

References Photo::getDescription(), phto, and setText().

00067 {
00068   setText( phto->getDescription() );
00069 }

void PhotoPreviewWidget::paint ( QPainter *  p  ) 

Definition at line 76 of file photoPreviewWidget.cpp.

References height, PHOTO_MARGIN, PHOTO_TEXT_MARGIN, pixmapXOffset, pixmapYOffset, and width.

Referenced by paintItem().

00077 {
00078   //create colors
00079   QColor offWhite( 255, 255, 255 );
00080   QColor darkBlue(35, 75, 139);
00081   QColor paperColor;
00082 
00083   //draw offwhite or selected color depending on if photo is selected
00084   QRect paperRect( x(), y(),
00085                               2*PHOTO_MARGIN + pixmapRect().width(),
00086                               2*PHOTO_MARGIN + pixmapRect().height() + PHOTO_TEXT_MARGIN + textRect().height() );
00087   if(isSelected())
00088     paperColor = darkBlue;
00089   else
00090     paperColor = offWhite;
00091   p->fillRect(  paperRect, QBrush( paperColor ) );
00092 
00093   //paint pixmap
00094   p->drawPixmap( x() + pixmapRect().x() + pixmapXOffset + 1,
00095                                  y() + pixmapRect().y() + pixmapYOffset + 1, 
00096                                  *pixmap());
00097   
00098   //paint text
00099   int align = AlignLeft | AlignTop | BreakAnywhere;
00100   if(isSelected())
00101     p->setPen( white );
00102   else
00103     p->setPen( black );
00104   p->drawText( x() + textRect().x() + 1, y() + textRect().y() + 1, 
00105                            textRect().width(), textRect().height(),
00106                            align, text() );
00107 }

void PhotoPreviewWidget::paintItem ( QPainter *  p,
const QColorGroup &  cg 
)

Repain iconview item.

Definition at line 109 of file photoPreviewWidget.cpp.

References buffer, getPhotoInfoRect(), height, mousedOver, paint(), PHOTO_SHADOW, PHOTO_SHADOW_END_OFFSET, photoInfoRect, Window::shadowB, Window::shadowBL, Window::shadowBR, Window::shadowR, Window::shadowTR, and width.

00110 {
00111   //resize old static buffer to new needed size, fill with widget background color
00112   static QPixmap buffer;
00113   QRect r = rect();
00114   QSize newSize = r.size().expandedTo(buffer.size() );
00115   buffer.resize(newSize);
00116   buffer.fill( white );
00117 
00118   //construct painter for buffer
00119   QPainter bufferPainter(&buffer, this);
00120   bufferPainter.translate( -r.x(), -r.y() );
00121  
00122    //paint item
00123   paint(&bufferPainter);
00124 
00125   //paint edit button
00126   if(mousedOver)
00127   {
00128     QRect photoInfoRect = getPhotoInfoRect();
00129     bufferPainter.drawPixmap( photoInfoRect, * (((Window*) qApp->mainWidget())->photoInfo) );
00130   }
00131 
00132   //paint shadows
00133   QPixmap* shadowBL, *shadowB, *shadowBR, *shadowR, *shadowTR;
00134   Window* window = (Window*) qApp->mainWidget();
00135   shadowBL = window->shadowBL;
00136   shadowB = window->shadowB;
00137   shadowBR = window->shadowBR;
00138   shadowR = window->shadowR;
00139   shadowTR = window->shadowTR;
00140 
00141   QRect shadowRect;
00142   shadowRect.setLeft( x() + PHOTO_SHADOW_END_OFFSET );
00143   shadowRect.setRight( shadowRect.left() + PHOTO_SHADOW );
00144   shadowRect.setTop( y() + rect().height() - PHOTO_SHADOW );
00145   shadowRect.setBottom( shadowRect.top() + PHOTO_SHADOW );
00146   bufferPainter.drawPixmap( shadowRect, *shadowBL );
00147 
00148   shadowRect.setLeft( shadowRect.right() + 1 );
00149   shadowRect.setRight( x() +  rect().width() - PHOTO_SHADOW - 1 );
00150   bufferPainter.drawPixmap( shadowRect, *shadowB );
00151 
00152   shadowRect.setLeft( shadowRect.right() + 1 );
00153   shadowRect.setRight( shadowRect.left() + PHOTO_SHADOW );
00154   bufferPainter.drawPixmap( shadowRect, *shadowBR );
00155 
00156   shadowRect.setBottom( shadowRect.top() - 1 );
00157   shadowRect.setTop( y() +PHOTO_SHADOW_END_OFFSET + PHOTO_SHADOW );
00158   bufferPainter.drawPixmap( shadowRect, *shadowR );
00159 
00160   shadowRect.setBottom( shadowRect.top() - 1 );
00161   shadowRect.setTop( y() +PHOTO_SHADOW_END_OFFSET );
00162   bufferPainter.drawPixmap( shadowRect, *shadowTR );
00163   
00164   //draw buffer to screen
00165   p->drawPixmap( x(), y(), buffer );
00166 }

void PhotoPreviewWidget::paintFocus ( QPainter *  p,
const QColorGroup &  cg 
)

Definition at line 168 of file photoPreviewWidget.cpp.

00168 { }

void PhotoPreviewWidget::setText ( const QString &  text  ) 

Definition at line 71 of file photoPreviewWidget.cpp.

References calibratedWidth, and clipText().

Referenced by PhotoDescEdit::disappear(), PhotoPreviewWidget(), and updateDescription().

00072 {
00073   QIconViewItem::setText( clipText(text, 1, calibratedWidth), false );
00074 }

void PhotoPreviewWidget::setPixmap ( const QPixmap &  p,
bool  redraw 
)

Definition at line 59 of file photoPreviewWidget.cpp.

References pixmapXOffset, pixmapYOffset, THUMBNAIL_HEIGHT, and THUMBNAIL_WIDTH.

Referenced by updateImage().

00060 {
00061   pixmapXOffset = (THUMBNAIL_WIDTH - p.width() ) / 2;  
00062   pixmapYOffset = (THUMBNAIL_HEIGHT - p.height() ) / 2;  
00063   QIconViewItem::setPixmap( p, redraw );
00064 }

bool PhotoPreviewWidget::acceptDrop ( const QMimeSource *  e  )  const

Definition at line 170 of file photoPreviewWidget.cpp.

00171 {
00172   return true;
00173 }

int PhotoPreviewWidget::compare ( QIconViewItem *  i  )  const

Definition at line 175 of file photoPreviewWidget.cpp.

References height.

00176 {
00177   if( pos().y() > (i->pos().y() + height()) ||
00178       (
00179         pos().y() >= i->pos().y() &&
00180         pos().x() >= i->pos().x()
00181       ))
00182   { return 1; }
00183   else
00184   { return -1; }
00185 }

void PhotoPreviewWidget::setMousedOver ( bool  val  ) 

Definition at line 219 of file photoPreviewWidget.cpp.

References mousedOver.

Referenced by PhotosIconView::clearPseudoSelection(), and PhotosIconView::repaintGroup().

00220 { 
00221   mousedOver = val;   
00222 }

QRect PhotoPreviewWidget::getPhotoInfoRect (  ) 

Definition at line 224 of file photoPreviewWidget.cpp.

References height, PHOTO_MARGIN, PHOTO_SHADOW, photoInfoRect, and width.

Referenced by PhotosIconView::contentsMouseMoveEvent(), and paintItem().

00225 {
00226   QRect photoInfoRect;
00227   QFontMetrics fm( qApp->font() );
00228   photoInfoRect.setLeft( x() + rect().width() - fm.height() - PHOTO_MARGIN - PHOTO_SHADOW - 1 );
00229   photoInfoRect.setRight( photoInfoRect.left() + fm.height() );
00230   photoInfoRect.setTop( y() + rect().height() - fm.height() - PHOTO_MARGIN - PHOTO_SHADOW - 1 );
00231   photoInfoRect.setBottom( photoInfoRect.top() + fm.height() );
00232   return photoInfoRect;
00233 }

QPoint PhotoPreviewWidget::getPhotoPos (  ) 

Definition at line 235 of file photoPreviewWidget.cpp.

References pixmapXOffset, and pixmapYOffset.

Referenced by PhotoDescEdit::PhotoDescEdit().

00236 {
00237   //get widget coordiantes of item
00238   int xpos,ypos;
00239   xpos = x() + pixmapRect().x() + pixmapXOffset + 1;
00240   ypos = y() + pixmapRect().y() + pixmapYOffset + 1;
00241   
00242   //shift by scrolled amount
00243   xpos-= iconView()->contentsX();
00244   ypos-= iconView()->contentsY();
00245 
00246   //offset by viewport top left
00247   //(why not iconview topleft? item actually placed in viewport which is placed in iconview. this
00248   //viewport can be offset (and when I wrote this code it was) from the iconview depending on Trolltech's
00249   //scrollview code which can using spacing between the viewport and scrolls widgets. since the viewport
00250   //is a full blown widget, we can figure out it's reall screen coordinates and need not consult the iconview object at all.
00251   QPoint viewportTL = iconView()->viewport()->mapToGlobal( QPoint(0,0) );
00252   xpos+= viewportTL.x();
00253   ypos+= viewportTL.y();
00254 
00255   return QPoint(xpos,ypos);
00256 }

void PhotoPreviewWidget::initializeItemRect (  )  [private]

Definition at line 187 of file photoPreviewWidget.cpp.

References PHOTO_MARGIN, PHOTO_SHADOW, PHOTO_TEXT_MARGIN, pixmapXOffset, pixmapYOffset, THUMBNAIL_HEIGHT, and THUMBNAIL_WIDTH.

Referenced by PhotoPreviewWidget().

00188 {
00189   //set pixmap rect to be offset slightly from top left corner (by photo margin)
00190   QRect pr = pixmapRect();
00191   int itemLeft = x();
00192   int itemTop = y();
00193   
00194   pixmapXOffset = (THUMBNAIL_WIDTH - pixmap()->width() ) / 2;  
00195   pixmapYOffset = (THUMBNAIL_HEIGHT - pixmap()->height() ) / 2;  
00196   
00197   pr.setLeft( x() + PHOTO_MARGIN );
00198   pr.setRight( pr.left() + THUMBNAIL_WIDTH );
00199   pr.setTop( y() + PHOTO_MARGIN );
00200   pr.setBottom( pr.top() + THUMBNAIL_HEIGHT );
00201   setPixmapRect( pr );
00202 
00203   //move text rect to be below new pixmap region.
00204   //reset height to allow for up to 3 lines of text.
00205   QFontMetrics fm( qApp->font() );
00206   QRect tr = QRect();
00207   tr.setLeft( x() + PHOTO_MARGIN );
00208   tr.setRight( tr.left() +THUMBNAIL_WIDTH );
00209   tr.setTop( y() + PHOTO_MARGIN + THUMBNAIL_HEIGHT + PHOTO_TEXT_MARGIN );
00210   tr.setBottom( tr.top() + 0*fm.leading() + 1*fm.height() );
00211   setTextRect( tr );
00212 
00213   //set overall item rect
00214   int itemW = THUMBNAIL_WIDTH + 2*PHOTO_MARGIN + PHOTO_SHADOW;
00215   int itemH = THUMBNAIL_HEIGHT + PHOTO_TEXT_MARGIN + textRect().height() + 2*PHOTO_MARGIN + PHOTO_SHADOW;
00216   setItemRect( QRect( itemLeft, itemTop, itemW, itemH ) );
00217 }


Member Data Documentation

Photo* PhotoPreviewWidget::phto [private]

Pointer to photo backend object.

Definition at line 74 of file photoPreviewWidget.h.

Referenced by getPhoto(), PhotoPreviewWidget(), updateDescription(), and updateImage().

int PhotoPreviewWidget::calibratedWidth [private]

Definition at line 76 of file photoPreviewWidget.h.

Referenced by PhotoPreviewWidget(), and setText().

bool PhotoPreviewWidget::mousedOver [private]

Definition at line 78 of file photoPreviewWidget.h.

Referenced by paintItem(), PhotoPreviewWidget(), and setMousedOver().

QRect PhotoPreviewWidget::photoInfoRect [private]

Definition at line 80 of file photoPreviewWidget.h.

Referenced by getPhotoInfoRect(), and paintItem().

int PhotoPreviewWidget::pixmapXOffset [private]

offsets used to center pixmap

Definition at line 83 of file photoPreviewWidget.h.

Referenced by getPhotoPos(), initializeItemRect(), paint(), and setPixmap().

int PhotoPreviewWidget::pixmapYOffset [private]

Definition at line 83 of file photoPreviewWidget.h.

Referenced by getPhotoPos(), initializeItemRect(), paint(), and setPixmap().


The documentation for this class was generated from the following files:
Generated on Wed Jan 24 05:38:32 2007 for AlbumShaper by  doxygen 1.5.1