mobile-widgets/themeinterface: make most part static

Make variables and functions static where possible, this is done
to prevent different versions of theme with different values.

Signed-off-by: jan Iversen <jan@casacondor.com>
This commit is contained in:
jan Iversen 2020-01-28 22:56:20 +01:00 committed by Dirk Hohndel
parent f16dc72556
commit 15fbcb655a
2 changed files with 146 additions and 164 deletions

View file

@ -4,6 +4,67 @@
#include "core/metrics.h"
#include "core/settings/qPrefDisplay.h"
QColor themeInterface::m_backgroundColor;
QColor themeInterface::m_contrastAccentColor;
QColor themeInterface::m_darkerPrimaryColor;
QColor themeInterface::m_darkerPrimaryTextColor;
QColor themeInterface::m_drawerColor;
QColor themeInterface::m_lightDrawerColor;
QColor themeInterface::m_lightPrimaryColor;
QColor themeInterface::m_lightPrimaryTextColor;
QColor themeInterface::m_primaryColor;
QColor themeInterface::m_primaryTextColor;
QColor themeInterface::m_secondaryTextColor;
QColor themeInterface::m_textColor;
double themeInterface::m_basePointSize;
double themeInterface::m_headingPointSize;
double themeInterface::m_regularPointSize;
double themeInterface::m_smallPointSize;
double themeInterface::m_titlePointSize;
QString themeInterface::m_currentTheme;
QString themeInterface::m_iconStyle;
const QColor BLUE_BACKGROUND_COLOR = "#eff0f1";
const QColor BLUE_CONTRAST_ACCENT_COLOR = "#FF5722";
const QColor BLUE_DARKER_PRIMARY_COLOR = "#303F9f";
const QColor BLUE_DARKER_PRIMARY_TEXT_COLOR = "#ECECEC";
const QColor BLUE_DRAWER_COLOR = "#FFFFFF";
const QColor BLUE_LIGHT_DRAWER_COLOR = "#FFFFFF";
const QColor BLUE_LIGHT_PRIMARY_COLOR = "#C5CAE9";
const QColor BLUE_LIGHT_PRIMARY_TEXT_COLOR = "#212121";
const QColor BLUE_PRIMARY_COLOR = "#3F51B5";
const QColor BLUE_PRIMARY_TEXT_COLOR = "#FFFFFF";
const QColor BLUE_SECONDARY_TEXT_COLOR = "#757575";
const QColor BLUE_TEXT_COLOR = "#212121";
const QColor PINK_BACKGROUND_COLOR = "#eff0f1";
const QColor PINK_CONTRAST_ACCENT_COLOR = "#FF5722";
const QColor PINK_DARKER_PRIMARY_COLOR = "#C2185B";
const QColor PINK_DARKER_PRIMARY_TEXT_COLOR = "#ECECEC";
const QColor PINK_DRAWER_COLOR = "#FFFFFF";
const QColor PINK_LIGHT_DRAWER_COLOR = "#FFFFFF";
const QColor PINK_LIGHT_PRIMARY_COLOR = "#FFDDF4";
const QColor PINK_LIGHT_PRIMARY_TEXT_COLOR = "#212121";
const QColor PINK_PRIMARY_COLOR = "#FF69B4";
const QColor PINK_PRIMARY_TEXT_COLOR = "#212121";
const QColor PINK_SECONDARY_TEXT_COLOR = "#757575";
const QColor PINK_TEXT_COLOR = "#212121";
const QColor DARK_BACKGROUND_COLOR = "#303030";
const QColor DARK_CONTRAST_ACCENT_COLOR = "#FF5722";
const QColor DARK_DARKER_PRIMARY_COLOR = "#303F9f";
const QColor DARK_DARKER_PRIMARY_TEXT_COLOR = "#ECECEC";
const QColor DARK_DRAWER_COLOR = "#424242";
const QColor DARK_LIGHT_DRAWER_COLOR = "#FFFFFF";
const QColor DARK_LIGHT_PRIMARY_COLOR = "#C5CAE9";
const QColor DARK_LIGHT_PRIMARY_TEXT_COLOR = "#ECECEC";
const QColor DARK_PRIMARY_COLOR = "#3F51B5";
const QColor DARK_PRIMARY_TEXT_COLOR = "#ECECEC";
const QColor DARK_SECONDARY_TEXT_COLOR = "#757575";
const QColor DARK_TEXT_COLOR = "#ECECEC";
themeInterface *themeInterface::instance()
{
static themeInterface *self = new themeInterface;
@ -16,22 +77,22 @@ void themeInterface::setup(QQmlContext *ct)
ct->setContextProperty("ThemeNew", instance());
// get current theme
instance()->m_currentTheme = qPrefDisplay::theme();
instance()->update_theme();
m_currentTheme = qPrefDisplay::theme();
update_theme();
// check system font
instance()->m_basePointSize = defaultModelFont().pointSize();
m_basePointSize = defaultModelFont().pointSize();
// set initial font size
instance()->set_currentScale(qPrefDisplay::mobile_scale());
set_currentScale(qPrefDisplay::mobile_scale());
}
void themeInterface::set_currentTheme(const QString &theme)
{
m_currentTheme = theme;
qPrefDisplay::set_theme(m_currentTheme);
update_theme();
emit currentThemeChanged(theme);
instance()->update_theme();
emit instance()->currentThemeChanged(theme);
}
double themeInterface::currentScale()
@ -42,7 +103,7 @@ void themeInterface::set_currentScale(double newScale)
{
if (newScale != qPrefDisplay::mobile_scale()) {
qPrefDisplay::set_mobile_scale(newScale);
emit currentScaleChanged(qPrefDisplay::mobile_scale());
emit instance()->currentScaleChanged(qPrefDisplay::mobile_scale());
}
// Set current font size
@ -50,74 +111,74 @@ void themeInterface::set_currentScale(double newScale)
// adjust all used font sizes
m_regularPointSize = defaultModelFont().pointSize();
emit regularPointSizeChanged(m_regularPointSize);
emit instance()->regularPointSizeChanged(m_regularPointSize);
m_headingPointSize = m_regularPointSize * 1.2;
emit headingPointSizeChanged(m_headingPointSize);
emit instance()->headingPointSizeChanged(m_headingPointSize);
m_smallPointSize = m_regularPointSize * 0.8;
emit smallPointSizeChanged(m_smallPointSize);
emit instance()->smallPointSizeChanged(m_smallPointSize);
m_titlePointSize = m_regularPointSize * 1.5;
emit titlePointSizeChanged(m_titlePointSize);
emit instance()->titlePointSizeChanged(m_titlePointSize);
}
void themeInterface::update_theme()
{
if (m_currentTheme == "Blue") {
m_backgroundColor = m_blueBackgroundColor;
m_contrastAccentColor = m_blueContrastAccentColor;
m_darkerPrimaryColor = m_blueDarkerPrimaryColor;
m_darkerPrimaryTextColor = m_blueDarkerPrimaryTextColor;
m_drawerColor = m_blueDrawerColor;
m_lightDrawerColor = m_blueDrawerColor;
m_lightPrimaryColor = m_blueLightPrimaryColor;
m_lightPrimaryTextColor = m_blueLightPrimaryTextColor;
m_primaryColor = m_bluePrimaryColor;
m_primaryTextColor = m_bluePrimaryTextColor;
m_secondaryTextColor = m_blueSecondaryTextColor;
m_textColor = m_blueTextColor;
m_backgroundColor = BLUE_BACKGROUND_COLOR;
m_contrastAccentColor = BLUE_CONTRAST_ACCENT_COLOR;
m_darkerPrimaryColor = BLUE_DARKER_PRIMARY_COLOR;
m_darkerPrimaryTextColor = BLUE_DARKER_PRIMARY_TEXT_COLOR;
m_drawerColor = BLUE_DRAWER_COLOR;
m_lightDrawerColor = BLUE_LIGHT_DRAWER_COLOR;
m_lightPrimaryColor = BLUE_LIGHT_PRIMARY_COLOR;
m_lightPrimaryTextColor = BLUE_LIGHT_PRIMARY_TEXT_COLOR;
m_primaryColor = BLUE_PRIMARY_COLOR;
m_primaryTextColor = BLUE_PRIMARY_TEXT_COLOR;
m_secondaryTextColor = BLUE_SECONDARY_TEXT_COLOR;
m_textColor = BLUE_TEXT_COLOR;
m_iconStyle = ":/icons";
} else if (m_currentTheme == "Pink") {
m_backgroundColor = m_pinkBackgroundColor;
m_contrastAccentColor = m_pinkContrastAccentColor;
m_darkerPrimaryColor = m_pinkDarkerPrimaryColor;
m_darkerPrimaryTextColor = m_pinkDarkerPrimaryTextColor;
m_drawerColor = m_pinkDrawerColor;
m_lightDrawerColor = m_pinkDrawerColor;
m_lightPrimaryColor = m_pinkLightPrimaryColor;
m_lightPrimaryTextColor = m_pinkLightPrimaryTextColor;
m_primaryColor = m_pinkPrimaryColor;
m_primaryTextColor = m_pinkPrimaryTextColor;
m_secondaryTextColor = m_pinkSecondaryTextColor;
m_textColor = m_pinkTextColor;
m_backgroundColor = PINK_BACKGROUND_COLOR;
m_contrastAccentColor = PINK_CONTRAST_ACCENT_COLOR;
m_darkerPrimaryColor = PINK_DARKER_PRIMARY_COLOR;
m_darkerPrimaryTextColor = PINK_DARKER_PRIMARY_TEXT_COLOR;
m_drawerColor = PINK_DRAWER_COLOR;
m_lightDrawerColor = PINK_LIGHT_DRAWER_COLOR;
m_lightPrimaryColor = PINK_LIGHT_PRIMARY_COLOR;
m_lightPrimaryTextColor = PINK_LIGHT_PRIMARY_TEXT_COLOR;
m_primaryColor = PINK_PRIMARY_COLOR;
m_primaryTextColor = PINK_PRIMARY_TEXT_COLOR;
m_secondaryTextColor = PINK_SECONDARY_TEXT_COLOR;
m_textColor = PINK_TEXT_COLOR;
m_iconStyle = ":/icons";
} else {
m_backgroundColor = m_darkBackgroundColor;
m_contrastAccentColor = m_darkContrastAccentColor;
m_darkerPrimaryColor = m_darkDarkerPrimaryColor;
m_darkerPrimaryTextColor = m_darkDarkerPrimaryTextColor;
m_drawerColor = m_darkDrawerColor;
m_lightDrawerColor = m_darkDrawerColor;
m_lightPrimaryColor = m_darkLightPrimaryColor;
m_lightPrimaryTextColor = m_darkLightPrimaryTextColor;
m_primaryColor = m_darkPrimaryColor;
m_primaryTextColor = m_darkPrimaryTextColor;
m_secondaryTextColor = m_darkSecondaryTextColor;
m_textColor = m_darkTextColor;
m_backgroundColor = DARK_BACKGROUND_COLOR;
m_contrastAccentColor = DARK_CONTRAST_ACCENT_COLOR;
m_darkerPrimaryColor = DARK_DARKER_PRIMARY_COLOR;
m_darkerPrimaryTextColor = DARK_DARKER_PRIMARY_TEXT_COLOR;
m_drawerColor = DARK_DRAWER_COLOR;
m_lightDrawerColor = DARK_LIGHT_DRAWER_COLOR;
m_lightPrimaryColor = DARK_LIGHT_PRIMARY_COLOR;
m_lightPrimaryTextColor = DARK_LIGHT_PRIMARY_TEXT_COLOR;
m_primaryColor = DARK_PRIMARY_COLOR;
m_primaryTextColor = DARK_PRIMARY_TEXT_COLOR;
m_secondaryTextColor = DARK_SECONDARY_TEXT_COLOR;
m_textColor = DARK_TEXT_COLOR;
m_iconStyle = ":/icons-dark";
}
emit backgroundColorChanged(m_backgroundColor);
emit contrastAccentColorChanged(m_contrastAccentColor);
emit darkerPrimaryColorChanged(m_darkerPrimaryColor);
emit darkerPrimaryTextColorChanged(m_darkerPrimaryTextColor);
emit drawerColorChanged(m_drawerColor);
emit lightDrawerColorChanged(m_lightDrawerColor);
emit lightPrimaryColorChanged(m_lightPrimaryColor);
emit lightPrimaryTextColorChanged(m_lightPrimaryTextColor);
emit primaryColorChanged(m_primaryColor);
emit primaryTextColorChanged(m_primaryTextColor);
emit secondaryTextColorChanged(m_secondaryTextColor);
emit textColorChanged(m_textColor);
emit iconStyleChanged(m_iconStyle);
emit instance()->backgroundColorChanged(m_backgroundColor);
emit instance()->contrastAccentColorChanged(m_contrastAccentColor);
emit instance()->darkerPrimaryColorChanged(m_darkerPrimaryColor);
emit instance()->darkerPrimaryTextColorChanged(m_darkerPrimaryTextColor);
emit instance()->drawerColorChanged(m_drawerColor);
emit instance()->lightDrawerColorChanged(m_lightDrawerColor);
emit instance()->lightPrimaryColorChanged(m_lightPrimaryColor);
emit instance()->lightPrimaryTextColorChanged(m_lightPrimaryTextColor);
emit instance()->primaryColorChanged(m_primaryColor);
emit instance()->primaryTextColorChanged(m_primaryTextColor);
emit instance()->secondaryTextColorChanged(m_secondaryTextColor);
emit instance()->textColorChanged(m_textColor);
emit instance()->iconStyleChanged(m_iconStyle);
}

