aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items
diff options
context:
space:
mode:
authorLouis du Verdier <louis.du.verdier@free.fr>2017-07-29 22:57:43 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2018-01-16 11:45:34 +0000
commite26e1c61c7acb1538a50c9ab570c6811c652581d (patch)
tree7ac82daa87b15be4cec32ab00e41689e96bf3925 /src/quick/items
parent196c691ebce3a48c6479162f3084790b6d0af8b8 (diff)
Add a speed property to AnimatedImage
QMovie handles most of AnimatedImage's behaviors and already provides a speed property (that is a percentage, 100% by default). This commit only offers the possibility to change its value from the QML. Task-number: QTBUG-62203 Change-Id: I8b7b79053181c1544aee1e95054b3b48229381fb Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/items')
-rw-r--r--src/quick/items/qquickanimatedimage.cpp27
-rw-r--r--src/quick/items/qquickanimatedimage_p.h5
-rw-r--r--src/quick/items/qquickanimatedimage_p_p.h3
-rw-r--r--src/quick/items/qquickitemsmodule.cpp4
4 files changed, 38 insertions, 1 deletions
diff --git a/src/quick/items/qquickanimatedimage.cpp b/src/quick/items/qquickanimatedimage.cpp
index 5bc5b0faff..4180714f86 100644
--- a/src/quick/items/qquickanimatedimage.cpp
+++ b/src/quick/items/qquickanimatedimage.cpp
@@ -260,6 +260,32 @@ int QQuickAnimatedImage::frameCount() const
return d->_movie->frameCount();
}
+/*!
+ \qmlproperty real QtQuick::AnimatedImage::speed
+ \since QtQuick 2.11
+
+ This property holds the speed of the animation.
+
+ The speed is measured in percentage of the original animated image speed.
+ The default speed is 1.0 (original speed).
+*/
+qreal QQuickAnimatedImage::speed() const
+{
+ Q_D(const QQuickAnimatedImage);
+ return d->speed;
+}
+
+void QQuickAnimatedImage::setSpeed(qreal speed)
+{
+ Q_D(QQuickAnimatedImage);
+ if (d->speed != speed) {
+ d->speed = speed;
+ if (d->_movie)
+ d->_movie->setSpeed(qRound(speed * 100.0));
+ emit speedChanged();
+ }
+}
+
void QQuickAnimatedImage::setSource(const QUrl &url)
{
Q_D(QQuickAnimatedImage);
@@ -396,6 +422,7 @@ void QQuickAnimatedImage::movieRequestFinished()
this, SLOT(movieUpdate()));
if (d->cache)
d->_movie->setCacheMode(QMovie::CacheAll);
+ d->_movie->setSpeed(qRound(d->speed * 100.0));
d->status = Ready;
emit statusChanged(d->status);
diff --git a/src/quick/items/qquickanimatedimage_p.h b/src/quick/items/qquickanimatedimage_p.h
index f7a6bd808b..678907a6e2 100644
--- a/src/quick/items/qquickanimatedimage_p.h
+++ b/src/quick/items/qquickanimatedimage_p.h
@@ -70,6 +70,7 @@ class Q_AUTOTEST_EXPORT QQuickAnimatedImage : public QQuickImage
Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged)
Q_PROPERTY(int currentFrame READ currentFrame WRITE setCurrentFrame NOTIFY frameChanged)
Q_PROPERTY(int frameCount READ frameCount NOTIFY frameCountChanged)
+ Q_PROPERTY(qreal speed READ speed WRITE setSpeed NOTIFY speedChanged REVISION 11)
// read-only for AnimatedImage
Q_PROPERTY(QSize sourceSize READ sourceSize NOTIFY sourceSizeChanged)
@@ -89,6 +90,9 @@ public:
int frameCount() const;
+ qreal speed() const;
+ void setSpeed(qreal speed);
+
// Extends QQuickImage's src property
void setSource(const QUrl&) override;
virtual QSize sourceSize();
@@ -98,6 +102,7 @@ Q_SIGNALS:
void pausedChanged();
void frameChanged();
void frameCountChanged();
+ Q_REVISION(11) void speedChanged();
private Q_SLOTS:
void movieUpdate();
diff --git a/src/quick/items/qquickanimatedimage_p_p.h b/src/quick/items/qquickanimatedimage_p_p.h
index 68c4f2d359..ef30c39fed 100644
--- a/src/quick/items/qquickanimatedimage_p_p.h
+++ b/src/quick/items/qquickanimatedimage_p_p.h
@@ -70,7 +70,7 @@ class QQuickAnimatedImagePrivate : public QQuickImagePrivate
public:
QQuickAnimatedImagePrivate()
- : playing(true), paused(false), preset_currentframe(0), _movie(0), oldPlaying(false)
+ : playing(true), paused(false), speed(1.0), preset_currentframe(0), _movie(0), oldPlaying(false)
#if QT_CONFIG(qml_network)
, reply(0), redirectCount(0)
#endif
@@ -82,6 +82,7 @@ public:
bool playing;
bool paused;
+ qreal speed;
int preset_currentframe;
QMovie *_movie;
bool oldPlaying;
diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp
index a7600c97bc..4839b4dd4f 100644
--- a/src/quick/items/qquickitemsmodule.cpp
+++ b/src/quick/items/qquickitemsmodule.cpp
@@ -411,6 +411,10 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor)
#if QT_CONFIG(quick_path)
qmlRegisterType<QQuickPathAngleArc>(uri, 2, 11, "PathAngleArc");
#endif
+
+#if QT_CONFIG(quick_animatedimage)
+ qmlRegisterType<QQuickAnimatedImage, 11>(uri, 2, 11,"AnimatedImage");
+#endif
}
static void initResources()