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
00028 PhotoWidget::PhotoWidget( PhotosIconView *parent,
00029 Photo* phto ) : QIconViewItem( parent,
00030 phto->getDescription(),
00031 *phto->getImage(PADDED_THUMBNAIL) )
00032 {
00033 this->parent = parent;
00034 this->phto = phto;
00035 }
00036
00037 Photo* PhotoWidget::getPhoto()
00038 {
00039 return phto;
00040 }
00041
00042 void PhotoWidget::sync()
00043 {
00044 phto->setDescription(text());
00045 }
00046
00047 void PhotoWidget::updateImage()
00048 {
00049 this->setPixmap(*(phto->getImage(PADDED_THUMBNAIL)));
00050 }
00051
00052 void PhotoWidget::updateDescription()
00053 {
00054 this->setText( phto->getDescription() );
00055 }
00056
00057 void PhotoWidget::paintItem( QPainter* p,
00058 const QColorGroup& cg)
00059 {
00060 if(isSelected())
00061 {
00062
00063 int align = AlignHCenter;
00064 align |= WordBreak | BreakAnywhere;
00065
00066
00067 QRect rct = rect();
00068 rct.moveBy(-x(), -y());
00069 QPixmap buffer( size() );
00070
00071 QPainter bp( &buffer );
00072
00073 bp.setBrushOrigin( p->brushOrigin() );
00074 bp.fillRect( rct, white );
00075 QRect pr = pixmapRect(false);
00076 pr.moveBy(-x(), -y());
00077 bp.drawPixmap(pr, *pixmap());
00078 QRect tr = textRect(false);
00079 tr.moveBy(-x(), -y());
00080 bp.drawText(tr,align, text());
00081 bp.setPen( red );
00082 bp.drawRect(rct);
00083 bp.end();
00084
00085 p->drawPixmap( x(), y(), buffer );
00086 }
00087 else
00088 {
00089 QIconViewItem::paintItem ( p, cg);
00090 }
00091 }
00092
00093 void PhotoWidget::setText ( const QString & text )
00094 {
00095 sync();
00096 QIconViewItem::setText(text);
00097 }
00098
00099 void PhotoWidget::dropped( QDropEvent *e, const QValueList<QIconDragItem> & )
00100 {
00101
00102 if(e->source()->parentWidget() == parent)
00103 {
00104
00105 if(e->pos().x() < (x() + (width()/2)))
00106 {
00107
00108 int num=0;
00109 QIconViewItem* current = parent->firstItem();
00110 while(current != NULL)
00111 {
00112 if(current->isSelected())
00113 {
00114 num++;
00115 }
00116 current = current->nextItem();
00117 }
00118
00119
00120 int xpos = x() - num;
00121
00122
00123 current = parent->firstItem();
00124 while(current != NULL)
00125 {
00126 if(current->isSelected())
00127 {
00128 current->move(xpos, y());
00129 xpos++;
00130 }
00131 current = current->nextItem();
00132 }
00133 }
00134
00135 else
00136 {
00137
00138 int xpos = x() + (width()/2) + 1;
00139
00140
00141 QIconViewItem* current = parent->firstItem();
00142 while(current != NULL)
00143 {
00144 if(current->isSelected())
00145 {
00146 current->move(xpos, y());
00147 xpos++;
00148 }
00149 current = current->nextItem();
00150 }
00151 }
00152 }
00153 }
00154
00155 bool PhotoWidget::acceptDrop( const QMimeSource *) const
00156 {
00157 return true;
00158 }
00159
00160 int PhotoWidget::compare ( QIconViewItem * i ) const
00161 {
00162 if( pos().y() > (i->pos().y() + height()) ||
00163 (
00164 pos().y() >= i->pos().y() &&
00165 pos().x() >= i->pos().x()
00166 ))
00167 { return 1; }
00168 else
00169 { return -1; }
00170 }
00171