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

0001 /*
0002  * SPDX-FileCopyrightText: 2019 Nicolas Fella <nicolas.fella@gmx.de>
0003  * SPDX-FileCopyrightText: 2021-2022 Devin Lin <espidev@gmail.com>
0004  * 
0005  * SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 
0008 import QtQuick 2.12
0009 import QtQuick.Controls 2.15
0010 import QtQuick.Layouts 1.15
0011 import QtGraphicalEffects 1.12
0012 
0013 import org.kde.plasma.core 2.0 as PlasmaCore
0014 import org.kde.notificationmanager 1.1 as Notifications
0015 
0016 import org.kde.kirigami 2.12 as Kirigami
0017 
0018 /**
0019  * Lockscreen component that is loaded after the device is locked.
0020  * 
0021  * Special attention must be paid to ensuring the GUI loads as fast as possible.
0022  */
0023 PlasmaCore.ColorScope {
0024     id: root
0025 
0026     property var lockScreenState: LockScreenState {}
0027     property var notifModel: Notifications.WatchedNotificationsModel {}
0028     
0029     // only show widescreen mode for short height devices (ex. phone landscape)
0030     property bool isWidescreen: root.height < 720 && (root.height < root.width * 0.75)
0031     property bool notificationsShown: false
0032     
0033     readonly property bool drawerOpen: flickable.openFactor >= 1
0034     property var passwordBar: keypadLoader.item.passwordBar
0035     
0036     colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
0037     anchors.fill: parent
0038     
0039     // listen for keyboard events, and focus on input area
0040     Component.onCompleted: forceActiveFocus();
0041     Keys.onPressed: {
0042         passwordBar.isPinMode = false;
0043         flickable.goToOpenPosition();
0044         passwordBar.textField.forceActiveFocus();
0045     }
0046 
0047     // wallpaper blur
0048     Loader {
0049         anchors.fill: parent
0050         asynchronous: true
0051         sourceComponent: WallpaperBlur {
0052             source: wallpaper
0053             blur: root.notificationsShown || root.drawerOpen // only blur once animation finished for performance
0054         }
0055     }
0056     
0057     // header bar and action drawer
0058     HeaderComponent {
0059         id: headerBar
0060         z: 1 // on top of flick area
0061         anchors.fill: parent
0062         
0063         openFactor: flickable.openFactor
0064         notificationsModel: root.notifModel
0065         onPasswordRequested: root.askPassword()
0066     }
0067     
0068     Connections {
0069         target: root.lockScreenState
0070         
0071         // ensure keypad is opened when password is updated (ex. keyboard)
0072         function onPasswordChanged() {
0073             flickable.goToOpenPosition()
0074         }
0075     }
0076 
0077     FlickContainer {
0078         id: flickable
0079         anchors.fill: parent
0080         
0081         property real openFactor: position / keypadHeight
0082         
0083         onOpened: {
0084             if (root.lockScreenState.passwordless) {
0085                 // try unlocking if flicked to the top, and we have passwordless login
0086                 root.lockScreenState.tryPassword();
0087             }
0088         }
0089         
0090         keypadHeight: PlasmaCore.Units.gridUnit * 20
0091         
0092         // go to closed position when loaded
0093         Component.onCompleted: {
0094             flickable.position = 0;
0095             flickable.goToClosePosition();
0096         }
0097         
0098         // update position, and cap it at the keypad height
0099         onPositionChanged: {
0100             if (position > keypadHeight) {
0101                 position = keypadHeight;
0102             } else if (position < 0) {
0103                 position = 0;
0104             }
0105         }
0106         
0107         Item {
0108             width: flickable.width
0109             height: flickable.height
0110             y: flickable.contentY // effectively anchored to the screen
0111             
0112             LockScreenNarrowContent {
0113                 id: phoneComponent
0114                 
0115                 visible: !isWidescreen
0116                 active: visible
0117                 opacity: 1 - flickable.openFactor
0118                 
0119                 fullHeight: root.height
0120                 
0121                 lockScreenState: root.lockScreenState
0122                 notificationsModel: root.notifModel
0123                 onNotificationsShownChanged: root.notificationsShown = notificationsShown
0124                 
0125                 onPasswordRequested: flickable.goToOpenPosition()
0126                 
0127                 anchors.top: parent.top
0128                 anchors.bottom: scrollUpIconLoader.top
0129                 anchors.left: parent.left
0130                 anchors.right: parent.right
0131                 
0132                 // move while swiping up
0133                 transform: Translate { y: Math.round((1 - phoneComponent.opacity) * (-root.height / 6)) }
0134             }
0135             
0136             LockScreenWideScreenContent {
0137                 id: tabletComponent
0138                 
0139                 visible: isWidescreen
0140                 active: visible
0141                 opacity: 1 - flickable.openFactor
0142                 
0143                 lockScreenState: root.lockScreenState
0144                 notificationsModel: root.notifModel
0145                 onNotificationsShownChanged: root.notificationsShown = notificationsShown
0146                 
0147                 onPasswordRequested: flickable.goToOpenPosition()
0148                 
0149                 anchors.topMargin: headerBar.statusBarHeight
0150                 anchors.top: parent.top
0151                 anchors.bottom: scrollUpIconLoader.top
0152                 anchors.left: parent.left
0153                 anchors.right: parent.right
0154                 
0155                 // move while swiping up
0156                 transform: Translate { y: Math.round((1 - phoneComponent.opacity) * (-root.height / 6)) }
0157             }
0158             
0159             // scroll up icon
0160             Loader {
0161                 id: scrollUpIconLoader
0162                 asynchronous: true
0163                 
0164                 anchors.bottom: parent.bottom
0165                 anchors.bottomMargin: PlasmaCore.Units.gridUnit + flickable.position * 0.5
0166                 anchors.horizontalCenter: parent.horizontalCenter
0167                 
0168                 sourceComponent: PlasmaCore.IconItem {
0169                     id: scrollUpIcon
0170                     implicitWidth: PlasmaCore.Units.iconSizes.smallMedium
0171                     implicitHeight: PlasmaCore.Units.iconSizes.smallMedium 
0172                     opacity: 1 - flickable.openFactor
0173                     
0174                     colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
0175                     source: "arrow-up"
0176                 }
0177             }
0178             
0179             // password keypad
0180             Loader {
0181                 id: keypadLoader
0182                 width: parent.width
0183                 asynchronous: true
0184                 active: !root.lockScreenState.passwordless // only load keypad if not passwordless
0185                 
0186                 anchors.bottom: parent.bottom
0187                 
0188                 sourceComponent: ColumnLayout {
0189                     property alias passwordBar: keypad.passwordBar
0190                     
0191                     transform: Translate { y: flickable.keypadHeight - flickable.position }
0192                     spacing: 0
0193                     
0194                     // info notification text
0195                     Label {
0196                         Layout.fillWidth: true
0197                         Layout.rightMargin: Kirigami.Units.largeSpacing
0198                         Layout.leftMargin: Kirigami.Units.largeSpacing
0199                         Layout.bottomMargin: PlasmaCore.Units.smallSpacing * 2
0200                         font.pointSize: 9
0201                         
0202                         elide: Text.ElideRight
0203                         horizontalAlignment: Text.AlignHCenter
0204                         text: root.lockScreenState.info
0205                         opacity: (root.lockScreenState.info.length === 0 || flickable.openFactor < 1) ? 0 : 1
0206                         color: 'white'
0207                         
0208                         Behavior on opacity {
0209                             NumberAnimation { duration: 200 }
0210                         }
0211                     }
0212                     
0213                     // scroll down icon
0214                     PlasmaCore.IconItem {
0215                         Layout.alignment: Qt.AlignHCenter
0216                         Layout.bottomMargin: PlasmaCore.Units.gridUnit
0217                         implicitWidth: PlasmaCore.Units.iconSizes.smallMedium
0218                         implicitHeight: PlasmaCore.Units.iconSizes.smallMedium
0219                         colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
0220                         source: "arrow-down"
0221                         opacity: Math.sin((Math.PI / 2) * flickable.openFactor + 1.5 * Math.PI) + 1
0222                     }
0223 
0224                     Keypad {
0225                         id: keypad
0226                         Layout.fillWidth: true
0227                         focus: true
0228                         
0229                         lockScreenState: root.lockScreenState
0230                         swipeProgress: flickable.openFactor
0231                     }
0232                 }
0233             }
0234         }
0235     }
0236 }