From e89a93fc979957a8206ce364c91ffdcffc0f0ff5 Mon Sep 17 00:00:00 2001 From: Ruslan Kabatsayev Date: Thu, 30 Jan 2025 12:36:46 +0800 Subject: [PATCH] Handle font size changes in Cardinals --- src/core/modules/LandscapeMgr.cpp | 30 +++++++++++++++++++----------- src/core/modules/LandscapeMgr.hpp | 3 +++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/core/modules/LandscapeMgr.cpp b/src/core/modules/LandscapeMgr.cpp index 8e97dfaa630df..b870ea5c109e1 100644 --- a/src/core/modules/LandscapeMgr.cpp +++ b/src/core/modules/LandscapeMgr.cpp @@ -71,17 +71,8 @@ constexpr char ATMOSPHERE_MODEL_CONF_VAL_DEFAULT[]="preetham"; Cardinals::Cardinals() : color(0.6f,0.2f,0.2f) { - QSettings* conf = StelApp::getInstance().getSettings(); - Q_ASSERT(conf); - screenFontSize = StelApp::getInstance().getScreenFontSize(); propMgr = StelApp::getInstance().getStelPropertyManager(); - // Default font size is 24 - font4WCR.setPixelSize(conf->value("viewing/cardinal_font_size", screenFontSize+11).toInt()); - // Default font size is 18 - font8WCR.setPixelSize(conf->value("viewing/ordinal_font_size", screenFontSize+5).toInt()); - // Draw the principal wind points even smaller. - font16WCR.setPixelSize(conf->value("viewing/16wcr_font_size", screenFontSize+2).toInt()); - font32WCR.setPixelSize(conf->value("viewing/32wcr_font_size", screenFontSize).toInt()); + updateFontSizes(); // English names for cardinals labels = { @@ -94,6 +85,23 @@ Cardinals::Cardinals() { dSbW,"SbW" }, {dSWbS,"SWbS"}, {dSWbW,"SWbW"}, { dWbS,"WbS" }, { dWbN,"WbN" }, {dNWbW,"NWbW"}, {dNWbN,"NWbN"}, { dNbW,"NbW" } }; + QObject::connect(&StelApp::getInstance(), &StelApp::screenFontSizeChanged, + [this]{updateFontSizes();}); +} + +void Cardinals::updateFontSizes() +{ + QSettings* conf = StelApp::getInstance().getSettings(); + Q_ASSERT(conf); + screenFontSize = StelApp::getInstance().getScreenFontSize(); + const float scale = StelApp::getInstance().screenFontSizeRatio(); + // Default font size is 24 + font4WCR.setPixelSize(conf->value("viewing/cardinal_font_size", screenFontSize+11*scale).toInt()); + // Default font size is 18 + font8WCR.setPixelSize(conf->value("viewing/ordinal_font_size", screenFontSize+5*scale).toInt()); + // Draw the principal wind points even smaller. + font16WCR.setPixelSize(conf->value("viewing/16wcr_font_size", screenFontSize+2*scale).toInt()); + font32WCR.setPixelSize(conf->value("viewing/32wcr_font_size", screenFontSize).toInt()); } Cardinals::~Cardinals() @@ -159,7 +167,7 @@ void Cardinals::draw(const StelCore* core, double latitude) const if (fader4WCR.getInterstate()>0.f) { const StelProjectorP prj = core->getProjection(StelCore::FrameAltAz, StelCore::RefractionOff); - const float ppx = static_cast(core->getCurrentStelProjectorParams().devicePixelsPerPixel); + const float ppx = prj->getScreenScale(); StelPainter sPainter(prj); sPainter.setFont(font4WCR); float sshift=0.f, bshift=0.f, cshift=0.f, dshift=0.f, vshift=1.f; diff --git a/src/core/modules/LandscapeMgr.hpp b/src/core/modules/LandscapeMgr.hpp index 977a8a783ae67..d383e837ee320 100644 --- a/src/core/modules/LandscapeMgr.hpp +++ b/src/core/modules/LandscapeMgr.hpp @@ -102,6 +102,9 @@ class Cardinals bool getFlagShow16WCRLabels() const { return fader16WCR; } void setFlagShow32WCRLabels(bool b) { fader32WCR = b; StelApp::immediateSave("viewing/flag_32wcr_points", b);} bool getFlagShow32WCRLabels() const { return fader32WCR; } +private: + void updateFontSizes(); + private: class StelPropertyMgr* propMgr; QFont font4WCR, font8WCR, font16WCR, font32WCR;