diff --git a/src/qt_gui/main_window.cpp b/src/qt_gui/main_window.cpp index 49297a996..6977fcdfc 100644 --- a/src/qt_gui/main_window.cpp +++ b/src/qt_gui/main_window.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "about_dialog.h" #include "cheats_patches.h" @@ -26,6 +27,8 @@ #include "common/discord_rpc_handler.h" #endif +std::string s_system_style_name; + MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); installEventFilter(this); @@ -118,21 +121,15 @@ void MainWindow::CreateActions() { void MainWindow::AddUiWidgets() { // add toolbar widgets - static QString s_system_style_name; - static bool s_system_style_name_set; - - if (!s_system_style_name_set) { - s_system_style_name_set = true; - s_system_style_name = QApplication::style()->objectName(); - } + QString qsystem_style_name; + qsystem_style_name = QApplication::style()->objectName(); + s_system_style_name = qsystem_style_name.toStdString(); std::string widget_style = Config::getWidgetStyle(); if (widget_style == "Fusion") { qApp->setStyle(QStyleFactory::create("Fusion")); - qApp->setStyleSheet(QString()); } else if (widget_style == "System") { - qApp->setStyle(s_system_style_name); - qApp->setStyleSheet(QString()); + qApp->setStyle(qsystem_style_name); } ui->toolBar->setObjectName("mw_toolbar"); ui->toolBar->addWidget(ui->playButton); @@ -571,10 +568,35 @@ void MainWindow::CreateConnects() { connect(ui->setThemeSystemDark, &QAction::triggered, &m_window_themes, [this]() { m_window_themes.SetWindowTheme(Theme::SystemDark, ui->mw_searchbar); Config::setMainWindowTheme(static_cast(Theme::SystemDark)); - if (isIconBlack) { + + bool isSystemDarkMode; + #ifdef __linux__ + const QPalette defaultPalette; + const auto text = defaultPalette.color(QPalette::WindowText); + const auto window = defaultPalette.color(QPalette::Window); + if (text.lightness() > window.lightness()) { + isSystemDarkMode = true; + } else { + isSystemDarkMode = false; + } + #else + if(QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark) { + isSystemDarkMode = true; + } else { + isSystemDarkMode = false; + } + #endif + if(isSystemDarkMode) { + if (isIconBlack) { SetUiIcons(false); isIconBlack = false; - } + } + } else { + if (!isIconBlack) { + SetUiIcons(true); + isIconBlack = true; + } + } }); connect(ui->setThemeSystemLight, &QAction::triggered, &m_window_themes, [this]() { m_window_themes.SetWindowTheme(Theme::SystemLight, ui->mw_searchbar); diff --git a/src/qt_gui/main_window.h b/src/qt_gui/main_window.h index b1f1b9667..d624c45be 100644 --- a/src/qt_gui/main_window.h +++ b/src/qt_gui/main_window.h @@ -24,6 +24,8 @@ #include "main_window_ui.h" #include "pkg_viewer.h" +extern std::string s_system_style_name; + class GameListFrame; class MainWindow : public QMainWindow { diff --git a/src/qt_gui/settings_dialog.cpp b/src/qt_gui/settings_dialog.cpp index 6746f9692..0dbc56dff 100644 --- a/src/qt_gui/settings_dialog.cpp +++ b/src/qt_gui/settings_dialog.cpp @@ -16,6 +16,7 @@ #include "common/logging/backend.h" #include "common/logging/filter.h" #include "common/logging/formatter.h" +#include "common/logging/log.h" #include "main_window.h" #include "settings_dialog.h" #include "ui_settings_dialog.h" @@ -527,6 +528,18 @@ void SettingsDialog::UpdateSettings() { #endif BackgroundMusicPlayer::getInstance().setVolume(ui->BGMVolumeSlider->value()); + + if (Config::getWidgetStyle() == "Fusion") { + qApp->setStyle(QStyleFactory::create("Fusion")); + } else if (Config::getWidgetStyle() == "System") { + qApp->setStyle(QString::fromStdString(s_system_style_name)); + } + printf("%s", s_system_style_name.c_str()); + + foreach (QWidget* widget, QApplication::topLevelWidgets()) { + widget->update(); + } + QCoreApplication::processEvents(); } void SettingsDialog::ResetInstallFolders() {