-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathMain.qml
More file actions
647 lines (559 loc) · 24.9 KB
/
Main.qml
File metadata and controls
647 lines (559 loc) · 24.9 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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Dialogs
import QtQuick.Controls.Fusion
ApplicationWindow {
id: mainWindow
width: 800
height: 620
visible: true
title: qsTr("DashBoard Quick Example")
// 颜色对话框
ColorDialog {
id: colorDialog
title: qsTr("Choose color")
}
// 计算对比度足够的文本颜色(WCAG标准)
function getContrastTextColor(bgColor) {
function normalize(x) {
return x <= 0.03928 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
}
function getRelativeLuminance(r, g, b) {
return 0.2126 * normalize(r / 255.0) + 0.7152 * normalize(g / 255.0) + 0.0722 * normalize(b / 255.0);
}
var luminance = getRelativeLuminance(bgColor.r * 255, bgColor.g * 255, bgColor.b * 255);
return luminance > 0.179 ? "black" : "white";
}
// 初始化颜色按钮
function initializeColorButtons() {
arcColorButton.palette.buttonText = getContrastTextColor(dashboard.arcColor);
scaleColorButton.palette.buttonText = getContrastTextColor(dashboard.scaleColor);
pointerColorButton.palette.buttonText = getContrastTextColor(dashboard.pointerColor);
scaleColorButton.palette.buttonText = getContrastTextColor(dashboard.scaleTextColor);
backgroundColorButton.palette.buttonText = getContrastTextColor(dashboard.backgroundColor);
valueColorButton.palette.buttonText = getContrastTextColor(dashboard.valueColor);
titleColorButton.palette.buttonText = getContrastTextColor(dashboard.titleColor);
}
// 快速主题函数
function applyClassicTheme() {
dashboard.arcColor = "#383d4a";
dashboard.scaleColor = "#04a8ad";
dashboard.pointerColor = "#04b5c8";
dashboard.scaleTextColor = "#908574";
dashboard.backgroundColor = "transparent";
dashboard.valueColor = "#908574";
dashboard.titleColor = "#908574";
initializeColorButtons();
}
function applyDarkTheme() {
dashboard.arcColor = "#282c34";
dashboard.scaleColor = "#61afef";
dashboard.pointerColor = "#c678dd";
dashboard.scaleTextColor = "#abb2bf";
dashboard.backgroundColor = "#1e2127";
dashboard.valueColor = "#98c379";
dashboard.titleColor = "#e06c75";
initializeColorButtons();
}
function applyModernTheme() {
dashboard.arcColor = "#4682b4";
dashboard.scaleColor = "#6495ed";
dashboard.pointerColor = "#dc143c";
dashboard.scaleTextColor = "#2f4f4f";
dashboard.backgroundColor = "#f0f8ff";
dashboard.valueColor = "#191970";
dashboard.titleColor = "#4169e1";
initializeColorButtons();
}
ColumnLayout {
anchors.fill: parent
anchors.margins: 10
spacing: 10
RowLayout {
Layout.fillWidth: true
Layout.fillHeight: true
spacing: 15
// === 左侧:仪表盘显示区域 ===
ColumnLayout {
Layout.fillWidth: true
Layout.fillHeight: true
spacing: 10
// 仪表盘显示
DashBoard {
id: dashboard
Layout.fillWidth: true
Layout.fillHeight: true
Layout.margins: 10
value: 25
title: qsTr("Dashboard")
}
// 数值控制组
GroupBox {
title: qsTr("Value Settings")
Layout.fillWidth: true
GridLayout {
columns: 3
anchors.fill: parent
Label {
id: valueLabel
text: qsTr("Current value:")
Layout.alignment: Qt.AlignHCenter
}
Slider {
id: valueSlider
Layout.fillWidth: true
from: dashboard.minValue
to: dashboard.maxValue
value: dashboard.value
onMoved: {
if (pressed) {
dashboard.setValue(value);
}
}
}
SpinBox {
id: valueSpinBox
from: dashboard.minValue
to: dashboard.maxValue
value: dashboard.value
editable: true
onValueModified: dashboard.setValue(value)
}
Label {
text: qsTr("Min value:")
Layout.alignment: Qt.AlignRight
}
SpinBox {
id: minValueSpinBox
from: -1000
to: 1000
value: dashboard.minValue
editable: true
onValueModified: dashboard.minValue = value
Layout.columnSpan: 2
}
Label {
text: qsTr("Max value:")
Layout.alignment: Qt.AlignRight
}
SpinBox {
id: maxValueSpinBox
from: -1000
to: 1000
value: dashboard.maxValue
editable: true
onValueModified: dashboard.maxValue = value
Layout.columnSpan: 2
}
}
}
// 文本设置组
GroupBox {
title: qsTr("Text Settings")
Layout.fillWidth: true
GridLayout {
columns: 2
anchors.fill: parent
Label {
text: qsTr("Title:")
Layout.alignment: Qt.AlignRight
}
TextField {
id: titleTextField
Layout.fillWidth: true
text: dashboard.title
onTextChanged: dashboard.title = text
placeholderText: qsTr("Enter dashboard title")
}
Label {
text: qsTr("Unit:")
Layout.alignment: Qt.AlignRight
}
TextField {
id: unitTextField
Layout.fillWidth: true
text: dashboard.unit
onTextChanged: dashboard.unit = text
placeholderText: qsTr("Enter value unit")
}
}
}
}
// === 右侧:控制面板 ===
ColumnLayout {
Layout.fillHeight: true
Layout.fillWidth: true
spacing: 10
// 几何设置组
GroupBox {
title: qsTr("Geometry Settings")
Layout.fillWidth: true
GridLayout {
columns: 2
anchors.fill: parent
Label {
text: qsTr("Start angle:")
Layout.alignment: Qt.AlignRight
}
SpinBox {
id: startAngleSpinBox
from: 0
to: 360
value: dashboard.startAngle
editable: true
onValueModified: dashboard.startAngle = value
}
Label {
text: qsTr("End angle:")
Layout.alignment: Qt.AlignRight
}
SpinBox {
id: endAngleSpinBox
from: startAngleSpinBox.value
to: 720
value: dashboard.endAngle
editable: true
onValueModified: dashboard.endAngle = value
}
Label {
text: qsTr("Major scales:")
Layout.alignment: Qt.AlignRight
}
SpinBox {
id: scaleMajorSpinBox
from: 1
to: 100
value: dashboard.scaleMajor
editable: true
onValueModified: dashboard.scaleMajor = value
}
Label {
text: qsTr("Minor scales:")
Layout.alignment: Qt.AlignRight
}
SpinBox {
id: scaleMinorSpinBox
from: 1
to: 100
value: dashboard.scaleMinor
editable: true
onValueModified: dashboard.scaleMinor = value
}
}
}
// 颜色设置组
GroupBox {
title: qsTr("Color Settings")
Layout.fillWidth: true
GridLayout {
columns: 4
anchors.fill: parent
// 第一列
Label {
text: qsTr("Arc color:")
Layout.alignment: Qt.AlignRight
}
Button {
id: arcColorButton
Layout.fillWidth: true
text: dashboard.arcColor.toString().toUpperCase()
onClicked: {
colorDialog.selectedColor = dashboard.arcColor;
colorDialog.accepted.connect(function () {
if (colorDialog.selectedColor) {
dashboard.arcColor = colorDialog.selectedColor;
arcColorButton.palette.buttonText = getContrastTextColor(dashboard.arcColor);
}
colorDialog.accepted.disconnect(arguments.callee);
});
colorDialog.open();
}
background: Rectangle {
color: dashboard.arcColor
border.color: "gray"
border.width: 1
}
}
Label {
text: qsTr("Scale color:")
Layout.alignment: Qt.AlignRight
}
Button {
id: scaleColorButton
Layout.fillWidth: true
text: dashboard.scaleColor.toString().toUpperCase()
onClicked: {
colorDialog.selectedColor = dashboard.scaleColor;
colorDialog.accepted.connect(function () {
if (colorDialog.selectedColor) {
dashboard.scaleColor = colorDialog.selectedColor;
scaleColorButton.palette.buttonText = getContrastTextColor(dashboard.scaleColor);
}
colorDialog.accepted.disconnect(arguments.callee);
});
colorDialog.open();
}
background: Rectangle {
color: dashboard.scaleColor
border.color: "gray"
border.width: 1
}
}
Label {
text: qsTr("Pointer color:")
Layout.alignment: Qt.AlignRight
}
Button {
id: pointerColorButton
Layout.fillWidth: true
text: dashboard.pointerColor.toString().toUpperCase()
onClicked: {
colorDialog.selectedColor = dashboard.pointerColor;
colorDialog.accepted.connect(function () {
if (colorDialog.selectedColor) {
dashboard.pointerColor = colorDialog.selectedColor;
pointerColorButton.palette.buttonText = getContrastTextColor(dashboard.pointerColor);
}
colorDialog.accepted.disconnect(arguments.callee);
});
colorDialog.open();
}
background: Rectangle {
color: dashboard.pointerColor
border.color: "gray"
border.width: 1
}
}
// 第二列
Label {
text: qsTr("Text color:")
Layout.alignment: Qt.AlignRight
}
Button {
id: scaleTextColorButton
Layout.fillWidth: true
text: dashboard.scaleTextColor.toString().toUpperCase()
onClicked: {
colorDialog.selectedColor = dashboard.scaleTextColor;
colorDialog.accepted.connect(function () {
if (colorDialog.selectedColor) {
dashboard.scaleTextColor = colorDialog.selectedColor;
scaleTextColorButton.palette.buttonText = getContrastTextColor(dashboard.scaleTextColor);
}
colorDialog.accepted.disconnect(arguments.callee);
});
colorDialog.open();
}
background: Rectangle {
color: dashboard.scaleTextColor
border.color: "gray"
border.width: 1
}
}
Label {
text: qsTr("Background color:")
Layout.alignment: Qt.AlignRight
}
Button {
id: backgroundColorButton
Layout.fillWidth: true
text: dashboard.backgroundColor.toString().toUpperCase()
onClicked: {
colorDialog.selectedColor = dashboard.backgroundColor;
colorDialog.accepted.connect(function () {
if (colorDialog.selectedColor) {
dashboard.backgroundColor = colorDialog.selectedColor;
backgroundColorButton.palette.buttonText = getContrastTextColor(dashboard.backgroundColor);
}
colorDialog.accepted.disconnect(arguments.callee);
});
colorDialog.open();
}
background: Rectangle {
color: dashboard.backgroundColor
border.color: "gray"
border.width: 1
}
}
Label {
text: qsTr("Value color:")
Layout.alignment: Qt.AlignRight
}
Button {
id: valueColorButton
Layout.fillWidth: true
text: dashboard.valueColor.toString().toUpperCase()
onClicked: {
colorDialog.selectedColor = dashboard.valueColor;
colorDialog.accepted.connect(function () {
if (colorDialog.selectedColor) {
dashboard.valueColor = colorDialog.selectedColor;
valueColorButton.palette.buttonText = getContrastTextColor(dashboard.valueColor);
}
colorDialog.accepted.disconnect(arguments.callee);
});
colorDialog.open();
}
background: Rectangle {
color: dashboard.valueColor
border.color: "gray"
border.width: 1
}
}
Label {
text: qsTr("Title color:")
Layout.alignment: Qt.AlignRight
}
Button {
id: titleColorButton
Layout.fillWidth: true
text: dashboard.titleColor.toString().toUpperCase()
onClicked: {
colorDialog.selectedColor = dashboard.titleColor;
colorDialog.accepted.connect(function () {
if (colorDialog.selectedColor) {
dashboard.titleColor = colorDialog.selectedColor;
titleColorButton.palette.buttonText = getContrastTextColor(dashboard.titleColor);
}
colorDialog.accepted.disconnect(arguments.callee);
});
colorDialog.open();
}
background: Rectangle {
color: dashboard.titleColor
border.color: "gray"
border.width: 1
}
}
}
}
// 动画设置组
GroupBox {
title: qsTr("Animation Settings")
Layout.fillWidth: true
ColumnLayout {
anchors.fill: parent
Label {
id: durationLabel
text: qsTr("Animation duration: %1ms").arg(dashboard.animationDuration)
Layout.fillWidth: true
}
Slider {
id: animationDurationSlider
Layout.fillWidth: true
from: 0
to: 2000
value: dashboard.animationDuration
onValueChanged: {
dashboard.animationDuration = value;
durationLabel.text = qsTr("Animation duration: %1ms").arg(value);
}
}
}
}
// 操作按钮组
GroupBox {
title: qsTr("Actions")
Layout.fillWidth: true
GridLayout {
columns: 2
anchors.fill: parent
Button {
text: qsTr("Increase +1")
Layout.fillWidth: true
onClicked: dashboard.increaseValue(1.0)
}
Button {
text: qsTr("Decrease -1")
Layout.fillWidth: true
onClicked: dashboard.decreaseValue(1.0)
}
Button {
text: qsTr("Reset")
Layout.fillWidth: true
onClicked: dashboard.reset()
}
Button {
text: qsTr("Animate to 75")
Layout.fillWidth: true
onClicked: dashboard.setValueAnimated(75.0)
}
}
}
// 快速主题组
GroupBox {
title: qsTr("Quick Themes")
Layout.fillWidth: true
GridLayout {
columns: 3
anchors.fill: parent
Button {
text: qsTr("Classic")
Layout.fillWidth: true
onClicked: mainWindow.applyClassicTheme()
}
Button {
text: qsTr("Dark")
Layout.fillWidth: true
onClicked: mainWindow.applyDarkTheme()
}
Button {
text: qsTr("Modern")
Layout.fillWidth: true
onClicked: mainWindow.applyModernTheme()
}
}
}
}
}
Label {
id: statusLabel
Layout.fillWidth: true
text: qsTr("Status: Ready")
horizontalAlignment: Text.AlignHCenter
padding: 10
}
}
// === 信号连接 ===
Connections {
target: dashboard
function onValueChanged(value) {
console.log("Value changed to:", dashboard.value);
statusLabel.text = qsTr("Current value: %1").arg(dashboard.value);
}
function onValueIncreased(newValue) {
console.log("Value increased to:", newValue);
statusLabel.text = qsTr("Value increased to: %1").arg(newValue);
statusLabel.background.color = "lightgreen";
}
function onValueDecreased(newValue) {
console.log("Value decreased to:", newValue);
statusLabel.text = qsTr("Value decreased to: %1").arg(newValue);
statusLabel.background.color = "lightcoral";
}
function onValueReset() {
console.log("Value reset");
statusLabel.text = qsTr("Value reset to minimum");
statusLabel.background.color = "lightyellow";
}
function onAnimationStarted(oldValue, newValue) {
console.log("Animation started from", oldValue, "to", newValue);
statusLabel.text = qsTr("Animating: %1 → %2").arg(oldValue).arg(newValue);
statusLabel.background.color = "lightblue";
}
function onAnimationFinished(value) {
console.log("Animation finished at:", value);
statusLabel.text = qsTr("Animation finished: %1").arg(value);
statusLabel.background.color = "lightgreen";
}
}
// === 初始化 ===
Component.onCompleted: {
initializeColorButtons();
// 设置初始值
dashboard.setValueAnimated(25);
// 更新状态
statusLabel.text = qsTr("Dashboard initialized");
}
}