Fix forward navigation control on Linux.
[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     setFixedSize(pixels, pixels);
13     elevatorTimer = startTimer(elevatorInterval);
14 }
15
16 TranslucentButton::~TranslucentButton()
17 {
18     killTimer(elevatorTimer);
19 }
20
21 void TranslucentButton::paintEvent(QPaintEvent *)
22 {
23     QPainter painter(this);
24     if (!transparent) {
25         painter.setRenderHint(QPainter::Antialiasing, true);
26         painter.drawPixmap(0, 0, QPixmap(Platform::instance()->icon(name)).scaled(
27                 QSize(pixels, pixels), Qt::IgnoreAspectRatio,
28                 Qt::SmoothTransformation));
29     } else {
30         painter.fillRect(0, 0, pixels, pixels, Qt::NoBrush);
31     }
32 }
33
34 void TranslucentButton::flash(int duration)
35 {
36     raise();
37     show();
38     transparent = false;
39     update();
40     QTimer::singleShot(duration, this, SLOT(stopFlash()));
41 }
42
43 void TranslucentButton::stopFlash()
44 {
45     transparent = true;
46     update();
47 }
48
49 void TranslucentButton::mouseReleaseEvent(QMouseEvent *e)
50 {
51     Q_UNUSED(e);
52     emit triggered();
53     e->accept();
54 }
55
56 void TranslucentButton::timerEvent(QTimerEvent *e)
57 {
58     if (e->timerId() == elevatorTimer) {
59         raise();
60     }
61     QLabel::timerEvent(e);
62 }