-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathMain.qml
More file actions
295 lines (257 loc) · 10.5 KB
/
Main.qml
File metadata and controls
295 lines (257 loc) · 10.5 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
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Dialogs
import QtQuick.Controls.Fusion
ApplicationWindow {
id: mainWindow
width: 800
height: 380
visible: true
title: qsTr("Navigation Progress Bar Example")
// 颜色对话框
ColorDialog {
id: colorDialog
title: qsTr("Choose color")
}
ColumnLayout {
anchors.fill: parent
anchors.margins: 10
// 进度条和步骤控制布局
RowLayout {
Layout.fillWidth: true
Layout.fillHeight: true
NavigationProgressBar {
id: progressBar
Layout.fillWidth: true
Layout.fillHeight: true
messageList: ["Order Placed", "Payment Confirmed", "Processing", "Shipping", "Delivered"]
step: 2
spacing: 10
onStepChanged: {
stepSlider.value = step;
stepLabel.text = qsTr("Current Step: %1").arg(step);
statusLabel.text = qsTr("Step changed to: %1").arg(step);
}
onProgressCompleted: {
statusLabel.text = qsTr("All steps completed!");
}
}
Slider {
id: stepSlider
Layout.fillHeight: true
orientation: Qt.Vertical
from: 0
to: progressBar.maxStep
value: progressBar.step
stepSize: 1
onValueChanged: {
if (pressed && Math.abs(value - progressBar.step) > 0.1) {
progressBar.setStep(Math.round(value));
}
}
}
// 步骤控制面板
ColumnLayout {
spacing: 5
Label {
id: stepLabel
text: qsTr("Current Step: %1").arg(progressBar.step)
font.bold: true
}
Button {
text: qsTr("Previous Step")
onClicked: progressBar.previous()
enabled: progressBar.step > 0
}
Button {
text: qsTr("Next Step")
onClicked: progressBar.next()
enabled: progressBar.step < progressBar.maxStep
}
Button {
text: qsTr("Reset")
onClicked: progressBar.reset()
}
}
}
// 外观控制区域
GroupBox {
title: qsTr("Appearance Controls")
Layout.fillWidth: true
GridLayout {
columns: 2
width: parent.width
// 背景颜色选择
Label {
text: qsTr("Background Color:")
Layout.alignment: Qt.AlignRight
}
Button {
id: backgroundColorButton
Layout.fillWidth: true
text: progressBar.backgroundColor.toString().toUpperCase()
onClicked: {
colorDialog.selectedColor = progressBar.backgroundColor;
colorDialog.accepted.connect(function () {
if (colorDialog.selectedColor) {
progressBar.backgroundColor = colorDialog.selectedColor;
backgroundColorButton.text = progressBar.backgroundColor.toString().toUpperCase();
backgroundColorButton.palette.buttonText = getContrastTextColor(progressBar.backgroundColor);
}
colorDialog.accepted.disconnect(arguments.callee);
});
colorDialog.open();
}
background: Rectangle {
color: progressBar.backgroundColor
border.color: "gray"
border.width: 1
}
}
// 当前步骤颜色选择
Label {
text: qsTr("Current Step Color:")
Layout.alignment: Qt.AlignRight
}
Button {
id: currentColorButton
Layout.fillWidth: true
text: progressBar.currentBackgroundColor.toString().toUpperCase()
onClicked: {
colorDialog.selectedColor = progressBar.currentBackgroundColor;
colorDialog.accepted.connect(function () {
if (colorDialog.selectedColor) {
progressBar.currentBackgroundColor = colorDialog.selectedColor;
currentColorButton.text = progressBar.currentBackgroundColor.toString().toUpperCase();
currentColorButton.palette.buttonText = getContrastTextColor(progressBar.currentBackgroundColor);
}
colorDialog.accepted.disconnect(arguments.callee);
});
colorDialog.open();
}
background: Rectangle {
color: progressBar.currentBackgroundColor
border.color: "gray"
border.width: 1
}
}
// 文字颜色选择
Label {
text: qsTr("Text Color:")
Layout.alignment: Qt.AlignRight
}
Button {
id: foregroundColorButton
Layout.fillWidth: true
text: progressBar.foregroundColor.toString().toUpperCase()
onClicked: {
colorDialog.selectedColor = progressBar.foregroundColor;
colorDialog.accepted.connect(function () {
if (colorDialog.selectedColor) {
progressBar.foregroundColor = colorDialog.selectedColor;
foregroundColorButton.text = progressBar.foregroundColor.toString().toUpperCase();
foregroundColorButton.palette.buttonText = getContrastTextColor(progressBar.foregroundColor);
}
colorDialog.accepted.disconnect(arguments.callee);
});
colorDialog.open();
}
background: Rectangle {
color: progressBar.foregroundColor
border.color: "gray"
border.width: 1
}
}
// 间距控制
Label {
id: spacingLabel
text: qsTr("Spacing: %1").arg(progressBar.spacing)
Layout.alignment: Qt.AlignRight
}
Slider {
id: spacingSlider
Layout.fillWidth: true
from: 0
to: 50
value: progressBar.spacing
onValueChanged: {
progressBar.spacing = Math.round(value);
spacingLabel.text = qsTr("Spacing: %1").arg(Math.round(value));
}
}
}
}
// 步骤信息编辑区域
GroupBox {
title: qsTr("Step Management")
Layout.fillWidth: true
RowLayout {
width: parent.width
TextField {
id: messageEdit
Layout.fillWidth: true
placeholderText: qsTr("Enter step description...")
onAccepted: {
var text = messageEdit.text.trim();
if (text !== "") {
var messages = progressBar.messageList.concat([text]);
progressBar.messageList = messages;
messageEdit.text = "";
stepSlider.to = progressBar.maxStep;
}
}
}
Button {
text: qsTr("Add Step")
onClicked: {
var text = messageEdit.text.trim();
if (text !== "") {
var messages = progressBar.messageList.concat([text]);
progressBar.messageList = messages;
messageEdit.text = "";
stepSlider.to = progressBar.maxStep;
}
}
}
Button {
text: qsTr("Clear All")
onClicked: {
progressBar.messageList = [];
stepSlider.to = progressBar.maxStep;
}
}
}
}
// 状态显示
Label {
id: statusLabel
Layout.fillWidth: true
text: qsTr("Status: Ready")
horizontalAlignment: Text.AlignHCenter
padding: 10
background: Rectangle {
border.color: "gray"
border.width: 1
color: "transparent"
}
}
}
// 初始化颜色按钮的文本颜色
Component.onCompleted: {
backgroundColorButton.palette.buttonText = getContrastTextColor(progressBar.backgroundColor);
currentColorButton.palette.buttonText = getContrastTextColor(progressBar.currentBackgroundColor);
foregroundColorButton.palette.buttonText = getContrastTextColor(progressBar.foregroundColor);
}
// 计算字体颜色的函数(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";
}
}