Simplify in/out traces.
[dorian] / widgets / translucentbutton.cpp
1 #include <QtGui>
2
3 #include "translucentbutton.h"
4 #include "platform.h"
5
6 const int TranslucentButton::pixels = 95;
7
8 TranslucentButton::TranslucentButton(const QString &name_, QWidget *parent):
9     QLabel(parent), name(name_), transparent(true)
10 {
11     setGeometry(0, 0, pixels, pixels);
12     timer = new QTimer(this);
13     timer->setSingleShot(true);
14     connect(timer, SIGNAL(timeout()), this, SLOT(stopFlash()));
15     show();
16 }
17
18 void TranslucentButton::paintEvent(QPaintEvent *)
19 {
20     QPainter painter(this);
21     if (!transparent) {
22         painter.setRenderHint(QPainter::Antialiasing, true);
23         painter.drawPixmap(0, 0, QPixmap(Platform::icon(name)).scaled(
24                 QSize(pixels, pixels), Qt::IgnoreAspectRatio,
25                 Qt::SmoothTransformation));
26     } else {
27         painter.fillRect(0, 0, pixels, pixels, Qt::NoBrush);
28     }
29 }
30
31 void TranslucentButton::flash(int duration)
32 {
33     show();
34     raise();
35     transparent = false;
36     update();
37     timer->start(duration);
38 }
39
40 void TranslucentButton::stopFlash()
41 {
42     transparent = true;
43     update();
44 }
45
46 void TranslucentButton::mouseReleaseEvent(QMouseEvent *e)
47 {
48     Q_UNUSED(e);
49     emit triggered();
50     e->accept();
51 }