Merge branch 'master' into windows-clang

This commit is contained in:
qurious-pixel 2025-10-16 03:28:09 -07:00 committed by GitHub
commit 97a1a50bd2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 47 additions and 29 deletions

View file

@ -39,6 +39,7 @@ shortcut_dialog::shortcut_dialog(const std::shared_ptr<gui_settings> gui_setting
key_sequence_edit->setObjectName(shortcut.name);
key_sequence_edit->setMinimumWidth(label->sizeHint().width());
key_sequence_edit->setKeySequence(key_sequence);
key_sequence_edit->setClearButtonEnabled(true);
m_values[shortcut.name] = key_sequence.toString();

View file

@ -17,22 +17,32 @@ shortcut_handler::shortcut_handler(gui::shortcuts::shortcut_handler_id handler_i
continue;
}
const QKeySequence key_sequence = sc_settings.get_key_sequence(info, gui_settings);
QShortcut* shortcut = new QShortcut(key_sequence, parent);
shortcut->setAutoRepeat(info.allow_auto_repeat);
QKeySequence key_sequence = sc_settings.get_key_sequence(info, gui_settings);
shortcut_key_info key_info{};
key_info.shortcut = shortcut;
key_info.shortcut = make_shortcut(shortcut_key, info, key_sequence);
key_info.info = info;
key_info.key_sequence = key_sequence;
key_info.key_sequence = std::move(key_sequence);
m_shortcuts[shortcut_key] = key_info;
m_shortcuts[shortcut_key] = std::move(key_info);
}
}
connect(shortcut, &QShortcut::activated, this, [this, key = shortcut_key]()
QShortcut* shortcut_handler::make_shortcut(gui::shortcuts::shortcut key, const shortcut_info& info, const QKeySequence& key_sequence)
{
if (key_sequence.isEmpty())
{
return nullptr;
}
QShortcut* shortcut = new QShortcut(key_sequence, parent());
shortcut->setAutoRepeat(info.allow_auto_repeat);
connect(shortcut, &QShortcut::activated, this, [this, key]()
{
handle_shortcut(key, m_shortcuts[key].key_sequence);
});
connect(shortcut, &QShortcut::activatedAmbiguously, this, [this, key = shortcut_key]()
connect(shortcut, &QShortcut::activatedAmbiguously, this, [this, key]()
{
// TODO: do not allow same shortcuts and remove this connect
// activatedAmbiguously will trigger if you have the same key sequence for several shortcuts
@ -40,7 +50,8 @@ shortcut_handler::shortcut_handler(gui::shortcuts::shortcut_handler_id handler_i
shortcut_log.error("%s: Shortcut activated ambiguously: %s (%s)", m_handler_id, key, key_sequence.toString());
handle_shortcut(key, key_sequence);
});
}
return shortcut;
}
void shortcut_handler::update()
@ -61,11 +72,24 @@ void shortcut_handler::update()
shortcut_key_info& key_info = m_shortcuts[shortcut_key];
key_info.key_sequence = key_sequence;
if (key_info.shortcut)
{
if (key_sequence.isEmpty())
{
key_info.shortcut->deleteLater();
key_info.shortcut = nullptr;
}
else
{
key_info.shortcut->setKey(key_sequence);
}
}
else
{
key_info.shortcut = make_shortcut(shortcut_key, info, key_sequence);
}
}
}
void shortcut_handler::handle_shortcut(gui::shortcuts::shortcut shortcut_key, const QKeySequence& key_sequence)

View file

@ -23,6 +23,7 @@ public Q_SLOTS:
private:
void handle_shortcut(gui::shortcuts::shortcut shortcut_key, const QKeySequence& key_sequence);
QShortcut* make_shortcut(gui::shortcuts::shortcut key, const shortcut_info& info, const QKeySequence& key_sequence);
gui::shortcuts::shortcut_handler_id m_handler_id;
std::shared_ptr<gui_settings> m_gui_settings;

View file

@ -114,13 +114,5 @@ QKeySequence shortcut_settings::get_key_sequence(const shortcut_info& entry, con
const QString saved_value = gui_settings->GetValue(get_shortcut_gui_save(entry.name)).toString();
QKeySequence key_sequence = QKeySequence::fromString(saved_value);
if (key_sequence.isEmpty())
{
// Use the default shortcut if no shortcut was configured
key_sequence = QKeySequence::fromString(entry.key_sequence);
}
return key_sequence;
return QKeySequence::fromString(saved_value);
}