hyprpolkitagent/qml/main.qml

161 lines
4.3 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 17:00:37 +02:00
property var windowWidth: Math.round(fontMetrics.height * 32.2856)
property var windowHeight: Math.round(fontMetrics.height * 13.9528)
property var heightSafeMargin: 15
2024-10-14 18:55:01 +02:00
minimumWidth: Math.max(windowWidth, mainLayout.Layout.minimumWidth) + mainLayout.anchors.margins * 2
minimumHeight: Math.max(windowHeight, mainLayout.Layout.minimumHeight) + mainLayout.anchors.margins * 2 + heightSafeMargin
maximumWidth: minimumWidth
maximumHeight: minimumHeight
2024-10-14 18:55:01 +02:00
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 {
id: mainLayout
2024-10-14 18:55:01 +02:00
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
Layout.maximumWidth: parent.width
elide: Text.ElideRight
wrapMode: Text.WordWrap
2024-10-14 18:55:01 +02:00
}
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()
Layout.maximumWidth: parent.width
elide: Text.ElideRight
wrapMode: Text.WordWrap
2024-10-14 18:55:01 +02:00
}
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
2024-10-16 17:00:37 +02:00
Layout.topMargin: 0
2024-10-14 18:55:01 +02:00
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
}
}