homescreens/halcyon: Use ExtendedAbstractButton

This commit is contained in:
Devin Lin 2022-06-28 13:26:36 -04:00
parent 3f735708cf
commit 02bcf78742
3 changed files with 35 additions and 42 deletions

View file

@ -17,7 +17,12 @@ QQC2.AbstractButton {
/** /**
* The cursor shape when the mouse is over the button. * 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. * 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
}
} }

View file

@ -17,7 +17,7 @@ import org.kde.phone.homescreen.halcyon 1.0 as Halcyon
import org.kde.kirigami 2.19 as Kirigami import org.kde.kirigami 2.19 as Kirigami
Item { MobileShell.ExtendedAbstractButton {
id: delegate id: delegate
property alias iconItem: icon property alias iconItem: icon
@ -57,18 +57,9 @@ Item {
} }
} }
TapHandler { onRightClickPressed: openContextMenu()
id: tapHandler onClicked: launchApp();
acceptedButtons: Qt.LeftButton | Qt.RightButton onPressAndHold: openContextMenu()
onLongPressed: delegate.openContextMenu()
onTapped: (eventPoint.event.button === Qt.RightButton) ? delegate.openContextMenu() : delegate.launchApp();
}
HoverHandler {
id: hoverHandler
acceptedPointerTypes: PointerDevice.GenericPointer | PointerDevice.Cursor | PointerDevice.Pen
}
Loader { Loader {
id: dialogLoader id: dialogLoader
@ -92,7 +83,7 @@ Item {
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent
radius: height / 2 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 { RowLayout {

View file

@ -20,7 +20,7 @@ import org.kde.phone.homescreen.halcyon 1.0 as Halcyon
import org.kde.kirigami 2.19 as Kirigami import org.kde.kirigami 2.19 as Kirigami
Item { MobileShell.ExtendedAbstractButton {
id: delegate id: delegate
width: GridView.view.cellWidth width: GridView.view.cellWidth
height: GridView.view.cellHeight height: GridView.view.cellHeight
@ -39,6 +39,10 @@ Item {
dialogLoader.item.open(); dialogLoader.item.open();
} }
cursorShape: Qt.PointingHandCursor
onPressAndHold: openContextMenu()
onRightClickPressed: openContextMenu()
function launchApp() { function launchApp() {
// launch app // launch app
if (application.running) { 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 { Loader {
id: dialogLoader id: dialogLoader
active: false active: false
@ -108,7 +88,7 @@ Item {
duration: MobileShell.MobileShellSettings.animationsEnabled ? 80 : 1 duration: MobileShell.MobileShellSettings.animationsEnabled ? 80 : 1
to: MobileShell.MobileShellSettings.animationsEnabled ? 0.8 : 1 to: MobileShell.MobileShellSettings.animationsEnabled ? 0.8 : 1
onFinished: { onFinished: {
if (!tapHandler.pressed) { if (!delegate.pressed) {
growAnim.restart(); 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 { ColumnLayout {
anchors { anchors {
fill: parent fill: parent
@ -162,7 +153,7 @@ Item {
// darken effect when hovered/pressed // darken effect when hovered/pressed
layer { layer {
enabled: tapHandler.pressed || hoverHandler.hovered enabled: delegate.pressed || delegate.mouseHovered
effect: ColorOverlay { effect: ColorOverlay {
color: Qt.rgba(0, 0, 0, 0.3) color: Qt.rgba(0, 0, 0, 0.3)
} }