summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2019-04-08 17:38:13 +0300
committerRebecca Worledge <rebecca.worledge@theqtcompany.com>2019-04-09 03:11:28 +0000
commit03354671370a340637ae563871bb66d315913d15 (patch)
treebf1c5895a27cb09c061fe6e6ae300fc9d67eb1cf
parenta6c677ca70462dda0e7bdf3723093bb7ae5d82ff (diff)
LottieAnimation: fix frameRate property behavior
make it possible to reset overridden frameRate value to the animation-default one; do not frameRateChanged() signal when the value has not been changed Change-Id: I42ff22a82960f8083ffb2816b6a5d711644323fd Reviewed-by: Rebecca Worledge <rebecca.worledge@theqtcompany.com>
-rw-r--r--src/imports/lottieanimation.cpp17
-rw-r--r--src/imports/lottieanimation.h6
2 files changed, 17 insertions, 6 deletions
diff --git a/src/imports/lottieanimation.cpp b/src/imports/lottieanimation.cpp
index db49e10..ea0c308 100644
--- a/src/imports/lottieanimation.cpp
+++ b/src/imports/lottieanimation.cpp
@@ -192,6 +192,7 @@ LottieAnimation::LottieAnimation(QQuickItem *parent)
: QQuickPaintedItem(parent)
{
m_frameAdvance = new QTimer(this);
+ m_frameAdvance->setInterval(1000 / m_frameRate);
m_frameAdvance->setSingleShot(false);
connect (m_frameAdvance, &QTimer::timeout, this, &LottieAnimation::renderNextFrame);
@@ -335,10 +336,20 @@ int LottieAnimation::frameRate() const
void LottieAnimation::setFrameRate(int frameRate)
{
+ if (Q_UNLIKELY(m_frameRate == frameRate || frameRate <= 0))
+ return;
+
m_frameRate = frameRate;
+ emit frameRateChanged();
+
m_frameAdvance->setInterval(1000 / m_frameRate);
}
+void LottieAnimation::resetFrameRate()
+{
+ setFrameRate(m_animFrameRate);
+}
+
/*!
\qmlproperty enumeration LottieAnimation::quality
@@ -581,8 +592,6 @@ bool LottieAnimation::loadSource(QString filename)
QMetaObject::invokeMethod(m_frameRenderThread, "registerAnimator", Q_ARG(LottieAnimation*, this));
- m_frameAdvance->setInterval(1000 / m_frameRate);
-
if (m_autoPlay)
start();
@@ -642,7 +651,7 @@ int LottieAnimation::parse(QByteArray jsonSource)
m_startFrame = rootObj.value(QLatin1String("ip")).toVariant().toInt();
m_endFrame = rootObj.value(QLatin1String("op")).toVariant().toInt();
- m_frameRate = rootObj.value(QLatin1String("fr")).toVariant().toInt();
+ m_animFrameRate = rootObj.value(QLatin1String("fr")).toVariant().toInt();
m_animWidth = rootObj.value(QLatin1String("w")).toVariant().toReal();
m_animHeight = rootObj.value(QLatin1String("h")).toVariant().toReal();
@@ -668,9 +677,9 @@ int LottieAnimation::parse(QByteArray jsonSource)
if (rootObj.value(QLatin1String("chars")).toArray().count())
qCWarning(lcLottieQtBodymovinParser) << "chars not supported";
- emit frameRateChanged();
emit startFrameChanged();
emit endFrameChanged();
+ setFrameRate(m_animFrameRate);
return 0;
}
diff --git a/src/imports/lottieanimation.h b/src/imports/lottieanimation.h
index 96ec348..bc24d0d 100644
--- a/src/imports/lottieanimation.h
+++ b/src/imports/lottieanimation.h
@@ -49,7 +49,7 @@ class LottieAnimation : public QQuickPaintedItem
{
Q_OBJECT
Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged)
- Q_PROPERTY(int frameRate READ frameRate WRITE setFrameRate NOTIFY frameRateChanged)
+ Q_PROPERTY(int frameRate READ frameRate WRITE setFrameRate RESET resetFrameRate NOTIFY frameRateChanged)
Q_PROPERTY(int startFrame READ startFrame NOTIFY startFrameChanged)
Q_PROPERTY(int endFrame READ endFrame NOTIFY endFrameChanged)
Q_PROPERTY(Status status MEMBER m_status NOTIFY statusChanged)
@@ -83,6 +83,7 @@ public:
int frameRate() const;
void setFrameRate(int frameRate);
+ void resetFrameRate();
Quality quality() const;
void setQuality(Quality quality);
@@ -135,8 +136,9 @@ protected:
Status m_status = Null;
int m_startFrame = 0;
int m_endFrame = 0;
- int m_frameRate = 30;
int m_currentFrame = 0;
+ int m_frameRate = 30;
+ int m_animFrameRate = 30;
qreal m_animWidth = 0;
qreal m_animHeight = 0;
QHash<QString, int> m_markers;