aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2020-04-23 17:05:26 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-05-19 00:45:57 +0200
commitc2df9ce7b0cb6ac9a9117578a167d54a708c64b3 (patch)
tree7bacede462f1ca21886e9a36cbcf3bc4fa538cfc /examples
parentd62abf12a4d6e303d585850724f8ddc0ab448a75 (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 Change-Id: Ieb6d046168a2132659848a36ee0b694c580159b1 Reviewed-by: Andy Nichols <andy.nichols@qt.io> (cherry picked from commit af521a8df6caec41f626a4b3319601c20adff711) Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'examples')
-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
}