fix: font macro expansion + snaplayout jitter with fillWidth: true

This commit is contained in:
2026-11-07 14:42:22 +01:00
parent 4ac55b0c2e
commit a7767d2a80
6 changed files with 296 additions and 172 deletions
+35 -22
View File
@@ -5,6 +5,15 @@
namespace ZShell::config {
namespace {
settings::ObjectNode* style(
const settings::ObjectNode* cfg, const QString& key) {
return cfg->value(key).value<settings::ObjectNode*>();
}
} // namespace
FontStyleBase::FontStyleBase(QObject* parent) : QObject(parent) {}
QFont FontStyleBase::large() const {
@@ -20,12 +29,14 @@ QFont FontStyleBase::small() const {
}
QFont FontStyleBase::buildFont(
const FontSizeNode* cfg, const QString& fallbackFamily, qreal scale) {
const auto family = cfg->property("family").toString();
const auto size = cfg->property("size").toInt();
const auto weight = cfg->property("weight").value<QFont::Weight>();
const auto italic = cfg->property("italic").toBool();
const auto vaxes = cfg->property("vaxes").toMap();
const settings::ObjectNode* cfg,
const QString& fallbackFamily,
qreal scale) {
const auto family = cfg->value(u"family"_s).toString();
const auto size = cfg->value(u"size"_s).toInt();
const auto weight = cfg->value(u"weight"_s).value<QFont::Weight>();
const auto italic = cfg->value(u"italic"_s).toBool();
const auto vaxes = cfg->value(u"vaxes"_s).toMap();
QFont font;
font.setFamily(family.isEmpty() ? fallbackFamily : family);
@@ -45,14 +56,14 @@ QFont FontStyleBase::buildFont(
return font;
}
void FontStyleBase::bind(FontStyleNode* cfg) {
void FontStyleBase::bind(settings::ObjectNode* cfg) {
if (m_cfg == cfg) return;
if (m_cfg) {
disconnect(m_cfg, nullptr, this, nullptr);
disconnect(m_cfg->largeNode(), nullptr, this, nullptr);
disconnect(m_cfg->mediumNode(), nullptr, this, nullptr);
disconnect(m_cfg->smallNode(), nullptr, this, nullptr);
disconnect(style(m_cfg, u"large"_s), nullptr, this, nullptr);
disconnect(style(m_cfg, u"medium"_s), nullptr, this, nullptr);
disconnect(style(m_cfg, u"small"_s), nullptr, this, nullptr);
}
m_cfg = cfg;
@@ -61,17 +72,17 @@ void FontStyleBase::bind(FontStyleNode* cfg) {
connect(
cfg, &settings::Node::optionChanged, this, &FontStyleBase::rebuild);
connect(
cfg->largeNode(),
style(cfg, u"large"_s),
&settings::Node::optionChanged,
this,
&FontStyleBase::rebuild);
connect(
cfg->mediumNode(),
style(cfg, u"medium"_s),
&settings::Node::optionChanged,
this,
&FontStyleBase::rebuild);
connect(
cfg->smallNode(),
style(cfg, u"small"_s),
&settings::Node::optionChanged,
this,
&FontStyleBase::rebuild);
@@ -82,10 +93,10 @@ void FontStyleBase::bind(FontStyleNode* cfg) {
void FontStyleBase::rebuild() {
if (m_cfg) {
const auto family = m_cfg->property("family").toString();
m_large = buildFont(m_cfg->largeNode(), family, m_scale);
m_medium = buildFont(m_cfg->mediumNode(), family, m_scale);
m_small = buildFont(m_cfg->smallNode(), family, m_scale);
const auto family = m_cfg->value(u"family"_s).toString();
m_large = buildFont(style(m_cfg, u"large"_s), family, m_scale);
m_medium = buildFont(style(m_cfg, u"medium"_s), family, m_scale);
m_small = buildFont(style(m_cfg, u"small"_s), family, m_scale);
} else {
m_large = QFont();
m_medium = QFont();
@@ -118,16 +129,17 @@ FontBuilder IconFontStyle::pixelSize(int pixelSize) {
return FontBuilder(m_small).pixelSize(pixelSize);
}
void IconFontStyle::bind(FontStyleNode* cfg) {
void IconFontStyle::bind(settings::ObjectNode* cfg) {
if (m_cfg == cfg) return;
if (m_cfg) disconnect(m_cfg->extraLargeNode(), nullptr, this, nullptr);
if (m_cfg)
disconnect(style(m_cfg, u"extraLarge"_s), nullptr, this, nullptr);
FontStyleBase::bind(cfg);
if (cfg)
connect(
cfg->extraLargeNode(),
style(cfg, u"extraLarge"_s),
&settings::Node::optionChanged,
this,
&IconFontStyle::rebuild);
@@ -143,8 +155,9 @@ IconFontBuilders* IconFontStyle::builders() const {
void IconFontStyle::rebuild() {
if (m_cfg) {
const auto family = m_cfg->property("family").toString();
m_extraLarge = buildFont(m_cfg->extraLargeNode(), family, m_scale);
const auto family = m_cfg->value(u"family"_s).toString();
m_extraLarge =
buildFont(style(m_cfg, u"extraLarge"_s), family, m_scale);
} else {
m_extraLarge = QFont();
}