diff options
-rw-r--r-- | Bootstrap.qml | 104 | ||||
-rw-r--r-- | bootstrap.cxx | 51 | ||||
-rw-r--r-- | bootstrap.hxx | 44 | ||||
-rw-r--r-- | qmldir | 1 |
4 files changed, 79 insertions, 121 deletions
diff --git a/Bootstrap.qml b/Bootstrap.qml deleted file mode 100644 index 1738816..0000000 --- a/Bootstrap.qml +++ /dev/null @@ -1,104 +0,0 @@ -pragma Singleton -import QtQuick 2.15 - -QtObject { - enum Theme { - Light = 0, - Dark - } - property int theme: Bootstrap.Theme.Light - - property color accordionBg: bodyBg - - property real badgeFontSize: 13.6 - - property color bodyColor: theme ? "#a1a1a8" : "#747579" - property color bodyBg: theme ? "#222529" : "#ffffff" - - property color borderColor: theme ? "#12ffffff" : gray200 - property real borderRadius: 5.2 - - property real boxShadowOffsetX: 0 - property real boxShadowOffsetY: 0 - property int boxShadowBlurRadius: 40 - property color boxShadowColor: "#261d3a53" - - property real btnPaddingX: 16 - property real btnPaddingY: 8 - - property color btnColor: "#747579" - property color btnBg: "transparent" - property color btnBorderColor: btnBg - property real btnBorderWidth: 1 - property real btnBorderRadius: 5.2 - property real btnLgFontSize: 16 - property real btnLgBorderRadius: 8 - - property color primary: "#066ac9" - property color secondary: "#9a9ea4" - property color success: "#0cbc87" - property color danger: "#d6293e" - property color light: theme ? "#2a2c31" : "#f5f7f9" - property color dark: theme ? "#0f0f10" : "#24292d" - property color tertiaryBg: theme ? "#2b3035" : "#f8f9fa" - - property color btnPrimaryColor: "#ffffff" - property color btnPrimaryBg: primary - property color btnPrimaryBorderColor: primary - property color btnPrimaryActiveColor: btnPrimaryColor - property color btnPrimaryActiveBg: "#0555a1" - property color btnPrimaryActiveBorderColor: "#055097" - property color btnPrimaryDisabledColor: "#a6ffffff" - property color btnPrimaryDisabledBg: "#a6066ac9" - property color btnPrimaryDisabledBorderColor: btnPrimaryDisabledBg - - property color btnOutlinePrimaryColor: primary - property color btnOutlinePrimaryBg: btnBg - property color btnOutlinePrimaryBorderColor: primary - property color btnOutlinePrimaryActiveColor: btnPrimaryColor - property color btnOutlinePrimaryActiveBg: primary - property color btnOutlinePrimaryActiveBorderColor: primary - property color btnOutlinePrimaryDisabledColor: - btnPrimaryDisabledColor - property color btnOutlinePrimaryDisabledBg: btnBg - property color btnOutlinePrimaryDisabledBorderColor: - btnPrimaryDisabledColor - - property color btnSuccessColor: btnPrimaryColor - property color btnSuccessBg: success - property color btnSuccessBorderColor: success - property color btnSuccessActiveColor: btnSuccessColor - property color btnSuccessActiveBg: "#0a966c" - property color btnSuccessActiveBorderColor: "#098d65" - property color btnSuccessDisabledColor: btnPrimaryDisabledColor - property color btnSuccessDisabledBg: "#a60cbc87" - property color btnSuccessDisabledBorderColor: btnSuccessDisabledBg - - property color btnLightColor: "#000000" - property color btnLightBg: "#f5f7f9" - property color btnLightBorderColor: btnLightBg - property color btnLightActiveColor: btnLightColor - property color btnLightActiveBg: "#c4c6c7" - property color btnLightActiveBorderColor: "#b8b9bb" - property color btnLightDisabledColor: "#a6000000" - property color btnLightDisabledBg: "#a6f5f7f9" - property color btnLightDisabledBorderColor: btnLightDisabledBg - - property color cardBg: theme ? "#1b1e21" : "#ffffff" - property color cardTitleColor: theme ? "#f7f5f5" : "#24292d" - - property color dropdownColor: "#747579" - property color dropdownLinkColor: theme ? "#c5c6cc" : "#747579" - property color dropdownLinkHoverColor: "#066ac9" - property color dropdownLinkHoverBg: "#1a066ac9" - - property color headingColor: theme ? "#ffffff" : "#24292d" - - property color gray200: theme ? "#464950" : "#eff1f2" - property color gray300: theme ? "#3e3e40" : "#dde0e3" - property color gray500: theme ? "#bfc0c9" : "#9a9ea4" - property color gray600: theme ? "#c5c6cc" : "#747579" - property color gray700: theme ? "#f3f1f1" : "#404448" - property color gray800: theme ? "#f7f5f5" : "#24292d" - property color gray900: theme ? "#ffffff" : "#0b0f13" -} diff --git a/bootstrap.cxx b/bootstrap.cxx index bf9a499..7a03b8f 100644 --- a/bootstrap.cxx +++ b/bootstrap.cxx @@ -1,8 +1,11 @@ #include "bootstrap.hxx" Bootstrap::Bootstrap(QObject *parent): - QQmlEngineExtensionPlugin(parent), - m_purpose(None) + QObject(parent), + bs_mode(LightMode), + bs_theme(None), + bs_lightBodyBg("#fff"), + bs_darkBodyBg("#212529") { } @@ -11,14 +14,46 @@ Bootstrap *Bootstrap::qmlAttachedProperties(QObject *object) return new Bootstrap(object); } -Bootstrap::Purpose Bootstrap::purpose() const +Bootstrap::Mode Bootstrap::mode() const { - return m_purpose; + return bs_mode; } -void Bootstrap::setPurpose(Purpose purpose) +void Bootstrap::setMode(Mode mode) { - if (purpose == m_purpose) return; - m_purpose = purpose; - emit purposeChanged(); + if (mode == bs_mode) return; + bs_mode = mode; + emit modeChanged(); + emit bodyBgChanged(); +} + +Bootstrap::Theme Bootstrap::theme() const +{ + return bs_theme; +} + +void Bootstrap::setTheme(Theme theme) +{ + if (theme == bs_theme) return; + bs_theme = 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(); } diff --git a/bootstrap.hxx b/bootstrap.hxx index dc1a1dd..2297be0 100644 --- a/bootstrap.hxx +++ b/bootstrap.hxx @@ -2,18 +2,35 @@ #define BOOTSTRAP_HXX #include <QtQml> +#include <QColor> -class Bootstrap : public QQmlEngineExtensionPlugin +class BootstrapPlugin : public QQmlEngineExtensionPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) - Q_PROPERTY(Purpose purpose READ purpose WRITE setPurpose NOTIFY purposeChanged) +}; + +class Bootstrap : public QObject +{ + Q_OBJECT + 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") public: explicit Bootstrap(QObject *parent = nullptr); static Bootstrap *qmlAttachedProperties(QObject *object); - enum Purpose { + enum Mode { + LightMode, + DarkMode + }; + Q_ENUM(Mode) + enum Theme { None, Primary, Secondary, @@ -25,15 +42,26 @@ class Bootstrap : public QQmlEngineExtensionPlugin Dark, Link }; - Q_ENUM(Purpose) - Purpose purpose() const; - void setPurpose(Purpose purpose); + Q_ENUM(Theme) + + Mode mode() const; + void setMode(Mode mode); + Theme theme() const; + void setTheme(Theme theme); + QColor bodyBg() const; + void setLightBodyBg(QColor lightBodyBg); + void setDarkBodyBg(QColor darkBodyBg); signals: - void purposeChanged(); + void modeChanged(); + void themeChanged(); + void bodyBgChanged(); private: - Purpose m_purpose; + Mode bs_mode; + Theme bs_theme; + QColor bs_lightBodyBg; + QColor bs_darkBodyBg; }; QML_DECLARE_TYPEINFO(Bootstrap, QML_HAS_ATTACHED_PROPERTIES) @@ -1,3 +1,2 @@ module Bootstrap -singleton Bootstrap 5.3 Bootstrap.qml plugin qqc2bootstrap |