chore: code review for greeter: qml code

Log:
This commit is contained in:
groveer 2024-09-14 10:35:00 +08:00 committed by groveer
parent 60c8861e00
commit 5ca0d30059
12 changed files with 297 additions and 342 deletions

View File

@ -16,10 +16,9 @@ RowLayout {
property var buttonSize: 30
spacing: 15
Rectangle {
Item {
implicitWidth: bottomGroup.buttonSize + 6
implicitHeight: bottomGroup.buttonSize + 6
color: "transparent"
Layout.alignment: Qt.AlignHCenter
visible: userList.count > 1
@ -50,14 +49,15 @@ RowLayout {
userList.open()
}
background: RoundBlur {}
background: RoundBlur {
radius: usersBtn.width / 2
}
}
}
Rectangle {
Item {
implicitWidth: bottomGroup.buttonSize + 6
implicitHeight: bottomGroup.buttonSize + 6
color: "transparent"
Layout.alignment: Qt.AlignHCenter
D.RoundButton {
id: powerBtn
@ -82,7 +82,9 @@ RowLayout {
powerList.open()
}
background: RoundBlur {}
background: RoundBlur {
radius: powerBtn.width / 2
}
}
}
}

View File

@ -37,7 +37,7 @@ FocusScope {
}
}
property var state: LoginAnimation.Show
property int state: LoginAnimation.Show
Loader {
id: leftAnimation
@ -68,7 +68,7 @@ FocusScope {
anchors.fill: parent
onStopped: {
if (state === LoginAnimation.Hide) {
GreeterModel.emitAnimationPlayFinished()
GreeterModel.animationPlayFinished()
}
}
}
@ -88,37 +88,46 @@ FocusScope {
id: leftComp
z: -1
width: parent.width * 0.4
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.leftMargin: 30
anchors.topMargin: 30
anchors.bottomMargin: 30
anchors {
left: parent.left
top: parent.top
bottom: parent.bottom
leftMargin: 30
topMargin: 30
bottomMargin: 30
}
}
Item {
id: rightComp
z: -1
anchors.left: leftComp.right
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.rightMargin: 30
anchors.topMargin: 30
anchors.bottomMargin: 30
anchors {
left: leftComp.right
right: parent.right
top: parent.top
bottom: parent.bottom
leftMargin: 30
rightMargin: 30
topMargin: 30
bottomMargin: 30
}
}
QuickAction {
id: quickAction
anchors.verticalCenter: parent.verticalCenter
anchors.right: leftComp.right
anchors.rightMargin: leftComp.width / 9
anchors {
verticalCenter : parent.verticalCenter
right: leftComp.right
rightMargin: leftComp.width / 9
}
}
Row {
id: logo
anchors.bottom: leftComp.bottom
anchors.left: leftComp.left
anchors {
bottom: leftComp.bottom
left: leftComp.left
}
Image {
id: logoPic
@ -138,19 +147,24 @@ FocusScope {
UserInput {
id: userInput
anchors.verticalCenter: parent.verticalCenter
anchors.left: rightComp.left
anchors.leftMargin: rightComp.width / 5
anchors {
verticalCenter: parent.verticalCenter
left: rightComp.left
leftMargin: rightComp.width / 5
}
focus: true
}
ControlAction {
id: controlAction
anchors.bottom: rightComp.bottom
anchors.right: rightComp.right
anchors {
bottom: rightComp.bottom
right: rightComp.right
}
}
// Delay start animation, Because when the Qt control plays animation during initialization, the effect cannot be seen.
Timer {
id: delayStart
interval: 100
@ -187,7 +201,7 @@ FocusScope {
logoAnimation.item.start({x: logo.x, y: logo.y}, {x: root.x - logo.width, y: logo.y})
rightAnimation.item.start({x: userInput.x, y: userInput.y}, {x: root.width + userInput.width, y: userInput.y})
bottomAnimation.item.start({x: controlAction.x, y: controlAction.y}, {x: controlAction.x, y: controlAction.y + controlAction.height})
GreeterModel.emitAnimationPlayed()
GreeterModel.animationPlayed()
}
break
}

View File

@ -26,14 +26,6 @@ Item {
signal animationPlayed
signal animationPlayFinished
function emitAnimationPlayed() {
animationPlayed()
}
function emitAnimationPlayFinished() {
animationPlayFinished()
}
function quit() {
state = GreeterModel.Quit
}
@ -41,7 +33,7 @@ Item {
Connections {
target: userModel
function onUpdateTranslations(locale) {
console.log("translation updated");
console.log("translation updated")
logoProvider.updateLocale(locale)
TreeLand.retranslate()
}
@ -74,7 +66,7 @@ Item {
state = GreeterModel.AuthSucceeded
}
onLoginFailed: function () {
onLoginFailed: {
if (!checkUser(userName)) {
return
}
@ -83,7 +75,7 @@ Item {
}
Component.onCompleted: {
proxy.init();
proxy.init()
}
}

View File

@ -21,16 +21,12 @@ D.Popup {
Text {
text: qsTr("Password Hint")
color: Qt.rgba(1, 1, 1, 0.7)
font.weight: Font.Medium
font.pixelSize: 10
font.family: "Source Han Sans CN"
font: D.fontManager.t10
}
Text {
text: hintText
color: "white"
font.weight: Font.Medium
font.pixelSize: 12
font.family: "Source Han Sans CN"
font: D.fontManager.t10
}
}
}

View File

@ -16,7 +16,7 @@ Item {
Hide = 2
}
property var state: LoginAnimation.Show
property int state: LoginAnimation.Show
required property var target
function start(pos, to) {
@ -63,20 +63,20 @@ Item {
id: xAni
target: effect
duration: 1000
easing.type: Easing.OutCubic
easing.type: Easing.OutExpo
}
YAnimator {
id: yAni
target: effect
duration: 1000
easing.type: Easing.OutCubic
easing.type: Easing.OutExpo
}
OpacityAnimator {
target: effect
duration: 1000
from: root.state === LoginAnimation.Show ? 0 : 1
to: root.state === LoginAnimation.Show ? 1 : 0
easing.type: Easing.OutCubic
easing.type: Easing.OutExpo
}
}
}

View File

@ -1,3 +1,5 @@
// Copyright (C) 2023 ComixHe <heyuming@uniontech.com>.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
import QtQuick
import TreeLand.Greeter
import org.deepin.dtk 1.0 as D
@ -9,22 +11,8 @@ D.Menu {
padding: 6
width: 122
background: D.FloatingPanel {
anchors.fill: parent
background: RoundBlur {
radius: 12
blurRadius: 30
backgroundColor: D.Palette {
normal: Qt.rgba(238 / 255, 238 / 255, 238 / 255, 0.8)
}
insideBorderColor: D.Palette {
normal: Qt.rgba(1, 1, 1, 0.1)
}
outsideBorderColor: D.Palette {
normal: Qt.rgba(0, 0, 0, 0.06)
}
dropShadowColor: D.Palette {
normal: Qt.rgba(0, 0, 0, 0.2)
}
}
D.Action {
@ -68,9 +56,7 @@ D.Menu {
id: item
height: enabled ? 26 : 0
display: D.IconLabel.IconBesideText
font.weight: Font.Medium
font.pixelSize: 13
font.family: "Source Han Sans CN"
font: D.fontManager.t9
visible: enabled
property D.Palette highlightColor: D.Palette {

View File

@ -21,27 +21,9 @@ Column {
return user.locale
}
width: 400
height: 156
background: Rectangle {
height: 157
background: RoundBlur {
radius: 8
color: "white"
opacity: 0.1
}
RenderBufferBlitter {
id: blitter
parent: timedate
z: parent.z - 1
anchors.fill: parent
MultiEffect {
id: blur
anchors.fill: parent
source: blitter.content
autoPaddingEnabled: false
blurEnabled: true
blur: 1.0
blurMax: 64
saturation: 0.2
}
}
}
}

View File

@ -1,38 +1,31 @@
import QtQuick
import QtQuick.Effects
import Waylib.Server
import org.deepin.dtk 1.0 as D
D.BoxPanel {
width: parent.width
height: parent.height
radius: width / 2
color1: D.Palette {
normal: Qt.rgba(1, 1, 1, 0.3)
Item {
id: root
property int radius
anchors.fill: parent
Rectangle {
anchors.fill: parent
radius: root.radius
color: "white"
opacity: 0.1
}
color2: D.Palette {
normal: Qt.rgba(1, 1, 1, 0.3)
}
boxShadowBlur: 12
backgroundFlowsHovered: false
boxShadowOffsetY: 0
innerShadowOffsetY1: 0
insideBorderColor: D.Palette {
normal: Qt.rgba(1, 1, 1, 0)
}
outsideBorderColor: D.Palette {
normal: Qt.rgba(1, 1, 1, 0)
}
dropShadowColor: D.Palette {
normal: Qt.rgba(1, 1, 1, 0)
}
innerShadowColor1: D.Palette {
normal: Qt.rgba(1, 1, 1, 0)
}
innerShadowColor2: D.Palette {
normal: Qt.rgba(1, 1, 1, 0)
RenderBufferBlitter {
id: blitter
z: root.parent.z - 1
anchors.fill: parent
MultiEffect {
id: blur
anchors.fill: parent
source: blitter.content
autoPaddingEnabled: false
blurEnabled: true
blur: 1.0
blurMax: 64
saturation: 0.2
}
}
}

View File

@ -11,15 +11,8 @@ Popup {
modal: true
width: 220
height: 140
background: Rectangle {
color: "white"
opacity: 0
}
Rectangle {
color: Qt.rgba(255, 255, 255, 0.3)
anchors.fill: parent
radius: 15
background: RoundBlur {
radius: 12
}
function updateCurrentSession(index) {

View File

@ -1,3 +1,5 @@
// Copyright (C) 2023 ComixHe <heyuming@uniontech.com>.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
import QtQuick
import QtQuick.Controls
import TreeLand.Greeter
@ -24,25 +26,26 @@ Control {
text: currentDate.toLocaleTimeString(currentLocale, "HH:mm")
font.weight: Font.Light
font.pixelSize: 80
font.family: "Source Han Sans CN"
color: "white"
anchors.left: parent.left
anchors.leftMargin: 20
anchors.top: parent.top
// anchors.topMargin: 10
anchors {
left: parent.left
leftMargin: 20
top: parent.top
}
}
Text {
id: dateText
text: currentDate.toLocaleDateString(currentLocale)
font.family: "Source Han Sans CN"
font.weight: Font.Normal
font.pixelSize: 20
color: "white"
anchors.left: parent.left
anchors.leftMargin: 20
anchors.top: timeText.bottom
anchors {
left: parent.left
leftMargin: 20
top: timeText.bottom
}
}
}

View File

@ -40,22 +40,14 @@ Item {
}
}
Connections {
target: Greeter
function onVisibleChanged(visible) {
if (!visible) {
passwordField.text = ''
}
}
}
Rectangle {
anchors.horizontalCenter: parent.horizontalCenter
Item {
width: 32
height: 32
color: "transparent"
anchors.bottom: parent.top
anchors.bottomMargin: 56
anchors {
horizontalCenter: parent.horizontalCenter
bottom: parent.top
bottomMargin: 56
}
D.DciIcon {
name: "login_lock"
anchors.centerIn: parent
@ -77,8 +69,10 @@ Item {
anchors.horizontalCenter: parent.horizontalCenter
color: "transparent"
radius: 20
border.width: 2
border.color: Qt.rgba(1, 1, 1, 0.1)
border {
width: 2
color: Qt.rgba(1, 1, 1, 0.1)
}
D.QtIcon {
id: avatar
@ -102,8 +96,10 @@ Item {
radius: 20
anchors.fill: avatar
color: "transparent"
border.width: 1
border.color: Qt.rgba(0, 0, 0, 0.2)
border {
width: 1
color: Qt.rgba(0, 0, 0, 0.2)
}
}
}
@ -142,15 +138,19 @@ Item {
RowLayout {
height: parent.height
anchors.right: parent.right
anchors.rightMargin: 3
anchors {
right: parent.right
rightMargin: 3
}
D.ActionButton {
visible: passwordField.capsIndicatorVisible
palette.windowText: undefined
icon.name: "login_capslock"
icon.height: 10
icon.width: 10
icon {
name: "login_capslock"
height: 10
width: 10
}
Layout.alignment: Qt.AlignHCenter
implicitWidth: 16
implicitHeight: 16
@ -160,9 +160,11 @@ Item {
id: showPasswordBtn
palette.windowText: undefined
property bool hiddenPWD: true
icon.name: hiddenPWD ? "login_hidden_password" : "login_display_password"
icon.height: 10
icon.width: 10
icon {
name: hiddenPWD ? "login_hidden_password" : "login_display_password"
height: 10
width: 10
}
Layout.alignment: Qt.AlignHCenter
implicitWidth: 16
implicitHeight: 16
@ -191,14 +193,18 @@ Item {
D.RoundButton {
id: loginBtn
icon.name: "login_open"
icon.width: 16
icon.height: 16
icon {
name: "login_open"
width: 16
height: 16
}
height: passwordField.height
width: height
anchors.left: userCol.right
anchors.bottom: userCol.bottom
anchors.leftMargin: 20
anchors {
left: userCol.right
bottom: userCol.bottom
leftMargin: 20
}
enabled: passwordField.length != 0
background: Rectangle {
anchors.fill: parent
@ -211,14 +217,16 @@ Item {
RowLayout {
spacing: 10
anchors.right: userCol.left
anchors.bottom: userCol.bottom
anchors.rightMargin: 10
anchors {
right: userCol.left
bottom: userCol.bottom
rightMargin: 10
}
height: passwordField.height
D.RoundButton {
id: langBtn
text: 'L'
text: 'L' // TODO: replace with icon
visible: false
Layout.fillHeight: true
Layout.preferredWidth: passwordField.height
@ -229,15 +237,18 @@ Item {
}
onClicked: {
// TODO: impl language switch
console.log("need impl langBtn")
}
}
D.RoundButton {
id: hintBtn
icon.name: "login_hint"
icon.width: 16
icon.height: 16
icon {
name: "login_hint"
width: 16
height: 16
}
visible: hintLabel.hintText.length != 0
Layout.fillHeight: true
Layout.preferredWidth: passwordField.height
@ -266,9 +277,11 @@ Item {
id: hintText
font.pointSize: 10
color: "gray"
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: userCol.bottom
anchors.topMargin: 16
anchors {
horizontalCenter: parent.horizontalCenter
top: userCol.bottom
topMargin: 16
}
}
Component.onCompleted: {
@ -289,7 +302,8 @@ Item {
function userAuthFailed() {
passwordField.selectAll()
if (loginGroup.activeFocus)
if (loginGroup.activeFocus) {
passwordField.forceActiveFocus()
}
}
}

View File

@ -21,22 +21,8 @@ D.Popup {
width: 232
height: useScrollBar ? maxListHeight : listv.contentHeight + padding * 2
background: D.FloatingPanel {
anchors.fill: parent
background: RoundBlur {
radius: 12
blurRadius: 30
backgroundColor: D.Palette {
normal: Qt.rgba(238 / 255, 238 / 255, 238 / 255, 0.8)
}
insideBorderColor: D.Palette {
normal: Qt.rgba(1, 1, 1, 0.1)
}
outsideBorderColor: D.Palette {
normal: Qt.rgba(0, 0, 0, 0.06)
}
dropShadowColor: D.Palette {
normal: Qt.rgba(0, 0, 0, 0.2)
}
}
function selectCurrentUser(userName, index) {
@ -55,172 +41,166 @@ D.Popup {
listv.positionViewAtIndex(listv.currentIndex, ListView.Beginning)
}
D.ScrollView {
id: scrollv
ListView {
id: listv
anchors.fill: parent
clip: true
ScrollBar.vertical.active: users.useScrollBar
model: GreeterModel.userModel
width: parent.width
focus: true
D.ColorSelector.family: D.Palette.CrystalColor
clip: true
keyNavigationWraps: true
highlightMoveDuration: 0
Keys.onTabPressed: listv.incrementCurrentIndex()
Keys.onReturnPressed: selectCurrentUser(model.name, model.index)
ListView {
id: listv
model: GreeterModel.userModel
width: parent.width
property D.Palette highlightColor: D.Palette {
normal: D.DTK.makeColor(D.Color.Highlight)
}
delegate: D.CheckDelegate {
id: singleUser
height: 44
width: 220
padding: 4
focus: true
keyNavigationWraps: true
highlightMoveDuration: 0
Keys.onTabPressed: listv.incrementCurrentIndex()
Keys.onReturnPressed: selectCurrentUser(model.name, model.index)
property D.Palette highlightColor: D.Palette {
normal: D.DTK.makeColor(D.Color.Highlight)
onHoveredChanged: {
if (hovered) {
listv.currentIndex = index
}
}
delegate: D.CheckDelegate {
id: singleUser
height: 44
width: 220
padding: 4
focus: true
onHoveredChanged: {
if (hovered) {
listv.currentIndex = index
contentItem: RowLayout {
Control {
Layout.preferredHeight: 36
Layout.preferredWidth: 36
Layout.alignment: Qt.AlignVCenter
background: Item {
D.QtIcon {
id: source
anchors.fill: parent
fallbackSource: model.icon
visible: false
}
Rectangle {
id: maskSource
radius: 2
anchors.fill: source
visible: false
}
D.OpacityMask {
anchors.fill: source
source: source
maskSource: maskSource
invert: false
}
Rectangle {
radius: 2
anchors.fill: source
color: "transparent"
border {
width: 1
color: Qt.rgba(0, 0, 0, 0.2)
}
}
}
}
contentItem: RowLayout {
Control {
Layout.preferredHeight: 36
Layout.preferredWidth: 36
Layout.alignment: Qt.AlignVCenter
background: Item {
D.QtIcon {
id: source
Item {
width: 8
height: 8
anchors {
right: parent.right
bottom: parent.bottom
}
visible: model.logined
Rectangle {
anchors.centerIn: parent
color: Qt.rgba(0, 1, 2 / 250, 1)
height: 7
width: 7
radius: 4
border {
width: 1
color: Qt.rgba(1, 1, 1, 0.8)
}
z: 1
D.BoxShadow {
anchors.fill: parent
fallbackSource: model.icon
visible: false
}
Rectangle {
id: maskSource
radius: 2
anchors.fill: source
visible: false
}
D.OpacityMask {
anchors.fill: source
source: source
maskSource: maskSource
invert: false
}
Rectangle {
radius: 2
anchors.fill: source
color: "transparent"
border.width: 1
border.color: Qt.rgba(0, 0, 0, 0.2)
shadowBlur: 4
shadowColor: Qt.rgba(0, 180 / 255,
38 / 255, 0.21)
shadowOffsetX: 0
shadowOffsetY: 2
cornerRadius: parent.radius
hollow: true
}
}
Item {
width: 8
height: 8
anchors.right: parent.right
anchors.bottom: parent.bottom
visible: model.logined
Rectangle {
anchors.centerIn: parent
color: Qt.rgba(0, 1, 2 / 250, 1)
height: 7
width: 7
radius: 4
border.width: 1
border.color: Qt.rgba(1, 1, 1, 0.8)
z: 1
D.BoxShadow {
anchors.fill: parent
shadowBlur: 4
shadowColor: Qt.rgba(0, 180 / 255,
38 / 255, 0.21)
shadowOffsetX: 0
shadowOffsetY: 2
cornerRadius: parent.radius
hollow: true
}
Rectangle {
anchors.centerIn: parent
color: "transparent"
height: 6
width: 6
radius: 4
border {
width: 1
color: Qt.rgba(0, 0, 0, 0.05)
}
z: 2
Rectangle {
anchors.centerIn: parent
color: "transparent"
height: 6
width: 6
radius: 4
border.width: 1
border.color: Qt.rgba(0, 0, 0, 0.05)
z: 2
D.BoxShadow {
anchors.fill: parent
shadowBlur: 3
shadowColor: Qt.rgba(0, 0, 0, 0.2)
shadowOffsetX: 0
shadowOffsetY: 0
cornerRadius: parent.radius
}
D.BoxShadow {
anchors.fill: parent
shadowBlur: 3
shadowColor: Qt.rgba(0, 0, 0, 0.2)
shadowOffsetX: 0
shadowOffsetY: 0
cornerRadius: parent.radius
}
}
}
Column {
Layout.fillWidth: true
Layout.preferredHeight: 36
Layout.alignment: Qt.AlignVCenter
Text {
id: displayUserName
text: model.realName.length === 0 ? model.name : model.realName
color: singleUser.ListView.isCurrentItem ? "white" : "black"
font.weight: Font.Medium
font.pixelSize: 13
font.family: "Source Han Sans CN"
}
Text {
text: model.identity
color: singleUser.ListView.isCurrentItem ? Qt.rgba(
1, 1, 1,
0.7) : Qt.rgba(
0,
0, 0, 0.6)
font.weight: Font.Medium
font.pixelSize: 10
font.family: "Source Han Sans CN"
}
}
}
background: Rectangle {
id: userBackground
anchors.fill: parent
radius: 6
color: singleUser.ListView.isCurrentItem ? listv.D.ColorSelector.highlightColor : "transparent"
D.BoxShadow {
anchors.fill: parent
shadowBlur: 0
shadowColor: Qt.rgba(17 / 255, 47 / 255, 251 / 255, 0.5)
shadowOffsetX: 0
shadowOffsetY: -1
cornerRadius: parent.radius
hollow: true
Column {
Layout.fillWidth: true
Layout.preferredHeight: 36
Layout.alignment: Qt.AlignVCenter
Text {
id: displayUserName
text: model.realName.length === 0 ? model.name : model.realName
color: singleUser.ListView.isCurrentItem ? "white" : "black"
font: D.fontManager.t9
}
Text {
text: model.identity
color: singleUser.ListView.isCurrentItem ? Qt.rgba(1, 1, 1,0.7)
: Qt.rgba(0, 0, 0, 0.6)
font: D.fontManager.t10
}
}
onClicked: selectCurrentUser(model.name, index)
checked: GreeterModel.currentUser === model.name
}
background: Rectangle {
id: userBackground
anchors.fill: parent
radius: 6
color: singleUser.ListView.isCurrentItem ? listv.D.ColorSelector.highlightColor : "transparent"
D.BoxShadow {
anchors.fill: parent
shadowBlur: 0
shadowColor: Qt.rgba(17 / 255, 47 / 255, 251 / 255, 0.5)
shadowOffsetX: 0
shadowOffsetY: -1
cornerRadius: parent.radius
hollow: true
}
}
onClicked: selectCurrentUser(model.name, index)
checked: GreeterModel.currentUser === model.name
}
}
}