Debian Codegraph @

src/qml/Haruna/Components/InputPopup.qml

raw
1 /*
2 * SPDX-FileCopyrightText: 2022 George Florea Bănuș <[email protected]>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7 import QtQuick
8 import QtQuick.Controls
9 import QtQuick.Layouts
10
11 import org.kde.kirigami as Kirigami
12
13 Popup {
14 id: root
15
16 signal submitted(string text)
17 property string lastText: ""
18 property string placeholderText: ""
19 property string buttonText: ""
20 property alias warningText: warningMessage.text
21
22 modal: true
23
24 onOpened: {
25 textField.forceActiveFocus(Qt.MouseFocusReason)
26 textField.selectAll()
27 }
28
29 contentItem: RowLayout {
30 anchors.fill: parent
31 anchors.leftMargin: Kirigami.Units.largeSpacing
32 anchors.rightMargin: Kirigami.Units.largeSpacing
33
34 Label {
35 id: warningMessage
36
37 visible: text !== ""
38 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
39 onLinkActivated: (link) => Qt.openUrlExternally(link)
40
41 Layout.fillWidth: true
42 }
43
44 TextField {
45 id: textField
46
47 text: root.lastText
48 placeholderText: root.placeholderText
49 visible: root.warningText === ""
50
51 Layout.fillWidth: true
52
53 Keys.onPressed: function(event) {
54 switch(event.key) {
55 case Qt.Key_Enter:
56 case Qt.Key_Return:
57 submitButton.clicked()
58 return;
59 case Qt.Key_Escape:
60 root.close()
61 return;
62 }
63 }
64 }
65
66 Button {
67 id: submitButton
68
69 visible: root.warningText === ""
70 text: root.buttonText
71
72 onClicked: {
73 root.submitted(textField.text)
74 root.close()
75 textField.clear()
76 }
77 }
78 }
79 }