00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <qwidget.h>
00019 #include <qmenubar.h>
00020 #include <qpopupmenu.h>
00021 #include <qlayout.h>
00022 #include <qlabel.h>
00023 #include <qfont.h>
00024 #include <qpixmap.h>
00025 #include <qimage.h>
00026 #include <qpushbutton.h>
00027 #include <qlineedit.h>
00028 #include <qapplication.h>
00029 #include <qfiledialog.h>
00030 #include <qdir.h>
00031 #include <qcursor.h>
00032
00033
00034 #include "window.h"
00035 #include "about.h"
00036 #include "titleWidget.h"
00037 #include "layoutWidget.h"
00038 #include "subalbumsWidget.h"
00039 #include "subalbumWidget.h"
00040 #include "loadDialog.h"
00041 #include "saveDialog.h"
00042 #include "questionDialog.h"
00043 #include "../backend/album.h"
00044 #include "../backend/photo.h"
00045 #include "../config.h"
00046
00047 #include <iostream.h>
00048
00049
00050 TitleWidget::TitleWidget(QWidget *parent,
00051 const char* name ) : QFrame(parent,name)
00052 {
00054 window = (Window*)parent;
00055
00057 about = NULL;
00058
00059
00060 menu = new QMenuBar( this, "menuBar" );
00061 file = new QPopupMenu( this, "fileMenu" );
00062 NEW_ALBUM = file->insertItem( "&New", this, SLOT(newAlbum()), CTRL+Key_N );
00063 OPEN_ALBUM = file->insertItem( "&Open", this, SLOT(loadAlbum()), CTRL+Key_O );
00064 SAVE_ALBUM = file->insertItem( "&Save", this, SLOT(saveAlbum()), CTRL+Key_S );
00065 SAVEAS_ALBUM = file->insertItem( "&Save As", this, SLOT(saveAsAlbum()), CTRL+SHIFT+Key_S );
00066 file->insertItem( "&Quit", qApp, SLOT(quit()), CTRL+Key_Q);
00067 help = new QPopupMenu( this, "helpMenu" );
00068 help->insertItem( "&About", this, SLOT(aboutProgram()) );
00069 menu->insertItem( "&File", file );
00070 menu->insertSeparator();
00071 menu->insertItem( "&Help", help );
00072
00073
00074 albm = new Album();
00075
00076
00077 albumName = new QLabel( this );
00078 albumName->setText( "Album Name:" );
00079 albumName->setFont( QFont( "Times", 12, QFont::Bold ) );
00080 albumNameVal = new QLineEdit( this );
00081 albumNameVal->setFont( QFont( "Times", 12, QFont::Bold ) );
00082 connect( albumNameVal, SIGNAL(textChanged( const QString&)),
00083 SLOT( updateName(const QString&)) );
00084
00085 albumDescription = new QLabel( this );
00086 albumDescription->setText( "Description:" );
00087 albumDescription->setFont( QFont( "Times", 12, QFont::Bold ) );
00088 albumDescriptionVal = new QLineEdit( this );
00089 albumDescriptionVal->setFont( QFont( "Times", 12, QFont::Bold ) );
00090 connect( albumDescriptionVal, SIGNAL(textChanged( const QString&)),
00091 SLOT( updateDescription(const QString&)) );
00092
00093 albumAuthor = new QLabel( this );
00094 albumAuthor->setText( "Author:" );
00095 albumAuthor->setFont( QFont( "Times", 12, QFont::Bold ) );
00096 albumAuthorVal = new QLineEdit( this );
00097 albumAuthorVal->setFont( QFont( "Times", 12, QFont::Bold ) );
00098 connect( albumAuthorVal, SIGNAL(textChanged( const QString&)),
00099 SLOT( updateAuthor(const QString&)) );
00100
00101
00102 representativeImageText = new QLabel( this );
00103 representativeImageText->setText( "Thumbnail:" );
00104 representativeImageText->setFont( QFont( "Times", 12, QFont::Bold ) );
00105 setImageImage = new QPixmap( QString(IMAGE_PATH)+"set.png" );
00106 setImage = new QPushButton( this );
00107 setImage->setPixmap( *setImageImage );
00108 setImage->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum );
00109 setImage->setEnabled(false);
00110 connect( setImage, SIGNAL(clicked()), SLOT(setImageAction()) );
00111
00112
00113 representativeImage = albm->getRepresentativeImage(SMALL);
00114 representativeLogo = new QLabel( this );
00115 representativeLogo->setPixmap( *representativeImage );
00116
00117
00118 albumShaperImage = new QPixmap( QString(IMAGE_PATH)+"albumShaper.png" );
00119 albumShaperLogo = new QLabel( this );
00120 albumShaperLogo->setPixmap( *albumShaperImage );
00121
00122
00123 line = new QFrame(this);
00124 line->setFrameShadow( QFrame::Plain );
00125 line->setLineWidth( 2 );
00126 line->setFrameShape( QFrame::HLine );
00127
00128
00129 grid = new QGridLayout( this, 5, 6, 0 );
00130 grid->addMultiCellWidget( menu, 0, 0, 0, 5 );
00131 grid->addWidget( albumName, 1, 0, Qt::AlignLeft);
00132 grid->addWidget( albumNameVal, 1, 1);
00133 grid->addWidget( albumDescription, 2, 0, Qt::AlignLeft);
00134 grid->addWidget( albumDescriptionVal, 2, 1);
00135 grid->addWidget( albumAuthor, 3, 0, Qt::AlignLeft);
00136 grid->addWidget( albumAuthorVal, 3, 1);
00137 grid->addWidget( representativeImageText, 1, 2, Qt::AlignLeft );
00138 grid->addWidget( setImage, 2, 2, Qt::AlignLeft );
00139 grid->addMultiCellWidget( representativeLogo, 1, 3, 3, 3 );
00140 grid->addMultiCellWidget( line, 4, 4, 0, 5);
00141 grid->addMultiCellWidget( albumShaperLogo, 1, 3, 5, 5 );
00142
00143
00144
00145 grid->addColSpacing(1, 300 );
00146
00147
00148
00149 grid->setColStretch( 4, 1 );
00150
00151
00152 setPaletteBackgroundColor( QColor(255, 255, 255) );
00153
00155 busy = false;
00156 }
00157
00158 TitleWidget::~TitleWidget()
00159 {
00160 delete setImageImage;
00161 delete representativeImage;
00162 delete albumShaperImage;
00163 }
00164
00165 void TitleWidget::updateName( const QString& val )
00166 {
00167 albm->setName(val);
00168 }
00169
00170 void TitleWidget::updateDescription( const QString& val )
00171 {
00172 albm->setDescription(val);
00173 }
00174
00175 void TitleWidget::updateAuthor( const QString& val )
00176 {
00177 albm->setAuthor(val);
00178 }
00179
00180 void TitleWidget::setAlbum( Album* val)
00181 {
00182
00183 delete albm;
00184 albm = val;
00185 }
00186
00187 Album* TitleWidget::getAlbum()
00188 {
00189 return albm;
00190 }
00191
00192
00193 void TitleWidget::setImageAction()
00194 {
00195
00196
00197 SubalbumWidget* sw = window->getLayout()->getSubalbum();
00198 if(sw == NULL)
00199 return;
00200
00201
00202 Photo* selectedPhoto = sw->getSelectedPhoto();
00203 if(selectedPhoto == NULL)
00204 return;
00205
00206
00207 QImage* img = selectedPhoto->getImage(IMAGE);
00208 albm->setRepresentativeImages( img );
00209 delete img;
00210 img = NULL;
00211
00212
00213 representativeLogo->setPixmap( *(albm->getRepresentativeImage(SMALL)) );
00214
00215 }
00216
00217 void TitleWidget::refresh()
00218 {
00219 albumNameVal->setText( albm->getName() );
00220 albumDescriptionVal->setText( albm->getDescription() );
00221 albumAuthorVal->setText( albm->getAuthor() );
00222 representativeLogo->setPixmap( *(albm->getRepresentativeImage(SMALL)) );
00223 }
00224
00225 void TitleWidget::newAlbum()
00226 {
00227
00228 QuestionDialog sure( "New album?",
00229 "Warning, this operation cannot be undone and all current work will be lost.",
00230 "warning.png",
00231 this );
00232
00233 if(sure.exec())
00234 {
00235
00236 delete albm;
00237
00238
00239 albm = new Album();
00240
00241
00242 refresh();
00243 window->refresh();
00244 }
00245 }
00246
00247 void TitleWidget::loadAlbum()
00248 {
00249
00250 setBusy(true);
00251 window->getLayout()->getSubalbums()->updateButtons(false);
00252 if(window->getLayout()->getSubalbum() != NULL)
00253 window->getLayout()->getSubalbum()->updateButtons(false);
00254
00255 QString albumXML = QFileDialog::getOpenFileName(NULL,
00256 "XML Files (*.xml)",
00257 this,
00258 "open file dialog",
00259 "Choose an album to load" );
00260
00261
00262 if(albumXML.isNull())
00263 {
00264
00265 setBusy(false);
00266 window->getLayout()->getSubalbums()->updateButtons(true);
00267 if(window->getLayout()->getSubalbum() != NULL)
00268 window->getLayout()->getSubalbum()->updateButtons(true);
00269 return;
00270 }
00271
00272 qApp->setOverrideCursor( QCursor(Qt::WaitCursor));
00273
00274
00275 LoadDialog* dialog = new LoadDialog();
00276
00277
00278 QRect appRec = qApp->mainWidget()->geometry();
00279
00280
00281 int x, y;
00282 if(400 < appRec.width())
00283 { x = appRec.x() + ((appRec.width() - 400)/2); }
00284 else
00285 { x = appRec.x(); }
00286 if(300 < appRec.height())
00287 { y = appRec.y() + ((appRec.height() - 300)/2); }
00288 else
00289 { y = appRec.y(); }
00290
00291 dialog->setGeometry(x, y, 400, 300);
00292 dialog->show();
00293 dialog->repaint();
00294
00295
00296 dialog->printMessage("Freeing old album");
00297 delete albm;
00298 albm = new Album();
00299
00300
00301 albm->importFromDisk(dialog, albumXML);
00302
00303
00304 refresh();
00305
00306 window->refresh();
00307
00308 delete dialog;
00309
00310
00311 setBusy(false);
00312 window->getLayout()->getSubalbums()->updateButtons(true);
00313 if(window->getLayout()->getSubalbum() != NULL)
00314 window->getLayout()->getSubalbum()->updateButtons(true);
00315 qApp->restoreOverrideCursor();
00316 }
00317
00318 void TitleWidget::saveAlbum()
00319 {
00320
00321 setBusy(true);
00322 window->getLayout()->getSubalbums()->updateButtons(false);
00323 if(window->getLayout()->getSubalbum() != NULL)
00324 window->getLayout()->getSubalbum()->updateButtons(false);
00325
00326
00327
00328 if(!getAlbum()->prevSave())
00329 {
00330 saveAsAlbum();
00331 }
00332
00333 else
00334 {
00335 qApp->setOverrideCursor( QCursor(Qt::WaitCursor));
00336
00337
00338 SaveDialog* dialog = new SaveDialog();
00339
00340
00341 QRect appRec = qApp->mainWidget()->geometry();
00342
00343
00344 int x, y;
00345 if(400 < appRec.width())
00346 { x = appRec.x() + ((appRec.width() - 400)/2); }
00347 else
00348 { x = appRec.x(); }
00349 if(300 < appRec.height())
00350 { y = appRec.y() + ((appRec.height() - 300)/2); }
00351 else
00352 { y = appRec.y(); }
00353
00354 dialog->setGeometry(x, y, 400, 300);
00355 dialog->show();
00356 dialog->repaint();
00357
00358
00359 if( window->getLayout()->getSubalbum() != NULL )
00360 window->getLayout()->getSubalbum()->syncPhotos();
00361
00362 getAlbum()->exportToDisk(dialog);
00363
00364
00365 delete dialog;
00366
00367 qApp->restoreOverrideCursor();
00368 }
00369
00370
00371 setBusy(false);
00372 window->getLayout()->getSubalbums()->updateButtons(true);
00373 if(window->getLayout()->getSubalbum() != NULL)
00374 window->getLayout()->getSubalbum()->updateButtons(true);
00375 }
00376
00377 void TitleWidget::saveAsAlbum()
00378 {
00379
00380 QString dirName = QFileDialog::getExistingDirectory(NULL,
00381 this,
00382 "get existing directory",
00383 "Choose Directory for Album Folder",
00384 TRUE);
00385
00386 if(dirName.isNull())
00387 return;
00388
00389
00390 QDir d(dirName);
00391
00392 if(!d.isReadable())
00393 return;
00394
00395
00396
00397 QString albumName = getAlbum()->getName();
00398
00399
00400 if(albumName.stripWhiteSpace() == "")
00401 return;
00402
00403 albumName.replace( QChar(' '), "_" );
00404 albumName.replace( "<", "" );
00405 albumName.replace( ">", "" );
00406 albumName.replace( "&", "and" );
00407 albumName.replace( "\"", "" );
00408 albumName.replace( "\'", "" );
00409 albumName.replace( "?", "" );
00410
00411
00412 if(!d.mkdir(albumName))
00413 {
00414 cout << "Error! Unable to create save folder\n";
00415 return;
00416 }
00417
00418 qApp->setOverrideCursor( QCursor(Qt::WaitCursor));
00419
00420
00421 QString fullPath = d.absPath() + "/" + albumName;
00422
00423
00424 SaveDialog* dialog = new SaveDialog();
00425 dialog->setGeometry(200, 200, 400, 300);
00426 dialog->show();
00427 dialog->repaint();
00428
00429
00430 getAlbum()->exportToDisk(dialog, fullPath);
00431
00432
00433 delete dialog;
00434
00435 qApp->restoreOverrideCursor();
00436 }
00437
00438 void TitleWidget::aboutProgram()
00439 {
00440 if(about == NULL)
00441 {
00442 about = new About();
00443 connect( about, SIGNAL(aboutClosed()),
00444 this, SLOT(aboutClosed()));
00445 about->show();
00446
00447
00448 QRect appRec = qApp->mainWidget()->geometry();
00449 QRect aboutRec = about->geometry();
00450
00451
00452 int x, y;
00453 if(aboutRec.width() < appRec.width())
00454 { x = appRec.x() + ((appRec.width() - aboutRec.width())/2); }
00455 else
00456 { x = appRec.x(); }
00457 if(aboutRec.height() < appRec.height())
00458 { y = appRec.y() + ((appRec.height() - aboutRec.height())/2); }
00459 else
00460 { y = appRec.y(); }
00461
00462 about->move( QPoint( x, y) );
00463
00464
00465 }
00466 else
00467 {
00468 about->raise();
00469 }
00470 }
00471
00472 void TitleWidget::aboutClosed()
00473 {
00474 delete about;
00475 about = NULL;
00476 }
00477
00478 void TitleWidget::setSetButtonState(bool state)
00479 {
00480 setImage->setEnabled(state);
00481 }
00482
00483 bool TitleWidget::getBusy()
00484 {
00485 return busy;
00486 }
00487
00488 void TitleWidget::setBusy(bool val)
00489 {
00490 busy = val;
00491
00492
00493 if(busy)
00494 {
00495 file->setItemEnabled(NEW_ALBUM, false);
00496 file->setItemEnabled(OPEN_ALBUM, false);
00497 file->setItemEnabled(SAVE_ALBUM, false);
00498 file->setItemEnabled(SAVEAS_ALBUM, false);
00499 cacheSetButtonState = setImage->isEnabled();
00500 setSetButtonState(false);
00501 }
00502 else
00503 {
00504 file->setItemEnabled(NEW_ALBUM, true);
00505 file->setItemEnabled(OPEN_ALBUM, true);
00506 file->setItemEnabled(SAVE_ALBUM, true);
00507 file->setItemEnabled(SAVEAS_ALBUM, true);
00508 setSetButtonState(cacheSetButtonState);
00509 }
00510 }
00511