-
Notifications
You must be signed in to change notification settings - Fork 0
/
18_states_and_transitions.qml
104 lines (94 loc) · 3.05 KB
/
18_states_and_transitions.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
Rectangle {
width: 150; height: 360
color: "black"
Rectangle {
id: redLight
x: 25; y: 15; width: 100; height: 100
radius: 50
}
Rectangle {
id: yellowLight
x: 25; y: 130; width: 100; height: 100
radius: 50
}
Rectangle {
id: greenLight
x: 25; y: 245; width: 100; height: 100
radius: 50
}
states: [
State {
name: "stopState"
PropertyChanges { target: redLight; color: "red" }
PropertyChanges { target: yellowLight; color: "lightGray" }
PropertyChanges { target: greenLight; color: "lightGray" }
},
State {
name: "waitState"
PropertyChanges { target: redLight; color: "red" }
PropertyChanges { target: yellowLight; color: "yellow" }
PropertyChanges { target: greenLight; color: "lightGray" }
},
State {
name: "driveState"
PropertyChanges { target: redLight; color: "lightGray" }
PropertyChanges { target: yellowLight; color: "lightGray" }
PropertyChanges { target: greenLight; color: "green" }
},
State {
name: "slowState"
PropertyChanges { target: redLight; color: "lightGray" }
PropertyChanges { target: yellowLight; color: "yellow" }
PropertyChanges { target: greenLight; color: "lightGray" }
}
]
state: "stopState"
Timer {
interval: 1000
repeat: true
running: true
onTriggered: {
var states = ["stopState", "waitState", "driveState", "slowState"]
var nextIndex = ( states.indexOf(parent.state) + 1 ) % states.length
parent.state = states[nextIndex]
}
}
// transitions: [
// Transition {
// from: "stopState"; to: "waitState"
// PropertyAnimation {
// targets: [redLight, yellowLight]
// properties: "color"; duration: 100
// }
// },
// Transition {
// from: "waitState"; to: "driveState"
// PropertyAnimation {
// targets: [redLight, yellowLight, greenLight]
// properties: "color"; duration: 100
// }
// },
// Transition {
// from: "driveState"; to: "slowState"
// PropertyAnimation {
// targets: [greenLight, yellowLight]
// properties: "color"; duration: 100
// }
// },
// Transition {
// from: "slowState"; to: "stopState"
// PropertyAnimation {
// targets: [yellowLight, redLight]
// properties: "color"; duration: 100
// }
// }
// ]
// transitions: [
// Transition {
// from: "*"; to: "*"
// PropertyAnimation {
// targets: [redLight, yellowLight, greenLight]
// properties: "color"; duration: 100
// }
// } ]
}