Another failed attempt to make kinetic scrolling work. Simplified
[dorian] / widgets / translucentbutton.cpp
1 #include <QtGui>
2
3 #include "translucentbutton.h"
4 #include "platform.h"
5
6 const int TranslucentButton::pixels = 95;
7 const int TranslucentButton::elevatorInterval = 750;
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     elevatorTimer = startTimer(elevatorInterval);
17 }
18
19 TranslucentButton::~TranslucentButton()
20 {
21     killTimer(elevatorTimer);
22 }
23
24 void TranslucentButton::paintEvent(QPaintEvent *)
25 {
26     QPainter painter(this);
27     if (!transparent) {
28         painter.setRenderHint(QPainter::Antialiasing, true);
29         painter.drawPixmap(0, 0, QPixmap(Platform::icon(name)).scaled(
30                 QSize(pixels, pixels), Qt::IgnoreAspectRatio,
31                 Qt::SmoothTransformation));
32     } else {
33         painter.fillRect(0, 0, pixels, pixels, Qt::NoBrush);
34     }
35 }
36
37 void TranslucentButton::flash(int duration)
38 {
39     show();
40     raise();
41     transparent = false;
42     update();
43     timer->start(duration);
44 }
45
46 void TranslucentButton::stopFlash()
47 {
48     transparent = true;
49     update();
50 }
51
52 void TranslucentButton::mouseReleaseEvent(QMouseEvent *e)
53 {
54     Q_UNUSED(e);
55     emit triggered();
56     e->accept();
57 }
58
59 void TranslucentButton::timerEvent(QTimerEvent *e)
60 {
61     if (e->timerId() == elevatorTimer) {
62         raise();
63     }
64 }