feat: add root font size scale
This commit is contained in:
parent
9877bea91b
commit
70ee7e754d
3 changed files with 37 additions and 11 deletions
|
|
@ -180,6 +180,7 @@ class AppearanceFont : public ConfigObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
QML_ANONYMOUS
|
QML_ANONYMOUS
|
||||||
|
|
||||||
|
CONFIG_PROPERTY(qreal, scale, 1)
|
||||||
CONFIG_SUBOBJECT(FontStyleConfig, headline)
|
CONFIG_SUBOBJECT(FontStyleConfig, headline)
|
||||||
CONFIG_SUBOBJECT(FontStyleConfig, title)
|
CONFIG_SUBOBJECT(FontStyleConfig, title)
|
||||||
CONFIG_SUBOBJECT(FontStyleConfig, body)
|
CONFIG_SUBOBJECT(FontStyleConfig, body)
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,13 @@ QFont FontStyleBase::small() const {
|
||||||
return m_small;
|
return m_small;
|
||||||
}
|
}
|
||||||
|
|
||||||
QFont FontStyleBase::buildFont(const FontConfig* cfg, const QString& fallbackFamily) {
|
QFont FontStyleBase::buildFont(const FontConfig* cfg, const QString& fallbackFamily, qreal scale) {
|
||||||
QFont font;
|
QFont font;
|
||||||
font.setFamily(cfg->family().isEmpty() ? fallbackFamily : cfg->family());
|
font.setFamily(cfg->family().isEmpty() ? fallbackFamily : cfg->family());
|
||||||
font.setPointSize(cfg->size() > 0 ? cfg->size() : 1);
|
const int scaledSize = static_cast<int>(cfg->size() * scale);
|
||||||
font.setVariableAxis("opsz", static_cast<float>(font.pointSize()));
|
const int cappedSize = scaledSize > 0 ? scaledSize : 1;
|
||||||
|
font.setPointSize(cappedSize);
|
||||||
|
font.setVariableAxis("opsz", static_cast<float>(cappedSize));
|
||||||
font.setWeight(QFont::Weight(cfg->weight()));
|
font.setWeight(QFont::Weight(cfg->weight()));
|
||||||
font.setVariableAxis("wght", font.weight());
|
font.setVariableAxis("wght", font.weight());
|
||||||
font.setItalic(cfg->italic());
|
font.setItalic(cfg->italic());
|
||||||
|
|
@ -61,9 +63,9 @@ void FontStyleBase::bind(FontStyleConfig* cfg) {
|
||||||
void FontStyleBase::rebuild() {
|
void FontStyleBase::rebuild() {
|
||||||
if (m_cfg) {
|
if (m_cfg) {
|
||||||
const auto family = m_cfg->family();
|
const auto family = m_cfg->family();
|
||||||
m_large = buildFont(m_cfg->large(), family);
|
m_large = buildFont(m_cfg->large(), family, m_scale);
|
||||||
m_medium = buildFont(m_cfg->medium(), family);
|
m_medium = buildFont(m_cfg->medium(), family, m_scale);
|
||||||
m_small = buildFont(m_cfg->small(), family);
|
m_small = buildFont(m_cfg->small(), family, m_scale);
|
||||||
} else {
|
} else {
|
||||||
m_large = QFont();
|
m_large = QFont();
|
||||||
m_medium = QFont();
|
m_medium = QFont();
|
||||||
|
|
@ -72,6 +74,13 @@ void FontStyleBase::rebuild() {
|
||||||
emit fontsChanged();
|
emit fontsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FontStyleBase::setScale(qreal scale) {
|
||||||
|
if (qFuzzyCompare(m_scale + 1.0, scale + 1.0))
|
||||||
|
return;
|
||||||
|
m_scale = scale;
|
||||||
|
rebuild();
|
||||||
|
}
|
||||||
|
|
||||||
// FontStyle
|
// FontStyle
|
||||||
|
|
||||||
FontStyle::FontStyle(QObject* parent)
|
FontStyle::FontStyle(QObject* parent)
|
||||||
|
|
@ -119,10 +128,10 @@ IconFontBuilders* IconFontStyle::builders() const {
|
||||||
void IconFontStyle::rebuild() {
|
void IconFontStyle::rebuild() {
|
||||||
if (auto* cfg = qobject_cast<IconFontStyleConfig*>(m_cfg)) {
|
if (auto* cfg = qobject_cast<IconFontStyleConfig*>(m_cfg)) {
|
||||||
const auto family = cfg->family();
|
const auto family = cfg->family();
|
||||||
m_large = buildFont(cfg->large(), family);
|
m_large = buildFont(cfg->large(), family, m_scale);
|
||||||
m_medium = buildFont(cfg->medium(), family);
|
m_medium = buildFont(cfg->medium(), family, m_scale);
|
||||||
m_small = buildFont(cfg->small(), family);
|
m_small = buildFont(cfg->small(), family, m_scale);
|
||||||
m_extraLarge = buildFont(cfg->extraLarge(), family);
|
m_extraLarge = buildFont(cfg->extraLarge(), family, m_scale);
|
||||||
} else {
|
} else {
|
||||||
m_large = QFont();
|
m_large = QFont();
|
||||||
m_medium = QFont();
|
m_medium = QFont();
|
||||||
|
|
@ -210,6 +219,7 @@ void FontTokens::bindFont(AppearanceFont* font) {
|
||||||
m_font = font;
|
m_font = font;
|
||||||
|
|
||||||
if (font) {
|
if (font) {
|
||||||
|
rebuildScale();
|
||||||
m_headline->bind(font->headline());
|
m_headline->bind(font->headline());
|
||||||
m_title->bind(font->title());
|
m_title->bind(font->title());
|
||||||
m_body->bind(font->body());
|
m_body->bind(font->body());
|
||||||
|
|
@ -218,7 +228,9 @@ void FontTokens::bindFont(AppearanceFont* font) {
|
||||||
m_icon->bind(font->icon());
|
m_icon->bind(font->icon());
|
||||||
|
|
||||||
connect(font, &AppearanceFont::clockChanged, this, &FontTokens::rebuildClock);
|
connect(font, &AppearanceFont::clockChanged, this, &FontTokens::rebuildClock);
|
||||||
|
connect(font, &AppearanceFont::scaleChanged, this, &FontTokens::rebuildScale);
|
||||||
} else {
|
} else {
|
||||||
|
rebuildScale();
|
||||||
m_headline->bind(nullptr);
|
m_headline->bind(nullptr);
|
||||||
m_title->bind(nullptr);
|
m_title->bind(nullptr);
|
||||||
m_body->bind(nullptr);
|
m_body->bind(nullptr);
|
||||||
|
|
@ -230,6 +242,16 @@ void FontTokens::bindFont(AppearanceFont* font) {
|
||||||
rebuildClock();
|
rebuildClock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FontTokens::rebuildScale() {
|
||||||
|
const qreal s = m_font ? m_font->scale() : 1;
|
||||||
|
m_headline->setScale(s);
|
||||||
|
m_title->setScale(s);
|
||||||
|
m_body->setScale(s);
|
||||||
|
m_label->setScale(s);
|
||||||
|
m_mono->setScale(s);
|
||||||
|
m_icon->setScale(s);
|
||||||
|
}
|
||||||
|
|
||||||
void FontTokens::rebuildClock() {
|
void FontTokens::rebuildClock() {
|
||||||
QFont f;
|
QFont f;
|
||||||
if (m_font)
|
if (m_font)
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ public:
|
||||||
: QObject(parent) {}
|
: QObject(parent) {}
|
||||||
|
|
||||||
void bind(FontStyleConfig* cfg);
|
void bind(FontStyleConfig* cfg);
|
||||||
|
void setScale(qreal scale);
|
||||||
|
|
||||||
[[nodiscard]] QFont large() const;
|
[[nodiscard]] QFont large() const;
|
||||||
[[nodiscard]] QFont medium() const;
|
[[nodiscard]] QFont medium() const;
|
||||||
|
|
@ -70,9 +71,10 @@ signals:
|
||||||
protected:
|
protected:
|
||||||
virtual void rebuild();
|
virtual void rebuild();
|
||||||
|
|
||||||
static QFont buildFont(const FontConfig* cfg, const QString& fallbackFamily);
|
static QFont buildFont(const FontConfig* cfg, const QString& fallbackFamily, qreal scale);
|
||||||
|
|
||||||
FontStyleConfig* m_cfg = nullptr;
|
FontStyleConfig* m_cfg = nullptr;
|
||||||
|
qreal m_scale = 1;
|
||||||
QFont m_large;
|
QFont m_large;
|
||||||
QFont m_medium;
|
QFont m_medium;
|
||||||
QFont m_small;
|
QFont m_small;
|
||||||
|
|
@ -148,6 +150,7 @@ signals:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void rebuildClock();
|
void rebuildClock();
|
||||||
|
void rebuildScale();
|
||||||
|
|
||||||
AppearanceFont* m_font = nullptr;
|
AppearanceFont* m_font = nullptr;
|
||||||
FontStyle* m_headline;
|
FontStyle* m_headline;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue