[Qt-qml] Pause animation until a condition is met
Adriano Rezende
adriano.rezende at openbossa.org
Fri Sep 3 18:05:15 CEST 2010
On Fri, Aug 27, 2010 at 6:58 PM, Alex <alexlordax+qt at gmail.com> wrote:
> ConditionPauseAnimation.qml
> =====================
>
> SequentialAnimation {
> id: root
>
> property bool condition
>
> loops: condition ? 0 : Animation.Infinite
>
> ScriptAction {
> script: {
> if(condition) {
> root.running = false
> }
> }
> }
>
> PauseAnimation { duration: 200 }
> }
>
> Usage in Nigel's example:
>
> ConditionPauseAnimation { condition: buttonMouseArea.pressed == false }
>
There is a problem with this approach.
You should not stop an animation that is inside a group animation.
So you cannot use ConditionPauseAnimation inside a group to be used
like a guard.
To do what you want you can do like this:
GuardAnimation.qml
===========================================
ScriptAction {
property variant target
property bool condition
script: if (condition) target.paused = true
onConditionChanged: target.paused = false
}
Example of usage:
===========================================
Item {
width: 500
height: 500
Rectangle {
id: item
width: 100
height: 100
color: "red"
}
MouseArea {
id: mouseArea
anchors.fill: parent
}
SequentialAnimation {
id: animation
running: true
loops: Animation.Infinite
NumberAnimation { target: item; properties: "y"; from: 0; to:
100; duration: 500; }
GuardAnimation { target: animation; condition: mouseArea.pressed; }
NumberAnimation { target: item; properties: "y"; from: 100;
to: 0; duration: 500; }
}
}
Br,
Adriano
More information about the Qt-qml
mailing list