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

subalbumsWidget.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 <qwidget.h>
00019 #include <qlayout.h>
00020 #include <qlabel.h>
00021 #include <qfont.h>
00022 #include <qpixmap.h>
00023 #include <qapplication.h>
00024 #include <qtoolbutton.h>
00025 #include <qtooltip.h>
00026 
00027 //Projectwide includes
00028 #include "subalbumsWidget.h"
00029 #include "subalbumPreviewWidget.h"
00030 #include "subalbumsIconView.h"
00031 #include "questionDialog.h"
00032 #include "layoutWidget.h"
00033 #include "window.h"
00034 #include "titleWidget.h"
00035 #include "../backend/album.h"
00036 #include "../backend/subalbum.h"
00037 #include "../config.h"
00038 
00039 //==============================================
00040 SubalbumsWidget::SubalbumsWidget(QWidget *parent, 
00041                                  const char* name ) : 
00042                                  QWidget(parent,name)
00043 {
00044   //set layout pointer
00045   layout = (LayoutWidget*)parent;
00046 
00047   //create subalbums text
00048   subalbumsText = new QLabel( this );
00049   subalbumsText->setText( tr("Subalbums: ") );
00050   subalbumsText->setFont( QFont( "Times", 12, QFont::Bold ) );
00051 
00052   //create subalbums iconview
00053   subalbums = new SubalbumsIconView( this );
00054   
00055   //establish a top-down view such that the scrollbar is always placed on the right
00056   subalbums->setArrangement( QIconView::LeftToRight );
00057   subalbums->setVScrollBarMode( QScrollView::AlwaysOn );
00058 
00059   //only allow one subalbum to be selected at a time
00060   subalbums->setSelectionMode( QIconView::Single ) ;
00061 
00062   //set auto-scroll off for drag-n-drop
00063   subalbums->setDragAutoScroll(true);
00064   subalbums->setAcceptDrops(true);
00065 
00066   //connect drop event on iconview to reorder slot
00067   connect( subalbums, SIGNAL(itemHasMoved()), SLOT(reorder()) );  
00068 
00069   //connect selectionChanged signal to updateSubalbumLayout method
00070   connect( subalbums, SIGNAL(selectionChanged(QIconViewItem*)),
00071            SLOT(updateSubalbumLayout(QIconViewItem*)) );
00072 
00073   //connect rightButtonClicked signal to updateSubalbumLayout method
00074   connect( subalbums, SIGNAL(rightButtonClicked(QIconViewItem*, const QPoint&)),
00075            SLOT(updateSubalbumLayout(QIconViewItem*)) );
00076            
00077   //create create/delete buttons  
00078   QFont buttonFont( qApp->font() );
00079   buttonFont.setBold(true);
00080   buttonFont.setPointSize( 11 );
00081   
00082   createSubalbum = new QToolButton( this );
00083   createSubalbum->setTextLabel(tr("Create"));
00084   createSubalbum->setIconSet( QPixmap(QString(IMAGE_PATH)+"create.png") );
00085   createSubalbum->setTextPosition(QToolButton::Right);
00086   createSubalbum->setFont( buttonFont );
00087   createSubalbum->setUsesTextLabel( true );
00088   QToolTip::add( createSubalbum, tr("Create a subalbum and append to subalbum list") );
00089   connect( createSubalbum, SIGNAL(clicked()), SLOT(createAction()) );
00090                                 
00091   deleteSubalbum = new QToolButton( this );
00092   deleteSubalbum->setTextLabel(tr("Delete"));
00093   deleteSubalbum->setIconSet( QPixmap(QString(IMAGE_PATH)+"delete.png") );
00094   deleteSubalbum->setTextPosition(QToolButton::Right);
00095   deleteSubalbum->setFont( buttonFont );
00096   deleteSubalbum->setUsesTextLabel( true );
00097   deleteSubalbum->setEnabled(false);
00098   QToolTip::add( deleteSubalbum, tr("Delete selected subalbum and all conents") );
00099   connect( deleteSubalbum, SIGNAL(clicked()), SLOT(deleteAction()) );
00100   
00101   //place label, listbox, and buttons in grid
00102   grid = new QGridLayout( this, 3, 5, 0 );
00103   grid->addMultiCellWidget( subalbumsText, 0, 0, 0, 4 );
00104   grid->addMultiCellWidget( subalbums, 1, 1, 0, 4 );
00105   grid->addWidget( createSubalbum, 2, 1);
00106   grid->addWidget( deleteSubalbum, 2, 3);
00107 
00108   grid->setColStretch( 0, 1 );
00109   grid->setColStretch( 2, 1 );
00110   grid->setColStretch( 4, 1 );
00111   
00112   //set listbox to grow
00113   grid->setRowStretch( 1, 1 );
00114 
00115   //set the background of the widget to be white
00116   setPaletteBackgroundColor( QColor(255, 255, 255) );
00117 }
00118 //==============================================
00119 void SubalbumsWidget::createAction()
00120 {
00121   Subalbum* n = new Subalbum(layout->getWindow()->getTitle()->getAlbum(),
00122                                              layout->getWindow()->getTitle()->getAlbum()->getNumSubalbums()+1);
00123   SubalbumPreviewWidget* p = new SubalbumPreviewWidget( subalbums, n );
00124   p->setDropEnabled(true);
00125    
00126   layout->getWindow()->getTitle()->getAlbum()->appendSubalbum( n );
00127 }
00128 //==============================================
00129 void SubalbumsWidget::deleteAction()
00130 {
00131   //if an item is selected it remove it
00132   if(subalbums->currentItem() != NULL)
00133   { 
00134     //check if user is sure
00135     QuestionDialog sure( tr("Delete subalbum?"),
00136                          tr("Once deleted a subalbum and it's contents cannot be brought back unless a saved copy of the album exists."),
00137                          "warning.png",
00138                          this );
00139     //if user say yes then delete subalbum and refresh
00140     if(sure.exec())  
00141     {
00142       //delete the subalbum
00143       Subalbum* s = ((SubalbumPreviewWidget*) subalbums->currentItem())->getSubalbum();
00144       delete subalbums->currentItem();
00145 
00146       //remove subalbum from backend album object
00147       layout->getWindow()->getTitle()->getAlbum()->removeSubalbum( s );
00148       
00149       //rearrange the items in the grid
00150       subalbums->arrangeItemsInGrid();
00151       
00152       //update which subalbum is shown in the layout area
00153       updateSubalbumLayout(subalbums->firstItem(), false);
00154       
00155       //check if any subalbums selected, if not deactivate delete button
00156       if(subalbums->currentItem() == NULL || !subalbums->currentItem()->isSelected())
00157       {
00158           deleteSubalbum->setEnabled(false);
00159       }
00160       
00161       //no images themselves selected so disable set button
00162       layout->getWindow()->getTitle()->setSetButtonState(false);
00163     }
00164   }
00165 }
00166 //==============================================
00167 void SubalbumsWidget::updateSubalbumLayout( QIconViewItem* selection)
00168 {
00169   //if application busy ignore action
00170   if(layout->getWindow()->getTitle()->getBusy())
00171   {
00172     return;
00173   }
00174   
00175   //activate/disable delete button depending on if something is currently selected or not
00176   if(selection == NULL)
00177     deleteSubalbum->setEnabled(false);
00178   else
00179     deleteSubalbum->setEnabled(true);
00180 
00181   updateSubalbumLayout(selection, true);
00182 }
00183 //==============================================
00184 void SubalbumsWidget::updateSubalbumLayout( QIconViewItem* selection, bool oldExists)
00185 {
00186   //hide photo edit dialog in case we were just editing a photo
00187   layout->stopEdit(oldExists);
00188 
00189   if(selection == NULL)
00190     layout->updateSubalbum( NULL, oldExists );
00191   else
00192   {
00193     layout->updateSubalbum(((SubalbumPreviewWidget*)selection)->getSubalbum(), oldExists);
00194   }
00195 }
00196 //==============================================
00197 void SubalbumsWidget::updateSubalbumName(const QString& val)
00198 {
00199   //if an item is selected
00200   if(subalbums->currentItem() != NULL)
00201   { 
00202     subalbums->currentItem()->setText(val);
00203   }
00204   subalbums->arrangeItemsInGrid();
00205 }
00206 //==============================================
00207 void SubalbumsWidget::updateSubalbumThumbnail( QPixmap* val)
00208 {
00209   //if an item is selected
00210   if(subalbums->currentItem() != NULL)
00211   { 
00212     subalbums->currentItem()->setPixmap( *val );
00213   }
00214   subalbums->arrangeItemsInGrid();
00215 }
00216 //==============================================
00217 void SubalbumsWidget::reorder()
00218 {
00219   //so item has been moved, reorder linked list of items as necessary
00220   subalbums->sort( true );
00221   subalbums->arrangeItemsInGrid();
00222   
00223   //get handle on backend album object
00224   Album* albm = layout->getWindow()->getTitle()->getAlbum();
00225   
00226   //sync lists
00227   albm->syncSubalbumList((SubalbumPreviewWidget*)subalbums->firstItem());
00228 }
00229 //==============================================
00230 void SubalbumsWidget::refresh()
00231 {
00232   //delete all previous entries
00233   QIconViewItem* current = subalbums->firstItem();
00234   QIconViewItem* temp;
00235   while(current != NULL)
00236   {
00237     //get next pointer  
00238     temp = current->nextItem();
00239     
00240     //delete widget
00241     delete current;
00242     current = temp;
00243   }
00244 
00245   //insert all new subalums
00246   Subalbum* curSubalbum = layout->getWindow()->getTitle()->getAlbum()->getFirstSubalbum();
00247   while( curSubalbum != NULL)
00248   {
00249     (void) new SubalbumPreviewWidget( subalbums, curSubalbum );
00250     curSubalbum = curSubalbum->getNext();
00251   }
00252   
00253   //refresh layout
00254   subalbums->arrangeItemsInGrid();
00255   updateSubalbumLayout( subalbums->firstItem(), false );
00256   
00257   //auto select first item
00258   if(subalbums->firstItem() != NULL)
00259     subalbums->setSelected( subalbums->firstItem(), true);
00260 }
00261 //==============================================
00262 LayoutWidget* SubalbumsWidget::getParent()
00263 {
00264   return layout;
00265 }
00266 //==============================================
00267 void SubalbumsWidget::updateButtons(bool enable)
00268 {
00269   if(!enable)
00270   {
00271     buttonsState = createSubalbum->isEnabled();
00272     createSubalbum->setEnabled(enable);
00273     deleteSubalbum->setEnabled(enable);  
00274   }
00275   else
00276   {
00277     createSubalbum->setEnabled(enable);
00278     deleteSubalbum->setEnabled(buttonsState);  
00279   }
00280 }
00281 //==============================================

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