Warning, /plasma/plasma-mobile/look-and-feel/contents/lockscreen/Keypad.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * SPDX-FileCopyrightText: 2020-2022 Devin Lin <espidev@gmail.com>
0003  * 
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 import QtQuick 2.12
0008 import QtQuick.Controls 2.1
0009 import QtQuick.Layouts 1.1
0010 import QtGraphicalEffects 1.12
0011 
0012 import org.kde.plasma.components 3.0 as PlasmaComponents
0013 import org.kde.plasma.core 2.0 as PlasmaCore
0014 import org.kde.plasma.workspace.keyboardlayout 1.0
0015 import org.kde.plasma.private.mobileshell 1.0 as MobileShell
0016 
0017 import org.kde.kirigami 2.12 as Kirigami
0018 
0019 Rectangle {
0020     id: keypadRoot
0021     
0022     required property var lockScreenState
0023     
0024     property alias passwordBar: passwordBar
0025     
0026     // 0 - keypad is not shown, 1 - keypad is shown
0027     property double swipeProgress
0028     
0029     // slightly translucent background, for key contrast
0030     color: Kirigami.ColorUtils.adjustColor(PlasmaCore.Theme.backgroundColor, {"alpha": 0.9*255})
0031     
0032     // colour calculations
0033     readonly property color buttonColor: Qt.lighter(PlasmaCore.Theme.backgroundColor, 1.3)
0034     readonly property color buttonPressedColor: Qt.darker(PlasmaCore.Theme.backgroundColor, 1.08)
0035     readonly property color buttonTextColor: PlasmaCore.Theme.textColor
0036     readonly property color dropShadowColor: Qt.darker(PlasmaCore.Theme.backgroundColor, 1.2)
0037     readonly property color headerBackgroundColor: Qt.lighter(PlasmaCore.Theme.backgroundColor, 1.3)
0038     
0039     opacity: Math.sin((Math.PI / 2) * swipeProgress + 1.5 * Math.PI) + 1
0040     
0041     implicitHeight: {
0042         if (passwordBar.isPinMode && !Qt.inputMethod.visible) {
0043             return PlasmaCore.Units.gridUnit * 17;
0044         } else {
0045             return Math.min(root.height - passwordBar.implicitHeight, // don't make the password bar go off the screen
0046                             PlasmaCore.Units.smallSpacing * 2 + Qt.inputMethod.keyboardRectangle.height + passwordBar.implicitHeight);
0047         }
0048     }
0049     
0050     Behavior on implicitHeight {
0051         NumberAnimation {
0052             duration: Kirigami.Units.longDuration
0053             easing.type: Easing.InOutQuad
0054         }
0055     }
0056 
0057     MobileShell.HapticsEffectLoader {
0058         id: haptics
0059     }
0060     
0061     RectangularGlow {
0062         anchors.topMargin: 1
0063         anchors.fill: passwordBar
0064         cached: true
0065         glowRadius: 4
0066         spread: 0.2
0067         color: keypadRoot.dropShadowColor
0068         opacity: (Math.sin(2*((Math.PI / 2) * keypadRoot.swipeProgress + 1.5 * Math.PI)) + 1)
0069     }
0070     
0071     // pin display and bar
0072     PasswordBar {
0073         id: passwordBar
0074         
0075         anchors.top: parent.top
0076         anchors.left: parent.left
0077         anchors.right: parent.right
0078         
0079         color: keypadRoot.headerBackgroundColor
0080         opacity: (Math.sin(2*((Math.PI / 2) * keypadRoot.swipeProgress + 1.5 * Math.PI)) + 1)
0081 
0082         lockScreenState: keypadRoot.lockScreenState
0083         
0084         keypadOpen: swipeProgress === 1
0085         previewCharIndex: -2
0086     }
0087     
0088     // actual number keys
0089     ColumnLayout {
0090         visible: opacity > 0
0091         opacity: passwordBar.isPinMode ? 1 : 0
0092         
0093         Behavior on opacity {
0094             NumberAnimation {
0095                 duration: Kirigami.Units.longDuration
0096                 easing.type: Easing.InOutQuad
0097             }
0098         }
0099         
0100         anchors {
0101             left: parent.left
0102             right: parent.right
0103             top: passwordBar.bottom
0104             bottom: parent.bottom
0105             topMargin: PlasmaCore.Units.gridUnit
0106             bottomMargin: PlasmaCore.Units.gridUnit
0107         }
0108         spacing: PlasmaCore.Units.gridUnit
0109 
0110         GridLayout {
0111             id: grid
0112             Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
0113             Layout.leftMargin: PlasmaCore.Units.gridUnit * 0.5
0114             Layout.rightMargin: PlasmaCore.Units.gridUnit * 0.5
0115             Layout.maximumWidth: PlasmaCore.Units.gridUnit * 22
0116             Layout.maximumHeight: PlasmaCore.Units.gridUnit * 12.5
0117             opacity: (Math.sin(2*((Math.PI / 2) * keypadRoot.swipeProgress + 1.5 * Math.PI)) + 1)
0118             
0119             columns: 4
0120             
0121             readonly property real keyRadius: 5
0122             
0123             // numpad keys
0124             Repeater {
0125                 model: ["1", "2", "3", "R", "4", "5", "6", "0", "7", "8", "9", "E"]
0126 
0127                 delegate: AbstractButton {
0128                     id: button
0129                     Layout.fillWidth: true
0130                     Layout.fillHeight: true
0131                     visible: modelData.length > 0
0132                     opacity: (Math.sin(2*((Math.PI / 2) * keypadRoot.swipeProgress + 1.5 * Math.PI)) + 1)
0133 
0134                     background: Rectangle {
0135                         id: keyRect
0136                         radius: grid.keyRadius
0137                         color: button.pressed ? keypadRoot.buttonPressedColor : keypadRoot.buttonColor
0138                         
0139                         RectangularGlow {
0140                             anchors.topMargin: 1
0141                             anchors.fill: parent
0142                             
0143                             z: -1
0144                             cornerRadius: keyRect.radius * 2
0145                             cached: true
0146                             glowRadius: 2
0147                             spread: 0.2
0148                             color: button.pressed ? keypadRoot.buttonPressedColor : keypadRoot.dropShadowColor
0149                         }
0150                     }
0151 
0152                     onPressedChanged: {
0153                         if (pressed) {
0154                             haptics.buttonVibrate();
0155                         }
0156                     }
0157 
0158                     onClicked: {
0159                         if (modelData === "R") {
0160                             passwordBar.backspace();
0161                         } else if (modelData === "E") {
0162                             passwordBar.enter();
0163                         } else {
0164                             passwordBar.keyPress(modelData);
0165                         }
0166                     }
0167                     onPressAndHold: {
0168                         if (modelData === "R") {
0169                             haptics.buttonVibrate();
0170                             passwordBar.clear();
0171                         }
0172                     }
0173                     
0174                     contentItem: Item {
0175                         PlasmaComponents.Label {
0176                             visible: modelData !== "R" && modelData !== "E"
0177                             text: modelData
0178                             anchors.centerIn: parent
0179                             font.pointSize: 18
0180                             font.weight: Font.Light
0181                             color: keypadRoot.buttonTextColor
0182                         }
0183 
0184                         PlasmaCore.IconItem {
0185                             visible: modelData === "R"
0186                             anchors.centerIn: parent
0187                             source: "edit-clear"
0188                         }
0189 
0190                         PlasmaCore.IconItem {
0191                             visible: modelData === "E"
0192                             anchors.centerIn: parent
0193                             source: "go-next"
0194                         }
0195                     }
0196                 }
0197             }
0198         }
0199     }
0200 }