diff options
author | Jan Arve Saether <jan-arve.saether@qt.io> | 2020-03-25 16:53:18 +0100 |
---|---|---|
committer | Jan Arve Sæther <jan-arve.saether@qt.io> | 2020-04-02 07:29:37 +0200 |
commit | 5a2f1f4c71a71dbc01af71bdbc83ff650475f525 (patch) | |
tree | 0dd431bd88030429d9120f32b5b88b64978dec00 /src | |
parent | cbd4456c9db70afda6c8408be7e5da800889d169 (diff) |
Fix signal emission order for zero-duration animations
The order for non-zero-duration animations are:
* started()
* runningChanged(true)
* stopped()
* runningChanged(false)
* finished()
This patch tries to ensure that zero-duration animations have the same signal
emission order.
The problem was that when setRunning(true) was called on zero-duration
animation, it would call itself (setRunning(false)) lower in the call stack in
order to immediately stop again. This had the implication that we could emit
stopped() even before started() was emitted (since the recursive call to
setRunning(false) would actually complete before the ancestor stack frame
setRunning(true) was completed)
To fix this we emit started() *before* we call start() on the animationInstance.
There is still a bug in that runningChanged(true) is still not emitted for a
zero-duration animation, but this patch should improve the current behavior in
the sense that stopped() is not emitted _before_ started().
Task-number: QTBUG-48193
Change-Id: Ic2bc85e648e6746f6a058e2e9136515e7fdb6192
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit 8e0711cafd7e78c6e5d77fdda6be91135a355cd1)
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/quick/util/qquickanimation.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/quick/util/qquickanimation.cpp b/src/quick/util/qquickanimation.cpp index 2043b50545..34942bdd9a 100644 --- a/src/quick/util/qquickanimation.cpp +++ b/src/quick/util/qquickanimation.cpp @@ -176,11 +176,8 @@ void QQuickAbstractAnimationPrivate::commence() animationInstance = new QQuickAnimatorProxyJob(animationInstance, q); animationInstance->addAnimationChangeListener(this, QAbstractAnimationJob::Completion); } + emit q->started(); animationInstance->start(); - if (animationInstance->isStopped()) { - running = false; - emit q->stopped(); - } } } @@ -293,10 +290,8 @@ void QQuickAbstractAnimation::setRunning(bool r) d->animationInstance->setLoopCount(d->animationInstance->currentLoop() + d->loopCount); supressStart = true; //we want the animation to continue, rather than restart } - if (!supressStart) { + if (!supressStart) d->commence(); - emit started(); - } } else { if (d->paused) { d->paused = false; //reset paused state to false when stopped @@ -314,7 +309,16 @@ void QQuickAbstractAnimation::setRunning(bool r) } } - emit runningChanged(d->running); + + if (r == d->running) { + // This might happen if we start an animation with 0 duration: This will result in that + // commence() will emit started(), and then when it starts it will call setCurrentTime(0), + // (which is both start and end time of the animation), so it will also end up calling + // setRunning(false) (recursively) and stop the animation. + // Therefore, the state of d->running will in that case be different than r if we are back in + // the root stack frame of the recursive calls to setRunning() + emit runningChanged(d->running); + } } /*! |