Use StyleHelper::UiFont()

Change-Id: I0c09578b76c48ddb255f44bb6117089dd092a72c
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Alessandro Portale
2023-11-15 10:37:30 +01:00
parent f8671f3e3c
commit 6c57c51981
16 changed files with 30 additions and 83 deletions

View File

@@ -94,11 +94,6 @@ StyleHelper::ToolbarStyle StyleHelper::toolbarStyle()
return s_toolbarStyle; return s_toolbarStyle;
} }
qreal StyleHelper::sidebarFontSize()
{
return HostOsInfo::isMacHost() ? 10 : 7.5;
}
QColor StyleHelper::notTooBrightHighlightColor() QColor StyleHelper::notTooBrightHighlightColor()
{ {
QColor highlightColor = QApplication::palette().highlight().color(); QColor highlightColor = QApplication::palette().highlight().color();

View File

@@ -60,7 +60,6 @@ enum UiElement {
QTCREATOR_UTILS_EXPORT int navigationWidgetHeight(); QTCREATOR_UTILS_EXPORT int navigationWidgetHeight();
QTCREATOR_UTILS_EXPORT void setToolbarStyle(ToolbarStyle style); QTCREATOR_UTILS_EXPORT void setToolbarStyle(ToolbarStyle style);
QTCREATOR_UTILS_EXPORT ToolbarStyle toolbarStyle(); QTCREATOR_UTILS_EXPORT ToolbarStyle toolbarStyle();
QTCREATOR_UTILS_EXPORT qreal sidebarFontSize();
QTCREATOR_UTILS_EXPORT QPalette sidebarFontPalette(const QPalette &original); QTCREATOR_UTILS_EXPORT QPalette sidebarFontPalette(const QPalette &original);
// This is our color table, all colors derive from baseColor // This is our color table, all colors derive from baseColor

View File

@@ -9,10 +9,11 @@
#include "../iwizardfactory.h" #include "../iwizardfactory.h"
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/fancylineedit.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
#include <utils/icon.h> #include <utils/icon.h>
#include <utils/fancylineedit.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/stylehelper.h>
#include <QApplication> #include <QApplication>
#include <QCheckBox> #include <QCheckBox>
@@ -569,14 +570,7 @@ void SettingsDialog::showPage(const Id pageId)
void SettingsDialog::createGui() void SettingsDialog::createGui()
{ {
// Header label with large font and a bit of spacing (align with group boxes) m_headerLabel->setFont(StyleHelper::UiFont(StyleHelper::UiElementH2));
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);
auto headerHLayout = new QHBoxLayout; auto headerHLayout = new QHBoxLayout;
const int leftMargin = QApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin); const int leftMargin = QApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin);

View File

@@ -181,11 +181,9 @@ void FancyToolButton::paintEvent(QPaintEvent *event)
const bool isTitledAction = defaultAction() && defaultAction()->property("titledAction").toBool(); const bool isTitledAction = defaultAction() && defaultAction()->property("titledAction").toBool();
// draw popup texts // draw popup texts
if (isTitledAction && !m_iconsOnly) { if (isTitledAction && !m_iconsOnly) {
QFont normalFont(painter.font()); const QFont normalFont = StyleHelper::UiFont(StyleHelper::UiElementPanelSubtitle);
QRect centerRect = rect(); QRect centerRect = rect();
normalFont.setPointSizeF(StyleHelper::sidebarFontSize()); const QFont boldFont = StyleHelper::UiFont(StyleHelper::UiElementPanelTitle);
QFont boldFont(normalFont);
boldFont.setBold(true);
const QFontMetrics fm(normalFont); const QFontMetrics fm(normalFont);
const QFontMetrics boldFm(boldFont); const QFontMetrics boldFm(boldFont);
const int lineHeight = boldFm.height(); const int lineHeight = boldFm.height();
@@ -286,9 +284,7 @@ QSize FancyToolButton::sizeHint() const
QSizeF buttonSize = iconSize().expandedTo(QSize(64, 38)); QSizeF buttonSize = iconSize().expandedTo(QSize(64, 38));
if (defaultAction() && defaultAction()->property("titledAction").toBool()) { if (defaultAction() && defaultAction()->property("titledAction").toBool()) {
QFont boldFont(font()); const QFont boldFont = StyleHelper::UiFont(StyleHelper::UiElementPanelTitle);
boldFont.setPointSizeF(StyleHelper::sidebarFontSize());
boldFont.setBold(true);
const QFontMetrics fm(boldFont); const QFontMetrics fm(boldFont);
const qreal lineHeight = fm.height(); const qreal lineHeight = fm.height();
const int extraHeight = 10 // Spacing between top and projectName const int extraHeight = 10 // Spacing between top and projectName

View File

@@ -68,9 +68,7 @@ QSize FancyTabBar::tabSizeHint(bool minimum) const
Core::Constants::MODEBAR_ICONSONLY_BUTTON_SIZE / (minimum ? 3 : 1)}; Core::Constants::MODEBAR_ICONSONLY_BUTTON_SIZE / (minimum ? 3 : 1)};
} }
QFont boldFont(font()); const QFont boldFont = StyleHelper::UiFont(StyleHelper::UiElementPanelTitle);
boldFont.setPointSizeF(StyleHelper::sidebarFontSize());
boldFont.setBold(true);
const QFontMetrics fm(boldFont); const QFontMetrics fm(boldFont);
const int spacing = 8; const int spacing = 8;
const int width = 60 + spacing + 2; const int width = 60 + spacing + 2;
@@ -285,9 +283,7 @@ static void paintIconAndText(QPainter *painter, const QRect &rect,
const QIcon &icon, const QString &text, const QIcon &icon, const QString &text,
bool enabled, bool selected) bool enabled, bool selected)
{ {
QFont boldFont(painter->font()); const QFont boldFont = StyleHelper::UiFont(StyleHelper::UiElementPanelTitle);
boldFont.setPointSizeF(StyleHelper::sidebarFontSize());
boldFont.setBold(true);
painter->setFont(boldFont); painter->setFont(boldFont);
const bool drawIcon = rect.height() > 36; const bool drawIcon = rect.height() > 36;

View File

@@ -166,7 +166,8 @@ QSize ProgressBar::sizeHint() const
int width = 50; int width = 50;
int height = PROGRESSBAR_HEIGHT + 5; int height = PROGRESSBAR_HEIGHT + 5;
if (m_titleVisible) { 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); width = qMax(width, fm.horizontalAdvance(m_title) + 16);
height += fm.height() + 5; height += fm.height() + 5;
if (!m_subtitle.isEmpty()) { if (!m_subtitle.isEmpty()) {
@@ -192,14 +193,6 @@ void ProgressBar::mouseReleaseEvent(QMouseEvent *event)
QWidget::mouseReleaseEvent(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) void ProgressBar::mouseMoveEvent(QMouseEvent *ev)
{ {
update(); update();
@@ -220,7 +213,7 @@ void ProgressBar::paintEvent(QPaintEvent *)
percent = 1; percent = 1;
QPainter p(this); QPainter p(this);
const QFont fnt(titleFont()); const QFont fnt = StyleHelper::UiFont(StyleHelper::UiElementPanelTitle);
const QFontMetrics fm(fnt); const QFontMetrics fm(fnt);
const int titleHeight = m_titleVisible ? fm.height() + 5 : 4; const int titleHeight = m_titleVisible ? fm.height() + 5 : 4;

View File

@@ -52,7 +52,6 @@ protected:
void mouseReleaseEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override;
private: private:
QFont titleFont() const;
QFont subtitleFont() const; QFont subtitleFont() const;
QString m_text; QString m_text;

View File

@@ -661,9 +661,7 @@ void ProgressManagerPrivate::updateStatusDetailsWidget()
} else if (progress->isSubtitleVisibleInStatusBar() && !progress->subtitle().isEmpty()) { } else if (progress->isSubtitleVisibleInStatusBar() && !progress->subtitle().isEmpty()) {
if (!m_statusDetailsLabel) { if (!m_statusDetailsLabel) {
m_statusDetailsLabel = new QLabel(m_summaryProgressWidget); m_statusDetailsLabel = new QLabel(m_summaryProgressWidget);
QFont font(m_statusDetailsLabel->font()); const QFont font = StyleHelper::UiFont(StyleHelper::UiElementPanelTitle);
font.setPointSizeF(StyleHelper::sidebarFontSize());
font.setBold(true);
m_statusDetailsLabel->setFont(font); m_statusDetailsLabel->setFont(font);
} }
m_statusDetailsLabel->setText(progress->subtitle()); m_statusDetailsLabel->setText(progress->subtitle());

View File

@@ -49,10 +49,7 @@ BuildProgress::BuildProgress(TaskWindow *taskWindow, Qt::Orientation orientation
warningLayout->addWidget(m_warningIcon); warningLayout->addWidget(m_warningIcon);
warningLayout->addWidget(m_warningLabel); warningLayout->addWidget(m_warningLabel);
// ### TODO this setup should be done by style const QFont f = Utils::StyleHelper::UiFont(Utils::StyleHelper::UiElementPanelTitle);
QFont f = this->font();
f.setPointSizeF(Utils::StyleHelper::sidebarFontSize());
f.setBold(true);
m_errorLabel->setFont(f); m_errorLabel->setFont(f);
m_warningLabel->setFont(f); m_warningLabel->setFont(f);
m_errorLabel->setPalette(Utils::StyleHelper::sidebarFontPalette(m_errorLabel->palette())); m_errorLabel->setPalette(Utils::StyleHelper::sidebarFontPalette(m_errorLabel->palette()));

View File

@@ -18,7 +18,7 @@
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/stringutils.h> #include <utils/stringutils.h>
#include <utils/stringutils.h> #include <utils/stylehelper.h>
#include <QMargins> #include <QMargins>
#include <QCoreApplication> #include <QCoreApplication>
@@ -54,9 +54,7 @@ BuildSettingsWidget::BuildSettingsWidget(Target *target) :
if (!BuildConfigurationFactory::find(m_target)) { if (!BuildConfigurationFactory::find(m_target)) {
auto noSettingsLabel = new QLabel(this); auto noSettingsLabel = new QLabel(this);
noSettingsLabel->setText(Tr::tr("No build settings available")); noSettingsLabel->setText(Tr::tr("No build settings available"));
QFont f = noSettingsLabel->font(); noSettingsLabel->setFont(StyleHelper::UiFont(StyleHelper::UiElementH2));
f.setPointSizeF(f.pointSizeF() * 1.2);
noSettingsLabel->setFont(f);
vbox->addWidget(noSettingsLabel); vbox->addWidget(noSettingsLabel);
return; return;
} }
@@ -128,10 +126,7 @@ void BuildSettingsWidget::addSubWidget(NamedWidget *widget)
auto label = new QLabel(this); auto label = new QLabel(this);
label->setText(widget->displayName()); label->setText(widget->displayName());
QFont f = label->font(); label->setFont(StyleHelper::UiFont(StyleHelper::UiElementH2));
f.setBold(true);
f.setPointSizeF(f.pointSizeF() * 1.2);
label->setFont(f);
label->setContentsMargins(0, 18, 0, 0); label->setContentsMargins(0, 18, 0, 0);

View File

@@ -100,10 +100,7 @@ void PanelsWidget::addPropertiesPanel(const QString &displayName)
auto nameLabel = new QLabel(m_root); auto nameLabel = new QLabel(m_root);
nameLabel->setText(displayName); nameLabel->setText(displayName);
nameLabel->setContentsMargins(0, ABOVE_HEADING_MARGIN, 0, 0); nameLabel->setContentsMargins(0, ABOVE_HEADING_MARGIN, 0, 0);
QFont f = nameLabel->font(); nameLabel->setFont(StyleHelper::UiFont(StyleHelper::UiElementH1));
f.setBold(true);
f.setPointSizeF(f.pointSizeF() * 1.6);
nameLabel->setFont(f);
m_layout->addWidget(nameLabel); m_layout->addWidget(nameLabel);
m_layout->addWidget(Layouting::createHr()); m_layout->addWidget(Layouting::createHr());
} }

View File

@@ -37,6 +37,7 @@
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/qtcsettings.h> #include <utils/qtcsettings.h>
#include <utils/styledbar.h> #include <utils/styledbar.h>
#include <utils/stylehelper.h>
#include <utils/treemodel.h> #include <utils/treemodel.h>
#include <utils/utilsicons.h> #include <utils/utilsicons.h>
@@ -569,10 +570,7 @@ public:
selectorView->setAutoFillBackground(true); selectorView->setAutoFillBackground(true);
auto activeLabel = new QLabel(Tr::tr("Active Project")); auto activeLabel = new QLabel(Tr::tr("Active Project"));
QFont font = activeLabel->font(); activeLabel->setFont(StyleHelper::UiFont(StyleHelper::UiElementH2));
font.setBold(true);
font.setPointSizeF(font.pointSizeF() * 1.2);
activeLabel->setFont(font);
auto innerLayout = new QVBoxLayout; auto innerLayout = new QVBoxLayout;
innerLayout->setSpacing(10); innerLayout->setSpacing(10);
@@ -905,8 +903,7 @@ void SelectorDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
case 2: { case 2: {
QColor col = creatorTheme()->color(Theme::TextColorNormal); QColor col = creatorTheme()->color(Theme::TextColorNormal);
opt.palette.setColor(QPalette::Text, col); opt.palette.setColor(QPalette::Text, col);
opt.font.setBold(true); opt.font = StyleHelper::UiFont(StyleHelper::UiElementH2);
opt.font.setPointSizeF(opt.font.pointSizeF() * 1.2);
break; break;
} }
} }

View File

@@ -17,7 +17,7 @@
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/stringutils.h> #include <utils/stringutils.h>
#include <utils/infolabel.h> #include <utils/stylehelper.h>
#include <QAction> #include <QAction>
#include <QComboBox> #include <QComboBox>
@@ -69,10 +69,7 @@ RunSettingsWidget::RunSettingsWidget(Target *target) :
runLabel->setBuddy(m_runConfigurationCombo); runLabel->setBuddy(m_runConfigurationCombo);
QFont f = runLabel->font(); const QFont f = Utils::StyleHelper::UiFont(Utils::StyleHelper::UiElementH2);
f.setBold(true);
f.setPointSizeF(f.pointSizeF() * 1.2);
runTitle->setFont(f); runTitle->setFont(f);
deployTitle->setFont(f); deployTitle->setFont(f);
@@ -501,10 +498,7 @@ void RunSettingsWidget::addSubWidget(QWidget *widget, QLabel *label)
{ {
widget->setContentsMargins({}); widget->setContentsMargins({});
QFont f = label->font(); label->setFont(Utils::StyleHelper::UiFont(Utils::StyleHelper::UiElementH2));
f.setBold(true);
f.setPointSizeF(f.pointSizeF() * 1.2);
label->setFont(f);
label->setContentsMargins(0, 18, 0, 0); label->setContentsMargins(0, 18, 0, 0);

View File

@@ -25,6 +25,7 @@
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/stylehelper.h>
#include <utils/treemodel.h> #include <utils/treemodel.h>
#include <utils/utilsicons.h> #include <utils/utilsicons.h>
@@ -184,10 +185,7 @@ void TargetGroupItemPrivate::ensureWidget()
auto label = new QLabel; auto label = new QLabel;
label->setText(Tr::tr("No kit defined in this project.")); label->setText(Tr::tr("No kit defined in this project."));
QFont f = label->font(); label->setFont(StyleHelper::UiFont(StyleHelper::UiElementH2));
f.setPointSizeF(f.pointSizeF() * 1.4);
f.setBold(true);
label->setFont(f);
label->setContentsMargins(10, 10, 10, 10); label->setContentsMargins(10, 10, 10, 10);
label->setAlignment(Qt::AlignTop); label->setAlignment(Qt::AlignTop);

View File

@@ -3,6 +3,9 @@
#include "dragshapebutton.h" #include "dragshapebutton.h"
#include "baseitem.h" #include "baseitem.h"
#include <utils/stylehelper.h>
#include <QDrag> #include <QDrag>
#include <QGuiApplication> #include <QGuiApplication>
#include <QMimeData> #include <QMimeData>
@@ -17,9 +20,7 @@ DragShapeButton::DragShapeButton(QWidget *parent)
setMinimumSize(75, 75); setMinimumSize(75, 75);
setMaximumSize(75, 75); setMaximumSize(75, 75);
setIconSize(QSize(45, 45)); setIconSize(QSize(45, 45));
QFont f = font(); setFont(Utils::StyleHelper::UiFont(Utils::StyleHelper::UiElementPanelSubtitle));
f.setPointSize(8);
setFont(f);
} }
void DragShapeButton::setShapeInfo(int groupIndex, int shapeIndex) void DragShapeButton::setShapeInfo(int groupIndex, int shapeIndex)

View File

@@ -78,9 +78,7 @@ IntroductionWidget::IntroductionWidget(QWidget *parent)
m_continueLabel->setAlignment(Qt::AlignCenter); m_continueLabel->setAlignment(Qt::AlignCenter);
m_continueLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); m_continueLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
m_continueLabel->setWordWrap(true); m_continueLabel->setWordWrap(true);
auto fnt = font(); m_continueLabel->setFont(StyleHelper::UiFont(StyleHelper::UiElementH1));
fnt.setPointSizeF(fnt.pointSizeF() * 1.5);
m_continueLabel->setFont(fnt);
m_continueLabel->setPalette(palette()); m_continueLabel->setPalette(palette());
layout->addWidget(m_continueLabel); layout->addWidget(m_continueLabel);
m_bodyCss = "font-size: 16px;"; m_bodyCss = "font-size: 16px;";