Main Page | Class Hierarchy | Class List | File List | Class 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 //==============================================
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     //draw red border around item
00063     int align = AlignHCenter;
00064     align |= WordBreak | BreakAnywhere;
00065     
00066     //create buffer to draw in
00067     QRect rct = rect();
00068     rct.moveBy(-x(), -y());
00069     QPixmap buffer( size() );
00070     //create a painter pointing to the buffer
00071     QPainter bp( &buffer );
00072     //paint to buffer
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     //paint buffer to widget
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   //item is being moved around within subalbum
00102   if(e->source()->parentWidget() == parent)
00103   {
00104     //selected photos dropped on left of object   
00105     if(e->pos().x() < (x() + (width()/2)))
00106     {         
00107       //count number of items being moved
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       //compute new x-coordinate of first object being moved
00120       int xpos = x() - num;
00121       
00122       //iterate over each object being moved and move to their new location
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     } //end if
00134     //selected photos being dropped on right of object
00135     else
00136     {
00137       //compute first new x coordinate for selected photos
00138       int xpos = x() + (width()/2) + 1;
00139       
00140       //iterate over all selected photos and move to their new location
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     } //end else
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 //==============================================

Generated on Thu Nov 13 00:10:54 2003 for AlbumShaper by doxygen 1.3.4