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

window.cpp

Go to the documentation of this file.
00001 //==============================================
00002 //  copyright            : (C) 2003-2005 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 
00011 //Systemwide includes
00012 #include <qframe.h>
00013 #include <qlayout.h>
00014 #include <qpixmap.h>
00015 #include <qtooltip.h>
00016 #include <qdir.h>
00017 #include <qapplication.h>
00018 #include <qiconview.h>
00019 
00020 //PLATFORM_SPECIFIC_CODE
00021 #if defined(Q_OS_MACX)
00022 #include "/Developer/Headers/FlatCarbon/Carbon.h"
00023 #endif
00024 
00025 //Projectwide includes
00026 #include "window.h"
00027 #include "titleWidget.h"
00028 #include "layoutWidget.h"
00029 #include "statusWidget.h"
00030 #include "subalbumsWidget.h"
00031 #include "subalbumWidget.h"
00032 #include "dialogs/questionDialog.h"
00033 #include "dialogs/alertDialog.h"
00034 
00035 //#include "presentation/presentationWidget.h"
00036 #include "../config.h"
00037 #include "../backend/album.h"
00038 #include "../backend/subalbum.h"
00039 #include "../backend/photo.h"
00040 #include "../backend/recentAlbums.h"
00041 #include "../configuration/configuration.h"
00042 #include "../configuration/loadingSavingWidget.h"
00043 #include "../configuration/layoutSettingsWidget.h"
00044 #include "../configuration/alertsWidget.h"
00045 #include "../configuration/miscSettings.h"
00046 
00047 //==============================================
00048 Window::Window( QWidget* parent, const char* name ) : QWidget(parent,name)
00049 {
00050   //don't clear pixmap area before painting, prevents flicker
00051   setWFlags(WRepaintNoErase);
00052 
00053   //load shadow pixmaps
00054   shadowBL = new QPixmap( QString(IMAGE_PATH)+"miscImages/photoGradientBottomLeft.png" );
00055   shadowB = new QPixmap( QString(IMAGE_PATH)+"miscImages/photoGradientBottom.png" );
00056   shadowBR = new QPixmap( QString(IMAGE_PATH)+"miscImages/photoGradientBottomRight.png" );
00057   shadowR = new QPixmap( QString(IMAGE_PATH)+"miscImages/photoGradientRight.png" );
00058   shadowTR = new QPixmap( QString(IMAGE_PATH)+"miscImages/photoGradientTopRight.png" );
00059 
00060   //load photo info pixmap
00061   photoInfo = new QPixmap( QString(IMAGE_PATH)+"buttonIcons/photoInfo.png");
00062 
00063   //------------------------------------------------
00064   //create configuration object with default settings
00065   config = new Configuration();
00066   LoadingSavingWidget::setDefaults(config);
00067   LayoutSettingsWidget::setDefaults(config);
00068   AlertsWidget::setDefaults(config);
00069   MiscSettings::setDefaults(config);
00070   //------------------------------------------------
00071   //load user settings
00072   config->loadSettings();
00073 
00074   //if temorary image directory does not exist create it
00075   QDir homeDir;
00076   bool configDirMade = true;
00077   if(!homeDir.exists( config->getString( "loadSave", "tempImageDirectory")) )
00078   { configDirMade = homeDir.mkdir( config->getString( "loadSave", "tempImageDirectory")); }
00079   //if directory could not be made attempt to revert to default directory
00080   if(!configDirMade)
00081   {
00082     AlertDialog alert( "unable to create temp dir", QString("unable to make temporary directory! (" + config->getString( "loadSave", "tempImageDirectory") ),
00083   "alertIcons/warning.png", this );
00084   alert.exec();
00085 
00086 
00087     config->resetSetting( "loadSave", "tempImageDirectory" );
00088     configDirMade = true;
00089     if(!homeDir.exists( config->getString( "loadSave", "tempImageDirectory")) )
00090     { configDirMade = homeDir.mkdir( config->getString( "loadSave", "tempImageDirectory")); }
00091   }
00092 
00093   //if we are still unable to create the temporary image directory then immediately abort
00094   if(!configDirMade)
00095   {
00096       AlertDialog alert( "unable to create temp dir", QString("unable to make temporary directory! (" + config->getString( "loadSave", "tempImageDirectory") ),
00097   "alertIcons/warning.png", this );
00098   alert.exec();
00099 
00100 close();
00101   }
00102 
00103   //------------------------------------------------
00104   //create top level widgets
00105   title  = new TitleWidget (this, "title");
00106   layout = new LayoutWidget(this, "layout");
00107   status = new StatusWidget(this, "status");
00108 
00110   connect( layout, SIGNAL(collectionSelected(Subalbum*)),
00111            title,  SLOT(refreshCollectionAnnotations(Subalbum*)) );
00112 
00114   connect( title,  SIGNAL(subalbumNameChanged()),
00115            layout, SLOT(refreshSelectedCollectionIconName()) );
00116   
00117 //  slideshow = new SlideshowWidget(this, "slideshow", WResizeNoErase);
00118 //  slideshow->hide();
00119 //  connect( slideshow, SIGNAL(endSlideshow()), this, SLOT(endSlideshow()) );
00120     
00121   //refresh subalbums listing
00122   layout->refresh();
00123 
00124   //place widgets in main frame
00125   grid = new QGridLayout( this, 3, 2, 0);                
00126   grid->addWidget( title,     0, 0 );
00127   grid->addWidget( layout,    1, 0 );
00128   grid->setRowStretch( 1, 1 );
00129   grid->addWidget( status,    2, 0 );
00130   grid->setRowSpacing( 2, 24 );
00131 //  grid->addMultiCellWidget( slideshow, 0, 2, 1, 1 );
00132   grid->setColStretch(0, 1 );  
00133   
00134   //PLATFORM_SPECIFIC_CODE
00135   //create and set application icon
00136   #if( !defined(Q_OS_MACX) && !defined(Q_OS_WIN) )
00137   setIcon( QPixmap(QString(IMAGE_PATH)+"miscImages/as32.png") );
00138   #endif
00139 
00140   setCaption( 
00141 #ifdef CVS_CODE
00142       "(CVS BUILD) " +        
00143 #endif              
00144               tr("Album Shaper"));
00145   //------------------------------------------------
00146   //apply settings
00147   QToolTip::setGloballyEnabled( config->getBool( "layout", "showTooltips" ) );
00148   title->useAnimation( config->getBool( "layout", "animation" ) );
00149   //------------------------------------------------
00150 }
00151 //==============================================
00152 Window::~Window()
00153 {
00154   //flush and reinsert recent albums listing
00155   config->removeGroup( "recentAlbums" );
00156   RecentAlbums* recentAlbums = title->getRecentAlbums();
00157   int num = recentAlbums->numEntries();
00158   int i;
00159   QString albumName, albumLocation, albumPhotoCount;
00160   for(i=0; i<num; i++)
00161   {
00162     recentAlbums->getEntry( i, albumName, albumLocation, albumPhotoCount );
00163     config->setString( "recentAlbums", QString("%1_name").arg(i),     albumName );
00164     config->setString( "recentAlbums", QString("%1_location").arg(i), albumLocation );    
00165     config->setString( "recentAlbums", QString("%1_photoCount").arg(i), albumPhotoCount );    
00166   }  
00167   
00168   //store window size and placement in config object
00169   config->setInt( "layout", "windowPosX", pos().x() );
00170   config->setInt( "layout", "windowPosY", pos().y() );
00171   config->setInt( "layout", "windowWidth", size().width() );
00172   config->setInt( "layout", "windowHeight", size().height() );
00173 
00174   //save user settings
00175   config->saveSettings();
00176 
00177   //delete non-qt objects
00178   delete config;
00179   config = NULL;
00180 }
00181 //==============================================
00182 TitleWidget* Window::getTitle()
00183 {
00184   return title;
00185 }
00186 //==============================================
00187 LayoutWidget* Window::getLayout()
00188 {
00189   return layout;
00190 }
00191 //==============================================
00192 StatusWidget* Window::getStatus()
00193 {
00194   return status;
00195 }
00196 //==============================================
00197 void Window::refresh()
00198 {
00199   layout->refresh();
00200 }
00201 //==============================================
00202 void Window::closeEvent( QCloseEvent* e)
00203 {
00204   //check if unsaved modifications exist, warn user they
00205   //will lose these if they quit now
00206   if(title->getAlbum()->albumModified() )
00207   {
00208     //if user has chosen to not receive destructive action warnings, or agrees to the action then quit
00209     bool proceed = (!config->getBool( "alerts", "showDestructiveAlerts" ));
00210     if(!proceed)
00211     {
00212       QuestionDialog sure( tr("Quit without saving?"),
00213                                        tr("You have unsaved work. Are you sure you want to quit without saving?"),
00214                                        "alertIcons/warning.png",
00215                                        this );
00216       proceed = sure.exec();
00217     }
00218     if(proceed)
00219       e->accept();
00220     else
00221       e->ignore();
00222   }
00223   else
00224   {
00225     e->accept();
00226   }
00227 }
00228 //==============================================
00229 Configuration* Window::getConfig()
00230 {
00231   return config;
00232 }
00233 //==============================================
00234 /*
00235  void Window::startSlideshowAtBeginning()
00236 {
00237   startSlideshow(true);
00238 }  
00239 //==============================================
00240 void Window::startSlideshowWithSelectedPhoto()
00241 {
00242   startSlideshow(false);  
00243 }
00244 //==============================================
00245  void Window::startSlideshow( bool startAtBeginning )
00246 { 
00247   //setup presentation
00248   if( startAtBeginning ) 
00249   {
00250     //start the slideshow
00251     slideshow->beginSlideshow(title->getAlbum());
00252   }
00253   else
00254   {
00255     //get selected collection
00256     Subalbum* startCollection = layout->getSubalbums()->getSelectedSubalbum();
00257   
00258     //get selected photo.if no photos selected in collection then we'll start with first photo in collection
00259     Photo* startPhoto = layout->getSubalbum()->getFirstSelectedPhoto();
00260     if(startPhoto == NULL) startPhoto = startCollection->getFirst();
00261 
00262     //start the slideshow
00263     slideshow->beginSlideshow( title->getAlbum(), 
00264                                startCollection, startPhoto );
00265   }
00266 
00267   //hide title, layout, and status widgets
00268   //show slideshow region fullscreen
00269   grid->setColStretch(0, 0 );  
00270   grid->setColStretch(1, 1 );  
00271   title->hide();
00272   layout->hide();
00273   status->hide();
00274   slideshow->show();
00275   slideshow->setFocus(); 
00276   
00277   //PLATFORM_SPECIFIC_CODE
00278   #if defined(Q_OS_MACX)
00279   SetSystemUIMode(kUIModeAllHidden, NULL);
00280   #endif
00281 
00282   showFullScreen();
00283 }
00284 //==============================================
00285 void Window::endSlideshow()
00286 {
00287   //exit from fullscreen mode
00288   showNormal();
00289 
00290   //PLATFORM_SPECIFIC_CODE
00291   #if defined(Q_OS_MACX)
00292   SetSystemUIMode(kUIModeNormal, NULL);
00293   #endif
00294     
00295   //give collection contents keyboard focus and select
00296   //and ensure visibility of last shown photo during presentation
00297   layout->getSubalbum()->getPhotos()->setFocus();
00298  
00299   Subalbum* tmpCollection = slideshow->getCurCollection();
00300   Photo* tmpPhoto = slideshow->getCurPhoto();
00301 
00302   if(tmpCollection != NULL)
00303   {
00304     layout->getSubalbums()->setSelectedSubalbum( tmpCollection );      
00305     if(tmpPhoto != NULL) 
00306     { 
00307       layout->getSubalbum()->setSelectedPhoto( tmpPhoto ); 
00308     }    
00309   }
00310   
00311   //hide slideshow and bring title, layout, and status back up
00312   title->show();
00313   layout->show();
00314   status->show();
00315   slideshow->hide();
00316   grid->setColStretch(1, 0 );  
00317   grid->setColStretch(0, 1 );  
00318   
00319 }
00320 */
00321 //==============================================
00322 bool Window::event( QEvent *e )
00323 {
00324   //if base class handles event return immediately
00325   if (QWidget::event( e ) )
00326     return true;
00327   
00328   //handle showMinimized events
00329   if ( e->type() == QEvent::ShowMinimized )
00330   {
00331     //update menu entries as per window state change
00332     title->windowStateChanged( false );
00333     return true;
00334   }
00335   
00336   return false;
00337 }
00338 //==============================================
00339 void Window::hideEvent( QHideEvent *)
00340 {
00341   //update menu entries as per window state change
00342   title->windowStateChanged( false );
00343 }
00344 //==============================================
00345 void Window::showEvent ( QShowEvent * )
00346 {
00347   //update menu entries as per window state change
00348   title->windowStateChanged( true );
00349 }
00350 //==============================================

Generated on Mon Apr 11 18:27:47 2005 for AlbumShaper by  doxygen 1.3.9.1