From f8671f3e3cb95b1c4911304955129045d4e110ce Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Tue, 14 Nov 2023 12:13:38 +0100 Subject: [PATCH] Utils: Introduce StyleHelper::UiFont() for centralized font definitions Custom font sizes of UI texts like titles and subtitles were usually defined on the spot in code. With the upcoming focus on unified fonts and colors in Qt Creator, a centralization of font styles in needed. This adds the font getter function StyleHelper::UiFont() and the enum UiElement that specifies types as H1..H6 and some custom ones. Change-Id: Ie0d6e6fb51fe24d8aee6b4242941cbff45fe3853 Reviewed-by: hjk Reviewed-by: Artem Sokolovskii --- src/libs/utils/stylehelper.cpp | 32 ++++++++++++++++++++++++++++++++ src/libs/utils/stylehelper.h | 11 +++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/libs/utils/stylehelper.cpp b/src/libs/utils/stylehelper.cpp index 49a83234258..e3a68b90c96 100644 --- a/src/libs/utils/stylehelper.cpp +++ b/src/libs/utils/stylehelper.cpp @@ -938,4 +938,36 @@ QColor StyleHelper::ensureReadableOn(const QColor &background, const QColor &des return foreground; } +QFont StyleHelper::UiFont(UiElement element) +{ + QFont font; + + constexpr qreal panelTitleSize = HostOsInfo::isMacHost() ? 10 : 7.5; + + switch (element) { + case UiElementH1: + font.setPointSizeF(font.pointSizeF() * 1.6); + font.setBold(true); + break; + case UiElementH2: + font.setPointSizeF(font.pointSizeF() * 1.2); + font.setBold(true); + break; + case UiElementH3: + break; + case UiElementH4: + break; + case UiElementPanelTitle: { + font.setPointSizeF(panelTitleSize); + font.setBold(true); + break; + } + case UiElementPanelSubtitle: + font.setPointSizeF(panelTitleSize); + break; + } + + return font; +} + } // namespace Utils diff --git a/src/libs/utils/stylehelper.h b/src/libs/utils/stylehelper.h index a7656b3eb3a..b493c031001 100644 --- a/src/libs/utils/stylehelper.h +++ b/src/libs/utils/stylehelper.h @@ -47,6 +47,15 @@ enum ToolbarStyle { }; constexpr ToolbarStyle defaultToolbarStyle = ToolbarStyleCompact; +enum UiElement { + UiElementH1, + UiElementH2, + UiElementH3, + UiElementH4, + UiElementPanelTitle, + UiElementPanelSubtitle, +}; + // Height of the project explorer navigation bar QTCREATOR_UTILS_EXPORT int navigationWidgetHeight(); QTCREATOR_UTILS_EXPORT void setToolbarStyle(ToolbarStyle style); @@ -73,6 +82,8 @@ QTCREATOR_UTILS_EXPORT QColor sidebarShadow(); QTCREATOR_UTILS_EXPORT QColor toolBarDropShadowColor(); QTCREATOR_UTILS_EXPORT QColor notTooBrightHighlightColor(); +QTCREATOR_UTILS_EXPORT QFont UiFont(UiElement element); + // Sets the base color and makes sure all top level widgets are updated QTCREATOR_UTILS_EXPORT void setBaseColor(const QColor &color);