Bug #1531
openQt client, Shortcuts options dialog, try to change to used shortcut causes the used shortcut action to happen sometimes
0%
Description
Qt5, Mac 3.0 & 3.1
Game->Options->Shortcuts, from the Shortcuts options dialog press the button for an option and then enter, e.g. F8, get error msg that F8 is "ALREADY ASSIGNED TO ... Top Five Cities", and also the "Top Five Cities" report appears. Same thing for some but not all other shortcuts, I saw it for Ctrl/Meta+S "Save Game", and Ctrl/Meta+P "City Production", but not F "Fortify", not Shift+D "Disband", and not Shift+P "Pillage".
Files
Updated by Dean Brown 26 days ago
The difference between the cases where it happens and when it doesn't appears to be whether the key event is something that a QLineEdit is designed to handle. But the menu system processes the key event first, before line_edit::keyReleaseEvent() gets it, so adding a call to grabKeyboard() in line_edit::line_edit() doesn't help. A QLineEdit can have an input mask, but it won't let you allow F8 or Ctrl/Meta.
Maybe can over-ride keyReleaseEvent() at the QApplication or QMenu level? But awkward to test if there's a line_edit active.
Updated by Dean Brown 19 days ago
Dug more into this and it's frustrating. Tried overriding keyReleaseEvent() at the QMenu level but that got ugly and didn't work - my overiding function never got called. Finding out if there's a line_edit active is no problem - can test current_app()->focusWidget().
Couple more ideas -
1. have all the connected slots in menu.cpp which correspond to one of the 61 enum shortcut_id in shortcuts.h check if a line_edit is active before doing anything.
2. If there's an easy way to get a list of all the active QAction's, there's a routine bool QObject::blockSignals(bool block) that could be used to temporarily block them.
Updated by Dean Brown 18 days ago
- File 1531.patch 1531.patch added
Found a working fix. Not enough to just look at the enum shortcut_id in shortcuts.h, some menu actions are not in there, e.g. F7. Using blockSignals(bool block) works, there is code in menu.cpp to iterate over all actions, so added similar method mr_menu::block_actions(bool block)
This patch should be OK for all branches.