Utils: Align enum StyleHelper::UiElement with upcoming design system #3

The Qt Creator Design System defines display headings H1 and H2 with a
"Titillium  Web" font face.

This change introduces the "Titillium Web" based as new H1 and H2 and
lets the WelcomeScreen code obtain them via StyleHelper::UiFont(). It is
supposed to not change the visual appearance.

Change-Id: Ia2c5ac14858e574c4ffd31af1ed80ac1781cd970
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Alessandro Portale
2023-11-17 11:06:23 +01:00
parent b3acdae338
commit 1da84754db
6 changed files with 26 additions and 29 deletions

View File

@@ -933,6 +933,15 @@ QColor StyleHelper::ensureReadableOn(const QColor &background, const QColor &des
return foreground;
}
static QStringList brandFontFamilies()
{
const static QStringList families = []{
const int id = QFontDatabase::addApplicationFont(":/studiofonts/TitilliumWeb-Regular.ttf");
return id >= 0 ? QFontDatabase::applicationFontFamilies(id) : QStringList();
}();
return families;
}
QFont StyleHelper::UiFont(UiElement element)
{
QFont font;
@@ -941,8 +950,14 @@ QFont StyleHelper::UiFont(UiElement element)
switch (element) {
case UiElementH1:
font.setFamilies(brandFontFamilies());
font.setPixelSize(30);
font.setWeight(QFont::Light);
font.setWordSpacing(2);
break;
case UiElementH2:
font.setFamilies(brandFontFamilies());
font.setPixelSize(16);
break;
case UiElementH3:
font.setPointSizeF(font.pointSizeF() * 1.6);

View File

@@ -8,6 +8,7 @@
#include <utils/icon.h>
#include <utils/theme/theme.h>
#include <utils/stylehelper.h>
#include <QHBoxLayout>
#include <QLabel>
@@ -177,7 +178,7 @@ void WelcomePageButton::setSize(Size size)
const int hMargin = size == SizeSmall ? 12 : 26;
const int vMargin = size == SizeSmall ? 2 : 4;
d->m_layout->setContentsMargins(hMargin, vMargin, hMargin, vMargin);
d->m_label->setFont(size == SizeSmall ? font() : WelcomePageHelpers::brandFont());
d->m_label->setFont(size == SizeSmall ? font() : StyleHelper::UiFont(StyleHelper::UiElementH2));
}
void WelcomePageButton::setWithAccentColor(bool withAccent)

View File

@@ -13,7 +13,6 @@
#include <utils/theme/theme.h>
#include <QEasingCurve>
#include <QFontDatabase>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QHoverEvent>
@@ -46,21 +45,6 @@ static QFont sizedFont(int size, const QWidget *widget)
namespace WelcomePageHelpers {
QFont brandFont()
{
const static QFont f = []{
const int id = QFontDatabase::addApplicationFont(":/studiofonts/TitilliumWeb-Regular.ttf");
QFont result;
result.setPixelSize(16);
if (id >= 0) {
const QStringList fontFamilies = QFontDatabase::applicationFontFamilies(id);
result.setFamilies(fontFamilies);
}
return result;
}();
return f;
}
QWidget *panelBar(QWidget *parent)
{
auto frame = new QWidget(parent);
@@ -83,7 +67,7 @@ SearchBox::SearchBox(QWidget *parent)
m_lineEdit = new FancyLineEdit;
m_lineEdit->setFiltering(true);
m_lineEdit->setFrame(false);
m_lineEdit->setFont(WelcomePageHelpers::brandFont());
m_lineEdit->setFont(StyleHelper::UiFont(StyleHelper::UiElementH2));
m_lineEdit->setMinimumHeight(33);
m_lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
@@ -801,7 +785,7 @@ ListModel *SectionedGridView::addSection(const Section &section, const QList<Lis
}.emerge();
m_sectionLabels.append(sectionLabel);
sectionLabel->setContentsMargins(0, ItemGap, 0, 0);
sectionLabel->setFont(Core::WelcomePageHelpers::brandFont());
sectionLabel->setFont(StyleHelper::UiFont(StyleHelper::UiElementH2));
auto scrollArea = qobject_cast<QScrollArea *>(widget(0));
auto vbox = qobject_cast<QVBoxLayout *>(scrollArea->widget()->layout());
@@ -858,7 +842,7 @@ void SectionedGridView::zoomInSection(const Section &section)
noMargin
}.emerge();
sectionLabel->setContentsMargins(0, ItemGap, 0, 0);
sectionLabel->setFont(Core::WelcomePageHelpers::brandFont());
sectionLabel->setFont(StyleHelper::UiFont(StyleHelper::UiElementH2));
auto gridView = new GridView(zoomedInWidget);
gridView->setItemDelegate(m_itemDelegate);

View File

@@ -35,7 +35,6 @@ constexpr QSize GridItemImageSize(GridItemWidth - GridItemGap
- GridItemGap - 1 // Upper margin + 1 pixel
- 67); // Bottom margin (for title + tags)
CORE_EXPORT QFont brandFont();
CORE_EXPORT QWidget *panelBar(QWidget *parent = nullptr);
} // namespace WelcomePageHelpers

View File

@@ -23,7 +23,7 @@
#include <utils/icon.h>
#include <utils/qtcassert.h>
#include <utils/stringutils.h>
#include <utils/qtcassert.h>
#include <utils/stylehelper.h>
#include <utils/theme/theme.h>
#include <QAbstractItemDelegate>
@@ -583,11 +583,11 @@ public:
manageSessionsButton->setOnClicked([] { SessionManager::showSessionManager(); });
auto sessionsLabel = new QLabel(this);
sessionsLabel->setFont(brandFont());
sessionsLabel->setFont(StyleHelper::UiFont(StyleHelper::UiElementH2));
sessionsLabel->setText(Tr::tr("Sessions"));
auto recentProjectsLabel = new QLabel(this);
recentProjectsLabel->setFont(brandFont());
recentProjectsLabel->setFont(StyleHelper::UiFont(StyleHelper::UiElementH2));
recentProjectsLabel->setText(Tr::tr("Projects"));
auto sessionsList = new TreeView(this, "Sessions");

View File

@@ -24,6 +24,7 @@
#include <utils/icon.h>
#include <utils/qtcassert.h>
#include <utils/styledbar.h>
#include <utils/stylehelper.h>
#include <utils/theme/theme.h>
#include <utils/treemodel.h>
@@ -175,10 +176,7 @@ public:
hbox->addSpacing(16);
QFont welcomeFont = brandFont();
welcomeFont.setPixelSize(30);
welcomeFont.setWeight(QFont::Light);
welcomeFont.setWordSpacing(2);
const QFont welcomeFont = StyleHelper::UiFont(StyleHelper::UiElementH1);
auto welcomeLabel = new QLabel("Welcome to");
welcomeLabel->setFont(welcomeFont);
@@ -263,7 +261,7 @@ public:
vbox->addItem(newVBox);
auto newLabel = new QLabel(Tr::tr("New to Qt?"), mainWidget);
newLabel->setFont(brandFont());
newLabel->setFont(StyleHelper::UiFont(StyleHelper::UiElementH2));
newLabel->setAlignment(Qt::AlignHCenter);
newVBox->addWidget(newLabel);