From 074fe66e5714d379e8bb23720a1c5042932c6a0c Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Mon, 18 May 2020 11:28:48 +0200 Subject: [PATCH] - moved app theme to new lib --- ScStwApp.pro | 2 + ScStwSrc/ScStwApp.pro | 9 +- ScStwSrc/headers/apptheme.h | 31 ---- .../qml/SettingsDialog/StartPage.qml | 9 +- ScStwSrc/resources/qml/main.qml | 4 + ScStwSrc/sources/apptheme.cpp | 132 ------------------ ScStwSrc/sources/main.cpp | 4 +- shared-libraries | 2 +- 8 files changed, 17 insertions(+), 176 deletions(-) delete mode 100644 ScStwSrc/headers/apptheme.h delete mode 100644 ScStwSrc/sources/apptheme.cpp diff --git a/ScStwApp.pro b/ScStwApp.pro index cc58038..7adfb72 100644 --- a/ScStwApp.pro +++ b/ScStwApp.pro @@ -3,7 +3,9 @@ CONFIG += ordered SUBDIRS += \ ScStwLibraries \ + ScStwStyling \ ScStwApp ScStwApp.file = ScStwSrc/ScStwApp.pro ScStwLibraries.file = shared-libraries/ScStwLibraries/ScStwLibraries.pro +ScStwStyling.file = shared-libraries/ScStwStyling/ScStwStyling.pro diff --git a/ScStwSrc/ScStwApp.pro b/ScStwSrc/ScStwApp.pro index 6975494..96110f0 100644 --- a/ScStwSrc/ScStwApp.pro +++ b/ScStwSrc/ScStwApp.pro @@ -22,20 +22,15 @@ TARGET = speedclimbing_stw # include submodules include($$PWD/../shared-libraries/ScStwLibraries/ScStwLibraries.pri) +include($$PWD/../shared-libraries/ScStwStyling/ScStwStyling.pri) SOURCES += \ sources/scstwappbackend.cpp \ sources/main.cpp \ - sources/appsettings.cpp \ - #sources/speedtimer.cpp \ - #sources/climbingrace.cpp \ - sources/apptheme.cpp + sources/appsettings.cpp HEADERS += \ headers/appsettings.h \ - #headers/speedtimer.h \ - #headers/climbingrace.h \ - headers/apptheme.h \ headers/scstwappbackend.h RESOURCES += \ diff --git a/ScStwSrc/headers/apptheme.h b/ScStwSrc/headers/apptheme.h deleted file mode 100644 index e2e683b..0000000 --- a/ScStwSrc/headers/apptheme.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef APPTHEME_H -#define APPTHEME_H - -#include -#include -#include "appsettings.h" - -class AppTheme : public QObject -{ - Q_OBJECT - Q_PROPERTY(QVariant style READ getStyle NOTIFY styleChanged) -public: - explicit AppTheme(QObject *parent = nullptr); - -private: - QVariant lightTheme; - QVariant darkTheme; - - QVariant * currentTheme; - - -signals: - void styleChanged(); - -public slots: - QVariant getStyle(); - Q_INVOKABLE void changeTheme(); - Q_INVOKABLE void refreshTheme(); -}; - -#endif // APPTHEME_H diff --git a/ScStwSrc/resources/qml/SettingsDialog/StartPage.qml b/ScStwSrc/resources/qml/SettingsDialog/StartPage.qml index 8208e72..0ed25ff 100644 --- a/ScStwSrc/resources/qml/SettingsDialog/StartPage.qml +++ b/ScStwSrc/resources/qml/SettingsDialog/StartPage.qml @@ -5,6 +5,8 @@ import QtQuick.Controls 2.2 import QtQuick.Layouts 1.3 import QtGraphicalEffects 1.0 import QtQuick.Controls.Styles 1.4 + +import com.itsblue.speedclimbingstopwatch 2.0 import "../components" Column { @@ -49,11 +51,12 @@ Column { width: parent.width height: parentObj.delegateHeight - checked: speedBackend.readSetting("theme") === "Dark" + checked: parseInt(speedBackend.readSetting("theme")) === AppTheme.Dark onCheckedChanged: { - speedBackend.writeSetting("theme", checked ? "Dark":"Light") - appTheme.refreshTheme() + var newTheme = checked ? AppTheme.Dark:AppTheme.Light + speedBackend.writeSetting("theme", newTheme) + appTheme.setTheme(newTheme) } } } diff --git a/ScStwSrc/resources/qml/main.qml b/ScStwSrc/resources/qml/main.qml index 5b203b1..6427439 100644 --- a/ScStwSrc/resources/qml/main.qml +++ b/ScStwSrc/resources/qml/main.qml @@ -98,6 +98,10 @@ Window { AppTheme { id: appTheme + + Component.onCompleted: { + appTheme.setTheme(speedBackend.readSetting("theme")) + } } /*------------------------ diff --git a/ScStwSrc/sources/apptheme.cpp b/ScStwSrc/sources/apptheme.cpp deleted file mode 100644 index dd6fd19..0000000 --- a/ScStwSrc/sources/apptheme.cpp +++ /dev/null @@ -1,132 +0,0 @@ -#include "headers/apptheme.h" - -AppTheme::AppTheme(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"} - - }; - this->darkTheme = tmpDarkTheme; - - 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->lightTheme = tmpLightTheme; - - QString currentThemeString = pGlobalAppSettings->loadSetting("theme"); - - if(currentThemeString == "Light"){ - this->currentTheme = &this->lightTheme; - } - else if (currentThemeString == "Dark") { - this->currentTheme = &this->darkTheme; - } - else { - this->currentTheme = &this->lightTheme; - } -} - -QVariant AppTheme::getStyle() { - return *this->currentTheme; -} - -void AppTheme::changeTheme() { - QString currentThemeString = pGlobalAppSettings->loadSetting("theme"); - QString newThemeString = "Light"; - - if(currentThemeString == "Light"){ - this->currentTheme = &this->darkTheme; - newThemeString = "Dark"; - - } - else if (currentThemeString == "Dark") { - this->currentTheme = &this->lightTheme; - newThemeString = "Light"; - } - else { - this->currentTheme = &this->lightTheme; - } - - pGlobalAppSettings->writeSetting("theme", newThemeString); - - emit this->styleChanged(); -} - -void AppTheme::refreshTheme() { - QString currentThemeString = pGlobalAppSettings->loadSetting("theme"); - - if(currentThemeString == "Light"){ - this->currentTheme = &this->lightTheme; - } - else if (currentThemeString == "Dark") { - this->currentTheme = &this->darkTheme; - } - - emit this->styleChanged(); -} diff --git a/ScStwSrc/sources/main.cpp b/ScStwSrc/sources/main.cpp index f539554..70d7354 100644 --- a/ScStwSrc/sources/main.cpp +++ b/ScStwSrc/sources/main.cpp @@ -53,12 +53,12 @@ #include "headers/appsettings.h" //#include "headers/speedtimer.h" //#include "headers/climbingrace.h" -#include "headers/apptheme.h" #include "headers/scstwappbackend.h" #include #include #include #include +#include #include int main(int argc, char *argv[]) @@ -91,7 +91,7 @@ int main(int argc, char *argv[]) qmlRegisterType("com.itsblue.speedclimbingstopwatch", 2, 0, "SpeedBackend"); qmlRegisterType("com.itsblue.speedclimbingstopwatch", 2, 0, "ScStwRace"); qmlRegisterType("com.itsblue.speedclimbingstopwatch", 2, 0, "ScStwTimer"); - qmlRegisterType("com.itsblue.speedclimbingstopwatch", 2, 0, "AppTheme"); + qmlRegisterType("com.itsblue.speedclimbingstopwatch", 2, 0, "AppTheme"); //qmlRegisterUncreatableType("com.itsblue.speedclimbingstopwatch", 2, 0, "ScStw", "This is a static class and therefore not instantiable"); qmlRegisterType("com.itsblue.speedclimbingstopwatch", 2, 0, "ScStw"); qmlRegisterType("com.itsblue.speedclimbingstopwatch", 2, 0, "ScStwClient"); diff --git a/shared-libraries b/shared-libraries index 3f199b1..ddc4898 160000 --- a/shared-libraries +++ b/shared-libraries @@ -1 +1 @@ -Subproject commit 3f199b151131775e572c964bd3bb64120940c153 +Subproject commit ddc48986ad557f9e8ef1f779f9e0d42a128d81cf