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

subalbumWidget.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 <qlayout.h>
00019 #include <qlabel.h>
00020 #include <qfont.h>
00021 #include <qframe.h>
00022 #include <qpushbutton.h>
00023 #include <qtoolbutton.h>
00024 #include <qpixmap.h>
00025 #include <qlineedit.h>
00026 #include <qfiledialog.h>
00027 #include <qcursor.h>
00028 #include <qapplication.h>
00029 #include <qtooltip.h>
00030 
00031 //Projectwide includes
00032 #include "../backend/subalbum.h"
00033 #include "../backend/photo.h"
00034 #include "window.h"
00035 #include "titleWidget.h"
00036 #include "layoutWidget.h"
00037 #include "subalbumWidget.h"
00038 #include "subalbumsWidget.h"
00039 #include "photoWidget.h"
00040 #include "questionDialog.h"
00041 #include "photosIconView.h"
00042 #include "statusWidget.h"
00043 #include "guiTools.h"
00044 #include "../config.h"
00045 
00046 //==============================================
00047 SubalbumWidget::SubalbumWidget(Subalbum* salbum,
00048                                QWidget *parent, 
00049                                const char* name ) : 
00050                                QWidget(parent,name)
00051 {
00052   //store subalbum pointer
00053   subalbum = salbum;
00054 
00055   //store layout pointer
00056   layout = (LayoutWidget*)parent;
00057 
00058   annotationsFrame = new QFrame(this); 
00059   
00060   //create subalbum name and description label and text entries
00061   subalbumName = new QLabel( annotationsFrame );
00062   subalbumName->setText( tr("Subalbum Name:") );
00063   subalbumName->setFont( QFont( "Times", 12, QFont::Bold ) );
00064   subalbumNameVal = new QLineEdit( annotationsFrame );
00065   subalbumNameVal->setFont( QFont( "Times", 12, QFont::Bold ) );
00066   subalbumNameVal->setText(  subalbum->getName() );
00067   connect( subalbumNameVal, SIGNAL(textChanged(const QString&)),
00068            SLOT(updateName(const QString&)) );
00069 
00070   subalbumDescription = new QLabel( annotationsFrame );
00071   subalbumDescription->setText( tr("Description:") );
00072   subalbumDescription->setFont( QFont( "Times", 12, QFont::Bold ) );
00073   subalbumDescriptionVal = new QLineEdit( annotationsFrame );
00074   subalbumDescriptionVal->setFont( QFont( "Times", 12, QFont::Bold ) );
00075   subalbumDescriptionVal->setText(  subalbum->getDescription() );
00076   connect( subalbumDescriptionVal, SIGNAL(textChanged(const QString&)),
00077            SLOT(updateDescription(const QString&)) );
00078 
00079   //create set image button
00080   representativeImageText = new QLabel( annotationsFrame );
00081   representativeImageText->setText( tr("Thumbnail:") );
00082   representativeImageText->setFont( QFont( "Times", 12, QFont::Bold ) );
00083  
00084   QFont buttonFont( qApp->font() );
00085   buttonFont.setBold(true);
00086   buttonFont.setPointSize( 11 );
00087  
00088   setImage = new QToolButton( annotationsFrame );
00089   setImage->setTextLabel(tr("Set") );
00090   setImage->setTextPosition(QToolButton::Right);
00091   setImage->setFont( buttonFont );
00092   setImage->setUsesTextLabel( true );
00093   setImage->setEnabled(false);
00094   QToolTip::add( setImage, tr("Set subalbum thumbnail to selected photo") );
00095   connect( setImage, SIGNAL(clicked()), SLOT(setImageAction()) );
00096   
00097   //create representative image
00098   representativeLogo = new QLabel( annotationsFrame );
00099   representativeLogo->setPixmap( *subalbum->getRepresentativeImage(SMALL) );
00100 
00101   //create photo collection
00102   photos = new PhotosIconView( this );
00103   
00104   //establish a top-down view such that the scrollbar is always placed on the right
00105   photos->setArrangement( QIconView::LeftToRight );
00106   photos->setVScrollBarMode( QScrollView::AlwaysOn );
00107   
00108   //allow multiple photos to be selected with control and shift keys
00109   photos->setSelectionMode( QIconView::Extended ) ;
00110   
00111   //set auto-scroll on for drag-n-drop
00112   photos->setDragAutoScroll(true);
00113   photos->setAcceptDrops(true);
00114 
00115   //whenever photo names are changed sync with backend object
00116   connect( photos, SIGNAL(itemRenamed( QIconViewItem *)), 
00117            this, SLOT(rearrangeAndSaveCurrent( QIconViewItem *)));
00118            
00119   //connect selectionChanged signal to update buttons method
00120   connect( photos, SIGNAL(selectionChanged()),
00121            SLOT(updateButtons()) );
00122 
00123   //connect rightButtonClicked signal to update buttons method
00124   connect( photos, SIGNAL(rightButtonClicked(QIconViewItem*, const QPoint&)),
00125            SLOT(updateButtons()) );
00126            
00127   //if the set button is clicked set the representative image for the subalbum
00128   connect( setImage, SIGNAL(clicked()), SLOT(setImageAction()) );
00129 
00130   //connect drop event on iconview to reorder slot
00131   connect( photos, SIGNAL(itemHasMoved()), SLOT(reorder()) );  
00132   
00133   //create all buttons
00134   buttonsFrame = new QFrame(this);
00135    
00136   addImage = new QToolButton( buttonsFrame );
00137   addImage->setTextLabel(tr("Add Photo"));
00138   addImage->setIconSet( QPixmap(QString(IMAGE_PATH)+"add.png") );
00139   addImage->setTextPosition(QToolButton::Right);
00140   addImage->setFont( buttonFont );
00141   addImage->setUsesTextLabel( true );
00142   QToolTip::add( addImage, tr("Add photos to selected subalbum") );
00143   connect( addImage, SIGNAL(clicked()), SLOT(addImageAction()) );
00144   
00145   removeImage = new QToolButton( buttonsFrame );
00146   removeImage->setTextLabel(tr("Remove Photo"));
00147   removeImage->setIconSet( QPixmap(QString(IMAGE_PATH)+"remove.png") );
00148   removeImage->setTextPosition(QToolButton::Right);
00149   removeImage->setFont( buttonFont );
00150   removeImage->setUsesTextLabel( true );
00151   QToolTip::add( removeImage, tr("Remove selected photos from subalbum") );
00152   connect( removeImage, SIGNAL(clicked()), SLOT(removeImageAction()) );
00153   
00154   rotate90Image = new QToolButton( buttonsFrame );
00155   rotate90Image->setTextLabel(tr("Rotate 90") );
00156   rotate90Image->setIconSet( QPixmap(QString(IMAGE_PATH)+"rotate90.png") );
00157   rotate90Image->setTextPosition(QToolButton::Right);
00158   rotate90Image->setFont( buttonFont );
00159   rotate90Image->setUsesTextLabel( true );
00160   QToolTip::add( rotate90Image, tr("Rotate selected photos clockwise 90 degrees") );
00161   connect( rotate90Image, SIGNAL(clicked()), SLOT(rotate90ImageAction()) );
00162     
00163   rotate270Image = new QToolButton( buttonsFrame );
00164   rotate270Image->setTextLabel(tr("Rotate 270") );
00165   rotate270Image->setIconSet( QPixmap(QString(IMAGE_PATH)+"rotate270.png") );
00166   rotate270Image->setTextPosition(QToolButton::Right);
00167   rotate270Image->setFont( buttonFont );
00168   rotate270Image->setUsesTextLabel( true );
00169   QToolTip::add( rotate270Image, tr("Rotate selected photos counterclockwise 90 degrees") );
00170   connect( rotate270Image, SIGNAL(clicked()), SLOT(rotate270ImageAction()) );
00171 
00172   flipHorizontallyImage = new QToolButton( buttonsFrame );
00173   flipHorizontallyImage->setTextLabel(tr("Flip Horiz.") );
00174   flipHorizontallyImage->setIconSet( QPixmap(QString(IMAGE_PATH)+"flipHorizontally.png") );
00175   flipHorizontallyImage->setTextPosition(QToolButton::Right);
00176   flipHorizontallyImage->setFont( buttonFont );
00177   flipHorizontallyImage->setUsesTextLabel( true );
00178   QToolTip::add( flipHorizontallyImage, tr("Flip selected photos horizontally") );
00179   connect( flipHorizontallyImage, SIGNAL(clicked()), SLOT(flipHorizontallyImageAction()) );
00180   
00181   flipVerticallyImage = new QToolButton( buttonsFrame );
00182   flipVerticallyImage->setTextLabel(tr("Flip Vert.") );
00183   flipVerticallyImage->setIconSet( QPixmap(QString(IMAGE_PATH)+"flipVertically.png") );
00184   flipVerticallyImage->setTextPosition(QToolButton::Right);
00185   flipVerticallyImage->setFont( buttonFont );
00186   flipVerticallyImage->setUsesTextLabel( true );
00187   QToolTip::add( flipVerticallyImage, tr("Flip selected photos vertically") );
00188   connect( flipVerticallyImage, SIGNAL(clicked()), SLOT(flipVerticallyImageAction()) );
00189     
00190   editButton = new QToolButton( buttonsFrame );
00191   editButton->setTextLabel(tr("Edit") );
00192   editButton->setIconSet( QPixmap(QString(IMAGE_PATH)+"editPhoto.png") );
00193   editButton->setTextPosition(QToolButton::Right);
00194   editButton->setFont( buttonFont );
00195   editButton->setUsesTextLabel( true );
00196   QToolTip::add( editButton, tr("Edit selected photo") );
00197   connect( editButton, SIGNAL(clicked()), SLOT(editAction()) );
00198     
00199   //place all items in grid layout
00200   annotationGrid = new QGridLayout( annotationsFrame, 4, 5, 0 );
00201   annotationGrid->addWidget( subalbumName,                1, 0, Qt::AlignLeft );
00202   annotationGrid->addWidget( subalbumNameVal,             1, 1 );
00203   annotationGrid->addWidget( subalbumDescription,         2, 0, Qt::AlignLeft );
00204   annotationGrid->addWidget( subalbumDescriptionVal,      2, 1 );
00205   annotationGrid->addWidget( representativeImageText,     1, 3, Qt::AlignLeft );
00206   annotationGrid->addMultiCellWidget( setImage,           2, 2, 3, 3 );
00207   annotationGrid->addMultiCellWidget( representativeLogo, 0, 3, 4, 4 );
00208   annotationGrid->setRowStretch( 0, 1 );
00209   annotationGrid->setRowStretch( 3, 1 );
00210   annotationGrid->addColSpacing( 1, 300 );
00211   annotationGrid->addColSpacing( 2, 10 );
00212   
00213   buttonsGrid = new QGridLayout( buttonsFrame,             1, 9, 0 );
00214   buttonsGrid->addWidget( addImage,                   0, 1, Qt::AlignLeft );
00215   buttonsGrid->addWidget( removeImage,                0, 2, Qt::AlignLeft );
00216   buttonsGrid->addWidget( rotate90Image,              0, 3, Qt::AlignLeft );
00217   buttonsGrid->addWidget( rotate270Image,             0, 4, Qt::AlignLeft );
00218   buttonsGrid->addWidget( flipHorizontallyImage,      0, 5, Qt::AlignLeft );
00219   buttonsGrid->addWidget( flipVerticallyImage,        0, 6, Qt::AlignLeft );
00220   buttonsGrid->addWidget( editButton,                 0, 7, Qt::AlignLeft );
00221   buttonsGrid->setColStretch( 0, 1 );
00222   buttonsGrid->setColStretch( 8, 1 );
00223   
00224   mainGrid = new QGridLayout( this, 1, 3, 0 );
00225   mainGrid->addWidget( annotationsFrame, 0, 0 );
00226   mainGrid->addWidget( photos, 1, 0 );
00227   mainGrid->addWidget( buttonsFrame, 2, 0 );
00228   mainGrid->setRowStretch( 1, 1 );
00229    
00230   //set the background of the widget to be white
00231   setPaletteBackgroundColor( QColor(255, 255, 255) );
00232   
00233   //by default no selected images so disable all buttons besides add
00234   removeImage->setEnabled(false);  
00235   rotate90Image->setEnabled(false);  
00236   rotate270Image->setEnabled(false);  
00237   flipHorizontallyImage->setEnabled(false);  
00238   flipVerticallyImage->setEnabled(false);  
00239   editButton->setEnabled(false);  
00240 }
00241 //==============================================
00242 void SubalbumWidget::setSubalbum(Subalbum* salbum)
00243 {
00244   //set new subalbum pointer
00245   subalbum = salbum;
00246   
00247   //update representative image, subalbum name and description
00248   subalbumNameVal->setText(  subalbum->getName() );
00249   subalbumDescriptionVal->setText(  subalbum->getDescription() );
00250   representativeLogo->setPixmap( *subalbum->getRepresentativeImage(SMALL) );
00251   
00252   //update photo listing
00253   refreshPhotos();
00254   
00255   //disable/enable buttons as necessary
00256   updateButtons();
00257 }
00258 //==============================================
00259 //called when user clicks "set image" button
00260 void SubalbumWidget::setImageAction()
00261 {
00262   //---------------------------------------------------------    
00263   //get handle on photo widget
00264   Photo* selectedPhoto = getSelectedPhoto();
00265   if(selectedPhoto == NULL)
00266     return;
00267   //---------------------------------------------------------    
00268   //set representative images
00269   subalbum->setRepresentativeImages( selectedPhoto->getImage(THUMBNAIL) );
00270   //---------------------------------------------------------    
00271   //update onscreen images
00272   representativeLogo->setPixmap( *(subalbum->getRepresentativeImage(SMALL)) );
00273   layout->updateSubalbumImage( subalbum->getRepresentativeImage(MEDIUM) );
00274   //---------------------------------------------------------    
00275 }
00276 //==============================================
00277 void SubalbumWidget::updateName( const QString& val )
00278 {
00279   subalbum->setName(val);
00280   layout->updateSubalbumName(val);
00281 }
00282 //==============================================
00283 void SubalbumWidget::updateDescription( const QString& val )
00284 {
00285   subalbum->setDescription(val);
00286 }
00287 //==============================================
00288 void SubalbumWidget::addImageAction()
00289 {
00290   //set busy flag and deactivate menu's/buttons, and selecting photos
00291   layout->getWindow()->getTitle()->setBusy(true);
00292   layout->getSubalbums()->updateButtons(false);
00293   updateButtons(false);
00294   photos->setSelectionMode( QIconView::NoSelection ) ;
00295     
00296   //Get filename from user  
00297   QStringList fileNames = QFileDialog::getOpenFileNames(tr("Images (*.gif *.jpg *.jpeg *.png *.xpm *.GIF *.JPG *.JPEG *.PNG *.XPM)"),
00298                                                         NULL,
00299                                                         this,
00300                                                         "add photos dialog",
00301                                                         tr("Select photos"));
00302                                                               
00303   qApp->setOverrideCursor( QCursor(Qt::WaitCursor));
00304   
00305   //setup progress bar
00306   layout->getWindow()->getStatus()->showProgressBar( tr("Adding photos:"), fileNames.count() );
00307   qApp->processEvents();
00308   
00309   //iterate through each file and add to album
00310   QStringList::iterator it;
00311   int num=0;
00312   for(it = fileNames.begin(); it != fileNames.end(); it++ )
00313   {
00314     //if successful adding photo add widget
00315     if(subalbum->addPhoto(*it, false))
00316     {  
00317       PhotoWidget* p =  new PhotoWidget( photos, subalbum->getLast() );
00318       p->setRenameEnabled(true);
00319       photos->ensureItemVisible(p);
00320     }
00321     num++;
00322     layout->getWindow()->getStatus()->updateProgress( num );
00323     qApp->processEvents();
00324   }
00325   photos->arrangeItemsInGrid();
00326   
00327   //remove progress bar
00328   layout->getWindow()->getStatus()->setStatus( tr("Adding photos complete.") );
00329   
00330   //unset busy flag and activate menu's/buttons
00331   layout->getWindow()->getTitle()->setBusy(false);
00332   layout->getSubalbums()->updateButtons(true);
00333   updateButtons(true);
00334   photos->setSelectionMode( QIconView::Extended ) ;
00335   qApp->restoreOverrideCursor();
00336 }
00337 //==============================================
00338 void SubalbumWidget::removeImageAction()
00339 {
00340   //set busy flag and deactivate menu's/buttons
00341   layout->getWindow()->getTitle()->setBusy(true);
00342   layout->getSubalbums()->updateButtons(false);
00343   updateButtons(false);
00344   photos->setSelectionMode( QIconView::NoSelection ) ;
00345   
00346   //check if user is sure
00347   QuestionDialog sure( tr("Remove selected photos?"),
00348                        tr("Once removed photos cannot be restored. Furthermore apon resaving they are physically removed from your album."),
00349                        "warning.png",
00350                        this );    
00351   //if user say yes then delete subalbum and refresh
00352   if(sure.exec())  
00353   {
00354     qApp->setOverrideCursor( QCursor(Qt::WaitCursor));
00355     //iterate through all photos and remove those that are selected
00356     QIconViewItem* current = photos->firstItem();
00357     QIconViewItem* temp;
00358     while(current != NULL)
00359     {
00360       //if not selected move on
00361       if(!current->isSelected())
00362       {
00363         current = current->nextItem();
00364         continue;
00365       }
00366       
00367       //get next pointer  
00368       temp = current->nextItem();
00369     
00370       //grab point to backend photo
00371       Photo* phto = ((PhotoWidget*)current)->getPhoto();
00372     
00373       //delete photo widget
00374       delete current;
00375       current = temp;
00376     
00377       //delete backend photo
00378       subalbum->removePhoto(phto); 
00379       
00380       //check if any photos selected, if not deactivate all buttons besides add button
00381       updateButtons();
00382     }
00383   
00384     photos->arrangeItemsInGrid();
00385   
00386     //unset busy flag and activate menu's/buttons
00387     qApp->restoreOverrideCursor();
00388   }
00389     
00390   layout->getWindow()->getTitle()->setBusy(false);
00391   layout->getSubalbums()->updateButtons(true);
00392   updateButtons(true);
00393   photos->setSelectionMode( QIconView::Extended ) ;
00394 }
00395 //==============================================
00396 void SubalbumWidget::rotate90ImageAction()
00397 {
00398   //set busy flag and deactivate menu's/buttons
00399   qApp->setOverrideCursor( QCursor(Qt::WaitCursor));
00400   layout->getWindow()->getTitle()->setBusy(true);
00401   layout->getSubalbums()->updateButtons(false);
00402   photos->setSelectionMode( QIconView::NoSelection ) ;
00403   updateButtons(false);
00404   
00405   //setup progress bar
00406   layout->getWindow()->getStatus()->showProgressBar( tr("Rotating images 90 degrees:"), photos->numSelected() );
00407   qApp->processEvents();
00408     
00409   //rotate the selected photos
00410   int num = 0;
00411   QIconViewItem* current = photos->firstItem();
00412   while(current != NULL)
00413   {
00414     if(current->isSelected())
00415     {
00416       ((PhotoWidget*)current)->getPhoto()->rotate90();
00417       photos->ensureItemVisible(((PhotoWidget*)current));
00418       ((PhotoWidget*)current)->updateImage();
00419       num++; 
00420       layout->getWindow()->getStatus()->updateProgress( num );
00421       qApp->processEvents();
00422     }
00423     
00424     //move to next item
00425     current = current->nextItem();
00426   }
00427 
00428   //hide progress bar
00429   layout->getWindow()->getStatus()->setStatus( tr("Rotation complete.") );
00430     
00431   //not busy any more
00432   layout->getWindow()->getTitle()->setBusy(false);
00433   layout->getSubalbums()->updateButtons(true);
00434   updateButtons(true);
00435   photos->setSelectionMode( QIconView::Extended ) ;
00436   qApp->restoreOverrideCursor();
00437 }
00438 //==============================================
00439 void SubalbumWidget::rotate270ImageAction()
00440 {
00441   //set busy flag and deactivate menu's/buttons
00442   qApp->setOverrideCursor( QCursor(Qt::WaitCursor));
00443   layout->getWindow()->getTitle()->setBusy(true);
00444   layout->getSubalbums()->updateButtons(false);
00445   photos->setSelectionMode( QIconView::NoSelection ) ;
00446   updateButtons(false);
00447   
00448   //setup progress bar
00449   layout->getWindow()->getStatus()->showProgressBar( tr("Rotating images 270 degrees:"), photos->numSelected() );
00450   qApp->processEvents();
00451   
00452   //rotate the selected photos
00453   int num = 0;
00454   QIconViewItem* current = photos->firstItem();
00455   while(current != NULL)
00456   {
00457     if(current->isSelected())
00458     {
00459       ((PhotoWidget*)current)->getPhoto()->rotate270();
00460       photos->ensureItemVisible(((PhotoWidget*)current));
00461       ((PhotoWidget*)current)->updateImage();
00462       num++;
00463       layout->getWindow()->getStatus()->updateProgress( num );
00464       qApp->processEvents();
00465     }
00466     
00467     //move to next item
00468     current = current->nextItem();
00469   }
00470   
00471   //hide progress bar
00472   layout->getWindow()->getStatus()->setStatus( tr("Rotation complete.") );
00473   
00474   //not busy any more
00475   layout->getWindow()->getTitle()->setBusy(false);
00476   layout->getSubalbums()->updateButtons(true);
00477   updateButtons(true);
00478   photos->setSelectionMode( QIconView::Extended ) ;
00479   qApp->restoreOverrideCursor();
00480 }
00481 //==============================================
00482 void SubalbumWidget::flipHorizontallyImageAction()
00483 {
00484   //set busy flag and deactivate menu's/buttons
00485   qApp->setOverrideCursor( QCursor(Qt::WaitCursor));
00486   layout->getWindow()->getTitle()->setBusy(true);
00487   layout->getSubalbums()->updateButtons(false);
00488   photos->setSelectionMode( QIconView::NoSelection ) ;
00489   updateButtons(false);
00490   
00491   //setup progress bar
00492   layout->getWindow()->getStatus()->showProgressBar( tr("Flipping images horizontally:"), photos->numSelected() );
00493   qApp->processEvents();
00494   
00495   //flip the selected photos
00496   int num = 0;
00497   QIconViewItem* current = photos->firstItem();
00498   while(current != NULL)
00499   {
00500     if(current->isSelected())
00501     {
00502       ((PhotoWidget*)current)->getPhoto()->flipHorizontally();
00503       photos->ensureItemVisible(((PhotoWidget*)current));
00504       ((PhotoWidget*)current)->updateImage();
00505       num++;
00506       layout->getWindow()->getStatus()->updateProgress( num );
00507       qApp->processEvents();
00508     }
00509     
00510     //move to next item
00511     current = current->nextItem();
00512   }
00513   
00514   //hide progress bar
00515   layout->getWindow()->getStatus()->setStatus( tr("Flipping complete.") );
00516   
00517   //not busy any more
00518   layout->getWindow()->getTitle()->setBusy(false);
00519   layout->getSubalbums()->updateButtons(true);
00520   updateButtons(true);
00521   photos->setSelectionMode( QIconView::Extended ) ;
00522   qApp->restoreOverrideCursor();
00523 }
00524 //==============================================
00525 void SubalbumWidget::flipVerticallyImageAction()
00526 {
00527   //set busy flag and deactivate menu's/buttons
00528   qApp->setOverrideCursor( QCursor(Qt::WaitCursor));
00529   layout->getWindow()->getTitle()->setBusy(true);
00530   layout->getSubalbums()->updateButtons(false);
00531   photos->setSelectionMode( QIconView::NoSelection ) ;
00532   updateButtons(false);
00533   
00534   //setup progress bar
00535   layout->getWindow()->getStatus()->showProgressBar( tr("Flipping images vertically:"), photos->numSelected() );
00536   qApp->processEvents();
00537   
00538   //flip the selected photos
00539   int num = 0;
00540   QIconViewItem* current = photos->firstItem();
00541   while(current != NULL)
00542   {
00543     if(current->isSelected())
00544     {
00545       ((PhotoWidget*)current)->getPhoto()->flipVertically();
00546       photos->ensureItemVisible(((PhotoWidget*)current));
00547       ((PhotoWidget*)current)->updateImage();
00548       num++;
00549       layout->getWindow()->getStatus()->updateProgress( num );
00550       qApp->processEvents();
00551     }
00552     
00553     //move to next item
00554     current = current->nextItem();
00555   }
00556   
00557   //hide progress bar
00558   layout->getWindow()->getStatus()->setStatus( tr("Flipping complete.") );
00559   
00560   //not busy any more
00561   layout->getWindow()->getTitle()->setBusy(false);
00562   layout->getSubalbums()->updateButtons(true);
00563   updateButtons(true);
00564   photos->setSelectionMode( QIconView::Extended ) ;
00565   qApp->restoreOverrideCursor();
00566 }
00567 //==============================================
00568 void SubalbumWidget::editAction()
00569 {
00570   Photo* selected = getSelectedPhoto();
00571   if(selected != NULL)
00572     layout->editPhoto( selected );
00573   else
00574   {
00575     //bring up dialog scolding user for trying to edit either no or multiple photos at once
00576   }
00577 }
00578 //==============================================
00579 void SubalbumWidget::refreshPhotos()
00580 {
00581   //remove all thumbnails
00582   photos->clear();
00583 
00584   //insert photo thumbnails
00585   Photo* currentPhoto = subalbum->getFirst();
00586   while(currentPhoto != NULL)
00587   {
00588     PhotoWidget* p = new PhotoWidget( photos, currentPhoto );
00589     p->setRenameEnabled(true);
00590     currentPhoto = currentPhoto->getNext();
00591   }
00592   
00593   photos->arrangeItemsInGrid();
00594 }
00595 //==============================================
00596 void SubalbumWidget::refreshSelectedPhotos()
00597 {
00598   QIconViewItem* current = photos->firstItem();
00599   while(current != NULL)
00600   {
00601     //found a selected item!
00602     if(current->isSelected())
00603     {
00604       ((PhotoWidget*)current)->updateImage();
00605       ((PhotoWidget*)current)->updateDescription();
00606     }
00607     
00608     //move to next item
00609     current = current->nextItem();
00610   }
00611 }
00612 //==============================================
00613 void SubalbumWidget::syncPhotos()
00614 {
00615   PhotoWidget* current = (PhotoWidget*)photos->firstItem(); 
00616   while(current != NULL)
00617   {
00618     current->sync();
00619     current = (PhotoWidget*)current->nextItem();  
00620   }
00621 }
00622 //==============================================
00623 Subalbum* SubalbumWidget::getSubalbum()
00624 {
00625   return subalbum;
00626 }
00627 //==============================================
00628 Photo* SubalbumWidget::getSelectedPhoto()
00629 {
00630   //determine if one photo is selected
00631   int numSelected = 0;
00632   QIconViewItem* current = photos->firstItem();
00633   QIconViewItem* selected = NULL;
00634   while(current != NULL)
00635   {
00636     //found a selected item!
00637     if(current->isSelected())
00638     {
00639       numSelected++;
00640       selected = current;
00641     }
00642     
00643     //if more than one found then bail!
00644     if(numSelected > 1)
00645       break;
00646     
00647     //move to next item
00648     current = current->nextItem();
00649   }
00650   
00651   //if one item is selected then return photo pointer
00652   if(numSelected == 1)
00653   {
00654     return ((PhotoWidget*)selected)->getPhoto();
00655   }
00656   else
00657   {
00658     return NULL;
00659   }
00660 }
00661 //==============================================
00662 void SubalbumWidget::resizeEvent( QResizeEvent * )
00663 {
00664   photos->arrangeItemsInGrid();  
00665 }
00666 //==============================================
00667 QIconView* SubalbumWidget::getPhotos()
00668 {
00669   return photos;
00670 }
00671 //==============================================
00672 void SubalbumWidget::rearrangeAndSaveCurrent(QIconViewItem* item)
00673 {
00674   ((PhotoWidget*)item)->sync();
00675   photos->arrangeItemsInGrid();  
00676 }
00677 //==============================================
00678 void SubalbumWidget::reorder()
00679 {
00680   //so item has been moved, reorder linked list of items as necessary
00681   photos->sort( true );
00682   photos->arrangeItemsInGrid();
00683     
00684   //sync lists
00685   subalbum->syncPhotoList((PhotoWidget*)photos->firstItem());
00686 }
00687 //==============================================
00688 void SubalbumWidget::updateButtons()
00689 {
00690   bool anySelected = false;
00691   QIconViewItem* current = photos->firstItem();
00692   while(current != NULL)
00693   {
00694     if(current->isSelected())
00695     {
00696      anySelected = true;
00697      break;
00698     }
00699     
00700     //move to next item
00701     current = current->nextItem();
00702   }
00703 
00704   if(!anySelected)
00705   {
00706     removeImage->setEnabled(false);  
00707     rotate90Image->setEnabled(false);  
00708     rotate270Image->setEnabled(false);  
00709     flipHorizontallyImage->setEnabled(false);  
00710     flipVerticallyImage->setEnabled(false);  
00711     editButton->setEnabled(false);  
00712     layout->getWindow()->getTitle()->setSetButtonState(false);
00713     setImage->setEnabled(false);
00714   }
00715   else
00716   {
00717     removeImage->setEnabled(true);  
00718     rotate90Image->setEnabled(true);  
00719     rotate270Image->setEnabled(true);  
00720     flipHorizontallyImage->setEnabled(true);  
00721     flipVerticallyImage->setEnabled(true);  
00722     editButton->setEnabled(true);  
00723     layout->getWindow()->getTitle()->setSetButtonState(true);
00724     setImage->setEnabled(true);
00725   }
00726 }
00727 //==============================================
00728 void SubalbumWidget::updateButtons(bool enable)
00729 {
00730   if(!enable)
00731   {
00732     buttonsState = rotate90Image->isEnabled();
00733     addImage->setEnabled(enable);
00734     removeImage->setEnabled(enable);  
00735     rotate90Image->setEnabled(enable);  
00736     rotate270Image->setEnabled(enable);  
00737     flipHorizontallyImage->setEnabled(enable);  
00738     flipVerticallyImage->setEnabled(enable);  
00739     editButton->setEnabled(enable);  
00740     setImage->setEnabled(enable);
00741   }
00742   else
00743   {
00744     addImage->setEnabled(enable);
00745     removeImage->setEnabled(buttonsState);  
00746     rotate90Image->setEnabled(buttonsState);  
00747     rotate270Image->setEnabled(buttonsState);  
00748     flipHorizontallyImage->setEnabled(buttonsState);  
00749     flipVerticallyImage->setEnabled(buttonsState);  
00750     editButton->setEnabled(buttonsState);  
00751     setImage->setEnabled(buttonsState);
00752   }
00753 }
00754 //==============================================
00755 
00756 

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