Make stop state max arc

This commit is contained in:
Kovid Goyal 2020-12-04 18:42:25 +05:30
parent 3973d843e5
commit 1b5f9a97d0
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -8,6 +8,10 @@
#include <QPropertyAnimation> #include <QPropertyAnimation>
#include <QParallelAnimationGroup> #include <QParallelAnimationGroup>
#define arc_length_max 0.734f
#define arc_length_min 0.02f
class SpinAnimator: public QObject { class SpinAnimator: public QObject {
Q_OBJECT Q_OBJECT
Q_PROPERTY(float arc_length READ get_arc_length WRITE set_arc_length) Q_PROPERTY(float arc_length READ get_arc_length WRITE set_arc_length)
@ -16,7 +20,7 @@ class SpinAnimator: public QObject {
public: public:
SpinAnimator(QObject* parent = 0, const int speed_factor=300) : SpinAnimator(QObject* parent = 0, const int speed_factor=300) :
QObject(parent), QObject(parent),
m_arc_length(0), m_arc_length(arc_length_max),
m_arc_rotation(0), m_arc_rotation(0),
m_overall_rotation(0), m_overall_rotation(0),
m_has_pending_updates(false), m_has_pending_updates(false),
@ -25,7 +29,6 @@ public:
QPropertyAnimation *a; QPropertyAnimation *a;
#define S(property, duration) a = new QPropertyAnimation(this, QByteArray(#property), this); a->setEasingCurve(QEasingCurve::InOutCubic); a->setDuration(duration); a->setLoopCount(-1); m_animation.addAnimation(a); #define S(property, duration) a = new QPropertyAnimation(this, QByteArray(#property), this); a->setEasingCurve(QEasingCurve::InOutCubic); a->setDuration(duration); a->setLoopCount(-1); m_animation.addAnimation(a);
S(arc_length, 7 * speed_factor); S(arc_length, 7 * speed_factor);
const float arc_length_max = 0.734f, arc_length_min = 0.01f;
a->setStartValue(arc_length_min); a->setStartValue(arc_length_min);
a->setKeyValueAt(0.25, arc_length_min); a->setKeyValueAt(0.25, arc_length_min);
a->setKeyValueAt(0.5, arc_length_max); a->setKeyValueAt(0.5, arc_length_max);
@ -46,7 +49,7 @@ public:
} }
~SpinAnimator() { m_animation.stop(); m_animation.clear(); } ~SpinAnimator() { m_animation.stop(); m_animation.clear(); }
void start() { m_animation.start(); } void start() { m_animation.start(); }
void stop() { m_animation.stop(); } void stop() { m_animation.stop(); m_arc_length = arc_length_max; m_arc_rotation = 0; m_overall_rotation = 0; notify_of_update(); }
bool is_running() { return m_animation.state() == QAbstractAnimation::Running; } bool is_running() { return m_animation.state() == QAbstractAnimation::Running; }
void draw(QPainter &painter, QRect bounds, const QColor &color, const float thickness=0.f) { void draw(QPainter &painter, QRect bounds, const QColor &color, const float thickness=0.f) {
m_has_pending_updates = false; m_has_pending_updates = false;