on c3f33dd help sign in
unity8/qml/Components/PinLockscreen.qml
233 lines 7.1 kB history 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 as published by
6 * the Free Software Foundation; version 3.
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 */
17import QtQuick 2.0
18import Ubuntu.Components 0.1
19import Ubuntu.Components.ListItems 0.1
20import "../Components"
22Column {
23 id: root
24 anchors.centerIn: parent
25 spacing: units.gu(3.5)
27 property alias placeholderText: pinentryField.placeholderText
28 property int padWidth: units.gu(34)
29 property int padHeight: units.gu(28)
30 property int minPinLength: -1
31 property int maxPinLength: -1
33 signal entered(string passphrase)
34 signal cancel()
36 property bool entryEnabled: true
38 function clear(playAnimation) {
39 pinentryField.text = "";
40 if (playAnimation) {
41 wrongPasswordAnimation.start();
42 }
43 }
45 QtObject {
46 id: priv
47 property bool autoConfirm: root.minPinLength == root.maxPinLength && root.minPinLength != -1
48 }
50 UbuntuShape {
51 id: pinentryField
52 objectName: "pinentryField"
53 anchors.horizontalCenter: parent.horizontalCenter
54 color: "#55000000"
55 width:root.padWidth
56 height: units.gu(5)
57 radius: "medium"
58 property string text: ""
59 property string placeholderText: ""
61 function appendChar(character) {
62 if (root.maxPinLength == -1 || pinentryField.text.length < root.maxPinLength) {
63 pinentryField.text = pinentryField.text + character;
64 }
65 }
67 onTextChanged: {
68 pinentryFieldLabel.text = "";
69 for (var i = 0; i < text.length; ++i) {
70 pinentryFieldLabel.text += "•";
71 }
72 if (priv.autoConfirm && text.length === root.maxPinLength) {
73 root.entered(text);
74 }
75 }
77 Label {
78 id: pinentryFieldLabel
79 anchors.centerIn: parent
80 width: parent.width - (backspaceIcon.width + backspaceIcon.anchors.rightMargin) * 2
81 elide: Text.ElideMiddle
82 horizontalAlignment: Text.AlignHCenter
83 font.pixelSize: units.dp(44)
84 color: "#f3f3e7"
85 opacity: 0.6
86 }
87 Label {
88 id: pinentryFieldPlaceHolder
89 objectName: "pinentryFieldPlaceHolder"
90 anchors.centerIn: parent
91 horizontalAlignment: Text.AlignHCenter
92 color: "#f3f3e7"
93 opacity: 0.6
94 text: parent.placeholderText
95 visible: pinentryFieldLabel.text.length == 0
96 }
98 Icon {
99 id: backspaceIcon
100 objectName: "backspaceIcon"
101 anchors {
102 top: parent.top
103 topMargin: units.gu(1)
104 right: parent.right
105 rightMargin: units.gu(2)
106 bottom: parent.bottom
107 bottomMargin: units.gu(1)
108 }
109 visible: entryEnabled && !priv.autoConfirm
110 width: height
111 name: "erase"
112 color: "#f3f3e7"
113 opacity: 0.6
114 MouseArea {
115 anchors.fill: parent
116 onClicked: pinentryField.text = pinentryField.text.substring(0, pinentryField.text.length-1);
117 }
118 }
119 }
121 UbuntuShape {
122 anchors {
123 left: parent.left
124 right: parent.right
125 margins: (parent.width - root.padWidth) / 2
126 }
127 height: root.padHeight
128 color: "#55000000"
129 radius: "medium"
131 ThinDivider {
132 anchors {
133 left: parent.left
134 right: parent.right
135 top: parent.top
136 topMargin: root.padHeight / 4
137 }
138 }
139 ThinDivider {
140 anchors {
141 left: parent.left
142 right: parent.right
143 verticalCenter: parent.verticalCenter
144 }
145 }
146 ThinDivider {
147 anchors {
148 left: parent.left
149 right: parent.right
150 bottom: parent.bottom
151 bottomMargin: root.padHeight / 4
152 }
153 }
155 ThinDivider {
156 anchors.centerIn: parent
157 anchors.horizontalCenterOffset: -root.padWidth / 6
158 width: root.padHeight
159 rotation: -90
160 }
161 ThinDivider {
162 anchors.centerIn: parent
163 anchors.horizontalCenterOffset: root.padWidth / 6
164 width: root.padHeight
165 rotation: -90
166 }
168 Grid {
169 anchors {
170 left: parent.left
171 right: parent.right
172 margins: (parent.width - root.padWidth) / 2
173 }
175 columns: 3
177 Repeater {
178 model: 9
180 PinPadButton {
181 objectName: "pinPadButton" + (index + 1)
182 width: root.padWidth / 3
183 height: root.padHeight / 4
184 text: index + 1
185 enabled: entryEnabled
187 onClicked: {
188 pinentryField.appendChar(text);
189 }
190 }
191 }
193 PinPadButton {
194 objectName: "pinPadButtonBack"
195 width: root.padWidth / 3
196 height: root.padHeight / 4
197 subText: i18n.tr("CANCEL")
198 onClicked: root.cancel();
199 }
201 PinPadButton {
202 objectName: "pinPadButton0"
203 width: root.padWidth / 3
204 height: root.padHeight / 4
205 text: "0"
206 onClicked: pinentryField.appendChar(text);
207 enabled: entryEnabled
208 }
210 PinPadButton {
211 objectName: "pinPadButtonErase"
212 width: root.padWidth / 3
213 height: root.padHeight / 4
214 iconName: priv.autoConfirm ? "erase" : ""
215 subText: priv.autoConfirm ? "" : i18n.tr("DONE")
216 onClicked: {
217 if (priv.autoConfirm) {
218 pinentryField.text = pinentryField.text.substring(0, pinentryField.text.length-1);
219 } else {
220 root.entered(pinentryField.text);
221 }
222 }
223 enabled: priv.autoConfirm ? entryEnabled : pinentryField.text.length >= root.minPinLength
224 }
225 }
226 }
228 WrongPasswordAnimation {
229 id: wrongPasswordAnimation
230 objectName: "wrongPasswordAnimation"
231 target: pinentryField
232 }