Accept keys in windowheap conditionally

In WindowHeap we currently always accept the keyboard event regardless
of whether the event was handled.

This will allow the event to propagate to other handlers
This commit is contained in:
David Edmundson 2022-07-14 16:35:29 +01:00 committed by Vlad Zahorodnii
parent e726779c9b
commit a61719ddc4

View file

@ -244,7 +244,9 @@ FocusScope {
const nextIndex = findNextItem(heap.selectedIndex, direction); const nextIndex = findNextItem(heap.selectedIndex, direction);
if (nextIndex != -1) { if (nextIndex != -1) {
heap.selectedIndex = nextIndex; heap.selectedIndex = nextIndex;
return true;
} }
return false;
} }
function selectLastItem(direction) { function selectLastItem(direction) {
@ -259,39 +261,43 @@ FocusScope {
} }
if (last != -1) { if (last != -1) {
heap.selectedIndex = last; heap.selectedIndex = last;
return true;
} }
return false;
} }
onActiveFocusChanged: resetSelected(); onActiveFocusChanged: resetSelected();
Keys.onPressed: { Keys.onPressed: {
let handled = false;
switch (event.key) { switch (event.key) {
case Qt.Key_Up: case Qt.Key_Up:
selectNextItem(WindowHeap.Direction.Up); handled = selectNextItem(WindowHeap.Direction.Up);
break; break;
case Qt.Key_Down: case Qt.Key_Down:
selectNextItem(WindowHeap.Direction.Down); handled = selectNextItem(WindowHeap.Direction.Down);
break; break;
case Qt.Key_Left: case Qt.Key_Left:
selectNextItem(WindowHeap.Direction.Left); handled = selectNextItem(WindowHeap.Direction.Left);
break; break;
case Qt.Key_Right: case Qt.Key_Right:
selectNextItem(WindowHeap.Direction.Right); handled = selectNextItem(WindowHeap.Direction.Right);
break; break;
case Qt.Key_Home: case Qt.Key_Home:
selectLastItem(WindowHeap.Direction.Left); handled = selectLastItem(WindowHeap.Direction.Left);
break; break;
case Qt.Key_End: case Qt.Key_End:
selectLastItem(WindowHeap.Direction.Right); handled = selectLastItem(WindowHeap.Direction.Right);
break; break;
case Qt.Key_PageUp: case Qt.Key_PageUp:
selectLastItem(WindowHeap.Direction.Up); handled = selectLastItem(WindowHeap.Direction.Up);
break; break;
case Qt.Key_PageDown: case Qt.Key_PageDown:
selectLastItem(WindowHeap.Direction.Down); handled = selectLastItem(WindowHeap.Direction.Down);
break; break;
case Qt.Key_Return: case Qt.Key_Return:
case Qt.Key_Space: case Qt.Key_Space:
handled = true;
let selectedItem = null; let selectedItem = null;
if (heap.selectedIndex != -1) { if (heap.selectedIndex != -1) {
selectedItem = windowsRepeater.itemAt(heap.selectedIndex); selectedItem = windowsRepeater.itemAt(heap.selectedIndex);
@ -316,6 +322,6 @@ FocusScope {
default: default:
return; return;
} }
event.accepted = true; event.accepted = handled;
} }
} }