From 81a72b6eeb0614d2f8139314cf5d3948faa467b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Wed, 12 Apr 2023 17:28:44 +0800 Subject: Body font & its use in Label --- Bootstrap.cxx | 40 +++++++++++++++++++++++++++++++++++++++- Bootstrap.hxx | 12 +++++++++++- Label.qml | 5 +++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/Bootstrap.cxx b/Bootstrap.cxx index 31681a4..99a8639 100644 --- a/Bootstrap.cxx +++ b/Bootstrap.cxx @@ -9,15 +9,32 @@ B[i] = QColor{color.u.s};\ free(color.u.s);\ } - + Bootstrap::Bootstrap(QObject *parent): QObject{parent}, bsMode{Mode::Light}, bsTheme{Theme::None}, +#ifdef __ANDROID__ + bsFontSansSerif{"Roboto"}, +#elif defined(__APPLE__) + bsFontSansSerif{"Helvetica Neue"}, +#elif defined(__EMSCRIPTEN__) + bsFontSansSerif{"Arial"}, +#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32) \ + || defined(_WIN64) || defined(__WIN64) + bsFontSansSerif{"Segoe UI"}, +#else + bsFontSansSerif{"Liberation Sans"}, +#endif + bsBodyFont{bsFontSansSerif}, bodyColors{{"#212529", "#adb5bd"}}, bodyBgs{{"#fff", "#212529"}}, borderColors{{"#dee2e6", "#495057"}} { + bsBodyFont.setStyleHint(QFont::SansSerif); + bsBodyFont.setPointSizeF(16.0); + bsBodyFont.setWeight(QFont::Normal); + QFile conf{QStringLiteral(":/qtquickcontrols2.conf")}; if (!conf.open(QIODevice::ReadOnly | QIODevice::Text)) return; auto toml = toml_parse(conf.readAll().data(), nullptr, 0); @@ -32,6 +49,17 @@ Bootstrap::Bootstrap(QObject *parent): auto mode = toml_int_in(bootstrap, "Mode"); if (mode.ok) bsMode = static_cast(mode.u.i); + auto fontFamily = toml_string_in(bootstrap, "BodyFontFamily"); + if (fontFamily.ok) { + bsBodyFont.setFamily(fontFamily.u.s); + free(fontFamily.u.s); + bsBodyFont.setStyleHint(QFont::AnyStyle); + } + auto fontSize = toml_double_in(bootstrap, "BodyFontSize"); + if (fontSize.ok) bsBodyFont.setPointSizeF(fontSize.u.d); + auto fontWeight = toml_int_in(bootstrap, "BodyFontWeight"); + if (fontWeight.ok) bsBodyFont.setWeight(fontWeight.u.i); + toml_array_t *colors; OVERRIDE_COLORS("BodyColors", bodyColors); OVERRIDE_COLORS("BodyBgs", bodyBgs); @@ -72,6 +100,16 @@ void Bootstrap::setTheme(Theme theme) emit themeChanged(); } +QString Bootstrap::fontSansSerif() const +{ + return bsFontSansSerif; +} + +QFont Bootstrap::bodyFont() const +{ + return bsBodyFont; +} + QColor Bootstrap::bodyColor() const { return bodyColors.at(static_cast(bsMode)); diff --git a/Bootstrap.hxx b/Bootstrap.hxx index 8b70645..37b5870 100644 --- a/Bootstrap.hxx +++ b/Bootstrap.hxx @@ -1,8 +1,9 @@ #ifndef BOOTSTRAP_HXX #define BOOTSTRAP_HXX -#include +#include #include +#include class Qootstrap : public QQmlEngineExtensionPlugin { @@ -16,6 +17,9 @@ class Bootstrap : public QObject Q_CLASSINFO("RegisterEnumClassesUnscoped", "false") Q_PROPERTY(Mode mode READ mode WRITE setMode NOTIFY modeChanged) Q_PROPERTY(Theme theme READ theme WRITE setTheme NOTIFY themeChanged) + Q_PROPERTY(QString fontSansSerif READ fontSansSerif + NOTIFY fontSansSerifChanged) + Q_PROPERTY(QFont bodyFont READ bodyFont NOTIFY bodyFontChanged) Q_PROPERTY(QColor bodyColor READ bodyColor NOTIFY bodyColorChanged) Q_PROPERTY(QColor bodyBg READ bodyBg NOTIFY bodyBgChanged) Q_PROPERTY(QColor borderColor READ borderColor @@ -51,6 +55,8 @@ class Bootstrap : public QObject Theme theme() const; void setTheme(Theme theme); + QString fontSansSerif() const; + QFont bodyFont() const; QColor bodyColor() const; QColor bodyBg() const; QColor borderColor() const; @@ -61,10 +67,14 @@ class Bootstrap : public QObject void bodyColorChanged(); void bodyBgChanged(); void borderColorChanged(); + void fontSansSerifChanged(); + void bodyFontChanged(); private: Mode bsMode; Theme bsTheme; + QString bsFontSansSerif; + QFont bsBodyFont; QVector bodyColors; QVector bodyBgs; QVector borderColors; diff --git a/Label.qml b/Label.qml index 593ded0..c2038e0 100644 --- a/Label.qml +++ b/Label.qml @@ -4,6 +4,11 @@ import Bootstrap 5.3 Label { id: control + font { + family: Bootstrap.bodyFont.family + pointSize: Bootstrap.bodyFont.pointSize + weight: Bootstrap.bodyFont.weight + } color: Bootstrap.bodyColor linkColor: control.palette.link } -- cgit v1.2.3