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

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