From d0b8a775075085678df38e9c6d63c551823f1162 Mon Sep 17 00:00:00 2001 From: Khang Tran Date: Tue, 23 Apr 2024 15:47:03 -0400 Subject: [PATCH] Fix #19987 Menu Navigation not working with Left/Right arrows Add a force close upon using Right Arrow on a non-submenu item Use signals when appropriate to invoke openPrevMenu/openNextMenu Add hasSiblingMenus property to allow context menus using the StyledMenu class to be closed using left/right arrow key --- src/appshell/qml/platform/AppMenuBar.qml | 9 +++++++++ src/appshell/view/navigableappmenumodel.cpp | 13 ++++++++++++- src/appshell/view/navigableappmenumodel.h | 2 ++ .../qml/Muse/UiComponents/StyledMenuLoader.qml | 11 +++++++++++ .../qml/Muse/UiComponents/internal/StyledMenu.qml | 13 +++++++++++++ 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/appshell/qml/platform/AppMenuBar.qml b/src/appshell/qml/platform/AppMenuBar.qml index 3b76416dceeaf..1a57ffac7a746 100644 --- a/src/appshell/qml/platform/AppMenuBar.qml +++ b/src/appshell/qml/platform/AppMenuBar.qml @@ -205,11 +205,20 @@ ListView { id: menuLoader property string menuId: "" + property bool hasSiblingMenus: true onHandleMenuItem: function(itemId) { Qt.callLater(appMenuModel.handleMenuItem, itemId) } + onOpenPrevMenu: { + appMenuModel.openPrevMenu() + } + + onOpenNextMenu: { + appMenuModel.openNextMenu() + } + onOpened: { appMenuModel.openedMenuId = menuLoader.menuId } diff --git a/src/appshell/view/navigableappmenumodel.cpp b/src/appshell/view/navigableappmenumodel.cpp index f46673e865638..c2673de21da46 100644 --- a/src/appshell/view/navigableappmenumodel.cpp +++ b/src/appshell/view/navigableappmenumodel.cpp @@ -97,6 +97,18 @@ void NavigableAppMenuModel::handleMenuItem(const QString& itemId) AppMenuModel::handleMenuItem(itemId); } +void NavigableAppMenuModel::openPrevMenu() +{ + navigate(Qt::Key_Left); + activateHighlightedMenu(); +} + +void NavigableAppMenuModel::openNextMenu() +{ + navigate(Qt::Key_Right); + activateHighlightedMenu(); +} + void NavigableAppMenuModel::openMenu(const QString& menuId, bool byHover) { bool navigationStarted = isNavigationStarted(); @@ -343,7 +355,6 @@ bool NavigableAppMenuModel::processEventForAppMenu(QEvent* event) default: break; } - return false; } diff --git a/src/appshell/view/navigableappmenumodel.h b/src/appshell/view/navigableappmenumodel.h index f504d9d92a007..14cdb0622e329 100644 --- a/src/appshell/view/navigableappmenumodel.h +++ b/src/appshell/view/navigableappmenumodel.h @@ -48,6 +48,8 @@ class NavigableAppMenuModel : public AppMenuModel Q_INVOKABLE void load() override; Q_INVOKABLE void handleMenuItem(const QString& itemId) override; Q_INVOKABLE void openMenu(const QString& menuId, bool byHover); + Q_INVOKABLE void openPrevMenu(); + Q_INVOKABLE void openNextMenu(); bool isNavigationStarted() const; bool isMenuOpened() const; diff --git a/src/framework/uicomponents/qml/Muse/UiComponents/StyledMenuLoader.qml b/src/framework/uicomponents/qml/Muse/UiComponents/StyledMenuLoader.qml index 57c69af8398cd..876de4bb1a5e0 100644 --- a/src/framework/uicomponents/qml/Muse/UiComponents/StyledMenuLoader.qml +++ b/src/framework/uicomponents/qml/Muse/UiComponents/StyledMenuLoader.qml @@ -29,11 +29,14 @@ Loader { id: loader signal handleMenuItem(string itemId) + signal openPrevMenu() + signal openNextMenu() signal opened() signal closed(bool force) property alias menu: loader.item property var menuAnchorItem: null + property bool hasSiblingMenus: root.hasSiblingMenus property alias isMenuOpened: loader.active @@ -62,6 +65,14 @@ Loader { Qt.callLater(loader.handleMenuItem, itemId) } + onOpenPrevMenu: { + Qt.callLater(loader.openPrevMenu) + } + + onOpenNextMenu: { + Qt.callLater(loader.openNextMenu) + } + onClosed: function(force) { Qt.callLater(prv.unloadMenu, force) } diff --git a/src/framework/uicomponents/qml/Muse/UiComponents/internal/StyledMenu.qml b/src/framework/uicomponents/qml/Muse/UiComponents/internal/StyledMenu.qml index b0e6e31582db6..dfcbc1640a4ab 100644 --- a/src/framework/uicomponents/qml/Muse/UiComponents/internal/StyledMenu.qml +++ b/src/framework/uicomponents/qml/Muse/UiComponents/internal/StyledMenu.qml @@ -33,8 +33,11 @@ MenuView { property alias model: view.model property int preferredAlign: Qt.AlignRight // Left, HCenter, Right + property bool hasSiblingMenus: loader.hasSiblingMenus signal handleMenuItem(string itemId) + signal openPrevMenu() + signal openNextMenu() property alias width: content.width property alias height: content.height @@ -138,6 +141,10 @@ MenuView { case NavigationEvent.Right: var selectedItem = prv.selectedItem() if (!Boolean(selectedItem) || !selectedItem.hasSubMenu) { + if (root.hasSiblingMenus) { + root.close(true) + root.openNextMenu() + } return } @@ -160,6 +167,10 @@ MenuView { } root.close() + + if(root.hasSiblingMenus) { + root.openPrevMenu() + } break case NavigationEvent.Up: case NavigationEvent.Down: @@ -180,6 +191,7 @@ MenuView { var menuLoaderComponent = Qt.createComponent("../StyledMenuLoader.qml"); root.subMenuLoader = menuLoaderComponent.createObject(root) root.subMenuLoader.menuAnchorItem = root.anchorItem + root.subMenuLoader.hasSiblingMenus = root.hasSiblingMenus root.subMenuLoader.handleMenuItem.connect(function(itemId) { Qt.callLater(root.handleMenuItem, itemId) @@ -195,6 +207,7 @@ MenuView { if (force) { root.close(true) + root.openNextMenu() } }) }