7
7
* Description : a widget to display free space for a mount-point.
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>
11
11
* This program is free software; you can redistribute it
12
12
* and/or modify it under the terms of the GNU General
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);
122
126
connect(d->timer, SIGNAL(timeout()),
123
127
this, SLOT(slotTimeout()));
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);
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.
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)),
293
301
p.drawRect(gRect);
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);
301
309
p.drawText(tRect, Qt::AlignCenter, text);
338
346
tip += cnt.tipFooter;
348
d->toolTip->setToolTip(tip);
345
setWhatsThis(QString());
346
setToolTip(QString());
352
d->toolTip->setToolTip(QString());
356
void FreeSpaceWidget::enterEvent(QEvent *e)
361
void FreeSpaceWidget::leaveEvent(QEvent* e)
350
366
#if KDE_IS_VERSION(4,1,68)
351
367
void FreeSpaceWidget::slotTimeout()