on 436b607 help sign in
unity8/qml/Components/PinLockscreen.qml
228 lines 7.4 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 y: units.gu(4)
25 spacing: units.gu(2)
27 property string infoText
28 property string retryText
29 property string errorText
30 property int padWidth: units.gu(34)
31 property int padHeight: units.gu(28)
32 property int minPinLength: -1
33 property int maxPinLength: -1
34 property bool showCancelButton: true
36 readonly property string passphrase: pinentryField.text
38 signal entered(string passphrase)
39 signal cancel()
41 property bool entryEnabled: true
43 function clear(showAnimation) {
44 pinentryField.text = "";
45 if (showAnimation) {
46 pinentryField.incorrectOverride = true;
47 wrongPasswordAnimation.start();
48 }
49 }
51 Column {
52 id: shakeContainer
53 anchors.horizontalCenter: parent.horizontalCenter
54 width: parent.width
55 spacing: units.gu(1)
57 Label {
58 id: infoField
59 objectName: "infoTextLabel"
60 fontSize: "large"
61 color: "#f3f3e7"
62 anchors.horizontalCenter: parent.horizontalCenter
63 text: root.infoText
64 }
66 Item {
67 id: pinContainer
68 anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
69 height: units.gu(4)
71 Row {
72 id: pinentryField
73 objectName: "pinentryField"
74 anchors.horizontalCenter: parent.horizontalCenter
75 anchors.verticalCenter: parent.verticalCenter
76 spacing: Math.max(0, Math.min(units.gu(3), (parent.width / root.maxPinLength) - units.gu(3)))
78 property string text
79 property bool incorrectOverride: false
81 Repeater {
82 model: pinentryField.text.length
83 delegate: Rectangle {
84 color: "#f3f3e7"
85 width: Math.min(units.gu(2), (pinContainer.width - pinContainer.height*2 ) / (root.maxPinLength >= 0 ? root.maxPinLength : 16))
86 height: width
87 radius: width / 2
88 }
89 }
91 function appendNumber(number) {
92 if (incorrectOverride) {
93 incorrectOverride = false;
94 }
96 pinentryField.text = pinentryField.text + number
98 if (root.minPinLength > 0 && root.maxPinLength > 0
99 && root.minPinLength == root.maxPinLength && pinentryField.text.length == root.minPinLength) {
100 root.entered(pinentryField.text)
101 }
102 }
104 function backspace() {
105 pinentryField.text = pinentryField.text.substring(0, pinentryField.text.length-1)
106 }
107 }
108 Label {
109 id: wrongNoticeLabel
110 objectName: "wrongNoticeLabel"
111 fontSize: "x-large"
112 color: "#f3f3e7"
113 anchors.horizontalCenter: parent.horizontalCenter
114 horizontalAlignment: Text.AlignHCenter
115 text: root.errorText
116 visible: pinentryField.incorrectOverride
117 scale: Math.min(1, parent.width / width)
118 }
120 AbstractButton {
121 objectName: "backspaceIcon"
122 anchors { right: parent.right; top: parent.top; bottom: parent.bottom }
123 width: height
124 enabled: root.entryEnabled
126 Icon {
127 anchors.fill: parent
128 name: "erase"
129 color: "#f3f3e7"
130 }
132 opacity: (pinentryField.text.length > 0 && !pinentryField.incorrectOverride) ? 1 : 0
134 Behavior on opacity {
135 UbuntuNumberAnimation {}
136 }
138 onClicked: pinentryField.backspace()
139 }
140 }
142 Label {
143 objectName: "retryLabel"
144 fontSize: "x-small"
145 color: "#f3f3e7"
146 anchors.horizontalCenter: parent.horizontalCenter
147 text: root.retryText || " "
148 }
149 }
151 ThinDivider {
152 anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
153 }
155 Grid {
156 id: numbersGrid
157 anchors { horizontalCenter: parent.horizontalCenter }
158 columns: 3
160 property int buttonHeight: units.gu(8)
161 property int buttonWidth: units.gu(12)
163 Repeater {
164 model: 9
166 PinPadButton {
167 objectName: "pinPadButton" + text
168 text: index + 1
169 height: numbersGrid.buttonHeight
170 width: numbersGrid.buttonWidth
171 enabled: root.entryEnabled && (root.maxPinLength == -1 ||
172 pinentryField.text.length < root.maxPinLength ||
173 pinentryField.incorrectOverride)
175 onClicked: {
176 pinentryField.appendNumber(index + 1)
177 }
178 }
179 }
180 Item {
181 height: numbersGrid.buttonHeight
182 width: numbersGrid.buttonWidth
183 }
184 PinPadButton {
185 text: "0"
186 height: numbersGrid.buttonHeight
187 width: numbersGrid.buttonWidth
188 enabled: root.entryEnabled && (root.maxPinLength == -1 ||
189 pinentryField.text.length < root.maxPinLength ||
190 pinentryField.incorrectOverride)
192 onClicked: {
193 pinentryField.appendNumber(0)
194 }
195 }
196 Item {
197 height: numbersGrid.buttonHeight
198 width: numbersGrid.buttonWidth
199 }
200 PinPadButton {
201 iconName: "close"
202 height: units.gu(5) // visual spec has this row a little closer in
203 width: numbersGrid.buttonWidth
205 onClicked: root.cancel()
206 visible: root.showCancelButton
207 }
208 Item {
209 height: units.gu(5)
210 width: numbersGrid.buttonWidth
211 }
212 PinPadButton {
213 iconName: "tick"
214 objectName: "confirmButton"
215 height: units.gu(5)
216 width: numbersGrid.buttonWidth
217 enabled: root.enabled && pinentryField.text.length >= root.minPinLength
218 visible: root.minPinLength == -1 || root.minPinLength !== root.maxPinLength
220 onClicked: root.entered(pinentryField.text)
221 }
222 }
223 WrongPasswordAnimation {
224 id: wrongPasswordAnimation
225 objectName: "wrongPasswordAnimation"
226 target: shakeContainer
227 }