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 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'Bootstrap.cxx') 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)); -- cgit v1.2.3