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

View File

@ -4,6 +4,8 @@ import QtQuick.Controls 2.2
ItemDelegate {
property GridView grid
highlighted: grid.activeFocus && grid.currentItem === this
Keys.onLeftPressed: {
grid.moveCurrentIndexLeft()
}
@ -13,11 +15,9 @@ ItemDelegate {
Keys.onDownPressed: {
grid.moveCurrentIndexDown()
}
Keys.onUpPressed: {
grid.moveCurrentIndexUp()
}
Keys.onReturnPressed: {
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()) {
noHwDecoderDialog.open()
}
// Don't show any highlighted item until interacting with them
currentIndex = -1
}
function pairingComplete(error)
@ -131,13 +134,13 @@ GridView {
Menu {
id: pcContextMenu
MenuItem {
NavigableMenuItem {
text: "Wake PC"
onTriggered: computerModel.wakeComputer(index)
visible: !model.addPc && !model.online && model.wakeable
height: visible ? implicitHeight : 0
}
MenuItem {
NavigableMenuItem {
text: "Delete PC"
onTriggered: {
deletePcDialog.pcIndex = index

View File

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

View File

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