juce_PropertyPanel.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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 at the bottom of the list, under a section heading with
  50. a plus/minus button that allows it to be opened and closed.
  51. The components in the list will be owned by this object and will be automatically
  52. deleted later on when no longer needed.
  53. To add properies without them being in a section, use addProperties().
  54. */
  55. void addSection (const String& sectionTitle,
  56. const Array<PropertyComponent*>& newPropertyComponents,
  57. bool shouldSectionInitiallyBeOpen = true);
  58. /** Calls the refresh() method of all PropertyComponents in the panel */
  59. void refreshAll() const;
  60. /** Returns true if the panel contains no properties. */
  61. bool isEmpty() const;
  62. /** Returns the height that the panel needs in order to display all of its content
  63. without scrolling.
  64. */
  65. int getTotalContentHeight() const;
  66. //==============================================================================
  67. /** Returns a list of all the names of sections in the panel.
  68. These are the sections that have been added with addSection().
  69. */
  70. StringArray getSectionNames() const;
  71. /** Returns true if the section at this index is currently open.
  72. The index is from 0 up to the number of items returned by getSectionNames().
  73. */
  74. bool isSectionOpen (int sectionIndex) const;
  75. /** Opens or closes one of the sections.
  76. The index is from 0 up to the number of items returned by getSectionNames().
  77. */
  78. void setSectionOpen (int sectionIndex, bool shouldBeOpen);
  79. /** Enables or disables one of the sections.
  80. The index is from 0 up to the number of items returned by getSectionNames().
  81. */
  82. void setSectionEnabled (int sectionIndex, bool shouldBeEnabled);
  83. //==============================================================================
  84. /** Saves the current state of open/closed sections so it can be restored later.
  85. The caller is responsible for deleting the object that is returned.
  86. To restore this state, use restoreOpennessState().
  87. @see restoreOpennessState
  88. */
  89. XmlElement* getOpennessState() const;
  90. /** Restores a previously saved arrangement of open/closed sections.
  91. This will try to restore a snapshot of the panel's state that was created by
  92. the getOpennessState() method. If any of the sections named in the original
  93. XML aren't present, they will be ignored.
  94. @see getOpennessState
  95. */
  96. void restoreOpennessState (const XmlElement& newState);
  97. //==============================================================================
  98. /** Sets a message to be displayed when there are no properties in the panel.
  99. The default message is "nothing selected".
  100. */
  101. void setMessageWhenEmpty (const String& newMessage);
  102. /** Returns the message that is displayed when there are no properties.
  103. @see setMessageWhenEmpty
  104. */
  105. const String& getMessageWhenEmpty() const;
  106. //==============================================================================
  107. /** @internal */
  108. void paint (Graphics&) override;
  109. /** @internal */
  110. void resized() override;
  111. private:
  112. class SectionComponent;
  113. Viewport viewport;
  114. class PropertyHolderComponent;
  115. PropertyHolderComponent* propertyHolderComponent;
  116. String messageWhenEmpty;
  117. void init();
  118. void updatePropHolderLayout() const;
  119. void updatePropHolderLayout (int width) const;
  120. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PropertyPanel)
  121. };
  122. #endif // JUCE_PROPERTYPANEL_H_INCLUDED