From dc10e6136625f413b442e2b36bdc323e06afa490 Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 31 Mar 2017 14:24:53 +0100 Subject: [PATCH] Added ConcertinaPanel::setCustomPanelHeader() method to allow custom components to be used as ConcertinaPanel headers --- .../layout/juce_ConcertinaPanel.cpp | 42 ++++++++++++++++--- .../layout/juce_ConcertinaPanel.h | 13 ++++++ 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/modules/juce_gui_basics/layout/juce_ConcertinaPanel.cpp b/modules/juce_gui_basics/layout/juce_ConcertinaPanel.cpp index 9b0a9f9b75..a1083c4855 100644 --- a/modules/juce_gui_basics/layout/juce_ConcertinaPanel.cpp +++ b/modules/juce_gui_basics/layout/juce_ConcertinaPanel.cpp @@ -219,16 +219,25 @@ public: void paint (Graphics& g) override { - const Rectangle area (getWidth(), getHeaderSize()); - g.reduceClipRegion (area); + if (customHeaderComponent == nullptr) + { + const Rectangle area (getWidth(), getHeaderSize()); + g.reduceClipRegion (area); - getLookAndFeel().drawConcertinaPanelHeader (g, area, isMouseOver(), isMouseButtonDown(), - getPanel(), *component); + getLookAndFeel().drawConcertinaPanelHeader (g, area, isMouseOver(), isMouseButtonDown(), + getPanel(), *component); + } } void resized() override { - component->setBounds (getLocalBounds().withTop (getHeaderSize())); + auto bounds = getLocalBounds(); + auto headerBounds = bounds.removeFromTop (getHeaderSize()); + + if (customHeaderComponent != nullptr) + customHeaderComponent->setBounds (headerBounds); + + component->setBounds (bounds); } void mouseDown (const MouseEvent&) override @@ -250,11 +259,23 @@ public: getPanel().panelHeaderDoubleClicked (component); } + void setCustomHeaderComponent (Component* headerComponent, bool shouldTakeOwnership) + { + customHeaderComponent.set (headerComponent, shouldTakeOwnership); + + if (headerComponent != nullptr) + { + addAndMakeVisible (customHeaderComponent); + customHeaderComponent->addMouseListener (this, false); + } + } + OptionalScopedPointer component; private: PanelSizes dragStartSizes; int mouseDownY; + OptionalScopedPointer customHeaderComponent; int getHeaderSize() const noexcept { @@ -362,6 +383,17 @@ void ConcertinaPanel::setPanelHeaderSize (Component* component, int headerSize) } } +void ConcertinaPanel::setCustomPanelHeader (Component* component, Component* customComponent, bool takeOwnership) +{ + OptionalScopedPointer optional (customComponent, takeOwnership); + + const auto index = indexOfComp (component); + jassert (index >= 0); // The specified component doesn't seem to have been added! + + if (index >= 0) + holders.getUnchecked (index)->setCustomHeaderComponent (optional.release(), takeOwnership); +} + void ConcertinaPanel::resized() { applyLayout (getFittedSizes(), false); diff --git a/modules/juce_gui_basics/layout/juce_ConcertinaPanel.h b/modules/juce_gui_basics/layout/juce_ConcertinaPanel.h index 851b5cf029..aa12b7e15b 100644 --- a/modules/juce_gui_basics/layout/juce_ConcertinaPanel.h +++ b/modules/juce_gui_basics/layout/juce_ConcertinaPanel.h @@ -92,6 +92,19 @@ public: /** Sets the height of the header section for one of the panels. */ void setPanelHeaderSize (Component* panelComponent, int headerSize); + /** Sets a custom header Component for one of the panels. + + @param panelComponent the panel component to add the custom header to. + @param customHeaderComponent the custom component to use for the panel header. + This can be nullptr to clear the custom header component + and just use the standard LookAndFeel panel. + @param takeOwnership if true, then the PanelHolder will take ownership + of the custom header component, and will delete it later when + it's no longer needed. If false, it won't delete it, and + you must make sure it doesn't get deleted while in use. + */ + void setCustomPanelHeader (Component* panelComponent, Component* customHeaderComponent, bool takeOwnership); + //============================================================================== /** This abstract base class is implemented by LookAndFeel classes. */ struct JUCE_API LookAndFeelMethods