shift-shell/shell/contents/lockscreen/Keypad.qml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

198 lines
6.9 KiB
QML
Raw Normal View History

// SPDX-FileCopyrightText: 2020-2023 Devin Lin <espidev@gmail.com>
// SPDX-License-Identifier: GPL-2.0-or-later
2020-08-31 01:38:46 +00:00
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Effects
import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.plasma.core as PlasmaCore
2020-08-31 01:38:46 +00:00
import org.kde.plasma.workspace.keyboardlayout 1.0
import org.kde.plasma.private.mobileshell as MobileShell
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
required property var lockScreenState
property alias passwordBar: passwordBar
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(Kirigami.Theme.backgroundColor, {"alpha": 0.9*255})
2020-08-31 01:38:46 +00:00
2020-11-21 19:49:08 +00:00
// colour calculations
readonly property color buttonColor: Qt.lighter(Kirigami.Theme.backgroundColor, 1.3)
readonly property color buttonPressedColor: Qt.darker(Kirigami.Theme.backgroundColor, 1.08)
readonly property color buttonTextColor: Kirigami.Theme.textColor
readonly property color dropShadowColor: Qt.darker(Kirigami.Theme.backgroundColor, 1.2)
readonly property color headerBackgroundColor: Qt.lighter(Kirigami.Theme.backgroundColor, 1.3)
2020-11-21 19:49:08 +00:00
opacity: Math.sin((Math.PI / 2) * swipeProgress + 1.5 * Math.PI) + 1
implicitHeight: {
if (passwordBar.isPinMode && !Qt.inputMethod.visible) {
return Kirigami.Units.gridUnit * 17;
} else {
return Math.min(root.height - passwordBar.implicitHeight, // don't make the password bar go off the screen
Kirigami.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
}
}
MobileShell.HapticsEffect {
id: haptics
}
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
2020-11-21 19:49:08 +00:00
color: keypadRoot.headerBackgroundColor
opacity: (Math.sin(2*((Math.PI / 2) * keypadRoot.swipeProgress + 1.5 * Math.PI)) + 1)
lockScreenState: keypadRoot.lockScreenState
2020-11-21 19:49:08 +00:00
2021-04-11 04:26:30 +00:00
keypadOpen: swipeProgress === 1
2021-04-11 15:46:50 +00:00
previewCharIndex: -2
layer.enabled: true
layer.effect: MultiEffect {
blurMax: 16
shadowEnabled: true
shadowVerticalOffset: 1
shadowOpacity: 0.3
shadowColor: keypadRoot.dropShadowColor
}
}
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
2021-04-11 04:26:30 +00:00
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
topMargin: Kirigami.Units.gridUnit
bottomMargin: Kirigami.Units.gridUnit
2020-08-31 01:38:46 +00:00
}
spacing: Kirigami.Units.gridUnit
2020-08-31 01:38:46 +00:00
GridLayout {
id: grid
2020-08-31 01:38:46 +00:00
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Layout.leftMargin: Kirigami.Units.gridUnit * 0.5
Layout.rightMargin: Kirigami.Units.gridUnit * 0.5
Layout.maximumWidth: Kirigami.Units.gridUnit * 22
Layout.maximumHeight: Kirigami.Units.gridUnit * 12.5
opacity: (Math.sin(2*((Math.PI / 2) * keypadRoot.swipeProgress + 1.5 * Math.PI)) + 1)
2020-08-31 01:38:46 +00:00
columns: 4
readonly property real keyRadius: 5
2020-08-31 01:38:46 +00:00
// numpad keys
Repeater {
model: ["1", "2", "3", "R", "4", "5", "6", "0", "7", "8", "9", "E"]
delegate: AbstractButton {
id: button
2020-08-31 01:38:46 +00:00
Layout.fillWidth: true
Layout.fillHeight: true
visible: modelData.length > 0
opacity: (Math.sin(2*((Math.PI / 2) * keypadRoot.swipeProgress + 1.5 * Math.PI)) + 1)
background: Rectangle {
2020-08-31 01:38:46 +00:00
id: keyRect
radius: grid.keyRadius
color: button.pressed ? keypadRoot.buttonPressedColor : keypadRoot.buttonColor
}
layer.enabled: true
layer.effect: MultiEffect {
blurMax: 16
shadowEnabled: true
shadowVerticalOffset: 1
shadowOpacity: 0.3
shadowColor: keypadRoot.dropShadowColor
2020-08-31 01:38:46 +00:00
}
onPressedChanged: {
if (pressed) {
haptics.buttonVibrate();
}
2020-08-31 01:38:46 +00:00
}
onClicked: {
if (modelData === "R") {
passwordBar.backspace();
} else if (modelData === "E") {
passwordBar.enter();
} else {
passwordBar.keyPress(modelData);
}
}
onPressAndHold: {
if (modelData === "R") {
haptics.buttonVibrate();
passwordBar.clear();
}
2020-08-31 01:38:46 +00:00
}
contentItem: Item {
PlasmaComponents.Label {
visible: modelData !== "R" && modelData !== "E"
text: modelData
anchors.centerIn: parent
font.pointSize: 18
font.weight: Font.Light
color: keypadRoot.buttonTextColor
}
2020-08-31 01:38:46 +00:00
Kirigami.Icon {
visible: modelData === "R"
anchors.centerIn: parent
2023-10-23 06:42:38 +00:00
width: Kirigami.Units.iconSizes.small
height: Kirigami.Units.iconSizes.small
source: "edit-clear"
}
Kirigami.Icon {
visible: modelData === "E"
anchors.centerIn: parent
2023-10-23 06:42:38 +00:00
width: Kirigami.Units.iconSizes.small
height: Kirigami.Units.iconSizes.small
source: "go-next"
}
2020-08-31 01:38:46 +00:00
}
}
}
}
}
}