mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Improved font handling
This commit is contained in:
@@ -83,28 +83,29 @@ cvf::ref<caf::FixedAtlasFont> RiaFontCache::getFont( FontSize size )
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
/// In the 2019 releases the font size was stored as an enum value rather than actual size
|
||||
/// Use this method for legacy conversion
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaFontCache::pointSizeFromFontSizeEnum( FontSize fontSize )
|
||||
RiaFontCache::FontSize RiaFontCache::legacyEnumToPointSize( int enumValue )
|
||||
{
|
||||
switch ( fontSize )
|
||||
switch ( enumValue )
|
||||
{
|
||||
case RiaFontCache::FONT_SIZE_8:
|
||||
return 8;
|
||||
case RiaFontCache::FONT_SIZE_10:
|
||||
return 10;
|
||||
case RiaFontCache::FONT_SIZE_12:
|
||||
return 12;
|
||||
case RiaFontCache::FONT_SIZE_14:
|
||||
return 14;
|
||||
case RiaFontCache::FONT_SIZE_16:
|
||||
return 16;
|
||||
case RiaFontCache::FONT_SIZE_24:
|
||||
return 24;
|
||||
case RiaFontCache::FONT_SIZE_32:
|
||||
return 32;
|
||||
case 0:
|
||||
return FONT_SIZE_8;
|
||||
case 1:
|
||||
return FONT_SIZE_10;
|
||||
case 2:
|
||||
return FONT_SIZE_12;
|
||||
case 3:
|
||||
return FONT_SIZE_14;
|
||||
case 4:
|
||||
return FONT_SIZE_16;
|
||||
case 5:
|
||||
return FONT_SIZE_24;
|
||||
case 6:
|
||||
return FONT_SIZE_32;
|
||||
default:
|
||||
return 16;
|
||||
return FONT_SIZE_8;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,11 +121,11 @@ RiaFontCache::FontSize RiaFontCache::fontSizeEnumFromPointSize( int pointSize )
|
||||
int closestDiff = std::numeric_limits<int>::max();
|
||||
for ( FontSize enumValue : allValues )
|
||||
{
|
||||
int diff = std::abs( pointSizeFromFontSizeEnum( enumValue ) - pointSize );
|
||||
int diff = std::abs( (int)enumValue - pointSize );
|
||||
if ( diff < closestDiff )
|
||||
{
|
||||
closestEnumValue = enumValue;
|
||||
closestDiff = diff;
|
||||
closestDiff;
|
||||
}
|
||||
}
|
||||
return closestEnumValue;
|
||||
|
||||
@@ -40,20 +40,21 @@ class RiaFontCache
|
||||
public:
|
||||
enum FontSize
|
||||
{
|
||||
FONT_SIZE_8,
|
||||
FONT_SIZE_10,
|
||||
FONT_SIZE_12,
|
||||
FONT_SIZE_14,
|
||||
FONT_SIZE_16,
|
||||
FONT_SIZE_24,
|
||||
FONT_SIZE_32,
|
||||
MIN_FONT_SIZE = 8,
|
||||
FONT_SIZE_8 = 8,
|
||||
FONT_SIZE_10 = 10,
|
||||
FONT_SIZE_12 = 12,
|
||||
FONT_SIZE_14 = 14,
|
||||
FONT_SIZE_16 = 16,
|
||||
FONT_SIZE_24 = 24,
|
||||
FONT_SIZE_32 = 32,
|
||||
MAX_FONT_SIZE = FONT_SIZE_32
|
||||
};
|
||||
|
||||
typedef caf::AppEnum<FontSize> FontSizeType;
|
||||
|
||||
static cvf::ref<caf::FixedAtlasFont> getFont( FontSize fontSize );
|
||||
static int pointSizeFromFontSizeEnum( FontSize fontSize );
|
||||
static FontSize legacyEnumToPointSize( int enumValue );
|
||||
static FontSize fontSizeEnumFromPointSize( int pointSize );
|
||||
|
||||
static void clear();
|
||||
|
||||
@@ -1605,10 +1605,9 @@ void RiaGuiApplication::applyGuiPreferences( const RiaPreferences* oldPreference
|
||||
|
||||
for ( auto fontTypeSizePair : fontSizes )
|
||||
{
|
||||
RiaFontCache::FontSize oldFontSizeEnum = oldPreferences->defaultFontSizes()[fontTypeSizePair.first];
|
||||
if ( oldFontSizeEnum != fontTypeSizePair.second )
|
||||
RiaFontCache::FontSize oldFontSize = oldPreferences->defaultFontSizes()[fontTypeSizePair.first];
|
||||
if ( oldFontSize != fontTypeSizePair.second )
|
||||
{
|
||||
int oldFontSize = RiaFontCache::pointSizeFromFontSizeEnum( oldFontSizeEnum );
|
||||
if ( viewWindow->hasCustomFontSizes( fontTypeSizePair.first, oldFontSize ) )
|
||||
{
|
||||
existingObjectsWithCustomFonts = true;
|
||||
@@ -1656,11 +1655,10 @@ void RiaGuiApplication::applyGuiPreferences( const RiaPreferences* oldPreference
|
||||
{
|
||||
for ( auto fontTypeSizePair : fontSizes )
|
||||
{
|
||||
RiaFontCache::FontSize oldFontSizeEnum = oldPreferences->defaultFontSizes()[fontTypeSizePair.first];
|
||||
if ( oldFontSizeEnum != fontTypeSizePair.second )
|
||||
RiaFontCache::FontSize oldFontSize = oldPreferences->defaultFontSizes()[fontTypeSizePair.first];
|
||||
int newFontSize = fontTypeSizePair.second;
|
||||
if ( oldFontSize != newFontSize )
|
||||
{
|
||||
int oldFontSize = RiaFontCache::pointSizeFromFontSizeEnum( oldFontSizeEnum );
|
||||
int newFontSize = RiaFontCache::pointSizeFromFontSizeEnum( fontTypeSizePair.second );
|
||||
viewWindow->applyFontSize( fontTypeSizePair.first, oldFontSize, newFontSize, applySettingsToAllViews );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -628,11 +628,26 @@ QList<caf::PdmOptionItemInfo> RiaPreferences::calculateValueOptions( const caf::
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaPreferences::initAfterRead()
|
||||
{
|
||||
// If the stored font size is larger than the maximum enum value, the stored font size is actually point size
|
||||
// If the stored font size is smaller than the minimum enum value, the stored font size is actually just an enum value
|
||||
int defaultSceneFontEnumValue = static_cast<int>( defaultSceneFontSize.v() );
|
||||
if ( defaultSceneFontEnumValue > (int)RiaFontCache::MAX_FONT_SIZE )
|
||||
if ( defaultSceneFontEnumValue < (int)RiaFontCache::MIN_FONT_SIZE )
|
||||
{
|
||||
defaultSceneFontSize = RiaFontCache::fontSizeEnumFromPointSize( defaultSceneFontEnumValue );
|
||||
defaultSceneFontSize = RiaFontCache::legacyEnumToPointSize( defaultSceneFontEnumValue );
|
||||
}
|
||||
int defaultWellLabelFontEnumValue = static_cast<int>( defaultWellLabelFontSize.v() );
|
||||
if ( defaultWellLabelFontEnumValue < (int)RiaFontCache::MIN_FONT_SIZE )
|
||||
{
|
||||
defaultWellLabelFontSize = RiaFontCache::legacyEnumToPointSize( defaultWellLabelFontEnumValue );
|
||||
}
|
||||
int defaultAnnotationFontEnumValue = static_cast<int>( defaultAnnotationFontSize.v() );
|
||||
if ( defaultAnnotationFontEnumValue < (int)RiaFontCache::MIN_FONT_SIZE )
|
||||
{
|
||||
defaultAnnotationFontSize = RiaFontCache::legacyEnumToPointSize( defaultAnnotationFontEnumValue );
|
||||
}
|
||||
int defaultPlotFontEnumValue = static_cast<int>( defaultPlotFontSize.v() );
|
||||
if ( defaultPlotFontEnumValue < (int)RiaFontCache::MIN_FONT_SIZE )
|
||||
{
|
||||
defaultPlotFontSize = RiaFontCache::legacyEnumToPointSize( defaultPlotFontEnumValue );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -290,13 +290,15 @@ QString RimGridCrossPlotDataSet::createAutoName() const
|
||||
nameTags += timeStepString();
|
||||
}
|
||||
|
||||
QString fullTitle = nameTags.join( ", " );
|
||||
|
||||
if ( m_nameConfig->addGrouping() && groupParameter() != "None" )
|
||||
{
|
||||
QString catTitle = groupTitle();
|
||||
if ( !catTitle.isEmpty() ) nameTags += catTitle;
|
||||
if ( !catTitle.isEmpty() ) fullTitle += QString( " [%1]" ).arg( catTitle );
|
||||
}
|
||||
|
||||
return nameTags.join( ", " );
|
||||
return fullTitle;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -306,7 +308,7 @@ QString RimGridCrossPlotDataSet::groupTitle() const
|
||||
{
|
||||
if ( m_grouping != NO_GROUPING )
|
||||
{
|
||||
return QString( "Grouped by %1" ).arg( groupParameter() );
|
||||
return QString( "[%1]" ).arg( groupParameter() );
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -89,9 +89,9 @@ RimPlotAxisProperties::RimPlotAxisProperties()
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_titlePositionEnum, "TitlePosition", "Title Position", "", "", "");
|
||||
CAF_PDM_InitField(&m_titleFontSize, "FontSize", 10, "Font Size", "", "", "");
|
||||
m_titleFontSize = RiaFontCache::pointSizeFromFontSizeEnum(RiaApplication::instance()->preferences()->defaultPlotFontSize());
|
||||
m_titleFontSize = RiaApplication::instance()->preferences()->defaultPlotFontSize();
|
||||
CAF_PDM_InitField(&m_valuesFontSize, "ValuesFontSize", 10, "Font Size", "", "", "");
|
||||
m_valuesFontSize = RiaFontCache::pointSizeFromFontSizeEnum(RiaApplication::instance()->preferences()->defaultPlotFontSize());
|
||||
m_valuesFontSize = RiaApplication::instance()->preferences()->defaultPlotFontSize();
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_annotations, "Annotations", "", "", "", "");
|
||||
|
||||
|
||||
@@ -47,8 +47,7 @@ RimPlotWindow::RimPlotWindow()
|
||||
CAF_PDM_InitField( &m_showPlotLegends, "ShowTrackLegends", true, "Show Legends", "", "", "" );
|
||||
CAF_PDM_InitField( &m_plotLegendsHorizontal, "TrackLegendsHorizontal", true, "Legend Orientation", "", "", "" );
|
||||
m_plotLegendsHorizontal.uiCapability()->setUiEditorTypeName( caf::PdmUiComboBoxEditor::uiEditorTypeName() );
|
||||
int defaultFontSize = RiaFontCache::pointSizeFromFontSizeEnum(
|
||||
RiaApplication::instance()->preferences()->defaultPlotFontSize() );
|
||||
int defaultFontSize = RiaApplication::instance()->preferences()->defaultPlotFontSize();
|
||||
CAF_PDM_InitField( &m_legendFontSize,
|
||||
"LegendFontSize",
|
||||
std::max( 8, defaultFontSize - 2 ),
|
||||
|
||||
@@ -117,24 +117,17 @@ void RimSummaryPlotAxisFormatter::applyAxisPropertiesToPlot( RiuSummaryQwtPlot*
|
||||
|
||||
QwtText axisTitleY = qwtPlot->axisTitle( m_axisProperties->qwtPlotAxisType() );
|
||||
|
||||
QFont axisTitleYFont = axisTitleY.font();
|
||||
axisTitleYFont.setBold( true );
|
||||
axisTitleYFont.setPointSize( m_axisProperties->titleFontSize() );
|
||||
axisTitleY.setFont( axisTitleYFont );
|
||||
|
||||
axisTitleY.setText( axisTitle );
|
||||
|
||||
Qt::AlignmentFlag titleAlignment = Qt::AlignCenter;
|
||||
if ( m_axisProperties->titlePosition() == RimPlotAxisPropertiesInterface::AXIS_TITLE_END )
|
||||
{
|
||||
titleAlignment = Qt::AlignRight;
|
||||
}
|
||||
qwtPlot->setAxisTitleText( m_axisProperties->qwtPlotAxisType(), axisTitle );
|
||||
qwtPlot->setAxisFontsAndAlignment( m_axisProperties->qwtPlotAxisType(),
|
||||
m_axisProperties->titleFontSize(),
|
||||
m_axisProperties->valuesFontSize(),
|
||||
true,
|
||||
titleAlignment );
|
||||
qwtPlot->setAxisTitleText( m_axisProperties->qwtPlotAxisType(), axisTitle );
|
||||
qwtPlot->setAxisTitleEnabled( m_axisProperties->qwtPlotAxisType(), true );
|
||||
}
|
||||
|
||||
|
||||
@@ -99,11 +99,9 @@ RimSummaryTimeAxisProperties::RimSummaryTimeAxisProperties()
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_titlePositionEnum, "TitlePosition", "Title Position", "", "", "" );
|
||||
CAF_PDM_InitField( &m_titleFontSize, "FontSize", 10, "Font Size", "", "", "" );
|
||||
m_titleFontSize = RiaFontCache::pointSizeFromFontSizeEnum(
|
||||
RiaApplication::instance()->preferences()->defaultPlotFontSize() );
|
||||
m_titleFontSize = RiaApplication::instance()->preferences()->defaultPlotFontSize();
|
||||
CAF_PDM_InitField( &m_valuesFontSize, "ValuesFontSize", 10, "Font Size", "", "", "" );
|
||||
m_valuesFontSize = RiaFontCache::pointSizeFromFontSizeEnum(
|
||||
RiaApplication::instance()->preferences()->defaultPlotFontSize() );
|
||||
m_valuesFontSize = RiaApplication::instance()->preferences()->defaultPlotFontSize();
|
||||
|
||||
CAF_PDM_InitField( &m_automaticDateComponents, "AutoDate", true, "Automatic Date/Time Labels", "", "", "" );
|
||||
CAF_PDM_InitFieldNoDefault( &m_dateComponents, "DateComponents", "Set Date Label", "", "", "" );
|
||||
|
||||
@@ -41,8 +41,7 @@ void RiuDockedQwtPlot::applyFontSizes( bool replot /*= false*/ )
|
||||
{
|
||||
std::set<QwtPlot::Axis> allAxes = {QwtPlot::xBottom, QwtPlot::yLeft, QwtPlot::xTop, QwtPlot::yRight};
|
||||
|
||||
RiaFontCache::FontSize fontSizeEnum = RiaApplication::instance()->preferences()->defaultPlotFontSize();
|
||||
int fontPointSize = RiaFontCache::pointSizeFromFontSizeEnum( fontSizeEnum ) - 1;
|
||||
int fontPointSize = RiaApplication::instance()->preferences()->defaultPlotFontSize() - 1;
|
||||
|
||||
for ( QwtPlot::Axis axis : allAxes )
|
||||
{
|
||||
|
||||
@@ -92,8 +92,7 @@ RiuFlowCharacteristicsPlot::RiuFlowCharacteristicsPlot( RimFlowCharacteristicsPl
|
||||
addWindowZoom( m_sweepEffPlot );
|
||||
m_sweepEffPlot->setTitle( "Sweep Efficiency" );
|
||||
|
||||
int legendFontSize = RiaFontCache::pointSizeFromFontSizeEnum(
|
||||
RiaApplication::instance()->preferences()->defaultPlotFontSize() );
|
||||
int legendFontSize = RiaApplication::instance()->preferences()->defaultPlotFontSize();
|
||||
|
||||
{
|
||||
QwtText axisTitle = m_sweepEffPlot->axisTitle( QwtPlot::xBottom );
|
||||
|
||||
@@ -110,8 +110,8 @@ RiuMultiPlotPage::RiuMultiPlotPage( RimMultiPlotWindow* plotDefinition, QWidget*
|
||||
|
||||
setAcceptDrops( m_plotDefinition->acceptDrops() );
|
||||
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
int defaultFontSize = RiaFontCache::pointSizeFromFontSizeEnum( app->preferences()->defaultPlotFontSize() );
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
int defaultFontSize = app->preferences()->defaultPlotFontSize();
|
||||
setFontSize( defaultFontSize );
|
||||
|
||||
this->setObjectName( QString( "%1" ).arg( reinterpret_cast<uint64_t>( this ) ) );
|
||||
@@ -159,7 +159,7 @@ void RiuMultiPlotPage::insertPlot( RiuQwtPlotWidget* plotWidget, size_t index )
|
||||
plotWidget->setVisible( false );
|
||||
|
||||
QLabel* subTitle = new QLabel( plotWidget->plotDefinition()->description() );
|
||||
subTitle->setAlignment( Qt::AlignRight );
|
||||
subTitle->setAlignment( Qt::AlignHCenter );
|
||||
subTitle->setVisible( false );
|
||||
m_subTitles.insert( static_cast<int>( index ), subTitle );
|
||||
|
||||
@@ -262,11 +262,21 @@ void RiuMultiPlotPage::setSelectionsVisible( bool visible )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMultiPlotPage::setFontSize( int fontSize )
|
||||
{
|
||||
QFont font = m_plotTitle->font();
|
||||
{
|
||||
QFont font = m_plotTitle->font();
|
||||
|
||||
font.setPointSize( fontSize + 1 );
|
||||
font.setBold( true );
|
||||
m_plotTitle->setFont( font );
|
||||
font.setPointSize( fontSize + 2 );
|
||||
font.setBold( true );
|
||||
m_plotTitle->setFont( font );
|
||||
}
|
||||
|
||||
for ( QLabel* subTitle : m_subTitles )
|
||||
{
|
||||
QFont font = subTitle->font();
|
||||
font.setPointSize( fontSize );
|
||||
font.setBold( true );
|
||||
subTitle->setFont( font );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -274,7 +284,7 @@ void RiuMultiPlotPage::setFontSize( int fontSize )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiuMultiPlotPage::fontSize() const
|
||||
{
|
||||
return m_plotTitle->font().pointSize() - 1;
|
||||
return m_plotTitle->font().pointSize() - 2;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -134,8 +134,8 @@ RiuMultiPlotWindow::RiuMultiPlotWindow( RimMultiPlotWindow* plotDefinition, QWid
|
||||
|
||||
setFocusPolicy( Qt::StrongFocus );
|
||||
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
int defaultFontSize = RiaFontCache::pointSizeFromFontSizeEnum( app->preferences()->defaultPlotFontSize() );
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
int defaultFontSize = app->preferences()->defaultPlotFontSize();
|
||||
setFontSize( defaultFontSize );
|
||||
|
||||
QSize pageSize = m_plotDefinition->pageLayout().fullRectPixels( RiaGuiApplication::applicationResolution() ).size();
|
||||
@@ -247,6 +247,11 @@ void RiuMultiPlotWindow::setFontSize( int fontSize )
|
||||
{
|
||||
QFont font = this->font();
|
||||
font.setPointSize( fontSize );
|
||||
this->setFont( font );
|
||||
for ( auto page : m_pages )
|
||||
{
|
||||
page->setFontSize( fontSize );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -63,8 +63,7 @@ void RiuQwtPlotTools::setCommonPlotBehaviour( QwtPlot* plot )
|
||||
gridPen.setColor( Qt::lightGray );
|
||||
grid->setPen( gridPen );
|
||||
|
||||
int fontSize = RiaFontCache::pointSizeFromFontSizeEnum(
|
||||
RiaApplication::instance()->preferences()->defaultPlotFontSize() );
|
||||
int fontSize = RiaApplication::instance()->preferences()->defaultPlotFontSize();
|
||||
// Axis number font
|
||||
QFont axisFont = plot->axisFont( QwtPlot::xBottom );
|
||||
axisFont.setPointSize( fontSize );
|
||||
|
||||
@@ -145,14 +145,14 @@ void RiuQwtPlotWidget::setAxisFontsAndAlignment( QwtPlot::Axis axis,
|
||||
{
|
||||
// Axis number font
|
||||
QFont axisFont = this->axisFont( axis );
|
||||
axisFont.setPixelSize( valueFontSize );
|
||||
axisFont.setPointSize( valueFontSize );
|
||||
axisFont.setBold( false );
|
||||
this->setAxisFont( axis, axisFont );
|
||||
|
||||
// Axis title font
|
||||
QwtText axisTitle = this->axisTitle( axis );
|
||||
QFont axisTitleFont = axisTitle.font();
|
||||
axisTitleFont.setPixelSize( titleFontSize );
|
||||
axisTitleFont.setPointSize( titleFontSize );
|
||||
axisTitleFont.setBold( titleBold );
|
||||
axisTitle.setFont( axisTitleFont );
|
||||
axisTitle.setRenderFlags( alignment );
|
||||
|
||||
@@ -97,8 +97,7 @@ RiuViewer::RiuViewer( const QGLFormat& format, QWidget* parent )
|
||||
{
|
||||
cvf::Font* standardFont = RiaGuiApplication::instance()->defaultSceneFont();
|
||||
QFont font = RiaGuiApplication::instance()->font();
|
||||
font.setPointSize( RiaFontCache::pointSizeFromFontSizeEnum(
|
||||
RiaGuiApplication::instance()->preferences()->defaultSceneFontSize() ) );
|
||||
font.setPointSize( RiaGuiApplication::instance()->preferences()->defaultSceneFontSize() );
|
||||
|
||||
m_axisCross = new cvf::OverlayAxisCross( m_mainCamera.p(), standardFont );
|
||||
m_axisCross->setAxisLabels( "X", "Y", "Z" );
|
||||
@@ -1331,8 +1330,7 @@ void RiuViewer::updateFonts()
|
||||
m_showAxisCross = true;
|
||||
|
||||
QFont font = QApplication::font();
|
||||
font.setPointSize(
|
||||
RiaFontCache::pointSizeFromFontSizeEnum( RiaApplication::instance()->preferences()->defaultSceneFontSize() ) );
|
||||
font.setPointSize( RiaApplication::instance()->preferences()->defaultSceneFontSize() );
|
||||
|
||||
m_zScaleLabel->setFont( font );
|
||||
m_infoLabel->setFont( font );
|
||||
|
||||
Reference in New Issue
Block a user