-
Notifications
You must be signed in to change notification settings - Fork 0
/
Login.qml
150 lines (131 loc) · 4.61 KB
/
Login.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
import "components"
import QtQuick 2.0
import QtQuick.Layouts 1.2
import QtQuick.Controls.Styles 1.4
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
SessionManagementScreen {
property bool showUsernamePrompt: !showUserList
property int usernameFontSize
property string usernameFontColor
property string lastUserName
property bool passwordFieldOutlined: config.PasswordFieldOutlined == "true"
property bool hidePasswordRevealIcon: config.HidePasswordRevealIcon == "false"
property int visibleBoundary: mapFromItem(loginButton, 0, 0).y
onHeightChanged: visibleBoundary = mapFromItem(loginButton, 0, 0).y + loginButton.height + units.smallSpacing
signal loginRequest(string username, string password)
onShowUsernamePromptChanged: {
if (!showUsernamePrompt) {
lastUserName = ""
}
}
function startLogin() {
var username = showUsernamePrompt ? userNameInput.text : userList.selectedUser
var password = passwordBox.text
loginButton.forceActiveFocus();
loginRequest(username, password);
}
PlasmaComponents.TextField {
id: userNameInput
Layout.fillWidth: true
Layout.minimumHeight: 21
implicitHeight: root.height / 28
font.family: config.Font || "Noto Sans"
font.pointSize: usernameFontSize
opacity: 0.5
text: lastUserName
visible: showUsernamePrompt
focus: showUsernamePrompt && !lastUserName
placeholderText: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Username")
style: TextFieldStyle {
textColor: "black"
background: Rectangle {
radius: 3
}
}
}
PlasmaComponents.TextField {
id: passwordBox
Layout.fillWidth: true
Layout.minimumHeight: 21
implicitHeight: usernameFontSize * 2.85
font.pointSize: usernameFontSize * 0.8
opacity: passwordFieldOutlined ? 0.75 : 0.5
font.family: config.Font || "Noto Sans"
placeholderText: config.PasswordFieldPlaceholderText == "Password" ? i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Password") : config.PasswordFieldPlaceholderText
focus: !showUsernamePrompt || lastUserName
echoMode: TextInput.Password
revealPasswordButtonShown: hidePasswordRevealIcon
onAccepted: startLogin()
style: TextFieldStyle {
textColor: passwordFieldOutlined ? "white" : "black"
placeholderTextColor: passwordFieldOutlined ? "white" : "black"
passwordCharacter: config.PasswordFieldCharacter == "" ? "●" : config.PasswordFieldCharacter
background: Rectangle {
radius: 3
border.color: "white"
border.width: 1
color: passwordFieldOutlined ? "transparent" : "white"
}
}
Keys.onEscapePressed: {
mainStack.currentItem.forceActiveFocus();
}
Keys.onPressed: {
if (event.key == Qt.Key_Left && !text) {
userList.decrementCurrentIndex();
event.accepted = true
}
if (event.key == Qt.Key_Right && !text) {
userList.incrementCurrentIndex();
event.accepted = true
}
}
Keys.onReleased: {
if (loginButton.opacity == 0 && length > 0) {
showLoginButton.start()
}
if (loginButton.opacity > 0 && length == 0) {
hideLoginButton.start()
}
}
Connections {
target: sddm
onLoginFailed: {
passwordBox.selectAll()
passwordBox.forceActiveFocus()
}
}
}
Image {
id: loginButton
source: "components/artwork/login.svgz"
smooth: true
sourceSize: Qt.size(passwordBox.height, passwordBox.height)
anchors {
left: passwordBox.right
verticalCenter: passwordBox.verticalCenter
}
anchors.leftMargin: 8
visible: opacity > 0
opacity: 0
MouseArea {
anchors.fill: parent
onClicked: startLogin();
}
PropertyAnimation {
id: showLoginButton
target: loginButton
properties: "opacity"
to: 0.75
duration: 100
}
PropertyAnimation {
id: hideLoginButton
target: loginButton
properties: "opacity"
to: 0
duration: 80
}
}
}