AlbumShaper 1.0a3
PhotoPreviewWidget Class Reference

Displays photo thumbnail and description. More...

#include <photoPreviewWidget.h>

Inheritance diagram for PhotoPreviewWidget:
Collaboration diagram for PhotoPreviewWidget:

Public Member Functions

 PhotoPreviewWidget (Q3IconView *parent, Photo *phto)
 Sets subalbum pointer.
 
PhotogetPhoto ()
 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 (Q3IconViewItem *i) const
 
void setMousedOver (bool val)
 
QRect getPhotoInfoRect ()
 
QPoint getPhotoPos ()
 

Private Member Functions

void initializeItemRect ()
 

Private Attributes

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

Detailed Description

Displays photo thumbnail and description.

Definition at line 34 of file photoPreviewWidget.h.

Constructor & Destructor Documentation

◆ PhotoPreviewWidget()

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

Sets subalbum pointer.

Definition at line 29 of file photoPreviewWidget.cpp.

29 :
30 Q3IconViewItem( parent, QString(""), QPixmap(phto->getThumbnailFilename()) )
31{
32 //initially item not moused over, set photo pointer
33 mousedOver = false;
34 this->phto = phto;
35
36 //calibrated text width is icon width minus margin + info button size (info button is sized to be a square of height
37 //equal to text height, aka fm.height)
38 QFontMetrics fm( qApp->font() );
40
41 //actually set the items text by clipping it using the calibration width we just computed
43
44 //update the items rectange which is a function of the text width, icon rect,
45 //and margins for displaying selection and mouse over ovals
47}
Photo * phto
Pointer to photo backend object.
void setText(const QString &text)
QString getThumbnailFilename()
Gets the thumbnail filename.
Definition photo.cpp:194
QString getDescription()
Gets the description.
Definition photo.cpp:208
#define THUMBNAIL_WIDTH
Definition config.h:24
#define PHOTO_TEXT_MARGIN

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

Member Function Documentation

◆ acceptDrop()

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

Definition at line 170 of file photoPreviewWidget.cpp.

171{
172 return true;
173}

◆ compare()

int PhotoPreviewWidget::compare ( Q3IconViewItem * i) const

Definition at line 175 of file photoPreviewWidget.cpp.

176{
177 if( pos().y() > (i->pos().y() + height()) ||
178 (
179 pos().y() >= i->pos().y() &&
180 pos().x() >= i->pos().x()
181 ))
182 { return 1; }
183 else
184 { return -1; }
185}
int height
Definition blur.cpp:79

References height.

◆ getPhoto()

Photo * PhotoPreviewWidget::getPhoto ( )

◆ getPhotoInfoRect()

QRect PhotoPreviewWidget::getPhotoInfoRect ( )

Definition at line 224 of file photoPreviewWidget.cpp.

225{
226 QRect photoInfoRect;
227 QFontMetrics fm( qApp->font() );
228 photoInfoRect.setLeft( x() + rect().width() - fm.height() - PHOTO_MARGIN - PHOTO_SHADOW - 1 );
229 photoInfoRect.setRight( photoInfoRect.left() + fm.height() );
230 photoInfoRect.setTop( y() + rect().height() - fm.height() - PHOTO_MARGIN - PHOTO_SHADOW - 1 );
231 photoInfoRect.setBottom( photoInfoRect.top() + fm.height() );
232 return photoInfoRect;
233}
int width
Definition blur.cpp:79
#define PHOTO_SHADOW
#define PHOTO_MARGIN

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

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

◆ getPhotoPos()

QPoint PhotoPreviewWidget::getPhotoPos ( )

Definition at line 235 of file photoPreviewWidget.cpp.

236{
237 //get widget coordiantes of item
238 int xpos,ypos;
239 xpos = x() + pixmapRect().x() + pixmapXOffset + 1;
240 ypos = y() + pixmapRect().y() + pixmapYOffset + 1;
241
242 //shift by scrolled amount
243 xpos-= iconView()->contentsX();
244 ypos-= iconView()->contentsY();
245
246 //offset by viewport top left
247 //(why not iconview topleft? item actually placed in viewport which is placed in iconview. this
248 //viewport can be offset (and when I wrote this code it was) from the iconview depending on Trolltech's
249 //scrollview code which can using spacing between the viewport and scrolls widgets. since the viewport
250 //is a full blown widget, we can figure out it's reall screen coordinates and need not consult the iconview object at all.
251 QPoint viewportTL = iconView()->viewport()->mapToGlobal( QPoint(0,0) );
252 xpos+= viewportTL.x();
253 ypos+= viewportTL.y();
254
255 return QPoint(xpos,ypos);
256}
int pixmapXOffset
offsets used to center pixmap

References pixmapXOffset, and pixmapYOffset.

Referenced by PhotoDescEdit::PhotoDescEdit().

