From b1a514027b935ae1f3d91d167e6f3b1b637d4ddd Mon Sep 17 00:00:00 2001 From: reionwong Date: Wed, 7 Jul 2021 11:24:26 +0800 Subject: [PATCH] Add hover animation --- qml/StandardItem.qml | 100 ++++++++++++++++++++++++++++++++++++++----- qml/main.qml | 6 ++- 2 files changed, 94 insertions(+), 12 deletions(-) diff --git a/qml/StandardItem.qml b/qml/StandardItem.qml index 530cee7..651bd5a 100644 --- a/qml/StandardItem.qml +++ b/qml/StandardItem.qml @@ -28,8 +28,13 @@ import Cutefish.StatusBar 1.0 Item { id: control + property real moveX: 0 + property real moveY: 0 + property string popupText: "" + property bool checked: false + property bool animationEnabled: false signal clicked signal rightClicked @@ -40,6 +45,18 @@ Item { acceptedButtons: Qt.LeftButton | Qt.RightButton hoverEnabled: true + onEntered: { + _bgRect.x = mouseX + _bgRect.y = mouseY + _bgRect.state = "shown" + } + + onExited: { + control.moveX = mouseX + control.moveY = mouseY + _bgRect.state = "hidden" + } + onClicked: { if (mouse.button == Qt.LeftButton) control.clicked() @@ -64,24 +81,85 @@ Item { } Rectangle { - anchors.fill: parent - anchors.topMargin: 1 - anchors.bottomMargin: 1 + id: _bgRect radius: FishUI.Theme.smallRadius + state: "hidden" + states: [ + State { + name: "shown" + PropertyChanges { + target: _bgRect + x: 0 + y: 1 + width: control.width + height: control.height - 2 + visible: true + } + }, + State { + name: "hidden" + PropertyChanges { + target: _bgRect + x: control.moveX + y: control.moveY + width: 0 + height: 0 + visible: false + } + } + ] + + transitions:[ + Transition { + from: "hidden" + to: "shown" + + SequentialAnimation{ + PropertyAnimation { + target: _bgRect + properties: "visible" + duration: 0 + easing.type: Easing.OutQuart + } + PropertyAnimation { + target: _bgRect + properties: "x, y, width, height" + duration: control.animationEnabled ? 400 : 0 + easing.type: Easing.OutQuart + } + } + }, + Transition { + from: "shown" + to: "hidden" + + SequentialAnimation{ + PropertyAnimation { + target: _bgRect + properties: "x, y, width, height" + duration: control.animationEnabled ? 200 : 0 + easing.type: Easing.OutQuart + } + PropertyAnimation { + target: _bgRect + properties: "visible" + duration: 0 + easing.type: Easing.OutQuart + } + } + } + ] + color: { if (control.checked) { return (rootItem.darkMode) ? Qt.rgba(255, 255, 255, 0.2) : Qt.rgba(0, 0, 0, 0.1) } - if (_mouseArea.containsMouse) { - if (_mouseArea.containsPress) - return (rootItem.darkMode) ? Qt.rgba(255, 255, 255, 0.3) : Qt.rgba(0, 0, 0, 0.2) - else - return (rootItem.darkMode) ? Qt.rgba(255, 255, 255, 0.2) : Qt.rgba(0, 0, 0, 0.1) - } - - return "transparent" + if (_mouseArea.containsPress) + return (rootItem.darkMode) ? Qt.rgba(255, 255, 255, 0.3) : Qt.rgba(0, 0, 0, 0.2) + else + return (rootItem.darkMode) ? Qt.rgba(255, 255, 255, 0.2) : Qt.rgba(0, 0, 0, 0.1) } } } diff --git a/qml/main.qml b/qml/main.qml index a0407c2..2c04bff 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -233,10 +233,12 @@ Item { } delegate: StandardItem { + property bool darkMode: rootItem.darkMode + width: trayView.itemWidth height: ListView.view.height + animationEnabled: true - property bool darkMode: rootItem.darkMode onDarkModeChanged: updateTimer.restart() Timer { @@ -262,6 +264,7 @@ Item { StandardItem { id: controler + animationEnabled: true Layout.fillHeight: true Layout.preferredWidth: _controlerLayout.implicitWidth + FishUI.Units.largeSpacing @@ -339,6 +342,7 @@ Item { StandardItem { id: datetimeItem + animationEnabled: true Layout.fillHeight: true Layout.preferredWidth: _dateTimeLayout.implicitWidth + FishUI.Units.smallSpacing