From 0738195675ec6d537ef154aba19dc205d99ba1d3 Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Mon, 18 May 2020 11:27:09 +0200 Subject: [PATCH] created styling lib --- ScStwStyling/.gitignore | 1 + ScStwStyling/ScStwStyling.pri | 20 ++++ ScStwStyling/ScStwStyling.pro | 39 +++++++ ScStwStyling/headers/scstwapptheme.h | 36 ++++++ ScStwStyling/resources/ScStwStylingShared.qrc | 2 + ScStwStyling/sources/scstwapptheme.cpp | 104 ++++++++++++++++++ ScStwStyling/test.qrc | 2 + 7 files changed, 204 insertions(+) create mode 100644 ScStwStyling/.gitignore create mode 100644 ScStwStyling/ScStwStyling.pri create mode 100644 ScStwStyling/ScStwStyling.pro create mode 100644 ScStwStyling/headers/scstwapptheme.h create mode 100644 ScStwStyling/resources/ScStwStylingShared.qrc create mode 100644 ScStwStyling/sources/scstwapptheme.cpp create mode 100644 ScStwStyling/test.qrc diff --git a/ScStwStyling/.gitignore b/ScStwStyling/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/ScStwStyling/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/ScStwStyling/ScStwStyling.pri b/ScStwStyling/ScStwStyling.pri new file mode 100644 index 0000000..7285b4e --- /dev/null +++ b/ScStwStyling/ScStwStyling.pri @@ -0,0 +1,20 @@ +!isEmpty(SCSTWSTYLING_LIB):error("ScStwLibraries.pri already included") +SCSTWSTYLING_LIB = 1 + +#DEPENDS +CONFIG(release, debug|release): { + SCSTWSTYLING_LIB_OUTPUT_DIR="$$PWD/build/release" +} else { + SCSTWSTYLING_LIB_OUTPUT_DIR="$$PWD/build/debug" +} + +unix:LIBS += -L$$SCSTWSTYLING_LIB_OUTPUT_DIR -lScStwStyling + +win32:LIBS += -L$$SCSTWSTYLING_LIB_OUTPUT_DIR -lScStwStyling1 + +android { + ANDROID_EXTRA_LIBS += $$SCSTWSTYLING_LIB_OUTPUT_DIR/libScStwStyling.so +} + +INCLUDEPATH += "$$PWD" +INCLUDEPATH += "$$PWD"/headers diff --git a/ScStwStyling/ScStwStyling.pro b/ScStwStyling/ScStwStyling.pro new file mode 100644 index 0000000..7d09c03 --- /dev/null +++ b/ScStwStyling/ScStwStyling.pro @@ -0,0 +1,39 @@ +QT -= gui + +TEMPLATE = lib +DEFINES += SCSTWSTYLING_LIBRARY + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + sources/scstwapptheme.cpp + +HEADERS += \ + headers/scstwapptheme.h + +RESOURCES += \ + resources/ScStwStylingShared.qrc + +DISTFILES += + +#DEPENDS +CONFIG(release, debug|release): { + DESTDIR="$$PWD/build/release" +} else { + DESTDIR="$$PWD/build/debug" +} + +# Default rules for deployment. +target.path = $$GLOBAL_TARGET_PATH/lib +!isEmpty(target.path): INSTALLS += target diff --git a/ScStwStyling/headers/scstwapptheme.h b/ScStwStyling/headers/scstwapptheme.h new file mode 100644 index 0000000..b1c1cf0 --- /dev/null +++ b/ScStwStyling/headers/scstwapptheme.h @@ -0,0 +1,36 @@ +#ifndef APPTHEME_H +#define APPTHEME_H + +#include +#include + +class ScStwAppTheme : public QObject +{ + Q_OBJECT + Q_PROPERTY(QVariant style READ getStyle NOTIFY styleChanged) +public: + explicit ScStwAppTheme(QObject *parent = nullptr); + + enum Theme { + Light, + Dark + }; + Q_ENUM(Theme) + +private: + QMap themes; + + QVariantMap * currentTheme; + + Theme currentThemeKey; + +signals: + void styleChanged(); + +public slots: + QVariant getStyle(); + Q_INVOKABLE bool setTheme(Theme theme); + Q_INVOKABLE void refreshTheme(); +}; + +#endif // APPTHEME_H diff --git a/ScStwStyling/resources/ScStwStylingShared.qrc b/ScStwStyling/resources/ScStwStylingShared.qrc new file mode 100644 index 0000000..90f4a83 --- /dev/null +++ b/ScStwStyling/resources/ScStwStylingShared.qrc @@ -0,0 +1,2 @@ + + diff --git a/ScStwStyling/sources/scstwapptheme.cpp b/ScStwStyling/sources/scstwapptheme.cpp new file mode 100644 index 0000000..c07f6ed --- /dev/null +++ b/ScStwStyling/sources/scstwapptheme.cpp @@ -0,0 +1,104 @@ +#include "headers/scstwapptheme.h" + +ScStwAppTheme::ScStwAppTheme(QObject *parent) : QObject(parent) +{ + + QVariantMap tmpDarkTheme = { + {"backgroundColor", "#2d3037"}, + + {"buttonColor", "#202227"}, + {"buttonPressedColor", "#41454f"}, + {"buttonBorderColor", "grey"}, + {"disabledButtonColor", "#555555"}, + + {"viewColor", "#202227"}, + {"menuColor", "#292b32"}, + + {"delegate1Color", "#202227"}, + {"delegate2Color", "#202227"}, + {"delegateBackgroundColor", "#202227"}, + {"delegatePressedColor", "#41454f"}, + + {"textColor", "#ffffff"}, + {"textDarkColor", "#232323"}, + {"disabledTextColor", "#777777"}, + + {"sliderColor", "#6ccaf2"}, + + {"successColor", "#6bd43b"}, + {"errorColor", "#e03b2f"}, + + {"lineColor", "grey"}, + + {"backIcon", "qrc:/graphics/icons/back.png"}, + {"settIcon", "qrc:/graphics/icons/settings.png"}, + {"buzzerIcon", "qrc:/graphics/icons/buzzer.png"}, + {"startpadIcon", "qrc:/graphics/icons/startpad.png"}, + {"baseStationIcon", "qrc:/graphics/icons/BaseStation.png"}, + {"profilesIcon", "qrc:/graphics/icons/user.png"}, + {"confirmIcon", "qrc:/graphics/icons/ok.png"} + + }; + + QVariantMap tmpLightTheme = { + {"backgroundColor", "white"}, + + {"buttonColor", "white"}, + {"buttonPressedColor", "lightgrey"}, + {"buttonBorderColor", "grey"}, + {"disabledButtonColor", "#d5d5d5"}, + + {"viewColor", "white"}, + {"menuColor", "#f8f8f8"}, + + {"delegate1Color", "#202227"}, + {"delegate2Color", "#202227"}, + {"delegateBackgroundColor", "white"}, + {"delegatePressedColor", "#dddedf"}, + + {"textColor", "black"}, + {"textDarkColor", "#232323"}, + {"disabledTextColor", "grey"}, + + {"sliderColor", "#6ccaf2"}, + + {"successColor", "#60de26"}, + {"errorColor", "#ff0000"}, + + {"lineColor", "grey"}, + + {"backIcon", "qrc:/graphics/icons/back_black.png"}, + {"settIcon", "qrc:/graphics/icons/settings_black.png"}, + {"buzzerIcon", "qrc:/graphics/icons/buzzer_black.png"}, + {"startpadIcon", "qrc:/graphics/icons/startpad_black.png"}, + {"baseStationIcon", "qrc:/graphics/icons/BaseStation_black.png"}, + {"profilesIcon", "qrc:/graphics/icons/user_black.png"}, + {"confirmIcon", "qrc:/graphics/icons/ok_black.png"} + + }; + + this->themes = QMap({{Light, tmpLightTheme}, {Dark, tmpDarkTheme}}); + + this->currentThemeKey = Light; + + this->currentTheme = &this->themes[this->currentThemeKey]; +} + +QVariant ScStwAppTheme::getStyle() { + return *this->currentTheme; +} + +bool ScStwAppTheme::setTheme(Theme theme) { + if(theme > Dark || theme < Light) + return false; + + this->currentThemeKey = theme; + this->refreshTheme(); + return true; +} + +void ScStwAppTheme::refreshTheme() { + this->currentTheme = &this->themes[this->currentThemeKey]; + + emit this->styleChanged(); +} diff --git a/ScStwStyling/test.qrc b/ScStwStyling/test.qrc new file mode 100644 index 0000000..90f4a83 --- /dev/null +++ b/ScStwStyling/test.qrc @@ -0,0 +1,2 @@ + +