StateMachine or SequentialAnimation?
Unsolved
QML and Qt Quick
-
I'm looking for an advice about the best approach for this scenario.
I have to write a QML item that do the following:
- it has 4 states, let's call them rise1, wait1, rise2, wait2
- they runs in circle: rise1 -> wait1 -> rise2 -> wait2 -> rise1 -> ...
- each state has a specific duration in time (I have 4 properties to store their duration)
- a text shows the current time spent in each state
- there are two kind of transitions:
- a transition between one state and another (i.e., change the color and the label of the text)
- an animation that runs during the whole duration of the state (i.e. the text moves with the same duration of the current state)
I can use a
SequentialAnimation
, where each step is a state. But I will have difficult to provide internal animations (the counter to be updated each second). I have to placeScriptAction
here and there to initialize the timer, update the label, etc...:SequentialAnimation { // state: rise1 ScriptAction { script: initializeRise1(); } ParallelAnimation { PropertyAnimation { /* animation during rise1*/ } PropertyAnimation { /* animation during rise1*/ } } ParallelAnimation { PropertyAnimation { /* transition to wait1 */ } PropertyAnimation { /* transition to wait1 */ } } ScriptAction { script: finalizeRise1(); } // state: wait1 // ... } Timer { id: timer // this will update the counter } function initializeRise1() { myLabel.text = "Rise 1" timer.interval = 10 timer.running = true }
Do you think a StateMachine can be more suitable for this use case?