~ubuntu-branches/ubuntu/jaunty/digikam/jaunty

« back to all changes in this revision

Viewing changes to utilities/cameragui/freespacewidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Luka Renko
  • Date: 2009-01-21 21:55:15 UTC
  • mfrom: (1.2.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20090121215515-lry0s2pdep289o3u
Tags: 2:0.10.0~rc1-0ubuntu1
* New upstream release (release candididate 1)
* rules:
  - Simplify by including standard class/kde4.mk
* control:
  - Build-Depends on quilt (default patch system of kde4.mk)
  - Bump Standards-Version to 3.8.0
  - Bump debhelper dependancy to 7
  - Add ${misc:Depends} to make lintian happy
* {digikam|showfoto}.install:
  - Update icon paths
  - Do not package oxygen and apps icons: provided by kde-icons-oxygen
* patches/01-kubuntu-fix-armel.patch:
  - Fix cut&paste bug in the patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 * Date        : 2007-08-31
7
7
 * Description : a widget to display free space for a mount-point.
8
8
 *
9
 
 * Copyright (C) 2007-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
9
 * Copyright (C) 2007-2009 by Gilles Caulier <caulier dot gilles at gmail dot com>
10
10
 *
11
11
 * This program is free software; you can redistribute it
12
12
 * and/or modify it under the terms of the GNU General
49
49
 
50
50
// Local includes.
51
51
 
52
 
#include "ditemtooltip.h"
 
52
#include "freespacetooltip.h"
53
53
#include "albumsettings.h"
54
54
 
55
55
namespace Digikam
61
61
 
62
62
    MountPointInfo()
63
63
    {
64
 
        isValid     = false;
65
 
        kBSize      = 0;
66
 
        kBUsed      = 0;
67
 
        kBAvail     = 0;
 
64
        isValid = false;
 
65
        kBSize  = 0;
 
66
        kBUsed  = 0;
 
67
        kBAvail = 0;
68
68
    }
69
69
 
70
 
    QString       mountPoint;
71
 
 
72
70
    bool          isValid;
73
71
 
74
72
    unsigned long kBSize;
75
73
    unsigned long kBUsed;
76
74
    unsigned long kBAvail;
 
75
 
 
76
    QString       mountPoint;
77
77
};
78
78
 
79
79
class FreeSpaceWidgetPriv
82
82
 
83
83
    FreeSpaceWidgetPriv()
84
84
    {
85
 
        timer       = 0;
86
 
        isValid     = false;
87
 
        percentUsed = 0;
88
 
        kBSize      = 0;
89
 
        kBUsed      = 0;
90
 
        kBAvail     = 0;
91
 
        dSizeKb     = 0;
92
 
        mode        = FreeSpaceWidget::AlbumLibrary;
 
85
        toolTip      = 0;
 
86
        timer        = 0;
 
87
        isValid      = false;
 
88
        percentUsed  = 0;
 
89
        kBSize       = 0;
 
90
        kBUsed       = 0;
 
91
        kBAvail      = 0;
 
92
        dSizeKb      = 0;
 
93
        mode         = FreeSpaceWidget::AlbumLibrary;
93
94
    }
94
95
 
95
96
    bool                            isValid;
108
109
 
109
110
    QPixmap                         iconPix;
110
111
 
 
112
    FreeSpaceToolTip               *toolTip;
 
113
 
111
114
    FreeSpaceWidget::FreeSpaceMode  mode;
112
115
};
113
116
 
117
120
    setAttribute(Qt::WA_DeleteOnClose);
118
121
    setFixedWidth(width);
119
122
    setMaximumHeight(fontMetrics().height()+4);
120
 
    d->timer = new QTimer(this);
 
123
    d->timer   = new QTimer(this);
 
124
    d->toolTip = new FreeSpaceToolTip(this);
121
125
 
122
126
    connect(d->timer, SIGNAL(timeout()),
123
127
            this, SLOT(slotTimeout()));
256
260
            if (length > mountPointMatch)
257
261
            {
258
262
                mountPointMatch = info.mountPoint.length();
259
 
                selectedInfo = info;
 
263
                selectedInfo    = info;
260
264
            }
261
265
        }
262
266
    }
264
268
    if (!mountPointMatch)
265
269
    {
266
270
        kWarning(50003) << "Did not identify a valid mount point for" << path;
267
 
        return -1;
 
271
        return (unsigned long)(-1);
268
272
    }
269
273
 
270
274
    return selectedInfo.kBAvail;
285
289
        unsigned long eUsedKb = d->dSizeKb + d->kBUsed;
286
290
        int peUsed            = (int)(100.0*((double)eUsedKb/(double)d->kBSize));
287
291
        int pClamp            = peUsed > 100 ? 100 : peUsed;
288
 
        p.setBrush(peUsed > 95 ? Qt::red : Qt::darkGreen);
289
 
        p.setPen(Qt::white);
290
 
        QRect gRect(d->iconPix.height()+2, 1,
 
292
        QColor barcol         = QColor(62, 255, 62);          // Smooth Green.
 
293
        if (peUsed > 80)      barcol = QColor(240, 255, 62);  // Smooth Yellow.
 
294
        else if (peUsed > 95) barcol = QColor(255, 62, 62);   // Smooth Red.
 
295
 
 
296
        p.setBrush(barcol);
 
297
        p.setPen(palette().light().color());
 
298
        QRect gRect(d->iconPix.height()+3, 2,
291
299
                    (int)(((double)width()-3.0-d->iconPix.width()-2.0)*(pClamp/100.0)),
292
 
                    height()-3);
 
300
                    height()-5);
293
301
        p.drawRect(gRect);
294
302
 
295
 
        QRect tRect(d->iconPix.height()+2, 1, width()-3-d->iconPix.width()-2, height()-3);
 
303
        QRect tRect(d->iconPix.height()+3, 2, width()-3-d->iconPix.width()-2, height()-5);
296
304
        QString text        = QString("%1%").arg(peUsed);
297
305
        QFontMetrics fontMt = p.fontMetrics();
298
306
        QRect fontRect      = fontMt.boundingRect(tRect.x(), tRect.y(),
299
 
                                                tRect.width(), tRect.height(), 0, text);
300
 
        p.setPen(palette().text().color());
 
307
                                                  tRect.width(), tRect.height(), 0, text);
 
308
        p.setPen(Qt::black);
301
309
        p.drawText(tRect, Qt::AlignCenter, text);
302
310
    }
303
311
}
337
345
 
338
346
        tip += cnt.tipFooter;
339
347
 
340
 
        setWhatsThis(tip);
341
 
        setToolTip(tip);
 
348
        d->toolTip->setToolTip(tip);
342
349
    }
343
350
    else
344
351
    {
345
 
        setWhatsThis(QString());
346
 
        setToolTip(QString());
 
352
        d->toolTip->setToolTip(QString());
347
353
    }
348
354
}
349
355
 
 
356
void FreeSpaceWidget::enterEvent(QEvent *e)
 
357
{
 
358
    d->toolTip->show();
 
359
}
 
360
 
 
361
void FreeSpaceWidget::leaveEvent(QEvent* e)
 
362
{
 
363
    d->toolTip->hide();
 
364
}
 
365
 
350
366
#if KDE_IS_VERSION(4,1,68)
351
367
void FreeSpaceWidget::slotTimeout()
352
368
{