diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellRftEnsembleCurveSet.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellRftEnsembleCurveSet.cpp index f3c3659831..2977942626 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellRftEnsembleCurveSet.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellRftEnsembleCurveSet.cpp @@ -105,7 +105,7 @@ void RimWellRftEnsembleCurveSet::setColorMode( ColorMode mode ) void RimWellRftEnsembleCurveSet::initializeLegend() { auto ensembleParam = m_ensemble->ensembleParameter( m_ensembleParameter ); - m_ensembleLegendConfig->setTitle( m_ensemble->name() + ":\n" + m_ensembleParameter ); + m_ensembleLegendConfig->setTitle( m_ensemble->name() + "\n" + m_ensembleParameter ); RimEnsembleCurveSetColorManager::initializeLegendConfig( m_ensembleLegendConfig, ensembleParam ); } diff --git a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSet.cpp b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSet.cpp index 6f57489cab..dec25d467b 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSet.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSet.cpp @@ -897,6 +897,7 @@ void RimEnsembleCurveSet::updateCurveColors() plot->viewer()->overlayMargins() ); } m_legendOverlayFrame->setContentFrame( m_legendConfig->makeLegendFrame() ); + plot->viewer()->addOverlayFrame( m_legendOverlayFrame ); } else { diff --git a/ApplicationCode/UserInterface/RiuAbstractLegendFrame.cpp b/ApplicationCode/UserInterface/RiuAbstractLegendFrame.cpp index 7b36c9c6e8..011e43218c 100644 --- a/ApplicationCode/UserInterface/RiuAbstractLegendFrame.cpp +++ b/ApplicationCode/UserInterface/RiuAbstractLegendFrame.cpp @@ -41,11 +41,13 @@ QSize RiuAbstractLegendFrame::sizeHint() const layoutInfo( &layout ); QFontMetrics fontMetrics( this->font() ); - QStringList titleLines = m_title.split( "\n", QString::SkipEmptyParts ); + QRect titleRect = fontMetrics.boundingRect( QRect( 0, 0, 200, 200 ), Qt::AlignLeft, m_title ); - int preferredContentHeight = titleLines.size() * layout.lineSpacing + labelCount() * layout.lineSpacing; + int preferredContentHeight = titleRect.height() + labelCount() * layout.lineSpacing; int preferredHeight = preferredContentHeight + layout.margins.top() + layout.margins.bottom(); + int titleWidth = titleRect.width() + layout.margins.left() + layout.margins.right(); + int maxTickTextWidth = 0; for ( int i = 0; i < labelCount(); ++i ) { @@ -57,7 +59,7 @@ QSize RiuAbstractLegendFrame::sizeHint() const int preferredWidth = layout.tickEndX + layout.margins.left() + layout.margins.right() + layout.tickTextLeadSpace + maxTickTextWidth; - preferredWidth = std::max( preferredWidth, fontMetrics.boundingRect( m_title ).width() ); + preferredWidth = std::max( preferredWidth, titleWidth ); preferredWidth = std::min( preferredWidth, 400 ); return QSize( preferredWidth, preferredHeight ); @@ -72,10 +74,11 @@ QSize RiuAbstractLegendFrame::minimumSizeHint() const layoutInfo( &layout ); QFontMetrics fontMetrics( this->font() ); - QStringList titleLines = m_title.split( "\n", QString::SkipEmptyParts ); + QRect titleRect = fontMetrics.boundingRect( QRect( 0, 0, 200, 200 ), Qt::AlignLeft, m_title ); - int preferredContentHeight = titleLines.size() * layout.lineSpacing + 2 * layout.lineSpacing; + int preferredContentHeight = titleRect.height() + 2 * layout.lineSpacing; int preferredHeight = preferredContentHeight + layout.margins.top() + layout.margins.bottom(); + int titleWidth = titleRect.width() + layout.margins.left() + layout.margins.right(); int firstTextWidth = fontMetrics.boundingRect( label( 0 ) ).width(); int lastTextWidth = fontMetrics.boundingRect( label( labelCount() - 1 ) ).width(); @@ -84,7 +87,7 @@ QSize RiuAbstractLegendFrame::minimumSizeHint() const int preferredWidth = layout.tickEndX + layout.margins.left() + layout.margins.right() + layout.tickTextLeadSpace + maxTickTextWidth; - preferredWidth = std::max( preferredWidth, fontMetrics.boundingRect( m_title ).width() ); + preferredWidth = std::max( preferredWidth, titleWidth ); preferredWidth = std::min( preferredWidth, 400 ); return QSize( preferredWidth, preferredHeight ); @@ -100,10 +103,11 @@ void RiuAbstractLegendFrame::renderTo( QPainter* painter, const QRect& targetRec painter->save(); painter->translate( targetRect.topLeft() ); - QPoint titlePos( layout.margins.left(), layout.margins.top() + layout.lineSpacing / 2 ); - painter->drawText( titlePos, m_title ); - - QStringList titleLines = m_title.split( "\n", QString::SkipEmptyParts ); + QPoint titlePos( layout.margins.left(), layout.margins.top() ); + QFontMetrics fontMetrics( this->font() ); + QRect boundingRect = fontMetrics.boundingRect( targetRect, Qt::AlignLeft, m_title ); + boundingRect.moveTo( titlePos ); + painter->drawText( boundingRect, m_title ); std::vector> visibleTickLabels = visibleLabels( layout ); for ( auto tickLabel : visibleTickLabels ) diff --git a/ApplicationCode/UserInterface/RiuDraggableOverlayFrame.cpp b/ApplicationCode/UserInterface/RiuDraggableOverlayFrame.cpp index b55daa5442..9d5719116d 100644 --- a/ApplicationCode/UserInterface/RiuDraggableOverlayFrame.cpp +++ b/ApplicationCode/UserInterface/RiuDraggableOverlayFrame.cpp @@ -112,8 +112,12 @@ RiuDraggableOverlayFrame::AnchorCorner RiuDraggableOverlayFrame::anchorCorner() //-------------------------------------------------------------------------------------------------- QSize RiuDraggableOverlayFrame::sizeHint() const { - QSize contentSize = m_contentFrame->sizeHint(); - return QSize( contentSize.width() + 2, contentSize.height() + 2 ); + if ( m_contentFrame ) + { + QSize contentSize = m_contentFrame->sizeHint(); + return QSize( contentSize.width() + 2, contentSize.height() + 2 ); + } + return QSize( 0, 0 ); } //-------------------------------------------------------------------------------------------------- @@ -121,6 +125,10 @@ QSize RiuDraggableOverlayFrame::sizeHint() const //-------------------------------------------------------------------------------------------------- QSize RiuDraggableOverlayFrame::minimumSizeHint() const { - QSize contentSize = m_contentFrame->minimumSizeHint(); - return QSize( contentSize.width() + 2, contentSize.height() + 2 ); + if ( m_contentFrame ) + { + QSize contentSize = m_contentFrame->minimumSizeHint(); + return QSize( contentSize.width() + 2, contentSize.height() + 2 ); + } + return QSize( 0, 0 ); } diff --git a/ApplicationCode/UserInterface/RiuScalarMapperLegendFrame.cpp b/ApplicationCode/UserInterface/RiuScalarMapperLegendFrame.cpp index a94ba7ae4e..55fe1b7558 100644 --- a/ApplicationCode/UserInterface/RiuScalarMapperLegendFrame.cpp +++ b/ApplicationCode/UserInterface/RiuScalarMapperLegendFrame.cpp @@ -160,12 +160,10 @@ int RiuScalarMapperLegendFrame::rectCount() const void RiuScalarMapperLegendFrame::renderRect( QPainter* painter, const LayoutInfo& layout, int rectIndex ) const { int rectIndexFromBottom = rectCount() - rectIndex - 1; - cvf::Color3ub startColor = m_scalarMapper->mapToColor( - m_scalarMapper->domainValue( m_tickValues[rectIndexFromBottom] ) ); - cvf::Color3ub endColor = m_scalarMapper->mapToColor( - m_scalarMapper->domainValue( m_tickValues[rectIndexFromBottom + 1] ) ); - QColor startQColor( startColor.r(), startColor.g(), startColor.b() ); - QColor endQColor( endColor.r(), endColor.g(), endColor.b() ); + cvf::Color3ub startColor = m_scalarMapper->mapToColor( m_tickValues[rectIndexFromBottom] ); + cvf::Color3ub endColor = m_scalarMapper->mapToColor( m_tickValues[rectIndexFromBottom + 1] ); + QColor startQColor( startColor.r(), startColor.g(), startColor.b() ); + QColor endQColor( endColor.r(), endColor.g(), endColor.b() ); QRectF gradientRect( QPointF( layout.tickStartX, layout.colorBarRect.bottom() - layout.tickYPixelPos[rectIndexFromBottom] + 1 ),