started to restructure themes

This commit is contained in:
Dorian Zedler 2020-05-19 09:31:27 +02:00
parent 585d524a20
commit 0fe9bc24b0
Signed by: dorian
GPG key ID: 989DE36109AFA354
9 changed files with 191 additions and 118 deletions

View file

@ -1,4 +1,4 @@
QT -= gui QT += gui
TEMPLATE = lib TEMPLATE = lib
DEFINES += SCSTWSTYLING_LIBRARY DEFINES += SCSTWSTYLING_LIBRARY
@ -17,10 +17,12 @@ DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \ SOURCES += \
sources/scstwapptheme.cpp sources/scstwapptheme.cpp \
sources/scstwappthememanager.cpp
HEADERS += \ HEADERS += \
headers/scstwapptheme.h headers/scstwapptheme.h \
headers/scstwappthememanager.h
RESOURCES += \ RESOURCES += \
resources/ScStwStylingShared.qrc resources/ScStwStylingShared.qrc

View file

@ -3,34 +3,33 @@
#include <QObject> #include <QObject>
#include <QVariant> #include <QVariant>
#include <QFontDatabase>
class ScStwAppTheme : public QObject class ScStwAppTheme : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QVariant style READ getStyle NOTIFY styleChanged) Q_PROPERTY(QVariant colors READ getColors)
public: Q_PROPERTY(QVariant icons READ getIcons)
explicit ScStwAppTheme(QObject *parent = nullptr); Q_PROPERTY(QVariant fonts READ getFonts)
Q_PROPERTY(QVariant images READ getImages)
enum Theme {
Light, public:
Dark explicit ScStwAppTheme(QVariantMap colors, QVariantMap icons, QVariantMap fonts, QVariantMap images, QObject *parent = nullptr);
};
Q_ENUM(Theme)
private: private:
QMap<Theme, QVariantMap> themes; QVariantMap colors;
QVariantMap icons;
QVariantMap * currentTheme; QVariantMap fonts;
QVariantMap images;
Theme currentThemeKey;
signals: signals:
void styleChanged();
public slots: public slots:
QVariant getStyle(); QVariant getColors();
Q_INVOKABLE bool setTheme(Theme theme); QVariant getIcons();
Q_INVOKABLE void refreshTheme(); QVariant getFonts();
QVariant getImages();
}; };
#endif // APPTHEME_H #endif // APPTHEME_H

View file

@ -0,0 +1,30 @@
#ifndef SCSTWAPPTHEMEMANAGER_H
#define SCSTWAPPTHEMEMANAGER_H
#include <QObject>
#include "scstwapptheme.h"
class ScStwAppThemeManager : public QObject
{
Q_OBJECT
Q_PROPERTY(ScStwAppTheme* theme READ getTheme NOTIFY themeChanged)
public:
explicit ScStwAppThemeManager(QObject *parent = nullptr);
private:
QList<ScStwAppTheme*> themes;
ScStwAppTheme* currentTheme;
ScStwAppTheme* findThemeByName(QString themeName);
signals:
void themeChanged();
public slots:
ScStwAppTheme* getTheme();
Q_INVOKABLE bool setTheme(QString themeName);
};
#endif // SCSTWAPPTHEMEMANAGER_H

View file

@ -1,2 +1,5 @@
<!DOCTYPE RCC> <RCC>
<RCC version="1.0"/> <qresource prefix="/">
<file>fonts/fa5solid.woff</file>
</qresource>
</RCC>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1,104 +1,23 @@
#include "headers/scstwapptheme.h" #include "headers/scstwapptheme.h"
ScStwAppTheme::ScStwAppTheme(QObject *parent) : QObject(parent) ScStwAppTheme::ScStwAppTheme(QVariantMap colors, QVariantMap icons, QVariantMap fonts, QVariantMap images, QObject *parent) : QObject(parent)
{ {
this->colors = colors;
QVariantMap tmpDarkTheme = { this->icons = icons;
{"backgroundColor", "#2d3037"}, this->fonts = fonts;
this->images = images;
{"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<Theme, QVariantMap>({{Light, tmpLightTheme}, {Dark, tmpDarkTheme}});
this->currentThemeKey = Light;
this->currentTheme = &this->themes[this->currentThemeKey];
} }
QVariant ScStwAppTheme::getStyle() {
return *this->currentTheme; QVariant ScStwAppTheme::getColors() {
return this->colors;
} }
QVariant ScStwAppTheme::getIcons() {
bool ScStwAppTheme::setTheme(Theme theme) { return this->icons;
if(theme > Dark || theme < Light)
return false;
this->currentThemeKey = theme;
this->refreshTheme();
return true;
} }
QVariant ScStwAppTheme::getFonts() {
void ScStwAppTheme::refreshTheme() { return this->fonts;
this->currentTheme = &this->themes[this->currentThemeKey]; }
QVariant ScStwAppTheme::getImages() {
emit this->styleChanged(); return this->images;
} }

View file

@ -0,0 +1,120 @@
#include "../headers/scstwappthememanager.h"
ScStwAppThemeManager::ScStwAppThemeManager(QObject *parent) : QObject(parent)
{
QFontDatabase::addApplicationFont(":/fonts/fa5solid.woff");
QVariantMap icons = {
{"backIcon", "\uf053"},
{"settIcon", "\uf013"},
{"toppadIcon", "\uf10a"},
{"startpadIcon", "\uf3fa"},
{"profilesIcon", "\uf007"},
{"confirmIcon", "\uf00c"}
};
ScStwAppTheme * lightTheme = new ScStwAppTheme (
{
{"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"},
},
{
icons
},
{
{"icons", "Font Awesome 5 Free"}
},
{
{"baseStationIcon", "qrc:/graphics/icons/BaseStation.png"}
});
ScStwAppTheme *darkTheme = new ScStwAppTheme(
{
{"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"},
{"iconFontName", "Font Awesome 5 Free"},
},
{
icons
},
{
{"icons", "Font Awesome 5 Free"}
},
{
{"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"}
}
);
this->themes.append(lightTheme);
this->themes.append(darkTheme);
this->currentTheme = this->themes[0];
}
ScStwAppTheme* ScStwAppThemeManager::getTheme() {
return this->currentTheme;
}
bool ScStwAppThemeManager::setTheme(QString themeName) {
ScStwAppTheme * foundTheme = this->findThemeByName(themeName);
if(foundTheme == nullptr)
return false;
this->currentTheme = foundTheme;
emit this->themeChanged();
return true;
}