AlbumShaper 1.0a3
albumStatistics.cpp
Go to the documentation of this file.
1//==============================================
2// copyright : (C) 2003-2005 by Will Stokes
3//==============================================
4// This program is free software; you can redistribute it
5// and/or modify it under the terms of the GNU General
6// Public License as published by the Free Software
7// Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//==============================================
10
11//Systemwide includes
12#include <qlayout.h>
13#include <qlabel.h>
14#include <qfont.h>
15#include <qpixmap.h>
16#include <qimage.h>
17#include <qpushbutton.h>
18#include <qfileinfo.h>
19
20#include <qtoolbutton.h>
21//Added by qt3to4:
22#include <QCloseEvent>
23#include <Q3GridLayout>
24#include <Q3Frame>
25
26//Projectwide includes
27#include "albumStatistics.h"
28#include "../../config.h"
29#include "../../backend/album.h"
31#include "../../backend/photo.h"
33
34//==============================================
36 QWidget* parent,
37 const char* name ) :
38 QDialog(parent,name)
39{
40 //--------------------------------------------------------------
41 QColor white(255, 255, 255);
42 QColor darkBlue(35, 75, 139);
43 //--------------------------------------------------------------
44 //this album pointer
45 this->album = album;
46 //--
47 //compute size on disk
48 int albumSize = 0;
49 Subalbum* curSubalbum = album->getFirstSubalbum();
50 QFileInfo info;
51 while(curSubalbum != NULL)
52 {
53 Photo* curPhoto = curSubalbum->getFirst();
54 while(curPhoto != NULL)
55 {
56 info.setFile( curPhoto->getImageFilename() );
57 albumSize+=info.size();
58
59 info.setFile( curPhoto->getSlideshowFilename() );
60 albumSize+=info.size();
61
62 curPhoto = curPhoto->getNext();
63 }
64 curSubalbum = curSubalbum->getNext();
65 }
66 //--
67 //set window title
68 setCaption( tr("Album Statistics"));
69 //--
70 //create title
71 titleMessage = new QLabel( tr("Album Statistics:"), this);
72
73 QFont titleFont = titleMessage->font();
74 titleFont.setWeight(QFont::Bold);
75 titleFont.setPointSize( titleFont.pointSize() + 2 );
76
77 QFont statsFont = titleMessage->font();
78 statsFont.setWeight(QFont::Bold);
79
80 titleMessage->setFont( titleFont );
81 //--
82 //create stats
83 //--
84 numSubalbums = new QLabel( tr("Collections:"), this);
85 numSubalbums->setFont( statsFont );
86 numSubalbumsVal = new QLabel(this);
87 numSubalbumsVal->setText( QString("%1").arg(album->getNumSubalbums()) );
88 numSubalbumsVal->setFont( statsFont );
89 //--
90 numPhotos = new QLabel( tr("Photos:"), this);
91 numPhotos->setFont( statsFont );
92 numPhotosVal = new QLabel(this);
93 numPhotosVal->setText( QString("%1").arg(album->getNumPhotos()) );
94 numPhotosVal->setFont( statsFont );
95 //--
96 sizeOnDisk = new QLabel( tr("Size:"), this);
97 sizeOnDisk->setFont( statsFont );
98 sizeOnDiskVal = new QLabel(this);
99 sizeOnDiskVal->setFont( statsFont );
100 if(albumSize < 1024)
101 sizeOnDiskVal->setText( QString(tr("~%1 Bytes")).arg(albumSize) );
102 else if( albumSize/1024 < 1024)
103 sizeOnDiskVal->setText( QString(tr("~%1 Kb")).arg( ((float)albumSize)/1024 ) );
104 else if( albumSize/(1024*1024) < 1024)
105 sizeOnDiskVal->setText( QString(tr("~%1 Mb")).arg( ((float)albumSize)/(1024*1024) ) );
106 else
107 sizeOnDiskVal->setText( QString(tr("~%1 Gigs")).arg( ((float)albumSize)/(1024*1024*1024) ) );
108 //--
109 QString months[] = { tr("January"),
110 tr("February"),
111 tr("March"),
112 tr("April"),
113 tr("May"),
114 tr("June"),
115 tr("July"),
116 tr("August"),
117 tr("September"),
118 tr("October"),
119 tr("November"),
120 tr("December") };
121
122 created = new QLabel( tr("Created:"), this);
123 created->setFont( statsFont );
124 QString cVal = QString("%1 %2").arg(months[album->getCreationMonth()-1]).arg(album->getCreationDay());
125 if(album->getCreationDay() == 1 ||
126 album->getCreationDay() == 21 ||
127 album->getCreationDay() == 31)
128 cVal = cVal + "st";
129 else if(album->getCreationDay() == 2 ||
130 album->getCreationDay() == 22)
131 cVal = cVal + "nd";
132 else if(album->getCreationDay() == 3 ||
133 album->getCreationDay() == 23)
134 cVal = cVal + "rd";
135 else
136 cVal = cVal + "th";
137 cVal = QString("%1, %2").arg(cVal).arg(album->getCreationYear());
138
139 createdVal = new QLabel( cVal, this );
140 createdVal->setFont( statsFont );
141
142 modified = new QLabel( tr("Modified:"), this);
143 modified->setFont( statsFont );
144 QString mVal = QString("%1 %2").arg(months[album->getModificationMonth()-1]).arg(album->getModificationDay());
145
146 if(album->getModificationDay() == 1 ||
147 album->getModificationDay() == 21 ||
148 album->getModificationDay() == 31)
149 mVal = mVal + "st";
150 else if(album->getModificationDay() == 2 ||
151 album->getModificationDay() == 22)
152 mVal = mVal + "nd";
153 else if(album->getModificationDay() == 3 ||
154 album->getModificationDay() == 23)
155 mVal = mVal + "rd";
156 else
157 mVal = mVal + "th";
158 mVal = QString("%1, %2").arg(mVal).arg(album->getModificationYear());
159 modifiedVal = new QLabel( mVal, this );
160 modifiedVal->setFont( statsFont );
161 //--
162 //create album image and title labels
163 albumPreview = new Q3Frame( this );
165
166 //if no rep image use small version
168 {
169 QImage tImage = album->getRepresentativeImage( LARGE )->convertToImage();
170 int newWidth, newHeight;
171 calcScaledImageDimensions( tImage.width(), tImage.height(),
172 300, 300,
173 newWidth, newHeight);
174 QImage tImage2 = tImage.smoothScale( newWidth, newHeight );
175 albumImage = new QPixmap( newWidth, newHeight );
176 albumImage->convertFromImage( tImage2 );
177 albumIcon->setPixmap( *albumImage );
178 }
179
181 if(album->getName().compare("") != 0)
182 {
183 albumTitle->setText( "\"" + album->getName() + "\"" );
184 }
185 albumTitle->setFont( statsFont );
186 //--
187 //create close button
188 closeButton = new QPushButton( tr("Close"), this );
189 closeButton->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
190 closeButton->setDefault(true);
191 closeButton->setFocus();
192 connect( closeButton, SIGNAL(clicked()), SLOT(close()) );
193 //--
194 setPaletteBackgroundColor( darkBlue );
195 titleMessage->setPaletteForegroundColor( white );
196 titleMessage->setPaletteBackgroundColor( darkBlue );
197 numSubalbums->setPaletteForegroundColor( white );
198 numSubalbums->setPaletteBackgroundColor( darkBlue );
199 numSubalbumsVal->setPaletteForegroundColor( white );
200 numSubalbumsVal->setPaletteBackgroundColor( darkBlue );
201 numPhotos->setPaletteForegroundColor( white );
202 numPhotos->setPaletteBackgroundColor( darkBlue );
203 numPhotosVal->setPaletteForegroundColor( white );
204 numPhotosVal->setPaletteBackgroundColor( darkBlue );
205 sizeOnDisk->setPaletteForegroundColor( white );
206 sizeOnDisk->setPaletteBackgroundColor( darkBlue );
207 sizeOnDiskVal->setPaletteForegroundColor( white );
208 sizeOnDiskVal->setPaletteBackgroundColor( darkBlue );
209 created->setPaletteForegroundColor( white );
210 created->setPaletteBackgroundColor( darkBlue );
211 createdVal->setPaletteForegroundColor( white );
212 createdVal->setPaletteBackgroundColor( darkBlue );
213 modified->setPaletteForegroundColor( white );
214 modified->setPaletteBackgroundColor( darkBlue );
215 modifiedVal->setPaletteForegroundColor( white );
216 modifiedVal->setPaletteBackgroundColor( darkBlue );
217 albumTitle->setPaletteForegroundColor( white );
218 albumTitle->setPaletteBackgroundColor( darkBlue );
219 albumPreview->setPaletteBackgroundColor( darkBlue );
220 closeButton->setEraseColor(darkBlue);
221 //--
222 //place widgets in grid
223 grid = new Q3GridLayout( this, 10, 3, 0);
224 grid->setMargin(WIDGET_SPACING);
225 grid->setSpacing(WIDGET_SPACING);
226
227 grid->addRowSpacing( 0, 10 );
228 grid->setRowStretch( 0, 1 );
229
230 //add statistics text
231 grid->addMultiCellWidget( titleMessage, 1, 1, 0, 1, Qt::AlignCenter);
232
233 //add space between "Album Statistics" text and actual statistics
234 grid->addRowSpacing( 2, 10 );
235 grid->setRowStretch( 2, 1 );
236
237 grid->addWidget( numSubalbums, 3, 0 );
238 grid->addWidget( numSubalbumsVal, 3, 1, Qt::AlignRight );
239 grid->addWidget( numPhotos, 4, 0 );
240 grid->addWidget( numPhotosVal, 4, 1, Qt::AlignRight );
241 grid->addWidget( sizeOnDisk, 5, 0 );
242 grid->addWidget( sizeOnDiskVal, 5, 1, Qt::AlignRight );
243 grid->addWidget( created, 6,0 );
244 grid->addWidget( createdVal, 6, 1, Qt::AlignRight );
245 grid->addWidget( modified, 7,0 );
246 grid->addWidget( modifiedVal, 7, 1, Qt::AlignRight );
247
248 grid->setRowStretch( 8, 1 );
249
250
251 //add album image and name
252 grid2 = new Q3GridLayout( albumPreview, 2, 1, 0 );
253 grid2->setSpacing(WIDGET_SPACING);
254
255 grid2->addWidget( albumIcon, 0, 0, Qt::AlignCenter );
256 grid2->addWidget( albumTitle, 1, 0, Qt::AlignCenter );
257 grid->addMultiCellWidget( albumPreview, 0,8, 2, 2, Qt::AlignCenter );
258
259 //add ok button
260 grid->addMultiCellWidget( closeButton, 9,9, 0, 2, Qt::AlignCenter );
261 //--
262 //set window to not be resizeable
263 show();
264 setFixedSize(size());
265 //-------------------------------
266}
267//==============================================
272//==============================================
273void AlbumStatistics::closeEvent( QCloseEvent* e)
274{
275 QWidget::closeEvent( e );
276 emit closed();
277}
278//==============================================
280{
281 QDialog::reject();
282 emit closed();
283}
284//==============================================
#define LARGE
Definition album.h:19
QLabel * numSubalbumsVal
void closeEvent(QCloseEvent *e)
AlbumStatistics(Album *album, QWidget *parent=0, const char *name=0)
Q3GridLayout * grid2
Q3GridLayout * grid
Q3Frame * albumPreview
QPushButton * closeButton
Close button.
An album contains Subalbums.
Definition album.h:53
int getModificationDay()
Returns the last modified day.
Definition album.cpp:118
Subalbum * getFirstSubalbum()
Returns a pointer to the first Subalbum.
Definition album.cpp:135
int getCreationDay()
Returnst he creation day.
Definition album.cpp:122
int getModificationYear()
Returns the last modified year.
Definition album.cpp:116
int getNumSubalbums()
Returns number of subalbums.
Definition album.cpp:144
int getModificationMonth()
Returns the last modified month.
Definition album.cpp:117
int getCreationMonth()
Returns the creation month.
Definition album.cpp:121
int getNumPhotos()
Returns the number of photos.
Definition album.cpp:146
int getCreationYear()
Returns the creation year.
Definition album.cpp:120
QString getName()
Gets the album name.
Definition album.cpp:124
QPixmap * getRepresentativeImage(int size)
Returns the representative image.
Definition album.cpp:128
A photo consists of a full size image, a smaller slide show image, a very small thumbnail image,...
Definition photo.h:45
Photo * getNext()
Returns next photo pointer.
Definition photo.cpp:225
QString getImageFilename()
Gets the image filename.
Definition photo.cpp:192
QString getSlideshowFilename()
Gets the slideshow filename.
Definition photo.cpp:193
A subalbum contains photos.
Definition subalbum.h:49
Subalbum * getNext()
Returns pointer to next subalbum.
Definition subalbum.cpp:98
Photo * getFirst()
Returns first photo in subalbum.
Definition subalbum.cpp:100
#define WIDGET_SPACING
Definition config.h:31
void calcScaledImageDimensions(int origWidth, int origHeight, int idealWidth, int idealHeight, int &width, int &height)
Computes scale of image dimensions while respecting aspect ratio, equivalent to a QImage::scaleMin wi...