~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to core/utilities/cameragui/views/cameraiconviewtooltip.cpp

  • Committer: Package Import Robot
  • Author(s): Felix Geyer, Rohan Garg, Philip Muškovac, Felix Geyer
  • Date: 2011-09-23 18:18:55 UTC
  • mfrom: (1.2.36 upstream)
  • Revision ID: package-import@ubuntu.com-20110923181855-ifs67wxkugshev9k
Tags: 2:2.1.1-0ubuntu1
[ Rohan Garg ]
* New upstream release (LP: #834190)
  - debian/control
    + Build with libqtwebkit-dev
 - debian/kipi-plugins-common
    + Install libkvkontakte required by kipi-plugins
 - debian/digikam
    + Install panoramagui

[ Philip Muškovac ]
* New upstream release
  - debian/control:
    + Add libcv-dev, libcvaux-dev, libhighgui-dev, libboost-graph1.46-dev,
      libksane-dev, libxml2-dev, libxslt-dev, libqt4-opengl-dev, libqjson-dev,
      libgpod-dev and libqca2-dev to build-deps
    + Add packages for kipi-plugins, libmediawiki, libkface, libkgeomap and
      libkvkontakte
  - debian/rules:
    + Don't build with gphoto2 since it doesn't build with it.
  - Add kubuntu_fix_test_linking.diff to fix linking of the dngconverter test
  - update install files
  - update kubuntu_01_mysqld_executable_name.diff for new cmake layout
    and rename to kubuntu_mysqld_executable_name.diff
* Fix typo in digikam-data description (LP: #804894)
* Fix Vcs links

[ Felix Geyer ]
* Move library data files to the new packages libkface-data, libkgeomap-data
  and libkvkontakte-data.
* Override version of the embedded library packages to 1.0~digikam<version>.
* Exclude the library packages from digikam-dbg to prevent file conflicts in
  the future.
* Call dh_install with --list-missing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ============================================================
 
2
 *
 
3
 * This file is a part of digiKam project
 
4
 * http://www.digikam.org
 
5
 *
 
6
 * Date        : 2008-12-17
 
7
 * Description : camera icon view tool tip
 
8
 *
 
9
 * Copyright (C) 2008-2011 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
10
 *
 
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)
 
15
 * any later version.
 
16
 *
 
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.
 
21
 *
 
22
 * ============================================================ */
 
23
 
 
24
#include "cameraiconviewtooltip.h"
 
25
 
 
26
// Qt includes
 
27
 
 
28
#include <QPixmap>
 
29
#include <QPainter>
 
30
#include <QTextDocument>
 
31
#include <QDateTime>
 
32
 
 
33
// KDE includes
 
34
 
 
35
 
 
36
#include <klocale.h>
 
37
#include <kfileitem.h>
 
38
#include <kglobal.h>
 
39
#include <kdeversion.h>
 
40
#include <kmimetype.h>
 
41
 
 
42
// Local includes
 
43
 
 
44
#include "cameraiconview.h"
 
45
#include "cameraiconitem.h"
 
46
#include "albumsettings.h"
 
47
 
 
48
namespace Digikam
 
49
{
 
50
 
 
51
class CameraIconViewToolTip::CameraIconViewToolTipPriv
 
52
{
 
53
public:
 
54
 
 
55
    CameraIconViewToolTipPriv() :
 
56
        view(0),
 
57
        iconItem(0)
 
58
    {
 
59
    }
 
60
 
 
61
    CameraIconView* view;
 
62
    CameraIconItem* iconItem;
 
63
};
 
64
 
 
65
CameraIconViewToolTip::CameraIconViewToolTip(CameraIconView* view)
 
66
    : DItemToolTip(), d(new CameraIconViewToolTipPriv)
 
67
{
 
68
    d->view = view;
 
69
}
 
70
 
 
71
CameraIconViewToolTip::~CameraIconViewToolTip()
 
72
{
 
73
    delete d;
 
74
}
 
75
 
 
76
void CameraIconViewToolTip::setIconItem(CameraIconItem* iconItem)
 
77
{
 
78
    d->iconItem = iconItem;
 
79
 
 
80
    if (!d->iconItem ||
 
81
        !AlbumSettings::instance()->showToolTipsIsValid())
 
82
    {
 
83
        hide();
 
84
    }
 
85
    else
 
86
    {
 
87
        updateToolTip();
 
88
        reposition();
 
89
 
 
90
        if (isHidden() && !toolTipIsEmpty())
 
91
        {
 
92
            show();
 
93
        }
 
94
    }
 
95
}
 
96
 
 
97
QRect CameraIconViewToolTip::repositionRect()
 
98
{
 
99
    if (!d->iconItem)
 
100
    {
 
101
        return QRect();
 
102
    }
 
103
 
 
104
    QRect rect = d->iconItem->clickToOpenRect();
 
105
    rect.moveTopLeft(d->view->contentsToViewport(rect.topLeft()));
 
106
    rect.moveTopLeft(d->view->viewport()->mapToGlobal(rect.topLeft()));
 
107
    return rect;
 
108
}
 
109
 
 
110
QString CameraIconViewToolTip::tipContents()
 
111
{
 
112
    if (!d->iconItem)
 
113
    {
 
114
        return QString();
 
115
    }
 
116
 
 
117
    CamItemInfo info = d->iconItem->itemInfo();
 
118
    return fillTipContents(info);
 
119
}
 
120
 
 
121
QString CameraIconViewToolTip::fillTipContents(const CamItemInfo& info) const
 
122
{
 
123
    QString            str;
 
124
    AlbumSettings*     settings = AlbumSettings::instance();
 
125
    DToolTipStyleSheet cnt(settings->getToolTipsFont());
 
126
 
 
127
    QString tip                  = cnt.tipHeader;
 
128
    PhotoInfoContainer photoInfo = info.photoInfo;
 
129
 
 
130
    // -- File properties ----------------------------------------------
 
131
 
 
132
    if (settings->getToolTipsShowFileName()  ||
 
133
        settings->getToolTipsShowFileDate()  ||
 
134
        settings->getToolTipsShowFileSize()  ||
 
135
        settings->getToolTipsShowImageType() ||
 
136
        settings->getToolTipsShowImageDim())
 
137
    {
 
138
        tip += cnt.headBeg + i18n("File Properties") + cnt.headEnd;
 
139
 
 
140
        if (settings->getToolTipsShowFileName())
 
141
        {
 
142
            tip += cnt.cellBeg + i18n("Name:") + cnt.cellMid;
 
143
            tip += info.name + cnt.cellEnd;
 
144
        }
 
145
 
 
146
        if (settings->getToolTipsShowFileDate())
 
147
        {
 
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;
 
151
        }
 
152
 
 
153
        if (settings->getToolTipsShowFileSize())
 
154
        {
 
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;
 
159
        }
 
160
 
 
161
        if (settings->getToolTipsShowImageType())
 
162
        {
 
163
            KMimeType::Ptr mt = KMimeType::mimeType(info.mime);
 
164
 
 
165
            if (mt)
 
166
            {
 
167
                tip += cnt.cellBeg + i18n("Type:") + cnt.cellMid + mt->comment() + cnt.cellEnd;
 
168
            }
 
169
        }
 
170
 
 
171
        if (settings->getToolTipsShowImageDim())
 
172
        {
 
173
            if (info.width == -1 || info.height == -1)
 
174
            {
 
175
                str = i18n("Unknown");
 
176
            }
 
177
            else
 
178
            {
 
179
                QString mpixels;
 
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);
 
183
            }
 
184
 
 
185
            tip += cnt.cellBeg + i18n("Dimensions:") + cnt.cellMid + str + cnt.cellEnd;
 
186
        }
 
187
    }
 
188
 
 
189
    // -- Photograph Info ----------------------------------------------------
 
190
 
 
191
    if (settings->getToolTipsShowPhotoMake()  ||
 
192
        settings->getToolTipsShowPhotoDate()  ||
 
193
        settings->getToolTipsShowPhotoFocal() ||
 
194
        settings->getToolTipsShowPhotoExpo()  ||
 
195
        settings->getToolTipsShowPhotoMode()  ||
 
196
        settings->getToolTipsShowPhotoFlash() ||
 
197
        settings->getToolTipsShowPhotoWB())
 
198
    {
 
199
        if (!photoInfo.isEmpty())
 
200
        {
 
201
            QString metaStr;
 
202
            tip += cnt.headBeg + i18n("Photograph Properties") + cnt.headEnd;
 
203
 
 
204
            if (settings->getToolTipsShowPhotoMake())
 
205
            {
 
206
                str = QString("%1 / %2").arg(photoInfo.make.isEmpty() ? cnt.unavailable : photoInfo.make)
 
207
                      .arg(photoInfo.model.isEmpty() ? cnt.unavailable : photoInfo.model);
 
208
 
 
209
                if (str.length() > cnt.maxStringLength)
 
210
                {
 
211
                    str = str.left(cnt.maxStringLength-3) + "...";
 
212
                }
 
213
 
 
214
                metaStr += cnt.cellBeg + i18n("Make/Model:") + cnt.cellMid + Qt::escape(str) + cnt.cellEnd;
 
215
            }
 
216
 
 
217
            if (settings->getToolTipsShowPhotoDate())
 
218
            {
 
219
                if (photoInfo.dateTime.isValid())
 
220
                {
 
221
                    str = KGlobal::locale()->formatDateTime(photoInfo.dateTime, KLocale::ShortDate, true);
 
222
 
 
223
                    if (str.length() > cnt.maxStringLength)
 
224
                    {
 
225
                        str = str.left(cnt.maxStringLength-3) + "...";
 
226
                    }
 
227
 
 
228
                    metaStr += cnt.cellBeg + i18n("Created:") + cnt.cellMid + Qt::escape(str) + cnt.cellEnd;
 
229
                }
 
230
                else
 
231
                {
 
232
                    metaStr += cnt.cellBeg + i18n("Created:") + cnt.cellMid + Qt::escape(cnt.unavailable) + cnt.cellEnd;
 
233
                }
 
234
            }
 
235
 
 
236
            if (settings->getToolTipsShowPhotoFocal())
 
237
            {
 
238
                str = photoInfo.aperture.isEmpty() ? cnt.unavailable : photoInfo.aperture;
 
239
 
 
240
                if (photoInfo.focalLength35mm.isEmpty())
 
241
                {
 
242
                    str += QString(" / %1").arg(photoInfo.focalLength.isEmpty() ? cnt.unavailable : photoInfo.focalLength);
 
243
                }
 
244
                else
 
245
                    str += QString(" / %1").arg(i18n("%1 (35mm: %2)",
 
246
                                                     photoInfo.focalLength, photoInfo.focalLength35mm));
 
247
 
 
248
                if (str.length() > cnt.maxStringLength)
 
249
                {
 
250
                    str = str.left(cnt.maxStringLength-3) + "...";
 
251
                }
 
252
 
 
253
                metaStr += cnt.cellBeg + i18n("Aperture/Focal:") + cnt.cellMid + Qt::escape(str) + cnt.cellEnd;
 
254
            }
 
255
 
 
256
            if (settings->getToolTipsShowPhotoExpo())
 
257
            {
 
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));
 
262
 
 
263
                if (str.length() > cnt.maxStringLength)
 
264
                {
 
265
                    str = str.left(cnt.maxStringLength-3) + "...";
 
266
                }
 
267
 
 
268
                metaStr += cnt.cellBeg + i18n("Exposure/Sensitivity:") + cnt.cellMid + Qt::escape(str) + cnt.cellEnd;
 
269
            }
 
270
 
 
271
            if (settings->getToolTipsShowPhotoMode())
 
272
            {
 
273
                if (photoInfo.exposureMode.isEmpty() && photoInfo.exposureProgram.isEmpty())
 
274
                {
 
275
                    str = cnt.unavailable;
 
276
                }
 
277
                else if (!photoInfo.exposureMode.isEmpty() && photoInfo.exposureProgram.isEmpty())
 
278
                {
 
279
                    str = photoInfo.exposureMode;
 
280
                }
 
281
                else if (photoInfo.exposureMode.isEmpty() && !photoInfo.exposureProgram.isEmpty())
 
282
                {
 
283
                    str = photoInfo.exposureProgram;
 
284
                }
 
285
                else
 
286
                {
 
287
                    str = QString("%1 / %2").arg(photoInfo.exposureMode).arg(photoInfo.exposureProgram);
 
288
                }
 
289
 
 
290
                if (str.length() > cnt.maxStringLength)
 
291
                {
 
292
                    str = str.left(cnt.maxStringLength-3) + "...";
 
293
                }
 
294
 
 
295
                metaStr += cnt.cellBeg + i18n("Mode/Program:") + cnt.cellMid + Qt::escape(str) + cnt.cellEnd;
 
296
            }
 
297
 
 
298
            if (settings->getToolTipsShowPhotoFlash())
 
299
            {
 
300
                str = photoInfo.flash.isEmpty() ? cnt.unavailable : photoInfo.flash;
 
301
 
 
302
                if (str.length() > cnt.maxStringLength)
 
303
                {
 
304
                    str = str.left(cnt.maxStringLength-3) + "...";
 
305
                }
 
306
 
 
307
                metaStr += cnt.cellBeg + i18n("Flash:") + cnt.cellMid + Qt::escape(str) + cnt.cellEnd;
 
308
            }
 
309
 
 
310
            if (settings->getToolTipsShowPhotoWB())
 
311
            {
 
312
                str = photoInfo.whiteBalance.isEmpty() ? cnt.unavailable : photoInfo.whiteBalance;
 
313
 
 
314
                if (str.length() > cnt.maxStringLength)
 
315
                {
 
316
                    str = str.left(cnt.maxStringLength-3) + "...";
 
317
                }
 
318
 
 
319
                metaStr += cnt.cellBeg + i18n("White Balance:") + cnt.cellMid + Qt::escape(str) + cnt.cellEnd;
 
320
            }
 
321
 
 
322
            tip += metaStr;
 
323
        }
 
324
    }
 
325
 
 
326
    tip += cnt.tipFooter;
 
327
 
 
328
    return tip;
 
329
}
 
330
 
 
331
}  // namespace Digikam