diff --git a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp index 8a5e77c320..557e312dbb 100644 --- a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp +++ b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp @@ -57,6 +57,7 @@ #include "RimEnsembleCurveSet.h" #include "RimRegularLegendConfig.h" #include "cafTitledOverlayFrame.h" +#include "RimEnsembleCurveSetCollection.h" //-------------------------------------------------------------------------------------------------- /// @@ -164,6 +165,40 @@ void RiuSummaryQwtPlot::setZoomWindow(const QwtInterval& leftAxis, const QwtInte } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuSummaryQwtPlot::updateEnsembleLegendLayout() +{ + const int startMarginX = 65; + const int startMarginY = 35; + const int spacing = 5; + + int xpos = startMarginX; + int ypos = startMarginY; + int maxColumnWidth = 0; + + for (RimEnsembleCurveSet * curveSet : ownerPlotDefinition()->ensembleCurveSets()->curveSets()) + { + auto pairIt = m_ensembleLegendWidgets.find(curveSet); + if (pairIt != m_ensembleLegendWidgets.end()) + { + if (ypos + pairIt->second->height() + spacing > this->canvas()->height()) + { + xpos += spacing + maxColumnWidth; + ypos = startMarginY; + maxColumnWidth = 0; + } + + RiuCvfOverlayItemWidget* overlayWidget = pairIt->second; + overlayWidget->move(xpos, ypos); + + ypos += pairIt->second->height() + spacing; + maxColumnWidth = std::max(maxColumnWidth, pairIt->second->width()); + } + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -175,10 +210,11 @@ void RiuSummaryQwtPlot::addOrUpdateEnsembleCurveSetLegend(RimEnsembleCurveSet * if (it == m_ensembleLegendWidgets.end() || it->second == nullptr) { overlayWidget = new RiuCvfOverlayItemWidget(this); + new RiuWidgetDragger(overlayWidget); m_ensembleLegendWidgets[curveSetToShowLegendFor] = overlayWidget; - overlayWidget->move(65, 30); + } else { @@ -193,6 +229,8 @@ void RiuSummaryQwtPlot::addOrUpdateEnsembleCurveSetLegend(RimEnsembleCurveSet * overlayWidget->updateFromOverlyItem(curveSetToShowLegendFor->legendConfig()->titledOverlayFrame()); overlayWidget->show(); } + + this->updateEnsembleLegendLayout(); } //-------------------------------------------------------------------------------------------------- @@ -207,6 +245,8 @@ void RiuSummaryQwtPlot::removeEnsembleCurveSetLegend(RimEnsembleCurveSet * curve m_ensembleLegendWidgets.erase(it); } + + this->updateEnsembleLegendLayout(); } //-------------------------------------------------------------------------------------------------- @@ -237,6 +277,15 @@ void RiuSummaryQwtPlot::contextMenuEvent(QContextMenuEvent* event) } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuSummaryQwtPlot::resizeEvent(QResizeEvent *e) +{ + QwtPlot::resizeEvent(e); + updateEnsembleLegendLayout(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.h b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.h index 69f35ecb00..28829053f0 100644 --- a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.h +++ b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.h @@ -78,10 +78,12 @@ protected: virtual QSize sizeHint() const override; virtual QSize minimumSizeHint() const override; virtual void contextMenuEvent(QContextMenuEvent *) override; + virtual void resizeEvent(QResizeEvent *e) override; private: void setDefaults(); void selectClosestCurve(const QPoint& pos); + void updateEnsembleLegendLayout(); private slots: void onZoomedSlot( );