mirror of
https://github.com/Snigdha-OS/snigdhaos-sddm-config.git
synced 2025-12-06 10:03:51 +01:00
🚀 feat: add login initialization
This commit is contained in:
154
Login.qml
Normal file
154
Login.qml
Normal file
@@ -0,0 +1,154 @@
|
||||
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 = ""
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Login has been requested with the following username and password
|
||||
* If username field is visible, it will be taken from that, otherwise from the "name" property of the currentIndex
|
||||
*/
|
||||
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: 32
|
||||
implicitHeight: usernameFontSize * 2.85
|
||||
font.pointSize: usernameFontSize * 0.8
|
||||
font.family: config.Font || "Noto Sans"
|
||||
opacity: 1.0
|
||||
text: lastUserName
|
||||
visible: showUsernamePrompt
|
||||
focus: showUsernamePrompt && !lastUserName //if there's a username prompt it gets focus first, otherwise password does
|
||||
placeholderText: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Username")
|
||||
|
||||
style: TextFieldStyle {
|
||||
textColor: "white"
|
||||
placeholderTextColor: "white"
|
||||
background: Rectangle {
|
||||
radius: 0
|
||||
color: "#28282b"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PlasmaComponents.TextField {
|
||||
id: passwordBox
|
||||
Layout.fillWidth: true
|
||||
Layout.minimumHeight: 32
|
||||
implicitHeight: usernameFontSize * 2.85
|
||||
font.pointSize: usernameFontSize * 0.8
|
||||
opacity: passwordFieldOutlined ? 1.0 : 1.0
|
||||
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" : "white"
|
||||
placeholderTextColor: passwordFieldOutlined ? "white" : "white"
|
||||
passwordCharacter: config.PasswordFieldCharacter == "" ? "●" : config.PasswordFieldCharacter
|
||||
background: Rectangle {
|
||||
radius: 0
|
||||
border.color: "#6495ed"
|
||||
border.width: 1
|
||||
color: "#6495ed"
|
||||
}
|
||||
}
|
||||
|
||||
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: "assets/snigdhaos-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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user