Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

juce_KeyMappingEditorComponent.h 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. A component to allow editing of the keymaps stored by a KeyPressMappingSet
  23. object.
  24. @see KeyPressMappingSet
  25. @tags{GUI}
  26. */
  27. class JUCE_API KeyMappingEditorComponent : public Component
  28. {
  29. public:
  30. //==============================================================================
  31. /** Creates a KeyMappingEditorComponent.
  32. @param mappingSet this is the set of mappings to display and edit. Make sure the
  33. mappings object is not deleted before this component!
  34. @param showResetToDefaultButton if true, then at the bottom of the list, the
  35. component will include a 'reset to defaults' button.
  36. */
  37. KeyMappingEditorComponent (KeyPressMappingSet& mappingSet,
  38. bool showResetToDefaultButton);
  39. /** Destructor. */
  40. ~KeyMappingEditorComponent() override;
  41. //==============================================================================
  42. /** Sets up the colours to use for parts of the component.
  43. @param mainBackground colour to use for most of the background
  44. @param textColour colour to use for the text
  45. */
  46. void setColours (Colour mainBackground,
  47. Colour textColour);
  48. /** Returns the KeyPressMappingSet that this component is acting upon. */
  49. KeyPressMappingSet& getMappings() const noexcept { return mappings; }
  50. /** Returns the ApplicationCommandManager that this component is connected to. */
  51. ApplicationCommandManager& getCommandManager() const noexcept { return mappings.getCommandManager(); }
  52. //==============================================================================
  53. /** Can be overridden if some commands need to be excluded from the list.
  54. By default this will use the KeyPressMappingSet's shouldCommandBeVisibleInEditor()
  55. method to decide what to return, but you can override it to handle special cases.
  56. */
  57. virtual bool shouldCommandBeIncluded (CommandID commandID);
  58. /** Can be overridden to indicate that some commands are shown as read-only.
  59. By default this will use the KeyPressMappingSet's shouldCommandBeReadOnlyInEditor()
  60. method to decide what to return, but you can override it to handle special cases.
  61. */
  62. virtual bool isCommandReadOnly (CommandID commandID);
  63. /** This can be overridden to let you change the format of the string used
  64. to describe a keypress.
  65. This is handy if you're using non-standard KeyPress objects, e.g. for custom
  66. keys that are triggered by something else externally. If you override the
  67. method, be sure to let the base class's method handle keys you're not
  68. interested in.
  69. */
  70. virtual String getDescriptionForKeyPress (const KeyPress& key);
  71. //==============================================================================
  72. /** A set of colour IDs to use to change the colour of various aspects of the editor.
  73. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  74. methods.
  75. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  76. */
  77. enum ColourIds
  78. {
  79. backgroundColourId = 0x100ad00, /**< The background colour to fill the editor background. */
  80. textColourId = 0x100ad01, /**< The colour for the text. */
  81. };
  82. //==============================================================================
  83. /** @internal */
  84. void parentHierarchyChanged() override;
  85. /** @internal */
  86. void resized() override;
  87. private:
  88. //==============================================================================
  89. KeyPressMappingSet& mappings;
  90. TreeView tree;
  91. TextButton resetButton;
  92. class TopLevelItem;
  93. class ChangeKeyButton;
  94. class MappingItem;
  95. class CategoryItem;
  96. class ItemComponent;
  97. std::unique_ptr<TopLevelItem> treeItem;
  98. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (KeyMappingEditorComponent)
  99. };
  100. } // namespace juce