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

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

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