Debian Codegraph @

src/app/qml/dialogs/templates/ConfirmDialogWithInput.qml

raw
1 /*
2 * Copyright (C) 2013 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Arto Jalkanen <[email protected]>
17 */
18 import QtQuick 2.4
19 import Lomiri.Components 1.3
20 import Lomiri.Components.Popups 1.3
21
22 Dialog {
23 id: root
24
25 property alias inputText: input.text
26 property alias placeholderText: input.placeholderText
27 signal accepted(var text)
28 signal rejected
29
30 Component.onCompleted: {
31 // Need to force active focus to input, otherwise the parent object that created this
32 // dialog will continue to have active focus.
33 input.forceActiveFocus()
34 }
35
36 TextField {
37 id: input
38 objectName: "inputField"
39 focus: true
40 // Avoid need to press enter to make "Ok" button enabled.
41 inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase
42 validator: RegExpValidator {
43 regExp: /.+/
44 }
45 }
46
47 Button {
48 objectName: "okButton"
49 text: i18n.tr("OK")
50 enabled: input.acceptableInput
51 color: theme.palette.normal.positive
52 onClicked: {
53 accepted(input.text)
54 PopupUtils.close(root)
55 }
56 }
57
58 Button {
59 objectName: "cancelButton"
60 text: i18n.tr("Cancel")
61 onClicked: {
62 rejected()
63 PopupUtils.close(root)
64 }
65 }
66 }