Initial steps to keep library in a database.
[dorian] / widgets / translucentbutton.cpp
1 #include <QtGui>
2
3 #include "translucentbutton.h"
4 #include "platform.h"
5 #include "trace.h"
6
7 const int TranslucentButton::pixels = 95;
8
9 TranslucentButton::TranslucentButton(const QString &name_, QWidget *parent):
10     QLabel(parent), name(name_), transparent(true)
11 {
12     setGeometry(0, 0, pixels, pixels);
13     timer = new QTimer(this);
14     timer->setSingleShot(true);
15     connect(timer, SIGNAL(timeout()), this, SLOT(stopFlash()));
16     show();
17 }
18
19 void TranslucentButton::paintEvent(QPaintEvent *)
20 {
21     QPainter painter(this);
22     if (!transparent) {
23         painter.setRenderHint(QPainter::Antialiasing, true);
24         painter.drawPixmap(0, 0, QPixmap(Platform::icon(name)).scaled(
25                 QSize(pixels, pixels), Qt::IgnoreAspectRatio,
26                 Qt::SmoothTransformation));
27     } else {
28         painter.fillRect(0, 0, pixels, pixels, Qt::NoBrush);
29     }
30 }
31
32 void TranslucentButton::flash(int duration)
33 {
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 }