sddm-theme/Components/SessionButton.qml

179 lines
6.3 KiB
QML
Raw Permalink Normal View History

2024-06-23 18:47:23 +02:00
// Config created by Keyitdev https://github.com/Keyitdev/sddm-astronaut-theme
// Copyright (C) 2022-2024 Keyitdev
// Based on https://github.com/MarianArlt/sddm-sugar-dark
// Distributed under the GPLv3+ License https://www.gnu.org/licenses/gpl-3.0.html
import QtQuick 2.15
import QtQuick.Controls 2.15
import Qt5Compat.GraphicalEffects
Item {
id: sessionButton
height: root.font.pointSize
width: parent.width / 2
anchors.horizontalCenter: parent.horizontalCenter
property var selectedSession: selectSession.currentIndex
property string textConstantSession
property int loginButtonWidth
property Control exposeSession: selectSession
ComboBox {
id: selectSession
// important
// change also in errorMessage
height: root.font.pointSize * 2
hoverEnabled: true
anchors.left: parent.left
Keys.onPressed: {
if (event.key == Qt.Key_Up && loginButton.state != "enabled" && !popup.opened)
revealSecret.focus = true,
revealSecret.state = "focused",
currentIndex = currentIndex + 1;
if (event.key == Qt.Key_Up && loginButton.state == "enabled" && !popup.opened)
loginButton.focus = true,
loginButton.state = "focused",
currentIndex = currentIndex + 1;
if (event.key == Qt.Key_Down && !popup.opened)
systemButtons.children[0].focus = true,
systemButtons.children[0].state = "focused",
currentIndex = currentIndex - 1;
if ((event.key == Qt.Key_Left || event.key == Qt.Key_Right) && !popup.opened)
popup.open();
}
model: sessionModel
currentIndex: model.lastIndex
textRole: "name"
delegate: ItemDelegate {
width: parent.width
anchors.horizontalCenter: parent.horizontalCenter
contentItem: Text {
text: model.name
font.pointSize: root.font.pointSize * 0.8
font.family: root.font.family
color: selectSession.highlightedIndex === index ? root.palette.highlight.hslLightness >= 0.7 ? "#444444" : "white" : root.palette.window.hslLightness >= 0.8 ? root.palette.highlight.hslLightness >= 0.8 ? "#444444" : root.palette.highlight : "white"
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
}
highlighted: parent.highlightedIndex === index
background: Rectangle {
color: selectSession.highlightedIndex === index ? root.palette.highlight : "transparent"
}
}
indicator {
visible: false
}
contentItem: Text {
id: displayedItem
text: selectSession.currentText
color: root.palette.text
verticalAlignment: Text.AlignVCenter
anchors.left: parent.left
anchors.leftMargin: 3
font.pointSize: root.font.pointSize * 0.8
font.family: root.font.family
Keys.onReleased: parent.popup.open()
}
background: Rectangle {
color: "transparent"
border.width: parent.visualFocus ? 1 : 0
border.color: "transparent"
height: parent.visualFocus ? 2 : 0
width: displayedItem.implicitWidth
anchors.top: parent.bottom
anchors.left: parent.left
anchors.leftMargin: 3
}
popup: Popup {
id: popupHandler
y: parent.height - 1
x: config.ForceRightToLeft == "true" ? -loginButtonWidth + displayedItem.width : 0
width: sessionButton.width
implicitHeight: contentItem.implicitHeight
padding: 10
contentItem: ListView {
clip: true
implicitHeight: contentHeight + 20
model: selectSession.popup.visible ? selectSession.delegateModel : null
currentIndex: selectSession.highlightedIndex
ScrollIndicator.vertical: ScrollIndicator { }
}
background: Rectangle {
radius: config.RoundCorners / 2
color: config.BackgroundColor
layer.enabled: true
layer.effect: DropShadow {
transparentBorder: true
horizontalOffset: 0
verticalOffset: 0
radius: 20 * config.InterfaceShadowSize
samples: 41 * config.InterfaceShadowSize
cached: true
color: Qt.hsla(0,0,0,config.InterfaceShadowOpacity)
}
}
enter: Transition {
NumberAnimation { property: "opacity"; from: 0; to: 1 }
}
}
states: [
State {
name: "pressed"
when: selectSession.down
PropertyChanges {
target: displayedItem
color: Qt.darker(root.palette.highlight, 1.1)
}
PropertyChanges {
target: selectSession.background
border.color: Qt.darker(root.palette.highlight, 1.1)
}
},
State {
name: "hovered"
when: selectSession.hovered
PropertyChanges {
target: displayedItem
color: Qt.lighter(root.palette.highlight, 1.1)
}
PropertyChanges {
target: selectSession.background
border.color: Qt.lighter(root.palette.highlight, 1.1)
}
},
State {
name: "focused"
when: selectSession.visualFocus
PropertyChanges {
target: displayedItem
color: root.palette.highlight
}
PropertyChanges {
target: selectSession.background
border.color: root.palette.highlight
}
}
]
transitions: [
Transition {
PropertyAnimation {
properties: "color, border.color"
duration: 150
}
}
]
}
}