From d1abc78b46e5ded5cc9bc1bbd56e54411becb1e9 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 | 16 ++++++++---- .../UserInterface/RiuTextContentFrame.cpp | 25 +++++++++++++++++-- .../UserInterface/RiuTextContentFrame.h | 11 +++++--- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimEnsembleCurveFilterCollection.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimEnsembleCurveFilterCollection.cpp index 17f4f0832e6..b855a9839d3 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,17 @@ 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 ) + { + fontSize = plotWindow->legendFontSize(); + } + + return new RiuTextContentFrame( nullptr, QString( "Active curve filters:" ), descriptions, fontSize ); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/UserInterface/RiuTextContentFrame.cpp b/ApplicationLibCode/UserInterface/RiuTextContentFrame.cpp index 3da8e5ab5b6..225ce100173 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 fontSize ) : RiuAbstractOverlayContentFrame( parent ) , m_title( title ) , m_text( text ) + , m_fontSize( fontSize ) { setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ); + + updateFromFontSize(); } //-------------------------------------------------------------------------------------------------- @@ -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 ); @@ -92,7 +96,7 @@ QSize RiuTextContentFrame::minimumSizeHint() const //-------------------------------------------------------------------------------------------------- void RiuTextContentFrame::renderTo( QPainter* painter, const QRect& targetRect ) { - updateFontSize(); + updateFromFontSize(); QColor textColor = RiuGuiTheme::getColorByVariableName( "textColor" ); @@ -160,3 +164,20 @@ void RiuTextContentFrame::layoutInfo( LayoutInfo* layout ) const layout->margins = QMargins( 8, 8, 8, 8 ); layout->tickTextLeadSpace = 5; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuTextContentFrame::updateFromFontSize() +{ + if ( m_fontSize != -1 ) + { + QFont font = this->font(); + font.setPixelSize( m_fontSize ); + setFont( font ); + } + else + { + updateFontSize(); + } +} diff --git a/ApplicationLibCode/UserInterface/RiuTextContentFrame.h b/ApplicationLibCode/UserInterface/RiuTextContentFrame.h index d5f4d211ac8..b19ec992733 100644 --- a/ApplicationLibCode/UserInterface/RiuTextContentFrame.h +++ b/ApplicationLibCode/UserInterface/RiuTextContentFrame.h @@ -22,19 +22,21 @@ #include #include +class QFont; + 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 fontSize = -1 ); 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 +62,10 @@ class RiuTextContentFrame : public RiuAbstractOverlayContentFrame private: virtual void layoutInfo( LayoutInfo* layout ) const; -protected: + void updateFromFontSize(); + +private: QString m_title; QString m_text; + int m_fontSize; };