on xenial help sign in
make pinlockscreen adjust better to larger displays

Approved by: Mirco Müller

commit37ad6e0c82eb3f7dbae2c2bccc1f3dc03ab97eb7 authorMichael Zanetti <michael.zanetti@canonical.com> dateFri 20 Mar 2015, 11:56 (12 years ago) parentab3534ee06d2ba
5 files changed+204−157
qml/Components/Lockscreen.qml+14−7 qml/Components/PassphraseLockscreen.qml+5−4 qml/Components/PinLockscreen.qml+156−144 qml/Components/PinPadButton.qml+3−2 tests/qmltests/Components/tst_Lockscreen.qml+26
qml/Components/Lockscreen.qml+14−7
@@ -60,6 +60,8 @@ Showable {
6060 // 0: normal background, 1: black background
6161 property real darkenBackground: 0
6262
63+ property color foregroundColor: "#f3f3e7"
64+
6365 readonly property string passphrase: (pinPadLoader.item && pinPadLoader.item.passphrase) ? pinPadLoader.item.passphrase : ""
6466
6567 signal entered(string passphrase)
@@ -210,11 +212,16 @@ Showable {
210212 property: "delayMinutes"
211213 value: root.delayMinutes
212214 }
213− }
214− Binding {
215− target: pinPadLoader.item
216− property: "showCancelButton"
217− value: root.showCancelButton
215+ Binding {
216+ target: pinPadLoader.item
217+ property: "showCancelButton"
218+ value: root.showCancelButton
219+ }
220+ Binding {
221+ target: pinPadLoader.item
222+ property: "foregroundColor"
223+ value: root.foregroundColor
224+ }
218225 }
219226 }
220227
@@ -236,7 +243,7 @@ Showable {
236243 anchors.horizontalCenter: parent.horizontalCenter
237244
238245 text: callManager.hasCalls ? i18n.tr("Return to Call") : i18n.tr("Emergency Call")
239− color: "#f3f3e7"
246+ color: root.foregroundColor
240247 }
241248
242249 Icon {
@@ -246,7 +253,7 @@ Showable {
246253 width: emergencyCallLabel.height
247254 height: emergencyCallLabel.height
248255 name: "call-start"
249− color: "#f3f3e7"
256+ color: root.foregroundColor
250257 }
251258
252259 MouseArea {
qml/Components/PassphraseLockscreen.qml+5−4
@@ -26,6 +26,7 @@ Item {
2626 property string infoText
2727 property string errorText
2828 property bool entryEnabled: true
29+ property color foregroundColor: "#000000"
2930
3031 readonly property string passphrase: pinentryField.text
3132
@@ -53,7 +54,7 @@ Item {
5354 id: infoField
5455 objectName: "infoTextLabel"
5556 fontSize: "x-large"
56− color: "#f3f3e7"
57+ color: root.foregroundColor
5758 anchors.horizontalCenter: parent.horizontalCenter
5859 text: root.infoText
5960 }
@@ -79,7 +80,7 @@ Item {
7980 echoMode: TextInput.Password
8081 inputMethodHints: Qt.ImhHiddenText | Qt.ImhSensitiveData |
8182 Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
82− color: "#f3f3e7"
83+ color: root.foregroundColor
8384 cursorDelegate: Item {} // disable cursor
8485 onCursorPositionChanged: {
8586 // And because we don't show the cursor, always position the
@@ -119,7 +120,7 @@ Item {
119120 Repeater {
120121 model: pinentryField.length
121122 delegate: Rectangle {
122− color: "#f3f3e7"
123+ color: root.foregroundColor
123124 width: dotRow.dotSize
124125 height: width
125126 radius: width / 2
@@ -131,7 +132,7 @@ Item {
131132 id: wrongNoticeLabel
132133 objectName: "wrongNoticeLabel"
133134 fontSize: "large"
134− color: "#f3f3e7"
135+ color: root.foregroundColor
135136 anchors.horizontalCenter: parent.horizontalCenter
136137 horizontalAlignment: Text.AlignHCenter
137138 text: root.errorText
qml/Components/PinLockscreen.qml+156−144
@@ -19,19 +19,16 @@ import Ubuntu.Components 0.1
1919import Ubuntu.Components.ListItems 0.1
2020import "../Components"
2121
22−Column {
22+Item {
2323 id: root
24− y: units.gu(4)
25− spacing: units.gu(2)
2624
2725 property string infoText
2826 property string retryText
2927 property string errorText
30− property int padWidth: units.gu(34)
31− property int padHeight: units.gu(28)
3228 property int minPinLength: -1
3329 property int maxPinLength: -1
3430 property bool showCancelButton: true
31+ property color foregroundColor: "#000000"
3532
3633 readonly property string passphrase: pinentryField.text
3734
@@ -49,180 +46,195 @@ Column {
4946 }
5047
5148 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
49+ anchors {
50+ left: parent.left;
51+ right: parent.right;
52+ verticalCenter: parent.verticalCenter;
53+ verticalCenterOffset: Math.max(-units.gu(10), -(root.height - height) / 2) + units.gu(4)
6454 }
55+ spacing: units.gu(2)
6556
66− Item {
67− id: pinContainer
68− anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
69− height: units.gu(4)
57+ Column {
58+ id: shakeContainer
59+ anchors.horizontalCenter: parent.horizontalCenter
60+ width: parent.width
61+ spacing: units.gu(1)
7062
71− Row {
72− id: pinentryField
73− objectName: "pinentryField"
63+ Label {
64+ id: infoField
65+ objectName: "infoTextLabel"
66+ fontSize: "large"
67+ color: root.foregroundColor
7468 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− }
69+ text: root.infoText
70+ }
9071
91− function appendNumber(number) {
92− if (incorrectOverride) {
93− incorrectOverride = false;
72+ Item {
73+ id: pinContainer
74+ anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
75+ height: units.gu(4)
76+
77+ Row {
78+ id: pinentryField
79+ objectName: "pinentryField"
80+ anchors.horizontalCenter: parent.horizontalCenter
81+ anchors.verticalCenter: parent.verticalCenter
82+ spacing: Math.max(0, Math.min(units.gu(3), (parent.width / root.maxPinLength) - units.gu(3)))
83+
84+ property string text
85+ property bool incorrectOverride: false
86+
87+ Repeater {
88+ model: pinentryField.text.length
89+ delegate: Rectangle {
90+ color: root.foregroundColor
91+ width: Math.min(units.gu(2), (pinContainer.width - pinContainer.height*2 ) / (root.maxPinLength >= 0 ? root.maxPinLength : 16))
92+ height: width
93+ radius: width / 2
94+ }
9495 }
9596
96− pinentryField.text = pinentryField.text + number
97+ function appendNumber(number) {
98+ if (incorrectOverride) {
99+ incorrectOverride = false;
100+ }
97101
98− if (root.minPinLength > 0 && root.maxPinLength > 0
99− && root.minPinLength == root.maxPinLength && pinentryField.text.length == root.minPinLength) {
100− root.entered(pinentryField.text)
102+ pinentryField.text = pinentryField.text + number
103+
104+ if (root.minPinLength > 0 && root.maxPinLength > 0
105+ && root.minPinLength == root.maxPinLength && pinentryField.text.length == root.minPinLength) {
106+ root.entered(pinentryField.text)
107+ }
101108 }
102− }
103109
104− function backspace() {
105− pinentryField.text = pinentryField.text.substring(0, pinentryField.text.length-1)
110+ function backspace() {
111+ pinentryField.text = pinentryField.text.substring(0, pinentryField.text.length-1)
112+ }
113+ }
114+ Label {
115+ id: wrongNoticeLabel
116+ objectName: "wrongNoticeLabel"
117+ fontSize: "x-large"
118+ color: root.foregroundColor
119+ anchors.horizontalCenter: parent.horizontalCenter
120+ horizontalAlignment: Text.AlignHCenter
121+ text: root.errorText
122+ visible: pinentryField.incorrectOverride
123+ scale: Math.min(1, parent.width / width)
106124 }
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− }
119125
120− AbstractButton {
121− objectName: "backspaceIcon"
122− anchors { right: parent.right; top: parent.top; bottom: parent.bottom }
123− width: height
124− enabled: root.entryEnabled
126+ AbstractButton {
127+ objectName: "backspaceIcon"
128+ anchors { right: parent.right; top: parent.top; bottom: parent.bottom }
129+ width: height
130+ enabled: root.entryEnabled
125131
126− Icon {
127− anchors.fill: parent
128− name: "erase"
129− color: "#f3f3e7"
130− }
132+ Icon {
133+ anchors.fill: parent
134+ name: "erase"
135+ color: root.foregroundColor
136+ }
131137
132− opacity: (pinentryField.text.length > 0 && !pinentryField.incorrectOverride) ? 1 : 0
138+ opacity: (pinentryField.text.length > 0 && !pinentryField.incorrectOverride) ? 1 : 0
133139
134− Behavior on opacity {
135− UbuntuNumberAnimation {}
140+ Behavior on opacity {
141+ UbuntuNumberAnimation {}
142+ }
143+
144+ onClicked: pinentryField.backspace()
136145 }
146+ }
137147
138− onClicked: pinentryField.backspace()
148+ Label {
149+ objectName: "retryLabel"
150+ fontSize: "x-small"
151+ color: root.foregroundColor
152+ anchors.horizontalCenter: parent.horizontalCenter
153+ text: root.retryText || " "
139154 }
140155 }
141156
142− Label {
143− objectName: "retryLabel"
144− fontSize: "x-small"
145− color: "#f3f3e7"
146− anchors.horizontalCenter: parent.horizontalCenter
147− text: root.retryText || " "
157+ ThinDivider {
158+ anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
148159 }
149− }
150−
151− ThinDivider {
152− anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
153− }
154−
155− Grid {
156− id: numbersGrid
157− anchors { horizontalCenter: parent.horizontalCenter }
158− columns: 3
159−
160− property int buttonHeight: units.gu(8)
161− property int buttonWidth: units.gu(12)
162−
163− Repeater {
164− model: 9
165160
161+ Grid {
162+ id: numbersGrid
163+ objectName: "numbersGrid"
164+ anchors { horizontalCenter: parent.horizontalCenter }
165+ columns: 3
166+
167+ property int maxWidth: Math.min(units.gu(50), root.width - units.gu(8))
168+ property int buttonWidth: maxWidth / 3
169+ property int buttonHeight: buttonWidth * 2 / 3
170+
171+ Repeater {
172+ model: 9
173+
174+ PinPadButton {
175+ objectName: "pinPadButton" + text
176+ text: index + 1
177+ height: numbersGrid.buttonHeight
178+ width: numbersGrid.buttonWidth
179+ foregroundColor: root.foregroundColor
180+ enabled: root.entryEnabled && (root.maxPinLength == -1 ||
181+ pinentryField.text.length < root.maxPinLength ||
182+ pinentryField.incorrectOverride)
183+
184+ onClicked: {
185+ pinentryField.appendNumber(index + 1)
186+ }
187+ }
188+ }
189+ Item {
190+ height: numbersGrid.buttonHeight
191+ width: numbersGrid.buttonWidth
192+ }
166193 PinPadButton {
167− objectName: "pinPadButton" + text
168− text: index + 1
194+ text: "0"
169195 height: numbersGrid.buttonHeight
170196 width: numbersGrid.buttonWidth
197+ foregroundColor: root.foregroundColor
171198 enabled: root.entryEnabled && (root.maxPinLength == -1 ||
172199 pinentryField.text.length < root.maxPinLength ||
173200 pinentryField.incorrectOverride)
174201
175202 onClicked: {
176− pinentryField.appendNumber(index + 1)
203+ pinentryField.appendNumber(0)
177204 }
178205 }
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)
191−
192− onClicked: {
193− pinentryField.appendNumber(0)
206+ Item {
207+ height: numbersGrid.buttonHeight
208+ width: numbersGrid.buttonWidth
194209 }
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
210+ PinPadButton {
211+ iconName: "close"
212+ height: units.gu(5) // visual spec has this row a little closer in
213+ width: numbersGrid.buttonWidth
214+ foregroundColor: root.foregroundColor
215+ onClicked: root.cancel()
216+ visible: root.showCancelButton
217+ }
218+ Item {
219+ height: units.gu(5)
220+ width: numbersGrid.buttonWidth
221+ }
222+ PinPadButton {
223+ iconName: "tick"
224+ objectName: "confirmButton"
225+ height: units.gu(5)
226+ width: numbersGrid.buttonWidth
227+ foregroundColor: root.foregroundColor
228+ enabled: root.enabled && pinentryField.text.length >= root.minPinLength
229+ visible: root.minPinLength == -1 || root.minPinLength !== root.maxPinLength
204230
205− onClicked: root.cancel()
206− visible: root.showCancelButton
207− }
208− Item {
209− height: units.gu(5)
210− width: numbersGrid.buttonWidth
231+ onClicked: root.entered(pinentryField.text)
232+ }
211233 }
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
219−
220− onClicked: root.entered(pinentryField.text)
234+ WrongPasswordAnimation {
235+ id: wrongPasswordAnimation
236+ objectName: "wrongPasswordAnimation"
237+ target: shakeContainer
221238 }
222239 }
223− WrongPasswordAnimation {
224− id: wrongPasswordAnimation
225− objectName: "wrongPasswordAnimation"
226− target: shakeContainer
227− }
228240}
qml/Components/PinPadButton.qml+3−2
@@ -23,6 +23,7 @@ AbstractButton {
2323
2424 property alias text: label.text
2525 property string iconName
26+ property color foregroundColor: "#000000"
2627
2728 UbuntuShape {
2829 anchors.fill: parent
@@ -36,7 +37,7 @@ AbstractButton {
3637 id: label
3738 anchors.centerIn: parent
3839 horizontalAlignment: Text.AlignHCenter
39− color: "#f3f3e7"
40+ color: root.foregroundColor
4041 fontSize: "x-large"
4142 font.weight: Font.DemiBold
4243 visible: text.length > 0
@@ -52,7 +53,7 @@ AbstractButton {
5253 width: height
5354 anchors.centerIn: parent
5455 name: root.iconName
55− color: "#f3f3e7"
56+ color: root.foregroundColor
5657 visible: name.length > 0
5758 scale: root.pressed ? 0.9 : 1
5859 Behavior on scale {
tests/qmltests/Components/tst_Lockscreen.qml+26
@@ -173,6 +173,10 @@ Rectangle {
173173 function cleanup() {
174174 lockscreen.clear(false);
175175 delayMinutesTextField.text = "0"
176+
177+ // Reset sizing
178+ root.width = units.gu(80)
179+ root.height = units.gu(76)
176180 }
177181
178182 function waitForLockscreenReady() {
@@ -450,6 +454,28 @@ Rectangle {
450454 var label = findChild(lockscreen, "deviceLockedLabel")
451455 compare(label.text, "Device Locked")
452456 }
457+
458+ function test_resize_data() {
459+ return [
460+ { tag: "small", width: units.gu(40), height: units.gu(76) },
461+ { tag: "medium", width: units.gu(50), height: units.gu(86) },
462+ { tag: "large", width: units.gu(60), height: units.gu(96) },
463+ { tag: "x-large", width: units.gu(80), height: units.gu(116) },
464+ ]
465+ }
466+
467+ function test_resize(data) {
468+ var controlsAreaWidth = lockscreen.anchors.rightMargin;
469+ root.width = data.width + controlsAreaWidth;
470+ root.height = data.height;
471+ waitForRendering(root);
472+
473+ var numbersGrid = findChild(lockscreen, "numbersGrid");
474+ // Make sure the numbers pad keeps a 4gu margin on left/right but doesn't grow larger than 50 gu's width.
475+ // For rounding reasons it might be off 1 pixel. Let's make sure it's within +/- 1 pixel of what we expect
476+ verify(numbersGrid.width >= Math.min(units.gu(50), data.width - units.gu(8)) - 1);
477+ verify(numbersGrid.width <= Math.min(units.gu(50), data.width - units.gu(8)) + 1);
478+ }
453479 }
454480
455481 SignalSpy {