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

268 lines
8.3 KiB
QML
Raw Normal View History

2020-02-01 14:21:24 +00:00
/*
2021-03-01 20:03:25 +00:00
SPDX-FileCopyrightText: 2019 Nicolas Fella <nicolas.fella@gmx.de>
2021-03-01 20:03:25 +00:00
SPDX-License-Identifier: GPL-2.0-or-later
2020-02-01 14:21:24 +00:00
*/
2014-08-20 10:10:58 +00:00
2020-02-01 17:08:06 +00:00
import QtQuick 2.12
2016-02-24 19:15:15 +00:00
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
2020-02-01 14:21:24 +00:00
import QtGraphicalEffects 1.12
import org.kde.plasma.components 2.0 as PlasmaComponents
2016-02-24 19:15:15 +00:00
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.workspace.keyboardlayout 1.0
2020-08-31 01:38:46 +00:00
import org.kde.notificationmanager 1.1 as Notifications
2016-02-24 19:15:15 +00:00
import "../components"
2014-08-20 10:10:58 +00:00
PlasmaCore.ColorScope {
2020-02-01 14:21:24 +00:00
id: root
property string password
2020-08-31 01:38:46 +00:00
property bool isWidescreen: root.height < root.width * 0.75
property bool notificationsShown: phoneNotificationsList.count !== 0
2020-02-01 14:21:24 +00:00
property bool is24HourTime: Qt.locale().timeFormat(Locale.ShortFormat).toLowerCase().indexOf("ap") === -1
colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
anchors.fill: parent
2020-08-31 01:38:46 +00:00
function isPinDrawerOpen() {
return passwordFlickable.contentY === passwordFlickable.columnHeight;
}
function askPassword() {
showPasswordAnim.restart();
}
NumberAnimation {
id: showPasswordAnim
target: passwordFlickable
property: "contentY"
from: 0
to: passwordFlickable.contentHeight - passwordFlickable.height
duration: units.longDuration
easing.type: Easing.InOutQuad
}
2020-08-31 01:38:46 +00:00
// blur background once keypad is open
FastBlur {
id: blur
cached: true
2020-02-01 14:21:24 +00:00
anchors.fill: parent
source: wallpaper
radius: 50
opacity: 0
2020-08-31 01:38:46 +00:00
property bool doBlur: notificationsShown || isPinDrawerOpen() // only blur once animation finished for performance
Behavior on doBlur {
NumberAnimation {
target: blur
property: "opacity"
2020-08-31 01:38:46 +00:00
duration: 1000
to: blur.doBlur ? 0 : 1
2020-08-31 01:38:46 +00:00
easing.type: Easing.InOutQuad
}
}
}
Notifications.WatchedNotificationsModel {
id: notifModel
}
// header bar
SimpleHeaderBar {
anchors {
top: parent.top
left: parent.left
right: parent.right
}
height: units.gridUnit
opacity: 1 - (passwordFlickable.contentY / passwordFlickable.columnHeight)
}
2020-08-31 01:38:46 +00:00
// phone clock component
ColumnLayout {
id: phoneClockComponent
visible: !isWidescreen
z: passwordFlickable.contentY === 0 ? 5 : 0 // in front of password flickable when closed
2020-08-31 01:38:46 +00:00
anchors {
top: parent.top
topMargin: root.height / 2 - (height / 2 + units.gridUnit * 2)
left: parent.left
right: parent.right
}
spacing: 0
opacity: 1 - (passwordFlickable.contentY / passwordFlickable.columnHeight)
2020-08-31 01:38:46 +00:00
states: State {
name: "notification"; when: notificationsShown
PropertyChanges { target: phoneClockComponent; anchors.topMargin: units.gridUnit * 5 }
}
transitions: Transition {
NumberAnimation {
properties: "anchors.topMargin"
easing.type: Easing.InOutQuad
}
}
Clock {
id: phoneClock
alignment: Qt.AlignHCenter
Layout.bottomMargin: units.gridUnit * 2 // keep spacing even if media controls are gone
}
MediaControls {
Layout.alignment: Qt.AlignHCenter
Layout.fillWidth: true
Layout.maximumWidth: units.gridUnit * 25
Layout.minimumWidth: units.gridUnit * 15
Layout.leftMargin: units.gridUnit
Layout.rightMargin: units.gridUnit
}
}
2020-08-31 01:38:46 +00:00
// tablet clock component
Item {
id: tabletClockComponent
visible: isWidescreen
width: parent.width / 2
anchors {
2020-08-31 01:38:46 +00:00
top: parent.top
bottom: parent.bottom
left: parent.left
leftMargin: units.gridUnit * 3
}
z: passwordFlickable.contentY === 0 ? 5 : 0 // in front of password flickable when closed
2020-08-31 01:38:46 +00:00
ColumnLayout {
id: tabletLayout
anchors.centerIn: parent
spacing: units.gridUnit
opacity: 1 - (passwordFlickable.contentY / passwordFlickable.columnHeight)
Clock {
id: tabletClock
alignment: Qt.AlignLeft
Layout.fillWidth: true
Layout.minimumWidth: units.gridUnit * 20
}
MediaControls {
Layout.alignment: Qt.AlignLeft
Layout.fillWidth: true
Layout.maximumWidth: units.gridUnit * 25
Layout.minimumWidth: units.gridUnit * 20
}
}
}
// phone notifications list
NotificationsList {
id: phoneNotificationsList
visible: !isWidescreen
z: passwordFlickable.contentY === 0 ? 5 : 0 // prevent mousearea from interfering with pin drawer
anchors {
top: phoneClockComponent.bottom
topMargin: units.gridUnit
bottom: scrollUpIcon.top
bottomMargin: units.gridUnit
left: parent.left
right: parent.right
}
}
2020-08-31 01:38:46 +00:00
// tablet notifications list
ColumnLayout {
visible: isWidescreen
z: passwordFlickable.contentY === 0 ? 5 : 0 // prevent mousearea from interfering with pin drawer
anchors {
top: parent.top
bottom: parent.bottom
left: tabletClockComponent.right
right: parent.right
rightMargin: units.gridUnit
}
NotificationsList {
Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
Layout.fillWidth: true
Layout.minimumHeight: this.notificationListHeight
Layout.minimumWidth: units.gridUnit * 15
Layout.maximumWidth: units.gridUnit * 25
}
}
// scroll up icon
PlasmaCore.IconItem {
2020-08-31 01:38:46 +00:00
id: scrollUpIcon
anchors.bottom: parent.bottom
anchors.bottomMargin: units.gridUnit + passwordFlickable.contentY * 0.5
anchors.horizontalCenter: parent.horizontalCenter
opacity: 1 - (passwordFlickable.contentY / passwordFlickable.columnHeight)
colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
source: "arrow-up"
2014-08-20 10:10:58 +00:00
}
Flickable {
id: passwordFlickable
anchors.fill: parent
property int columnHeight: units.gridUnit * 20
height: columnHeight + root.height
contentHeight: columnHeight + root.height
boundsBehavior: Flickable.StopAtBounds
// always snap to end (either hidden or shown)
2020-10-18 12:57:47 +00:00
onMovementEnded: {
if (!atYBeginning && !atYEnd) {
if (contentY > columnHeight - contentY) {
flick(0, -1000);
} else {
flick(0, 1000);
}
}
}
// wipe password if it is more than half way down the screen
onContentYChanged: {
2020-08-31 01:38:46 +00:00
if (contentY < columnHeight / 2) {
keypad.reset();
2020-08-31 01:38:46 +00:00
}
2020-02-01 14:21:24 +00:00
}
ColumnLayout {
id: passwordLayout
anchors.bottom: parent.bottom
width: parent.width
2020-08-31 01:38:46 +00:00
spacing: units.gridUnit
2020-08-31 01:38:46 +00:00
// scroll down icon
PlasmaCore.IconItem {
Layout.alignment: Qt.AlignHCenter
2020-08-31 01:38:46 +00:00
colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
source: "arrow-down"
2020-11-21 19:49:08 +00:00
opacity: Math.sin((Math.PI / 2) * (passwordFlickable.contentY / passwordFlickable.columnHeight) + 1.5 * Math.PI) + 1
}
2014-08-19 15:50:59 +00:00
2020-08-31 01:38:46 +00:00
Keypad {
id: keypad
focus: passwordFlickable.contentY === passwordFlickable.columnHeight
2020-11-21 19:49:08 +00:00
swipeProgress: passwordFlickable.contentY / passwordFlickable.columnHeight
2020-02-01 14:21:24 +00:00
Layout.fillWidth: true
2020-08-31 01:38:46 +00:00
Layout.minimumHeight: units.gridUnit * 17
Layout.maximumWidth: root.width
}
2014-08-28 13:21:53 +00:00
}
}
LockOsd {
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
anchors.topMargin: PlasmaCore.Units.largeSpacing
}
2014-08-28 13:21:53 +00:00
}