From 02bcf787427dd370aad17a0a2def62b4dc34f249 Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Tue, 28 Jun 2022 13:26:36 -0400 Subject: [PATCH] homescreens/halcyon: Use ExtendedAbstractButton --- .../qml/components/ExtendedAbstractButton.qml | 13 +++++- .../contents/ui/DrawerListDelegate.qml | 19 +++----- .../package/contents/ui/GridAppDelegate.qml | 45 ++++++++----------- 3 files changed, 35 insertions(+), 42 deletions(-) diff --git a/components/mobileshell/qml/components/ExtendedAbstractButton.qml b/components/mobileshell/qml/components/ExtendedAbstractButton.qml index 63097ab1..c184b267 100644 --- a/components/mobileshell/qml/components/ExtendedAbstractButton.qml +++ b/components/mobileshell/qml/components/ExtendedAbstractButton.qml @@ -17,7 +17,12 @@ QQC2.AbstractButton { /** * The cursor shape when the mouse is over the button. */ - property alias cursorShape: mouseArea.cursorShape + property alias cursorShape: hoverHandler.cursorShape + + /** + * Whether a mouse is hovering over the button (not touch). + */ + readonly property bool mouseHovered: hoverHandler.hovered /** * Signal that is emitted when the right click button is pressed. @@ -36,4 +41,10 @@ QQC2.AbstractButton { } } } + + HoverHandler { + id: hoverHandler + acceptedDevices: PointerDevice.Mouse + acceptedPointerTypes: PointerDevice.Generic + } } diff --git a/containments/homescreens/halcyon/package/contents/ui/DrawerListDelegate.qml b/containments/homescreens/halcyon/package/contents/ui/DrawerListDelegate.qml index 45a56b5a..c99a310a 100644 --- a/containments/homescreens/halcyon/package/contents/ui/DrawerListDelegate.qml +++ b/containments/homescreens/halcyon/package/contents/ui/DrawerListDelegate.qml @@ -17,7 +17,7 @@ import org.kde.phone.homescreen.halcyon 1.0 as Halcyon import org.kde.kirigami 2.19 as Kirigami -Item { +MobileShell.ExtendedAbstractButton { id: delegate property alias iconItem: icon @@ -57,18 +57,9 @@ Item { } } - TapHandler { - id: tapHandler - acceptedButtons: Qt.LeftButton | Qt.RightButton - - onLongPressed: delegate.openContextMenu() - onTapped: (eventPoint.event.button === Qt.RightButton) ? delegate.openContextMenu() : delegate.launchApp(); - } - - HoverHandler { - id: hoverHandler - acceptedPointerTypes: PointerDevice.GenericPointer | PointerDevice.Cursor | PointerDevice.Pen - } + onRightClickPressed: openContextMenu() + onClicked: launchApp(); + onPressAndHold: openContextMenu() Loader { id: dialogLoader @@ -92,7 +83,7 @@ Item { Rectangle { anchors.fill: parent radius: height / 2 - color: tapHandler.pressed ? Qt.rgba(255, 255, 255, 0.2) : (hoverHandler.hovered ? Qt.rgba(255, 255, 255, 0.1) : "transparent") + color: delegate.pressed ? Qt.rgba(255, 255, 255, 0.2) : (delegate.mouseHovered ? Qt.rgba(255, 255, 255, 0.1) : "transparent") } RowLayout { diff --git a/containments/homescreens/halcyon/package/contents/ui/GridAppDelegate.qml b/containments/homescreens/halcyon/package/contents/ui/GridAppDelegate.qml index 4fc9291b..b58ef9c4 100644 --- a/containments/homescreens/halcyon/package/contents/ui/GridAppDelegate.qml +++ b/containments/homescreens/halcyon/package/contents/ui/GridAppDelegate.qml @@ -20,7 +20,7 @@ import org.kde.phone.homescreen.halcyon 1.0 as Halcyon import org.kde.kirigami 2.19 as Kirigami -Item { +MobileShell.ExtendedAbstractButton { id: delegate width: GridView.view.cellWidth height: GridView.view.cellHeight @@ -39,6 +39,10 @@ Item { dialogLoader.item.open(); } + cursorShape: Qt.PointingHandCursor + onPressAndHold: openContextMenu() + onRightClickPressed: openContextMenu() + function launchApp() { // launch app if (application.running) { @@ -48,30 +52,6 @@ Item { } } - TapHandler { - id: tapHandler - acceptedButtons: Qt.LeftButton | Qt.RightButton - - // launch app handled by press animation - onTapped: (eventPoint.event.button === Qt.RightButton) ? delegate.openContextMenu() : delegate.launchAppRequested = true; - onLongPressed: delegate.openContextMenu() - - onPressedChanged: { - if (pressed) { - growAnim.stop(); - shrinkAnim.restart(); - } else if (!pressed && !shrinkAnim.running) { - growAnim.restart(); - } - } - } - - HoverHandler { - id: hoverHandler - cursorShape: Qt.PointingHandCursor - acceptedPointerTypes: PointerDevice.GenericPointer | PointerDevice.Cursor | PointerDevice.Pen - } - Loader { id: dialogLoader active: false @@ -108,7 +88,7 @@ Item { duration: MobileShell.MobileShellSettings.animationsEnabled ? 80 : 1 to: MobileShell.MobileShellSettings.animationsEnabled ? 0.8 : 1 onFinished: { - if (!tapHandler.pressed) { + if (!delegate.pressed) { growAnim.restart(); } } @@ -127,6 +107,17 @@ Item { } } + onPressedChanged: { + if (pressed) { + growAnim.stop(); + shrinkAnim.restart(); + } else if (!pressed && !shrinkAnim.running) { + growAnim.restart(); + } + } + // launch app handled by press animation + onClicked: launchAppRequested = true; + ColumnLayout { anchors { fill: parent @@ -162,7 +153,7 @@ Item { // darken effect when hovered/pressed layer { - enabled: tapHandler.pressed || hoverHandler.hovered + enabled: delegate.pressed || delegate.mouseHovered effect: ColorOverlay { color: Qt.rgba(0, 0, 0, 0.3) }