summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2023-04-06 11:01:41 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2023-04-06 11:01:41 +0800
commit54082b1c3cb5beb49d6820844cbdb96d2f46814f (patch)
tree851ac155136fe2af7307326914dc605e9b7b0a4e
parent03399dffb1d96dec521d24d2c31a90b665194b97 (diff)
BodyBg can be set only from conf for now
bs_ prefix changed to bs & then capital letter
-rw-r--r--bootstrap.cxx53
-rw-r--r--bootstrap.hxx12
2 files changed, 29 insertions, 36 deletions
diff --git a/bootstrap.cxx b/bootstrap.cxx
index 433ccfd..b7941df 100644
--- a/bootstrap.cxx
+++ b/bootstrap.cxx
@@ -3,19 +3,30 @@
Bootstrap::Bootstrap(QObject *parent):
QObject(parent),
- bs_mode(LightMode),
- bs_theme(None),
- bs_lightBodyBg("#fff"),
- bs_darkBodyBg("#212529")
+ bsMode(LightMode),
+ bsTheme(None),
+ bsLightBodyBg("#fff"),
+ bsDarkBodyBg("#212529")
{
QFile conf{QStringLiteral(":/qtquickcontrols2.conf")};
if (!conf.open(QIODevice::ReadOnly | QIODevice::Text)) return;
auto toml = toml_parse(conf.readAll().data(), nullptr, 0);
conf.close();
auto bootstrap = toml_table_in(toml, "Bootstrap");
- if (bootstrap) {
- auto mode = toml_int_in(bootstrap, "Mode");
- if (mode.ok) bs_mode = static_cast<Mode>(mode.u.i);
+ if (!bootstrap) {
+ toml_free(toml);
+ return;
+ }
+ auto mode = toml_int_in(bootstrap, "Mode");
+ if (mode.ok) bsMode = static_cast<Mode>(mode.u.i);
+ auto bodyBg = toml_array_in(bootstrap, "BodyBg");
+ if (bodyBg) {
+ auto lightBodyBg = toml_string_at(bodyBg, 0).u.s;
+ bsLightBodyBg = QColor{lightBodyBg};
+ free(lightBodyBg);
+ auto darkBodyBg = toml_string_at(bodyBg, 1).u.s;
+ bsDarkBodyBg = QColor{darkBodyBg};
+ free(darkBodyBg);
}
toml_free(toml);
}
@@ -27,44 +38,30 @@ Bootstrap *Bootstrap::qmlAttachedProperties(QObject *object)
Bootstrap::Mode Bootstrap::mode() const
{
- return bs_mode;
+ return bsMode;
}
void Bootstrap::setMode(Mode mode)
{
- if (mode == bs_mode) return;
- bs_mode = mode;
+ if (mode == bsMode) return;
+ bsMode = mode;
emit modeChanged();
emit bodyBgChanged();
}
Bootstrap::Theme Bootstrap::theme() const
{
- return bs_theme;
+ return bsTheme;
}
void Bootstrap::setTheme(Theme theme)
{
- if (theme == bs_theme) return;
- bs_theme = theme;
+ if (theme == bsTheme) return;
+ bsTheme = theme;
emit themeChanged();
}
QColor Bootstrap::bodyBg() const
{
- return bs_mode ? bs_darkBodyBg : bs_lightBodyBg;
-}
-
-void Bootstrap::setLightBodyBg(QColor lightBodyBg)
-{
- if (lightBodyBg == bs_lightBodyBg) return;
- bs_lightBodyBg = lightBodyBg;
- emit bodyBgChanged();
-}
-
-void Bootstrap::setDarkBodyBg(QColor darkBodyBg)
-{
- if (darkBodyBg == bs_darkBodyBg) return;
- bs_darkBodyBg = darkBodyBg;
- emit bodyBgChanged();
+ return bsMode ? bsDarkBodyBg : bsLightBodyBg;
}
diff --git a/bootstrap.hxx b/bootstrap.hxx
index 2297be0..b1c3f9c 100644
--- a/bootstrap.hxx
+++ b/bootstrap.hxx
@@ -16,8 +16,6 @@ class Bootstrap : public QObject
Q_PROPERTY(Mode mode READ mode WRITE setMode NOTIFY modeChanged)
Q_PROPERTY(Theme theme READ theme WRITE setTheme NOTIFY themeChanged)
Q_PROPERTY(QColor bodyBg READ bodyBg NOTIFY bodyBgChanged)
- Q_PROPERTY(QColor lightBodyBg WRITE setLightBodyBg)
- Q_PROPERTY(QColor darkBodyBg WRITE setDarkBodyBg)
QML_ELEMENT
QML_UNCREATABLE("Bootstrap is an attached property")
@@ -49,8 +47,6 @@ class Bootstrap : public QObject
Theme theme() const;
void setTheme(Theme theme);
QColor bodyBg() const;
- void setLightBodyBg(QColor lightBodyBg);
- void setDarkBodyBg(QColor darkBodyBg);
signals:
void modeChanged();
@@ -58,10 +54,10 @@ class Bootstrap : public QObject
void bodyBgChanged();
private:
- Mode bs_mode;
- Theme bs_theme;
- QColor bs_lightBodyBg;
- QColor bs_darkBodyBg;
+ Mode bsMode;
+ Theme bsTheme;
+ QColor bsLightBodyBg;
+ QColor bsDarkBodyBg;
};
QML_DECLARE_TYPEINFO(Bootstrap, QML_HAS_ATTACHED_PROPERTIES)