From b6f5751b23e156d1b966f1f8d9015fa113038e13 Mon Sep 17 00:00:00 2001 From: tomboylover93 <95257311+tomboylover93@users.noreply.github.com> Date: Fri, 20 Dec 2024 21:44:16 -0300 Subject: [PATCH] Unify System (Dark) and System (Light) into a single theme To update the icon color you have to switch to another theme then back to System --- src/qt_gui/main_window.cpp | 69 +++++++++++++++++-------------- src/qt_gui/main_window_themes.cpp | 11 +---- src/qt_gui/main_window_themes.h | 2 +- src/qt_gui/main_window_ui.h | 21 ++++------ 4 files changed, 48 insertions(+), 55 deletions(-) diff --git a/src/qt_gui/main_window.cpp b/src/qt_gui/main_window.cpp index 6977fcdfc..8785535ff 100644 --- a/src/qt_gui/main_window.cpp +++ b/src/qt_gui/main_window.cpp @@ -115,8 +115,7 @@ void MainWindow::CreateActions() { m_theme_act_group->addAction(ui->setThemeBlue); m_theme_act_group->addAction(ui->setThemeViolet); m_theme_act_group->addAction(ui->setThemeGruvbox); - m_theme_act_group->addAction(ui->setThemeSystemDark); - m_theme_act_group->addAction(ui->setThemeSystemLight); + m_theme_act_group->addAction(ui->setThemeSystem); } void MainWindow::AddUiWidgets() { @@ -565,12 +564,12 @@ void MainWindow::CreateConnects() { isIconBlack = false; } }); - connect(ui->setThemeSystemDark, &QAction::triggered, &m_window_themes, [this]() { - m_window_themes.SetWindowTheme(Theme::SystemDark, ui->mw_searchbar); - Config::setMainWindowTheme(static_cast(Theme::SystemDark)); + connect(ui->setThemeSystem, &QAction::triggered, &m_window_themes, [this]() { + m_window_themes.SetWindowTheme(Theme::System, ui->mw_searchbar); + Config::setMainWindowTheme(static_cast(Theme::System)); bool isSystemDarkMode; - #ifdef __linux__ +#ifdef __linux__ const QPalette defaultPalette; const auto text = defaultPalette.color(QPalette::WindowText); const auto window = defaultPalette.color(QPalette::Window); @@ -579,31 +578,23 @@ void MainWindow::CreateConnects() { } else { isSystemDarkMode = false; } - #else +#else if(QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark) { isSystemDarkMode = true; } else { isSystemDarkMode = false; } - #endif - if(isSystemDarkMode) { +#endif + if (isSystemDarkMode) { if (isIconBlack) { - SetUiIcons(false); - isIconBlack = false; - } + SetUiIcons(false); + isIconBlack = false; + } } else { if (!isIconBlack) { - SetUiIcons(true); - isIconBlack = true; + SetUiIcons(true); + isIconBlack = true; } - } - }); - connect(ui->setThemeSystemLight, &QAction::triggered, &m_window_themes, [this]() { - m_window_themes.SetWindowTheme(Theme::SystemLight, ui->mw_searchbar); - Config::setMainWindowTheme(static_cast(Theme::SystemLight)); - if (!isIconBlack) { - SetUiIcons(true); - isIconBlack = true; } }); } @@ -984,14 +975,32 @@ void MainWindow::SetLastUsedTheme() { isIconBlack = false; SetUiIcons(false); break; - case Theme::SystemDark: - ui->setThemeSystemDark->setChecked(true); - isIconBlack = false; - SetUiIcons(false); - break; - case Theme::SystemLight: - ui->setThemeLight->setChecked(true); - isIconBlack = true; + case Theme::System: + ui->setThemeSystem->setChecked(true); + 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 = true) { + isIconBlack = false; + SetUiIcons(false); + } else if (isSystemDarkMode = false) { + isIconBlack = true; + SetUiIcons(true); + } break; } } diff --git a/src/qt_gui/main_window_themes.cpp b/src/qt_gui/main_window_themes.cpp index 00cf59591..645b0a734 100644 --- a/src/qt_gui/main_window_themes.cpp +++ b/src/qt_gui/main_window_themes.cpp @@ -151,16 +151,7 @@ void WindowThemes::SetWindowTheme(Theme theme, QLineEdit* mw_searchbar) { themePalette.setColor(QPalette::HighlightedText, Qt::black); qApp->setPalette(themePalette); break; - case Theme::SystemDark: - mw_searchbar->setStyleSheet("QLineEdit {" - "border: 1px solid;" - "border-radius: 4px; padding: 5px; }" - "QLineEdit:focus {" - "border: 1px solid; }"); - qApp->setPalette(s_system_palette); - qApp->setStyleSheet(QString()); - break; - case Theme::SystemLight: + case Theme::System: mw_searchbar->setStyleSheet("QLineEdit {" "border: 1px solid;" "border-radius: 4px; padding: 5px; }" diff --git a/src/qt_gui/main_window_themes.h b/src/qt_gui/main_window_themes.h index 1cdd89e77..d60cadb6d 100644 --- a/src/qt_gui/main_window_themes.h +++ b/src/qt_gui/main_window_themes.h @@ -9,7 +9,7 @@ #include #include -enum class Theme : int { Dark, Light, Green, Blue, Violet, Gruvbox, SystemDark, SystemLight }; +enum class Theme : int { Dark, Light, Green, Blue, Violet, Gruvbox, System }; class WindowThemes : public QObject { Q_OBJECT diff --git a/src/qt_gui/main_window_ui.h b/src/qt_gui/main_window_ui.h index 9723c9012..5f261ef55 100644 --- a/src/qt_gui/main_window_ui.h +++ b/src/qt_gui/main_window_ui.h @@ -37,8 +37,7 @@ public: QAction* setThemeBlue; QAction* setThemeViolet; QAction* setThemeGruvbox; - QAction* setThemeSystemDark; - QAction* setThemeSystemLight; + QAction* setThemeSystem; QWidget* centralWidget; QLineEdit* mw_searchbar; QPushButton* playButton; @@ -164,12 +163,9 @@ public: setThemeGruvbox = new QAction(MainWindow); setThemeGruvbox->setObjectName("setThemeGruvbox"); setThemeGruvbox->setCheckable(true); - setThemeSystemDark = new QAction(MainWindow); - setThemeSystemDark->setObjectName("setThemeSystemDark"); - setThemeSystemDark->setCheckable(true); - setThemeSystemLight = new QAction(MainWindow); - setThemeSystemLight->setObjectName("setThemeSystemLight"); - setThemeSystemLight->setCheckable(true); + setThemeSystem = new QAction(MainWindow); + setThemeSystem->setObjectName("setThemeSystem"); + setThemeSystem->setCheckable(true); centralWidget = new QWidget(MainWindow); centralWidget->setObjectName("centralWidget"); sizePolicy.setHeightForWidth(centralWidget->sizePolicy().hasHeightForWidth()); @@ -295,8 +291,7 @@ public: menuThemes->addAction(setThemeBlue); menuThemes->addAction(setThemeViolet); menuThemes->addAction(setThemeGruvbox); - menuThemes->addAction(setThemeSystemDark); - menuThemes->addAction(setThemeSystemLight); + menuThemes->addAction(setThemeSystem); menuGame_List_Icons->addAction(setIconSizeTinyAct); menuGame_List_Icons->addAction(setIconSizeSmallAct); menuGame_List_Icons->addAction(setIconSizeMediumAct); @@ -384,10 +379,8 @@ public: setThemeBlue->setText(QCoreApplication::translate("MainWindow", "Blue", nullptr)); setThemeViolet->setText(QCoreApplication::translate("MainWindow", "Violet", nullptr)); setThemeGruvbox->setText("Gruvbox"); - setThemeSystemDark->setText( - QCoreApplication::translate("MainWindow", "System (Dark)", nullptr)); - setThemeSystemLight->setText( - QCoreApplication::translate("MainWindow", "System (Light)", nullptr)); + setThemeSystem->setText( + QCoreApplication::translate("MainWindow", "System", nullptr)); toolBar->setWindowTitle(QCoreApplication::translate("MainWindow", "toolBar", nullptr)); } // retranslateUi };