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

saveDialog.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 <qlayout.h>
00013 #include <qlabel.h>
00014 #include <qfont.h>
00015 #include <qtextbrowser.h>
00016 #include <qlineedit.h>
00017 #include <qlistbox.h>
00018 #include <qframe.h>
00019 #include <qstringlist.h>
00020 #include <qdir.h>
00021 #include <qpushbutton.h>
00022 #include <qfiledialog.h>
00023 #include <qtooltip.h>
00024 
00025 //Projectwide includes
00026 #include "saveDialog.h"
00027 #include "../../config.h"
00028 
00029 //==============================================
00030 SaveDialog::SaveDialog( QString actionMessage,
00031                                     QString defaultPath,
00032                                     QString defaultTheme,
00033                                     QWidget* parent,
00034                                     const char* name ) :
00035                                     QDialog(parent,name)
00036 {
00037   //set window title
00038   setCaption( actionMessage );
00039 
00040   //set the background of the widget to be white
00041 //  setPaletteBackgroundColor( QColor(255, 255, 255) );
00042 
00043   QFont textFont( "Times", 12, QFont::Bold );
00044 
00045   //create location frame and widgets
00046   locationFrame = new QFrame( this );
00047   locationLabel = new QLabel( tr("Save to:"), locationFrame );
00048   locationLabel->setFont( textFont );
00049   locationVal = new QLineEdit( locationFrame );
00050   locationVal->setText( defaultPath );
00051   locationVal->setFont( textFont );
00052   browseButton = new QPushButton( locationFrame );
00053   browseButton->setPixmap( QPixmap(QString(IMAGE_PATH)+"buttonIcons/browse.png") );
00054   browseButton->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
00055   QToolTip::add( browseButton, tr("Browse to save destination") );
00056   connect( browseButton, SIGNAL(clicked()), SLOT(browse()) );
00057   locationGrid = new QGridLayout( locationFrame, 1, 3, 0 );
00058   locationGrid->addWidget( locationLabel, 0, 0 );
00059   locationGrid->addWidget( locationVal, 0, 1 );
00060   locationGrid->addWidget( browseButton, 0, 2);
00061   locationGrid->setColStretch( 1, 1 );
00062   locationGrid->setSpacing(WIDGET_SPACING); 
00063   
00064   //create theme selection frame and widgets
00065   themeSelectionFrame = new QFrame( this );
00066   themesLabel = new QLabel( tr("Themes:"), themeSelectionFrame );
00067   themesLabel->setFont( textFont );
00068   themesList = new QListBox( themeSelectionFrame );
00069   QToolTip::add( themesList, tr("Select theme for saving album") );
00070   QDir localDir( THEMES_PATH );
00071   QStringList list = localDir.entryList( QDir::Dirs );
00072   bool itemsAdded = false;
00073   QStringList::Iterator file;
00074   for ( file = list.begin(); file != list.end(); ++file )
00075   {
00076     if(localDir.exists( QString(*file) + "/theme.xsl" ))
00077     {
00078       themesList->insertItem( *file );
00079       itemsAdded = true;
00080     }
00081   }
00082 
00083   //attempt to select default theme passed in, if not found select first theme in list
00084   bool themeFound = false;
00085   uint i=0;
00086   for(i=0; i<themesList->count(); i++)
00087   {
00088     if(themesList->text(i) == defaultTheme )
00089     {
00090       themeFound = true;
00091       themesList->setCurrentItem( i );
00092       break;
00093     }
00094   }
00095   if(!themeFound && itemsAdded )
00096   {
00097     themesList->setCurrentItem( 0 );
00098   }
00099 
00100   connect( themesList, SIGNAL( highlighted(int) ), this, SLOT( updatePreview() ) );
00101 
00102   themeSelectionGrid = new QGridLayout( themeSelectionFrame, 2, 1, 0 );
00103   themeSelectionGrid->addWidget( themesLabel, 0, 0 );
00104   themeSelectionGrid->addWidget( themesList, 1, 0 );
00105 
00106   //create theme preview frame and widgets
00107   themePreviewFrame = new QFrame( this );
00108   themePreviewLabel = new QLabel( tr("Theme Preview:"), themePreviewFrame );
00109   themePreviewLabel->setFont( textFont );
00110   themeScreenShot = new QLabel( themePreviewFrame );
00111   screenShotLabel = new QLabel( themePreviewFrame );
00112   screenShotLabel->setFont( textFont );
00113   themeScreenPrev = new QPushButton( themePreviewFrame );
00114   themeScreenPrev->setPixmap( QPixmap(QString(IMAGE_PATH)+"buttonIcons/previous.png") );
00115   themeScreenPrev->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
00116   QToolTip::add( themeScreenPrev, tr("View previous theme screenshot") );
00117   connect( themeScreenPrev, SIGNAL(clicked()), SLOT(prevScreenShot()) );
00118   themeScreenNext = new QPushButton( themePreviewFrame );
00119   themeScreenNext->setPixmap( QPixmap(QString(IMAGE_PATH)+"buttonIcons/next.png") );
00120   themeScreenNext->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
00121   QToolTip::add( themeScreenNext, tr("View next theme screenshot") );
00122   connect( themeScreenNext, SIGNAL(clicked()), SLOT(nextScreenShot()) );
00123   themeFeatures = new QTextBrowser( themePreviewFrame );
00124   themeFeatures->setFrameStyle( QFrame::Panel | QFrame::Sunken );
00125   themeFeatures->mimeSourceFactory()->setFilePath( QStringList(THEMES_PATH) );
00126   updatePreview();
00127 
00128   themePreviewGrid = new QGridLayout( themePreviewFrame, 5, 5, 0);
00129   themePreviewGrid->addWidget( themePreviewLabel, 0, 0 );
00130   themePreviewGrid->addMultiCellWidget( themeScreenShot, 1, 1, 0, 4 );
00131   themePreviewGrid->addMultiCellWidget( screenShotLabel, 2, 2, 0, 4, Qt::AlignCenter );
00132   themePreviewGrid->setColStretch( 0, 1 );
00133   themePreviewGrid->addWidget( themeScreenPrev, 3, 1 );
00134   themePreviewGrid->addColSpacing( 2, 10 );
00135   themePreviewGrid->addWidget( themeScreenNext, 3, 3 );
00136   themePreviewGrid->setColStretch( 4, 1 );
00137   themePreviewGrid->addMultiCellWidget( themeFeatures, 4, 4, 0, 4 );
00138 
00139   //create buttons frame and widgets
00140   buttonsFrame = new QFrame( this );
00141   saveButton = new QPushButton( 
00142   //PLATFORM_SPECIFIC_CODE
00143  #ifndef Q_OS_MACX  
00144  QPixmap(QString(IMAGE_PATH)+"buttonIcons/save.png"),
00145  #endif
00146                                tr("Save"), buttonsFrame );
00147   saveButton->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
00148   saveButton->setDefault(true);
00149   connect( saveButton, SIGNAL(clicked()), SLOT(save()) );
00150   cancelButton = new QPushButton( 
00151   //PLATFORM_SPECIFIC_CODE
00152   #ifndef Q_OS_MACX  
00153   QPixmap(QString(IMAGE_PATH)+"buttonIcons/button_cancel.png"),
00154   #endif
00155  tr("Cancel"), buttonsFrame
00156 );
00157   cancelButton->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
00158   connect( cancelButton, SIGNAL(clicked()), SLOT(cancel()) );
00159   buttonsGrid = new QGridLayout( buttonsFrame, 1, 5, 0 );
00160   buttonsGrid->setColStretch( 0, 1 );
00161   buttonsGrid->addWidget( saveButton, 0, 1 );
00162   buttonsGrid->addColSpacing( 2, 10 );
00163   buttonsGrid->addWidget( cancelButton, 0, 3 );
00164   buttonsGrid->setColStretch( 4, 1 );
00165 
00166   //place top level frames in grid
00167   mainGrid = new QGridLayout( this, 3, 2, 0);
00168   mainGrid->addWidget( themeSelectionFrame, 0, 0 );
00169   mainGrid->addWidget( themePreviewFrame, 0, 1 );
00170   mainGrid->addMultiCellWidget( locationFrame, 1, 1, 0, 1 );
00171   mainGrid->addMultiCellWidget( buttonsFrame, 2, 2, 0, 1 );
00172 
00173   //allow image and description region of select theme to expand to fit window
00174   mainGrid->setColStretch( 1, 1 );
00175   mainGrid->setRowStretch( 1, 1 );
00176   mainGrid->setMargin(WIDGET_SPACING);
00177   mainGrid->setSpacing(WIDGET_SPACING); 
00178   
00179   //set window to not be resizeable
00180   this->show();
00181   setFixedSize(size());
00182 }
00183 //==============================================
00184 void SaveDialog::updatePreview()
00185 {
00186   previewNum = 1;
00187   int i=1;
00188   QDir localDir( THEMES_PATH );
00189   while( localDir.exists( QString( themesList->currentText() + "/preview%1.png").arg(i) ) )
00190   {
00191     i++;
00192   }
00193   numPreviews = i-1;
00194 
00195   //update theme description if provided
00196   if(localDir.exists( themesList->currentText() + "/description.html" ))
00197   {
00198     themeFeatures->setSource( themesList->currentText() + "/description.html" );
00199   }
00200 
00201   //update preview image to provide one or default otherwise
00202   if(localDir.exists( themesList->currentText() + "/preview1.png") )
00203   {
00204     screenShotLabel->setText( QString( tr("Screenshot") ) + QString( " %1/%2").arg(previewNum).arg(numPreviews) );
00205     themeScreenShot->setPixmap( QPixmap(THEMES_PATH + themesList->currentText() + "/preview1.png") );
00206     themeScreenPrev->setEnabled(false);
00207 
00208     if(previewNum == numPreviews)
00209       themeScreenNext->setEnabled(false);
00210     else
00211       themeScreenNext->setEnabled(true);
00212   }
00213   else
00214   {
00215     screenShotLabel->setText( "" );
00216     themeScreenShot->setPixmap( QPixmap(QString(IMAGE_PATH)+"miscImages/themePreview.png") );
00217     themeScreenPrev->setEnabled(false);
00218     themeScreenNext->setEnabled(false);
00219   }
00220 
00221 }
00222 //==============================================
00223 void SaveDialog::save()
00224 {
00225   accept();
00226 }
00227 //==============================================
00228 void SaveDialog::cancel()
00229 {
00230   reject();
00231 }
00232 //==============================================
00233 void SaveDialog::prevScreenShot()
00234 {
00235   previewNum--;
00236   themeScreenNext->setEnabled(true);
00237   if(previewNum == 1)
00238   {
00239     themeScreenPrev->setEnabled(false);
00240   }
00241 
00242   screenShotLabel->setText( QString( tr("Screenshot") ) + QString( " %1/%2").arg(previewNum).arg(numPreviews) );
00243   themeScreenShot->setPixmap( QPixmap( QString(THEMES_PATH + themesList->currentText() + "/preview%1.png").arg(previewNum) ) );
00244 }
00245 //==============================================
00246 void SaveDialog::nextScreenShot()
00247 {
00248   previewNum++;
00249   themeScreenPrev->setEnabled(true);
00250   if(previewNum == numPreviews)
00251   {
00252     themeScreenNext->setEnabled(false);
00253   }
00254 
00255   screenShotLabel->setText( QString( tr("Screenshot") ) + QString( " %1/%2").arg(previewNum).arg(numPreviews) );
00256   themeScreenShot->setPixmap( QPixmap( QString(THEMES_PATH + themesList->currentText() + "/preview%1.png").arg(previewNum) ) );
00257 }
00258 //==============================================
00259 void SaveDialog::browse()
00260 {
00261   //get directory from user
00262   QString dirName = QFileDialog::getSaveFileName( locationVal->text(),
00263                                                   NULL, this, NULL, "Save as" );
00264 
00265   if(!dirName.isNull())
00266     locationVal->setText( dirName );
00267 }
00268 //==============================================
00269 QString SaveDialog::getTheme()
00270 {
00271   return themesList->currentText();
00272 }
00273 //==============================================
00274 QString SaveDialog::getPath()
00275 {
00276   return locationVal->text();
00277 }
00278 //==============================================
00279 bool SaveDialog::selectThemeAndPath( QString titleMessage,
00280                                                         QString defaultPath,
00281                                                         QString &theme,
00282                                                         QString &path )
00283 {
00284   SaveDialog* dlg = new SaveDialog( titleMessage, defaultPath, theme );
00285   if( dlg->exec() == QDialog::Accepted )
00286   {
00287     theme = dlg->getTheme();
00288     path = dlg->getPath();
00289     delete dlg;
00290     return true;
00291   }
00292   else
00293   {
00294     delete dlg;
00295     return false;
00296   }
00297 }
00298 //==============================================
00299 bool SaveDialog::themeAvailable(QString theme)
00300 {
00301   //walk through the themes directory searching
00302   //for a directory with the name of the theme
00303   //that also has a theme.xsl file inside it
00304   QDir localDir( THEMES_PATH );
00305   QStringList list = localDir.entryList( QDir::Dirs );
00306   QStringList::Iterator file;
00307   for ( file = list.begin(); file != list.end(); ++file )
00308   {
00309     if(localDir.exists( QString(*file) + "/theme.xsl") &&
00310       QString(*file) == theme)
00311       return true;
00312   }
00313   //theme not found
00314   return false;
00315 }
00316 //==============================================

Generated on Sat Apr 2 05:44:04 2005 for AlbumShaper by  doxygen 1.3.9.1