~ubuntu-branches/ubuntu/feisty/digikam/feisty

« back to all changes in this revision

Viewing changes to digikam/utilities/cameragui/cameraiconitem.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2006-12-07 19:09:01 UTC
  • mfrom: (1.2.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20061207190901-h7wo0kj1wv9d5b46
Tags: 1:0.9.0~rc2-0ubuntu1
* New upstream release
* Sync packaging with debian
* Removed obsolete patches 10_kdesvn_606804_dcraw-return-code.diff
  and 11_kdesvn_606805_file-extention-parsing.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* ============================================================
2
 
 * Author: Renchi Raju <renchi@pooh.tam.uiuc.edu>
3
 
 * Date  : 2004-09-21
4
 
 * Description : 
 
2
 * Authors: Renchi Raju <renchi@pooh.tam.uiuc.edu>
 
3
 *          Gilles Caulier <caulier dot gilles at kdemail dot net> 
 
4
 * Date   : 2004-09-21
 
5
 * Description : camera icon view item 
5
6
 * 
6
 
 * Copyright 2004 by Renchi Raju
7
 
 
 
7
 * Copyright 2004-2005 by Renchi Raju
 
8
 * Copyright 2006 by Gilles Caulier
 
9
 *
8
10
 * This program is free software; you can redistribute it
9
11
 * and/or modify it under the terms of the GNU General
10
12
 * Public License as published by the Free Software Foundation;
18
20
 * 
19
21
 * ============================================================ */
20
22
 
 
23
// Qt includes.
 
24
 
21
25
#include <qpainter.h>
22
26
#include <qpixmap.h>
23
 
#include <iconview.h>
24
 
 
 
27
 
 
28
// KDE includes.
 
29
 
 
30
#include <kiconloader.h>
 
31
 
 
32
// Local includes.
 
33
 
 
34
#include "iconview.h"
 
35
#include "thumbnailsize.h"
 
36
#include "albumiconitem.h"
25
37
#include "gpiteminfo.h"
 
38
#include "themeengine.h"
 
39
#include "cameraiconview.h"
26
40
#include "cameraiconitem.h"
27
41
 
28
 
const char* CameraIconViewItem::new_xpm[] =
 
42
namespace Digikam
 
43
{
 
44
 
 
45
class CameraIconViewItemPriv
 
46
{
 
47
 
 
48
public:
 
49
 
 
50
    CameraIconViewItemPriv()
 
51
    {
 
52
        itemInfo            = 0;
 
53
        pixmapNewPicture    = QPixmap(newPicture_xpm);
 
54
        pixmapUnknowPicture = QPixmap(unknowPicture_xpm);
 
55
    }
 
56
 
 
57
    static const char *newPicture_xpm[];
 
58
    static const char *unknowPicture_xpm[];
 
59
 
 
60
    QString            downloadName;
 
61
 
 
62
    QPixmap            pixmap;
 
63
    QPixmap            pixmapNewPicture;
 
64
    QPixmap            pixmapUnknowPicture;
 
65
 
 
66
    QImage             thumbnail;
 
67
    
 
68
    QRect              pixRect;
 
69
    QRect              textRect;
 
70
    QRect              extraRect;
 
71
 
 
72
    GPItemInfo        *itemInfo;
 
73
};
 
74
 
 
75
const char *CameraIconViewItemPriv::newPicture_xpm[] =
29
76
{
30
77
    "13 13 8 1",
31
78
    "       c None",
51
98
    "      @      "
52
99
};
53
100
 
54
 
QPixmap* CameraIconViewItem::m_newEmblem = 0;
55
 
 
56
 
CameraIconViewItem::CameraIconViewItem(IconGroupItem* parent,
57
 
                                       const GPItemInfo& itemInfo,
58
 
                                       const QPixmap& pix,
59
 
                                       const QString& downloadName)
60
 
    : IconItem(parent)
61
 
{
62
 
    m_itemInfo     = new GPItemInfo(itemInfo);
63
 
    m_downloadName = downloadName;
64
 
    m_pixmap       = pix;
65
 
 
66
 
    calcRect();
 
101
const char *CameraIconViewItemPriv::unknowPicture_xpm[] = 
 
102
{
 
103
    "16 16 78 1",
 
104
    "   g None",
 
105
    ".  g #777777",
 
106
    "+  g #7A7A7A",
 
107
    "@  g #8C8C8C",
 
108
    "#  g #787878",
 
109
    "$  g #707070",
 
110
    "%  g #878787",
 
111
    "&  g #C3C3C3",
 
112
    "*  g #EAEAEA",
 
113
    "=  g #E4E4E4",
 
114
    "-  g #E2E2E2",
 
115
    ";  g #E6E6E6",
 
116
    ">  g #CECECE",
 
117
    ",  g #888888",
 
118
    "'  g #6B6B6B",
 
119
    ")  g #969696",
 
120
    "!  g #DEDEDE",
 
121
    "~  g #D8D8D8",
 
122
    "{  g #FFFFFF",
 
123
    "]  g #F2F2F2",
 
124
    "^  g #DFDFDF",
 
125
    "/  g #9D9D9D",
 
126
    "(  g #686868",
 
127
    "_  g #848484",
 
128
    ":  g #D0D0D0",
 
129
    "<  g #F1F1F1",
 
130
    "[  g #F0F0F0",
 
131
    "}  g #EBEBEB",
 
132
    "|  g #FDFDFD",
 
133
    "1  g #DDDDDD",
 
134
    "2  g #D4D4D4",
 
135
    "3  g #838383",
 
136
    "4  g #ABABAB",
 
137
    "5  g #C8C8C8",
 
138
    "6  g #CCCCCC",
 
139
    "7  g #F4F4F4",
 
140
    "8  g #D6D6D6",
 
141
    "9  g #E8E8E8",
 
142
    "0  g #C4C4C4",
 
143
    "a  g #A4A4A4",
 
144
    "b  g #656565",
 
145
    "c  g #B4B4B4",
 
146
    "d  g #B9B9B9",
 
147
    "e  g #BDBDBD",
 
148
    "f  g #B7B7B7",
 
149
    "g  g #898989",
 
150
    "h  g #6D6D6D",
 
151
    "i  g #808080",
 
152
    "j  g #AAAAAA",
 
153
    "k  g #A9A9A9",
 
154
    "l  g #737373",
 
155
    "m  g #7F7F7F",
 
156
    "n  g #9A9A9A",
 
157
    "o  g #D3D3D3",
 
158
    "p  g #909090",
 
159
    "q  g #727272",
 
160
    "r  g #8F8F8F",
 
161
    "s  g #8E8E8E",
 
162
    "t  g #8D8D8D",
 
163
    "u  g #EEEEEE",
 
164
    "v  g #FAFAFA",
 
165
    "w  g #929292",
 
166
    "x  g #C5C5C5",
 
167
    "y  g #5F5F5F",
 
168
    "z  g #989898",
 
169
    "A  g #CFCFCF",
 
170
    "B  g #9C9C9C",
 
171
    "C  g #A0A0A0",
 
172
    "D  g #FEFEFE",
 
173
    "E  g #ACACAC",
 
174
    "F  g #5E5E5E",
 
175
    "G  g #868686",
 
176
    "H  g #AFAFAF",
 
177
    "I  g #C1C1C1",
 
178
    "J  g #818181",
 
179
    "K  g #7E7E7E",
 
180
    "L  g #7B7B7B",
 
181
    "M  g #636363",
 
182
    "                ",
 
183
    "     .+@@#$     ",
 
184
    "   .%&*=-;>,'   ",
 
185
    "  .)!~={{]^-/(  ",
 
186
    "  _::<{[}|{123  ",
 
187
    " .456{7558{90ab ",
 
188
    " +cde96df={&g,h ",
 
189
    " ijjjjjk;{=@,,l ",
 
190
    " mnnnnno{-pgggq ",
 
191
    " #rprstuvwtttt' ",
 
192
    " $tpppp6xpppp@y ",
 
193
    "  mnnnzA~Bnnn.  ",
 
194
    "  'taaCD{Eaa,F  ",
 
195
    "   (GjHI0HjJF   ",
 
196
    "     (K,,LM     ",
 
197
    "                "
 
198
};
 
199
 
 
200
CameraIconViewItem::CameraIconViewItem(IconGroupItem* parent, const GPItemInfo& itemInfo,
 
201
                                       const QImage& thumbnail, const QString& downloadName)
 
202
                  : IconItem(parent)
 
203
{
 
204
    d = new CameraIconViewItemPriv;
 
205
    d->itemInfo     = new GPItemInfo(itemInfo);
 
206
    d->downloadName = downloadName;
 
207
    d->thumbnail    = thumbnail;
67
208
}
68
209
 
69
210
CameraIconViewItem::~CameraIconViewItem()
70
211
{
71
 
    delete m_itemInfo;
72
 
}
73
 
 
74
 
void CameraIconViewItem::setPixmap(const QPixmap& pixmap)
75
 
{
76
 
    m_pixmap = pixmap;
 
212
    delete d->itemInfo;
 
213
    delete d;
 
214
}
 
215
 
 
216
void CameraIconViewItem::setThumbnail(const QImage& thumbnail)
 
217
{
 
218
    d->thumbnail = thumbnail;
 
219
}
 
220
 
 
221
GPItemInfo* CameraIconViewItem::itemInfo() const
 
222
{
 
223
    return d->itemInfo; 
77
224
}
78
225
 
79
226
void CameraIconViewItem::paintItem()
80
227
{
81
 
    IconView* view = iconView();
82
 
    QColorGroup cg = view->colorGroup();
 
228
    CameraIconView* view = (CameraIconView*)iconView();
 
229
    QColorGroup cg       = view->colorGroup();
83
230
    QFont fn(view->font());
84
231
 
 
232
    QPixmap pix;
85
233
    QRect r(rect());
86
234
 
87
 
    QPixmap pix(r.width(), r.height());
88
 
    pix.fill(isSelected() ? view->colorGroup().highlight() :
89
 
             view->colorGroup().base());
90
 
 
91
 
    QPainter p(&pix);
92
 
 
93
 
    p.drawPixmap(m_pixRect.x() + (m_pixRect.width() - m_pixmap.width())/2,
94
 
                 m_pixRect.y() + (m_pixRect.height() - m_pixmap.height())/2,
95
 
                 m_pixmap);
96
 
 
97
235
    if (isSelected())
98
 
    {
99
 
        QPen pen;
100
 
        pen.setColor(cg.highlight());
101
 
        p.setPen(pen);
102
 
        p.drawRect(0, 0, pix.width(), pix.height());
103
 
        p.fillRect(0, m_textRect.y(), pix.width(),
104
 
                   m_textRect.height(), cg.highlight() );
105
 
        p.setPen( QPen( cg.highlightedText() ) );
106
 
    }
 
236
        pix = *(view->itemBaseSelPixmap());
107
237
    else
108
 
    {
109
 
        QPen pen;
110
 
        pen.setColor(cg.button());
111
 
        p.setPen(pen);
112
 
        p.drawRect(0, 0, pix.width(), pix.height());
113
 
        p.fillRect(0, m_textRect.y(), pix.width(),
114
 
                   m_textRect.height(), cg.button() );
115
 
        p.setPen( cg.text() );
116
 
    }
 
238
        pix = *(view->itemBaseRegPixmap());
117
239
    
118
 
 
119
 
    p.drawText(m_textRect, Qt::WordBreak|Qt::BreakAnywhere|
120
 
               Qt::AlignHCenter|Qt::AlignTop, m_itemInfo->name);
121
 
 
122
 
    if (!m_downloadName.isEmpty())
 
240
    ThemeEngine* te = ThemeEngine::instance();
 
241
 
 
242
    QPainter p(&pix);
 
243
 
 
244
    QString itemName     = AlbumIconItem::squeezedText(&p, r.width()-5, d->itemInfo->name);
 
245
    QString downloadName = AlbumIconItem::squeezedText(&p, r.width()-5, d->downloadName);
 
246
    calcRect(itemName, downloadName);
 
247
 
 
248
    p.setPen(isSelected() ? te->textSelColor() : te->textRegColor());
 
249
 
 
250
    p.drawPixmap(d->pixRect.x() + (d->pixRect.width()  - d->pixmap.width())  /2,
 
251
                 d->pixRect.y() + (d->pixRect.height() - d->pixmap.height()) /2,
 
252
                 d->pixmap);
 
253
 
 
254
    p.drawText(d->textRect, Qt::AlignHCenter|Qt::AlignTop, itemName);
 
255
 
 
256
    if (!d->downloadName.isEmpty())
123
257
    {
124
258
        if (fn.pointSize() > 0)
125
 
        {
126
259
            fn.setPointSize(QMAX(fn.pointSize()-2, 6));
127
 
        }
128
260
 
129
261
        p.setFont(fn);
130
 
        if (!isSelected())
131
 
            p.setPen(QPen("steelblue"));
132
 
        p.drawText(m_extraRect, Qt::WordBreak|
133
 
                   Qt::BreakAnywhere|Qt::AlignHCenter|
134
 
                   Qt::AlignTop,m_downloadName);
 
262
        p.setPen(isSelected() ? te->textSpecialSelColor() : te->textSpecialRegColor());
 
263
        p.drawText(d->extraRect, Qt::AlignHCenter|Qt::AlignTop, downloadName);
135
264
    }
136
265
 
137
266
    if (this == iconView()->currentItem())
138
267
    {
139
 
        p.setPen(QPen(isSelected() ? Qt::white : Qt::black,
140
 
                      1, Qt::DotLine));
 
268
        p.setPen(QPen(isSelected() ? Qt::white : Qt::black, 1, Qt::DotLine));
141
269
        p.drawRect(0, 0, r.width(), r.height());
142
270
    }
 
271
 
 
272
    // Draw download status icon.
 
273
    QPixmap downloaded;
143
274
    
144
 
    if (m_itemInfo->downloaded == 0)
 
275
    switch (d->itemInfo->downloaded)
145
276
    {
146
 
        int x = rect().width() - m_newEmblem->width() - 5;
147
 
        int y = 5;
148
 
        p.drawPixmap(x, y, *m_newEmblem);
 
277
        case GPItemInfo::NewPicture:
 
278
        {
 
279
            downloaded = d->pixmapNewPicture;
 
280
            break;
 
281
        }
 
282
        case GPItemInfo::DownloadedYes:
 
283
        {
 
284
            downloaded = SmallIcon( "button_ok" );
 
285
            break;
 
286
        }
 
287
        case GPItemInfo::DownloadStarted:
 
288
        {
 
289
            downloaded = SmallIcon( "run" );
 
290
            break;
 
291
        }
 
292
        case GPItemInfo::DownloadFailed:
 
293
        {
 
294
            downloaded = SmallIcon( "button_cancel" );
 
295
            break;
 
296
        }
 
297
        /* TODO: see B.K.O #107316 : disable temporally the unknow download status until     
 
298
                 a new method to identify the already downloaded pictures from camera is 
 
299
                 implemented.
 
300
  
 
301
        case GPItemInfo::DownloadUnknow:
 
302
        {
 
303
            downloaded = d->pixmapUnknowPicture;
 
304
            break;
 
305
        }
 
306
        */
149
307
    }
150
 
    
 
308
 
 
309
    if (!downloaded.isNull())
 
310
        p.drawPixmap(rect().width() - downloaded.width() - 5, 5, downloaded);
 
311
 
 
312
    // If camera item is locked (read only), draw a "Lock" icon.
 
313
    if (d->itemInfo->writePermissions == 0) 
 
314
        p.drawPixmap(5, 5, SmallIcon( "encrypted" ));
 
315
 
151
316
    p.end();
152
317
 
153
318
    r = QRect(view->contentsToViewport(QPoint(r.x(), r.y())),
158
323
 
159
324
void CameraIconViewItem::setDownloadName(const QString& downloadName)
160
325
{
161
 
    m_downloadName = downloadName;
162
 
    calcRect();
 
326
    d->downloadName = downloadName;
163
327
    repaint();
164
328
}
165
329
 
166
330
QString CameraIconViewItem::getDownloadName() const
167
331
{
168
 
    return m_downloadName;
169
 
}
170
 
 
171
 
void CameraIconViewItem::setDownloaded()
172
 
{
173
 
    if (m_itemInfo->downloaded != 1)
174
 
    {
175
 
        m_itemInfo->downloaded = 1;
176
 
        repaint();
177
 
    }
178
 
}
179
 
 
180
 
void CameraIconViewItem::calcRect()
181
 
{
182
 
    const int thumbSize = 128;
183
 
    
184
 
    m_pixRect       = QRect(0,0,0,0);
185
 
    m_textRect      = QRect(0,0,0,0);
186
 
    m_extraRect     = QRect(0,0,0,0);
187
 
    QRect itemRect  = rect();
188
 
    itemRect.moveTopLeft(QPoint(0,0));
189
 
 
190
 
    m_pixRect.setWidth(thumbSize);
191
 
    m_pixRect.setHeight(thumbSize);
 
332
    return d->downloadName;
 
333
}
 
334
 
 
335
void CameraIconViewItem::setDownloaded(int status)
 
336
{
 
337
    d->itemInfo->downloaded = status;
 
338
    repaint();
 
339
}
 
340
 
 
341
void CameraIconViewItem::toggleLock()
 
342
{
 
343
    if (d->itemInfo->writePermissions == 0) 
 
344
        d->itemInfo->writePermissions = 1;
 
345
    else 
 
346
        d->itemInfo->writePermissions = 0;
 
347
 
 
348
    repaint();
 
349
}
 
350
 
 
351
void CameraIconViewItem::calcRect(const QString& itemName, const QString& downloadName)
 
352
{
 
353
    CameraIconView* view = (CameraIconView*)iconView();
 
354
    int thumbSize        = view->thumbnailSize().size();
 
355
    d->pixmap            = QPixmap(d->thumbnail.smoothScale(thumbSize, thumbSize, QImage::ScaleMin));
 
356
    d->pixRect           = QRect(0,0,0,0);
 
357
    d->textRect          = QRect(0,0,0,0);
 
358
    d->extraRect         = QRect(0,0,0,0);
 
359
    QRect itemRect       = rect();
 
360
    itemRect.moveTopLeft(QPoint(0, 0));
 
361
 
 
362
    d->pixRect.setWidth(thumbSize);
 
363
    d->pixRect.setHeight(thumbSize);
192
364
 
193
365
    QFontMetrics fm(iconView()->font());
194
366
    QRect r = QRect(fm.boundingRect(0, 0, thumbSize, 0xFFFFFFFF,
195
 
                                    Qt::AlignHCenter | Qt::AlignTop |
196
 
                                    Qt::WordBreak | Qt::BreakAnywhere,
197
 
                                    m_itemInfo->name));
198
 
    m_textRect.setWidth(r.width());
199
 
    m_textRect.setHeight(r.height());
 
367
                                    Qt::AlignHCenter | Qt::AlignTop,
 
368
                                    itemName));
 
369
    d->textRect.setWidth(r.width());
 
370
    d->textRect.setHeight(r.height());
200
371
 
201
 
    if (!m_downloadName.isEmpty())
 
372
    if (!d->downloadName.isEmpty())
202
373
    {
203
374
        QFont fn(iconView()->font());
204
375
        if (fn.pointSize() > 0)
207
378
        }
208
379
 
209
380
        fm = QFontMetrics(fn);
210
 
        r = QRect(fm.boundingRect(0, 0, thumbSize, 0xFFFFFFFF,
211
 
                                  Qt::AlignHCenter | Qt::WordBreak |
212
 
                                  Qt::BreakAnywhere | Qt::AlignTop,
213
 
                                  m_downloadName));
214
 
        m_extraRect.setWidth(r.width());
215
 
        m_extraRect.setHeight(r.height());
 
381
        r  = QRect(fm.boundingRect(0, 0, thumbSize, 0xFFFFFFFF,
 
382
                                   Qt::AlignHCenter | Qt::WordBreak,
 
383
                                   downloadName));
 
384
        d->extraRect.setWidth(r.width());
 
385
        d->extraRect.setHeight(r.height());
216
386
 
217
 
        m_textRect.setWidth(QMAX(m_textRect.width(), m_extraRect.width()));
218
 
        m_textRect.setHeight(m_textRect.height() + m_extraRect.height());
 
387
        d->textRect.setWidth(QMAX(d->textRect.width(), d->extraRect.width()));
 
388
        d->textRect.setHeight(d->textRect.height() + d->extraRect.height());
219
389
    }
220
390
    
221
 
    int w = QMAX(m_textRect.width(), m_pixRect.width() );
222
 
    int h = m_textRect.height() + m_pixRect.height() ;
 
391
    int w = QMAX(d->textRect.width(), d->pixRect.width() );
 
392
    int h = d->textRect.height() + d->pixRect.height() ;
223
393
 
224
394
    itemRect.setWidth(w+4);
225
395
    itemRect.setHeight(h+4);
226
396
 
227
397
    // Center the pix and text rect
228
 
    m_pixRect = QRect(2, 2, m_pixRect.width(), m_pixRect.height());
229
 
    m_textRect = QRect((itemRect.width() - m_textRect.width())/2,
230
 
                       itemRect.height() - m_textRect.height(),
231
 
                       m_textRect.width(), m_textRect.height());
 
398
    d->pixRect  = QRect(2, 2, d->pixRect.width(), d->pixRect.height());
 
399
    d->textRect = QRect((itemRect.width() - d->textRect.width())/2,
 
400
                        itemRect.height() - d->textRect.height(),
 
401
                        d->textRect.width(), d->textRect.height());
232
402
 
233
 
    if (!m_extraRect.isEmpty())
 
403
    if (!d->extraRect.isEmpty())
234
404
    {
235
 
        m_extraRect = QRect((itemRect.width() - m_extraRect.width())/2,
236
 
                            itemRect.height() - m_extraRect.height(),
237
 
                            m_extraRect.width(), m_extraRect.height());
 
405
        d->extraRect = QRect((itemRect.width() - d->extraRect.width())/2,
 
406
                             itemRect.height() - d->extraRect.height(),
 
407
                             d->extraRect.width(), d->extraRect.height());
238
408
    }
239
409
}
240
410
 
241
411
QRect CameraIconViewItem::clickToOpenRect()
242
412
{
243
 
    QRect  r(rect());
 
413
    QRect r(rect());
244
414
    
245
 
    if (m_pixmap.isNull())
 
415
    if (d->pixmap.isNull())
246
416
    {
247
 
        QRect  pixRect(m_pixRect);
 
417
        QRect pixRect(d->pixRect);
248
418
        pixRect.moveBy(r.x(), r.y());
249
419
        return pixRect;
250
420
    }
251
421
 
252
 
 
253
 
    QRect pixRect(m_pixRect.x() + (m_pixRect.width() - m_pixmap.width())/2,
254
 
                  m_pixRect.y() + (m_pixRect.height() - m_pixmap.height())/2,
255
 
                  m_pixmap.width(),
256
 
                  m_pixmap.height());
 
422
    QRect pixRect(d->pixRect.x() + (d->pixRect.width()  - d->pixmap.width())/2,
 
423
                  d->pixRect.y() + (d->pixRect.height() - d->pixmap.height())/2,
 
424
                  d->pixmap.width(), d->pixmap.height());
257
425
    pixRect.moveBy(r.x(), r.y());
258
426
    return pixRect;
259
427
}
 
428
 
 
429
}  // namespace Digikam
 
430