From 01ec9f664ed72a482344457aa9505c967fde089d Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 19 Mar 2024 11:39:45 +0100 Subject: [PATCH] Add font size to text content frame --- .../RimEnsembleCurveFilterCollection.cpp | 17 ++++++++++---- .../Summary/RimEnsembleCurveSet.cpp | 2 +- .../UserInterface/RiuTextContentFrame.cpp | 23 ++++++++++++++++++- .../UserInterface/RiuTextContentFrame.h | 9 +++++--- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimEnsembleCurveFilterCollection.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimEnsembleCurveFilterCollection.cpp index 17f4f0832e..dd8ea5da0e 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimEnsembleCurveFilterCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimEnsembleCurveFilterCollection.cpp @@ -25,11 +25,8 @@ #include "RiuTextContentFrame.h" #include -#include #include -#include - CAF_PDM_SOURCE_INIT( RimEnsembleCurveFilterCollection, "RimEnsembleCurveFilterCollection" ); //-------------------------------------------------------------------------------------------------- @@ -43,7 +40,6 @@ RimEnsembleCurveFilterCollection::RimEnsembleCurveFilterCollection() CAF_PDM_InitFieldNoDefault( &m_filters, "CurveFilters", "" ); m_filters.uiCapability()->setUiTreeChildrenHidden( true ); - // m_filters.uiCapability()->setUiEditorTypeName(caf::PdmUiTableViewEditor::uiEditorTypeName()); m_filters.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN ); CAF_PDM_InitFieldNoDefault( &m_newFilterButton, "NewEnsembleFilter", "New Filter" ); @@ -247,7 +243,18 @@ RiuTextContentFrame* RimEnsembleCurveFilterCollection::makeFilterDescriptionFram { QString descriptions = filterDescriptions(); descriptions.replace( "+", "\n+" ); - return new RiuTextContentFrame( nullptr, QString( "Active curve filters:" ), descriptions ); + + // A size of -1 use default plot font + int fontSize = -1; + + auto plotWindow = firstAncestorOrThisOfType(); + if ( plotWindow ) + { + const double scalingFactor = 1.4; + fontSize = scalingFactor * plotWindow->fontSize(); + } + + return new RiuTextContentFrame( nullptr, QString( "Active curve filters:" ), descriptions, fontSize ); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimEnsembleCurveSet.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimEnsembleCurveSet.cpp index 5cf84dff46..76d5b59f02 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimEnsembleCurveSet.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimEnsembleCurveSet.cpp @@ -1756,7 +1756,7 @@ void RimEnsembleCurveSet::updateObjectiveFunctionLegend() } if ( !title.isEmpty() && !description.isEmpty() ) { - m_objectiveFunctionOverlayFrame->setContentFrame( new RiuTextContentFrame( nullptr, title, description ) ); + m_objectiveFunctionOverlayFrame->setContentFrame( new RiuTextContentFrame( nullptr, title, description, -1 ) ); m_objectiveFunctionOverlayFrame->setMaximumWidth( 10000 ); plot->plotWidget()->addOverlayFrame( m_objectiveFunctionOverlayFrame ); } diff --git a/ApplicationLibCode/UserInterface/RiuTextContentFrame.cpp b/ApplicationLibCode/UserInterface/RiuTextContentFrame.cpp index 3da8e5ab5b..e8b1642b44 100644 --- a/ApplicationLibCode/UserInterface/RiuTextContentFrame.cpp +++ b/ApplicationLibCode/UserInterface/RiuTextContentFrame.cpp @@ -34,12 +34,15 @@ //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RiuTextContentFrame::RiuTextContentFrame( QWidget* parent, const QString& title, const QString& text ) +RiuTextContentFrame::RiuTextContentFrame( QWidget* parent, const QString& title, const QString& text, int fontPixelSize ) : RiuAbstractOverlayContentFrame( parent ) , m_title( title ) , m_text( text ) + , m_fontPixelSize( fontPixelSize ) { setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ); + + updateFontSize(); } //-------------------------------------------------------------------------------------------------- @@ -71,6 +74,7 @@ QSize RiuTextContentFrame::minimumSizeHint() const { LayoutInfo layout( QSize( 200, 100 ) ); // Use default size layoutInfo( &layout ); + QFont titleFont = font(); titleFont.setBold( true ); QFontMetrics fontMetrics( titleFont ); @@ -160,3 +164,20 @@ void RiuTextContentFrame::layoutInfo( LayoutInfo* layout ) const layout->margins = QMargins( 8, 8, 8, 8 ); layout->tickTextLeadSpace = 5; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuTextContentFrame::updateFontSize() +{ + if ( m_fontPixelSize != -1 ) + { + QFont font = this->font(); + font.setPixelSize( m_fontPixelSize ); + setFont( font ); + } + else + { + RiuAbstractOverlayContentFrame::updateFontSize(); + } +} diff --git a/ApplicationLibCode/UserInterface/RiuTextContentFrame.h b/ApplicationLibCode/UserInterface/RiuTextContentFrame.h index d5f4d211ac..df3f078280 100644 --- a/ApplicationLibCode/UserInterface/RiuTextContentFrame.h +++ b/ApplicationLibCode/UserInterface/RiuTextContentFrame.h @@ -27,14 +27,14 @@ class RiuTextContentFrame : public RiuAbstractOverlayContentFrame Q_OBJECT public: - RiuTextContentFrame( QWidget* parent, const QString& title, const QString& text ); + RiuTextContentFrame( QWidget* parent, const QString& title, const QString& text, int fontPixeSize ); QSize sizeHint() const override; QSize minimumSizeHint() const override; void renderTo( QPainter* painter, const QRect& targetRect ) override; -protected: +private: struct LayoutInfo { LayoutInfo( const QSize& size ) @@ -60,7 +60,10 @@ class RiuTextContentFrame : public RiuAbstractOverlayContentFrame private: virtual void layoutInfo( LayoutInfo* layout ) const; -protected: + void updateFontSize(); + +private: QString m_title; QString m_text; + int m_fontPixelSize; };