2015-01-04 11:36:57 -06:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2016-01-24 14:54:04 -06:00
|
|
|
#pragma once
|
|
|
|
|
2018-08-06 23:43:07 -05:00
|
|
|
#include <map>
|
2021-11-15 17:57:41 -06:00
|
|
|
#include "core/hid/hid_types.h"
|
2014-03-31 21:26:50 -05:00
|
|
|
|
2015-06-21 08:58:59 -05:00
|
|
|
class QDialog;
|
2014-03-31 21:26:50 -05:00
|
|
|
class QKeySequence;
|
|
|
|
class QSettings;
|
2015-06-21 08:58:59 -05:00
|
|
|
class QShortcut;
|
2021-11-15 17:57:41 -06:00
|
|
|
class ControllerShortcut;
|
|
|
|
|
|
|
|
namespace Core::HID {
|
|
|
|
enum class ControllerTriggerType;
|
|
|
|
class EmulatedController;
|
|
|
|
} // namespace Core::HID
|
|
|
|
|
|
|
|
struct ControllerButtonSequence {
|
|
|
|
Core::HID::CaptureButtonState capture{};
|
|
|
|
Core::HID::HomeButtonState home{};
|
|
|
|
Core::HID::NpadButtonState npad{};
|
|
|
|
};
|
|
|
|
|
|
|
|
class ControllerShortcut : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ControllerShortcut(Core::HID::EmulatedController* controller);
|
|
|
|
~ControllerShortcut();
|
|
|
|
|
|
|
|
void SetKey(const ControllerButtonSequence& buttons);
|
|
|
|
void SetKey(const QString& buttons_shortcut);
|
|
|
|
|
|
|
|
ControllerButtonSequence ButtonSequence() const;
|
|
|
|
|
|
|
|
void SetEnabled(bool enable);
|
|
|
|
bool IsEnabled() const;
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void Activated();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void ControllerUpdateEvent(Core::HID::ControllerTriggerType type);
|
|
|
|
|
|
|
|
bool is_enabled{};
|
|
|
|
bool active{};
|
|
|
|
int callback_key{};
|
|
|
|
ControllerButtonSequence button_sequence{};
|
|
|
|
std::string name{};
|
|
|
|
Core::HID::EmulatedController* emulated_controller = nullptr;
|
|
|
|
};
|
2014-03-31 21:26:50 -05:00
|
|
|
|
2018-08-06 23:43:07 -05:00
|
|
|
class HotkeyRegistry final {
|
|
|
|
public:
|
2019-02-16 09:19:29 -06:00
|
|
|
friend class ConfigureHotkeys;
|
2018-08-06 23:43:07 -05:00
|
|
|
|
|
|
|
explicit HotkeyRegistry();
|
|
|
|
~HotkeyRegistry();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads hotkeys from the settings file.
|
|
|
|
*
|
|
|
|
* @note Yet unregistered hotkeys which are present in the settings will automatically be
|
|
|
|
* registered.
|
|
|
|
*/
|
|
|
|
void LoadHotkeys();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves all registered hotkeys to the settings file.
|
|
|
|
*
|
|
|
|
* @note Each hotkey group will be stored a settings group; For each hotkey inside that group, a
|
|
|
|
* settings group will be created to store the key sequence and the hotkey context.
|
|
|
|
*/
|
|
|
|
void SaveHotkeys();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a QShortcut object whose activated() signal can be connected to other QObjects'
|
|
|
|
* slots.
|
|
|
|
*
|
|
|
|
* @param group General group this hotkey belongs to (e.g. "Main Window", "Debugger").
|
|
|
|
* @param action Name of the action (e.g. "Start Emulation", "Load Image").
|
|
|
|
* @param widget Parent widget of the returned QShortcut.
|
|
|
|
* @warning If multiple QWidgets' call this function for the same action, the returned QShortcut
|
|
|
|
* will be the same. Thus, you shouldn't rely on the caller really being the
|
|
|
|
* QShortcut's parent.
|
|
|
|
*/
|
|
|
|
QShortcut* GetHotkey(const QString& group, const QString& action, QWidget* widget);
|
2021-11-15 17:57:41 -06:00
|
|
|
ControllerShortcut* GetControllerHotkey(const QString& group, const QString& action,
|
|
|
|
Core::HID::EmulatedController* controller);
|
2018-08-06 23:43:07 -05:00
|
|
|
|
|
|
|
/**
|
2019-02-16 09:19:29 -06:00
|
|
|
* Returns a QKeySequence object whose signal can be connected to QAction::setShortcut.
|
2018-08-06 23:43:07 -05:00
|
|
|
*
|
2019-02-16 09:19:29 -06:00
|
|
|
* @param group General group this hotkey belongs to (e.g. "Main Window", "Debugger").
|
|
|
|
* @param action Name of the action (e.g. "Start Emulation", "Load Image").
|
|
|
|
*/
|
|
|
|
QKeySequence GetKeySequence(const QString& group, const QString& action);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a Qt::ShortcutContext object who can be connected to other
|
|
|
|
* QAction::setShortcutContext.
|
|
|
|
*
|
|
|
|
* @param group General group this shortcut context belongs to (e.g. "Main Window",
|
|
|
|
* "Debugger").
|
|
|
|
* @param action Name of the action (e.g. "Start Emulation", "Load Image").
|
2018-08-06 23:43:07 -05:00
|
|
|
*/
|
2019-02-16 09:19:29 -06:00
|
|
|
Qt::ShortcutContext GetShortcutContext(const QString& group, const QString& action);
|
2018-08-06 23:43:07 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct Hotkey {
|
|
|
|
QKeySequence keyseq;
|
2021-11-15 17:57:41 -06:00
|
|
|
QString controller_keyseq;
|
2018-08-06 23:43:07 -05:00
|
|
|
QShortcut* shortcut = nullptr;
|
2021-11-15 17:57:41 -06:00
|
|
|
ControllerShortcut* controller_shortcut = nullptr;
|
2018-08-06 23:43:07 -05:00
|
|
|
Qt::ShortcutContext context = Qt::WindowShortcut;
|
|
|
|
};
|
|
|
|
|
|
|
|
using HotkeyMap = std::map<QString, Hotkey>;
|
|
|
|
using HotkeyGroupMap = std::map<QString, HotkeyMap>;
|
|
|
|
|
|
|
|
HotkeyGroupMap hotkey_groups;
|
|
|
|
};
|