hyprpolkitagent/qml/main.qml

152 lines
3.8 KiB
QML
Raw Normal View History

2024-10-14 18:55:01 +02:00
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
ApplicationWindow {
id: window
2024-10-16 16:53:52 +02:00
property var windowWidth: Math.round(fontMetrics.height * 39.2856)
property var windowHeight: Math.round(fontMetrics.height * 17.1428)
2024-10-14 18:55:01 +02:00
maximumWidth: windowWidth
maximumHeight: windowHeight
minimumWidth: windowWidth
minimumHeight: windowHeight
visible: true
2024-10-16 16:05:32 +02:00
onClosing: {
hpa.setResult("fail");
}
2024-10-14 18:55:01 +02:00
FontMetrics {
id: fontMetrics
}
SystemPalette {
id: system
colorGroup: SystemPalette.Active
}
Item {
anchors.fill: parent
Keys.onEscapePressed: (e) => {
hpa.setResult("fail");
}
Keys.onReturnPressed: (e) => {
hpa.setResult("auth:" + passwordField.text);
}
ColumnLayout {
anchors.fill: parent
anchors.margins: 4
2024-10-16 16:06:12 +02:00
Label {
2024-10-14 18:55:01 +02:00
color: Qt.darker(system.windowText, 0.8)
font.bold: true
font.pointSize: Math.round(fontMetrics.height * 1.05)
text: "Authenticating for " + hpa.getUser()
Layout.alignment: Qt.AlignHCenter
}
HSeparator {
Layout.topMargin: fontMetrics.height / 2
Layout.bottomMargin: fontMetrics.height / 2
}
2024-10-16 16:06:12 +02:00
Label {
2024-10-16 16:54:31 +02:00
color: system.windowText
2024-10-14 18:55:01 +02:00
text: hpa.getMessage()
}
TextField {
id: passwordField
Layout.topMargin: fontMetrics.height / 2
placeholderText: "Password"
Layout.alignment: Qt.AlignHCenter
hoverEnabled: true
persistentSelection: true
echoMode: TextInput.Password
focus: true
Connections {
target: hpa
onFocusField: () => {
passwordField.focus = true;
}
2024-10-16 16:05:32 +02:00
onBlockInput: (block) => {
passwordField.readOnly = block;
if (!block) {
passwordField.focus = true;
passwordField.selectAll();
}
}
2024-10-14 18:55:01 +02:00
}
}
2024-10-16 16:06:12 +02:00
Label {
2024-10-14 18:55:01 +02:00
id: errorLabel
color: "red"
font.italic: true
Layout.topMargin: fontMetrics.height
text: ""
Layout.alignment: Qt.AlignHCenter
Connections {
target: hpa
onSetErrorString: (e) => {
errorLabel.text = e;
}
}
}
Rectangle {
color: "transparent"
Layout.fillHeight: true
}
HSeparator {
Layout.topMargin: fontMetrics.height / 2
Layout.bottomMargin: fontMetrics.height / 2
}
RowLayout {
Layout.alignment: Qt.AlignRight
Layout.rightMargin: fontMetrics.height / 2
Button {
text: "Cancel"
onClicked: (e) => {
hpa.setResult("fail");
}
}
Button {
text: "Authenticate"
onClicked: (e) => {
hpa.setResult("auth:" + passwordField.text);
}
}
}
}
}
component Separator: Rectangle {
color: Qt.darker(window.palette.text, 1.5)
}
component HSeparator: Separator {
implicitHeight: 1
Layout.fillWidth: true
Layout.leftMargin: fontMetrics.height * 8
Layout.rightMargin: fontMetrics.height * 8
}
}