1 /***************************************************************************
2 * KT list view item task implementation. *
3 * -------------------------------------------------------------------- *
4 * Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
5 * -------------------------------------------------------------------- *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 ***************************************************************************/
12 #include "usedSizeWidget.h"
14 #include <QVBoxLayout>
22 UsedSizeWidget::UsedSizeWidget(QWidget
* parent
) :
23 QWidget(parent
), totalSize(0), usedSize(0), availableSize(0) {
25 setSizePolicy(QSizePolicy::Minimum
, QSizePolicy::MinimumExpanding
);
26 //setAutoFillBackground(true);
30 void UsedSizeWidget::paintEvent(QPaintEvent
* /*event*/) {
31 //kDebug() << "PaintEvent" << mountPoint << totalSize << usedSize << availableSize;
35 int endWidth
= width() - 2;
36 int endHeight
= height() - 2;
38 if (endWidth
<=0 || endHeight
<=0) {
43 paint
.fillRect(1, 1, endWidth
, endHeight
, QColor(0xCC, 0xCC, 0xCC, 50));
44 paint
.drawText(1, 1, endWidth
, endHeight
, Qt::AlignCenter
| Qt::TextWordWrap
, i18n("unknown"));
48 QLinearGradient
gradient(QPointF(0, endHeight
), QPointF(endWidth
, endHeight
));
50 qreal percent
= ((qreal
)usedSize
) / ((qreal
)totalSize
);
52 gradient
.setColorAt(0, QColor(0xA3, 0xF7, 0x72));
55 gradient
.setColorAt(0.5, QColor(0x5E, 0xD9, 0x35));
58 paint
.setPen(Qt::black
);
61 gradient
.setColorAt(0.75, QColor(0xF7, 0xB6, 0x3D));
64 gradient
.setColorAt(0.90, QColor(0xF7, 0x78, 0x34));
65 gradient
.setColorAt(0.95, QColor(0xD3, 0x42, 0x19));
68 gradient
.setColorAt(percent
, Qt::transparent
);
70 paint
.fillRect(1, 1, endWidth
, endHeight
, gradient
);
72 int percentUsed
= (usedSize
* 100) / totalSize
;
73 paint
.drawText(1, 1, endWidth
, endHeight
, Qt::AlignCenter
| Qt::TextWordWrap
, QString("%1%").arg(percentUsed
));
77 void UsedSizeWidget::setUsedSize(const QString
& mountPoint
, quint64 totalSize
, quint64 usedSize
, quint64 availableSize
) {
79 this->totalSize
= totalSize
;
80 this->usedSize
= usedSize
;
81 this->availableSize
= availableSize
;
82 this->mountPoint
= mountPoint
;
84 kDebug() << mountPoint
<< totalSize
<< usedSize
<< availableSize
;
89 #include "usedSizeWidget.moc"