mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 23:16:00 -06:00
Move to pixel size instead of point size for fonts
This commit is contained in:
parent
f279e85c2c
commit
4829c5eba2
@ -18,9 +18,14 @@
|
||||
|
||||
#include "RiaFontCache.h"
|
||||
|
||||
#include "RiaGuiApplication.h"
|
||||
|
||||
#include "cafAppEnum.h"
|
||||
#include "cafFixedAtlasFont.h"
|
||||
|
||||
#include <QDesktopWidget>
|
||||
#include <cmath>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
template <>
|
||||
@ -131,6 +136,36 @@ RiaFontCache::FontSize RiaFontCache::fontSizeEnumFromPointSize( int pointSize )
|
||||
return closestEnumValue;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaFontCache::pointSizeToPixelSize( int pointSize )
|
||||
{
|
||||
auto app = RiaGuiApplication::instance();
|
||||
if ( app )
|
||||
{
|
||||
int dpi = app->desktop()->logicalDpiX();
|
||||
double inches = pointSize / 72.0;
|
||||
return static_cast<int>( std::ceil( inches * dpi ) );
|
||||
}
|
||||
return pointSize;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaFontCache::pixelSizeToPointSize( int pixelSize )
|
||||
{
|
||||
auto app = RiaGuiApplication::instance();
|
||||
if ( app )
|
||||
{
|
||||
int dpi = app->desktop()->logicalDpiX();
|
||||
double inches = pixelSize / dpi;
|
||||
return static_cast<int>( std::ceil( inches * 72.0 ) );
|
||||
}
|
||||
return pixelSize;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -56,6 +56,8 @@ public:
|
||||
static cvf::ref<caf::FixedAtlasFont> getFont( FontSize fontSize );
|
||||
static FontSize legacyEnumToPointSize( int enumValue );
|
||||
static FontSize fontSizeEnumFromPointSize( int pointSize );
|
||||
static int pointSizeToPixelSize( int pointSize );
|
||||
static int pixelSizeToPointSize( int pixelSize );
|
||||
|
||||
static void clear();
|
||||
|
||||
|
@ -308,7 +308,7 @@ QString RimGridCrossPlotDataSet::groupTitle() const
|
||||
{
|
||||
if ( m_grouping != NO_GROUPING )
|
||||
{
|
||||
return QString( "[%1]" ).arg( groupParameter() );
|
||||
return groupParameter();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ QSize RiuAbstractLegendFrame::sizeHint() const
|
||||
QFontMetrics fontMetrics( this->font() );
|
||||
QRect titleRect = fontMetrics.boundingRect( QRect( 0, 0, 200, 200 ), Qt::AlignLeft, m_title );
|
||||
|
||||
int preferredContentHeight = titleRect.height() + labelCount() * layout.lineSpacing;
|
||||
int preferredContentHeight = titleRect.height() + labelCount() * layout.lineSpacing + 0.5 * layout.lineSpacing;
|
||||
int preferredHeight = preferredContentHeight + layout.margins.top() + layout.margins.bottom();
|
||||
|
||||
int titleWidth = titleRect.width() + layout.margins.left() + layout.margins.right();
|
||||
@ -81,7 +81,7 @@ QSize RiuAbstractLegendFrame::minimumSizeHint() const
|
||||
QFontMetrics fontMetrics( this->font() );
|
||||
QRect titleRect = fontMetrics.boundingRect( QRect( 0, 0, 200, 200 ), Qt::AlignLeft, m_title );
|
||||
|
||||
int preferredContentHeight = titleRect.height() + 2.25 * layout.lineSpacing;
|
||||
int preferredContentHeight = titleRect.height() + 2 * layout.lineSpacing + 0.5 * layout.lineSpacing;
|
||||
int preferredHeight = preferredContentHeight + layout.margins.top() + layout.margins.bottom();
|
||||
int titleWidth = titleRect.width() + layout.margins.left() + layout.margins.right();
|
||||
|
||||
@ -104,22 +104,24 @@ QSize RiuAbstractLegendFrame::minimumSizeHint() const
|
||||
void RiuAbstractLegendFrame::renderTo( QPainter* painter, const QRect& targetRect )
|
||||
{
|
||||
QFont font = this->font();
|
||||
font.setPointSize( RiaApplication::instance()->preferences()->defaultPlotFontSize() );
|
||||
font.setPixelSize(
|
||||
RiaFontCache::pointSizeToPixelSize( RiaApplication::instance()->preferences()->defaultPlotFontSize() ) );
|
||||
this->setFont( font );
|
||||
|
||||
LayoutInfo layout( QSize( targetRect.width(), targetRect.height() ) );
|
||||
layoutInfo( &layout );
|
||||
|
||||
painter->save();
|
||||
painter->translate( targetRect.topLeft() );
|
||||
painter->setFont( this->font() );
|
||||
|
||||
painter->translate( targetRect.topLeft() );
|
||||
QPoint titlePos( layout.margins.left(), layout.margins.top() );
|
||||
{
|
||||
painter->save();
|
||||
painter->translate( QPoint( layout.margins.left(), layout.margins.top() ) );
|
||||
QTextDocument td;
|
||||
td.setDocumentMargin( 0.0 );
|
||||
td.setDefaultFont( this->font() );
|
||||
td.setHtml( m_title );
|
||||
td.setPlainText( m_title );
|
||||
td.drawContents( painter );
|
||||
painter->restore();
|
||||
}
|
||||
@ -130,6 +132,7 @@ void RiuAbstractLegendFrame::renderTo( QPainter* painter, const QRect& targetRec
|
||||
painter->save();
|
||||
painter->translate( tickLabel.first.topLeft() );
|
||||
QTextDocument td;
|
||||
td.setDocumentMargin( 0.0 );
|
||||
td.setDefaultFont( this->font() );
|
||||
td.setPlainText( tickLabel.second );
|
||||
td.drawContents( painter );
|
||||
|
@ -51,7 +51,7 @@ RiuTextOverlayContentFrame::RiuTextOverlayContentFrame( QWidget* parent /*= null
|
||||
layout->addWidget( m_textLabel );
|
||||
|
||||
QFont font = m_textLabel->font();
|
||||
font.setPointSize( RiaApplication::instance()->preferences()->defaultPlotFontSize() );
|
||||
RiaFontCache::pointSizeToPixelSize( RiaApplication::instance()->preferences()->defaultPlotFontSize() );
|
||||
m_textLabel->setFont( font );
|
||||
}
|
||||
|
||||
|
@ -37,9 +37,9 @@ void RiuCategoryLegendFrame::layoutInfo( LayoutInfo* layout ) const
|
||||
|
||||
int colorBarWidth = 25;
|
||||
int colorBarHeight = layout->overallLegendSize.height() - layout->margins.top() - layout->margins.bottom() -
|
||||
titleLines.size() * layout->lineSpacing;
|
||||
titleLines.size() * layout->lineSpacing - 0.5 * layout->lineSpacing;
|
||||
|
||||
int colorBarStartY = layout->margins.top() + titleLines.size() * layout->lineSpacing;
|
||||
int colorBarStartY = layout->margins.top() + titleLines.size() * layout->lineSpacing + 0.5 * layout->lineSpacing;
|
||||
|
||||
layout->colorBarRect = QRect( layout->margins.left(), colorBarStartY, colorBarWidth, colorBarHeight );
|
||||
|
||||
@ -100,9 +100,8 @@ QRect RiuCategoryLegendFrame::labelRect( const LayoutInfo& layout, int index ) c
|
||||
{
|
||||
float categoryHeight = static_cast<float>( layout.colorBarRect.height() ) / labelCount();
|
||||
const int posX = layout.tickEndX + layout.tickTextLeadSpace;
|
||||
int posY = static_cast<int>( layout.colorBarRect.bottom() - index * categoryHeight );
|
||||
int height = std::max( (int)categoryHeight, layout.charHeight );
|
||||
int posY = static_cast<int>( layout.colorBarRect.bottom() - ( index + 1 ) * categoryHeight );
|
||||
QString labelI = this->label( index );
|
||||
int width = this->fontMetrics().boundingRect( labelI ).width();
|
||||
return QRect( posX, posY - height, width, height );
|
||||
return QRect( posX, posY, width, categoryHeight );
|
||||
}
|
||||
|
@ -47,12 +47,13 @@ void RiuDockedQwtPlot::applyFontSizes( bool replot /*= false*/ )
|
||||
{
|
||||
QwtText text = this->axisTitle( axis );
|
||||
QFont font = text.font();
|
||||
font.setPointSize( fontPointSize );
|
||||
font.setPixelSize(
|
||||
RiaFontCache::pointSizeToPixelSize( RiaApplication::instance()->preferences()->defaultPlotFontSize() ) );
|
||||
text.setFont( font );
|
||||
this->setAxisTitle( axis, text );
|
||||
|
||||
QFont valuesFont = this->axisFont( axis );
|
||||
valuesFont.setPointSize( fontPointSize );
|
||||
valuesFont.setPixelSize( font.pixelSize() );
|
||||
this->setAxisFont( axis, valuesFont );
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ void RiuGridCrossQwtPlot::setLegendFontSize( int fontSize )
|
||||
if ( legend() )
|
||||
{
|
||||
QFont font = legend()->font();
|
||||
font.setPointSize( fontSize );
|
||||
font.setPixelSize( RiaFontCache::pointSizeToPixelSize( fontSize ) );
|
||||
legend()->setFont( font );
|
||||
// Set font size for all existing labels
|
||||
QList<QwtLegendLabel*> labels = legend()->findChildren<QwtLegendLabel*>();
|
||||
|
@ -262,10 +262,11 @@ void RiuMultiPlotPage::setSelectionsVisible( bool visible )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMultiPlotPage::setFontSize( int fontSize )
|
||||
{
|
||||
int pixelSize = RiaFontCache::pointSizeToPixelSize( fontSize );
|
||||
{
|
||||
QFont font = m_plotTitle->font();
|
||||
|
||||
font.setPointSize( fontSize + 2 );
|
||||
font.setPixelSize( pixelSize + 2 );
|
||||
font.setBold( true );
|
||||
m_plotTitle->setFont( font );
|
||||
}
|
||||
@ -273,7 +274,7 @@ void RiuMultiPlotPage::setFontSize( int fontSize )
|
||||
for ( QLabel* subTitle : m_subTitles )
|
||||
{
|
||||
QFont font = subTitle->font();
|
||||
font.setPointSize( fontSize );
|
||||
font.setPixelSize( pixelSize );
|
||||
font.setBold( true );
|
||||
subTitle->setFont( font );
|
||||
}
|
||||
@ -733,7 +734,7 @@ void RiuMultiPlotPage::reinsertPlotWidgets()
|
||||
}
|
||||
legends[visibleIndex]->setMaxColumns( legendColumns );
|
||||
QFont legendFont = legends[visibleIndex]->font();
|
||||
legendFont.setPointSize( m_plotDefinition->legendFontSize() );
|
||||
legendFont.setPixelSize( RiaFontCache::pointSizeToPixelSize( m_plotDefinition->legendFontSize() ) );
|
||||
legends[visibleIndex]->setFont( legendFont );
|
||||
legends[visibleIndex]->show();
|
||||
}
|
||||
|
@ -245,8 +245,10 @@ void RiuMultiPlotWindow::setSelectionsVisible( bool visible )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMultiPlotWindow::setFontSize( int fontSize )
|
||||
{
|
||||
QFont font = this->font();
|
||||
font.setPointSize( fontSize );
|
||||
QFont font = this->font();
|
||||
int pixelSize = RiaFontCache::pointSizeToPixelSize( fontSize );
|
||||
|
||||
font.setPixelSize( pixelSize );
|
||||
this->setFont( font );
|
||||
for ( auto page : m_pages )
|
||||
{
|
||||
@ -259,7 +261,7 @@ void RiuMultiPlotWindow::setFontSize( int fontSize )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiuMultiPlotWindow::fontSize() const
|
||||
{
|
||||
return this->font().pointSize();
|
||||
return RiaFontCache::pixelSizeToPointSize( this->font().pixelSize() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -66,7 +66,7 @@ void RiuQwtPlotTools::setCommonPlotBehaviour( QwtPlot* plot )
|
||||
int fontSize = RiaApplication::instance()->preferences()->defaultPlotFontSize();
|
||||
// Axis number font
|
||||
QFont axisFont = plot->axisFont( QwtPlot::xBottom );
|
||||
axisFont.setPointSize( fontSize );
|
||||
axisFont.setPixelSize( RiaFontCache::pointSizeToPixelSize( fontSize ) );
|
||||
|
||||
plot->setAxisFont( QwtPlot::xBottom, axisFont );
|
||||
plot->setAxisFont( QwtPlot::xTop, axisFont );
|
||||
@ -80,7 +80,7 @@ void RiuQwtPlotTools::setCommonPlotBehaviour( QwtPlot* plot )
|
||||
{
|
||||
QwtText axisTitle = plot->axisTitle( axis );
|
||||
QFont axisTitleFont = axisTitle.font();
|
||||
axisTitleFont.setPointSize( fontSize );
|
||||
axisTitleFont.setPixelSize( RiaFontCache::pointSizeToPixelSize( fontSize ) );
|
||||
axisTitleFont.setBold( false );
|
||||
axisTitle.setFont( axisTitleFont );
|
||||
axisTitle.setRenderFlags( Qt::AlignRight );
|
||||
|
@ -145,14 +145,14 @@ void RiuQwtPlotWidget::setAxisFontsAndAlignment( QwtPlot::Axis axis,
|
||||
{
|
||||
// Axis number font
|
||||
QFont axisFont = this->axisFont( axis );
|
||||
axisFont.setPointSize( valueFontSize );
|
||||
axisFont.setPixelSize( RiaFontCache::pointSizeToPixelSize( valueFontSize ) );
|
||||
axisFont.setBold( false );
|
||||
this->setAxisFont( axis, axisFont );
|
||||
|
||||
// Axis title font
|
||||
QwtText axisTitle = this->axisTitle( axis );
|
||||
QFont axisTitleFont = axisTitle.font();
|
||||
axisTitleFont.setPointSize( titleFontSize );
|
||||
axisTitleFont.setPixelSize( RiaFontCache::pointSizeToPixelSize( titleFontSize ) );
|
||||
axisTitleFont.setBold( titleBold );
|
||||
axisTitle.setFont( axisTitleFont );
|
||||
axisTitle.setRenderFlags( alignment );
|
||||
|
@ -78,9 +78,9 @@ void RiuScalarMapperLegendFrame::layoutInfo( LayoutInfo* layout ) const
|
||||
|
||||
int colorBarWidth = 25;
|
||||
int colorBarHeight = layout->overallLegendSize.height() - layout->margins.top() - layout->margins.bottom() -
|
||||
titleLines.size() * layout->lineSpacing;
|
||||
titleLines.size() * layout->lineSpacing - 0.5 * layout->lineSpacing;
|
||||
|
||||
int colorBarStartY = layout->margins.top() + titleLines.size() * layout->lineSpacing;
|
||||
int colorBarStartY = layout->margins.top() + titleLines.size() * layout->lineSpacing + 0.5 * layout->lineSpacing;
|
||||
|
||||
layout->colorBarRect = QRect( layout->margins.left(), colorBarStartY, colorBarWidth, colorBarHeight );
|
||||
|
||||
@ -203,5 +203,5 @@ QRect RiuScalarMapperLegendFrame::labelRect( const LayoutInfo& layout, int index
|
||||
QString labelI = this->label( index );
|
||||
int width = this->fontMetrics().boundingRect( labelI ).width() + 4;
|
||||
int height = std::min( layout.lineSpacing, std::abs( posY - posYp1 ) );
|
||||
return QRect( posX, posY - height / 2 - layout.charAscent / 2, width, height );
|
||||
return QRect( posX, posY - height / 2, width, height );
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ void RiuSummaryQwtPlot::setLegendFontSize( int fontSize )
|
||||
if ( legend() )
|
||||
{
|
||||
QFont font = legend()->font();
|
||||
font.setPointSize( fontSize );
|
||||
font.setPixelSize( RiaFontCache::pointSizeToPixelSize( fontSize ) );
|
||||
legend()->setFont( font );
|
||||
// Set font size for all existing labels
|
||||
QList<QwtLegendLabel*> labels = legend()->findChildren<QwtLegendLabel*>();
|
||||
|
Loading…
Reference in New Issue
Block a user