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

Generated on Sun Mar 4 19:42:56 2007 for AlbumShaper by doxygen 1.3.7