X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=widgets%2Ftranslucentbutton.cpp;h=d643df2ebd655dd39d792eb6b5d342012b5b55c6;hb=ab12e26d07ddb568b83a4115e2cab297524a7037;hp=7a6d6fe41355818164973bb960887a4c3d23f361;hpb=d38e9cc60afa71f1f3f6a6474d73a1df583bfa7c;p=dorian diff --git a/widgets/translucentbutton.cpp b/widgets/translucentbutton.cpp index 7a6d6fe..d643df2 100644 --- a/widgets/translucentbutton.cpp +++ b/widgets/translucentbutton.cpp @@ -1,15 +1,15 @@ +#include + #include "translucentbutton.h" +#include "platform.h" +#include "trace.h" -#ifdef Q_WS_MAC -# define ICON_PREFIX ":/icons/mac/" -#else -# define ICON_PREFIX ":/icons/" -#endif +const int TranslucentButton::pixels = 95; TranslucentButton::TranslucentButton(const QString &name_, QWidget *parent): - QWidget(parent), name(name_), opacity(1) + QLabel(parent), name(name_), transparent(true) { - setGeometry(0, 0, 50, 50); + setGeometry(0, 0, pixels, pixels); timer = new QTimer(this); timer->setSingleShot(true); connect(timer, SIGNAL(timeout()), this, SLOT(stopFlash())); @@ -19,24 +19,33 @@ TranslucentButton::TranslucentButton(const QString &name_, QWidget *parent): void TranslucentButton::paintEvent(QPaintEvent *) { QPainter painter(this); - if (opacity < 1) { + if (!transparent) { painter.setRenderHint(QPainter::Antialiasing, true); - painter.drawPixmap(0, 0, QPixmap(ICON_PREFIX + name + ".png").scaled( - QSize(95, 95), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + painter.drawPixmap(0, 0, QPixmap(Platform::icon(name)).scaled( + QSize(pixels, pixels), Qt::IgnoreAspectRatio, + Qt::SmoothTransformation)); } else { - painter.fillRect(0, 0, 95, 95, Qt::NoBrush); + painter.fillRect(0, 0, pixels, pixels, Qt::NoBrush); } } void TranslucentButton::flash(int duration) { - opacity = 0; + raise(); + transparent = false; update(); timer->start(duration); } void TranslucentButton::stopFlash() { - opacity = 1; + transparent = true; update(); } + +void TranslucentButton::mouseReleaseEvent(QMouseEvent *e) +{ + Q_UNUSED(e); + emit triggered(); + e->accept(); +}