1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
|
/*
* Copyright 2022 UBports Foundation
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.15
import Lomiri.Components 1.3
import AccountsService 0.1
Item {
id: root
objectName: "ClockPinPrompt"
property string text
property bool isSecret
property bool interactive: true
property bool loginError: false
property bool hasKeyboard: false //unused
property string enteredText: ""
property int previousNumber: -1
property var currentCode: []
property int maxnum: 10
readonly property int pincodeLength: AccountsService.pincodeLength
readonly property bool validCode: enteredText.length >= pincodeLength
property bool isLandscape: width > height
signal clicked()
signal canceled()
signal accepted(string response)
onCurrentCodeChanged: {
let tmpText = ""
let tmpCode = ""
const maxDigits = Math.max(root.pincodeLength, currentCode.length)
for( let i = 0; i < maxDigits; i++) {
if (i < currentCode.length) {
tmpText += '●'
tmpCode += currentCode[i]
} else {
tmpText += '○'
}
}
pinHint.text = tmpText
root.enteredText = tmpCode
if (root.enteredText.length >= pincodeLength) {
root.accepted(root.enteredText);
}
}
function addNumber (number, fromKeyboard) {
if (currentCode.length >= root.pincodeLength) return;
let tmpCodes = currentCode
tmpCodes.push(number)
currentCode = tmpCodes
// don't animate digits while with keyboard
if (!fromKeyboard) {
repeater.itemAt(number).animation.restart()
}
root.previousNumber = number
}
function removeOne() {
let tmpCodes = currentCode
tmpCodes.pop()
currentCode = tmpCodes
}
function reset() {
currentCode = []
loginError = false;
}
StyledItem {
id: d
readonly property color normal: theme.palette.normal.raisedText
readonly property color selected: theme.palette.normal.raisedSecondaryText
readonly property color selectedCircle: Qt.rgba(selected.r, selected.g, selected.b, 0.2)
readonly property color disabled:theme.palette.disabled.raisedSecondaryText
}
TextField {
id: pinHint
anchors.horizontalCenter: parent.horizontalCenter
width: contentWidth + eraseIcon.width + units.gu(3)
readOnly: true
color: d.selected
font {
pixelSize: units.gu(3)
letterSpacing: units.gu(1.75)
}
secondaryItem: Icon {
id: eraseIcon
name: "erase"
objectName: "EraseBtn"
height: units.gu(4)
width: units.gu(4)
color: enabled ? d.selected : d.disabled
enabled: root.currentCode.length > 0
anchors.verticalCenter: parent.verticalCenter
MouseArea {
anchors.fill: parent
onClicked: root.removeOne()
onPressAndHold: root.reset()
}
}
inputMethodHints: Qt.ImhDigitsOnly
Keys.onEscapePressed: {
root.canceled();
event.accepted = true;
}
Keys.onPressed: {
if(event.key >= Qt.Key_0 && event.key <= Qt.Key_9) {
root.addNumber(event.text, true)
event.accepted = true;
}
}
Keys.onReturnPressed: root.accepted(root.enteredText);
Keys.onEnterPressed: root.accepted(root.enteredText);
Keys.onBackPressed: {
root.removeOne()
}
}
Rectangle {
id: main
objectName: "SelectArea"
height: Math.min(parent.height, parent.width)
width: parent.width
anchors.bottom:parent.bottom
// in landscape, let the clock being close to the bottom
anchors.bottomMargin: root.isLandscape ? -units.gu(4) : undefined
anchors.horizontalCenter: parent.horizontalCenter
color: "transparent"
MouseArea {
id: mouseArea
anchors.fill: parent
function reEvaluate() {
var child = main.childAt(mouseX, mouseY)
if (child !== null && child.number !== undefined) {
var number = child.number
if (number > -1 && ( root.previousNumber === -1 || number !== root.previousNumber)) {
root.addNumber(number)
}
} else {
// outside
root.previousNumber = -1
}
}
onPressed: {
if (state !== "ENTRY_MODE") {
root.state = "ENTRY_MODE"
}
}
onPositionChanged: {
if (pressed)
reEvaluate()
}
}
Rectangle {
id: center
objectName: "CenterCircle"
height: main.height / 3
width: height
radius: height / 2
property int radiusSquared: radius * radius
property alias locker: centerImg.source
property alias animation: challengeAnim
anchors.centerIn: parent
color: "transparent"
property int number: -1
Icon {
id: centerImg
source: "image://theme/lock"
anchors.centerIn: parent
width: units.gu(4)
height: width
color: root.validCode ? d.selected : d.disabled
onSourceChanged: imgAnim.start()
}
SequentialAnimation {
id: challengeAnim
ParallelAnimation {
PropertyAnimation {
target: centerImg
property: "color"
to: d.selected
duration: 100
}
PropertyAnimation {
target: center
property: "color"
to: d.selectedCircle
duration: 100
}
}
PropertyAnimation {
target: center
property: "color"
to: "transparent"
duration: 400
}
}
SequentialAnimation {
id: imgAnim
NumberAnimation { target: centerImg; property: "opacity"; from: 0; to: 1; duration: 1000 }
}
}
Repeater {
id: repeater
objectName: "dotRepeater"
model: root.maxnum
Item {
id: numberComp
property int bigR: root.state === "ENTRY_MODE" || root.state === "TEST_MODE" || root.state === "EDIT_MODE" ? main.height / 3 : 0
property int radius: height / 2
property int offsetRadius: radius
property int number: index
property alias dot: point
property alias animation: anim
height: bigR / 2.2
width: height
x: (main.width / 2) + bigR * Math.sin(2 * Math.PI * index / root.maxnum) - offsetRadius
y: (main.height / 2) - bigR * Math.cos(2 * Math.PI * index / root.maxnum) - offsetRadius
Rectangle {
id: selectionRect
anchors.fill: parent
radius: numberComp.radius
color: d.selected
opacity: 0.1
}
Text {
id: point
font.pixelSize: main.height / 10
anchors.centerIn: parent
color: d.selected
text: index
opacity: root.state === "ENTRY_MODE" ? 1 : 0
property bool selected: false
Behavior on opacity {
LomiriNumberAnimation{ duration: 500 }
}
}
MouseArea {
anchors.fill: parent
onPressed: {
root.addNumber(index)
mouse.accepted = false
}
}
Behavior on bigR {
LomiriNumberAnimation { duration: 500 }
}
SequentialAnimation {
id: anim
ParallelAnimation {
PropertyAnimation {
target: point
property: "color"
to: d.disabled
duration: 100
}
PropertyAnimation {
target: selectionRect
property: "color"
to: d.selectedCircle
duration: 100
}
}
ParallelAnimation {
PropertyAnimation {
target: point
property: "color"
to: d.selected
duration: 400
}
PropertyAnimation {
target: selectionRect
property: "color"
to: d.selected
duration: 400
}
}
}
}
}
}
states: [
State{
name: "ENTRY_MODE"
StateChangeScript {
script: root.reset();
}
},
State{
name: "WRONG_PASSWORD"
when: root.loginError
PropertyChanges {
target: center
locker: "image://theme/dialog-warning-symbolic"
}
}
]
transitions: Transition {
from: "WRONG_PASSWORD"; to: "ENTRY_MODE";
PropertyAction { target: center; property: "locker"; value: "image://theme/dialog-warning-symbolic" }
PauseAnimation { duration: 1000 }
}
onActiveFocusChanged: {
if (!activeFocus && !pinHint.activeFocus) {
root.state = ""
} else {
root.state = "ENTRY_MODE"
pinHint.forceActiveFocus()
}
}
}
|