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 4.9KB

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