6621acb74cd97504c3b16917023f34154e531ec8
[dorian] / widgets / progress.cpp
1 #include <QtGui>
2
3 #include "progress.h"
4 #include "trace.h"
5
6 Progress::Progress(QWidget *parent):
7         QLabel(parent), progress(-1.0), timer(-1), mThickness(15)
8 {
9     hide();
10 }
11
12 void Progress::setProgress(qreal p)
13 {
14     TRACE;
15     qDebug() << p;
16     if (progress != p) {
17         progress = p;
18         flash();
19         update();
20     }
21 }
22
23 void Progress::paintEvent(QPaintEvent *e)
24 {
25     Q_UNUSED(e);
26     QPainter painter(this);
27     painter.setBrush(QBrush(QColor(100, 100, 100, 177)));
28     painter.setPen(Qt::NoPen);
29     int w = int(width() * progress);
30     painter.drawRect(0, 0, w, mThickness);
31     painter.setBrush(QBrush(QColor(100, 100, 100, 50)));
32     painter.drawRect(w, 0, width() - w, mThickness);
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         timer = -1;
47         hide();
48     }
49     QLabel::timerEvent(e);
50 }
51
52 int Progress::thickness() const
53 {
54     return mThickness;
55 }