More reorg.
[dorian] / widgets / translucentbutton.cpp
1 #include "translucentbutton.h"
2
3 #ifdef Q_WS_MAC
4 #   define ICON_PREFIX ":/icons/mac/"
5 #else
6 #   define ICON_PREFIX ":/icons/"
7 #endif
8
9 TranslucentButton::TranslucentButton(const QString &name_, QWidget *parent):
10     QWidget(parent), name(name_), mOpacity(1.)
11 {
12     setGeometry(0, 0, 50, 50);
13     show();
14 }
15
16 void TranslucentButton::paintEvent(QPaintEvent *)
17 {
18     if (mOpacity < 1) {
19         QPainter painter(this);
20         painter.setRenderHint(QPainter::Antialiasing, true);
21         painter.drawPixmap(0, 0, QPixmap(ICON_PREFIX + name + ".png").scaled(
22                 QSize(95, 95), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
23     }
24 }
25
26 void TranslucentButton::flash(int duration)
27 {
28     QPropertyAnimation *ani = new QPropertyAnimation(this, "opacity", 0);
29     ani->setDuration(duration);
30     ani->setStartValue(0.);
31     ani->setEndValue(1.);
32     ani->setEasingCurve(QEasingCurve::OutQuart);
33     ani->start(QPropertyAnimation::DeleteWhenStopped);
34 }
35
36 void TranslucentButton::setOpacity(qreal opacity)
37 {
38     mOpacity = opacity;
39     update();
40 }