Commit e3a7b894 authored by Ming Rui Zhang's avatar Ming Rui Zhang Committed by Andreas Traczyk

widgethelpers: add blinkable widget

Change-Id: If5b7bcd9ebac2082ab13399497843b72f11be09a
parent 035f929e
......@@ -75,6 +75,50 @@ FadeOutable::slotTimeout()
Q_EMIT willFadeOut();
}
Blinkable::Blinkable(QWidget* parent)
: QWidget(parent)
{
setAttribute(Qt::WA_NoSystemBackground);
fadeAnimation_ = new FadeAnimation(this, blinkTime_);
}
Blinkable::~Blinkable()
{}
void
Blinkable::slotAnimationFinished()
{
fadeAnimation_->setDirection(fadeAnimation_->direction() == QAbstractAnimation::Forward
? QAbstractAnimation::Backward
: QAbstractAnimation::Forward);
fadeAnimation_->start();
}
void
Blinkable::start()
{
connection_ = connect(fadeAnimation_, &QPropertyAnimation::finished, this, &Blinkable::slotAnimationFinished);
fadeAnimation_->setDirection(QAbstractAnimation::Forward);
fadeAnimation_->start();
}
void
Blinkable::stop()
{
disconnect(connection_);
fadeAnimation_->stop();
}
void
Blinkable::paintEvent(QPaintEvent *event)
{
QWidget::paintEvent(event);
if(!pixmap_)
return;
QPainter painter(this);
painter.drawPixmap(rect(), *pixmap_);
}
VignetteWidget::VignetteWidget(QWidget* parent)
: QWidget(parent)
{
......
......@@ -24,6 +24,7 @@
#include <QTimer>
#include <QMouseEvent>
#include <QPainter>
#include <QPixmap>
class FadeOutable : public QWidget
{
......@@ -60,6 +61,34 @@ private:
};
class Blinkable : public QWidget
{
Q_OBJECT
public:
explicit Blinkable(QWidget* parent = nullptr);
~Blinkable();
void start();
void stop();
void setBlinkTime(const quint64 ms) { blinkTime_ = ms; }
void setPixmap(QPixmap* pixmap) { pixmap_ = pixmap; }
void unsetPixmap() { pixmap_ = nullptr; }
protected:
void paintEvent(QPaintEvent *event);
private slots:
void slotAnimationFinished();
private:
FadeAnimation* fadeAnimation_;
quint64 blinkTime_{ 1000 };
QPixmap* pixmap_{ nullptr };
QMetaObject::Connection connection_;
};
class VignetteWidget : public QWidget
{
Q_OBJECT
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment