2015-01-04 23:06:57 +05:30
|
|
|
// Copyright 2014 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2016-01-25 02:24:04 +05:30
|
|
|
#pragma once
|
|
|
|
|
2018-08-07 10:13:07 +05:30
|
|
|
#include <map>
|
2014-04-01 07:56:50 +05:30
|
|
|
|
2015-06-21 19:28:59 +05:30
|
|
|
class QDialog;
|
2014-04-01 07:56:50 +05:30
|
|
|
class QKeySequence;
|
|
|
|
class QSettings;
|
2015-06-21 19:28:59 +05:30
|
|
|
class QShortcut;
|
2014-04-01 07:56:50 +05:30
|
|
|
|
2018-08-07 10:13:07 +05:30
|
|
|
class HotkeyRegistry final {
|
|
|
|
public:
|
2018-05-23 01:00:36 +05:30
|
|
|
friend class ConfigureHotkeys;
|
2018-08-07 10:13:07 +05:30
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
/**
|
2018-05-23 01:00:36 +05:30
|
|
|
* Returns a QKeySequence object who signal can be connected to QAction->SetShortcut.
|
2018-08-07 10:13:07 +05:30
|
|
|
*
|
2018-05-23 01:00:36 +05:30
|
|
|
* @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 shortcutcontext belongs to (e.g. "Main Window", "Debugger").
|
|
|
|
* @param action Name of the action (e.g. "Start Emulation", "Load Image").
|
2018-08-07 10:13:07 +05:30
|
|
|
*/
|
2018-05-23 01:00:36 +05:30
|
|
|
Qt::ShortcutContext GetShortcutContext(const QString& group, const QString& action);
|
2018-08-07 10:13:07 +05:30
|
|
|
|
|
|
|
private:
|
|
|
|
struct Hotkey {
|
2018-05-23 01:00:36 +05:30
|
|
|
Hotkey() : shortcut(nullptr), context(Qt::WindowShortcut) {}
|
|
|
|
|
2018-08-07 10:13:07 +05:30
|
|
|
QKeySequence keyseq;
|
|
|
|
QShortcut* shortcut = nullptr;
|
|
|
|
Qt::ShortcutContext context = Qt::WindowShortcut;
|
|
|
|
};
|
|
|
|
|
|
|
|
using HotkeyMap = std::map<QString, Hotkey>;
|
|
|
|
using HotkeyGroupMap = std::map<QString, HotkeyMap>;
|
|
|
|
|
|
|
|
HotkeyGroupMap hotkey_groups;
|
|
|
|
};
|