AlbumShaper  1.0a3
window.cpp
Go to the documentation of this file.
1 //==============================================
2 // copyright : (C) 2003-2005 by Will Stokes
3 //==============================================
4 // This program is free software; you can redistribute it
5 // and/or modify it under the terms of the GNU General
6 // Public License as published by the Free Software
7 // Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //==============================================
10 
11 //Systemwide includes
12 #include <q3frame.h>
13 #include <qlayout.h>
14 #include <qpixmap.h>
15 #include <qtooltip.h>
16 #include <qdir.h>
17 #include <qapplication.h>
18 #include <q3iconview.h>
19 //Added by qt3to4:
20 #include <Q3GridLayout>
21 #include <QShowEvent>
22 #include <QEvent>
23 #include <QHideEvent>
24 #include <QCloseEvent>
25 
26 //PLATFORM_SPECIFIC_CODE
27 #if defined(Q_OS_MACX)
28 #include "/Developer/Headers/FlatCarbon/Carbon.h"
29 #endif
30 
31 //Projectwide includes
32 #include "window.h"
33 #include "titleWidget.h"
34 #include "layoutWidget.h"
35 #include "statusWidget.h"
36 #include "subalbumsWidget.h"
37 #include "subalbumWidget.h"
38 #include "dialogs/questionDialog.h"
39 #include "dialogs/alertDialog.h"
40 
41 //#include "presentation/presentationWidget.h"
42 #include "../config.h"
43 #include "../backend/album.h"
44 #include "../backend/subalbum.h"
45 #include "../backend/photo.h"
46 #include "../backend/recentAlbums.h"
47 #include "../configuration/configuration.h"
48 #include "../configuration/loadingSavingWidget.h"
49 #include "../configuration/layoutSettingsWidget.h"
50 #include "../configuration/alertsWidget.h"
51 #include "../configuration/miscSettings.h"
52 
53 //==============================================
54 Window::Window( QWidget* parent, const char* name ) : QWidget(parent,name)
55 {
56  //don't clear pixmap area before painting, prevents flicker
57  setWindowFlags(Qt::WNoAutoErase);
58 
59  //load shadow pixmaps
60  shadowBL = new QPixmap( QString(IMAGE_PATH)+"miscImages/photoGradientBottomLeft.png" );
61  shadowB = new QPixmap( QString(IMAGE_PATH)+"miscImages/photoGradientBottom.png" );
62  shadowBR = new QPixmap( QString(IMAGE_PATH)+"miscImages/photoGradientBottomRight.png" );
63  shadowR = new QPixmap( QString(IMAGE_PATH)+"miscImages/photoGradientRight.png" );
64  shadowTR = new QPixmap( QString(IMAGE_PATH)+"miscImages/photoGradientTopRight.png" );
65 
66  //load photo info pixmap
67  photoInfo = new QPixmap( QString(IMAGE_PATH)+"buttonIcons/photoInfo.png");
68 
69  //------------------------------------------------
70  //create configuration object with default settings
71  config = new Configuration();
76  //------------------------------------------------
77  //load user settings
79 
80  //if temorary image directory does not exist create it
81  QDir homeDir;
82  bool configDirMade = true;
83  if(!homeDir.exists( config->getString( "loadSave", "tempImageDirectory")) )
84  { configDirMade = homeDir.mkdir( config->getString( "loadSave", "tempImageDirectory")); }
85  //if directory could not be made attempt to revert to default directory
86  if(!configDirMade)
87  {
88  AlertDialog alert( "unable to create temp dir", QString("unable to make temporary directory! (" + config->getString( "loadSave", "tempImageDirectory") ),
89  "alertIcons/warning.png", this );
90  alert.exec();
91 
92 
93  config->resetSetting( "loadSave", "tempImageDirectory" );
94  configDirMade = true;
95  if(!homeDir.exists( config->getString( "loadSave", "tempImageDirectory")) )
96  { configDirMade = homeDir.mkdir( config->getString( "loadSave", "tempImageDirectory")); }
97  }
98 
99  //if we are still unable to create the temporary image directory then immediately abort
100  if(!configDirMade)
101  {
102  AlertDialog alert( "unable to create temp dir", QString("unable to make temporary directory! (" + config->getString( "loadSave", "tempImageDirectory") ),
103  "alertIcons/warning.png", this );
104  alert.exec();
105 
106 close();
107  }
108 
109  //------------------------------------------------
110  //create top level widgets
111  title = new TitleWidget (this, "title");
112  layout = new LayoutWidget(this, "layout");
113  status = new StatusWidget(this, "status");
114 
116  connect( layout, SIGNAL(collectionSelected(Subalbum*)),
117  title, SLOT(refreshCollectionAnnotations(Subalbum*)) );
118 
120  connect( title, SIGNAL(subalbumNameChanged()),
121  layout, SLOT(refreshSelectedCollectionIconName()) );
122 
123 // slideshow = new SlideshowWidget(this, "slideshow", WResizeNoErase);
124 // slideshow->hide();
125 // connect( slideshow, SIGNAL(endSlideshow()), this, SLOT(endSlideshow()) );
126 
127  //refresh subalbums listing
128  layout->refresh();
129 
130  //place widgets in main frame
131  grid = new Q3GridLayout( this, 3, 2, 0);
132  grid->addWidget( title, 0, 0 );
133  grid->addWidget( layout, 1, 0 );
134  grid->setRowStretch( 1, 1 );
135  grid->addWidget( status, 2, 0 );
136  grid->setRowSpacing( 2, 24 );
137 // grid->addMultiCellWidget( slideshow, 0, 2, 1, 1 );
138  grid->setColStretch(0, 1 );
139 
140  //PLATFORM_SPECIFIC_CODE
141  //create and set application icon
142  #if( !defined(Q_OS_MACX) && !defined(Q_OS_WIN) )
143  setIcon( QPixmap(QString(IMAGE_PATH)+"miscImages/as32.png") );
144  #endif
145 
146  setCaption(
147 #ifdef CVS_CODE
148  "(CVS BUILD) " +
149 #endif
150  tr("Album Shaper"));
151  //------------------------------------------------
152  //apply settings
153  //QToolTip::setGloballyEnabled( config->getBool( "layout", "showTooltips" ) );
154  title->useAnimation( config->getBool( "layout", "animation" ) );
155  //------------------------------------------------
156 }
157 //==============================================
159 {
160  //flush and reinsert recent albums listing
161  config->removeGroup( "recentAlbums" );
162  RecentAlbums* recentAlbums = title->getRecentAlbums();
163  int num = recentAlbums->numEntries();
164  int i;
165  QString albumName, albumLocation, albumPhotoCount;
166  for(i=0; i<num; i++)
167  {
168  recentAlbums->getEntry( i, albumName, albumLocation, albumPhotoCount );
169  config->setString( "recentAlbums", QString("%1_name").arg(i), albumName );
170  config->setString( "recentAlbums", QString("%1_location").arg(i), albumLocation );
171  config->setString( "recentAlbums", QString("%1_photoCount").arg(i), albumPhotoCount );
172  }
173 
174  //store window size and placement in config object
175  config->setInt( "layout", "windowPosX", pos().x() );
176  config->setInt( "layout", "windowPosY", pos().y() );
177  config->setInt( "layout", "windowWidth", size().width() );
178  config->setInt( "layout", "windowHeight", size().height() );
179 
180  //save user settings
181  config->saveSettings();
182 
183  //delete non-qt objects
184  delete config;
185  config = NULL;
186 }
187 //==============================================
189 {
190  return title;
191 }
192 //==============================================
194 {
195  return layout;
196 }
197 //==============================================
199 {
200  return status;
201 }
202 //==============================================
204 {
205  layout->refresh();
206 }
207 //==============================================
208 void Window::closeEvent( QCloseEvent* e)
209 {
210  //check if unsaved modifications exist, warn user they
211  //will lose these if they quit now
212  if(title->getAlbum()->albumModified() )
213  {
214  //if user has chosen to not receive destructive action warnings, or agrees to the action then quit
215  bool proceed = (!config->getBool( "alerts", "showDestructiveAlerts" ));
216  if(!proceed)
217  {
218  QuestionDialog sure( tr("Quit without saving?"),
219  tr("You have unsaved work. Are you sure you want to quit without saving?"),
220  "alertIcons/warning.png",
221  this );
222  proceed = sure.exec();
223  }
224  if(proceed)
225  e->accept();
226  else
227  e->ignore();
228  }
229  else
230  {
231  e->accept();
232  }
233 }
234 //==============================================
236 {
237  return config;
238 }
239 //==============================================
240 /*
241  void Window::startSlideshowAtBeginning()
242 {
243  startSlideshow(true);
244 }
245 //==============================================
246 void Window::startSlideshowWithSelectedPhoto()
247 {
248  startSlideshow(false);
249 }
250 //==============================================
251  void Window::startSlideshow( bool startAtBeginning )
252 {
253  //setup presentation
254  if( startAtBeginning )
255  {
256  //start the slideshow
257  slideshow->beginSlideshow(title->getAlbum());
258  }
259  else
260  {
261  //get selected collection
262  Subalbum* startCollection = layout->getSubalbums()->getSelectedSubalbum();
263 
264  //get selected photo.if no photos selected in collection then we'll start with first photo in collection
265  Photo* startPhoto = layout->getSubalbum()->getFirstSelectedPhoto();
266  if(startPhoto == NULL) startPhoto = startCollection->getFirst();
267 
268  //start the slideshow
269  slideshow->beginSlideshow( title->getAlbum(),
270  startCollection, startPhoto );
271  }
272 
273  //hide title, layout, and status widgets
274  //show slideshow region fullscreen
275  grid->setColStretch(0, 0 );
276  grid->setColStretch(1, 1 );
277  title->hide();
278  layout->hide();
279  status->hide();
280  slideshow->show();
281  slideshow->setFocus();
282 
283  //PLATFORM_SPECIFIC_CODE
284  #if defined(Q_OS_MACX)
285  SetSystemUIMode(kUIModeAllHidden, NULL);
286  #endif
287 
288  showFullScreen();
289 }
290 //==============================================
291 void Window::endSlideshow()
292 {
293  //exit from fullscreen mode
294  showNormal();
295 
296  //PLATFORM_SPECIFIC_CODE
297  #if defined(Q_OS_MACX)
298  SetSystemUIMode(kUIModeNormal, NULL);
299  #endif
300 
301  //give collection contents keyboard focus and select
302  //and ensure visibility of last shown photo during presentation
303  layout->getSubalbum()->getPhotos()->setFocus();
304 
305  Subalbum* tmpCollection = slideshow->getCurCollection();
306  Photo* tmpPhoto = slideshow->getCurPhoto();
307 
308  if(tmpCollection != NULL)
309  {
310  layout->getSubalbums()->setSelectedSubalbum( tmpCollection );
311  if(tmpPhoto != NULL)
312  {
313  layout->getSubalbum()->setSelectedPhoto( tmpPhoto );
314  }
315  }
316 
317  //hide slideshow and bring title, layout, and status back up
318  title->show();
319  layout->show();
320  status->show();
321  slideshow->hide();
322  grid->setColStretch(1, 0 );
323  grid->setColStretch(0, 1 );
324 
325 }
326 */
327 //==============================================
328 bool Window::event( QEvent *e )
329 {
330  //if base class handles event return immediately
331  if (QWidget::event( e ) )
332  return true;
333 
334  //handle showMinimized events
335  if ( e->type() == QEvent::WindowStateChange && windowState() == Qt::WindowMinimized )
336  {
337  //update menu entries as per window state change
338  title->windowStateChanged( false );
339  return true;
340  }
341 
342  return false;
343 }
344 //==============================================
345 void Window::hideEvent( QHideEvent *)
346 {
347  //update menu entries as per window state change
348  title->windowStateChanged( false );
349 }
350 //==============================================
351 void Window::showEvent ( QShowEvent * )
352 {
353  //update menu entries as per window state change
354  title->windowStateChanged( true );
355 }
356 //==============================================
bool albumModified()
Returns true if album has been modified since the last save operation.
Definition: album.cpp:139
void removeGroup(QString group)
Removes an entire group of settings.
A configurable alert dialog that displays an alert/error message.
Definition: alertDialog.h:36
void setInt(QString group, QString key, int val)
Set int setting.
Q3GridLayout * grid
Grid objects placed in.
Definition: window.h:110
QPixmap * shadowBL
Definition: window.h:70
static void setDefaults(Configuration *config)
QPixmap * shadowR
Definition: window.h:70
void showEvent(QShowEvent *)
Definition: window.cpp:351
StatusWidget * getStatus()
returns a pointer to the status widget
Definition: window.cpp:198
QString getString(QString group, QString key)
Fetch string setting.
bool getBool(QString group, QString key)
Fetch bool setting.
void resetSetting(QString group, QString key)
Resets a setting to it&#39;s default value.
void hideEvent(QHideEvent *)
Definition: window.cpp:345
void refresh()
Refreshes layout.
bool loadSettings()
Loads settings.
static void setDefaults(Configuration *config)
void setString(QString group, QString key, QString value)
Sets a setting value, if group does not exist it is created, if setting does not exist it is also cre...
static void setDefaults(Configuration *config)
Displays list of subalbums and a particular subalbum layout.
Definition: layoutWidget.h:39
QString IMAGE_PATH
Definition: config.cpp:18
Window(QWidget *parent=0, const char *name=0)
Creates title area, layout, and tool bar and places them in grid.
Definition: window.cpp:54
Configuration * getConfig()
get setting object
Definition: window.cpp:235
A subalbum contains photos.
Definition: subalbum.h:48
int width
Definition: blur.cpp:79
bool event(QEvent *)
Definition: window.cpp:328
bool saveSettings()
Saves settings.
void useAnimation(bool val)
Use animation for rep images?
This class maintains and handles saving and loading a list of recently viewed albums.
Definition: recentAlbums.h:26
LayoutWidget * getLayout()
returns a pointer to the layout object
Definition: window.cpp:193
StatusWidget * status
Status widget either displays a status message or progress bar.
Definition: window.h:119
void closeEvent(QCloseEvent *e)
Definition: window.cpp:208
~Window()
Save user settings on destruct.
Definition: window.cpp:158
LayoutWidget * layout
Layout includes subalbums listing and particular subalbum layout.
Definition: window.h:116
TitleWidget * title
Title widget cont ains menu&#39;s, album information and Album Shaper icon.
Definition: window.h:113
void getEntry(int index, QString &name, QString &location, QString &photoCount)
Configuration object manages all user-specific application settings.
Definition: configuration.h:24
QPixmap * shadowTR
Definition: window.h:70
Widget which displays album name, description, representative image, and album shaper logo...
Definition: titleWidget.h:56
QPixmap * shadowB
Definition: window.h:70
static void setDefaults(Configuration *config)
QPixmap * shadowBR
Definition: window.h:70
Album * getAlbum()
Returns a pointer to the album object.
RecentAlbums * getRecentAlbums()
returns handle to recent albums object
void refresh()
refreshes the layout
Definition: window.cpp:203
void windowStateChanged(bool state)
Enables/disables "minimize" window menu entry depending on window state.
A configurable question dialog that returns true/false.
Configuration * config
Configuration settings.
Definition: window.h:107
QPixmap * photoInfo
Definition: window.h:73
TitleWidget * getTitle()
returns a pointer to the title widget
Definition: window.cpp:188
int height
Definition: blur.cpp:79