AlbumShaper  1.0a3
saveDialog.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 <qlayout.h>
13 #include <qlabel.h>
14 #include <qfont.h>
15 #include <q3textbrowser.h>
16 #include <qlineedit.h>
17 #include <q3listbox.h>
18 #include <q3frame.h>
19 #include <qstringlist.h>
20 #include <qdir.h>
21 #include <qpushbutton.h>
22 #include <q3filedialog.h>
23 #include <qtooltip.h>
24 //Added by qt3to4:
25 #include <Q3GridLayout>
26 #include <QPixmap>
27 
28 //Projectwide includes
29 #include "saveDialog.h"
30 #include "../clickableLabel.h"
31 #include "../../config.h"
32 
33 //==============================================
34 SaveDialog::SaveDialog( QString actionMessage,
35  QString defaultPath,
36  QString defaultTheme,
37  QWidget* parent,
38  const char* name ) :
39  QDialog(parent,name)
40 {
41  //set window title
42  setCaption( actionMessage );
43 
44  //set the background of the widget to be white
45 // setPaletteBackgroundColor( QColor(255, 255, 255) );
46 
47 
48  //create location frame and widgets
49  locationFrame = new Q3Frame( this );
50  locationLabel = new QLabel( tr("Save to:"), locationFrame );
51 
52  QFont boldFont = locationLabel->font();
53  boldFont.setWeight(QFont::Bold);
54 
55  locationLabel->setFont( boldFont );
56  locationVal = new QLineEdit( locationFrame );
57  locationVal->setText( defaultPath );
58  locationVal->setFont( boldFont );
59 
61  browseButton->setPixmap( QPixmap(QString(IMAGE_PATH)+"buttonIcons/browse.png") );
62  QToolTip::add( browseButton, tr("Browse to save destination") );
63  connect( browseButton, SIGNAL(clicked()), SLOT(browse()) );
64  locationGrid = new Q3GridLayout( locationFrame, 1, 3, 0 );
65  locationGrid->addWidget( locationLabel, 0, 0 );
66  locationGrid->addWidget( locationVal, 0, 1 );
67  locationGrid->addWidget( browseButton, 0, 2);
68  locationGrid->setColStretch( 1, 1 );
69  locationGrid->setSpacing(WIDGET_SPACING);
70 
71  //create theme selection frame and widgets
72  themeSelectionFrame = new Q3Frame( this );
73  themesLabel = new QLabel( tr("Themes:"), themeSelectionFrame );
74  themesLabel->setFont( boldFont );
75  themesList = new Q3ListBox( themeSelectionFrame );
76  QToolTip::add( themesList, tr("Select theme for saving album") );
77  QDir localDir( THEMES_PATH );
78  QStringList list = localDir.entryList( QDir::Dirs );
79  bool itemsAdded = false;
80  QStringList::Iterator file;
81  for ( file = list.begin(); file != list.end(); ++file )
82  {
83  if(localDir.exists( QString(*file) + "/theme.xsl" ))
84  {
85  themesList->insertItem( *file );
86  itemsAdded = true;
87  }
88  }
89 
90  //attempt to select default theme passed in, if not found select first theme in list
91  bool themeFound = false;
92  uint i=0;
93  for(i=0; i<themesList->count(); i++)
94  {
95  if(themesList->text(i) == defaultTheme )
96  {
97  themeFound = true;
98  themesList->setCurrentItem( i );
99  break;
100  }
101  }
102  if(!themeFound && itemsAdded )
103  {
104  themesList->setCurrentItem( 0 );
105  }
106 
107  connect( themesList, SIGNAL( highlighted(int) ), this, SLOT( updatePreview() ) );
108 
109  themeSelectionGrid = new Q3GridLayout( themeSelectionFrame, 2, 1, 0 );
110  themeSelectionGrid->addWidget( themesLabel, 0, 0 );
111  themeSelectionGrid->addWidget( themesList, 1, 0 );
112 
113  //create theme preview frame and widgets
114  themePreviewFrame = new Q3Frame( this );
115  themePreviewLabel = new QLabel( tr("Theme Preview:"), themePreviewFrame );
116  themePreviewLabel->setFont( boldFont );
119  screenShotLabel->setFont( boldFont );
120 
122  themeScreenPrev->setPixmap( QPixmap(QString(IMAGE_PATH)+"buttonIcons/previous.png") );
123  QToolTip::add( themeScreenPrev, tr("View previous theme screenshot") );
124  connect( themeScreenPrev, SIGNAL(clicked()), SLOT(prevScreenShot()) );
125 
127  themeScreenNext->setPixmap( QPixmap(QString(IMAGE_PATH)+"buttonIcons/next.png") );
128  QToolTip::add( themeScreenNext, tr("View next theme screenshot") );
129  connect( themeScreenNext, SIGNAL(clicked()), SLOT(nextScreenShot()) );
130 
132  themeFeatures->setFrameStyle( Q3Frame::Panel | Q3Frame::Sunken );
133  themeFeatures->mimeSourceFactory()->setFilePath( QStringList(THEMES_PATH) );
134  updatePreview();
135 
136  themePreviewGrid = new Q3GridLayout( themePreviewFrame, 5, 5, 0);
137  themePreviewGrid->addMultiCellWidget( themePreviewLabel, 0,0, 0,4 );
138 
139  themePreviewGrid->addWidget( themeScreenPrev, 1, 0, Qt::AlignVCenter );
140  themePreviewGrid->addColSpacing( 1, 10 );
141  themePreviewGrid->setColStretch( 1, 1 );
142  themePreviewGrid->addWidget( themeScreenShot, 1, 2 );
143  themePreviewGrid->addColSpacing( 3, 10 );
144  themePreviewGrid->setColStretch( 3, 1 );
145  themePreviewGrid->addWidget( themeScreenNext, 1, 4, Qt::AlignVCenter );
146  themePreviewGrid->addMultiCellWidget( screenShotLabel, 2, 2, 0, 4, Qt::AlignCenter );
147  themePreviewGrid->addMultiCellWidget( themeFeatures, 4, 4, 0, 4 );
148 
149  //create buttons frame and widgets
150  buttonsFrame = new Q3Frame( this );
151  saveButton = new QPushButton(
152  //PLATFORM_SPECIFIC_CODE
153  #ifndef Q_OS_MACX
154  QPixmap(QString(IMAGE_PATH)+"buttonIcons/save.png"),
155  #endif
156  tr("Save"), buttonsFrame );
157  saveButton->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
158  saveButton->setDefault(true);
159  connect( saveButton, SIGNAL(clicked()), SLOT(save()) );
160  cancelButton = new QPushButton(
161  //PLATFORM_SPECIFIC_CODE
162  #ifndef Q_OS_MACX
163  QPixmap(QString(IMAGE_PATH)+"buttonIcons/button_cancel.png"),
164  #endif
165  tr("Cancel"), buttonsFrame
166 );
167  cancelButton->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
168  connect( cancelButton, SIGNAL(clicked()), SLOT(cancel()) );
169  buttonsGrid = new Q3GridLayout( buttonsFrame, 1, 5, 0 );
170  buttonsGrid->setColStretch( 0, 1 );
171  buttonsGrid->addWidget( saveButton, 0, 1 );
172  buttonsGrid->addColSpacing( 2, 10 );
173  buttonsGrid->addWidget( cancelButton, 0, 3 );
174  buttonsGrid->setColStretch( 4, 1 );
175 
176  //place top level frames in grid
177  mainGrid = new Q3GridLayout( this, 3, 2, 0);
178  mainGrid->addWidget( themeSelectionFrame, 0, 0 );
179  mainGrid->addWidget( themePreviewFrame, 0, 1 );
180  mainGrid->addMultiCellWidget( locationFrame, 1, 1, 0, 1 );
181  mainGrid->addMultiCellWidget( buttonsFrame, 2, 2, 0, 1 );
182 
183  //allow image and description region of select theme to expand to fit window
184  mainGrid->setColStretch( 1, 1 );
185  mainGrid->setRowStretch( 1, 1 );
186  mainGrid->setMargin(WIDGET_SPACING);
187  mainGrid->setSpacing(WIDGET_SPACING);
188 
189  //set window to not be resizeable
190  this->show();
191  setFixedSize(size());
192 }
193 //==============================================
195 {
196  previewNum = 1;
197  int i=1;
198  QDir localDir( THEMES_PATH );
199  while( localDir.exists( QString( themesList->currentText() + "/preview%1.png").arg(i) ) ) { i++; }
200  numPreviews = i-1;
201 
202  //update theme description if provided
203  if(localDir.exists( themesList->currentText() + "/description.html" ))
204  {
205  themeFeatures->setSource( themesList->currentText() + "/description.html" );
206  }
207 
208  //update preview image to provide one or default otherwise
209  if(localDir.exists( themesList->currentText() + "/preview1.png") )
210  {
211  screenShotLabel->setText( QString( tr("Screenshot") ) + QString( " %1/%2").arg(previewNum).arg(numPreviews) );
212  themeScreenShot->setPixmap( QPixmap(THEMES_PATH + themesList->currentText() + "/preview1.png") );
213  themeScreenPrev->setInvisible( true );
215  }
216  else
217  {
218  screenShotLabel->setText( "" );
219  themeScreenShot->setPixmap( QPixmap(QString(IMAGE_PATH)+"miscImages/themePreview.png") );
220  themeScreenPrev->setInvisible( true );
221  themeScreenNext->setInvisible( true );
222  }
223 
224 }
225 //==============================================
227 {
228  accept();
229 }
230 //==============================================
232 {
233  reject();
234 }
235 //==============================================
237 {
238  previewNum--;
241 
242  screenShotLabel->setText( QString( tr("Screenshot") ) + QString( " %1/%2").arg(previewNum).arg(numPreviews) );
243  themeScreenShot->setPixmap( QPixmap( QString(THEMES_PATH + themesList->currentText() + "/preview%1.png").arg(previewNum) ) );
244 }
245 //==============================================
247 {
248  previewNum++;
251 
252  screenShotLabel->setText( QString( tr("Screenshot") ) + QString( " %1/%2").arg(previewNum).arg(numPreviews) );
253  themeScreenShot->setPixmap( QPixmap( QString(THEMES_PATH + themesList->currentText() + "/preview%1.png").arg(previewNum) ) );
254 }
255 //==============================================
257 {
258  //get directory from user
259  QString dirName = Q3FileDialog::getSaveFileName( locationVal->text(),
260  NULL, this, NULL, QString(tr("Save as")) );
261 
262  if(!dirName.isNull())
263  locationVal->setText( dirName );
264 }
265 //==============================================
267 {
268  return themesList->currentText();
269 }
270 //==============================================
272 {
273  return locationVal->text();
274 }
275 //==============================================
276 bool SaveDialog::selectThemeAndPath( QString titleMessage,
277  QString defaultPath,
278  QString &theme,
279  QString &path )
280 {
281  SaveDialog* dlg = new SaveDialog( titleMessage, defaultPath, theme );
282  if( dlg->exec() == QDialog::Accepted )
283  {
284  theme = dlg->getTheme();
285  path = dlg->getPath();
286  delete dlg;
287  return true;
288  }
289  else
290  {
291  delete dlg;
292  return false;
293  }
294 }
295 //==============================================
296 bool SaveDialog::themeAvailable(QString theme)
297 {
298  //walk through the themes directory searching
299  //for a directory with the name of the theme
300  //that also has a theme.xsl file inside it
301  QDir localDir( THEMES_PATH );
302  QStringList list = localDir.entryList( QDir::Dirs );
303  QStringList::Iterator file;
304  for ( file = list.begin(); file != list.end(); ++file )
305  {
306  if(localDir.exists( QString(*file) + "/theme.xsl") &&
307  QString(*file) == theme)
308  return true;
309  }
310  //theme not found
311  return false;
312 }
313 //==============================================
Q3TextBrowser * themeFeatures
Definition: saveDialog.h:70
Q3Frame * themePreviewFrame
Definition: saveDialog.h:65
QLabel * screenShotLabel
Definition: saveDialog.h:67
void prevScreenShot()
Definition: saveDialog.cpp:236
Save dialog widget.
Definition: saveDialog.h:36
QString getTheme()
Definition: saveDialog.cpp:266
void save()
Definition: saveDialog.cpp:226
QString getPath()
Definition: saveDialog.cpp:271
void setPixmap(const QPixmap &p)
Q3Frame * locationFrame
Definition: saveDialog.h:65
void nextScreenShot()
Definition: saveDialog.cpp:246
QPushButton * cancelButton
Definition: saveDialog.h:71
QLabel * locationLabel
Definition: saveDialog.h:67
QString IMAGE_PATH
Definition: config.cpp:18
static bool selectThemeAndPath(QString titleMessage, QString defaultPath, QString &theme, QString &path)
Definition: saveDialog.cpp:276
static bool themeAvailable(QString theme)
Definition: saveDialog.cpp:296
QLabel * themeScreenShot
Definition: saveDialog.h:67
A clickable label.
Q3Frame * themeSelectionFrame
Definition: saveDialog.h:65
Q3GridLayout * locationGrid
Definition: saveDialog.h:66
Q3Frame * buttonsFrame
Definition: saveDialog.h:65
ClickableLabel * themeScreenPrev
Definition: saveDialog.h:73
Q3GridLayout * themeSelectionGrid
Definition: saveDialog.h:66
void updatePreview()
Definition: saveDialog.cpp:194
Q3GridLayout * buttonsGrid
Definition: saveDialog.h:66
ClickableLabel * browseButton
Definition: saveDialog.h:73
void cancel()
Definition: saveDialog.cpp:231
#define WIDGET_SPACING
Definition: config.h:31
int numPreviews
Definition: saveDialog.h:76
void browse()
Definition: saveDialog.cpp:256
QLabel * themePreviewLabel
Definition: saveDialog.h:67
int previewNum
Definition: saveDialog.h:75
SaveDialog(QString actionMessage, QString defaultPath, QString defaultTheme, QWidget *parent=0, const char *name=0)
Definition: saveDialog.cpp:34
Q3ListBox * themesList
Definition: saveDialog.h:69
QLabel * themesLabel
Definition: saveDialog.h:67
QPushButton * saveButton
Definition: saveDialog.h:71
void setInvisible(bool val)
Q3GridLayout * mainGrid
Definition: saveDialog.h:66
Q3GridLayout * themePreviewGrid
Definition: saveDialog.h:66
QString THEMES_PATH
Definition: config.cpp:21
QLineEdit * locationVal
Definition: saveDialog.h:68
ClickableLabel * themeScreenNext
Definition: saveDialog.h:73