From 6c57c519816e06df292559452fb2c8b91a7933d7 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 15 Nov 2023 10:37:30 +0100 Subject: [PATCH] Use StyleHelper::UiFont() Change-Id: I0c09578b76c48ddb255f44bb6117089dd092a72c Reviewed-by: hjk --- src/libs/utils/stylehelper.cpp | 5 ----- src/libs/utils/stylehelper.h | 1 - src/plugins/coreplugin/dialogs/settingsdialog.cpp | 12 +++--------- src/plugins/coreplugin/fancyactionbar.cpp | 10 +++------- src/plugins/coreplugin/fancytabwidget.cpp | 8 ++------ .../coreplugin/progressmanager/progressbar.cpp | 13 +++---------- .../coreplugin/progressmanager/progressbar.h | 1 - .../coreplugin/progressmanager/progressmanager.cpp | 4 +--- src/plugins/projectexplorer/buildprogress.cpp | 5 +---- .../projectexplorer/buildsettingspropertiespage.cpp | 11 +++-------- src/plugins/projectexplorer/panelswidget.cpp | 5 +---- src/plugins/projectexplorer/projectwindow.cpp | 9 +++------ .../projectexplorer/runsettingspropertiespage.cpp | 12 +++--------- src/plugins/projectexplorer/targetsettingspanel.cpp | 6 ++---- src/plugins/scxmleditor/common/dragshapebutton.cpp | 7 ++++--- src/plugins/welcome/introductionwidget.cpp | 4 +--- 16 files changed, 30 insertions(+), 83 deletions(-) diff --git a/src/libs/utils/stylehelper.cpp b/src/libs/utils/stylehelper.cpp index e3a68b90c96..5e76ee3386e 100644 --- a/src/libs/utils/stylehelper.cpp +++ b/src/libs/utils/stylehelper.cpp @@ -94,11 +94,6 @@ StyleHelper::ToolbarStyle StyleHelper::toolbarStyle() return s_toolbarStyle; } -qreal StyleHelper::sidebarFontSize() -{ - return HostOsInfo::isMacHost() ? 10 : 7.5; -} - QColor StyleHelper::notTooBrightHighlightColor() { QColor highlightColor = QApplication::palette().highlight().color(); diff --git a/src/libs/utils/stylehelper.h b/src/libs/utils/stylehelper.h index b493c031001..4cda97ff569 100644 --- a/src/libs/utils/stylehelper.h +++ b/src/libs/utils/stylehelper.h @@ -60,7 +60,6 @@ enum UiElement { QTCREATOR_UTILS_EXPORT int navigationWidgetHeight(); QTCREATOR_UTILS_EXPORT void setToolbarStyle(ToolbarStyle style); QTCREATOR_UTILS_EXPORT ToolbarStyle toolbarStyle(); -QTCREATOR_UTILS_EXPORT qreal sidebarFontSize(); QTCREATOR_UTILS_EXPORT QPalette sidebarFontPalette(const QPalette &original); // This is our color table, all colors derive from baseColor diff --git a/src/plugins/coreplugin/dialogs/settingsdialog.cpp b/src/plugins/coreplugin/dialogs/settingsdialog.cpp index 1fd3220680a..3d890b8515e 100644 --- a/src/plugins/coreplugin/dialogs/settingsdialog.cpp +++ b/src/plugins/coreplugin/dialogs/settingsdialog.cpp @@ -9,10 +9,11 @@ #include "../iwizardfactory.h" #include +#include #include #include -#include #include +#include #include #include @@ -569,14 +570,7 @@ void SettingsDialog::showPage(const Id pageId) void SettingsDialog::createGui() { - // Header label with large font and a bit of spacing (align with group boxes) - QFont headerLabelFont = m_headerLabel->font(); - headerLabelFont.setBold(true); - // Paranoia: Should a font be set in pixels... - const int pointSize = headerLabelFont.pointSize(); - if (pointSize > 0) - headerLabelFont.setPointSize(pointSize + 2); - m_headerLabel->setFont(headerLabelFont); + m_headerLabel->setFont(StyleHelper::UiFont(StyleHelper::UiElementH2)); auto headerHLayout = new QHBoxLayout; const int leftMargin = QApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin); diff --git a/src/plugins/coreplugin/fancyactionbar.cpp b/src/plugins/coreplugin/fancyactionbar.cpp index a07dd718976..908e002791c 100644 --- a/src/plugins/coreplugin/fancyactionbar.cpp +++ b/src/plugins/coreplugin/fancyactionbar.cpp @@ -181,11 +181,9 @@ void FancyToolButton::paintEvent(QPaintEvent *event) const bool isTitledAction = defaultAction() && defaultAction()->property("titledAction").toBool(); // draw popup texts if (isTitledAction && !m_iconsOnly) { - QFont normalFont(painter.font()); + const QFont normalFont = StyleHelper::UiFont(StyleHelper::UiElementPanelSubtitle); QRect centerRect = rect(); - normalFont.setPointSizeF(StyleHelper::sidebarFontSize()); - QFont boldFont(normalFont); - boldFont.setBold(true); + const QFont boldFont = StyleHelper::UiFont(StyleHelper::UiElementPanelTitle); const QFontMetrics fm(normalFont); const QFontMetrics boldFm(boldFont); const int lineHeight = boldFm.height(); @@ -286,9 +284,7 @@ QSize FancyToolButton::sizeHint() const QSizeF buttonSize = iconSize().expandedTo(QSize(64, 38)); if (defaultAction() && defaultAction()->property("titledAction").toBool()) { - QFont boldFont(font()); - boldFont.setPointSizeF(StyleHelper::sidebarFontSize()); - boldFont.setBold(true); + const QFont boldFont = StyleHelper::UiFont(StyleHelper::UiElementPanelTitle); const QFontMetrics fm(boldFont); const qreal lineHeight = fm.height(); const int extraHeight = 10 // Spacing between top and projectName diff --git a/src/plugins/coreplugin/fancytabwidget.cpp b/src/plugins/coreplugin/fancytabwidget.cpp index 85935b27987..19b0dfda475 100644 --- a/src/plugins/coreplugin/fancytabwidget.cpp +++ b/src/plugins/coreplugin/fancytabwidget.cpp @@ -68,9 +68,7 @@ QSize FancyTabBar::tabSizeHint(bool minimum) const Core::Constants::MODEBAR_ICONSONLY_BUTTON_SIZE / (minimum ? 3 : 1)}; } - QFont boldFont(font()); - boldFont.setPointSizeF(StyleHelper::sidebarFontSize()); - boldFont.setBold(true); + const QFont boldFont = StyleHelper::UiFont(StyleHelper::UiElementPanelTitle); const QFontMetrics fm(boldFont); const int spacing = 8; const int width = 60 + spacing + 2; @@ -285,9 +283,7 @@ static void paintIconAndText(QPainter *painter, const QRect &rect, const QIcon &icon, const QString &text, bool enabled, bool selected) { - QFont boldFont(painter->font()); - boldFont.setPointSizeF(StyleHelper::sidebarFontSize()); - boldFont.setBold(true); + const QFont boldFont = StyleHelper::UiFont(StyleHelper::UiElementPanelTitle); painter->setFont(boldFont); const bool drawIcon = rect.height() > 36; diff --git a/src/plugins/coreplugin/progressmanager/progressbar.cpp b/src/plugins/coreplugin/progressmanager/progressbar.cpp index 689263534c6..fa1a3041658 100644 --- a/src/plugins/coreplugin/progressmanager/progressbar.cpp +++ b/src/plugins/coreplugin/progressmanager/progressbar.cpp @@ -166,7 +166,8 @@ QSize ProgressBar::sizeHint() const int width = 50; int height = PROGRESSBAR_HEIGHT + 5; if (m_titleVisible) { - const QFontMetrics fm(titleFont()); + const QFont font = StyleHelper::UiFont(StyleHelper::UiElementPanelTitle); + const QFontMetrics fm(font); width = qMax(width, fm.horizontalAdvance(m_title) + 16); height += fm.height() + 5; if (!m_subtitle.isEmpty()) { @@ -192,14 +193,6 @@ void ProgressBar::mouseReleaseEvent(QMouseEvent *event) QWidget::mouseReleaseEvent(event); } -QFont ProgressBar::titleFont() const -{ - QFont boldFont(font()); - boldFont.setPointSizeF(StyleHelper::sidebarFontSize()); - boldFont.setBold(true); - return boldFont; -} - void ProgressBar::mouseMoveEvent(QMouseEvent *ev) { update(); @@ -220,7 +213,7 @@ void ProgressBar::paintEvent(QPaintEvent *) percent = 1; QPainter p(this); - const QFont fnt(titleFont()); + const QFont fnt = StyleHelper::UiFont(StyleHelper::UiElementPanelTitle); const QFontMetrics fm(fnt); const int titleHeight = m_titleVisible ? fm.height() + 5 : 4; diff --git a/src/plugins/coreplugin/progressmanager/progressbar.h b/src/plugins/coreplugin/progressmanager/progressbar.h index 0762cdf833d..a56373bfa67 100644 --- a/src/plugins/coreplugin/progressmanager/progressbar.h +++ b/src/plugins/coreplugin/progressmanager/progressbar.h @@ -52,7 +52,6 @@ protected: void mouseReleaseEvent(QMouseEvent *event) override; private: - QFont titleFont() const; QFont subtitleFont() const; QString m_text; diff --git a/src/plugins/coreplugin/progressmanager/progressmanager.cpp b/src/plugins/coreplugin/progressmanager/progressmanager.cpp index a2d61902b1c..c7bc22f2a6c 100644 --- a/src/plugins/coreplugin/progressmanager/progressmanager.cpp +++ b/src/plugins/coreplugin/progressmanager/progressmanager.cpp @@ -661,9 +661,7 @@ void ProgressManagerPrivate::updateStatusDetailsWidget() } else if (progress->isSubtitleVisibleInStatusBar() && !progress->subtitle().isEmpty()) { if (!m_statusDetailsLabel) { m_statusDetailsLabel = new QLabel(m_summaryProgressWidget); - QFont font(m_statusDetailsLabel->font()); - font.setPointSizeF(StyleHelper::sidebarFontSize()); - font.setBold(true); + const QFont font = StyleHelper::UiFont(StyleHelper::UiElementPanelTitle); m_statusDetailsLabel->setFont(font); } m_statusDetailsLabel->setText(progress->subtitle()); diff --git a/src/plugins/projectexplorer/buildprogress.cpp b/src/plugins/projectexplorer/buildprogress.cpp index 7166ab474d9..d6c654ce5cc 100644 --- a/src/plugins/projectexplorer/buildprogress.cpp +++ b/src/plugins/projectexplorer/buildprogress.cpp @@ -49,10 +49,7 @@ BuildProgress::BuildProgress(TaskWindow *taskWindow, Qt::Orientation orientation warningLayout->addWidget(m_warningIcon); warningLayout->addWidget(m_warningLabel); - // ### TODO this setup should be done by style - QFont f = this->font(); - f.setPointSizeF(Utils::StyleHelper::sidebarFontSize()); - f.setBold(true); + const QFont f = Utils::StyleHelper::UiFont(Utils::StyleHelper::UiElementPanelTitle); m_errorLabel->setFont(f); m_warningLabel->setFont(f); m_errorLabel->setPalette(Utils::StyleHelper::sidebarFontPalette(m_errorLabel->palette())); diff --git a/src/plugins/projectexplorer/buildsettingspropertiespage.cpp b/src/plugins/projectexplorer/buildsettingspropertiespage.cpp index 2caa44712e0..a53e489d82d 100644 --- a/src/plugins/projectexplorer/buildsettingspropertiespage.cpp +++ b/src/plugins/projectexplorer/buildsettingspropertiespage.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include @@ -54,9 +54,7 @@ BuildSettingsWidget::BuildSettingsWidget(Target *target) : if (!BuildConfigurationFactory::find(m_target)) { auto noSettingsLabel = new QLabel(this); noSettingsLabel->setText(Tr::tr("No build settings available")); - QFont f = noSettingsLabel->font(); - f.setPointSizeF(f.pointSizeF() * 1.2); - noSettingsLabel->setFont(f); + noSettingsLabel->setFont(StyleHelper::UiFont(StyleHelper::UiElementH2)); vbox->addWidget(noSettingsLabel); return; } @@ -128,10 +126,7 @@ void BuildSettingsWidget::addSubWidget(NamedWidget *widget) auto label = new QLabel(this); label->setText(widget->displayName()); - QFont f = label->font(); - f.setBold(true); - f.setPointSizeF(f.pointSizeF() * 1.2); - label->setFont(f); + label->setFont(StyleHelper::UiFont(StyleHelper::UiElementH2)); label->setContentsMargins(0, 18, 0, 0); diff --git a/src/plugins/projectexplorer/panelswidget.cpp b/src/plugins/projectexplorer/panelswidget.cpp index e83eb9045c8..38843bfe8d7 100644 --- a/src/plugins/projectexplorer/panelswidget.cpp +++ b/src/plugins/projectexplorer/panelswidget.cpp @@ -100,10 +100,7 @@ void PanelsWidget::addPropertiesPanel(const QString &displayName) auto nameLabel = new QLabel(m_root); nameLabel->setText(displayName); nameLabel->setContentsMargins(0, ABOVE_HEADING_MARGIN, 0, 0); - QFont f = nameLabel->font(); - f.setBold(true); - f.setPointSizeF(f.pointSizeF() * 1.6); - nameLabel->setFont(f); + nameLabel->setFont(StyleHelper::UiFont(StyleHelper::UiElementH1)); m_layout->addWidget(nameLabel); m_layout->addWidget(Layouting::createHr()); } diff --git a/src/plugins/projectexplorer/projectwindow.cpp b/src/plugins/projectexplorer/projectwindow.cpp index cd4b2321174..44e62bc5279 100644 --- a/src/plugins/projectexplorer/projectwindow.cpp +++ b/src/plugins/projectexplorer/projectwindow.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -569,10 +570,7 @@ public: selectorView->setAutoFillBackground(true); auto activeLabel = new QLabel(Tr::tr("Active Project")); - QFont font = activeLabel->font(); - font.setBold(true); - font.setPointSizeF(font.pointSizeF() * 1.2); - activeLabel->setFont(font); + activeLabel->setFont(StyleHelper::UiFont(StyleHelper::UiElementH2)); auto innerLayout = new QVBoxLayout; innerLayout->setSpacing(10); @@ -905,8 +903,7 @@ void SelectorDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti case 2: { QColor col = creatorTheme()->color(Theme::TextColorNormal); opt.palette.setColor(QPalette::Text, col); - opt.font.setBold(true); - opt.font.setPointSizeF(opt.font.pointSizeF() * 1.2); + opt.font = StyleHelper::UiFont(StyleHelper::UiElementH2); break; } } diff --git a/src/plugins/projectexplorer/runsettingspropertiespage.cpp b/src/plugins/projectexplorer/runsettingspropertiespage.cpp index 2c675b0a043..a4800e41ea1 100644 --- a/src/plugins/projectexplorer/runsettingspropertiespage.cpp +++ b/src/plugins/projectexplorer/runsettingspropertiespage.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include @@ -69,10 +69,7 @@ RunSettingsWidget::RunSettingsWidget(Target *target) : runLabel->setBuddy(m_runConfigurationCombo); - QFont f = runLabel->font(); - f.setBold(true); - f.setPointSizeF(f.pointSizeF() * 1.2); - + const QFont f = Utils::StyleHelper::UiFont(Utils::StyleHelper::UiElementH2); runTitle->setFont(f); deployTitle->setFont(f); @@ -501,10 +498,7 @@ void RunSettingsWidget::addSubWidget(QWidget *widget, QLabel *label) { widget->setContentsMargins({}); - QFont f = label->font(); - f.setBold(true); - f.setPointSizeF(f.pointSizeF() * 1.2); - label->setFont(f); + label->setFont(Utils::StyleHelper::UiFont(Utils::StyleHelper::UiElementH2)); label->setContentsMargins(0, 18, 0, 0); diff --git a/src/plugins/projectexplorer/targetsettingspanel.cpp b/src/plugins/projectexplorer/targetsettingspanel.cpp index 0a95a7219b5..dba282b51d8 100644 --- a/src/plugins/projectexplorer/targetsettingspanel.cpp +++ b/src/plugins/projectexplorer/targetsettingspanel.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -184,10 +185,7 @@ void TargetGroupItemPrivate::ensureWidget() auto label = new QLabel; label->setText(Tr::tr("No kit defined in this project.")); - QFont f = label->font(); - f.setPointSizeF(f.pointSizeF() * 1.4); - f.setBold(true); - label->setFont(f); + label->setFont(StyleHelper::UiFont(StyleHelper::UiElementH2)); label->setContentsMargins(10, 10, 10, 10); label->setAlignment(Qt::AlignTop); diff --git a/src/plugins/scxmleditor/common/dragshapebutton.cpp b/src/plugins/scxmleditor/common/dragshapebutton.cpp index a644479ecf8..307827cb00e 100644 --- a/src/plugins/scxmleditor/common/dragshapebutton.cpp +++ b/src/plugins/scxmleditor/common/dragshapebutton.cpp @@ -3,6 +3,9 @@ #include "dragshapebutton.h" #include "baseitem.h" + +#include + #include #include #include @@ -17,9 +20,7 @@ DragShapeButton::DragShapeButton(QWidget *parent) setMinimumSize(75, 75); setMaximumSize(75, 75); setIconSize(QSize(45, 45)); - QFont f = font(); - f.setPointSize(8); - setFont(f); + setFont(Utils::StyleHelper::UiFont(Utils::StyleHelper::UiElementPanelSubtitle)); } void DragShapeButton::setShapeInfo(int groupIndex, int shapeIndex) diff --git a/src/plugins/welcome/introductionwidget.cpp b/src/plugins/welcome/introductionwidget.cpp index d89805037af..28e25fbf61f 100644 --- a/src/plugins/welcome/introductionwidget.cpp +++ b/src/plugins/welcome/introductionwidget.cpp @@ -78,9 +78,7 @@ IntroductionWidget::IntroductionWidget(QWidget *parent) m_continueLabel->setAlignment(Qt::AlignCenter); m_continueLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); m_continueLabel->setWordWrap(true); - auto fnt = font(); - fnt.setPointSizeF(fnt.pointSizeF() * 1.5); - m_continueLabel->setFont(fnt); + m_continueLabel->setFont(StyleHelper::UiFont(StyleHelper::UiElementH1)); m_continueLabel->setPalette(palette()); layout->addWidget(m_continueLabel); m_bodyCss = "font-size: 16px;";