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

albumStatistics.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 <qpixmap.h>
00022 #include <qimage.h>
00023 #include <qpushbutton.h> 
00024 #include <qfileinfo.h>
00025 
00026 //Projectwide includes
00027 #include "albumStatistics.h"
00028 #include "../backend/album.h"
00029 #include "../backend/subalbum.h"
00030 #include "../backend/photo.h"
00031 #include "../backend/imageTools.h"
00032 #include "../config.h"
00033 
00034 //==============================================
00035 AlbumStatistics::AlbumStatistics( Album* album, 
00036                                   QWidget* parent,
00037                                   const char* name ) : 
00038                                   QDialog(parent,name)
00039 {
00040   //--
00041   //this album pointer
00042   this->album = album;
00043   //--
00044   //compute number of photos and size on disk  
00045   int photos = 0;
00046   int albumSize = 0;
00047   Subalbum* curSubalbum = album->getFirstSubalbum();
00048   QFileInfo info;
00049   while(curSubalbum != NULL)
00050   {
00051     photos+= curSubalbum->getNumPhotos();
00052     Photo* curPhoto = curSubalbum->getFirst();
00053     while(curPhoto != NULL)
00054     {
00055       info.setFile( curPhoto->getImageFilename() );
00056       albumSize+=info.size();
00057       
00058       info.setFile( curPhoto->getSlideshowFilename() );
00059       albumSize+=info.size();
00060      
00061       curPhoto = curPhoto->getNext();    
00062     }
00063     curSubalbum = curSubalbum->getNext();
00064   }
00065   //--  
00066   //set window title
00067   setCaption( tr("Album Statistics"));
00068   //--
00069   //set the background of the widget to be white
00070   setPaletteBackgroundColor( QColor(255, 255, 255) );
00071   //--
00072   //create title
00073   titleMessage = new QLabel( tr("Album Statistics"), this);
00074   QFont titleFont( "Times", 14, QFont::Bold );
00075   titleFont.setUnderline(true);
00076   titleMessage->setFont( titleFont );
00077   //--
00078   //create stats
00079   QFont statsFont( "Times", 12, QFont::Bold );
00080   
00081   numSubalbums = new QLabel( tr("Subalbums:"), this);
00082   numSubalbums->setFont( statsFont );    
00083   numSubalbumsVal = new QLabel(this);
00084   numSubalbumsVal->setText( QString("%1").arg(album->getNumSubalbums()) );
00085   numSubalbumsVal->setFont( statsFont );
00086   
00087   numPhotos = new QLabel( tr("Photos:"), this);
00088   numPhotos->setFont( statsFont );    
00089   numPhotosVal = new QLabel(this);
00090   numPhotosVal->setText( QString("%1").arg(photos) );
00091   numPhotosVal->setFont( statsFont );
00092   
00093   sizeOnDisk = new QLabel( tr("Size:"), this);
00094   sizeOnDisk->setFont( statsFont );    
00095   sizeOnDiskVal = new QLabel(this);
00096   sizeOnDiskVal->setFont( statsFont );  
00097   if(albumSize < 1024)
00098     sizeOnDiskVal->setText( QString(tr("~%1 Bytes")).arg(albumSize) );
00099   else if( albumSize/1024 < 1024)
00100     sizeOnDiskVal->setText( QString(tr("~%1 Kb")).arg( ((float)albumSize)/1024 ) );
00101   else if( albumSize/(1024*1024) < 1024)
00102     sizeOnDiskVal->setText( QString(tr("~%1 Mb")).arg( ((float)albumSize)/(1024*1024) ) );
00103   else
00104     sizeOnDiskVal->setText( QString(tr("~%1 Gigs")).arg( ((float)albumSize)/(1024*1024*1024) ) );
00105   //--
00106   //create album image and title labels  
00107   albumPreview = new QFrame( this );
00108   albumIcon = new QLabel( albumPreview );
00109   
00110   //if no rep image use small version
00111   if(album->getRepresentativeImage(LARGE) == NULL)
00112     albumIcon->setPixmap( *album->getRepresentativeImage( SMALL ) );
00113   else
00114   {
00115     QImage tImage = album->getRepresentativeImage( LARGE )->convertToImage();
00116     int newWidth, newHeight;
00117     resizeImage( tImage.width(), tImage.height(),
00118                  300, 300,
00119                  newWidth, newHeight);
00120     QImage tImage2 = tImage.smoothScale( newWidth, newHeight );
00121     albumImage = new QPixmap( newWidth, newHeight );
00122     albumImage->convertFromImage( tImage2 );
00123     albumIcon->setPixmap( *albumImage );
00124   }
00125   
00126   albumTitle = new QLabel( albumPreview );
00127   if(album->getName().compare("") != 0)
00128   {
00129     albumTitle->setText( "\"" + album->getName() + "\"" );
00130   }  
00131   albumTitle->setFont( statsFont );  
00132   //--
00133   //create ok button
00134   okButton = new QPushButton( QPixmap(QString(IMAGE_PATH)+"button_ok.png"), 
00135                               tr("Ok"), 
00136                               this );
00137   okButton->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum );
00138   okButton->setDefault(true);
00139   connect( okButton, SIGNAL(clicked()), SLOT(close()) );
00140   //--
00141   //place widgets in grid
00142   grid = new QGridLayout( this, 8, 3, 0);
00143   
00144   //add statistics text
00145   grid->addMultiCellWidget( titleMessage, 1, 1, 0, 1, Qt::AlignCenter);
00146   grid->addWidget( numSubalbums, 3, 0 );
00147   grid->addWidget( numSubalbumsVal, 3, 1, Qt::AlignRight );
00148   grid->addWidget( numPhotos, 4, 0 );
00149   grid->addWidget( numPhotosVal, 4, 1, Qt::AlignRight );
00150   grid->addWidget( sizeOnDisk, 5, 0 );
00151   grid->addWidget( sizeOnDiskVal, 5, 1, Qt::AlignRight );
00152 
00153   //add album image and name
00154   grid2 = new QGridLayout( albumPreview, 2, 1, 0 );
00155   grid2->addWidget( albumIcon, 0, 0, Qt::AlignCenter );
00156   grid2->addWidget( albumTitle, 1, 0, Qt::AlignCenter );  
00157   grid->addMultiCellWidget( albumPreview, 0, 6, 2, 2, Qt::AlignCenter );
00158   
00159   //add ok button
00160   grid->addMultiCellWidget( okButton, 7, 7, 0, 2, Qt::AlignCenter );
00161    
00162   //add space between "Album Statistics" text and actual statistics 
00163   grid->addRowSpacing( 2, 10 );
00164   
00165   //create expanding white space above and below text on left
00166   grid->setRowStretch( 0, 1 );  
00167   grid->setRowStretch( 6, 1 );  
00168   
00169   //set the text area to stretch width-wise
00170   grid->setColStretch( 1, 1 );  
00171   //--
00172   //set window to not be resizeable
00173   this->show();
00174   setFixedSize(size());
00175   //-------------------------------
00176 }
00177 //==============================================
00178 void AlbumStatistics::closeEvent( QCloseEvent* e)
00179 {
00180   albumStatisticsClosed();
00181   QWidget::closeEvent( e );
00182 }
00183 //==============================================

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