From 94b3f80305e2fd34728848b335aca03a81555e4c Mon Sep 17 00:00:00 2001 From: Clayton Groeneveld Date: Fri, 29 Mar 2019 04:16:12 -0500 Subject: [PATCH] UI: Rename Default theme to System The system theme was named Default even though the default theme is Dark. This addresses that by renaming Default.qss to System.qss. I've made it backwards compatible so users already using this theme are not affected. The theme list now shows up as: -System -Dark (Default) -Acri -Rachni I have also made it so that you can specify the default theme in the UI config file. --- UI/data/locale/en-US.ini | 1 + UI/data/themes/{Default.qss => System.qss} | 0 UI/obs-app.cpp | 14 +++++-- UI/ui-config.h.in | 2 + UI/window-basic-settings.cpp | 44 ++++++++++++++++++---- 5 files changed, 50 insertions(+), 11 deletions(-) rename UI/data/themes/{Default.qss => System.qss} (100%) diff --git a/UI/data/locale/en-US.ini b/UI/data/locale/en-US.ini index f5198c78e..de6be7a08 100644 --- a/UI/data/locale/en-US.ini +++ b/UI/data/locale/en-US.ini @@ -86,6 +86,7 @@ ShowInMultiview="Show in Multiview" VerticalLayout="Vertical Layout" Group="Group" DoNotShowAgain="Do not show again" +Default="(Default)" # warning if program already open AlreadyRunning.Title="OBS is already running" diff --git a/UI/data/themes/Default.qss b/UI/data/themes/System.qss similarity index 100% rename from UI/data/themes/Default.qss rename to UI/data/themes/System.qss diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp index a58b28335..f271d0450 100644 --- a/UI/obs-app.cpp +++ b/UI/obs-app.cpp @@ -54,6 +54,8 @@ #include +#include "ui-config.h" + using namespace std; static log_handler_t def_log_handler; @@ -423,7 +425,7 @@ bool OBSApp::InitGlobalConfigDefaults() if (!config_get_bool(globalConfig, "General", "Pre21Defaults")) { config_set_default_string(globalConfig, "General", - "CurrentTheme", "Dark"); + "CurrentTheme", DEFAULT_THEME); } config_set_default_bool(globalConfig, "BasicWindow", @@ -1026,18 +1028,22 @@ bool OBSApp::InitTheme() const char *themeName = config_get_string(globalConfig, "General", "CurrentTheme"); + + if (strcmp(themeName, "Default") == 0) + themeName = "System"; + if (!themeName) { /* Use deprecated "Theme" value if available */ themeName = config_get_string(globalConfig, "General", "Theme"); if (!themeName) - themeName = "Default"; + themeName = DEFAULT_THEME; } - if (strcmp(themeName, "Default") != 0 && SetTheme(themeName)) + if (strcmp(themeName, DEFAULT_THEME) != 0 && SetTheme(themeName)) return true; - return SetTheme("Default"); + return SetTheme(DEFAULT_THEME); } OBSApp::OBSApp(int &argc, char **argv, profiler_name_store_t *store) diff --git a/UI/ui-config.h.in b/UI/ui-config.h.in index d2c7dd5fe..fe31138bb 100644 --- a/UI/ui-config.h.in +++ b/UI/ui-config.h.in @@ -27,3 +27,5 @@ #define RESTREAM_ENABLED @RESTREAM_ENABLED@ #define RESTREAM_CLIENTID "@RESTREAM_CLIENTID@" #define RESTREAM_HASH 0x@RESTREAM_HASH@ + +#define DEFAULT_THEME "Dark" diff --git a/UI/window-basic-settings.cpp b/UI/window-basic-settings.cpp index c34c5988e..19077ed10 100644 --- a/UI/window-basic-settings.cpp +++ b/UI/window-basic-settings.cpp @@ -48,6 +48,7 @@ #include "window-projector.hpp" #include +#include "ui-config.h" using namespace std; @@ -1003,17 +1004,31 @@ void OBSBasicSettings::LoadThemeList() } } + QString defaultTheme; + defaultTheme += DEFAULT_THEME; + defaultTheme += " "; + defaultTheme += QTStr("Default"); + /* Check shipped themes. */ QDirIterator uIt(QString(themeDir.c_str()), QStringList() << "*.qss", QDir::Files); while (uIt.hasNext()) { uIt.next(); QString name = uIt.fileName().section(".",0,0); - if (!uniqueSet.contains(name)) + + if (name == DEFAULT_THEME) + name = defaultTheme; + + if (!uniqueSet.contains(name) && name != "Default") ui->theme->addItem(name); } - int idx = ui->theme->findText(App()->GetTheme()); + const char *themeName = App()->GetTheme(); + + if (strcmp(themeName, DEFAULT_THEME) == 0) + themeName = QT_TO_UTF8(defaultTheme); + + int idx = ui->theme->findText(themeName); if (idx != -1) ui->theme->setCurrentIndex(idx); } @@ -2657,13 +2672,19 @@ void OBSBasicSettings::SaveGeneralSettings() int themeIndex = ui->theme->currentIndex(); QString themeData = ui->theme->itemText(themeIndex); - string theme = themeData.toStdString(); + QString defaultTheme; + defaultTheme += DEFAULT_THEME; + defaultTheme += " "; + defaultTheme += QTStr("Default"); + + if (themeData == defaultTheme) + themeData = DEFAULT_THEME; if (WidgetChanged(ui->theme)) { config_set_string(GetGlobalConfig(), "General", "CurrentTheme", - theme.c_str()); + QT_TO_UTF8(themeData)); - App()->SetTheme(theme); + App()->SetTheme(themeData.toUtf8().constData()); } #if defined(_WIN32) || defined(__APPLE__) @@ -3392,8 +3413,17 @@ void OBSBasicSettings::closeEvent(QCloseEvent *event) void OBSBasicSettings::on_theme_activated(int idx) { - string currT = ui->theme->itemText(idx).toStdString(); - App()->SetTheme(currT); + QString currT = ui->theme->itemText(idx); + + QString defaultTheme; + defaultTheme += DEFAULT_THEME; + defaultTheme += " "; + defaultTheme += QTStr("Default"); + + if (currT == defaultTheme) + currT = DEFAULT_THEME; + + App()->SetTheme(currT.toUtf8().constData()); } void OBSBasicSettings::on_listWidget_itemSelectionChanged() -- GitLab