hotkeys.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <map>
  6. class QDialog;
  7. class QKeySequence;
  8. class QSettings;
  9. class QShortcut;
  10. class HotkeyRegistry final {
  11. public:
  12. friend class ConfigureHotkeys;
  13. explicit HotkeyRegistry();
  14. ~HotkeyRegistry();
  15. /**
  16. * Loads hotkeys from the settings file.
  17. *
  18. * @note Yet unregistered hotkeys which are present in the settings will automatically be
  19. * registered.
  20. */
  21. void LoadHotkeys();
  22. /**
  23. * Saves all registered hotkeys to the settings file.
  24. *
  25. * @note Each hotkey group will be stored a settings group; For each hotkey inside that group, a
  26. * settings group will be created to store the key sequence and the hotkey context.
  27. */
  28. void SaveHotkeys();
  29. /**
  30. * Returns a QShortcut object whose activated() signal can be connected to other QObjects'
  31. * slots.
  32. *
  33. * @param group General group this hotkey belongs to (e.g. "Main Window", "Debugger").
  34. * @param action Name of the action (e.g. "Start Emulation", "Load Image").
  35. * @param widget Parent widget of the returned QShortcut.
  36. * @warning If multiple QWidgets' call this function for the same action, the returned QShortcut
  37. * will be the same. Thus, you shouldn't rely on the caller really being the
  38. * QShortcut's parent.
  39. */
  40. QShortcut* GetHotkey(const QString& group, const QString& action, QWidget* widget);
  41. /**
  42. * Returns a QKeySequence object whose signal can be connected to QAction::setShortcut.
  43. *
  44. * @param group General group this hotkey belongs to (e.g. "Main Window", "Debugger").
  45. * @param action Name of the action (e.g. "Start Emulation", "Load Image").
  46. */
  47. QKeySequence GetKeySequence(const QString& group, const QString& action);
  48. /**
  49. * Returns a Qt::ShortcutContext object who can be connected to other
  50. * QAction::setShortcutContext.
  51. *
  52. * @param group General group this shortcut context belongs to (e.g. "Main Window",
  53. * "Debugger").
  54. * @param action Name of the action (e.g. "Start Emulation", "Load Image").
  55. */
  56. Qt::ShortcutContext GetShortcutContext(const QString& group, const QString& action);
  57. private:
  58. struct Hotkey {
  59. QKeySequence keyseq;
  60. QShortcut* shortcut = nullptr;
  61. Qt::ShortcutContext context = Qt::WindowShortcut;
  62. };
  63. using HotkeyMap = std::map<QString, Hotkey>;
  64. using HotkeyGroupMap = std::map<QString, HotkeyMap>;
  65. HotkeyGroupMap hotkey_groups;
  66. };