-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathMain.qml
More file actions
413 lines (372 loc) · 16 KB
/
Copy pathMain.qml
File metadata and controls
413 lines (372 loc) · 16 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
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Dialogs
import QtQuick.Controls.Fusion
// iOS 风格的加载浮层 Demo,与 LoadingIndicatorQuick 布局一致。
ApplicationWindow {
id: mainWindow
width: 380
height: 500
visible: true
title: qsTr("Loading Overlay Quick Example")
// === 状态 ===
property string statusText: qsTr("Ready")
property string currentColorTarget: "" // "animation" | "card" | "text" | "dim"
// === 颜色对话框 ===
ColorDialog {
id: colorDialog
title: qsTr("Choose color")
onAccepted: {
if (!selectedColor)
return;
switch (mainWindow.currentColorTarget) {
case "animation":
loadingOverlay.animationColor = selectedColor;
animColorButton.palette.buttonText = getContrastTextColor(selectedColor);
break;
case "card":
loadingOverlay.cardBackgroundColor = selectedColor;
cardColorButton.palette.buttonText = getContrastTextColor(selectedColor);
break;
case "text":
loadingOverlay.textColor = selectedColor;
textColorButton.palette.buttonText = getContrastTextColor(selectedColor);
break;
case "dim":
loadingOverlay.dimColor = selectedColor;
dimColorButton.palette.buttonText = getContrastTextColor(selectedColor);
break;
}
mainWindow.currentColorTarget = "";
statusLabel.text = qsTr("Color changed");
}
}
// === 自动隐藏定时器 ===
Timer {
id: autoHideTimer
interval: 5000
repeat: false
onTriggered: {
loadingOverlay.hide();
statusLabel.text = qsTr("Loading overlay auto hidden");
statusLabel.color = "lightyellow";
}
}
// === 主布局 (与 LoadingIndicatorQuick 一致) ===
ColumnLayout {
anchors.fill: parent
anchors.margins: 10
spacing: 10
RowLayout {
Layout.fillWidth: true
Layout.fillHeight: true
ColumnLayout {
Layout.fillHeight: true
Layout.preferredWidth: 300
Layout.maximumWidth: 360
spacing: 10
// 动画设置组
GroupBox {
title: qsTr("Animation Settings")
Layout.fillWidth: true
ColumnLayout {
anchors.fill: parent
spacing: 6
Label {
id: speedValueLabel
text: qsTr("Animation speed: 100 ms")
}
Slider {
id: speedSlider
Layout.fillWidth: true
from: 50
to: 500
value: 100
onValueChanged: {
speedValueLabel.text = qsTr("Animation speed: %1 ms").arg(Math.round(value));
loadingOverlay.animationSpeed = Math.round(value);
}
}
}
}
// 文本设置组
GroupBox {
title: qsTr("Text Settings")
Layout.fillWidth: true
ColumnLayout {
anchors.fill: parent
spacing: 6
RowLayout {
Layout.fillWidth: true
CheckBox {
id: showTextCheckbox
text: qsTr("Show Text")
checked: true
onToggled: {
loadingOverlay.text = (checked && textEdit.text !== "") ? textEdit.text : "";
}
}
TextField {
id: textEdit
Layout.fillWidth: true
placeholderText: qsTr("Enter loading text")
text: qsTr("Loading...")
onTextChanged: {
if (showTextCheckbox.checked) {
loadingOverlay.text = text;
}
}
}
}
RowLayout {
Layout.fillWidth: true
CheckBox {
id: autoHideCheckbox
text: qsTr("Auto Hide After:")
checked: true
}
SpinBox {
id: durationSpinBox
from: 1
to: 60
value: 5
textFromValue: function (value, locale) {
return qsTr("%1 seconds").arg(value);
}
}
Item {
Layout.fillWidth: true
}
}
}
}
// 颜色设置组
GroupBox {
title: qsTr("Color settings")
Layout.fillWidth: true
GridLayout {
anchors.fill: parent
columns: 2
rowSpacing: 6
columnSpacing: 10
Label {
text: qsTr("Animation:")
}
Button {
id: animColorButton
Layout.fillWidth: true
text: loadingOverlay.animationColor.toString().toUpperCase()
onClicked: {
mainWindow.currentColorTarget = "animation";
colorDialog.selectedColor = loadingOverlay.animationColor;
colorDialog.open();
}
background: Rectangle {
color: loadingOverlay.animationColor
border.color: "gray"
border.width: 1
}
}
Label {
text: qsTr("Card:")
}
Button {
id: cardColorButton
Layout.fillWidth: true
text: loadingOverlay.cardBackgroundColor.toString().toUpperCase()
onClicked: {
mainWindow.currentColorTarget = "card";
colorDialog.selectedColor = loadingOverlay.cardBackgroundColor;
colorDialog.open();
}
background: Rectangle {
color: loadingOverlay.cardBackgroundColor
border.color: "gray"
border.width: 1
}
}
Label {
text: qsTr("Text:")
}
Button {
id: textColorButton
Layout.fillWidth: true
text: loadingOverlay.textColor.toString().toUpperCase()
onClicked: {
mainWindow.currentColorTarget = "text";
colorDialog.selectedColor = loadingOverlay.textColor;
colorDialog.open();
}
background: Rectangle {
color: loadingOverlay.textColor
border.color: "gray"
border.width: 1
}
}
Label {
text: qsTr("Dim:")
}
Button {
id: dimColorButton
Layout.fillWidth: true
text: loadingOverlay.dimColor.toString().toUpperCase()
onClicked: {
mainWindow.currentColorTarget = "dim";
colorDialog.selectedColor = loadingOverlay.dimColor;
colorDialog.open();
}
background: Rectangle {
color: loadingOverlay.dimColor
border.color: "gray"
border.width: 1
}
}
}
}
// 操作组
GroupBox {
title: qsTr("Actions")
Layout.fillWidth: true
GridLayout {
anchors.fill: parent
columns: 2
Button {
text: qsTr("Show")
Layout.fillWidth: true
onClicked: {
if (showTextCheckbox.checked && textEdit.text !== "") {
loadingOverlay.text = textEdit.text;
} else {
loadingOverlay.text = "";
}
loadingOverlay.show(loadingOverlay.text);
statusLabel.text = qsTr("Loading overlay shown");
statusLabel.color = "lightgreen";
if (autoHideCheckbox.checked) {
autoHideTimer.stop();
autoHideTimer.interval = durationSpinBox.value * 1000;
autoHideTimer.start();
}
}
}
Button {
text: qsTr("Hide")
Layout.fillWidth: true
onClicked: {
loadingOverlay.hide();
autoHideTimer.stop();
statusLabel.text = qsTr("Loading overlay hidden");
statusLabel.color = "lightcoral";
}
}
}
}
// 快速主题组
GroupBox {
title: qsTr("Quick Themes")
Layout.fillWidth: true
GridLayout {
anchors.fill: parent
columns: 3
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()
}
}
}
}
}
// === 底部状态栏 (与 CircularProgressQuick 一致) ===
Label {
id: statusLabel
Layout.fillWidth: true
text: qsTr("Status: Ready")
horizontalAlignment: Text.AlignHCenter
padding: 10
}
}
// 加载浮层
LoadingOverlay {
id: loadingOverlay
onTextChanged: {
statusLabel.text = qsTr("Text changed to: ") + loadingOverlay.text;
}
onTextColorChanged: {
statusLabel.text = qsTr("Text color changed");
}
onAnimationColorChanged: {
statusLabel.text = qsTr("Animation color changed");
statusLabel.color = "lightblue";
}
onCardBackgroundColorChanged: {
statusLabel.text = qsTr("Card color changed");
}
onDimColorChanged: {
statusLabel.text = qsTr("Dim color changed");
}
onAnimationSpeedChanged: {
statusLabel.text = qsTr("Animation speed changed to %1 ms").arg(animationSpeed);
}
}
// === 初始化 ===
Component.onCompleted: {
animColorButton.palette.buttonText = getContrastTextColor(loadingOverlay.animationColor);
cardColorButton.palette.buttonText = getContrastTextColor(loadingOverlay.cardBackgroundColor);
textColorButton.palette.buttonText = getContrastTextColor(loadingOverlay.textColor);
dimColorButton.palette.buttonText = getContrastTextColor(loadingOverlay.dimColor);
}
// === 主题函数 (与 CircularProgressQuick 一致: 命名函数 + 内联颜色) ===
function applyClassicTheme() {
loadingOverlay.animationColor = "#007aff"; // #007aff systemBlue
loadingOverlay.textColor = "#1c1c1e"; // #1c1c1e label
loadingOverlay.cardBackgroundColor = "#F2F2F7F2"; // #F2F2F7F2
loadingOverlay.dimColor = "#00000066"; // 40% black
updateColorButtons();
statusLabel.text = qsTr("Classic theme applied");
statusLabel.color = "lightblue";
}
function applyDarkTheme() {
loadingOverlay.animationColor = "#0a84ff"; // #0a84ff systemBlue dark
loadingOverlay.textColor = "#ffffff"; // white
loadingOverlay.cardBackgroundColor = "#1c1c1ef2"; // #1c1c1ef2
loadingOverlay.dimColor = "#00000099"; // 60% black
updateColorButtons();
statusLabel.text = qsTr("Dark theme applied");
statusLabel.color = "darkgray";
}
function applyModernTheme() {
loadingOverlay.animationColor = "#ff9500"; // #ff9500 systemOrange
loadingOverlay.textColor = "#1c1c1e"; // #1c1c1e
loadingOverlay.cardBackgroundColor = "#fffffff2"; // #fffffff2
loadingOverlay.dimColor = "#00000033"; // 20% black
updateColorButtons();
statusLabel.text = qsTr("Modern theme applied");
statusLabel.color = "lightpink";
}
function updateColorButtons() {
animColorButton.palette.buttonText = getContrastTextColor(loadingOverlay.animationColor);
cardColorButton.palette.buttonText = getContrastTextColor(loadingOverlay.cardBackgroundColor);
textColorButton.palette.buttonText = getContrastTextColor(loadingOverlay.textColor);
dimColorButton.palette.buttonText = getContrastTextColor(loadingOverlay.dimColor);
}
// 根据 WCAG 标准计算对比文字色 (黑或白)
function getContrastTextColor(bgColor) {
function normalize(x) {
return x <= 0.03928 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
}
const luminance = 0.2126 * normalize(bgColor.r) + 0.7152 * normalize(bgColor.g) + 0.0722 * normalize(bgColor.b);
return luminance > 0.179 ? "black" : "white";
}
}