Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

subalbumPreviewWidget.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 #include <qiconview.h>
00022 
00023 //Projectwide includes
00024 #include "subalbumPreviewWidget.h"
00025 #include "subalbumsIconView.h"
00026 #include "../backend/subalbum.h"
00027 #include "../backend/photo.h"
00028 #include "subalbumsWidget.h"
00029 #include "layoutWidget.h"
00030 #include "subalbumWidget.h"
00031 #include "photoWidget.h"
00032 //==============================================
00033 SubalbumPreviewWidget::SubalbumPreviewWidget( SubalbumsIconView* parent, 
00034                                               Subalbum* salbum ) :
00035                                               QIconViewItem(parent, 
00036                                                             salbum->getName(),
00037                                                             *salbum->getRepresentativeImage(MEDIUM))
00038 {
00039   this->parent = parent;
00040   subalbum = salbum;
00041 }
00042 //==============================================
00043 Subalbum* SubalbumPreviewWidget::getSubalbum()
00044 {
00045   return subalbum;
00046 }
00047 //==============================================
00048 void SubalbumPreviewWidget::paintItem( QPainter* p, 
00049                                        const QColorGroup& cg)                          
00050 {
00051   if(isSelected())
00052   {
00053     //draw red border around item
00054     int align = AlignHCenter;
00055     align |= WordBreak | BreakAnywhere;
00056     p->drawPixmap(pixmapRect(false),*pixmap());
00057     p->drawText(textRect(false),align, text());
00058     p->setPen( red );
00059     p->drawRect(rect());
00060   }
00061   else
00062   {
00063     QIconViewItem::paintItem ( p, cg);
00064   }
00065 }
00066 //==============================================
00067 void SubalbumPreviewWidget::dropped( QDropEvent *e, const QValueList<QIconDragItem> & ) 
00068 {
00069   if(e->source()->parentWidget() == parent)
00070   {
00071     if(e->pos().y() < (y() + (height()/2)))
00072     {
00073       parent->currentItem()->move(x(), y() - 1);
00074     }
00075     else
00076     {
00077       parent->currentItem()->move(x(), y() + (height()/2) + 1);
00078     }
00079   }
00080   else
00081   {
00082     //if the source of the items is the current subalbum icon view and
00083     //this is a different subalbum then
00084     //move photos from that subalbum to this one
00085     if(!isSelected() && e->source()->parentWidget() == ((LayoutWidget*)(parent->parentWidget()->parentWidget()))->getSubalbum()->getPhotos())
00086     {
00087       //iterate over all selected photos, inserting each 
00088       //into this subalbum, removing from old subalbum,
00089       //and deleting old photo widgets
00090       SubalbumWidget* oldSubalbumWidget = ((LayoutWidget*)(parent->parentWidget()->parentWidget()))->getSubalbum();
00091       Subalbum* oldSubalbum = oldSubalbumWidget->getSubalbum();
00092       QIconViewItem* current = oldSubalbumWidget->getPhotos()->firstItem();
00093     
00094       while(current != NULL)
00095       {
00096        //found a selected photo
00097         if(current->isSelected())      
00098         {
00099           //get pointer to photo
00100           Photo* photo = ((PhotoWidget*)current)->getPhoto();
00101                 
00102           //remove photo from that subalbum
00103           oldSubalbum->photoMoved(photo);
00104                 
00105           //add photo to this subalbum
00106           subalbum->addPhoto(photo);
00107         
00108           //delete photo widget and rearrange photos
00109           QIconViewItem* temp = current;
00110           current = current->nextItem();
00111           delete temp;
00112         
00113           oldSubalbumWidget->getPhotos()->arrangeItemsInGrid();
00114         }
00115         else
00116           current = current->nextItem();
00117       }
00118     }
00119   }
00120 }
00121 //==============================================
00122 bool SubalbumPreviewWidget::acceptDrop( const QMimeSource *) const
00123 {
00124   return true;
00125 }
00126 //==============================================
00127 int SubalbumPreviewWidget::compare ( QIconViewItem * i ) const
00128 {
00129   if(pos().y() >= i->pos().y())
00130   {  return 1; }
00131   else
00132   { return -1; }
00133 }
00134 //==============================================

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