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);
hk.context = static_cast<Qt::ShortcutContext>(shortcut.shortcut.context);
}
if (hk.shortcut) {
hk.shortcut->disconnect();
hk.shortcut->setKey(hk.keyseq);
for(auto const& [_, hotkey_shortcut] : hk.shortcuts) {
if (hotkey_shortcut) {
hotkey_shortcut->disconnect();
hotkey_shortcut->setKey(hk.keyseq);
}
}
}
}
QShortcut* HotkeyRegistry::GetHotkey(const QString& group, const QString& action, QObject* widget) {
Hotkey& hk = hotkey_groups[group][action];
QShortcut* shortcut = hk.shortcuts[widget->objectName()];
if (!hk.shortcut) {
hk.shortcut = new QShortcut(hk.keyseq, widget, nullptr, nullptr, hk.context);
if (!shortcut) {
shortcut = new QShortcut(hk.keyseq, widget, nullptr, nullptr, hk.context);
}
return hk.shortcut;
return shortcut;
}
QKeySequence HotkeyRegistry::GetKeySequence(const QString& group, const QString& action) {

View File

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