-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeProgressBar.qml
More file actions
461 lines (411 loc) · 19.1 KB
/
Copy pathTimeProgressBar.qml
File metadata and controls
461 lines (411 loc) · 19.1 KB
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
Rectangle {
id: root
// border.color: "#ff8c00"
border.width: 2
border.color: "#464646"
color: "#2B2B2B"
property var model: null
property int visibleStartTime: 0
property int visibleEndTime: RegimeManager.getTotalEstimatedTime()
property real timelineScale: 1.0 // Scale factor for timeline width
Component.onCompleted: {
updateTimeRange()
RegimeManager.updateVisibleRegimes(root.visibleStartTime, root.visibleEndTime)
}
Connections {
target: RegimeManager.visibleRegimeModel
function onTimelineUpdateRequired() {
updateTimeRange()
var totalTime = RegimeManager.getTotalEstimatedTime()
if (totalTime > 0) {
root.visibleStartTime = 0
root.visibleEndTime = totalTime
startTimeField.text = formatTime(0)
endTimeField.text = formatTime(totalTime)
updateVisibleRange()
}
}
}
Connections {
target: RegimeManager
function onRegimeDataUpdated() {
// Force immediate refresh of timeline when regime data changes
updateTimeRange()
}
}
function updateTimeRange() {
var totalTime = RegimeManager.getTotalEstimatedTime()
if (totalTime > 0) {
// Reset scale to 1.0 (perfect fit) on any update
timelineScale = 1.0
scaleSpinBox.value = 1
// Update end time if it's currently at max or unset
if (root.visibleEndTime >= totalTime || root.visibleEndTime === 0) {
root.visibleEndTime = totalTime
endTimeField.text = formatTime(totalTime)
}
// Update start time field
startTimeField.text = formatTime(root.visibleStartTime)
// Update time label
timeLabel.text = formatTime(RegimeManager.getTotalElapsedTime()) + " / " + formatTime(totalTime)
// Update visible regimes
RegimeManager.updateVisibleRegimes(root.visibleStartTime, root.visibleEndTime)
}
}
function formatTime(seconds) {
var hours = Math.floor(seconds / 3600)
var minutes = Math.floor((seconds % 3600) / 60)
var secs = seconds % 60
return Qt.formatTime(new Date(0, 0, 0, hours, minutes, secs), "hh:mm:ss")
}
function timeToSeconds(timeString) {
var parts = timeString.split(':')
if (parts.length !== 3) {
return 0
}
var hours = parseInt(parts[0], 10)
var minutes = parseInt(parts[1], 10)
var seconds = parseInt(parts[2], 10)
if (isNaN(hours) || isNaN(minutes) || isNaN(seconds)) {
return 0
}
return hours * 3600 + minutes * 60 + seconds
}
function updateVisibleRange() {
// Reset scale to 1.0 when time range changes
timelineScale = 1.0
scaleSpinBox.value = 1
RegimeManager.updateVisibleRegimes(root.visibleStartTime, root.visibleEndTime)
}
// ScrollView containing the timeline
ScrollView {
id: scrollView
implicitWidth: parent.width
// width: parent.width
height: 50
clip: true
// Calculate content width: at scale 1.0, all visible regimes fit in available width
contentWidth: {
var availableWidth = root.width // Account for margins
return Math.max(availableWidth, availableWidth * timelineScale)
}
ScrollBar.horizontal.policy: ScrollBar.AsNeeded
// Timeline content
Row {
y: 5
id: progressBar
width: scrollView.contentWidth
height: 30
spacing: 1
Repeater {
id: repeater
model: RegimeManager.visibleRegimeModel
delegate: Rectangle {
width: {
var visibleDuration = root.visibleEndTime - root.visibleStartTime
if (visibleDuration <= 0) return 0
var baseWidth = root.width // Same as available width calculation
// Each entry now represents a single repeat, so use maxTime directly
return model.maxTime / visibleDuration * baseWidth * timelineScale
}
height: progressBar.height
color: {
switch (model.state) {
case 2: return "lightblue" // Running
case 5: return "lightgreen" // Done
case 4: return "lightgray" // Skipped
case 6: return "lightcoral" // Error
default: return "white" // Waiting
}
}
border.color: model.isCycle ? "#9FC9CA" : "#464646" // Gray border for cycles
border.width: model.isCycle ? 1 : 2 // Thicker border for cycles
// Each rectangle now represents a single repeat
// Condition progress indicator (if condition time exists)
Rectangle {
id: conditionProgress
width: {
if (model.conditionTime > 0 && model.state === 2) { // Running
var conditionTimePassed = model.conditionTimePassed || 0
var conditionProgressRatio = conditionTimePassed / model.conditionTime
var conditionWidthRatio = model.conditionTime / model.maxTime
return Math.min(conditionProgressRatio, 1.0) * conditionWidthRatio * parent.width
}
return 0
}
height: parent.height
color: "#ff9500" // Orange color for condition progress
opacity: 0.8
visible: model.conditionTime > 0 && model.state === 2 // Only show when running and has condition
}
// Regime execution progress indicator (starts after condition)
Rectangle {
id: regimeProgress
x: {
if (model.conditionTime > 0) {
var conditionWidthRatio = model.conditionTime / model.maxTime
return conditionWidthRatio * parent.width
}
return 0
}
width: {
if (model.maxTime > 0 && model.state === 2) { // Running
var regimeTimePassed = model.regimeTimePassed || 0
var regimeExecutionTime = model.regimeExecutionTime
if (regimeExecutionTime > 0) {
var regimeProgressRatio = regimeTimePassed / regimeExecutionTime
var regimeWidthRatio = regimeExecutionTime / model.maxTime
return Math.min(regimeProgressRatio, 1.0) * regimeWidthRatio * parent.width
}
}
return 0
}
height: parent.height
color: "#3399ff" // Blue color for regime execution progress
opacity: 0.7
visible: model.state === 2 // Running
}
// Separator line between condition and regime execution (if condition exists)
Rectangle {
x: {
if (model.conditionTime > 0) {
var conditionWidthRatio = model.conditionTime / model.maxTime
return conditionWidthRatio * parent.width - 1
}
return 0
}
width: 2
height: parent.height
color: "#333333" // Dark separator line
opacity: 0.6
visible: model.conditionTime > 0
}
// Regime name text with repeat info
Text {
text: {
let baseName = model.name
let repeatInfo = ""
if (!model.isCycleEntry) {
repeatInfo += "Повтор " + (model.repeatIndex + 1)
}
else{
repeatInfo += "Цикл " + (model.cycleRepeatIndex + 1)
}
return baseName + "\n" + repeatInfo
}
anchors.centerIn: parent
color: "black"
font.pixelSize: Math.max(6, Math.min(10, parent.width / 12))
elide: Text.ElideRight
width: parent.width - 4
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
wrapMode: Text.WordWrap
}
// Tooltip on hover
MouseArea {
anchors.fill: parent
hoverEnabled: true
ToolTip {
contentWidth: 200
visible: parent.containsMouse
text: {
var tooltip = `${model.name}\nПовтор: ${model.repeatIndex + 1}`
if (model.isCycleEntry) {
tooltip += ` (Цикл ${model.cycleRepeatIndex + 1})`
}
tooltip += `\nДлительность: ${formatTime(model.maxTime)}\nСостояние: ${getStateName(model.state)}`
// Add progress information
if (model.conditionTime > 0) {
if (model.conditionCompleted) {
tooltip += `\nУсловие: ✓ Выполнено`
tooltip += `\nПрогресс выполнения: ${formatTime(model.regimeTimePassed || 0)} / ${formatTime(model.regimeExecutionTime)}`
} else {
tooltip += `\nПрогресс условия: ${formatTime(model.conditionTimePassed || 0)} / ${formatTime(model.conditionTime)}`
}
} else {
tooltip += `\nПрогресс выполнения: ${formatTime(model.regimeTimePassed || 0)} / ${formatTime(model.regimeExecutionTime)}`
}
// Add condition information if available
var regime = RegimeManager.model.getRegime(index)
if (regime && regime.condition) {
if (regime.condition.type === "time") {
tooltip += `\nУсловие: Ожидание ${regime.condition.time} мин`
} else if (regime.condition.type === "temp") {
tooltip += `\nУсловие: ${regime.condition.temp}°C + ${regime.condition.time} мин`
} else {
tooltip += `\nУсловие: Отсутствует`
}
}
// Add execution time breakdown
if (model.conditionTime > 0) {
tooltip += `\nВремя условия: ${formatTime(model.conditionTime)}`
tooltip += `\nВремя выполнения: ${formatTime(model.regimeExecutionTime)}`
}
// Add repeat statistics if any completed
if (regime && (regime.repeatsDone > 0 || regime.repeatsSkipped > 0 || regime.repeatsError > 0)) {
tooltip += `\nВыполнено: ${regime.repeatsDone}, Пропущено: ${regime.repeatsSkipped}, Ошибок: ${regime.repeatsError}`
}
if (model.isCycle) {
tooltip += `\nID цикла: ${model.cycleId}\nТип: Цикл`
} else {
tooltip += `\nТип: Отдельный режим`
}
return tooltip
}
delay: 500
}
}
}
}
}
}
// Time label below the timeline
Label {
id: timeLabel
y: 55
width: parent.width
// color: "white"
text: formatTime(RegimeManager.getTotalElapsedTime()) + " / " + formatTime(RegimeManager.getTotalEstimatedTime())
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
// Time range controls
RowLayout {
id: timeControls
x: 10
y: 80
width: parent.width - 20
spacing: 10
Label {
text: "Начало:"
// color: "black"
}
TextField {
id: startTimeField
Layout.preferredHeight: 35
Layout.preferredWidth: 80
text: formatTime(root.visibleStartTime)
inputMask: "99:99:99"
inputMethodHints: Qt.ImhTime
horizontalAlignment: TextInput.AlignHCenter
validator: RegularExpressionValidator {
regularExpression: /^([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/
}
onEditingFinished: {
if (acceptableInput) {
var newStartTime = timeToSeconds(text)
var totalTime = RegimeManager.getTotalEstimatedTime()
// Validate range: start must be >= 0 and < end time
if (newStartTime >= 0 && newStartTime < root.visibleEndTime && newStartTime <= totalTime) {
root.visibleStartTime = newStartTime
updateVisibleRange()
} else {
// Reset to previous valid value
text = formatTime(root.visibleStartTime)
}
} else {
// Reset to previous valid value
text = formatTime(root.visibleStartTime)
}
}
}
Label {
text: "Конец:"
// color: "black"
}
TextField {
id: endTimeField
Layout.preferredHeight: 35
Layout.preferredWidth: 80
text: formatTime(root.visibleEndTime)
inputMask: "99:99:99"
inputMethodHints: Qt.ImhTime
horizontalAlignment: TextInput.AlignHCenter
validator: RegularExpressionValidator {
regularExpression: /^([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/
}
onEditingFinished: {
if (acceptableInput) {
var newEndTime = timeToSeconds(text)
var totalTime = RegimeManager.getTotalEstimatedTime()
// Validate range: end must be > start time and <= total time
if (newEndTime > root.visibleStartTime && newEndTime <= totalTime) {
root.visibleEndTime = newEndTime
updateVisibleRange()
} else {
// Reset to previous valid value
text = formatTime(root.visibleEndTime)
}
} else {
// Reset to previous valid value
text = formatTime(root.visibleEndTime)
}
}
}
// Scale control for timeline zoom
Label {
text: "Масштаб:"
// color: "black"
}
SpinBox {
id: scaleSpinBox
Layout.preferredHeight: 35
Layout.preferredWidth: 80
from: 1
to: 100
value: Math.round(timelineScale)
wheelEnabled: true
onValueModified: {
timelineScale = value
}
up.indicator: ScrollArrow {
arrowColor: "white"
transform: Translate {x: 54 ; y: 2}
}
down.indicator: ScrollArrow {
arrowColor: "white"
rotation: 180
transform: Translate {x: 54; y: 12}
}
}
// Quick action buttons
Button {
text: "Показать все"
onClicked: {
var totalTime = RegimeManager.getTotalEstimatedTime()
if (totalTime > 0) {
root.visibleStartTime = 0
root.visibleEndTime = totalTime
startTimeField.text = formatTime(0)
endTimeField.text = formatTime(totalTime)
updateVisibleRange()
}
}
}
Button {
text: "Reset Scale"
visible: false
onClicked: {
timelineScale = 1.0
scaleSpinBox.value = 1
}
}
}
// Helper function to get state name for tooltip
function getStateName(state) {
switch (state) {
case 0: return "Ожидаение"
case 1: return "Остановлен"
case 2: return "Работает"
case 3: return "Пауза"
case 4: return "Пропущен"
case 5: return "Закончен"
case 6: return "Ошибка"
default: return "Unknown"
}
}
}