summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2019-04-08 18:12:27 +0300
committerKonstantin Ritt <ritt.ks@gmail.com>2019-04-09 04:27:56 +0000
commitbe7dd232757f07d9fd4d95eafcff86171ee5acf7 (patch)
treefae742fe443c2e51645b6afc47cf67f0d481e554
parente4cf857dd2766e17ca86114db36f309490f9401d (diff)
LottieAnimation: minor refactoring
* add status getter/setter * ensure that no statusChanged() signal is emitted when status doesn't change * ensure that status change emits statusChanged() signal * move code around Change-Id: I39dce43c61dd2d4ed0d2b2824610885309b068d4 Reviewed-by: Rebecca Worledge <rebecca.worledge@theqtcompany.com>
-rw-r--r--src/imports/lottieanimation.cpp91
-rw-r--r--src/imports/lottieanimation.h6
2 files changed, 55 insertions, 42 deletions
diff --git a/src/imports/lottieanimation.cpp b/src/imports/lottieanimation.cpp
index 58e3043..61c264b 100644
--- a/src/imports/lottieanimation.cpp
+++ b/src/imports/lottieanimation.cpp
@@ -130,39 +130,6 @@ Q_LOGGING_CATEGORY(lcLottieQtBodymovinParser, "qt.lottieqt.bodymovin.parser");
*/
/*!
- \qmlproperty enumeration LottieAnimation::status
-
- This property holds the current status of the LottieAnimation element.
-
- \value LottieAnimation.Null
- An initial value that is used when the status is not defined
- (Default)
-
- \value LottieAnimation.Loading
- The player is loading a Bodymovin file
-
- \value LottieAnimation.Ready
- Loading has finished successfully and the player is ready to play
- the animation
-
- \value LottieAnimation.Error
- An error occurred while loading the animation
-
- For example, you could implement \c onStatusChanged signal
- handler to monitor progress of loading an animation as follows:
-
- \qml
- LottieAnimation {
- source: ":/animation.json"
- autoPlay: false
- onStatusChanged: {
- if (status === LottieAnimation.Ready)
- start();
- }
- \endqml
-*/
-
-/*!
\qmlproperty bool LottieAnimation::autoPlay
Defines whether the player will start playing animation automatically after
@@ -251,6 +218,52 @@ void LottieAnimation::paint(QPainter *painter)
}
/*!
+ \qmlproperty enumeration LottieAnimation::status
+
+ This property holds the current status of the LottieAnimation element.
+
+ \value LottieAnimation.Null
+ An initial value that is used when the source is not defined
+ (Default)
+
+ \value LottieAnimation.Loading
+ The player is loading a Bodymovin file
+
+ \value LottieAnimation.Ready
+ Loading has finished successfully and the player is ready to play
+ the animation
+
+ \value LottieAnimation.Error
+ An error occurred while loading the animation
+
+ For example, you could implement \c onStatusChanged signal
+ handler to monitor progress of loading an animation as follows:
+
+ \qml
+ LottieAnimation {
+ source: ":/animation.json"
+ autoPlay: false
+ onStatusChanged: {
+ if (status === LottieAnimation.Ready)
+ start();
+ }
+ \endqml
+*/
+LottieAnimation::Status LottieAnimation::status() const
+{
+ return m_status;
+}
+
+void LottieAnimation::setStatus(LottieAnimation::Status status)
+{
+ if (Q_UNLIKELY(m_status == status))
+ return;
+
+ m_status = status;
+ emit statusChanged();
+}
+
+/*!
\qmlproperty string LottieAnimation::source
The path of the Bodymovin asset that LottieAnimation plays.
@@ -560,20 +573,17 @@ void LottieAnimation::setDirection(LottieAnimation::Direction direction)
bool LottieAnimation::loadSource(QString filename)
{
- m_status = Loading;
- emit statusChanged();
+ setStatus(Loading);
QFile sourceFile(filename);
if (!sourceFile.open(QIODevice::ReadOnly)) {
- m_status = Error;
- emit statusChanged();
+ setStatus(Error);
return false;
}
QByteArray json = sourceFile.readAll();
if (Q_UNLIKELY(parse(json) == -1)) {
- m_status = Error;
- emit statusChanged();
+ setStatus(Error);
return false;
}
@@ -591,8 +601,7 @@ bool LottieAnimation::loadSource(QString filename)
m_frameRenderThread->start();
- m_status = Ready;
- emit statusChanged();
+ setStatus(Ready);
return true;
}
diff --git a/src/imports/lottieanimation.h b/src/imports/lottieanimation.h
index bc24d0d..305be59 100644
--- a/src/imports/lottieanimation.h
+++ b/src/imports/lottieanimation.h
@@ -52,7 +52,7 @@ class LottieAnimation : public QQuickPaintedItem
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)
+ Q_PROPERTY(Status status READ status WRITE setStatus NOTIFY statusChanged)
Q_PROPERTY(Quality quality READ quality WRITE setQuality NOTIFY qualityChanged)
Q_PROPERTY(bool autoPlay MEMBER m_autoPlay NOTIFY autoPlayChanged)
Q_PROPERTY(int loops MEMBER m_loops NOTIFY loopsChanged)
@@ -78,6 +78,8 @@ public:
void paint(QPainter *painter) override;
+ Status status() const;
+
QString source() const;
void setSource(const QString &source);
@@ -125,6 +127,8 @@ protected slots:
void renderNextFrame();
protected:
+ void setStatus(Status status);
+
bool loadSource(QString filename);
virtual int parse(QByteArray jsonSource);