started to restructure themes
This commit is contained in:
parent
585d524a20
commit
0fe9bc24b0
9 changed files with 191 additions and 118 deletions
|
@ -1,4 +1,4 @@
|
|||
QT -= gui
|
||||
QT += gui
|
||||
|
||||
TEMPLATE = lib
|
||||
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
|
||||
|
||||
SOURCES += \
|
||||
sources/scstwapptheme.cpp
|
||||
sources/scstwapptheme.cpp \
|
||||
sources/scstwappthememanager.cpp
|
||||
|
||||
HEADERS += \
|
||||
headers/scstwapptheme.h
|
||||
headers/scstwapptheme.h \
|
||||
headers/scstwappthememanager.h
|
||||
|
||||
RESOURCES += \
|
||||
resources/ScStwStylingShared.qrc
|
||||
|
|
|
@ -3,34 +3,33 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
#include <QFontDatabase>
|
||||
|
||||
class ScStwAppTheme : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QVariant style READ getStyle NOTIFY styleChanged)
|
||||
public:
|
||||
explicit ScStwAppTheme(QObject *parent = nullptr);
|
||||
Q_PROPERTY(QVariant colors READ getColors)
|
||||
Q_PROPERTY(QVariant icons READ getIcons)
|
||||
Q_PROPERTY(QVariant fonts READ getFonts)
|
||||
Q_PROPERTY(QVariant images READ getImages)
|
||||
|
||||
enum Theme {
|
||||
Light,
|
||||
Dark
|
||||
};
|
||||
Q_ENUM(Theme)
|
||||
|
||||
public:
|
||||
explicit ScStwAppTheme(QVariantMap colors, QVariantMap icons, QVariantMap fonts, QVariantMap images, QObject *parent = nullptr);
|
||||
|
||||
private:
|
||||
QMap<Theme, QVariantMap> themes;
|
||||
|
||||
QVariantMap * currentTheme;
|
||||
|
||||
Theme currentThemeKey;
|
||||
QVariantMap colors;
|
||||
QVariantMap icons;
|
||||
QVariantMap fonts;
|
||||
QVariantMap images;
|
||||
|
||||
signals:
|
||||
void styleChanged();
|
||||
|
||||
public slots:
|
||||
QVariant getStyle();
|
||||
Q_INVOKABLE bool setTheme(Theme theme);
|
||||
Q_INVOKABLE void refreshTheme();
|
||||
QVariant getColors();
|
||||
QVariant getIcons();
|
||||
QVariant getFonts();
|
||||
QVariant getImages();
|
||||
};
|
||||
|
||||
#endif // APPTHEME_H
|
||||
|
|
30
ScStwStyling/headers/scstwappthememanager.h
Normal file
30
ScStwStyling/headers/scstwappthememanager.h
Normal 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
|
|
@ -1,2 +1,5 @@
|
|||
<!DOCTYPE RCC>
|
||||
<RCC version="1.0"/>
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>fonts/fa5solid.woff</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
BIN
ScStwStyling/resources/fonts/fa5brands.woff
Normal file
BIN
ScStwStyling/resources/fonts/fa5brands.woff
Normal file
Binary file not shown.
BIN
ScStwStyling/resources/fonts/fa5regular.woff
Normal file
BIN
ScStwStyling/resources/fonts/fa5regular.woff
Normal file
Binary file not shown.
BIN
ScStwStyling/resources/fonts/fa5solid.woff
Normal file
BIN
ScStwStyling/resources/fonts/fa5solid.woff
Normal file
Binary file not shown.
|
@ -1,104 +1,23 @@
|
|||
#include "headers/scstwapptheme.h"
|
||||
|
||||
ScStwAppTheme::ScStwAppTheme(QObject *parent) : QObject(parent)
|
||||
ScStwAppTheme::ScStwAppTheme(QVariantMap colors, QVariantMap icons, QVariantMap fonts, QVariantMap images, 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<Theme, QVariantMap>({{Light, tmpLightTheme}, {Dark, tmpDarkTheme}});
|
||||
|
||||
this->currentThemeKey = Light;
|
||||
|
||||
this->currentTheme = &this->themes[this->currentThemeKey];
|
||||
this->colors = colors;
|
||||
this->icons = icons;
|
||||
this->fonts = fonts;
|
||||
this->images = images;
|
||||
}
|
||||
|
||||
QVariant ScStwAppTheme::getStyle() {
|
||||
return *this->currentTheme;
|
||||
|
||||
QVariant ScStwAppTheme::getColors() {
|
||||
return this->colors;
|
||||
}
|
||||
|
||||
bool ScStwAppTheme::setTheme(Theme theme) {
|
||||
if(theme > Dark || theme < Light)
|
||||
return false;
|
||||
|
||||
this->currentThemeKey = theme;
|
||||
this->refreshTheme();
|
||||
return true;
|
||||
QVariant ScStwAppTheme::getIcons() {
|
||||
return this->icons;
|
||||
}
|
||||
|
||||
void ScStwAppTheme::refreshTheme() {
|
||||
this->currentTheme = &this->themes[this->currentThemeKey];
|
||||
|
||||
emit this->styleChanged();
|
||||
QVariant ScStwAppTheme::getFonts() {
|
||||
return this->fonts;
|
||||
}
|
||||
QVariant ScStwAppTheme::getImages() {
|
||||
return this->images;
|
||||
}
|
||||
|
|
120
ScStwStyling/sources/scstwappthememanager.cpp
Normal file
120
ScStwStyling/sources/scstwappthememanager.cpp
Normal 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;
|
||||
}
|
Reference in a new issue