d0a1409f1878963cd9120e681050abb5ec18a43c
[dorian] / widgets / progress.cpp
1 #include <QtGui>
2
3 #include "progress.h"
4 #include "trace.h"
5
6 Progress::Progress(QWidget *parent): QLabel(parent), progress(-1.0), timer(-1)
7 {
8     hide();
9 }
10
11 void Progress::setProgress(qreal p)
12 {
13     Trace t("Progress::setProgress");
14     qDebug() << p;
15     if (progress != p) {
16         progress = p;
17         flash();
18         update();
19     }
20 }
21
22 void Progress::paintEvent(QPaintEvent *e)
23 {
24     Q_UNUSED(e);
25     QPainter painter(this);
26     painter.setBrush(QBrush(QColor(100, 100, 100, 177)));
27     painter.setPen(Qt::NoPen);
28     int w = int(width() * progress);
29     int h = height();
30     painter.drawRect(0, 0, w, h);
31     painter.setBrush(QBrush(QColor(100, 100, 100, 50)));
32     painter.drawRect(w, 0, width(), h);
33 }
34
35 void Progress::flash()
36 {
37     killTimer(timer);
38     show();
39     timer = startTimer(700);
40 }
41
42 void Progress::timerEvent(QTimerEvent *e)
43 {
44     if (e->timerId() == timer) {
45         killTimer(timer);
46         hide();
47     }
48 }