-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.qml
349 lines (319 loc) · 11 KB
/
Main.qml
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
import QtQuick 2.15
import QtQuick.Controls 2.0
import SddmComponents 2.0
import Qt5Compat.GraphicalEffects
Rectangle {
id: root
width: 640
height: 480
readonly property color textColor: config.stringValue("basicTextColor")
property int currentUsersIndex: userModel.lastIndex
property int currentSessionsIndex: sessionModel.lastIndex
property int usernameRole: Qt.UserRole + 1
property int realNameRole: Qt.UserRole + 2
property int sessionNameRole: Qt.UserRole + 4
property string currentUsername: config.boolValue("showUserRealNameByDefault") ?
userModel.data(userModel.index(currentUsersIndex, 0), realNameRole)
: userModel.data(userModel.index(currentUsersIndex, 0), usernameRole)
property string currentSession: sessionModel.data(sessionModel.index(currentSessionsIndex, 0), sessionNameRole)
property string passwordFontSize: config.intValue("passwordFontSize") || 96
property string usersFontSize: config.intValue("usersFontSize") || 48
property string sessionsFontSize: config.intValue("sessionsFontSize") || 24
function usersCycleSelectPrev() {
if (currentUsersIndex - 1 < 0) {
currentUsersIndex = userModel.count - 1;
} else {
currentUsersIndex--;
}
}
function usersCycleSelectNext() {
if (currentUsersIndex >= userModel.count - 1) {
currentUsersIndex = 0;
} else {
currentUsersIndex++;
}
}
function bgFillMode() {
switch(config.stringValue("backgroundMode"))
{
case "aspect":
return Image.PreserveAspectCrop;
case "fill":
return Image.Stretch;
case "tile":
return Image.Tile;
default:
return Image.Pad;
}
}
function sessionsCycleSelectPrev() {
if (currentSessionsIndex - 1 < 0) {
currentSessionsIndex = sessionModel.rowCount() - 1;
} else {
currentSessionsIndex--;
}
}
function sessionsCycleSelectNext() {
if (currentSessionsIndex >= sessionModel.rowCount() - 1) {
currentSessionsIndex = 0;
} else {
currentSessionsIndex++;
}
}
Connections {
target: sddm
function onLoginFailed() {
backgroundBorder.border.width = 5;
animateBorder.restart();
passwordInput.clear();
}
function onLoginSucceeded() {
backgroundBorder.border.width = 0;
animateBorder.stop();
}
}
Item {
id: mainFrame
property variant geometry: screenModel.geometry(screenModel.primary)
x: geometry.x
y: geometry.y
width: geometry.width
height: geometry.height
Shortcut {
sequences: ["Alt+U", "F2"]
onActivated: {
if (!username.visible) {
username.visible = true;
return;
}
usersCycleSelectNext();
}
}
Shortcut {
sequences: ["Alt+Ctrl+S", "Ctrl+F3"]
onActivated: {
if (!sessionName.visible) {
sessionName.visible = true;
return;
}
sessionsCycleSelectPrev();
}
}
Shortcut {
sequences: ["Alt+S", "F3"]
onActivated: {
if (!sessionName.visible) {
sessionName.visible = true;
return;
}
sessionsCycleSelectNext();
}
}
Shortcut {
sequences: ["Alt+Ctrl+U", "Ctrl+F2"]
onActivated: {
if (!username.visible) {
username.visible = true;
return;
}
usersCycleSelectPrev();
}
}
Shortcut {
sequence: "F10"
onActivated: {
if (sddm.canSuspend) {
sddm.suspend();
}
}
}
Shortcut {
sequence: "F11"
onActivated: {
if (sddm.canPowerOff) {
sddm.powerOff();
}
}
}
Shortcut {
sequence: "F12"
onActivated: {
if (sddm.canReboot) {
sddm.reboot();
}
}
}
Shortcut {
sequence: "F1"
onActivated: {
helpMessage.visible = !helpMessage.visible
}
}
Rectangle {
id: background
visible: true
anchors.fill: parent
color: config.stringValue("backgroundFill") || "transparent"
Image {
id: image
anchors.fill: parent
source: config.stringValue("background")
smooth: true
fillMode: bgFillMode()
z: 2
}
Rectangle {
id: backgroundBorder
anchors.fill: parent
z: 4
border.color: "#ff3117"
border.width: 0
color: "transparent"
Behavior on border.width {
SequentialAnimation {
id: animateBorder
running: false
loops: Animation.Infinite
NumberAnimation { from: 5; to: 10; duration: 700 }
NumberAnimation { from: 10; to: 5; duration: 400 }
}
}
}
FastBlur {
id: fastBlur
z: 3
anchors.fill: image
source: image
radius: config.intValue("blurRadius")
}
}
TextInput {
id: passwordInput
width: parent.width*(config.bar_width)
height: 200/120*passwordFontSize
font.family: config.font
font.pointSize: passwordFontSize
font.bold: true
font.letterSpacing: 20/96*passwordFontSize
anchors {
verticalCenter: parent.verticalCenter
horizontalCenter: parent.horizontalCenter
}
echoMode: config.boolValue("passwordMask") ? TextInput.Password : null
color: config.stringValue("passwordTextColor") || textColor
selectionColor: textColor
selectedTextColor: "#000000"
clip: true
horizontalAlignment: TextInput.AlignHCenter
verticalAlignment: TextInput.AlignVCenter
passwordCharacter: config.stringValue("passwordCharacter") || "*"
cursorVisible: config.boolValue("passwordInputCursorVisible")
onAccepted: {
if (text != "") {
sddm.login(userModel.data(userModel.index(currentUsersIndex, 0), usernameRole)
|| "123test", text, currentSessionsIndex);
}
}
Rectangle {
z: -1
anchors.fill: parent
color: config.stringValue("passwordInputBackground") || "transparent"
radius: config.intValue("passwordInputRadius") || 10
}
cursorDelegate: Rectangle {
id: passwordInputCursor
width: 18/96*passwordFontSize
visible: config.boolValue("passwordInputCursorVisible")
onHeightChanged: height = passwordInput.height/2
anchors.verticalCenter: parent.verticalCenter
color: (() => {
if (config.stringValue("passwordCursorColor").length == 7 && config.stringValue("passwordCursorColor")[0] == "#") {
return config.stringValue("passwordCursorColor");
} else if (config.stringValue("passwordCursorColor") == "constantRandom") {
return generateRandomColor();
} else {
return textColor
}
})()
function generateRandomColor() {
var color = "#";
for (var i = 0; i<3; i++) {
var color_number = parseInt(Math.random()*255);
var hex_color = color_number.toString(16);
if (color_number < 16) {
hex_color = "0" + hex_color;
}
color += hex_color;
}
return color;
}
Connections {
target: passwordInput
function onTextEdited() {
if (config.stringValue("passwordCursorColor") == "random") {
passwordInputCursor.color = generateRandomColor();
}
}
}
}
}
UsersChoose {
id: username
text: currentUsername
visible: config.boolValue("showUsersByDefault")
width: mainFrame.width/2.5/48*usersFontSize
anchors {
horizontalCenter: parent.horizontalCenter
bottom: passwordInput.top
bottomMargin: 40
}
onPrevClicked: {
usersCycleSelectPrev();
}
onNextClicked: {
usersCycleSelectNext();
}
}
SessionsChoose {
id: sessionName
text: currentSession
visible: config.boolValue("showSessionsByDefault")
width: mainFrame.width/2.5/24*sessionsFontSize
anchors {
horizontalCenter: parent.horizontalCenter
bottom: parent.bottom
bottomMargin: 30
}
onPrevClicked: {
sessionsCycleSelectPrev();
}
onNextClicked: {
sessionsCycleSelectNext();
}
}
Text {
id: helpMessage
visible: false
text: "Show help - F1\n" +
"Cycle select next user - F2 or Alt+u\n" +
"Cycle select previous user - Ctrl+F2 or Alt+Ctrl+u\n" +
"Cycle select next session - F3 or Alt+s\n" +
"Cycle select previous session - Ctrl+F3 or Alt+Ctrl+s\n" +
"Suspend - F10\n" +
"Poweroff - F11\n" +
"Reboot - F12"
color: textColor
font.family: config.font
font.pointSize: 18
anchors {
top: parent.top
topMargin: 30
left: parent.left
leftMargin: 30
}
}
Component.onCompleted: {
passwordInput.forceActiveFocus();
}
}
}