Skip to content

Commit

Permalink
Add font size to text content frame
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Mar 19, 2024
1 parent 8eb70b9 commit e1e1408
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@
#include "RiuTextContentFrame.h"

#include <cafPdmUiPushButtonEditor.h>
#include <cafPdmUiTableViewEditor.h>
#include <cafPdmUiTreeOrdering.h>

#include <algorithm>

CAF_PDM_SOURCE_INIT( RimEnsembleCurveFilterCollection, "RimEnsembleCurveFilterCollection" );

//--------------------------------------------------------------------------------------------------
Expand All @@ -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" );
Expand Down Expand Up @@ -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<RimPlotWindow>();
if ( plotWindow )
{
fontSize = plotWindow->legendFontSize();
}

return new RiuTextContentFrame( nullptr, QString( "Active curve filters:" ), descriptions, fontSize );
}

//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
25 changes: 23 additions & 2 deletions ApplicationLibCode/UserInterface/RiuTextContentFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

updateFromFontSize();
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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 );
Expand All @@ -92,7 +96,7 @@ QSize RiuTextContentFrame::minimumSizeHint() const
//--------------------------------------------------------------------------------------------------
void RiuTextContentFrame::renderTo( QPainter* painter, const QRect& targetRect )
{
updateFontSize();
updateFromFontSize();

QColor textColor = RiuGuiTheme::getColorByVariableName( "textColor" );

Expand Down Expand Up @@ -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_fontPixelSize != -1 )
{
QFont font = this->font();
font.setPixelSize( m_fontPixelSize );
setFont( font );
}
else
{
updateFontSize();
}
}
11 changes: 8 additions & 3 deletions ApplicationLibCode/UserInterface/RiuTextContentFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@
#include <QFrame>
#include <QString>

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

0 comments on commit e1e1408

Please sign in to comment.