Kraxy/EBN: missing Q_OBJECT
[kphotoalbum.git] / ThumbnailView / CellGeometry.cpp
blob086f6220fbe07a2644f5638c783697c7520311e2
1 /* Copyright (C) 2003-2009 Jesper K. Pedersen <blackie@kde.org>
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public
5 License as published by the Free Software Foundation; either
6 version 2 of the License, or (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; see the file COPYING. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
18 #include "CellGeometry.h"
19 #include "ThumbnailCache.h"
20 #include "ThumbnailModel.h"
21 #include "DB/ResultId.h"
22 #include "Settings/SettingsData.h"
24 using Utilities::StringSet;
26 ThumbnailView::CellGeometry::CellGeometry( ThumbnailFactory* factory )
27 :ThumbnailComponent(factory)
31 /**
32 * Return desired size of the whole cell
34 QSize ThumbnailView::CellGeometry::cellSize() const
36 int width = Settings::SettingsData::instance()->thumbSize();
37 int height = width;
39 switch (Settings::SettingsData::instance()->thumbnailAspectRatio()) {
40 case Settings::Aspect_16_9:
41 height = (int) (height * 9.0 / 16);
42 break;
43 case Settings::Aspect_4_3:
44 height = (int) (height * 3.0 / 4);
45 break;
46 case Settings::Aspect_3_2:
47 height = (int) (height * 2.0 / 3);
48 break;
49 case Settings::Aspect_9_16:
50 width = (int) (width * 9.0 / 16);
51 break;
52 case Settings::Aspect_3_4:
53 width = (int) (width * 3.0 / 4);
54 break;
55 case Settings::Aspect_2_3:
56 width = (int) (width * 2.0 / 3);
57 break;
58 case Settings::Aspect_1_1:
59 // nothing
62 return QSize( width, height);
66 /**
67 * Return the geometry for the icon in the cell (row,col). The returned coordinates are local to the cell.
69 QRect ThumbnailView::CellGeometry::iconGeometry( int row, int col ) const
71 DB::ResultId mediaId = model()->imageAt( row, col );
72 if ( mediaId.isNull() ) // empty cell
73 return QRect();
75 const QSize cellSize = this->cellSize();
76 const int space = Settings::SettingsData::instance()->thumbnailSpace();
77 int width = cellSize.width() - 2 * space;
78 int height = cellSize.height() - 2 * space;
80 QPixmap pixmap;
81 if (!cache()->find(mediaId, &pixmap)
82 || (pixmap.width() == 0 && pixmap.height() == 0)) {
83 return QRect( space, space, width, height );
86 int xoff = space + (width - pixmap.width()) / 2;
87 int yoff = space + (height - pixmap.height()) / 2;
89 return QRect( xoff, yoff, pixmap.width(), pixmap.height() );
92 /**
93 * return the number of categories with valies in for the given image.
95 static int noOfCategoriesForImage(const DB::ResultId& image )
97 int catsInText = 0;
98 QStringList grps = image.fetchInfo()->availableCategories();
99 for( QStringList::const_iterator it = grps.constBegin(); it != grps.constEnd(); ++it ) {
100 QString category = *it;
101 if ( category != QString::fromLatin1( "Folder" ) && category != QString::fromLatin1( "Media Type" ) ) {
102 StringSet items = image.fetchInfo()->itemsOfCategory( category );
103 if (!items.empty()) {
104 catsInText++;
108 return catsInText;
113 * Return the height of the text under the thumbnails.
115 int ThumbnailView::CellGeometry::textHeight( int charHeight, bool reCalc ) const
117 int h = 0;
118 static int maxCatsInText = 0;
120 if ( Settings::SettingsData::instance()->displayLabels() )
121 h += charHeight +2;
122 if ( Settings::SettingsData::instance()->displayCategories()) {
123 if ( reCalc ) {
124 maxCatsInText = 0;
125 Q_FOREACH(DB::ResultId id, model()->imageList(ViewOrder)) {
126 maxCatsInText = qMax( noOfCategoriesForImage(id), maxCatsInText);
129 h += charHeight * ( maxCatsInText ) +5;
131 return h;