fix: font macro expansion + snaplayout jitter with fillWidth: true
This commit is contained in:
@@ -30,6 +30,8 @@ qml_module(ZShell-config
|
||||
utilities.hpp
|
||||
DEPENDENCIES
|
||||
ZShell.Settings
|
||||
LIBRARIES
|
||||
Qt::Quick
|
||||
)
|
||||
|
||||
target_link_libraries(ZShell-config PUBLIC
|
||||
|
||||
@@ -134,25 +134,11 @@ struct FontConfig {
|
||||
|
||||
} // namespace detail
|
||||
|
||||
class FontSizeNode : public settings::ObjectNode {
|
||||
CONFIG_NODE(FontSizeNode, settings::ObjectNode)
|
||||
};
|
||||
|
||||
class FontStyleNode : public settings::ObjectNode {
|
||||
CONFIG_NODE(FontStyleNode, settings::ObjectNode)
|
||||
|
||||
public:
|
||||
virtual FontSizeNode* largeNode() const = 0;
|
||||
virtual FontSizeNode* mediumNode() const = 0;
|
||||
virtual FontSizeNode* smallNode() const = 0;
|
||||
virtual FontSizeNode* extraLargeNode() const { return nullptr; }
|
||||
};
|
||||
|
||||
#define ARG(...) __VA_ARGS__
|
||||
#define FONT(...) ZShell::config::detail::FontConfig __VA_ARGS__
|
||||
#define FONT_CONFIG(Style, Size, props) \
|
||||
class FontConfig##Style##Size : public FontSizeNode { \
|
||||
CONFIG_NODE(FontConfig##Style##Size, FontSizeNode) \
|
||||
class FontConfig##Style##Size : public settings::ObjectNode { \
|
||||
CONFIG_NODE(FontConfig##Style##Size, settings::ObjectNode) \
|
||||
\
|
||||
CONFIG_PROPERTY( \
|
||||
QString, \
|
||||
@@ -168,18 +154,13 @@ class FontStyleNode : public settings::ObjectNode {
|
||||
FONT_CONFIG(Style, Medium, ARG(medium_)) \
|
||||
FONT_CONFIG(Style, Small, ARG(small_)) \
|
||||
\
|
||||
class FontStyle##Style : public FontStyleNode { \
|
||||
CONFIG_NODE(FontStyle##Style, FontStyleNode) \
|
||||
class FontStyle##Style : public settings::ObjectNode { \
|
||||
CONFIG_NODE(FontStyle##Style, settings::ObjectNode) \
|
||||
\
|
||||
CONFIG_PROPERTY(QString, family, family_) \
|
||||
CONFIG_SUBOBJECT(FontConfig##Style##Large, large) \
|
||||
CONFIG_SUBOBJECT(FontConfig##Style##Medium, medium) \
|
||||
CONFIG_SUBOBJECT(FontConfig##Style##Small, small) \
|
||||
\
|
||||
public: \
|
||||
FontSizeNode* largeNode() const override { return m_large; } \
|
||||
FontSizeNode* mediumNode() const override { return m_medium; } \
|
||||
FontSizeNode* smallNode() const override { return m_small; } \
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
@@ -215,20 +196,14 @@ FONT_CONFIG(Icon, Large, FONT({.size = static_cast<int>(32 / 1.33)}))
|
||||
FONT_CONFIG(Icon, Medium, FONT({.size = static_cast<int>(24 / 1.33)}))
|
||||
FONT_CONFIG(Icon, Small, FONT({.size = static_cast<int>(20 / 1.33)}))
|
||||
|
||||
class FontStyleIcon : public FontStyleNode {
|
||||
CONFIG_NODE(FontStyleIcon, FontStyleNode)
|
||||
class FontStyleIcon : public settings::ObjectNode {
|
||||
CONFIG_NODE(FontStyleIcon, settings::ObjectNode)
|
||||
|
||||
CONFIG_PROPERTY(QString, family, u"Material Symbols Rounded"_s)
|
||||
CONFIG_SUBOBJECT(FontConfigIconExtraLarge, extraLarge)
|
||||
CONFIG_SUBOBJECT(FontConfigIconLarge, large)
|
||||
CONFIG_SUBOBJECT(FontConfigIconMedium, medium)
|
||||
CONFIG_SUBOBJECT(FontConfigIconSmall, small)
|
||||
|
||||
public:
|
||||
FontSizeNode* extraLargeNode() const override { return m_extraLarge; }
|
||||
FontSizeNode* largeNode() const override { return m_large; }
|
||||
FontSizeNode* mediumNode() const override { return m_medium; }
|
||||
FontSizeNode* smallNode() const override { return m_small; }
|
||||
};
|
||||
|
||||
#undef ARG
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -2,18 +2,16 @@
|
||||
|
||||
#include "fontbuilder.hpp"
|
||||
|
||||
#include <qfont.h>
|
||||
#include <qobject.h>
|
||||
#include <qqmlintegration.h>
|
||||
#include <qvariantmap.h>
|
||||
|
||||
#include "settings/objectnode.hpp"
|
||||
|
||||
namespace ZShell::config {
|
||||
|
||||
class AppearanceFont;
|
||||
class FontBuilders;
|
||||
class FontStyleBase;
|
||||
class FontSizeNode;
|
||||
class FontStyleNode;
|
||||
class IconFontStyle;
|
||||
|
||||
class FontBuilders : public QObject {
|
||||
@@ -69,7 +67,7 @@ class FontStyleBase : public QObject {
|
||||
public:
|
||||
explicit FontStyleBase(QObject* parent = nullptr);
|
||||
|
||||
virtual void bind(FontStyleNode* cfg);
|
||||
virtual void bind(settings::ObjectNode* cfg);
|
||||
void setScale(qreal scale);
|
||||
|
||||
[[nodiscard]] QFont large() const;
|
||||
@@ -83,9 +81,11 @@ class FontStyleBase : public QObject {
|
||||
virtual void rebuild();
|
||||
|
||||
static QFont buildFont(
|
||||
const FontSizeNode* cfg, const QString& fallbackFamily, qreal scale);
|
||||
const settings::ObjectNode* cfg,
|
||||
const QString& fallbackFamily,
|
||||
qreal scale);
|
||||
|
||||
FontStyleNode* m_cfg = nullptr;
|
||||
settings::ObjectNode* m_cfg = nullptr;
|
||||
qreal m_scale = 1;
|
||||
QFont m_large;
|
||||
QFont m_medium;
|
||||
@@ -96,7 +96,8 @@ class FontStyle : public FontStyleBase {
|
||||
Q_OBJECT
|
||||
QML_ANONYMOUS
|
||||
|
||||
Q_PROPERTY(FontBuilders* builders READ builders CONSTANT FINAL)
|
||||
Q_PROPERTY(
|
||||
ZShell::config::FontBuilders* builders READ builders CONSTANT FINAL)
|
||||
|
||||
public:
|
||||
explicit FontStyle(QObject* parent = nullptr);
|
||||
@@ -112,15 +113,16 @@ class IconFontStyle : public FontStyleBase {
|
||||
QML_ANONYMOUS
|
||||
|
||||
Q_PROPERTY(QFont extraLarge READ extraLarge NOTIFY fontsChanged FINAL)
|
||||
Q_PROPERTY(IconFontBuilders* builders READ builders CONSTANT FINAL)
|
||||
Q_PROPERTY(
|
||||
ZShell::config::IconFontBuilders* builders READ builders CONSTANT FINAL)
|
||||
|
||||
public:
|
||||
explicit IconFontStyle(QObject* parent = nullptr);
|
||||
|
||||
Q_INVOKABLE FontBuilder size(int pointSize);
|
||||
Q_INVOKABLE FontBuilder pixelSize(int pixelSize);
|
||||
Q_INVOKABLE ZShell::config::FontBuilder size(int pointSize);
|
||||
Q_INVOKABLE ZShell::config::FontBuilder pixelSize(int pixelSize);
|
||||
|
||||
void bind(FontStyleNode* cfg) override;
|
||||
void bind(settings::ObjectNode* cfg) override;
|
||||
|
||||
[[nodiscard]] QFont extraLarge() const;
|
||||
[[nodiscard]] IconFontBuilders* builders() const;
|
||||
|
||||
Reference in New Issue
Block a user