Fix gamepad menu focus and dismissal issues

This commit is contained in:
Cameron Gutman 2019-02-09 19:59:01 -08:00
parent 48e78d2cd3
commit 8de42b3199
5 changed files with 36 additions and 7 deletions

View file

@ -162,15 +162,24 @@ GridView {
}
}
Keys.onMenuPressed: {
if (model.running) {
// This will primarily be keyboard/gamepad driven so use
// open() instead of popup()
appContextMenu.open()
}
}
function doQuitGame() {
quitAppDialog.appName = appModel.getRunningAppName()
quitAppDialog.segueToStream = false
quitAppDialog.open()
}
Menu {
NavigableMenu {
id: appContextMenu
NavigableMenuItem {
parentMenu: appContextMenu
text: model.running ? "Resume Game" : "Launch Game"
onTriggered: {
appContextMenu.close()
@ -178,6 +187,7 @@ GridView {
}
}
NavigableMenuItem {
parentMenu: appContextMenu
text: "Quit Game"
onTriggered: doQuitGame()
visible: model.running

View file

@ -0,0 +1,8 @@
import QtQuick 2.0
import QtQuick.Controls 2.2
Menu {
onOpened: {
itemAt(0).forceActiveFocus(Qt.TabFocusReason)
}
}

View file

@ -2,6 +2,10 @@ import QtQuick 2.0
import QtQuick.Controls 2.2
MenuItem {
// Qt 5.10 has a menu property, but we need to support 5.9
// so we must make our own.
property Menu parentMenu
// Ensure focus can't be given to an invisible item
enabled: visible
height: visible ? implicitHeight : 0
@ -10,4 +14,8 @@ MenuItem {
Keys.onReturnPressed: {
triggered()
}
Keys.onEscapePressed: {
parentMenu.close()
}
}

View file

@ -135,14 +135,10 @@ GridView {
wrapMode: Text.Wrap
}
Menu {
NavigableMenu {
id: pcContextMenu
NavigableMenuItem {
text: "Wake PC"
onTriggered: computerModel.wakeComputer(index)
visible: !model.addPc && !model.online && model.wakeable
}
NavigableMenuItem {
parentMenu: pcContextMenu
text: "Delete PC"
onTriggered: {
deletePcDialog.pcIndex = index
@ -150,6 +146,12 @@ GridView {
deletePcDialog.open()
}
}
NavigableMenuItem {
parentMenu: pcContextMenu
text: "Wake PC"
onTriggered: computerModel.wakeComputer(index)
visible: !model.addPc && !model.online && model.wakeable
}
}
onClicked: {

View file

@ -13,5 +13,6 @@
<file>gui/CliQuitStreamSegue.qml</file>
<file>gui/CliStartStreamSegue.qml</file>
<file>gui/AutoResizingComboBox.qml</file>
<file>gui/NavigableMenu.qml</file>
</qresource>
</RCC>