shift-shell/look-and-feel/contents/lockscreen/Keypad.qml

239 lines
8.3 KiB
QML
Raw Normal View History

2020-08-31 01:38:46 +00:00
/*
2021-04-11 04:26:30 +00:00
SPDX-FileCopyrightText: 2020-2021 Devin Lin <espidev@gmail.com>
2020-08-31 01:38:46 +00:00
2021-03-01 20:03:25 +00:00
SPDX-License-Identifier: GPL-2.0-or-later
2020-08-31 01:38:46 +00:00
*/
import QtQuick 2.12
2020-11-13 15:24:01 +00:00
import QtQuick.Controls 2.1
2020-08-31 01:38:46 +00:00
import QtQuick.Layouts 1.1
import QtGraphicalEffects 1.12
import org.kde.plasma.components 3.0 as PlasmaComponents
2020-08-31 01:38:46 +00:00
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.workspace.keyboardlayout 1.0
2020-11-21 19:49:08 +00:00
import org.kde.kirigami 2.12 as Kirigami
2020-08-31 01:38:46 +00:00
Rectangle {
id: keypadRoot
2020-11-21 19:49:08 +00:00
// 0 - keypad is not shown, 1 - keypad is shown
property double swipeProgress
// slightly translucent background, for key contrast
color: Kirigami.ColorUtils.adjustColor(PlasmaCore.Theme.backgroundColor, {"alpha": 0.9*255})
2020-08-31 01:38:46 +00:00
property string pinLabel: qsTr("Enter PIN")
2020-11-21 19:49:08 +00:00
// colour calculations
property color buttonColor: Qt.lighter(PlasmaCore.Theme.backgroundColor, 1.3)
property color buttonPressedColor: Qt.darker(PlasmaCore.Theme.backgroundColor, 1.08)
property color buttonTextColor: PlasmaCore.Theme.textColor
property color dropShadowColor: Qt.darker(PlasmaCore.Theme.backgroundColor, 1.2)
2020-11-21 19:49:08 +00:00
property color headerBackgroundColor: Qt.lighter(PlasmaCore.Theme.backgroundColor, 1.3)
opacity: Math.sin((Math.PI / 2) * swipeProgress + 1.5 * Math.PI) + 1
implicitHeight: {
if (passwordBar.isPinMode && !Qt.inputMethod.visible) {
return PlasmaCore.Units.gridUnit * 17;
} else {
return Math.min(root.height - passwordBar.implicitHeight, // don't make the password bar go off the screen
PlasmaCore.Units.smallSpacing * 2 + Qt.inputMethod.keyboardRectangle.height + passwordBar.implicitHeight);
}
}
2021-04-11 04:26:30 +00:00
Behavior on implicitHeight {
NumberAnimation {
duration: Kirigami.Units.longDuration
easing.type: Easing.InOutQuad
}
}
signal passwordChanged()
function reset() {
2021-04-11 15:46:50 +00:00
passwordBar.reset();
2020-08-31 01:38:46 +00:00
}
Connections {
target: authenticator
function onSucceeded() {
2021-04-11 15:46:50 +00:00
passwordBar.pinLabel = qsTr("Logging in...");
passwordBar.waitingForAuth = false;
}
2020-08-31 01:38:46 +00:00
function onFailed() {
root.password = "";
2021-04-11 15:46:50 +00:00
passwordBar.pinLabel = qsTr("Wrong PIN");
passwordBar.waitingForAuth = false;
}
function onGraceLockedChanged() {
// try authenticating if it was waiting for grace lock to stop and it has stopped
2021-04-11 15:46:50 +00:00
if (!authenticator.graceLocked && passwordBar.waitingForAuth) {
authenticator.tryUnlock(root.password);
}
2020-08-31 01:38:46 +00:00
}
}
// listen for keyboard events
Keys.onPressed: {
if (event.modifiers === Qt.NoModifier) {
if (event.key === Qt.Key_Backspace) {
2021-04-11 15:46:50 +00:00
passwordBar.backspace();
2021-03-15 20:40:29 +00:00
} else if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
2021-04-11 15:46:50 +00:00
passwordBar.enter();
2020-08-31 01:38:46 +00:00
} else if (event.text != "") {
2021-04-11 15:46:50 +00:00
passwordBar.keyPress(event.text);
2020-08-31 01:38:46 +00:00
}
}
if (event.modifiers & Qt.ControlModifier) {
if (event.key === Qt.Key_Backspace) {
passwordBar.clear();
}
}
2020-08-31 01:38:46 +00:00
}
RectangularGlow {
anchors.topMargin: 1
2021-04-11 04:26:30 +00:00
anchors.fill: passwordBar
cached: true
glowRadius: 4
spread: 0.2
color: keypadRoot.dropShadowColor
opacity: (Math.sin(2*((Math.PI / 2) * keypadRoot.swipeProgress + 1.5 * Math.PI)) + 1)
}
2021-04-11 04:26:30 +00:00
// pin display and bar
PasswordBar {
id: passwordBar
2020-11-21 19:49:08 +00:00
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
color: keypadRoot.headerBackgroundColor
opacity: (Math.sin(2*((Math.PI / 2) * keypadRoot.swipeProgress + 1.5 * Math.PI)) + 1)
2021-04-11 04:26:30 +00:00
keypadOpen: swipeProgress === 1
password: root.password
2021-04-11 15:46:50 +00:00
previewCharIndex: -2
pinLabel: qsTr("Enter PIN")
onPasswordChanged: keypadRoot.passwordChanged()
2021-04-11 15:46:50 +00:00
onChangePassword: root.password = password
Binding {
target: passwordBar
property: "password"
value: root.password
}
}
2021-04-11 04:26:30 +00:00
// actual number keys
ColumnLayout {
2021-04-11 04:26:30 +00:00
visible: opacity > 0
opacity: passwordBar.isPinMode ? 1 : 0
Behavior on opacity {
NumberAnimation {
duration: Kirigami.Units.longDuration
easing.type: Easing.InOutQuad
2020-11-21 19:49:08 +00:00
}
}
2021-04-11 04:26:30 +00:00
2020-08-31 01:38:46 +00:00
anchors {
left: parent.left
right: parent.right
2021-04-11 04:26:30 +00:00
top: passwordBar.bottom
2020-08-31 01:38:46 +00:00
bottom: parent.bottom
2021-09-13 16:40:56 +00:00
topMargin: PlasmaCore.Units.gridUnit
bottomMargin: PlasmaCore.Units.gridUnit
2020-08-31 01:38:46 +00:00
}
2021-09-13 16:40:56 +00:00
spacing: PlasmaCore.Units.gridUnit
2020-08-31 01:38:46 +00:00
GridLayout {
property string thePw
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
2021-09-13 16:40:56 +00:00
Layout.leftMargin: PlasmaCore.Units.gridUnit * 0.5
Layout.rightMargin: PlasmaCore.Units.gridUnit * 0.5
Layout.maximumWidth: PlasmaCore.Units.gridUnit * 22
Layout.maximumHeight: PlasmaCore.Units.gridUnit * 12.5
2020-08-31 01:38:46 +00:00
columns: 4
2020-08-31 01:38:46 +00:00
// numpad keys
Repeater {
model: ["1", "2", "3", "R", "4", "5", "6", "0", "7", "8", "9", "E"]
2020-08-31 01:38:46 +00:00
delegate: Item {
Layout.fillWidth: true
Layout.fillHeight: true
RectangularGlow {
anchors.topMargin: 1
anchors.fill: keyRect
cornerRadius: keyRect.radius * 2
cached: true
glowRadius: 2
spread: 0.2
color: keypadRoot.dropShadowColor
opacity: (Math.sin(2*((Math.PI / 2) * keypadRoot.swipeProgress + 1.5 * Math.PI)) + 1)
}
2020-08-31 01:38:46 +00:00
Rectangle {
id: keyRect
anchors.centerIn: parent
width: parent.width
height: parent.height
radius: 5
2020-11-21 19:49:08 +00:00
color: keypadRoot.buttonColor
2020-08-31 01:38:46 +00:00
visible: modelData.length > 0
2020-11-21 19:49:08 +00:00
opacity: (Math.sin(2*((Math.PI / 2) * keypadRoot.swipeProgress + 1.5 * Math.PI)) + 1)
2020-08-31 01:38:46 +00:00
2020-11-13 15:24:01 +00:00
AbstractButton {
2020-08-31 01:38:46 +00:00
anchors.fill: parent
2020-11-20 09:58:43 +00:00
onPressedChanged: {
2020-11-21 19:49:08 +00:00
if (pressed) {
parent.color = keypadRoot.buttonPressedColor;
} else {
parent.color = keypadRoot.buttonColor;
}
2020-11-20 09:58:43 +00:00
}
2020-08-31 01:38:46 +00:00
onClicked: {
if (modelData === "R") {
2021-04-11 15:46:50 +00:00
passwordBar.backspace();
2020-08-31 01:38:46 +00:00
} else if (modelData === "E") {
2021-04-11 15:46:50 +00:00
passwordBar.enter();
2020-08-31 01:38:46 +00:00
} else {
2021-04-11 15:46:50 +00:00
passwordBar.keyPress(modelData);
2020-08-31 01:38:46 +00:00
}
}
onPressAndHold: {
if (modelData === "R") {
2021-04-11 15:46:50 +00:00
passwordBar.clear();
}
}
2020-08-31 01:38:46 +00:00
}
}
2020-08-31 01:38:46 +00:00
PlasmaComponents.Label {
visible: modelData !== "R" && modelData !== "E"
text: modelData
anchors.centerIn: parent
font.pointSize: 18
font.weight: Font.Light
2020-11-21 19:49:08 +00:00
color: keypadRoot.buttonTextColor
2020-08-31 01:38:46 +00:00
}
PlasmaCore.IconItem {
visible: modelData === "R"
anchors.centerIn: parent
source: "edit-clear"
}
PlasmaCore.IconItem {
visible: modelData === "E"
anchors.centerIn: parent
source: "go-next"
}
}
}
}
}
}