From be765f8d883697d2284343f9ee6c858987622857 Mon Sep 17 00:00:00 2001 From: Redson Date: Mon, 14 Nov 2022 16:33:25 -0300 Subject: [PATCH 1/9] feat: Add empty menu Signed-off-by: Redson --- launcher/ui/MainWindow.cpp | 26 ++++++++++++++++++++++++++ launcher/ui/MainWindow.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 85b00b677..31d0f6c28 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -264,6 +264,8 @@ public: TranslatedAction actionLockToolbars; + TranslatedAction actionChangeTheme; + QVector all_toolbuttons; QWidget *centralWidget = nullptr; @@ -428,6 +430,11 @@ public: actionLockToolbars.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Lock Toolbars")); actionLockToolbars->setCheckable(true); all_actions.append(&actionLockToolbars); + + actionChangeTheme = TranslatedAction(MainWindow); + actionChangeTheme->setObjectName(QStringLiteral("actionChangeTheme")); + actionChangeTheme.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Themes")); + all_actions.append(&actionChangeTheme); } void createMainToolbar(QMainWindow *MainWindow) @@ -528,6 +535,8 @@ public: viewMenu = menuBar->addMenu(tr("&View")); viewMenu->setSeparatorsCollapsible(false); + viewMenu->addAction(actionChangeTheme); + viewMenu->addSeparator(); viewMenu->addAction(actionCAT); viewMenu->addSeparator(); @@ -822,6 +831,7 @@ public: createInstanceToolbar(MainWindow); MainWindow->updateToolsMenu(); + MainWindow->updateThemeMenu(); retranslateUi(MainWindow); @@ -1271,6 +1281,22 @@ void MainWindow::updateToolsMenu() ui->actionLaunchInstance->setMenu(launchMenu); } +void MainWindow::updateThemeMenu() +{ + QMenu *themeMenu = ui->actionChangeTheme->menu(); + + if (themeMenu) + { + themeMenu->clear(); + } + else + { + themeMenu = new QMenu(this); + } + + ui->actionChangeTheme->setMenu(themeMenu); +} + void MainWindow::repopulateAccountsMenu() { accountMenu->clear(); diff --git a/launcher/ui/MainWindow.h b/launcher/ui/MainWindow.h index f9d1f1c73..47e221b76 100644 --- a/launcher/ui/MainWindow.h +++ b/launcher/ui/MainWindow.h @@ -170,6 +170,8 @@ private slots: void updateToolsMenu(); + void updateThemeMenu(); + void instanceActivated(QModelIndex); void instanceChanged(const QModelIndex ¤t, const QModelIndex &previous); From 0e916244f03cd8bd296f6cc4fe2be34a745ecab4 Mon Sep 17 00:00:00 2001 From: leo78913 Date: Mon, 14 Nov 2022 19:59:26 -0300 Subject: [PATCH 2/9] feat: Add themes and their logic. Signed-off-by: leo78913 --- launcher/ui/MainWindow.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 8d5e0c83f..cbdb2b8f7 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -106,6 +106,7 @@ #include "ui/dialogs/UpdateDialog.h" #include "ui/dialogs/EditAccountDialog.h" #include "ui/dialogs/ExportInstanceDialog.h" +#include "ui/themes/ITheme.h" #include "UpdateController.h" #include "KonamiCode.h" @@ -1313,6 +1314,25 @@ void MainWindow::updateThemeMenu() themeMenu = new QMenu(this); } + auto themes = APPLICATION->getValidApplicationThemes(); + + QActionGroup* ThemesGroup = new QActionGroup( this ); + + for (int i = 0; i < themes.size(); i++) + { + + auto *theme = themes[i]; + QAction * themeAction = themeMenu->addAction(theme->name()); + + themeAction->setCheckable(true); + themeAction->setActionGroup(ThemesGroup); + + connect(themeAction, &QAction::triggered, [theme]() { + APPLICATION->setApplicationTheme(theme->name().toLower(),false); + + }); + } + ui->actionChangeTheme->setMenu(themeMenu); } From ef53455b6610844a633624fa172b7bf80310651c Mon Sep 17 00:00:00 2001 From: Redson Date: Tue, 15 Nov 2022 05:19:46 -0300 Subject: [PATCH 3/9] fix: Build on QT6 Signed-off-by: Redson --- launcher/ui/MainWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index cbdb2b8f7..a00fb4025 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -49,7 +49,7 @@ #include #include - +#include #include #include #include From aa3ea79f94887aedc91c52860d5a7b6557900a6f Mon Sep 17 00:00:00 2001 From: Redson Date: Tue, 15 Nov 2022 05:38:31 -0300 Subject: [PATCH 4/9] fix: Check the current theme box on startup. Signed-off-by: Redson --- launcher/ui/MainWindow.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index a00fb4025..f8a37596f 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -1305,12 +1305,9 @@ void MainWindow::updateThemeMenu() { QMenu *themeMenu = ui->actionChangeTheme->menu(); - if (themeMenu) - { + if (themeMenu) { themeMenu->clear(); - } - else - { + } else { themeMenu = new QMenu(this); } @@ -1320,11 +1317,13 @@ void MainWindow::updateThemeMenu() for (int i = 0; i < themes.size(); i++) { - auto *theme = themes[i]; QAction * themeAction = themeMenu->addAction(theme->name()); themeAction->setCheckable(true); + if (APPLICATION->settings()->get("ApplicationTheme").toString() == theme->id()) { + themeAction->setChecked(true); + } themeAction->setActionGroup(ThemesGroup); connect(themeAction, &QAction::triggered, [theme]() { From a12f892841399163fbc12e72c61c7ed6fae882cf Mon Sep 17 00:00:00 2001 From: Redson Date: Tue, 15 Nov 2022 05:46:24 -0300 Subject: [PATCH 5/9] fix: Check the box when the theme is changed via settings Signed-off-by: Redson --- launcher/ui/MainWindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index f8a37596f..e2ab3b466 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -1965,6 +1965,7 @@ void MainWindow::globalSettingsClosed() proxymodel->sort(0); updateMainToolBar(); updateToolsMenu(); + updateThemeMenu(); updateStatusCenter(); // This needs to be done to prevent UI elements disappearing in the event the config is changed // but Prism Launcher exits abnormally, causing the window state to never be saved: From 6fe626ab9ad9f76b793f09ceb5e8e8cced3f15ba Mon Sep 17 00:00:00 2001 From: Redson Date: Tue, 15 Nov 2022 06:09:13 -0300 Subject: [PATCH 6/9] feat: Make the changes persistent. Signed-off-by: Redson --- launcher/ui/MainWindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index e2ab3b466..f62d97601 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -1327,8 +1327,8 @@ void MainWindow::updateThemeMenu() themeAction->setActionGroup(ThemesGroup); connect(themeAction, &QAction::triggered, [theme]() { - APPLICATION->setApplicationTheme(theme->name().toLower(),false); - + APPLICATION->setApplicationTheme(theme->id(),false); + APPLICATION->settings()->set("ApplicationTheme", theme->id()); }); } From 37a117d2effc21b23b86ada80951bfd23671a64b Mon Sep 17 00:00:00 2001 From: RedsonBr140 Date: Wed, 16 Nov 2022 12:24:28 -0300 Subject: [PATCH 7/9] chore: Var definition inside the for loop Co-authored-by: flow Signed-off-by: RedsonBr140 --- launcher/ui/MainWindow.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index f62d97601..1f8444afa 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -1315,9 +1315,7 @@ void MainWindow::updateThemeMenu() QActionGroup* ThemesGroup = new QActionGroup( this ); - for (int i = 0; i < themes.size(); i++) - { - auto *theme = themes[i]; + for (auto* theme : themes) { QAction * themeAction = themeMenu->addAction(theme->name()); themeAction->setCheckable(true); From bd3a693e700bc0b1ea9bbc72631ccd13ba755277 Mon Sep 17 00:00:00 2001 From: RedsonBr140 Date: Thu, 17 Nov 2022 06:20:53 -0300 Subject: [PATCH 8/9] chore: Change var name Co-authored-by: Sefa Eyeoglu Signed-off-by: RedsonBr140 --- launcher/ui/MainWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 1f8444afa..dcf1be99d 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -1313,7 +1313,7 @@ void MainWindow::updateThemeMenu() auto themes = APPLICATION->getValidApplicationThemes(); - QActionGroup* ThemesGroup = new QActionGroup( this ); + QActionGroup* themesGroup = new QActionGroup( this ); for (auto* theme : themes) { QAction * themeAction = themeMenu->addAction(theme->name()); From f72ac94c111a788d197e78fd4e0433513965807a Mon Sep 17 00:00:00 2001 From: Redson Date: Thu, 17 Nov 2022 06:39:05 -0300 Subject: [PATCH 9/9] fix: Fix usage below Signed-off-by: Redson --- launcher/ui/MainWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index dcf1be99d..e1ea13d31 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -1322,7 +1322,7 @@ void MainWindow::updateThemeMenu() if (APPLICATION->settings()->get("ApplicationTheme").toString() == theme->id()) { themeAction->setChecked(true); } - themeAction->setActionGroup(ThemesGroup); + themeAction->setActionGroup(themesGroup); connect(themeAction, &QAction::triggered, [theme]() { APPLICATION->setApplicationTheme(theme->id(),false);