Unity 8
 All Classes Functions
PinLockscreen.qml
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  */
16 
17 import QtQuick 2.0
18 import Ubuntu.Components 0.1
19 import Ubuntu.Components.ListItems 0.1
20 import "../Components"
21 
22 Column {
23  id: root
24  anchors.top: parent.top
25  anchors.topMargin: units.gu(4)
26  anchors.horizontalCenter: parent.horizontalCenter
27  spacing: units.gu(2)
28 
29  property string infoText
30  property string retryText
31  property string errorText
32  property int padWidth: units.gu(34)
33  property int padHeight: units.gu(28)
34  property int minPinLength: -1
35  property int maxPinLength: -1
36  property bool showCancelButton: true
37 
38  signal entered(string passphrase)
39  signal cancel()
40 
41  property bool entryEnabled: true
42 
43  function clear(showAnimation) {
44  pinentryField.text = "";
45  if (showAnimation) {
46  pinentryField.incorrectOverride = true;
47  wrongPasswordAnimation.start();
48  }
49  }
50 
51  Column {
52  id: shakeContainer
53  anchors.horizontalCenter: parent.horizontalCenter
54  width: parent.width
55  spacing: units.gu(1)
56 
57  Label {
58  id: infoField
59  objectName: "infoTextLabel"
60  fontSize: "large"
61  color: "#f3f3e7"
62  anchors.horizontalCenter: parent.horizontalCenter
63  text: root.infoText
64  }
65 
66  Item {
67  id: pinContainer
68  anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
69  height: units.gu(4)
70 
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)))
77 
78  property string text
79  property bool incorrectOverride: false
80 
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  }
90 
91  function appendNumber(number) {
92  if (incorrectOverride) {
93  incorrectOverride = false;
94  }
95 
96  pinentryField.text = pinentryField.text + number
97 
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  }
103 
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  }
118 
119  AbstractButton {
120  objectName: "backspaceIcon"
121  anchors { right: parent.right; top: parent.top; bottom: parent.bottom }
122  width: height
123 
124  Icon {
125  anchors.fill: parent
126  name: "erase"
127  color: "#f3f3e7"
128  }
129 
130  opacity: (pinentryField.text.length && !pinentryField.incorrectOverride) > 0 ? 1 : 0
131 
132  Behavior on opacity {
133  UbuntuNumberAnimation {}
134  }
135 
136  onClicked: pinentryField.backspace()
137  }
138  }
139 
140  Label {
141  objectName: "retryLabel"
142  fontSize: "x-small"
143  color: "#f3f3e7"
144  anchors.horizontalCenter: parent.horizontalCenter
145  text: root.retryText || " "
146  }
147  }
148 
149  ThinDivider {
150  anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
151  }
152 
153  Grid {
154  id: numbersGrid
155  anchors { horizontalCenter: parent.horizontalCenter }
156  columns: 3
157 
158  property int buttonHeight: units.gu(8)
159  property int buttonWidth: units.gu(12)
160 
161  Repeater {
162  model: 9
163 
164  PinPadButton {
165  objectName: "pinPadButton" + text
166  text: index + 1
167  height: numbersGrid.buttonHeight
168  width: numbersGrid.buttonWidth
169  enabled: root.entryEnabled && (root.maxPinLength == -1 ||
170  pinentryField.text.length < root.maxPinLength ||
171  pinentryField.incorrectOverride)
172 
173  onClicked: {
174  pinentryField.appendNumber(index + 1)
175  }
176  }
177  }
178  Item {
179  height: numbersGrid.buttonHeight
180  width: numbersGrid.buttonWidth
181  }
182  PinPadButton {
183  text: "0"
184  height: numbersGrid.buttonHeight
185  width: numbersGrid.buttonWidth
186  enabled: root.entryEnabled && (root.maxPinLength == -1 ||
187  pinentryField.text.length < root.maxPinLength ||
188  pinentryField.incorrectOverride)
189 
190  onClicked: {
191  pinentryField.appendNumber(0)
192  }
193  }
194  Item {
195  height: numbersGrid.buttonHeight
196  width: numbersGrid.buttonWidth
197  }
198  PinPadButton {
199  iconName: "close"
200  height: units.gu(5) // visual spec has this row a little closer in
201  width: numbersGrid.buttonWidth
202 
203  onClicked: root.cancel()
204  visible: root.showCancelButton
205  }
206  Item {
207  height: units.gu(5)
208  width: numbersGrid.buttonWidth
209  }
210  PinPadButton {
211  iconName: "tick"
212  objectName: "confirmButton"
213  height: units.gu(5)
214  width: numbersGrid.buttonWidth
215  enabled: root.enabled && pinentryField.text.length >= root.minPinLength
216  visible: root.minPinLength == -1 || root.minPinLength !== root.maxPinLength
217 
218  onClicked: root.entered(pinentryField.text)
219  }
220  }
221  WrongPasswordAnimation {
222  id: wrongPasswordAnimation
223  objectName: "wrongPasswordAnimation"
224  target: shakeContainer
225  }
226 }