◆ initializeItemRect()

void PhotoPreviewWidget::initializeItemRect ( )
private

Definition at line 187 of file photoPreviewWidget.cpp.

188{
189 //set pixmap rect to be offset slightly from top left corner (by photo margin)
190 QRect pr = pixmapRect();
191 int itemLeft = x();
192 int itemTop = y();
193
194 pixmapXOffset = (THUMBNAIL_WIDTH - pixmap()->width() ) / 2;
195 pixmapYOffset = (THUMBNAIL_HEIGHT - pixmap()->height() ) / 2;
196
197 pr.setLeft( x() + PHOTO_MARGIN );
198 pr.setRight( pr.left() + THUMBNAIL_WIDTH );
199 pr.setTop( y() + PHOTO_MARGIN );
200 pr.setBottom( pr.top() + THUMBNAIL_HEIGHT );
201 setPixmapRect( pr );
202
203 //move text rect to be below new pixmap region.
204 //reset height to allow for up to 3 lines of text.
205 QFontMetrics fm( qApp->font() );
206 QRect tr = QRect();
207 tr.setLeft( x() + PHOTO_MARGIN );
208 tr.setRight( tr.left() +THUMBNAIL_WIDTH );
209 tr.setTop( y() + PHOTO_MARGIN + THUMBNAIL_HEIGHT + PHOTO_TEXT_MARGIN );
210 tr.setBottom( tr.top() + 0*fm.leading() + 1*fm.height() );
211 setTextRect( tr );
212
213 //set overall item rect
214 int itemW = THUMBNAIL_WIDTH + 2*PHOTO_MARGIN + PHOTO_SHADOW;
215 int itemH = THUMBNAIL_HEIGHT + PHOTO_TEXT_MARGIN + textRect().height() + 2*PHOTO_MARGIN + PHOTO_SHADOW;
216 setItemRect( QRect( itemLeft, itemTop, itemW, itemH ) );
217}
#define THUMBNAIL_HEIGHT
Definition config.h:25

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

Referenced by PhotoPreviewWidget().

◆ paint()

void PhotoPreviewWidget::paint ( QPainter * p)

Definition at line 76 of file photoPreviewWidget.cpp.

77{
78 //create colors
79 QColor offWhite( 255, 255, 255 );
80 QColor darkBlue(35, 75, 139);
81 QColor paperColor;
82
83 //draw offwhite or selected color depending on if photo is selected
84 QRect paperRect( x(), y(),
85 2*PHOTO_MARGIN + pixmapRect().width(),
86 2*PHOTO_MARGIN + pixmapRect().height() + PHOTO_TEXT_MARGIN + textRect().height() );
87 if(isSelected())
88 paperColor = darkBlue;
89 else
90 paperColor = offWhite;
91 p->fillRect( paperRect, QBrush( paperColor ) );
92
93 //paint pixmap
94 p->drawPixmap( x() + pixmapRect().x() + pixmapXOffset + 1,
95 y() + pixmapRect().y() + pixmapYOffset + 1,
96 *pixmap());
97
98 //paint text
99 int align = Qt::AlignLeft | Qt::AlignTop | Qt::TextWrapAnywhere;
100 if(isSelected())
101 p->setPen( Qt::white );
102 else
103 p->setPen( Qt::black );
104 p->drawText( x() + textRect().x() + 1, y() + textRect().y() + 1,
105 textRect().width(), textRect().height(),
106 align, text() );
107}

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

Referenced by paintItem().

◆ paintFocus()

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

Definition at line 168 of file photoPreviewWidget.cpp.

168{ }

◆ paintItem()

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

Repain iconview item.

Definition at line 109 of file photoPreviewWidget.cpp.

