Finish keyboard navigation for GridViews and MenuItems

This commit is contained in:
Cameron Gutman 2018-09-23 19:06:26 -07:00
parent 2e3de32810
commit 8fb37ae229
6 changed files with 30 additions and 7 deletions

View File

@ -31,6 +31,11 @@ GridView {
stackView.pop() stackView.pop()
} }
Component.onCompleted: {
// Don't show any highlighted item until interacting with them
currentIndex = -1
}
onVisibleChanged: { onVisibleChanged: {
if (visible) { if (visible) {
appModel.computerLost.connect(computerLost) appModel.computerLost.connect(computerLost)
@ -51,7 +56,7 @@ GridView {
delegate: NavigableItemDelegate { delegate: NavigableItemDelegate {
width: 200; height: 335; width: 200; height: 335;
grid: pcGrid grid: appGrid
Image { Image {
id: appIcon id: appIcon
@ -129,7 +134,7 @@ GridView {
} }
height: visible ? implicitHeight : 0 height: visible ? implicitHeight : 0
} }
MenuItem { NavigableMenuItem {
text: "Quit Game" text: "Quit Game"
onTriggered: { onTriggered: {
quitAppDialog.appName = appModel.getRunningAppName() quitAppDialog.appName = appModel.getRunningAppName()

View File

@ -4,6 +4,8 @@ import QtQuick.Controls 2.2
ItemDelegate { ItemDelegate {
property GridView grid property GridView grid
highlighted: grid.activeFocus && grid.currentItem === this
Keys.onLeftPressed: { Keys.onLeftPressed: {
grid.moveCurrentIndexLeft() grid.moveCurrentIndexLeft()
} }
@ -13,11 +15,9 @@ ItemDelegate {
Keys.onDownPressed: { Keys.onDownPressed: {
grid.moveCurrentIndexDown() grid.moveCurrentIndexDown()
} }
Keys.onUpPressed: { Keys.onUpPressed: {
grid.moveCurrentIndexUp() grid.moveCurrentIndexUp()
} }
Keys.onReturnPressed: { Keys.onReturnPressed: {
clicked() clicked()
} }

View File

@ -0,0 +1,8 @@
import QtQuick 2.0
import QtQuick.Controls 2.2
MenuItem {
Keys.onReturnPressed: {
triggered()
}
}

View File

@ -45,6 +45,9 @@ GridView {
else if (!prefs.hasAnyHardwareAcceleration()) { else if (!prefs.hasAnyHardwareAcceleration()) {
noHwDecoderDialog.open() noHwDecoderDialog.open()
} }
// Don't show any highlighted item until interacting with them
currentIndex = -1
} }
function pairingComplete(error) function pairingComplete(error)
@ -131,13 +134,13 @@ GridView {
Menu { Menu {
id: pcContextMenu id: pcContextMenu
MenuItem { NavigableMenuItem {
text: "Wake PC" text: "Wake PC"
onTriggered: computerModel.wakeComputer(index) onTriggered: computerModel.wakeComputer(index)
visible: !model.addPc && !model.online && model.wakeable visible: !model.addPc && !model.online && model.wakeable
height: visible ? implicitHeight : 0 height: visible ? implicitHeight : 0
} }
MenuItem { NavigableMenuItem {
text: "Delete PC" text: "Delete PC"
onTriggered: { onTriggered: {
deletePcDialog.pcIndex = index deletePcDialog.pcIndex = index

View File

@ -26,7 +26,7 @@ ApplicationWindow {
focus: true focus: true
onCurrentItemChanged: { onCurrentItemChanged: {
// Ensure focus travels to the next view // Ensure focus travels to the next view when going back
if (currentItem) { if (currentItem) {
currentItem.forceActiveFocus() currentItem.forceActiveFocus()
} }
@ -37,6 +37,12 @@ ApplicationWindow {
stackView.pop() stackView.pop()
} }
} }
Keys.onBackPressed: {
if (depth > 1) {
stackView.pop()
}
}
} }
onVisibilityChanged: { onVisibilityChanged: {

View File

@ -9,5 +9,6 @@
<file>gui/QuitSegue.qml</file> <file>gui/QuitSegue.qml</file>
<file>gui/NavigableToolButton.qml</file> <file>gui/NavigableToolButton.qml</file>
<file>gui/NavigableItemDelegate.qml</file> <file>gui/NavigableItemDelegate.qml</file>
<file>gui/NavigableMenuItem.qml</file>
</qresource> </qresource>
</RCC> </RCC>