From f87c7c55261f938b8c7df2bd178cce713364568b Mon Sep 17 00:00:00 2001 From: Yari Polla Date: Tue, 14 Mar 2023 01:21:37 +0100 Subject: [PATCH] homescreens/halcyon: switch page when trying to move out of the grids --- .../mobileshell/qml/components/GridView.qml | 45 +++++++++++++++++++ .../package/contents/ui/FavoritesView.qml | 5 +++ .../package/contents/ui/HomeScreen.qml | 12 +++++ 3 files changed, 62 insertions(+) diff --git a/components/mobileshell/qml/components/GridView.qml b/components/mobileshell/qml/components/GridView.qml index 8fc6de85..62077f87 100644 --- a/components/mobileshell/qml/components/GridView.qml +++ b/components/mobileshell/qml/components/GridView.qml @@ -13,6 +13,51 @@ GridView { highlightFollowsCurrentItem: true highlight: highlightComponent + /** These function are called when the user tries to move the highlight outside the allowed surface by using arrow keys. + * Useful to override the default behaviour of GridView (Pac-Man effect). + */ + property var topEdgeCallback: null + property var bottomEdgeCallback: null + property var leftEdgeCallback: null + property var rightEdgeCallback: null + + Keys.onPressed: event => { + if (!currentItem) { + return; + } + + switch(event.key){ + case Qt.Key_Left: { + if (currentItem.x === 0 + && leftEdgeCallback) { + leftEdgeCallback(); + } + break; + } + case Qt.Key_Right: { + if (indexAt(currentItem.x + cellWidth, currentItem.y) === -1 + && rightEdgeCallback) { + rightEdgeCallback(); + } + break; + } + case Qt.Key_Up: { + if (currentItem.y === 0 + && topEdgeCallback) { + topEdgeCallback(); + } + break; + } + case Qt.Key_Down: { + if (indexAt(currentItem.x, currentItem.y + cellHeight) === -1 + && bottomEdgeCallback) { + bottomEdgeCallback(); + } + break; + } + } + } + onActiveFocusChanged: { if (!activeFocus) { currentIndex = -1; diff --git a/containments/homescreens/halcyon/package/contents/ui/FavoritesView.qml b/containments/homescreens/halcyon/package/contents/ui/FavoritesView.qml index 5917535f..10c44f15 100644 --- a/containments/homescreens/halcyon/package/contents/ui/FavoritesView.qml +++ b/containments/homescreens/halcyon/package/contents/ui/FavoritesView.qml @@ -34,6 +34,7 @@ Item { property bool folderShown: false signal openConfigureRequested() + signal pageForwardRequested(); Connections { target: parent @@ -87,6 +88,10 @@ Item { transform: Translate { x: favoritesGrid.translateX } opacity: 1 - openFolderProgress visible: opacity !== 0 + + rightEdgeCallback: () => { + pageForwardRequested(); + } } FolderGrid { diff --git a/containments/homescreens/halcyon/package/contents/ui/HomeScreen.qml b/containments/homescreens/halcyon/package/contents/ui/HomeScreen.qml index d4b1eb5c..dfa05ec2 100644 --- a/containments/homescreens/halcyon/package/contents/ui/HomeScreen.qml +++ b/containments/homescreens/halcyon/package/contents/ui/HomeScreen.qml @@ -93,6 +93,12 @@ Item { searchWidget: root.searchWidget interactive: root.interactive onOpenConfigureRequested: root.openConfigure() + + onPageForwardRequested: { + swipeView.setCurrentIndex(1); + swipeView.focusChild(); + resetHighlight(); + } } } @@ -111,6 +117,12 @@ Item { interactive: root.interactive leftMargin: horizontalMargin rightMargin: horizontalMargin + + leftEdgeCallback: () => { + swipeView.setCurrentIndex(0); + swipeView.focusChild(); + currentIndex = -1; + } } } }