summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2023-04-12 17:28:44 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2023-04-12 17:28:44 +0800
commit81a72b6eeb0614d2f8139314cf5d3948faa467b0 (patch)
treee4db90f5f12c80fc6089d9db18397c32a5000c2a
parentdb23fd439fbc4acf7cb102538decb3e49100d6ff (diff)
Body font & its use in Label
-rw-r--r--Bootstrap.cxx40
-rw-r--r--Bootstrap.hxx12
-rw-r--r--Label.qml5
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>(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<int>(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 <QtQml>
+#include <QFont>
#include <QColor>
+#include <QtQml>
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<QColor> bodyColors;
QVector<QColor> bodyBgs;
QVector<QColor> 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
}