00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <qpixmap.h>
00019 #include <qstring.h>
00020 #include <qpainter.h>
00021
00022
00023 #include "photoWidget.h"
00024 #include "photosIconView.h"
00025 #include "../backend/photo.h"
00026
00027 #include <iostream.h>
00028
00029
00030 PhotoWidget::PhotoWidget( PhotosIconView *parent,
00031 Photo* phto ) : QIconViewItem( parent,
00032 phto->getDescription(),
00033 *phto->getImage(PADDED_THUMBNAIL) )
00034 {
00035 this->parent = parent;
00036 this->phto = phto;
00037 }
00038
00039 Photo* PhotoWidget::getPhoto()
00040 {
00041 return phto;
00042 }
00043
00044 void PhotoWidget::sync()
00045 {
00046 phto->setDescription(text());
00047 }
00048
00049 void PhotoWidget::updateImage()
00050 {
00051 this->setPixmap(*(phto->getImage(PADDED_THUMBNAIL)));
00052 }
00053
00054 void PhotoWidget::updateDescription()
00055 {
00056 this->setText( phto->getDescription() );
00057 }
00058
00059 void PhotoWidget::paintItem( QPainter* p,
00060 const QColorGroup& cg)
00061 {
00062 if(isSelected())
00063 {
00064
00065 int align = AlignHCenter;
00066 align |= WordBreak | BreakAnywhere;
00067
00068
00069 QRect rct = rect();
00070 rct.moveBy(-x(), -y());
00071 QPixmap buffer( size() );
00072
00073 QPainter bp( &buffer );
00074
00075 bp.setBrushOrigin( p->brushOrigin() );
00076 bp.fillRect( rct, white );
00077 QRect pr = pixmapRect(false);
00078 pr.moveBy(-x(), -y());
00079 bp.drawPixmap(pr, *pixmap());
00080 QRect tr = textRect(false);
00081 tr.moveBy(-x(), -y());
00082 bp.drawText(tr,align, text());
00083 bp.setPen( red );
00084 bp.drawRect(rct);
00085 bp.end();
00086
00087 p->drawPixmap( x(), y(), buffer );
00088 }
00089 else
00090 {
00091 QIconViewItem::paintItem ( p, cg);
00092 }
00093 }
00094
00095 void PhotoWidget::setText ( const QString & text )
00096 {
00097 sync();
00098 QIconViewItem::setText(text);
00099 }
00100
00101 void PhotoWidget::dropped( QDropEvent *e, const QValueList<QIconDragItem> & )
00102 {
00103 if(e->source()->parentWidget() == parent)
00104 {
00105 if(e->pos().x() < (x() + (width()/2)))
00106 {
00107 parent->currentItem()->move(x() - 1, y());
00108 }
00109 else
00110 {
00111 parent->currentItem()->move(x() + (width()/2) + 1, y());
00112 }
00113 }
00114 }
00115
00116 bool PhotoWidget::acceptDrop( const QMimeSource *) const
00117 {
00118 return true;
00119 }
00120
00121 int PhotoWidget::compare ( QIconViewItem * i ) const
00122 {
00123 if( pos().y() > (i->pos().y() + height()) ||
00124 (
00125 pos().y() >= i->pos().y() &&
00126 pos().x() >= i->pos().x()
00127 ))
00128 { return 1; }
00129 else
00130 { return -1; }
00131 }
00132