1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : camera icon view tool tip
9
* Copyright (C) 2008-2011 by Gilles Caulier <caulier dot gilles at gmail dot com>
11
* This program is free software; you can redistribute it
12
* and/or modify it under the terms of the GNU General
13
* Public License as published by the Free Software Foundation;
14
* either version 2, or (at your option)
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* ============================================================ */
24
#include "cameraiconviewtooltip.h"
30
#include <QTextDocument>
37
#include <kfileitem.h>
39
#include <kdeversion.h>
40
#include <kmimetype.h>
44
#include "cameraiconview.h"
45
#include "cameraiconitem.h"
46
#include "albumsettings.h"
51
class CameraIconViewToolTip::CameraIconViewToolTipPriv
55
CameraIconViewToolTipPriv() :
62
CameraIconItem* iconItem;
65
CameraIconViewToolTip::CameraIconViewToolTip(CameraIconView* view)
66
: DItemToolTip(), d(new CameraIconViewToolTipPriv)
71
CameraIconViewToolTip::~CameraIconViewToolTip()
76
void CameraIconViewToolTip::setIconItem(CameraIconItem* iconItem)
78
d->iconItem = iconItem;
81
!AlbumSettings::instance()->showToolTipsIsValid())
90
if (isHidden() && !toolTipIsEmpty())
97
QRect CameraIconViewToolTip::repositionRect()
104
QRect rect = d->iconItem->clickToOpenRect();
105
rect.moveTopLeft(d->view->contentsToViewport(rect.topLeft()));
106
rect.moveTopLeft(d->view->viewport()->mapToGlobal(rect.topLeft()));
110
QString CameraIconViewToolTip::tipContents()
117
CamItemInfo info = d->iconItem->itemInfo();
118
return fillTipContents(info);
121
QString CameraIconViewToolTip::fillTipContents(const CamItemInfo& info) const
124
AlbumSettings* settings = AlbumSettings::instance();
125
DToolTipStyleSheet cnt(settings->getToolTipsFont());
127
QString tip = cnt.tipHeader;
128
PhotoInfoContainer photoInfo = info.photoInfo;
130
// -- File properties ----------------------------------------------
132
if (settings->getToolTipsShowFileName() ||
133
settings->getToolTipsShowFileDate() ||
134
settings->getToolTipsShowFileSize() ||
135
settings->getToolTipsShowImageType() ||
136
settings->getToolTipsShowImageDim())
138
tip += cnt.headBeg + i18n("File Properties") + cnt.headEnd;
140
if (settings->getToolTipsShowFileName())
142
tip += cnt.cellBeg + i18n("Name:") + cnt.cellMid;
143
tip += info.name + cnt.cellEnd;
146
if (settings->getToolTipsShowFileDate())
148
QDateTime creatededDate = info.mtime;
149
str = KGlobal::locale()->formatDateTime(creatededDate, KLocale::ShortDate, true);
150
tip += cnt.cellBeg + i18n("Date:") + cnt.cellMid + str + cnt.cellEnd;
153
if (settings->getToolTipsShowFileSize())
155
tip += cnt.cellBeg + i18n("Size:") + cnt.cellMid;
156
str = i18n("%1 (%2)", KIO::convertSize(info.size),
157
KGlobal::locale()->formatNumber(info.size, 0));
158
tip += str + cnt.cellEnd;
161
if (settings->getToolTipsShowImageType())
163
KMimeType::Ptr mt = KMimeType::mimeType(info.mime);
167
tip += cnt.cellBeg + i18n("Type:") + cnt.cellMid + mt->comment() + cnt.cellEnd;
171
if (settings->getToolTipsShowImageDim())
173
if (info.width == -1 || info.height == -1)
175
str = i18n("Unknown");
180
mpixels.setNum(info.width*info.height/1000000.0, 'f', 2);
181
str = i18nc("width x height (megapixels Mpx)", "%1x%2 (%3Mpx)",
182
info.width, info.height, mpixels);
185
tip += cnt.cellBeg + i18n("Dimensions:") + cnt.cellMid + str + cnt.cellEnd;
189
// -- Photograph Info ----------------------------------------------------
191
if (settings->getToolTipsShowPhotoMake() ||
192
settings->getToolTipsShowPhotoDate() ||
193
settings->getToolTipsShowPhotoFocal() ||
194
settings->getToolTipsShowPhotoExpo() ||
195
settings->getToolTipsShowPhotoMode() ||
196
settings->getToolTipsShowPhotoFlash() ||
197
settings->getToolTipsShowPhotoWB())
199
if (!photoInfo.isEmpty())
202
tip += cnt.headBeg + i18n("Photograph Properties") + cnt.headEnd;
204
if (settings->getToolTipsShowPhotoMake())
206
str = QString("%1 / %2").arg(photoInfo.make.isEmpty() ? cnt.unavailable : photoInfo.make)
207
.arg(photoInfo.model.isEmpty() ? cnt.unavailable : photoInfo.model);
209
if (str.length() > cnt.maxStringLength)
211
str = str.left(cnt.maxStringLength-3) + "...";
214
metaStr += cnt.cellBeg + i18n("Make/Model:") + cnt.cellMid + Qt::escape(str) + cnt.cellEnd;
217
if (settings->getToolTipsShowPhotoDate())
219
if (photoInfo.dateTime.isValid())
221
str = KGlobal::locale()->formatDateTime(photoInfo.dateTime, KLocale::ShortDate, true);
223
if (str.length() > cnt.maxStringLength)
225
str = str.left(cnt.maxStringLength-3) + "...";
228
metaStr += cnt.cellBeg + i18n("Created:") + cnt.cellMid + Qt::escape(str) + cnt.cellEnd;
232
metaStr += cnt.cellBeg + i18n("Created:") + cnt.cellMid + Qt::escape(cnt.unavailable) + cnt.cellEnd;
236
if (settings->getToolTipsShowPhotoFocal())
238
str = photoInfo.aperture.isEmpty() ? cnt.unavailable : photoInfo.aperture;
240
if (photoInfo.focalLength35mm.isEmpty())
242
str += QString(" / %1").arg(photoInfo.focalLength.isEmpty() ? cnt.unavailable : photoInfo.focalLength);
245
str += QString(" / %1").arg(i18n("%1 (35mm: %2)",
246
photoInfo.focalLength, photoInfo.focalLength35mm));
248
if (str.length() > cnt.maxStringLength)
250
str = str.left(cnt.maxStringLength-3) + "...";
253
metaStr += cnt.cellBeg + i18n("Aperture/Focal:") + cnt.cellMid + Qt::escape(str) + cnt.cellEnd;
256
if (settings->getToolTipsShowPhotoExpo())
258
str = QString("%1 / %2").arg(photoInfo.exposureTime.isEmpty() ? cnt.unavailable :
259
photoInfo.exposureTime)
260
.arg(photoInfo.sensitivity.isEmpty() ? cnt.unavailable :
261
i18n("%1 ISO", photoInfo.sensitivity));
263
if (str.length() > cnt.maxStringLength)
265
str = str.left(cnt.maxStringLength-3) + "...";
268
metaStr += cnt.cellBeg + i18n("Exposure/Sensitivity:") + cnt.cellMid + Qt::escape(str) + cnt.cellEnd;
271
if (settings->getToolTipsShowPhotoMode())
273
if (photoInfo.exposureMode.isEmpty() && photoInfo.exposureProgram.isEmpty())
275
str = cnt.unavailable;
277
else if (!photoInfo.exposureMode.isEmpty() && photoInfo.exposureProgram.isEmpty())
279
str = photoInfo.exposureMode;
281
else if (photoInfo.exposureMode.isEmpty() && !photoInfo.exposureProgram.isEmpty())
283
str = photoInfo.exposureProgram;
287
str = QString("%1 / %2").arg(photoInfo.exposureMode).arg(photoInfo.exposureProgram);
290
if (str.length() > cnt.maxStringLength)
292
str = str.left(cnt.maxStringLength-3) + "...";
295
metaStr += cnt.cellBeg + i18n("Mode/Program:") + cnt.cellMid + Qt::escape(str) + cnt.cellEnd;
298
if (settings->getToolTipsShowPhotoFlash())
300
str = photoInfo.flash.isEmpty() ? cnt.unavailable : photoInfo.flash;
302
if (str.length() > cnt.maxStringLength)
304
str = str.left(cnt.maxStringLength-3) + "...";
307
metaStr += cnt.cellBeg + i18n("Flash:") + cnt.cellMid + Qt::escape(str) + cnt.cellEnd;
310
if (settings->getToolTipsShowPhotoWB())
312
str = photoInfo.whiteBalance.isEmpty() ? cnt.unavailable : photoInfo.whiteBalance;
314
if (str.length() > cnt.maxStringLength)
316
str = str.left(cnt.maxStringLength-3) + "...";
319
metaStr += cnt.cellBeg + i18n("White Balance:") + cnt.cellMid + Qt::escape(str) + cnt.cellEnd;
326
tip += cnt.tipFooter;
331
} // namespace Digikam