The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

174 lines
6.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_PROPERTYPANEL_H_INCLUDED
  18. #define JUCE_PROPERTYPANEL_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A panel that holds a list of PropertyComponent objects.
  22. This panel displays a list of PropertyComponents, and allows them to be organised
  23. into collapsible sections.
  24. To use, simply create one of these and add your properties to it with addProperties()
  25. or addSection().
  26. @see PropertyComponent
  27. */
  28. class JUCE_API PropertyPanel : public Component
  29. {
  30. public:
  31. //==============================================================================
  32. /** Creates an empty property panel. */
  33. PropertyPanel();
  34. /** Creates an empty property panel. */
  35. PropertyPanel (const String& name);
  36. /** Destructor. */
  37. ~PropertyPanel();
  38. //==============================================================================
  39. /** Deletes all property components from the panel. */
  40. void clear();
  41. /** Adds a set of properties to the panel.
  42. The components in the list will be owned by this object and will be automatically
  43. deleted later on when no longer needed.
  44. These properties are added without them being inside a named section. If you
  45. want them to be kept together in a collapsible section, use addSection() instead.
  46. */
  47. void addProperties (const Array<PropertyComponent*>& newPropertyComponents);
  48. /** Adds a set of properties to the panel.
  49. These properties are added under a section heading with a plus/minus button that
  50. allows it to be opened and closed. If indexToInsertAt is < 0 then it will be added
  51. at the end of the list, or before the given index if the index is non-zero.
  52. The components in the list will be owned by this object and will be automatically
  53. deleted later on when no longer needed.
  54. To add properies without them being in a section, use addProperties().
  55. */
  56. void addSection (const String& sectionTitle,
  57. const Array<PropertyComponent*>& newPropertyComponents,
  58. bool shouldSectionInitiallyBeOpen = true,
  59. int indexToInsertAt = -1);
  60. /** Calls the refresh() method of all PropertyComponents in the panel */
  61. void refreshAll() const;
  62. /** Returns true if the panel contains no properties. */
  63. bool isEmpty() const;
  64. /** Returns the height that the panel needs in order to display all of its content
  65. without scrolling.
  66. */
  67. int getTotalContentHeight() const;
  68. //==============================================================================
  69. /** Returns a list of all the names of sections in the panel.
  70. These are the sections that have been added with addSection().
  71. */
  72. StringArray getSectionNames() const;
  73. /** Returns true if the section at this index is currently open.
  74. The index is from 0 up to the number of items returned by getSectionNames().
  75. */
  76. bool isSectionOpen (int sectionIndex) const;
  77. /** Opens or closes one of the sections.
  78. The index is from 0 up to the number of items returned by getSectionNames().
  79. */
  80. void setSectionOpen (int sectionIndex, bool shouldBeOpen);
  81. /** Enables or disables one of the sections.
  82. The index is from 0 up to the number of items returned by getSectionNames().
  83. */
  84. void setSectionEnabled (int sectionIndex, bool shouldBeEnabled);
  85. /** Remove one of the sections using the section index.
  86. The index is from 0 up to the number of items returned by getSectionNames().
  87. */
  88. void removeSection (int sectionIndex);
  89. //==============================================================================
  90. /** Saves the current state of open/closed sections so it can be restored later.
  91. The caller is responsible for deleting the object that is returned.
  92. To restore this state, use restoreOpennessState().
  93. @see restoreOpennessState
  94. */
  95. XmlElement* getOpennessState() const;
  96. /** Restores a previously saved arrangement of open/closed sections.
  97. This will try to restore a snapshot of the panel's state that was created by
  98. the getOpennessState() method. If any of the sections named in the original
  99. XML aren't present, they will be ignored.
  100. @see getOpennessState
  101. */
  102. void restoreOpennessState (const XmlElement& newState);
  103. //==============================================================================
  104. /** Sets a message to be displayed when there are no properties in the panel.
  105. The default message is "nothing selected".
  106. */
  107. void setMessageWhenEmpty (const String& newMessage);
  108. /** Returns the message that is displayed when there are no properties.
  109. @see setMessageWhenEmpty
  110. */
  111. const String& getMessageWhenEmpty() const noexcept;
  112. //==============================================================================
  113. /** @internal */
  114. void paint (Graphics&) override;
  115. /** @internal */
  116. void resized() override;
  117. private:
  118. Viewport viewport;
  119. struct SectionComponent;
  120. struct PropertyHolderComponent;
  121. PropertyHolderComponent* propertyHolderComponent;
  122. String messageWhenEmpty;
  123. void init();
  124. void updatePropHolderLayout() const;
  125. void updatePropHolderLayout (int width) const;
  126. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PropertyPanel)
  127. };
  128. #endif // JUCE_PROPERTYPANEL_H_INCLUDED