KeyboardCustomizationSettings.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #ifndef CRYINCLUDE_EDITOR_KEYBOARD_CUSTOMIZATION_SETTINGS_H
  9. #define CRYINCLUDE_EDITOR_KEYBOARD_CUSTOMIZATION_SETTINGS_H
  10. #pragma once
  11. #include <QWidget>
  12. #include <QHash>
  13. #include <QVector>
  14. // TODO: Move to an utils class or at least namespace
  15. QString RemoveAcceleratorAmpersands(const QString& original);
  16. class SANDBOX_API KeyboardCustomizationSettings
  17. {
  18. public:
  19. struct Shortcut
  20. {
  21. QString text;
  22. QList<QKeySequence> keySequence;
  23. };
  24. using Snapshot = QHash<const QAction*, Shortcut>;
  25. KeyboardCustomizationSettings(const QString& group, QWidget* parent);
  26. virtual ~KeyboardCustomizationSettings();
  27. // Iterates over all KeyboardCustomizationSettings instances and calls EnableShortcuts()
  28. static void EnableShortcutsGlobally(bool);
  29. static void LoadDefaultsGlobally();
  30. static void SaveGlobally();
  31. // Enables or disables shortcuts. Disabling shortcuts is used when in game mode.
  32. void EnableShortcuts(bool);
  33. void Load();
  34. void Load(const Snapshot& snapshot);
  35. void LoadDefaults();
  36. void Save();
  37. Snapshot CreateSnapshot();
  38. QAction* FindActionForShortcut(QKeySequence) const;
  39. public:
  40. static void ExportToFile(QWidget* parentWindow);
  41. static void ImportFromFile(QWidget* parentWindow);
  42. private:
  43. AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
  44. const QWidget* m_parent;
  45. const QString m_group;
  46. const Snapshot m_defaults;
  47. bool m_shortcutsEnabled;
  48. Snapshot m_lastEnabledShortcuts; // just to avoid load/save IO from/to disk
  49. AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
  50. void LoadFromSnapshot(const Snapshot& snapshot);
  51. QJsonObject ExportGroup();
  52. void ImportGroup(const QJsonObject& group);
  53. void ClearShortcutsAndAccelerators();
  54. private:
  55. AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
  56. static QVector<KeyboardCustomizationSettings*> m_instances;
  57. AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
  58. };
  59. #endif //CRYINCLUDE_EDITOR_KEYBOARD_CUSTOMIZATION_SETTINGS_H