mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2026-04-01 18:45:21 -06:00
implement qaction hotkey support on controller
This commit is contained in:
parent
20612442fa
commit
76722813b1
@ -782,6 +782,7 @@ void GMainWindow::InitializeHotkeys() {
|
||||
this->addAction(action);
|
||||
if (!primary_only)
|
||||
secondary_window->addAction(action);
|
||||
hotkey_registry.SetAction(main_window, action_name, action);
|
||||
};
|
||||
|
||||
link_action_shortcut(ui->action_Load_File, QStringLiteral("Load File"));
|
||||
|
||||
@ -54,6 +54,9 @@ void ControllerHotkeyMonitor::checkAllButtons() {
|
||||
it.lastStatus = currentStatus;
|
||||
}
|
||||
if (trigger) {
|
||||
if (it.hk->action) {
|
||||
it.hk->action->trigger();
|
||||
}
|
||||
for (auto const& [name, hotkey_shortcut] : it.hk->shortcuts) {
|
||||
if (hotkey_shortcut && hotkey_shortcut->isEnabled()) {
|
||||
QWidget* parent = qobject_cast<QWidget*>(hotkey_shortcut->parent());
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <QAction>
|
||||
#include <QShortcut>
|
||||
#include <QtGlobal>
|
||||
#include "citra_qt/hotkeys.h"
|
||||
@ -77,3 +78,8 @@ Qt::ShortcutContext HotkeyRegistry::GetShortcutContext(const QString& group,
|
||||
Hotkey& hk = hotkey_groups[group][action];
|
||||
return hk.context;
|
||||
}
|
||||
|
||||
void HotkeyRegistry::SetAction(const QString& group, const QString& action_name, QAction* action) {
|
||||
Hotkey& hk = hotkey_groups[group][action_name];
|
||||
hk.action = action;
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <QAction>
|
||||
#include <QKeySequence>
|
||||
#include <QString>
|
||||
#include "core/frontend/input.h"
|
||||
@ -22,6 +23,7 @@ struct Hotkey {
|
||||
Qt::ShortcutContext context = Qt::WindowShortcut;
|
||||
std::unique_ptr<Input::ButtonDevice> button_device = nullptr;
|
||||
std::unique_ptr<Input::ButtonDevice> button_device2 = nullptr;
|
||||
QAction* action = nullptr;
|
||||
};
|
||||
|
||||
class HotkeyRegistry final {
|
||||
@ -80,6 +82,15 @@ public:
|
||||
*/
|
||||
Qt::ShortcutContext GetShortcutContext(const QString& group, const QString& action);
|
||||
|
||||
/**
|
||||
* Stores a QAction into the appropriate hotkey, for triggering by controller
|
||||
*
|
||||
* @param group General group this shortcut context belongs to
|
||||
* @param action_name Name of the action
|
||||
* @param action The QAction to store
|
||||
*/
|
||||
void SetAction(const QString& group, const QString& action_name, QAction* action);
|
||||
|
||||
private:
|
||||
using HotkeyMap = std::map<QString, Hotkey>;
|
||||
using HotkeyGroupMap = std::map<QString, HotkeyMap>;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user