Commit 02bcf787 authored by Devin Lin's avatar Devin Lin 🎨
Browse files

homescreens/halcyon: Use ExtendedAbstractButton

parent 3f735708
Pipeline #196713 passed with stage
in 1 minute and 17 seconds
......@@ -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
}
}
......@@ -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 {
......
......@@ -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)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment