Fix crash if key bindings specified in profile cannot be found. Improve
[personal-kdebase.git] / apps / kinfocenter / partition / usedSizeWidget.cpp
blobe46a5698e36cb2a11299927b578d7f48013c2143
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>
15 #include <QLabel>
16 #include <QPainter>
18 #include <klocale.h>
19 #include <kdebug.h>
20 #include <kglobal.h>
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;
33 QPainter paint(this);
35 int endWidth = width() - 2;
36 int endHeight = height() - 2;
38 if (endWidth<=0 || endHeight<=0) {
39 return;
42 if (totalSize==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"));
45 return;
48 QLinearGradient gradient(QPointF(0, endHeight), QPointF(endWidth, endHeight));
50 qreal percent = ((qreal)usedSize) / ((qreal)totalSize);
52 gradient.setColorAt(0, QColor(0xA3, 0xF7, 0x72));
54 if (percent > 0.5)
55 gradient.setColorAt(0.5, QColor(0x5E, 0xD9, 0x35));
57 if (percent > 0.6)
58 paint.setPen(Qt::black);
60 if (percent > 0.75)
61 gradient.setColorAt(0.75, QColor(0xF7, 0xB6, 0x3D));
63 if (percent > 0.95) {
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;
86 update();
89 #include "usedSizeWidget.moc"