From f525fa83f3c08ee342fbf894f42ada771e9dc97c Mon Sep 17 00:00:00 2001 From: krepa098 Date: Fri, 6 Feb 2015 14:02:31 +0100 Subject: [PATCH] Spinner: fade in --- src/chatlog/content/spinner.cpp | 11 ++++++++++- src/chatlog/content/spinner.h | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/chatlog/content/spinner.cpp b/src/chatlog/content/spinner.cpp index 9f7901b48..0f43a22b2 100644 --- a/src/chatlog/content/spinner.cpp +++ b/src/chatlog/content/spinner.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include Spinner::Spinner(const QString &img, QSize Size, qreal speed) @@ -31,6 +32,14 @@ Spinner::Spinner(const QString &img, QSize Size, qreal speed) timer.setInterval(1000/30); // 30Hz timer.setSingleShot(false); + blendAnimation = new QVariantAnimation(this); + blendAnimation->setStartValue(0.0); + blendAnimation->setEndValue(1.0); + blendAnimation->setDuration(350); + blendAnimation->setEasingCurve(QEasingCurve::InCubic); + blendAnimation->start(QAbstractAnimation::DeleteWhenStopped); + connect(blendAnimation, &QVariantAnimation::valueChanged, this, [this](const QVariant& val) { alpha = val.toDouble(); }); + QObject::connect(&timer, &QTimer::timeout, this, &Spinner::timeout); } @@ -45,7 +54,7 @@ void Spinner::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, Q QTransform trans = QTransform().rotate(QTime::currentTime().msecsSinceStartOfDay() / 1000.0 * rotSpeed) .translate(-size.width()/2.0, -size.height()/2.0); - + painter->setOpacity(alpha); painter->setTransform(trans, true); painter->setRenderHint(QPainter::SmoothPixmapTransform); painter->drawPixmap(0, 0, pmap); diff --git a/src/chatlog/content/spinner.h b/src/chatlog/content/spinner.h index c35b5a4a4..cdec722e1 100644 --- a/src/chatlog/content/spinner.h +++ b/src/chatlog/content/spinner.h @@ -23,6 +23,8 @@ #include #include +class QVariantAnimation; + class Spinner : public QObject, public ChatLineContent { Q_OBJECT @@ -43,6 +45,8 @@ private: QPixmap pmap; qreal rotSpeed; QTimer timer; + qreal alpha = 0.0; + QVariantAnimation* blendAnimation; };