Fixed HotkeyRegistry::GetHotkey locking shortcuts to the first widget that calls it

This commit is contained in:
OpenSauce04 2024-08-02 23:43:32 +01:00
parent bf0a1348c3
commit 303c67d3c8
2 changed files with 10 additions and 7 deletions

View File

@ -33,21 +33,24 @@ void HotkeyRegistry::LoadHotkeys() {
QKeySequence::fromString(shortcut.shortcut.keyseq, QKeySequence::NativeText); QKeySequence::fromString(shortcut.shortcut.keyseq, QKeySequence::NativeText);
hk.context = static_cast<Qt::ShortcutContext>(shortcut.shortcut.context); hk.context = static_cast<Qt::ShortcutContext>(shortcut.shortcut.context);
} }
if (hk.shortcut) { for(auto const& [_, hotkey_shortcut] : hk.shortcuts) {
hk.shortcut->disconnect(); if (hotkey_shortcut) {
hk.shortcut->setKey(hk.keyseq); hotkey_shortcut->disconnect();
hotkey_shortcut->setKey(hk.keyseq);
}
} }
} }
} }
QShortcut* HotkeyRegistry::GetHotkey(const QString& group, const QString& action, QObject* widget) { QShortcut* HotkeyRegistry::GetHotkey(const QString& group, const QString& action, QObject* widget) {
Hotkey& hk = hotkey_groups[group][action]; Hotkey& hk = hotkey_groups[group][action];
QShortcut* shortcut = hk.shortcuts[widget->objectName()];
if (!hk.shortcut) { if (!shortcut) {
hk.shortcut = new QShortcut(hk.keyseq, widget, nullptr, nullptr, hk.context); shortcut = new QShortcut(hk.keyseq, widget, nullptr, nullptr, hk.context);
} }
return hk.shortcut; return shortcut;
} }
QKeySequence HotkeyRegistry::GetKeySequence(const QString& group, const QString& action) { QKeySequence HotkeyRegistry::GetKeySequence(const QString& group, const QString& action) {

View File

@ -71,7 +71,7 @@ private:
struct Hotkey { struct Hotkey {
QKeySequence keyseq; QKeySequence keyseq;
QString controller_keyseq; QString controller_keyseq;
QShortcut* shortcut = nullptr; std::map<QString, QShortcut*> shortcuts;
Qt::ShortcutContext context = Qt::WindowShortcut; Qt::ShortcutContext context = Qt::WindowShortcut;
}; };