From 8b7507ad5ca2a5a63fc04b24b0a020daceac6ac6 Mon Sep 17 00:00:00 2001 From: Dino Date: Mon, 30 Jun 2025 17:16:16 -0400 Subject: [PATCH] #1531 qt: options dlog, fix unwanted execution of entered shortcut --- client/gui-qt/menu.cpp | 27 +++++++++++++++++++++++++++ client/gui-qt/menu.h | 2 ++ client/gui-qt/shortcuts.cpp | 10 ++++++++++ 3 files changed, 39 insertions(+) diff --git a/client/gui-qt/menu.cpp b/client/gui-qt/menu.cpp index 49471ab591..c070a6c67c 100644 --- a/client/gui-qt/menu.cpp +++ b/client/gui-qt/menu.cpp @@ -1927,6 +1927,33 @@ QString mr_menu::shortcut_2_menustring(int sid) return QString(); } +/**********************************************************************//** + Inner foreach() loop of mr_menu::mr_menu::block_actions() + Implemented as separate function to avoid shadow warnings about + internal variables of foreach() inside foreach() +**************************************************************************/ +void mr_menu::block_actions_inner(const QMenu *m, bool block) +{ + foreach (QAction *a, m->actions()) { + a->blockSignals(block); + } +} + +/**********************************************************************//** + block/unblock all menu actions + Called from the shortcuts dialog line_edit so that user entered potential + new shortcuts don't get executed. See HR Bug #1531 +**************************************************************************/ +void mr_menu::block_actions(bool block) +{ + QList menus; + + menus = findChildren(); + foreach (const QMenu *m, menus) { + block_actions_inner(m, block); + } +} + /**********************************************************************//** Updates airlift menu **************************************************************************/ diff --git a/client/gui-qt/menu.h b/client/gui-qt/menu.h index ba0c0d1e02..1a173be59e 100644 --- a/client/gui-qt/menu.h +++ b/client/gui-qt/menu.h @@ -281,6 +281,7 @@ public: void execute_shortcut(int sid); QString shortcut_exist(fc_shortcut *fcs); QString shortcut_2_menustring(int sid); + void block_actions(bool block); QAction *minimap_status; QAction *scale_fonts_status; QAction *lock_status; @@ -436,6 +437,7 @@ private: fc_shortcut *fcs, QString *ret); bool shortcut_2_menustring_inner(const QMenu *m, QKeySequence seq, QString *ret); + void block_actions_inner(const QMenu *m, bool block); }; #endif // FC__MENU_H diff --git a/client/gui-qt/shortcuts.cpp b/client/gui-qt/shortcuts.cpp index 452c73f79f..5d8db8b720 100644 --- a/client/gui-qt/shortcuts.cpp +++ b/client/gui-qt/shortcuts.cpp @@ -346,6 +346,10 @@ line_edit::line_edit(): QLineEdit() { setContextMenuPolicy(Qt::NoContextMenu); setWindowModality(Qt::WindowModal); + + // block menu actions so that user entered potential + // new shortcuts don't get executed. See HR Bug #1531 + gui()->menu_bar->block_actions(TRUE); } /**********************************************************************//** @@ -360,6 +364,9 @@ void line_edit::mousePressEvent(QMouseEvent *event) fcp->sc->mouse = shc.mouse; fcp->sc->mod = shc.mod; fcp->sc->key = 0; + + // unblock menu actions + gui()->menu_bar->block_actions(FALSE); parentWidget()->close(); } @@ -376,6 +383,9 @@ void line_edit::keyReleaseEvent(QKeyEvent *event) fcp->sc->mouse = Qt::AllButtons; fcp->sc->key = shc.key; fcp->sc->mod = shc.mod; + + // unblock menu actions + gui()->menu_bar->block_actions(FALSE); parentWidget()->close(); } -- 2.31.0