-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathMain.qml
More file actions
264 lines (225 loc) · 7.87 KB
/
Main.qml
File metadata and controls
264 lines (225 loc) · 7.87 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
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Controls.Fusion
ApplicationWindow {
id: mainWindow
width: 600
height: 500
visible: true
title: qsTr("Password Input Quick Example")
ColumnLayout {
anchors.fill: parent
anchors.margins: 10
// 基本密码输入框
GroupBox {
title: qsTr("Basic Password Input")
Layout.fillWidth: true
ColumnLayout {
width: parent.width
PasswordInput {
id: basicPasswordInput
Layout.fillWidth: true
Layout.preferredHeight: 50
placeholderText: qsTr("Enter your password here")
onTextChanged: {
mainWindow.updateStatus(qsTr("Basic password input updated"));
}
}
}
}
// 带自定义提示的密码框
GroupBox {
title: qsTr("Password Input with Custom Placeholder")
Layout.fillWidth: true
ColumnLayout {
width: parent.width
PasswordInput {
id: customPasswordInput
Layout.fillWidth: true
Layout.preferredHeight: 50
placeholderText: qsTr("Minimum 8 characters with special symbols")
onTextChanged: {
mainWindow.updateStatus(qsTr("Custom password input updated"));
}
}
}
}
// 控制面板
GroupBox {
title: qsTr("Controls")
Layout.fillWidth: true
GridLayout {
columns: 3
width: parent.width
// 显示所有密码按钮
Button {
text: qsTr("Show All Passwords")
Layout.fillWidth: true
onClicked: {
mainWindow.showAllPasswords();
mainWindow.updateStatus(qsTr("All passwords are now visible"));
}
}
// 隐藏所有密码按钮
Button {
text: qsTr("Hide All Passwords")
Layout.fillWidth: true
onClicked: {
mainWindow.hideAllPasswords();
mainWindow.updateStatus(qsTr("All passwords are now hidden"));
}
}
// 清除所有密码按钮
Button {
text: qsTr("Clear All Passwords")
Layout.fillWidth: true
onClicked: {
mainWindow.clearAllPasswords();
mainWindow.updateStatus(qsTr("All passwords cleared"));
}
}
// 验证按钮
Button {
text: qsTr("Validate Passwords")
Layout.columnSpan: 3
Layout.fillWidth: true
onClicked: {
mainWindow.validatePasswords();
}
}
}
}
// 自定义图标设置
GroupBox {
title: qsTr("Custom Icon Settings")
Layout.fillWidth: true
RowLayout {
width: parent.width
TextField {
id: visibleIconInput
Layout.fillWidth: true
placeholderText: qsTr("Visible icon (text or emoji)")
text: "👁️"
}
TextField {
id: hiddenIconInput
Layout.fillWidth: true
placeholderText: qsTr("Hidden icon (text or emoji)")
text: "🔒"
}
Button {
text: qsTr("Apply Icons")
onClicked: {
mainWindow.applyCustomIcons();
mainWindow.updateStatus(qsTr("Custom icons applied"));
}
}
}
}
// 状态显示
GroupBox {
title: qsTr("Status")
Layout.fillWidth: true
Rectangle {
width: parent.width
radius: 4
Text {
id: statusLabel
anchors.centerIn: parent
text: qsTr("Ready")
font.pixelSize: 14
horizontalAlignment: Text.AlignHCenter
}
}
}
// 密码信息显示
GroupBox {
title: qsTr("Password Information")
Layout.fillWidth: true
ColumnLayout {
width: parent.width
spacing: 5
Text {
text: qsTr("Basic Input: ") + (basicPasswordInput.passwordVisible ? qsTr("Visible") : qsTr("Hidden")) + " | " + qsTr("Length: ") + basicPasswordInput.text.length
font.pixelSize: 12
}
Text {
text: qsTr("Custom Input: ") + (customPasswordInput.passwordVisible ? qsTr("Visible") : qsTr("Hidden")) + " | " + qsTr("Length: ") + customPasswordInput.text.length
font.pixelSize: 12
}
}
}
}
// 收集所有密码输入框
function getAllPasswordInputs() {
return [basicPasswordInput, customPasswordInput];
}
// 显示所有密码
function showAllPasswords() {
var inputs = getAllPasswordInputs();
for (var i = 0; i < inputs.length; i++) {
if (!inputs[i].passwordVisible) {
inputs[i].togglePasswordVisibility();
}
}
}
// 隐藏所有密码
function hideAllPasswords() {
var inputs = getAllPasswordInputs();
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].passwordVisible) {
inputs[i].togglePasswordVisibility();
}
}
}
// 清除所有密码
function clearAllPasswords() {
var inputs = getAllPasswordInputs();
for (var i = 0; i < inputs.length; i++) {
inputs[i].clear();
}
}
// 验证密码
function validatePasswords() {
var inputs = getAllPasswordInputs();
var allValid = true;
var messages = [];
for (var i = 0; i < inputs.length; i++) {
var input = inputs[i];
if (input.text.length > 0) {
if (input.text.length < 6) {
var inputName = input === basicPasswordInput ? qsTr("Basic input") : qsTr("Custom input");
messages.push(qsTr("%1 is too short (minimum 6 characters)").arg(inputName));
allValid = false;
}
}
}
if (allValid && messages.length === 0) {
updateStatus("✓ " + qsTr("All passwords are valid"));
} else if (messages.length === 0) {
updateStatus("ℹ " + qsTr("No passwords to validate"));
} else {
updateStatus("✗ " + messages.join("; "));
}
}
// 应用自定义图标
function applyCustomIcons() {
var inputs = getAllPasswordInputs();
var visibleIcon = visibleIconInput.text.trim();
var hiddenIcon = hiddenIconInput.text.trim();
if (visibleIcon !== "" && hiddenIcon !== "") {
for (var i = 0; i < inputs.length; i++) {
inputs[i].setToggleIcons(visibleIcon, hiddenIcon);
}
}
}
// 更新状态
function updateStatus(message) {
statusLabel.text = message;
}
// 组件加载完成后的初始化
Component.onCompleted: {
updateStatus(qsTr("Application started successfully"));
}
}