AlbumShaper
1.0a3
|
Displays photo thumbnail and description. More...
#include <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 |
Displays photo thumbnail and description.
Definition at line 32 of file photoPreviewWidget.h.
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.
: QIconViewItem( parent, QString(""), QPixmap(phto->getThumbnailFilename()) ) { //initially item not moused over, set photo pointer mousedOver = false; this->phto = phto; //calibrated text width is icon width minus margin + info button size (info button is sized to be a square of height //equal to text height, aka fm.height) QFontMetrics fm( qApp->font() ); calibratedWidth = THUMBNAIL_WIDTH - PHOTO_TEXT_MARGIN - fm.height(); //actually set the items text by clipping it using the calibration width we just computed setText( phto->getDescription() ); //update the items rectange which is a function of the text width, icon rect, //and margins for displaying selection and mouse over ovals initializeItemRect(); }
bool PhotoPreviewWidget::acceptDrop | ( | const QMimeSource * | e | ) | const |
Definition at line 170 of file photoPreviewWidget.cpp.
{ return true; }
int PhotoPreviewWidget::compare | ( | QIconViewItem * | i | ) | const |
Definition at line 175 of file photoPreviewWidget.cpp.
References height.
{ if( pos().y() > (i->pos().y() + height()) || ( pos().y() >= i->pos().y() && pos().x() >= i->pos().x() )) { return 1; } else { return -1; } }
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().
{ return phto; }
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().
{ QRect photoInfoRect; QFontMetrics fm( qApp->font() ); photoInfoRect.setLeft( x() + rect().width() - fm.height() - PHOTO_MARGIN - PHOTO_SHADOW - 1 ); photoInfoRect.setRight( photoInfoRect.left() + fm.height() ); photoInfoRect.setTop( y() + rect().height() - fm.height() - PHOTO_MARGIN - PHOTO_SHADOW - 1 ); photoInfoRect.setBottom( photoInfoRect.top() + fm.height() ); return photoInfoRect; }
QPoint PhotoPreviewWidget::getPhotoPos | ( | ) |
Definition at line 235 of file photoPreviewWidget.cpp.
References pixmapXOffset, and pixmapYOffset.
Referenced by PhotoDescEdit::PhotoDescEdit().
{ //get widget coordiantes of item int xpos,ypos; xpos = x() + pixmapRect().x() + pixmapXOffset + 1; ypos = y() + pixmapRect().y() + pixmapYOffset + 1; //shift by scrolled amount xpos-= iconView()->contentsX(); ypos-= iconView()->contentsY(); //offset by viewport top left //(why not iconview topleft? item actually placed in viewport which is placed in iconview. this //viewport can be offset (and when I wrote this code it was) from the iconview depending on Trolltech's //scrollview code which can using spacing between the viewport and scrolls widgets. since the viewport //is a full blown widget, we can figure out it's reall screen coordinates and need not consult the iconview object at all. QPoint viewportTL = iconView()->viewport()->mapToGlobal( QPoint(0,0) ); xpos+= viewportTL.x(); ypos+= viewportTL.y(); return QPoint(xpos,ypos); }
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().
{ //set pixmap rect to be offset slightly from top left corner (by photo margin) QRect pr = pixmapRect(); int itemLeft = x(); int itemTop = y(); pixmapXOffset = (THUMBNAIL_WIDTH - pixmap()->width() ) / 2; pixmapYOffset = (THUMBNAIL_HEIGHT - pixmap()->height() ) / 2; pr.setLeft( x() + PHOTO_MARGIN ); pr.setRight( pr.left() + THUMBNAIL_WIDTH ); pr.setTop( y() + PHOTO_MARGIN ); pr.setBottom( pr.top() + THUMBNAIL_HEIGHT ); setPixmapRect( pr ); //move text rect to be below new pixmap region. //reset height to allow for up to 3 lines of text. QFontMetrics fm( qApp->font() ); QRect tr = QRect(); tr.setLeft( x() + PHOTO_MARGIN ); tr.setRight( tr.left() +THUMBNAIL_WIDTH ); tr.setTop( y() + PHOTO_MARGIN + THUMBNAIL_HEIGHT + PHOTO_TEXT_MARGIN ); tr.setBottom( tr.top() + 0*fm.leading() + 1*fm.height() ); setTextRect( tr ); //set overall item rect int itemW = THUMBNAIL_WIDTH + 2*PHOTO_MARGIN + PHOTO_SHADOW; int itemH = THUMBNAIL_HEIGHT + PHOTO_TEXT_MARGIN + textRect().height() + 2*PHOTO_MARGIN + PHOTO_SHADOW; setItemRect( QRect( itemLeft, itemTop, itemW, itemH ) ); }
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().
{ //create colors QColor offWhite( 255, 255, 255 ); QColor darkBlue(35, 75, 139); QColor paperColor; //draw offwhite or selected color depending on if photo is selected QRect paperRect( x(), y(), 2*PHOTO_MARGIN + pixmapRect().width(), 2*PHOTO_MARGIN + pixmapRect().height() + PHOTO_TEXT_MARGIN + textRect().height() ); if(isSelected()) paperColor = darkBlue; else paperColor = offWhite; p->fillRect( paperRect, QBrush( paperColor ) ); //paint pixmap p->drawPixmap( x() + pixmapRect().x() + pixmapXOffset + 1, y() + pixmapRect().y() + pixmapYOffset + 1, *pixmap()); //paint text int align = AlignLeft | AlignTop | BreakAnywhere; if(isSelected()) p->setPen( white ); else p->setPen( black ); p->drawText( x() + textRect().x() + 1, y() + textRect().y() + 1, textRect().width(), textRect().height(), align, text() ); }
void PhotoPreviewWidget::paintFocus | ( | QPainter * | p, |
const QColorGroup & | cg | ||
) |
Definition at line 168 of file photoPreviewWidget.cpp.
{ }
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.
{ //resize old static buffer to new needed size, fill with widget background color static QPixmap buffer; QRect r = rect(); QSize newSize = r.size().expandedTo(buffer.size() ); buffer.resize(newSize); buffer.fill( white ); //construct painter for buffer QPainter bufferPainter(&buffer, this); bufferPainter.translate( -r.x(), -r.y() ); //paint item paint(&bufferPainter); //paint edit button if(mousedOver) { QRect photoInfoRect = getPhotoInfoRect(); bufferPainter.drawPixmap( photoInfoRect, * (((Window*) qApp->mainWidget())->photoInfo) ); } //paint shadows QPixmap* shadowBL, *shadowB, *shadowBR, *shadowR, *shadowTR; Window* window = (Window*) qApp->mainWidget(); shadowBL = window->shadowBL; shadowB = window->shadowB; shadowBR = window->shadowBR; shadowR = window->shadowR; shadowTR = window->shadowTR; QRect shadowRect; shadowRect.setLeft( x() + PHOTO_SHADOW_END_OFFSET ); shadowRect.setRight( shadowRect.left() + PHOTO_SHADOW ); shadowRect.setTop( y() + rect().height() - PHOTO_SHADOW ); shadowRect.setBottom( shadowRect.top() + PHOTO_SHADOW ); bufferPainter.drawPixmap( shadowRect, *shadowBL ); shadowRect.setLeft( shadowRect.right() + 1 ); shadowRect.setRight( x() + rect().width() - PHOTO_SHADOW - 1 ); bufferPainter.drawPixmap( shadowRect, *shadowB ); shadowRect.setLeft( shadowRect.right() + 1 ); shadowRect.setRight( shadowRect.left() + PHOTO_SHADOW ); bufferPainter.drawPixmap( shadowRect, *shadowBR ); shadowRect.setBottom( shadowRect.top() - 1 ); shadowRect.setTop( y() +PHOTO_SHADOW_END_OFFSET + PHOTO_SHADOW ); bufferPainter.drawPixmap( shadowRect, *shadowR ); shadowRect.setBottom( shadowRect.top() - 1 ); shadowRect.setTop( y() +PHOTO_SHADOW_END_OFFSET ); bufferPainter.drawPixmap( shadowRect, *shadowTR ); //draw buffer to screen p->drawPixmap( x(), y(), buffer ); }
void PhotoPreviewWidget::setMousedOver | ( | bool | val | ) |
Definition at line 219 of file photoPreviewWidget.cpp.
References mousedOver.
Referenced by PhotosIconView::clearPseudoSelection(), and PhotosIconView::repaintGroup().
{ mousedOver = val; }
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().
{ pixmapXOffset = (THUMBNAIL_WIDTH - p.width() ) / 2; pixmapYOffset = (THUMBNAIL_HEIGHT - p.height() ) / 2; QIconViewItem::setPixmap( p, redraw ); }
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().
{ QIconViewItem::setText( clipText(text, 1, calibratedWidth), false ); }
void PhotoPreviewWidget::updateDescription | ( | ) |
Update photo description.
Definition at line 66 of file photoPreviewWidget.cpp.
References Photo::getDescription(), phto, and setText().
{ setText( phto->getDescription() ); }
void PhotoPreviewWidget::updateImage | ( | ) |
Update photo thumbnail from background object.
Definition at line 54 of file photoPreviewWidget.cpp.
References Photo::getThumbnailFilename(), phto, and setPixmap().
{ setPixmap( QPixmap(phto->getThumbnailFilename()), false); }
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().
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::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().