View file

@ -35,56 +35,17 @@ class themeInterface : public QObject {
Q_PROPERTY(QString currentTheme MEMBER m_currentTheme WRITE set_currentTheme NOTIFY currentThemeChanged)
Q_PROPERTY(QString iconStyle MEMBER m_iconStyle NOTIFY iconStyleChanged)
// Compatibility existing code
Q_PROPERTY(QColor blueBackgroundColor MEMBER m_blueBackgroundColor CONSTANT)
Q_PROPERTY(QColor blueContrastAccentColor MEMBER m_blueTextColor CONSTANT)
Q_PROPERTY(QColor blueDarkerPrimaryColor MEMBER m_blueDarkerPrimaryColor CONSTANT)
Q_PROPERTY(QColor blueDarkerPrimaryTextColor MEMBER m_blueDarkerPrimaryTextColor CONSTANT)
Q_PROPERTY(QColor blueDrawerColor MEMBER m_blueDrawerColor CONSTANT)
Q_PROPERTY(QColor blueLightDrawerColor MEMBER m_blueLightDrawerColor CONSTANT)
Q_PROPERTY(QColor blueLightPrimaryColor MEMBER m_blueLightPrimaryColor CONSTANT)
Q_PROPERTY(QColor blueLightPrimaryTextColor MEMBER m_blueLightPrimaryTextColor CONSTANT)
Q_PROPERTY(QColor bluePrimaryColor MEMBER m_bluePrimaryColor CONSTANT)
Q_PROPERTY(QColor bluePrimaryTextColor MEMBER m_bluePrimaryTextColor CONSTANT)
Q_PROPERTY(QColor blueSecondaryTextColor MEMBER m_blueSecondaryTextColor CONSTANT)
Q_PROPERTY(QColor blueTextColor MEMBER m_blueTextColor CONSTANT)
Q_PROPERTY(QColor pinkBackgroundColor MEMBER m_pinkBackgroundColor CONSTANT)
Q_PROPERTY(QColor pinkContrastAccentColor MEMBER m_pinkContrastAccentColor CONSTANT)
Q_PROPERTY(QColor pinkDarkerPrimaryColor MEMBER m_blueDarkerPrimaryColor CONSTANT)
Q_PROPERTY(QColor pinkDarkerPrimaryTextColor MEMBER m_blueDarkerPrimaryTextColor CONSTANT)
Q_PROPERTY(QColor pinkDrawerColor MEMBER m_pinkDrawerColor CONSTANT)
Q_PROPERTY(QColor pinkLightDrawerColor MEMBER m_pinkLightDrawerColor CONSTANT)
Q_PROPERTY(QColor pinkLightPrimaryColor MEMBER m_blueLightPrimaryColor CONSTANT)
Q_PROPERTY(QColor pinkLightPrimaryTextColor MEMBER m_blueLightPrimaryTextColor CONSTANT)
Q_PROPERTY(QColor pinkPrimaryColor MEMBER m_pinkPrimaryColor CONSTANT)
Q_PROPERTY(QColor pinkPrimaryTextColor MEMBER m_pinkPrimaryTextColor CONSTANT)
Q_PROPERTY(QColor pinkSecondaryTextColor MEMBER m_blueSecondaryTextColor CONSTANT)
Q_PROPERTY(QColor pinkTextColor MEMBER m_pinkTextColor CONSTANT)
Q_PROPERTY(QColor darkBackgroundColor MEMBER m_darkBackgroundColor CONSTANT)
Q_PROPERTY(QColor darkContrastAccentColor MEMBER m_darkContrastAccentColor CONSTANT)
Q_PROPERTY(QColor darkDarkerPrimaryColor MEMBER m_blueDarkerPrimaryColor CONSTANT)
Q_PROPERTY(QColor darkDarkerPrimaryTextColor MEMBER m_blueDarkerPrimaryTextColor CONSTANT)
Q_PROPERTY(QColor darkDrawerColor MEMBER m_drawerColor CONSTANT)
Q_PROPERTY(QColor darkLightDrawerColor MEMBER m_darkLightDrawerColor CONSTANT)
Q_PROPERTY(QColor darkLightPrimaryColor MEMBER m_blueLightPrimaryColor CONSTANT)
Q_PROPERTY(QColor darkLightPrimaryTextColor MEMBER m_blueLightPrimaryTextColor CONSTANT)
Q_PROPERTY(QColor darkPrimaryColor MEMBER m_darkPrimaryColor CONSTANT)
Q_PROPERTY(QColor darkPrimaryTextColor MEMBER m_darkPrimaryTextColor CONSTANT)
Q_PROPERTY(QColor darkSecondaryTextColor MEMBER m_blueSecondaryTextColor CONSTANT)
Q_PROPERTY(QColor darkTextColor MEMBER m_darkTextColor CONSTANT)
public:
static themeInterface *instance();
static void setup(QQmlContext *ct);
public slots:
void set_currentTheme(const QString &theme);
static double currentScale();
double currentScale();
void set_currentScale(double);
public slots:
static void set_currentTheme(const QString &theme);
static void set_currentScale(double);
signals:
void backgroundColorChanged(QColor);
@ -111,68 +72,28 @@ signals:
private:
themeInterface() {}
void update_theme();
static void update_theme();
QColor m_backgroundColor;
QColor m_contrastAccentColor;
QColor m_darkerPrimaryColor;
QColor m_darkerPrimaryTextColor;
QColor m_drawerColor;
QColor m_lightDrawerColor;
QColor m_lightPrimaryColor;
QColor m_lightPrimaryTextColor;
QColor m_primaryColor;
QColor m_primaryTextColor;
QColor m_secondaryTextColor;
QColor m_textColor;
static QColor m_backgroundColor;
static QColor m_contrastAccentColor;
static QColor m_darkerPrimaryColor;
static QColor m_darkerPrimaryTextColor;
static QColor m_drawerColor;
static QColor m_lightDrawerColor;
static QColor m_lightPrimaryColor;
static QColor m_lightPrimaryTextColor;
static QColor m_primaryColor;
static QColor m_primaryTextColor;
static QColor m_secondaryTextColor;
static QColor m_textColor;
double m_basePointSize;
double m_headingPointSize;
double m_regularPointSize;
double m_smallPointSize;
double m_titlePointSize;
static double m_basePointSize;
static double m_headingPointSize;
static double m_regularPointSize;
static double m_smallPointSize;
static double m_titlePointSize;
QString m_currentTheme;
QString m_iconStyle;
// Compatibility existing code
const QColor m_blueBackgroundColor = "#eff0f1";
const QColor m_blueContrastAccentColor = "#FF5722";
const QColor m_blueDarkerPrimaryColor = "#303F9f";
const QColor m_blueDarkerPrimaryTextColor = "#ECECEC";
const QColor m_blueDrawerColor = "#FFFFFF";
const QColor m_blueLightDrawerColor = "#FFFFFF";
const QColor m_blueLightPrimaryColor = "#C5CAE9";
const QColor m_blueLightPrimaryTextColor = "#212121";
const QColor m_bluePrimaryColor = "#3F51B5";
const QColor m_bluePrimaryTextColor = "#FFFFFF";
const QColor m_blueSecondaryTextColor = "#757575";
const QColor m_blueTextColor = "#212121";
const QColor m_pinkBackgroundColor = "#eff0f1";
const QColor m_pinkContrastAccentColor = "#FF5722";
const QColor m_pinkDarkerPrimaryColor = "#C2185B";
const QColor m_pinkDarkerPrimaryTextColor = "#ECECEC";
const QColor m_pinkDrawerColor = "#FFFFFF";
const QColor m_pinkLightDrawerColor = "#FFFFFF";
const QColor m_pinkLightPrimaryColor = "#FFDDF4";
const QColor m_pinkLightPrimaryTextColor = "#212121";
const QColor m_pinkPrimaryColor = "#FF69B4";
const QColor m_pinkPrimaryTextColor = "#212121";
const QColor m_pinkSecondaryTextColor = "#757575";
const QColor m_pinkTextColor = "#212121";
const QColor m_darkBackgroundColor = "#303030";
const QColor m_darkContrastAccentColor = "#FF5722";
const QColor m_darkDarkerPrimaryColor = "#303F9f";
const QColor m_darkDarkerPrimaryTextColor = "#ECECEC";
const QColor m_darkDrawerColor = "#424242";
const QColor m_darkLightDrawerColor = "#FFFFFF";
const QColor m_darkLightPrimaryColor = "#C5CAE9";
const QColor m_darkLightPrimaryTextColor = "#ECECEC";
const QColor m_darkPrimaryColor = "#3F51B5";
const QColor m_darkPrimaryTextColor = "#ECECEC";
const QColor m_darkSecondaryTextColor = "#757575";
const QColor m_darkTextColor = "#ECECEC";
static QString m_currentTheme;
static QString m_iconStyle;
};
#endif