mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-01 03:37:15 -06:00
212f5bf5ae
Required changes to use Qt6 and disable support for Qt5. There are still some adjustments related to Qt6 to be done, but these changes are not required to make Qt6 compile on relevant systems. * Build system changes Qt6 * Override enterEvent * Update QKeySequence * QtChart changes * Use QScreen to instepct dotsPerInch * Add app->quit() * Required updates for code related to QString * Use RiaQDateTimeTools * Required changes related to regular expressions * Support compile on Qt < 6.5 When version < 6.5 is found, qt_generate_deploy_app_script() is disabled. Compilation of ResInsight will work, but the install target will be incomplete. * Octave: add missing header. * Qt Advanced Docking: force Qt6 where both Qt5 and Qt6 is available. --------- Co-authored-by: magnesj <1793152+magnesj@users.noreply.github.com> Co-authored-by: Kristian Bendiksen <kristian.bendiksen@gmail.com>
126 lines
4.8 KiB
C++
126 lines
4.8 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2017 Statoil ASA
|
|
//
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
//
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
// for more details.
|
|
//
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "RiaFontCache.h"
|
|
|
|
#include "RiaGuiApplication.h"
|
|
|
|
#include "cafAssert.h"
|
|
#include "cafFixedAtlasFont.h"
|
|
|
|
#include <cmath>
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
caf::FixedAtlasFont::FontSize mapToAtlasFontSize( int pointSize )
|
|
{
|
|
if ( pointSize >= 6 && pointSize < 8 )
|
|
return caf::FixedAtlasFont::POINT_SIZE_6;
|
|
else if ( pointSize >= 8 && pointSize < 10 )
|
|
return caf::FixedAtlasFont::POINT_SIZE_8;
|
|
else if ( pointSize >= 10 && pointSize < 12 )
|
|
return caf::FixedAtlasFont::POINT_SIZE_10;
|
|
else if ( pointSize >= 12 && pointSize < 14 )
|
|
return caf::FixedAtlasFont::POINT_SIZE_12;
|
|
else if ( pointSize >= 14 && pointSize < 16 )
|
|
return caf::FixedAtlasFont::POINT_SIZE_14;
|
|
else if ( pointSize >= 16 && pointSize < 20 )
|
|
return caf::FixedAtlasFont::POINT_SIZE_16;
|
|
else if ( pointSize >= 20 && pointSize < 28 )
|
|
return caf::FixedAtlasFont::POINT_SIZE_24;
|
|
|
|
return caf::FixedAtlasFont::POINT_SIZE_32;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
std::map<caf::FixedAtlasFont::FontSize, cvf::ref<caf::FixedAtlasFont>> RiaFontCache::ms_fonts;
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
cvf::ref<caf::FixedAtlasFont> RiaFontCache::getFont( FontSize pointFontSize )
|
|
{
|
|
int pointSize = caf::FontTools::absolutePointSize( pointFontSize );
|
|
return getFont( pointSize );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
cvf::ref<caf::FixedAtlasFont> RiaFontCache::getFont( int pointSize )
|
|
{
|
|
int currentDPI = 96;
|
|
if ( RiaGuiApplication::isRunning() )
|
|
{
|
|
currentDPI = RiaGuiApplication::applicationResolution();
|
|
}
|
|
|
|
// the Fixed Atlas Fonts appear to be assuming a DPI of 96, so we need scaling.
|
|
double scaling = currentDPI / 96.0;
|
|
int scaledSize = scaling * pointSize;
|
|
auto atlasFontSize = mapToAtlasFontSize( scaledSize );
|
|
|
|
auto existing_it = ms_fonts.find( atlasFontSize );
|
|
if ( existing_it == ms_fonts.end() )
|
|
{
|
|
auto newFont = new caf::FixedAtlasFont( atlasFontSize );
|
|
bool inserted = false;
|
|
std::tie( existing_it, inserted ) = ms_fonts.insert( std::make_pair( atlasFontSize, newFont ) );
|
|
CAF_ASSERT( inserted );
|
|
}
|
|
return existing_it->second;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
/// In the 2019 releases the font size was stored as an enum value rather than actual size
|
|
/// Use this method for legacy conversion
|
|
//--------------------------------------------------------------------------------------------------
|
|
RiaFontCache::FontSize RiaFontCache::legacyEnumToPointSize( int enumValue )
|
|
{
|
|
switch ( enumValue )
|
|
{
|
|
case 0:
|
|
return FontSize::FONT_SIZE_8;
|
|
case 1:
|
|
return FontSize::FONT_SIZE_10;
|
|
case 2:
|
|
return FontSize::FONT_SIZE_12;
|
|
case 3:
|
|
return FontSize::FONT_SIZE_14;
|
|
case 4:
|
|
return FontSize::FONT_SIZE_16;
|
|
case 5:
|
|
return FontSize::FONT_SIZE_24;
|
|
case 6:
|
|
return FontSize::FONT_SIZE_32;
|
|
default:
|
|
return FontSize::FONT_SIZE_8;
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RiaFontCache::clear()
|
|
{
|
|
ms_fonts.clear();
|
|
}
|