From 3c5c37e5a81c63363e4a28abecc1739ba7172685 Mon Sep 17 00:00:00 2001 From: Ruben Thoms Date: Tue, 6 Oct 2020 17:10:33 +0200 Subject: [PATCH] Legend title issues Fixes #6728. --- .../UserInterface/RiuAbstractLegendFrame.cpp | 10 ++++++---- .../UserInterface/RiuScalarMapperLegendFrame.cpp | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ApplicationCode/UserInterface/RiuAbstractLegendFrame.cpp b/ApplicationCode/UserInterface/RiuAbstractLegendFrame.cpp index 04c1a874d5..976b96e766 100644 --- a/ApplicationCode/UserInterface/RiuAbstractLegendFrame.cpp +++ b/ApplicationCode/UserInterface/RiuAbstractLegendFrame.cpp @@ -48,7 +48,7 @@ QSize RiuAbstractLegendFrame::sizeHint() const layoutInfo( &layout ); QFontMetrics fontMetrics( this->font() ); - QRect titleRect = fontMetrics.boundingRect( QRect( 0, 0, 200, 200 ), Qt::AlignLeft, m_title ); + QRect titleRect = fontMetrics.boundingRect( QRect( 0, 0, 200, 200 ), Qt::AlignLeft | Qt::TextWordWrap, m_title ); int preferredContentHeight = titleRect.height() + labelCount() * layout.lineSpacing + 0.5 * layout.lineSpacing; int preferredHeight = preferredContentHeight + layout.margins.top() + layout.margins.bottom(); @@ -67,7 +67,7 @@ QSize RiuAbstractLegendFrame::sizeHint() const maxTickTextWidth; preferredWidth = std::max( preferredWidth, titleWidth ); - preferredWidth = std::min( preferredWidth, 400 ); + preferredWidth = std::min( preferredWidth, 200 ); return QSize( preferredWidth, preferredHeight ); } @@ -81,7 +81,7 @@ QSize RiuAbstractLegendFrame::minimumSizeHint() const layoutInfo( &layout ); QFontMetrics fontMetrics( this->font() ); - QRect titleRect = fontMetrics.boundingRect( QRect( 0, 0, 200, 200 ), Qt::AlignLeft, m_title ); + QRect titleRect = fontMetrics.boundingRect( QRect( 0, 0, 200, 200 ), Qt::AlignLeft | Qt::TextWordWrap, m_title ); int preferredContentHeight = titleRect.height() + 2 * layout.lineSpacing + 0.5 * layout.lineSpacing; int preferredHeight = preferredContentHeight + layout.margins.top() + layout.margins.bottom(); @@ -127,7 +127,9 @@ void RiuAbstractLegendFrame::renderTo( QPainter* painter, const QRect& targetRec QTextDocument td; td.setDocumentMargin( 0.0 ); td.setDefaultFont( this->font() ); - td.setHtml( QString( "%2" ).arg( textColor.name() ).arg( m_title ) ); + td.setHtml( QString( "%2" ) + .arg( textColor.name() ) + .arg( m_title.replace( "\n", "
" ) ) ); td.drawContents( painter ); painter->restore(); } diff --git a/ApplicationCode/UserInterface/RiuScalarMapperLegendFrame.cpp b/ApplicationCode/UserInterface/RiuScalarMapperLegendFrame.cpp index e2be50ea9f..d1f76cf245 100644 --- a/ApplicationCode/UserInterface/RiuScalarMapperLegendFrame.cpp +++ b/ApplicationCode/UserInterface/RiuScalarMapperLegendFrame.cpp @@ -78,9 +78,10 @@ void RiuScalarMapperLegendFrame::layoutInfo( LayoutInfo* layout ) const int colorBarWidth = 25; int colorBarHeight = layout->overallLegendSize.height() - layout->margins.top() - layout->margins.bottom() - - titleLines.size() * layout->lineSpacing - 0.5 * layout->lineSpacing; + titleLines.size() * ( layout->charHeight + layout->lineSpacing ) - 0.5 * layout->lineSpacing; - int colorBarStartY = layout->margins.top() + titleLines.size() * layout->lineSpacing + 0.5 * layout->lineSpacing; + int colorBarStartY = layout->margins.top() + titleLines.size() * ( layout->lineSpacing + layout->charHeight ) + + 0.5 * layout->lineSpacing; layout->colorBarRect = QRect( layout->margins.left(), colorBarStartY, colorBarWidth, colorBarHeight );