X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=widgets%2Ftranslucentbutton.cpp;h=d643df2ebd655dd39d792eb6b5d342012b5b55c6;hb=ab12e26d07ddb568b83a4115e2cab297524a7037;hp=02c4e25c97f7c65d2b852a3e7de853b741c62525;hpb=10aedec25f5b9d80b6694e8e04fa63e9773729a0;p=dorian diff --git a/widgets/translucentbutton.cpp b/widgets/translucentbutton.cpp index 02c4e25..d643df2 100644 --- a/widgets/translucentbutton.cpp +++ b/widgets/translucentbutton.cpp @@ -1,16 +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, 95, 95); + setGeometry(0, 0, pixels, pixels); timer = new QTimer(this); timer->setSingleShot(true); connect(timer, SIGNAL(timeout()), this, SLOT(stopFlash())); @@ -20,32 +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::mousePressEvent(QMouseEvent *e) +void TranslucentButton::mouseReleaseEvent(QMouseEvent *e) { Q_UNUSED(e); - Trace t("TranslucentButton::mousePressEvent"); emit triggered(); e->accept(); }