2 * Copyright (C) 2016 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
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.
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/>.
18 import Ubuntu.Components 1.3
22 implicitHeight: units.gu(5)
25 property bool isPrompt
26 property bool isAlphanumeric
28 property bool isSecret
32 signal responded(string text)
35 passwordInput.text = "";
42 property bool enabled: true
43 readonly property color textColor: passwordInput.enabled ? theme.palette.normal.raisedText
44 : theme.palette.disabled.raisedText
45 readonly property color selectedColor: passwordInput.enabled ? theme.palette.normal.raised
46 : theme.palette.disabled.raised
47 readonly property color drawColor: passwordInput.enabled ? theme.palette.normal.raisedSecondaryText
48 : theme.palette.disabled.raisedSecondaryText
49 readonly property color errorColor: passwordInput.enabled ? theme.palette.normal.negative
50 : theme.palette.disabled.negative
55 border.width: units.dp(1)
56 border.color: d.drawColor
62 objectName: "promptButton"
64 visible: !root.isPrompt
68 onClicked: root.clicked()
71 anchors.centerIn: parent
79 objectName: "promptField"
81 visible: root.isPrompt
85 inputMethodHints: root.isAlphanumeric ? Qt.ImhNone : Qt.ImhDigitsOnly
86 echoMode: root.isSecret ? TextInput.Password : TextInput.Normal
89 readonly property real frameSpacing: units.gu(0.5)
92 property color color: d.textColor
93 property color selectedTextColor: d.selectedColor
94 property color selectionColor: d.textColor
95 property color borderColor: "transparent"
96 property color backgroundColor: "transparent"
97 property color errorColor: d.errorColor
98 property real frameSpacing: passwordInput.frameSpacing
105 name: "keyboard-caps-enabled"
109 visible: root.isSecret && false // TODO: detect when caps lock is on
117 root.responded(text);
120 Keys.onEscapePressed: root.canceled()
122 // We use our own custom placeholder label instead of the standard
123 // TextField one because the standard one hardcodes baseText as the
124 // palette color, whereas we want raisedSecondaryText.
130 verticalCenter: parent.verticalCenter
131 leftMargin: units.gu(1.5)
132 rightMargin: anchors.leftMargin +
133 (capsIcon.visible ? capsIcon.width + passwordInput.frameSpacing
137 visible: passwordInput.text == "" && !passwordInput.inputMethodComposing
139 elide: Text.ElideRight