From c7a019ddcd164ecfbf82be6129967c96be2667d5 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: Thu, 6 Apr 2023 12:19:31 +0800 Subject: Rename the files --- Bootstrap.cxx | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Bootstrap.hxx | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ bootstrap.cxx | 67 ----------------------------------------------------------- bootstrap.hxx | 59 ---------------------------------------------------- bootstrap.pro | 25 ---------------------- qootstrap.pro | 24 +++++++++++++++++++++ 6 files changed, 150 insertions(+), 151 deletions(-) create mode 100644 Bootstrap.cxx create mode 100644 Bootstrap.hxx delete mode 100644 bootstrap.cxx delete mode 100644 bootstrap.hxx delete mode 100644 bootstrap.pro create mode 100644 qootstrap.pro diff --git a/Bootstrap.cxx b/Bootstrap.cxx new file mode 100644 index 0000000..4873f01 --- /dev/null +++ b/Bootstrap.cxx @@ -0,0 +1,67 @@ +#include "tomlc99/toml.h" +#include "Bootstrap.hxx" + +Bootstrap::Bootstrap(QObject *parent): + QObject(parent), + bsTheme(None), + bsDarkMode(false), + 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) { + toml_free(toml); + return; + } + auto darkMode = toml_bool_in(bootstrap, "DarkMode"); + if (darkMode.ok) bsDarkMode = darkMode.u.b; + 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); +} + +Bootstrap *Bootstrap::qmlAttachedProperties(QObject *object) +{ + return new Bootstrap(object); +} + +bool Bootstrap::darkMode() const +{ + return bsDarkMode; +} + +void Bootstrap::setDarkMode(bool darkMode) +{ + if (darkMode == bsDarkMode) return; + bsDarkMode = darkMode; + emit darkModeChanged(); + emit bodyBgChanged(); +} + +Bootstrap::Theme Bootstrap::theme() const +{ + return bsTheme; +} + +void Bootstrap::setTheme(Theme theme) +{ + if (theme == bsTheme) return; + bsTheme = theme; + emit themeChanged(); +} + +QColor Bootstrap::bodyBg() const +{ + return bsDarkMode ? bsDarkBodyBg : bsLightBodyBg; +} diff --git a/Bootstrap.hxx b/Bootstrap.hxx new file mode 100644 index 0000000..eecbda6 --- /dev/null +++ b/Bootstrap.hxx @@ -0,0 +1,59 @@ +#ifndef BOOTSTRAP_HXX +#define BOOTSTRAP_HXX + +#include +#include + +class Qootstrap : public QQmlEngineExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) +}; + +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 bodyBg READ bodyBg NOTIFY bodyBgChanged) + QML_ELEMENT + QML_UNCREATABLE("Bootstrap is an attached property") + + public: + explicit Bootstrap(QObject *parent = nullptr); + static Bootstrap *qmlAttachedProperties(QObject *object); + + enum Theme { + None, + Primary, + Secondary, + Success, + Danger, + Warning, + Info, + Light, + Dark, + Link + }; + Q_ENUM(Theme) + Theme theme() const; + void setTheme(Theme theme); + bool darkMode() const; + void setDarkMode(bool darkMode); + QColor bodyBg() const; + + signals: + void themeChanged(); + void darkModeChanged(); + void bodyBgChanged(); + + private: + Theme bsTheme; + bool bsDarkMode; + QColor bsLightBodyBg; + QColor bsDarkBodyBg; +}; + +QML_DECLARE_TYPEINFO(Bootstrap, QML_HAS_ATTACHED_PROPERTIES) + +#endif diff --git a/bootstrap.cxx b/bootstrap.cxx deleted file mode 100644 index 921a190..0000000 --- a/bootstrap.cxx +++ /dev/null @@ -1,67 +0,0 @@ -#include "tomlc99/toml.h" -#include "bootstrap.hxx" - -Bootstrap::Bootstrap(QObject *parent): - QObject(parent), - bsTheme(None), - bsDarkMode(false), - 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) { - toml_free(toml); - return; - } - auto darkMode = toml_bool_in(bootstrap, "DarkMode"); - if (darkMode.ok) bsDarkMode = darkMode.u.b; - 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); -} - -Bootstrap *Bootstrap::qmlAttachedProperties(QObject *object) -{ - return new Bootstrap(object); -} - -bool Bootstrap::darkMode() const -{ - return bsDarkMode; -} - -void Bootstrap::setDarkMode(bool darkMode) -{ - if (darkMode == bsDarkMode) return; - bsDarkMode = darkMode; - emit darkModeChanged(); - emit bodyBgChanged(); -} - -Bootstrap::Theme Bootstrap::theme() const -{ - return bsTheme; -} - -void Bootstrap::setTheme(Theme theme) -{ - if (theme == bsTheme) return; - bsTheme = theme; - emit themeChanged(); -} - -QColor Bootstrap::bodyBg() const -{ - return bsDarkMode ? bsDarkBodyBg : bsLightBodyBg; -} diff --git a/bootstrap.hxx b/bootstrap.hxx deleted file mode 100644 index eecbda6..0000000 --- a/bootstrap.hxx +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef BOOTSTRAP_HXX -#define BOOTSTRAP_HXX - -#include -#include - -class Qootstrap : public QQmlEngineExtensionPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) -}; - -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 bodyBg READ bodyBg NOTIFY bodyBgChanged) - QML_ELEMENT - QML_UNCREATABLE("Bootstrap is an attached property") - - public: - explicit Bootstrap(QObject *parent = nullptr); - static Bootstrap *qmlAttachedProperties(QObject *object); - - enum Theme { - None, - Primary, - Secondary, - Success, - Danger, - Warning, - Info, - Light, - Dark, - Link - }; - Q_ENUM(Theme) - Theme theme() const; - void setTheme(Theme theme); - bool darkMode() const; - void setDarkMode(bool darkMode); - QColor bodyBg() const; - - signals: - void themeChanged(); - void darkModeChanged(); - void bodyBgChanged(); - - private: - Theme bsTheme; - bool bsDarkMode; - QColor bsLightBodyBg; - QColor bsDarkBodyBg; -}; - -QML_DECLARE_TYPEINFO(Bootstrap, QML_HAS_ATTACHED_PROPERTIES) - -#endif diff --git a/bootstrap.pro b/bootstrap.pro deleted file mode 100644 index 5a38056..0000000 --- a/bootstrap.pro +++ /dev/null @@ -1,25 +0,0 @@ -TEMPLATE = lib -CONFIG += plugin qmltypes -QT += qml - -QML_IMPORT_NAME = Bootstrap -QML_IMPORT_MAJOR_VERSION = 5 -QML_IMPORT_MINOR_VERSION = 3 - -import.files = \ - qmldir \ - $${QML_IMPORT_NAME}.qml -import.path = $$[QT_INSTALL_QML]/$$QML_IMPORT_NAME - -style.files = \ - ApplicationWindow.qml -style.path = $$[QT_INSTALL_QML]/QtQuick/Controls.2/$$QML_IMPORT_NAME - -HEADERS += $${TARGET}.hxx -SOURCES += \ - $${TARGET}.cxx \ - tomlc99/toml.c -TARGET = qootstrap -target.path = $$[QT_INSTALL_QML]/$$QML_IMPORT_NAME - -INSTALLS += import style target diff --git a/qootstrap.pro b/qootstrap.pro new file mode 100644 index 0000000..4f50f3d --- /dev/null +++ b/qootstrap.pro @@ -0,0 +1,24 @@ +TEMPLATE = lib +CONFIG += plugin qmltypes +QT += qml + +QML_IMPORT_NAME = Bootstrap +QML_IMPORT_MAJOR_VERSION = 5 +QML_IMPORT_MINOR_VERSION = 3 + +import.files = \ + qmldir \ + $${QML_IMPORT_NAME}.qml +import.path = $$[QT_INSTALL_QML]/$$QML_IMPORT_NAME + +style.files = \ + ApplicationWindow.qml +style.path = $$[QT_INSTALL_QML]/QtQuick/Controls.2/$$QML_IMPORT_NAME + +HEADERS += $${QML_IMPORT_NAME}.hxx +SOURCES += \ + $${QML_IMPORT_NAME}.cxx \ + tomlc99/toml.c +target.path = $$[QT_INSTALL_QML]/$$QML_IMPORT_NAME + +INSTALLS += import style target -- cgit v1.2.3