Add font size to text content frame

This commit is contained in:
Magne Sjaastad 2024-03-19 11:39:45 +01:00
parent 785871cae3
commit 2e456a6f9b
4 changed files with 41 additions and 10 deletions

View File

@ -25,11 +25,8 @@
#include "RiuTextContentFrame.h"
#include <cafPdmUiPushButtonEditor.h>
#include <cafPdmUiTableViewEditor.h>
#include <cafPdmUiTreeOrdering.h>
#include <algorithm>
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<RimPlotWindow>();
if ( plotWindow )
{
const double scalingFactor = 1.4;
fontSize = scalingFactor * plotWindow->fontSize();
}
return new RiuTextContentFrame( nullptr, QString( "Active curve filters:" ), descriptions, fontSize );
}
//--------------------------------------------------------------------------------------------------

View File

@ -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 );
}

View File

@ -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();
}
}

View File

@ -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 @@ protected:
private:
virtual void layoutInfo( LayoutInfo* layout ) const;
protected:
void updateFontSize();
private:
QString m_title;
QString m_text;
int m_fontPixelSize;
};