mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Spinner: fade in
This commit is contained in:
parent
3c349e29ad
commit
f525fa83f3
|
@ -20,6 +20,7 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
|
#include <QVariantAnimation>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
Spinner::Spinner(const QString &img, QSize Size, qreal speed)
|
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.setInterval(1000/30); // 30Hz
|
||||||
timer.setSingleShot(false);
|
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);
|
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)
|
QTransform trans = QTransform().rotate(QTime::currentTime().msecsSinceStartOfDay() / 1000.0 * rotSpeed)
|
||||||
.translate(-size.width()/2.0, -size.height()/2.0);
|
.translate(-size.width()/2.0, -size.height()/2.0);
|
||||||
|
painter->setOpacity(alpha);
|
||||||
painter->setTransform(trans, true);
|
painter->setTransform(trans, true);
|
||||||
painter->setRenderHint(QPainter::SmoothPixmapTransform);
|
painter->setRenderHint(QPainter::SmoothPixmapTransform);
|
||||||
painter->drawPixmap(0, 0, pmap);
|
painter->drawPixmap(0, 0, pmap);
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
|
||||||
|
class QVariantAnimation;
|
||||||
|
|
||||||
class Spinner : public QObject, public ChatLineContent
|
class Spinner : public QObject, public ChatLineContent
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -43,6 +45,8 @@ private:
|
||||||
QPixmap pmap;
|
QPixmap pmap;
|
||||||
qreal rotSpeed;
|
qreal rotSpeed;
|
||||||
QTimer timer;
|
QTimer timer;
|
||||||
|
qreal alpha = 0.0;
|
||||||
|
QVariantAnimation* blendAnimation;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user