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
)
32 * Return desired size of the whole cell
34 QSize
ThumbnailView::CellGeometry::cellSize() const
36 int width
= Settings::SettingsData::instance()->thumbSize();
39 switch (Settings::SettingsData::instance()->thumbnailAspectRatio()) {
40 case Settings::Aspect_16_9
:
41 height
= (int) (height
* 9.0 / 16);
43 case Settings::Aspect_4_3
:
44 height
= (int) (height
* 3.0 / 4);
46 case Settings::Aspect_3_2
:
47 height
= (int) (height
* 2.0 / 3);
49 case Settings::Aspect_9_16
:
50 width
= (int) (width
* 9.0 / 16);
52 case Settings::Aspect_3_4
:
53 width
= (int) (width
* 3.0 / 4);
55 case Settings::Aspect_2_3
:
56 width
= (int) (width
* 2.0 / 3);
58 case Settings::Aspect_1_1
:
62 return QSize( width
, height
);
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
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
;
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() );
93 * return the number of categories with valies in for the given image.
95 static int noOfCategoriesForImage(const DB::ResultId
& image
)
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()) {
113 * Return the height of the text under the thumbnails.
115 int ThumbnailView::CellGeometry::textHeight( int charHeight
, bool reCalc
) const
118 static int maxCatsInText
= 0;
120 if ( Settings::SettingsData::instance()->displayLabels() )
122 if ( Settings::SettingsData::instance()->displayCategories()) {
125 Q_FOREACH(DB::ResultId id
, model()->imageList(ViewOrder
)) {
126 maxCatsInText
= qMax( noOfCategoriesForImage(id
), maxCatsInText
);
129 h
+= charHeight
* ( maxCatsInText
) +5;