diff options
-rw-r--r-- | Bootstrap.cxx | 17 | ||||
-rw-r--r-- | Bootstrap.hxx | 5 | ||||
-rw-r--r-- | Label.qml | 9 | ||||
-rw-r--r-- | qootstrap.pro | 3 |
4 files changed, 33 insertions, 1 deletions
diff --git a/Bootstrap.cxx b/Bootstrap.cxx index 4873f01..994ed84 100644 --- a/Bootstrap.cxx +++ b/Bootstrap.cxx @@ -5,6 +5,8 @@ Bootstrap::Bootstrap(QObject *parent): QObject(parent), bsTheme(None), bsDarkMode(false), + bsLightBodyColor("#212529"), + bsDarkBodyColor("#adb5bd"), bsLightBodyBg("#fff"), bsDarkBodyBg("#212529") { @@ -19,6 +21,15 @@ Bootstrap::Bootstrap(QObject *parent): } 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; @@ -46,6 +57,7 @@ void Bootstrap::setDarkMode(bool darkMode) if (darkMode == bsDarkMode) return; bsDarkMode = darkMode; emit darkModeChanged(); + emit bodyColorChanged(); emit bodyBgChanged(); } @@ -61,6 +73,11 @@ void Bootstrap::setTheme(Theme theme) emit themeChanged(); } +QColor Bootstrap::bodyColor() const +{ + return bsDarkMode ? bsDarkBodyColor : bsLightBodyColor; +} + QColor Bootstrap::bodyBg() const { return bsDarkMode ? bsDarkBodyBg : bsLightBodyBg; diff --git a/Bootstrap.hxx b/Bootstrap.hxx index 828a031..7d993c2 100644 --- a/Bootstrap.hxx +++ b/Bootstrap.hxx @@ -15,6 +15,7 @@ class Bootstrap : public QObject Q_OBJECT 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) QML_ELEMENT QML_UNCREATABLE("Bootstrap is an attached property") @@ -40,16 +41,20 @@ class Bootstrap : public QObject void setTheme(Theme theme); bool darkMode() const; void setDarkMode(bool darkMode); + QColor bodyColor() const; QColor bodyBg() const; signals: void themeChanged(); void darkModeChanged(); + void bodyColorChanged(); void bodyBgChanged(); private: Theme bsTheme; bool bsDarkMode; + QColor bsLightBodyColor; + QColor bsDarkBodyColor; QColor bsLightBodyBg; QColor bsDarkBodyBg; }; diff --git a/Label.qml b/Label.qml new file mode 100644 index 0000000..593ded0 --- /dev/null +++ b/Label.qml @@ -0,0 +1,9 @@ +import QtQuick 2.15 +import QtQuick.Templates 2.15 +import Bootstrap 5.3 + +Label { + id: control + color: Bootstrap.bodyColor + linkColor: control.palette.link +} diff --git a/qootstrap.pro b/qootstrap.pro index 1b743f4..d3df35e 100644 --- a/qootstrap.pro +++ b/qootstrap.pro @@ -10,7 +10,8 @@ import.files = qmldir import.path = $$[QT_INSTALL_QML]/$$QML_IMPORT_NAME style.files = \ - ApplicationWindow.qml + ApplicationWindow.qml \ + Label.qml style.path = $$[QT_INSTALL_QML]/QtQuick/Controls.2/$$QML_IMPORT_NAME HEADERS += $${QML_IMPORT_NAME}.hxx |