summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Bootstrap.cxx94
-rw-r--r--Bootstrap.hxx32
2 files changed, 66 insertions, 60 deletions
diff --git a/Bootstrap.cxx b/Bootstrap.cxx
index c0d2fb9..7183cb7 100644
--- a/Bootstrap.cxx
+++ b/Bootstrap.cxx
@@ -2,54 +2,54 @@
#include "Bootstrap.hxx"
Bootstrap::Bootstrap(QObject *parent):
- QObject(parent),
- bsTheme(None),
- bsDarkMode(false),
- bsLightBodyColor("#212529"),
- bsDarkBodyColor("#adb5bd"),
- bsLightBodyBg("#fff"),
- bsDarkBodyBg("#212529"),
- bsLightBorderColor("#dee2e6"),
- bsDarkBorderColor("#495057")
+ QObject{parent},
+ bsMode{Light},
+ bsTheme{Theme::None},
+ bodyColors{{"#212529", "#adb5bd"}},
+ bodyBgs{{"#fff", "#212529"}},
+ borderColors{{"#dee2e6", "#495057"}}
{
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) {
toml_free(toml);
return;
}
- auto darkMode = toml_bool_in(bootstrap, "DarkMode");
- if (darkMode.ok) bsDarkMode = darkMode.u.b;
- auto bodyColor = toml_array_in(bootstrap, "BodyColor");
- if (bodyColor) {
- auto lightBodyColor = toml_string_at(bodyColor, 0).u.s;
- bsLightBodyColor = QColor{lightBodyColor};
- free(lightBodyColor);
- auto darkBodyColor = toml_string_at(bodyColor, 1).u.s;
- bsDarkBodyColor = QColor{darkBodyColor};
- free(darkBodyColor);
- }
- 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);
- }
- auto borderColor = toml_array_in(bootstrap, "BorderColor");
- if (borderColor) {
- auto lightBorderColor = toml_string_at(borderColor, 0).u.s;
- bsLightBorderColor = QColor{lightBorderColor};
- free(lightBorderColor);
- auto darkBorderColor = toml_string_at(borderColor, 1).u.s;
- bsDarkBorderColor = QColor{darkBorderColor};
- free(darkBorderColor);
- }
+
+ auto mode = toml_int_in(bootstrap, "Mode");
+ if (mode.ok) bsMode = static_cast<Mode>(mode.u.i);
+
+ auto colors = toml_array_in(bootstrap, "BodyColors");
+ if (colors)
+ for (int i = 0; ; i++) {
+ auto color = toml_string_at(colors, i);
+ if (!color.ok) break;
+ bodyColors.append(QColor{color.u.s});
+ free(color.u.s);
+ }
+
+ colors = toml_array_in(bootstrap, "BodyBgs");
+ if (colors)
+ for (int i = 0; ; i++) {
+ auto color = toml_string_at(colors, i);
+ if (!color.ok) break;
+ bodyBgs.append(QColor{color.u.s});
+ free(color.u.s);
+ }
+
+ colors = toml_array_in(bootstrap, "BorderColors");
+ if (colors)
+ for (int i = 0; ; i++) {
+ auto color = toml_string_at(colors, i);
+ if (!color.ok) break;
+ borderColors.append(QColor{color.u.s});
+ free(color.u.s);
+ }
+
toml_free(toml);
}
@@ -58,16 +58,16 @@ Bootstrap *Bootstrap::qmlAttachedProperties(QObject *object)
return new Bootstrap(object);
}
-bool Bootstrap::darkMode() const
+Bootstrap::Mode Bootstrap::mode() const
{
- return bsDarkMode;
+ return bsMode;
}
-void Bootstrap::setDarkMode(bool darkMode)
+void Bootstrap::setMode(Mode mode)
{
- if (darkMode == bsDarkMode) return;
- bsDarkMode = darkMode;
- emit darkModeChanged();
+ if (mode == bsMode) return;
+ bsMode = mode;
+ emit modeChanged();
emit bodyColorChanged();
emit bodyBgChanged();
emit borderColorChanged();
@@ -87,15 +87,15 @@ void Bootstrap::setTheme(Theme theme)
QColor Bootstrap::bodyColor() const
{
- return bsDarkMode ? bsDarkBodyColor : bsLightBodyColor;
+ return bodyColors.at(bsMode);
}
QColor Bootstrap::bodyBg() const
{
- return bsDarkMode ? bsDarkBodyBg : bsLightBodyBg;
+ return bodyBgs.at(bsMode);
}
QColor Bootstrap::borderColor() const
{
- return bsDarkMode ? bsDarkBorderColor : bsLightBorderColor;
+ return borderColors.at(bsMode);
}
diff --git a/Bootstrap.hxx b/Bootstrap.hxx
index 57fa3aa..2d9553b 100644
--- a/Bootstrap.hxx
+++ b/Bootstrap.hxx
@@ -13,11 +13,13 @@ class Qootstrap : public QQmlEngineExtensionPlugin
class Bootstrap : public QObject
{
Q_OBJECT
+ 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(bool darkMode READ darkMode WRITE setDarkMode NOTIFY darkModeChanged)
Q_PROPERTY(QColor bodyColor READ bodyColor NOTIFY bodyColorChanged)
Q_PROPERTY(QColor bodyBg READ bodyBg NOTIFY bodyBgChanged)
- Q_PROPERTY(QColor borderColor READ borderColor NOTIFY borderColorChanged)
+ Q_PROPERTY(QColor borderColor READ borderColor
+ NOTIFY borderColorChanged)
QML_ELEMENT
QML_UNCREATABLE("Bootstrap is an attached property")
@@ -25,7 +27,15 @@ class Bootstrap : public QObject
explicit Bootstrap(QObject *parent = nullptr);
static Bootstrap *qmlAttachedProperties(QObject *object);
- enum Theme {
+ enum Mode {
+ Light,
+ Dark
+ };
+ Q_ENUM(Mode)
+ Mode mode() const;
+ void setMode(Mode mode);
+
+ enum class Theme {
None,
Primary,
Secondary,
@@ -40,28 +50,24 @@ class Bootstrap : public QObject
Q_ENUM(Theme)
Theme theme() const;
void setTheme(Theme theme);
- bool darkMode() const;
- void setDarkMode(bool darkMode);
+
QColor bodyColor() const;
QColor bodyBg() const;
QColor borderColor() const;
signals:
void themeChanged();
- void darkModeChanged();
+ void modeChanged();
void bodyColorChanged();
void bodyBgChanged();
void borderColorChanged();
private:
+ Mode bsMode;
Theme bsTheme;
- bool bsDarkMode;
- QColor bsLightBodyColor;
- QColor bsDarkBodyColor;
- QColor bsLightBodyBg;
- QColor bsDarkBodyBg;
- QColor bsLightBorderColor;
- QColor bsDarkBorderColor;
+ QVector<QColor> bodyColors;
+ QVector<QColor> bodyBgs;
+ QVector<QColor> borderColors;
};
QML_DECLARE_TYPEINFO(Bootstrap, QML_HAS_ATTACHED_PROPERTIES)