Main Page   Compound List   File List   Compound Members   File Members  

photoWidget.cpp

Go to the documentation of this file.
00001 //==============================================
00002 //  copyright            : (C) 2003 by Will Stokes
00003 //==============================================
00004 //  This program is free software; you can redistribute it 
00005 //  and/or modify it under the terms of the GNU General 
00006 //  Public License as published by the Free Software 
00007 //  Foundation; either version 2 of the License, or  
00008 //  (at your option) any later version.         
00009 //
00010 //  As a special exception, Will Stokes gives permission to 
00011 //  link this program with Qt non-commercial edition, and 
00012 //  distribute the resulting executable, without including the 
00013 //  source code for the Qt non-commercial edition in the 
00014 //  source distribution. 
00015 //==============================================
00016 
00017 //Systemwide includes
00018 #include <qpixmap.h>
00019 #include <qstring.h>
00020 #include <qpainter.h>
00021 
00022 //Projectwide includes
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     //draw red border around item
00065     int align = AlignHCenter;
00066     align |= WordBreak | BreakAnywhere;
00067     
00068     //create buffer to draw in
00069     QRect rct = rect();
00070     rct.moveBy(-x(), -y());
00071     QPixmap buffer( size() );
00072     //create a painter pointing to the buffer
00073     QPainter bp( &buffer );
00074     //paint to buffer
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     //paint buffer to widget
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 //==============================================

Generated on Tue Jun 10 23:41:21 2003 for AlbumShaper by doxygen 1.3.1