aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick/imageelements/animatedsprite.qml
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2020-04-23 17:05:26 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2020-04-24 10:24:58 +0200
commitaf521a8df6caec41f626a4b3319601c20adff711 (patch)
treefec25e4f642f55e842b3c9e0807de3579ce02d90 /examples/quick/imageelements/animatedsprite.qml
parent119be2f769a1fee1ef115ee99a239264e2daff71 (diff)
Resume AnimatedSprite playback when visibility changes
Amends f5e2783 that was made in 5.6 to avoid updating the AnimatedSprite when not visible. The problem is, if the sprite was running, the expectation is that becoming visible again resumes the playback. It can be argued what the correct behavior is: do we expect the playback to resume from the point when the sprite went invisible, or should it take the time spent as invisible into account? This patch only corrects the immediate problem and provides the former, i.e. playback will resume from the point it had when becoming invisible. The AnimatedSprite scene in the imageelements example is improved to be able to test this. It can also exercise all the start/pause/resume/advance functions now. Fixes: QTBUG-63942 Pick-to: 5.15 Change-Id: Ieb6d046168a2132659848a36ee0b694c580159b1 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'examples/quick/imageelements/animatedsprite.qml')
-rw-r--r--examples/quick/imageelements/animatedsprite.qml24
1 files changed, 18 insertions, 6 deletions
diff --git a/examples/quick/imageelements/animatedsprite.qml b/examples/quick/imageelements/animatedsprite.qml
index cc5226882a..8666c2b9fc 100644
--- a/examples/quick/imageelements/animatedsprite.qml
+++ b/examples/quick/imageelements/animatedsprite.qml
@@ -70,19 +70,31 @@ Item {
}
//! [sprite]
+ Text {
+ text: "Left click to resume\nMiddle click to advance backward\nRight click to advance forward"
+ visible: sprite.paused
+ }
+
MouseArea {
anchors.fill: parent
- acceptedButtons: Qt.LeftButton | Qt.RightButton
+ acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
onClicked: (mouse) => {
- if (!sprite.running)
+ if (!sprite.running) {
sprite.start();
- if (!sprite.paused)
+ } else if (!sprite.paused) {
sprite.pause();
- if ( mouse.button == Qt.LeftButton ) {
- sprite.advance(1);
} else {
- sprite.advance(-1);
+ if (mouse.button === Qt.LeftButton)
+ sprite.resume();
+ else if (mouse.button === Qt.MiddleButton)
+ sprite.advance(-1);
+ else if (mouse.button === Qt.RightButton)
+ sprite.advance(1);
}
}
}
+
+ Component.onCompleted: console.log("Press Space to toggle visibility. Click with mouse to pause/resume.")
+ focus: true
+ Keys.onSpacePressed: sprite.visible = !sprite.visible
}