110{
111 //resize old static buffer to new needed size, fill with widget background color
112 static QPixmap buffer;
113 QRect r = rect();
114 QSize newSize = r.size().expandedTo(buffer.size() );
115 buffer.resize(newSize);
116 buffer.fill( Qt::white );
117
118 //construct painter for buffer
119 QPainter bufferPainter(&buffer);
120 bufferPainter.translate( -r.x(), -r.y() );
121
122 //paint item
123 paint(&bufferPainter);
124
125 //paint edit button
126 if(mousedOver)
127 {
129 bufferPainter.drawPixmap( photoInfoRect, * (((Window*) qApp->mainWidget())->photoInfo) );
130 }
131
132 //paint shadows
133 QPixmap* shadowBL, *shadowB, *shadowBR, *shadowR, *shadowTR;
134 Window* window = (Window*) qApp->mainWidget();
135 shadowBL = window->shadowBL;
136 shadowB = window->shadowB;
137 shadowBR = window->shadowBR;
138 shadowR = window->shadowR;
139 shadowTR = window->shadowTR;
140
141 QRect shadowRect;
142 shadowRect.setLeft( x() + PHOTO_SHADOW_END_OFFSET );
143 shadowRect.setRight( shadowRect.left() + PHOTO_SHADOW );
144 shadowRect.setTop( y() + rect().height() - PHOTO_SHADOW );
145 shadowRect.setBottom( shadowRect.top() + PHOTO_SHADOW );
146 bufferPainter.drawPixmap( shadowRect, *shadowBL );
147
148 shadowRect.setLeft( shadowRect.right() + 1 );
149 shadowRect.setRight( x() + rect().width() - PHOTO_SHADOW - 1 );
150 bufferPainter.drawPixmap( shadowRect, *shadowB );
151
152 shadowRect.setLeft( shadowRect.right() + 1 );
153 shadowRect.setRight( shadowRect.left() + PHOTO_SHADOW );
154 bufferPainter.drawPixmap( shadowRect, *shadowBR );
155
156 shadowRect.setBottom( shadowRect.top() - 1 );
157 shadowRect.setTop( y() +PHOTO_SHADOW_END_OFFSET + PHOTO_SHADOW );
158 bufferPainter.drawPixmap( shadowRect, *shadowR );
159
160 shadowRect.setBottom( shadowRect.top() - 1 );
161 shadowRect.setTop( y() +PHOTO_SHADOW_END_OFFSET );
162 bufferPainter.drawPixmap( shadowRect, *shadowTR );
163
164 //draw buffer to screen
165 p->drawPixmap( x(), y(), buffer );
166}
float * buffer
Definition blur.cpp:80
void paint(QPainter *p)
Top level widget, encapsulates the title widget, the layout widget, and the toolbar widget.
Definition window.h:40
QPixmap * shadowTR
Definition window.h:70
QPixmap * shadowB
Definition window.h:70
QPixmap * shadowR
Definition window.h:70
QPixmap * shadowBR
Definition window.h:70
QPixmap * shadowBL
Definition window.h:70
#define PHOTO_SHADOW_END_OFFSET

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.

◆ setMousedOver()

void PhotoPreviewWidget::setMousedOver ( bool val)

Definition at line 219 of file photoPreviewWidget.cpp.

220{
221 mousedOver = val;
222}

References mousedOver.

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

◆ setPixmap()

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

Definition at line 59 of file photoPreviewWidget.cpp.

60{
61 pixmapXOffset = (THUMBNAIL_WIDTH - p.width() ) / 2;
62 pixmapYOffset = (THUMBNAIL_HEIGHT - p.height() ) / 2;
63 Q3IconViewItem::setPixmap( p, redraw );
64}

References pixmapXOffset, pixmapYOffset, THUMBNAIL_HEIGHT, and THUMBNAIL_WIDTH.

Referenced by PhotosIconView::drawBackground(), and updateImage().

◆ setText()

void PhotoPreviewWidget::setText ( const QString & text)

Definition at line 71 of file photoPreviewWidget.cpp.

72{
73 Q3IconViewItem::setText( clipText(text, 1, calibratedWidth), false );
74}
QString clipText(QString string, int lines, int lineWidth)
clip text to fit within numer of lines and max width
Definition guiTools.cpp:72

References calibratedWidth, and clipText().

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

◆ updateDescription()

void PhotoPreviewWidget::updateDescription ( )

Update photo description.

Definition at line 66 of file photoPreviewWidget.cpp.

67{
69}

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

◆ updateImage()

void PhotoPreviewWidget::updateImage ( )

Update photo thumbnail from background object.

Definition at line 54 of file photoPreviewWidget.cpp.

55{
56 setPixmap( QPixmap(phto->getThumbnailFilename()), false);
57}
void setPixmap(const QPixmap &p, bool redraw)

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

Member Data Documentation

◆ calibratedWidth

int PhotoPreviewWidget::calibratedWidth
private

Definition at line 78 of file photoPreviewWidget.h.

Referenced by PhotoPreviewWidget(), and setText().

◆ mousedOver

bool PhotoPreviewWidget::mousedOver
private

Definition at line 80 of file photoPreviewWidget.h.

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

◆ photoInfoRect

QRect PhotoPreviewWidget::photoInfoRect
private

Definition at line 82 of file photoPreviewWidget.h.

Referenced by getPhotoInfoRect(), and paintItem().

◆ phto

Photo* PhotoPreviewWidget::phto
private

Pointer to photo backend object.

Definition at line 76 of file photoPreviewWidget.h.

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

◆ pixmapXOffset

int PhotoPreviewWidget::pixmapXOffset
private

offsets used to center pixmap

Definition at line 85 of file photoPreviewWidget.h.

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

◆ pixmapYOffset

int PhotoPreviewWidget::pixmapYOffset
private

Definition at line 85 of file photoPreviewWidget.h.

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


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