From 56a80f3822a5b354b5bf35b82b532d3d35ca1006 Mon Sep 17 00:00:00 2001 From: reionwong Date: Tue, 27 Jul 2021 22:44:07 +0800 Subject: [PATCH] Improve more details --- .gitignore | 2 + screenlocker/CMakeLists.txt | 8 +- screenlocker/application.h | 2 +- screenlocker/qml.qrc | 1 - screenlocker/qml/Greeter.qml | 5 - screenlocker/qml/LockScreen.qml | 268 +++++++++++++++++++++++++++----- 6 files changed, 235 insertions(+), 51 deletions(-) delete mode 100644 screenlocker/qml/Greeter.qml diff --git a/.gitignore b/.gitignore index f147edf..6f50db9 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,5 @@ compile_commands.json # QtCreator local machine specific files for imported projects *creator.user* + +/build/* diff --git a/screenlocker/CMakeLists.txt b/screenlocker/CMakeLists.txt index 2e609d0..46943fa 100644 --- a/screenlocker/CMakeLists.txt +++ b/screenlocker/CMakeLists.txt @@ -12,11 +12,11 @@ set(PROJECT_SOURCES qml.qrc ) -add_executable(screenlocker +add_executable(cutefish-screenlocker ${PROJECT_SOURCES} ) -target_link_libraries(screenlocker +target_link_libraries(cutefish-screenlocker PRIVATE Qt5::Core Qt5::DBus @@ -25,4 +25,6 @@ target_link_libraries(screenlocker Qt5::Quick ${X11_LIBRARIES} -) \ No newline at end of file +) + +install(TARGETS cutefish-screenlocker RUNTIME DESTINATION /usr/bin) \ No newline at end of file diff --git a/screenlocker/application.h b/screenlocker/application.h index 5dc6bd5..8369af1 100644 --- a/screenlocker/application.h +++ b/screenlocker/application.h @@ -38,7 +38,7 @@ private: QList m_views; org_kde_ksld *m_ksldInterface = nullptr; - bool m_testing = true; + bool m_testing = false; }; #endif // APPLICATION_H diff --git a/screenlocker/qml.qrc b/screenlocker/qml.qrc index 081bbed..57b629b 100644 --- a/screenlocker/qml.qrc +++ b/screenlocker/qml.qrc @@ -1,6 +1,5 @@ qml/LockScreen.qml - qml/Greeter.qml diff --git a/screenlocker/qml/Greeter.qml b/screenlocker/qml/Greeter.qml deleted file mode 100644 index 9c36e13..0000000 --- a/screenlocker/qml/Greeter.qml +++ /dev/null @@ -1,5 +0,0 @@ -import QtQuick 2.0 - -Item { - -} diff --git a/screenlocker/qml/LockScreen.qml b/screenlocker/qml/LockScreen.qml index 11af041..1b0d296 100644 --- a/screenlocker/qml/LockScreen.qml +++ b/screenlocker/qml/LockScreen.qml @@ -1,9 +1,29 @@ -import QtQuick 2.0 +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: Rion Wong + * + * 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 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 import QtGraphicalEffects 1.0 +import Cutefish.Accounts 1.0 as Accounts import FishUI 1.0 as FishUI Item { @@ -11,6 +31,9 @@ Item { property alias notification: message.text + LayoutMirroring.enabled: Qt.locale().textDirection === Qt.RightToLeft + LayoutMirroring.childrenInherit: true + Image { id: wallpaperImage anchors.fill: parent @@ -33,66 +56,226 @@ Item { visible: true } - ColumnLayout { - anchors.fill: parent - spacing: FishUI.Units.largeSpacing * 1.5 + Accounts.UserAccount { + id: currentUser + } - Item { - Layout.fillHeight: true + Timer { + repeat: true + running: true + interval: 1000 + + onTriggered: { + timeLabel.updateInfo() + dateLabel.updateInfo() } + } + + Component.onCompleted: { + timeLabel.updateInfo() + dateLabel.updateInfo() + } + + Item { + id: _topItem + anchors.left: parent.left + anchors.right: parent.right + anchors.top: parent.top + anchors.bottom: _mainItem.top + anchors.bottomMargin: root.height * 0.1 Label { + id: timeLabel + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter Layout.alignment: Qt.AlignHCenter - text: "cutefish" + font.pointSize: 35 color: "white" - } - TextField { - id: password - Layout.alignment: Qt.AlignHCenter - Layout.preferredHeight: 40 - Layout.preferredWidth: 240 - placeholderText: qsTr("Password") - focus: true + function updateInfo() { + timeLabel.text = new Date().toLocaleString(Qt.locale(), "hh:mm") + } + } - echoMode: TextInput.Password + Label { + id: dateLabel + anchors.top: timeLabel.bottom + anchors.topMargin: FishUI.Units.largeSpacing + anchors.horizontalCenter: parent.horizontalCenter + font.pointSize: 19 + color: "white" - background: Rectangle { - color: "white" - opacity: 0.4 - radius: FishUI.Theme.bigRadius + function updateInfo() { + dateLabel.text = new Date().toLocaleDateString(Qt.locale(), Locale.LongFormat) } + } - Keys.onEnterPressed: authenticator.tryUnlock(password.text) - Keys.onReturnPressed: authenticator.tryUnlock(password.text) - Keys.onEscapePressed: password.text = "" + DropShadow { + anchors.fill: timeLabel + source: timeLabel + z: -1 + horizontalOffset: 1 + verticalOffset: 1 + radius: 10 + samples: radius * 4 + spread: 0.35 + color: Qt.rgba(0, 0, 0, 0.8) + opacity: 0.1 + visible: true } - Button { - Layout.alignment: Qt.AlignHCenter - Layout.preferredHeight: 40 - Layout.preferredWidth: 240 - text: qsTr("Unlock") - onClicked: authenticator.tryUnlock(password.text) + DropShadow { + anchors.fill: dateLabel + source: dateLabel + z: -1 + horizontalOffset: 1 + verticalOffset: 1 + radius: 10 + samples: radius * 4 + spread: 0.35 + color: Qt.rgba(0, 0, 0, 0.8) + opacity: 0.1 + visible: true } + } - Label { - id: message - text: "" - Layout.alignment: Qt.AlignHCenter - font.bold: true - color: "white" - Behavior on opacity { - NumberAnimation { - duration: 250 + Item { + id: _mainItem + anchors.centerIn: parent + width: 260 + FishUI.Units.largeSpacing * 3 + height: _mainLayout.implicitHeight + FishUI.Units.largeSpacing * 4 + + Layout.alignment: Qt.AlignHCenter + + Rectangle { + anchors.fill: parent + radius: FishUI.Theme.bigRadius + 2 + color: FishUI.Theme.darkMode ? "#424242" : "white" + opacity: 0.5 + } + + ColumnLayout { + id: _mainLayout + anchors.fill: parent + anchors.margins: FishUI.Units.largeSpacing * 1.5 + spacing: FishUI.Units.smallSpacing + + Image { + id: userIcon + + property int iconSize: 60 + + Layout.preferredHeight: iconSize + Layout.preferredWidth: iconSize + sourceSize: Qt.size(iconSize, iconSize) + source: currentUser.iconFileName ? "file:///" + currentUser.iconFileName : "image://icontheme/default-user" + Layout.alignment: Qt.AlignHCenter + + layer.enabled: true + layer.effect: OpacityMask { + maskSource: Item { + width: userIcon.width + height: userIcon.height + + Rectangle { + anchors.fill: parent + radius: parent.height / 2 + } + } } } - opacity: text == "" ? 0 : 1 + + Label { + Layout.alignment: Qt.AlignHCenter + text: currentUser.userName + } + + Item { + height: 1 + } + + TextField { + id: password + Layout.alignment: Qt.AlignHCenter + Layout.preferredHeight: 40 + Layout.preferredWidth: 260 + placeholderText: qsTr("Password") + focus: true + + echoMode: TextInput.Password + + background: Rectangle { + color: FishUI.Theme.darkMode ? "#7B7B7B" : "white" + radius: FishUI.Theme.bigRadius + opacity: 0.5 + } + + Keys.onEnterPressed: root.tryUnlock() + Keys.onReturnPressed: root.tryUnlock() + Keys.onEscapePressed: password.text = "" + } + + Button { + id: unlockBtn + hoverEnabled: true + focusPolicy: Qt.NoFocus + Layout.alignment: Qt.AlignHCenter + Layout.preferredHeight: 40 + Layout.preferredWidth: 260 + text: qsTr("Unlock") + onClicked: root.tryUnlock() + + scale: unlockBtn.pressed ? 0.95 : 1.0 + + Behavior on scale { + NumberAnimation { + duration: 100 + } + } + +// contentItem: Text { +// text: unlockBtn.text +// font: unlockBtn.font +// horizontalAlignment: Text.AlignHCenter +// verticalAlignment: Text.AlignVCenter +// elide: Text.ElideRight +// color: "#1C1C1C" +// } + + background: Rectangle { + color: FishUI.Theme.darkMode ? "#7B7B7B" : "white" + opacity: unlockBtn.pressed ? 0.3 : unlockBtn.hovered ? 0.4 : 0.5 + radius: FishUI.Theme.bigRadius + } + } + } + } + + Label { + id: message + text: "" + anchors.top: _mainItem.bottom + anchors.topMargin: FishUI.Units.largeSpacing + anchors.horizontalCenter: parent.horizontalCenter + font.bold: true + color: "white" + + Behavior on opacity { + NumberAnimation { + duration: 250 + } } - Item { - Layout.fillHeight: true + opacity: text == "" ? 0 : 1 + } + + function tryUnlock() { + if (!password.text) { + root.notification = qsTr("Please enter your password") + return } + + authenticator.tryUnlock(password.text) } Connections { @@ -100,6 +283,7 @@ Item { function onFailed() { root.notification = qsTr("Unlocking failed") } + function onGraceLockedChanged() { if (!authenticator.graceLocked) { root.notification = "" @@ -107,9 +291,11 @@ Item { password.focus = true } } + function onMessage(text) { root.notification = text } + function onError(text) { root.notification = text }