From: Alan Alpert Date: Wed, 9 May 2012 07:01:37 +0000 (+1000) Subject: AnimatedSprite framespeed properties now restart animation. X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=67fb05034c9758d25464f2103ae6068dbc9bb110;p=konrad%2Fqtdeclarative.git AnimatedSprite framespeed properties now restart animation. For a simple element, we're taking the simple solution for the interaction of changing these parameters during an animation. Task-number: QTBUG-25045 Task-number: QTBUG-25043 Change-Id: I1fb37fc029f23ce92558cb2e5deed80a69784173 Reviewed-by: Martin Jones --- diff --git a/src/quick/items/qquickanimatedsprite.cpp b/src/quick/items/qquickanimatedsprite.cpp index 7110351..2049001 100644 --- a/src/quick/items/qquickanimatedsprite.cpp +++ b/src/quick/items/qquickanimatedsprite.cpp @@ -237,19 +237,23 @@ struct AnimatedSpriteVertices { /*! \qmlproperty qreal QtQuick2::AnimatedSprite::frameRate - Frames per second to show in the animation. Values below 0 are invalid. + Frames per second to show in the animation. Values equal to or below 0 are invalid. If frameRate is valid then it will be used to calculate the duration of the frames. If not, and frameDuration is valid , then frameDuration will be used. + + Changing this parameter will restart the animation. */ /*! \qmlproperty int QtQuick2::AnimatedSprite::frameDuration - Duration of each frame of the animation. Values below 0 are invalid. + Duration of each frame of the animation. Values equal to or below 0 are invalid. If frameRate is valid then it will be used to calculate the duration of the frames. If not, and frameDuration is valid, then frameDuration will be used. + + Changing this parameter will restart the animation. */ /*! @@ -314,6 +318,8 @@ struct AnimatedSpriteVertices { If frameSync is set to true, it overrides both frameRate and frameDuration. Default is false. + + Changing this parameter will restart the animation. */ /*! @@ -383,6 +389,11 @@ void QQuickAnimatedSprite::start() return; m_curLoop = 0; m_timestamp.start(); + if (m_spriteEngine) { + m_spriteEngine->stop(0); + m_spriteEngine->updateSprites(0); + m_spriteEngine->start(0); + } m_running = true; emit runningChanged(true); update(); @@ -393,6 +404,7 @@ void QQuickAnimatedSprite::stop() if (!m_running) return; m_running = false; + m_pauseOffset = 0; emit runningChanged(false); } @@ -550,7 +562,7 @@ void QQuickAnimatedSprite::prepareNextFrame() if (m_node == 0) //error creating node return; - uint timeInt = m_timestamp.elapsed() + m_pauseOffset; + int timeInt = m_timestamp.elapsed() + m_pauseOffset; qreal time = timeInt / 1000.; m_material->elementHeight = height(); m_material->elementWidth = width(); diff --git a/src/quick/items/qquickanimatedsprite_p.h b/src/quick/items/qquickanimatedsprite_p.h index 708f94b..fb00136 100644 --- a/src/quick/items/qquickanimatedsprite_p.h +++ b/src/quick/items/qquickanimatedsprite_p.h @@ -249,6 +249,7 @@ public slots: if (m_sprite->m_frameSync != arg) { m_sprite->setFrameSync(arg); emit frameSyncChanged(arg); + restart(); } } @@ -302,6 +303,7 @@ public slots: if (m_sprite->m_frameRate != arg) { m_sprite->setFrameRate(arg); emit frameRateChanged(arg); + restart(); } } @@ -310,6 +312,7 @@ public slots: if (m_sprite->m_frameDuration != arg) { m_sprite->setFrameDuration(arg); emit frameDurationChanged(arg); + restart(); } }