-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmain.qml
269 lines (204 loc) · 6.84 KB
/
main.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
import QtQuick 2.8
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.0
import QtQuick.Window 2.2
import ScxmlStopWatch 1.0
import QtScxml 5.8
import "qrc:/../Include"
Window {
id: window
width: 320
height: 480
visible: true
title: qsTr("Stop Watch")
function pad(number) {
if (number < 10) {
return '0' + number;
}
return number;
}
ScxmlStopWatch {
id: machine
running: false
Component.onCompleted: {
/* DataModel values may be changed here */
machine.initialValues = {
"i_UPDATE_DELAY_MS" : 100 /* you may change interval here and
it will be applied to state machine */
}
machine.running = true
}
}
EventConnection {
stateMachine: machine
events: ["out.display"]
onOccurred: {
textTime.text = event.data.ElapsedMS
textLap.text = event.data.LapMS
/* Simple Timer Mode */
var lapCount = event.data.LapCount
if (lapCount===0) {
if (listView.model.count)
listView.model.clear()
}
/* User Pressed Lap Button */
else {
/* New Lap */
if ((listView.count-1)!==lapCount) {
/* If this is the first press of 'Lap' button */
/* display previous lap */
if (lapCount===1) {
listView.model.insert(0, { lapIndex: 1,
startTime: "00:00.000",
endTime: event.data.ElapsedMS })
}
/* current lap */
listView.model.insert(0, { lapIndex: lapCount + 1,
startTime: event.data.ElapsedMS,
endTime: "00:00.000" })
/* scroll to top item */
listView.currentIndex = 0
}
/* Updating Current Lap Values */
else if (listView.count>1) {
listView.model.setProperty(0, "endTime", event.data.LapMS)
}
}
}
}
Loader { /* OPTIONAL SVG MONITOR */
id: svgMonitorLoader
Component {
id: svgMonitorComponent
ScxmlSvgMonitorWindow {
id: svgMonitorWindow
visible: true
x: svgMonitorLoader.x
width: 620
height: 960
svgMonitor.svgUrl: "qrc:/StopWatch.svg"
Component.onCompleted: {
svgMonitor.scxmlStateMachine = machine
}
onVisibleChanged: if (!visible) { svgMonitorLoader.sourceComponent = null }
}
}
}
Item {
id: timeItem
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: listView.visible ? listView.top : bottomPanel.top
CheckBox { /* OPTIONAL SVG MONITOR */
id: checkMonitor
anchors.top: parent.top
anchors.right: parent.right
anchors.margins: 10
text: qsTr("Monitor")
checkable: false
checked: svgMonitorLoader.status === Loader.Ready
onClicked: {
var notmonitored = svgMonitorLoader.sourceComponent === null
if (notmonitored) {
svgMonitorLoader.x = window.x + window.width + 20
}
svgMonitorLoader.sourceComponent = notmonitored ?
svgMonitorComponent : null
}
}
Text {
id: textTime
anchors.fill: parent
text: "00:00"
font.pixelSize: 22
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
Text {
id: textLap
anchors.fill: parent
anchors.topMargin: 22 + 12 + 4
visible: listView.visible
text: "00:00"
font.pixelSize: 12
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
}
RowLayout {
id: bottomPanel
anchors.left: parent.left
anchors.margins: 5
anchors.right: parent.right
anchors.bottom: parent.bottom
height: 40
Button {
id: btn1
contentItem: Text {
text: btn1.text
font: btn1.font
color: machine.ready ? "black" : machine.active ? "red" : "green"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
text: machine.ready ? qsTr("Start") : machine.active ? qsTr("Pause") : qsTr("Resume")
Layout.fillWidth: true
Layout.fillHeight: true
onPressed: machine.submitEvent("button.1")
}
Button {
id: btn2
contentItem: Text {
text: btn2.text
font: btn2.font
color: machine.active ? "purple" : "blue"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
text: machine.active ? qsTr("Lap") : qsTr("Reset")
Layout.fillWidth: true
Layout.fillHeight: true
onPressed: machine.submitEvent("button.2")
visible: !machine.ready
}
}
ListView {
id: listView
anchors.top: parent.top
anchors.topMargin: parent.height / 3
anchors.right: parent.right
anchors.left: parent.left
anchors.bottomMargin: 20
anchors.bottom: bottomPanel.top
visible: count !== 0
ScrollBar.vertical: ScrollBar {
active: true
}
model: ListModel {
}
delegate:
RowLayout {
id: row1
x: 20
width: listView.width - 20
height: 30
spacing: 10
Text {
text: pad(lapIndex)
Layout.preferredWidth: row1.width * 0.2
Layout.fillHeight: true
}
Text {
text: startTime
Layout.preferredWidth: row1.width * 0.4
Layout.fillHeight: true
}
Text {
text: endTime
Layout.preferredWidth: row1.width * 0.4
Layout.fillHeight: true
}
}
}
}