00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <qpixmap.h>
00013 #include <qstring.h>
00014 #include <qpainter.h>
00015 #include <qfontmetrics.h>
00016 #include <qapplication.h>
00017 #include <qrect.h>
00018 #include <qbitmap.h>
00019
00020
00021 #include "photoPreviewWidget.h"
00022 #include "photosIconView.h"
00023 #include "window.h"
00024 #include "../config.h"
00025 #include "../backend/photo.h"
00026 #include "../backend/tools/guiTools.h"
00027
00028
00029 PhotoPreviewWidget::PhotoPreviewWidget( QIconView *parent, Photo* phto ) :
00030 QIconViewItem( parent, QString(""), QPixmap(phto->getThumbnailFilename()) )
00031 {
00032
00033 mousedOver = false;
00034 this->phto = phto;
00035
00036
00037
00038 QFontMetrics fm( qApp->font() );
00039 calibratedWidth = THUMBNAIL_WIDTH - PHOTO_TEXT_MARGIN - fm.height();
00040
00041
00042 setText( phto->getDescription() );
00043
00044
00045
00046 initializeItemRect();
00047 }
00048
00049 Photo* PhotoPreviewWidget::getPhoto()
00050 {
00051 return phto;
00052 }
00053
00054 void PhotoPreviewWidget::updateImage()
00055 {
00056 setPixmap( QPixmap(phto->getThumbnailFilename()), false);
00057 }
00058
00059 void PhotoPreviewWidget::setPixmap(const QPixmap& p, bool redraw )
00060 {
00061 pixmapXOffset = (THUMBNAIL_WIDTH - p.width() ) / 2;
00062 pixmapYOffset = (THUMBNAIL_HEIGHT - p.height() ) / 2;
00063 QIconViewItem::setPixmap( p, redraw );
00064 }
00065
00066 void PhotoPreviewWidget::updateDescription()
00067 {
00068 setText( phto->getDescription() );
00069 }
00070
00071 void PhotoPreviewWidget::setText ( const QString & text )
00072 {
00073 QIconViewItem::setText( clipText(text, 1, calibratedWidth), false );
00074 }
00075
00076 void PhotoPreviewWidget::paint( QPainter *p )
00077 {
00078
00079 QColor offWhite( 255, 255, 255 );
00080 QColor darkBlue(35, 75, 139);
00081 QColor paperColor;
00082
00083
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
00094 p->drawPixmap( x() + pixmapRect().x() + pixmapXOffset + 1,
00095 y() + pixmapRect().y() + pixmapYOffset + 1,
00096 *pixmap());
00097
00098
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 }
00108
00109 void PhotoPreviewWidget::paintItem( QPainter* p, const QColorGroup&)
00110 {
00111
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
00119 QPainter bufferPainter(&buffer, this);
00120 bufferPainter.translate( -r.x(), -r.y() );
00121
00122
00123 paint(&bufferPainter);
00124
00125
00126 if(mousedOver)
00127 {
00128 QRect photoInfoRect = getPhotoInfoRect();
00129 bufferPainter.drawPixmap( photoInfoRect, * (((Window*) qApp->mainWidget())->photoInfo) );
00130 }
00131
00132
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
00165 p->drawPixmap( x(), y(), buffer );
00166 }
00167
00168 void PhotoPreviewWidget::paintFocus( QPainter*, const QColorGroup& ) { }
00169
00170 bool PhotoPreviewWidget::acceptDrop( const QMimeSource *) const
00171 {
00172 return true;
00173 }
00174
00175 int PhotoPreviewWidget::compare ( QIconViewItem * i ) const
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 }
00186
00187 void PhotoPreviewWidget::initializeItemRect()
00188 {
00189
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
00204
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
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 }
00218
00219 void PhotoPreviewWidget::setMousedOver(bool val)
00220 {
00221 mousedOver = val;
00222 }
00223
00224 QRect PhotoPreviewWidget::getPhotoInfoRect()
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 }
00234
00235 QPoint PhotoPreviewWidget::getPhotoPos()
00236 {
00237
00238 int xpos,ypos;
00239 xpos = x() + pixmapRect().x() + pixmapXOffset + 1;
00240 ypos = y() + pixmapRect().y() + pixmapYOffset + 1;
00241
00242
00243 xpos-= iconView()->contentsX();
00244 ypos-= iconView()->contentsY();
00245
00246
00247
00248
00249
00250
00251 QPoint viewportTL = iconView()->viewport()->mapToGlobal( QPoint(0,0) );
00252 xpos+= viewportTL.x();
00253 ypos+= viewportTL.y();
00254
00255 return QPoint(xpos,ypos);
00256 }
00257