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

265 lines
8.2 KiB
QML
Raw Normal View History

2020-02-01 14:21:24 +00:00
/*
Copyright (C) 2019 Nicolas Fella <nicolas.fella@gmx.de>
2016-02-24 19:15:15 +00:00
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
2014-08-19 12:08:19 +00:00
2016-02-24 19:15:15 +00:00
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
2020-02-01 14:21:24 +00:00
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2016-02-24 19:15:15 +00:00
GNU General Public License for more details.
2014-08-06 11:58:32 +00:00
2016-02-24 19:15:15 +00:00
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
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
colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
anchors.fill: parent
2020-08-31 01:38:46 +00:00
function isPinDrawerOpen() {
return passwordFlickable.contentY === passwordFlickable.columnHeight;
}
// blur background once keypad is open
FastBlur {
id: blur
cached: true
2020-02-01 14:21:24 +00:00
anchors.fill: parent
source: wallpaper
2020-08-31 01:38:46 +00:00
visible: true
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: "radius"
duration: 1000
to: blur.doBlur ? 0 : 50
easing.type: Easing.InOutQuad
}
PropertyAction {
target: blur
property: "visible"
value: blur.doBlur
}
}
}
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
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
z: 5
}
}
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
}
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
z: 5
}
}
}
// 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
leftMargin: units.gridUnit
right: parent.right
rightMargin: units.gridUnit
}
}
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)
onFlickEnded: {
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) {
root.password = "";
2020-08-31 01:38:46 +00:00
keypad.pinLabel = qsTr("Enter PIN");
}
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
opacity: Math.sin((Math.PI / 2) * (passwordFlickable.contentY / passwordFlickable.columnHeight) + 1.5 * Math.PI) + 1
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"
}
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-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
}
}
}