@@ -129,6 +129,8 @@ int fontScale = defaultFontScale;
129129static std::map<QWidget*, std::pair<QFont::Weight, bool >> mapNormalFontUpdates;
130130// Contains all widgets where a fixed pitch font has been set with GUIUtil::setFixedPitchFont
131131static std::set<QWidget*> setFixedPitchFontUpdates;
132+ // Contains all widgets where a non-default fontsize has been seet with GUIUtil::setFont
133+ static std::map<QWidget*, int > mapFontSizeUpdates;
132134#ifdef Q_OS_MAC
133135// Contains all widgets where the macOS focus rect has been disabled.
134136static std::set<QWidget*> setRectsDisabled;
@@ -1287,15 +1289,21 @@ void setApplicationFont()
12871289 " match: " << qApp->font ().exactMatch ();
12881290}
12891291
1290- void setFont (const std::vector<QWidget*> &vecWidgets, QFont::Weight weight, bool fItalic )
1292+ void setFont (const std::vector<QWidget*> &vecWidgets, QFont::Weight weight, int nPointSize, bool fItalic )
12911293{
12921294 // TODO: Evaluate maybe wrapping this later into some "theme handler" or so..
1293- QFont font = getFont (weight, fItalic );
1295+ QFont font = getFont (weight, fItalic , nPointSize );
12941296
12951297 for (auto it : vecWidgets) {
12961298 auto fontAttributes = std::make_pair (weight, fItalic );
12971299 auto itw = mapNormalFontUpdates.emplace (std::make_pair (it, fontAttributes));
12981300 if (!itw.second ) itw.first ->second = fontAttributes;
1301+
1302+ if (nPointSize != -1 ) {
1303+ auto its = mapFontSizeUpdates.emplace (std::make_pair (it, nPointSize));
1304+ if (!its.second ) its.first ->second = nPointSize;
1305+ }
1306+
12991307 it->setFont (font);
13001308 }
13011309}
@@ -1314,6 +1322,13 @@ void updateFonts()
13141322 // TODO: Evaluate maybe wrapping this later into some "theme handler" or so..
13151323 setApplicationFont ();
13161324
1325+ auto getKey = [](QWidget* w) -> QString
1326+ {
1327+ return w->parent () ? w->parent ()->objectName () + w->objectName () :
1328+ w->objectName ();
1329+ };
1330+
1331+ static std::map<QString, int > mapDefaultFontSizes;
13171332 std::map<QWidget*, QFont> mapWidgetFonts;
13181333
13191334 for (QWidget* w : qApp->allWidgets ()) {
@@ -1322,22 +1337,41 @@ void updateFonts()
13221337 font.setWeight (qApp->font ().weight ());
13231338 font.setStyleName (qApp->font ().styleName ());
13241339 font.setStyle (qApp->font ().style ());
1340+ // Set the font size based on the widgets default font size + the font scale
1341+ QString key = getKey (w);
1342+ if (!mapDefaultFontSizes.count (key)) {
1343+ mapDefaultFontSizes.emplace (std::make_pair (key, font.pointSize () > 0 ? font.pointSize () : defaultFontSize));
1344+ }
1345+ font.setPointSizeF (getScaledFontSize (mapDefaultFontSizes[key]));
13251346 mapWidgetFonts.emplace (w, font);
13261347 }
13271348
13281349 auto itn = mapNormalFontUpdates.begin ();
13291350 while (itn != mapNormalFontUpdates.end ()) {
13301351 if (mapWidgetFonts.count (itn->first )) {
1331- mapWidgetFonts[itn->first ] = getFont (itn->second .first , itn->second .second );
1352+ mapWidgetFonts[itn->first ] = getFont (itn->second .first , itn->second .second , mapDefaultFontSizes[ getKey (itn-> first )] );
13321353 ++itn;
13331354 } else {
13341355 itn = mapNormalFontUpdates.erase (itn);
13351356 }
13361357 }
1358+ auto its = mapFontSizeUpdates.begin ();
1359+ while (its != mapFontSizeUpdates.end ()) {
1360+ if (mapWidgetFonts.count (its->first )) {
1361+ QFont font = mapWidgetFonts[its->first ];
1362+ font.setPointSizeF (getScaledFontSize (its->second ));
1363+ mapWidgetFonts[its->first ] = font;
1364+ ++its;
1365+ } else {
1366+ its = mapFontSizeUpdates.erase (its);
1367+ }
1368+ }
13371369 auto itf = setFixedPitchFontUpdates.begin ();
13381370 while (itf != setFixedPitchFontUpdates.end ()) {
13391371 if (mapWidgetFonts.count (*itf)) {
1340- mapWidgetFonts[*itf] = fixedPitchFont ();
1372+ QFont font = fixedPitchFont ();
1373+ font.setPointSizeF (getScaledFontSize (mapDefaultFontSizes[getKey (*itf)]));
1374+ mapWidgetFonts[*itf] = font;
13411375 ++itf;
13421376 } else {
13431377 itf = setFixedPitchFontUpdates.erase (itf);
@@ -1346,10 +1380,13 @@ void updateFonts()
13461380
13471381 for (auto it: mapWidgetFonts) {
13481382 it.first ->setFont (it.second );
1383+ if (gArgs .IsArgSet (" -debug-ui" )) {
1384+ qDebug () << __func__ << " : set font " << it.second << " for widget " << it.first ->objectName ();
1385+ }
13491386 }
13501387}
13511388
1352- QFont getFont (QFont::Weight weight, bool fItalic )
1389+ QFont getFont (QFont::Weight weight, bool fItalic , int nPointSize )
13531390{
13541391 // TODO: Evaluate maybe wrapping this later into some "theme handler" or so..
13551392 QFont font;
@@ -1398,6 +1435,11 @@ QFont getFont(QFont::Weight weight, bool fItalic)
13981435 font.setWeight (weight > QFont::Normal ? QFont::Bold : QFont::Normal);
13991436 font.setStyle (fItalic ? QFont::StyleItalic : QFont::StyleNormal);
14001437 }
1438+
1439+ if (nPointSize != -1 ) {
1440+ font.setPointSizeF (getScaledFontSize (nPointSize));
1441+ }
1442+
14011443 if (gArgs .IsArgSet (" -debug-ui" )) {
14021444 qDebug () << __func__ << " : font size: " << font.pointSizeF () << " family: " << font.family () << " , style: " << font.styleName () << " match: " << font.exactMatch ();
14031445 }
0 commit comments