+#include <QtGui>
+
#include "translucentbutton.h"
+#include "platform.h"
-#ifdef Q_WS_MAC
-# define ICON_PREFIX ":/icons/mac/"
-#else
-# define ICON_PREFIX ":/icons/"
-#endif
+const int TranslucentButton::pixels = 95;
+const int TranslucentButton::elevatorInterval = 750;
TranslucentButton::TranslucentButton(const QString &name_, QWidget *parent):
- QWidget(parent), name(name_), opacity(1)
+ QLabel(parent), name(name_), transparent(true)
{
- setGeometry(0, 0, 50, 50);
- timer = new QTimer(this);
- timer->setSingleShot(true);
- connect(timer, SIGNAL(timeout()), this, SLOT(stopFlash()));
- show();
+ setFixedSize(pixels, pixels);
+ elevatorTimer = startTimer(elevatorInterval);
+}
+
+TranslucentButton::~TranslucentButton()
+{
+ killTimer(elevatorTimer);
}
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::instance()->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();
+ show();
+ transparent = false;
update();
- timer->start(duration);
+ QTimer::singleShot(duration, this, SLOT(stopFlash()));
}
void TranslucentButton::stopFlash()
{
- opacity = 1;
+ transparent = true;
update();
}
+
+void TranslucentButton::mouseReleaseEvent(QMouseEvent *e)
+{
+ Q_UNUSED(e);
+ emit triggered();
+ e->accept();
+}
+
+void TranslucentButton::timerEvent(QTimerEvent *e)
+{
+ if (e->timerId() == elevatorTimer) {
+ raise();
+ }
+ QLabel::timerEvent(e);
+}