2 * Copyright (C) 2013, 2014, 2015 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/>.
18import Lomiri.Components 1.3
24 height: shakeContainer.height
27 property string infoText
28 property string errorText
29 property bool entryEnabled: true
30 property color foregroundColor: "#000000"
32 readonly property string passphrase: pinentryField.text
34 signal entered(string passphrase)
37 function clear(playAnimation) {
38 pinentryField.text = "";
39 pinentryField.incorrectOverride = false;
40 pinentryField.forceActiveFocus();
42 wrongPasswordAnimation.start();
48 anchors.horizontalCenter: parent.horizontalCenter
54 objectName: "infoTextLabel"
56 color: root.foregroundColor
57 anchors.horizontalCenter: parent.horizontalCenter
63 anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
69 objectName: "pinentryField"
72 property bool incorrectOverride: false
79 horizontalAlignment: Text.AlignHCenter
80 font.pixelSize: FontUtils.sizeToPixels("large")
81 echoMode: TextInput.Password
82 inputMethodHints: Qt.ImhHiddenText | Qt.ImhSensitiveData |
83 Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
84 color: root.foregroundColor
85 cursorDelegate: Item {} // disable cursor
86 onCursorPositionChanged: {
87 // And because we don't show the cursor, always position the
88 // cursor at the end of the string (so backspace works like
89 // the user expects, even if they've clicked on us and
90 // thus accidentally moved the cursor)
91 if (cursorPosition !== length) {
92 cursorPosition = length
97 // This is so that we can draw our own dots, for we want
98 // complete control over the pixel sizes. (The lomiri font
99 // has oddly sized password characters that don't scale right)
102 // simulate being disabled, but without removing OSK focus
103 maximumLength: root.entryEnabled ? 32767 : length
105 onTextChanged: incorrectOverride = true
108 if (pinentryField.text) {
109 root.entered(pinentryField.text);
116 anchors.centerIn: entryContainer
118 property real dotSize: Math.min(units.gu(2), entryContainer.width / pinentryField.length)
119 spacing: Math.min(units.gu(2), Math.max(0, (entryContainer.width / pinentryField.length) - dotSize))
122 model: pinentryField.length
123 delegate: Rectangle {
124 color: root.foregroundColor
125 width: dotRow.dotSize
134 objectName: "wrongNoticeLabel"
136 color: root.foregroundColor
137 anchors.horizontalCenter: parent.horizontalCenter
138 horizontalAlignment: Text.AlignHCenter
140 visible: pinentryField.text.length == 0 && !pinentryField.incorrectOverride
145 WrongPasswordAnimation {
146 id: wrongPasswordAnimation
147 objectName: "wrongPasswordAnimation"
148 target: shakeContainer