homescreens/halcyon: switch page when trying to move out of the grids

This commit is contained in:
Yari Polla 2023-03-14 01:21:37 +01:00 committed by Devin Lin
parent e21354bf63
commit f87c7c5526
3 changed files with 62 additions and 0 deletions

View file

@ -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;

View file

@ -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 {

View file

@ -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;
}
}
}
}