diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2019-04-08 17:38:13 +0300 |
---|---|---|
committer | Rebecca Worledge <rebecca.worledge@theqtcompany.com> | 2019-04-09 03:11:28 +0000 |
commit | 03354671370a340637ae563871bb66d315913d15 (patch) | |
tree | bf1c5895a27cb09c061fe6e6ae300fc9d67eb1cf /src/imports/lottieanimation.cpp | |
parent | a6c677ca70462dda0e7bdf3723093bb7ae5d82ff (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>
Diffstat (limited to 'src/imports/lottieanimation.cpp')
-rw-r--r-- | src/imports/lottieanimation.cpp | 17 |
1 files changed, 13 insertions, 4 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; } |