Merge pull request #454 from RedsonBr140/menu-themes

This commit is contained in:
flow 2022-11-17 09:47:55 -08:00 committed by GitHub
commit 5cf2a8b5fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 1 deletions

View File

@ -49,7 +49,7 @@
#include <QKeyEvent> #include <QKeyEvent>
#include <QAction> #include <QAction>
#include <QActionGroup>
#include <QApplication> #include <QApplication>
#include <QButtonGroup> #include <QButtonGroup>
#include <QHBoxLayout> #include <QHBoxLayout>
@ -106,6 +106,7 @@
#include "ui/dialogs/UpdateDialog.h" #include "ui/dialogs/UpdateDialog.h"
#include "ui/dialogs/EditAccountDialog.h" #include "ui/dialogs/EditAccountDialog.h"
#include "ui/dialogs/ExportInstanceDialog.h" #include "ui/dialogs/ExportInstanceDialog.h"
#include "ui/themes/ITheme.h"
#include "UpdateController.h" #include "UpdateController.h"
#include "KonamiCode.h" #include "KonamiCode.h"
@ -268,6 +269,8 @@ public:
TranslatedAction actionLockToolbars; TranslatedAction actionLockToolbars;
TranslatedAction actionChangeTheme;
QVector<TranslatedToolButton *> all_toolbuttons; QVector<TranslatedToolButton *> all_toolbuttons;
QWidget *centralWidget = nullptr; QWidget *centralWidget = nullptr;
@ -440,6 +443,11 @@ public:
actionLockToolbars.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Lock Toolbars")); actionLockToolbars.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Lock Toolbars"));
actionLockToolbars->setCheckable(true); actionLockToolbars->setCheckable(true);
all_actions.append(&actionLockToolbars); 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) void createMainToolbar(QMainWindow *MainWindow)
@ -544,6 +552,8 @@ public:
viewMenu = menuBar->addMenu(tr("&View")); viewMenu = menuBar->addMenu(tr("&View"));
viewMenu->setSeparatorsCollapsible(false); viewMenu->setSeparatorsCollapsible(false);
viewMenu->addAction(actionChangeTheme);
viewMenu->addSeparator();
viewMenu->addAction(actionCAT); viewMenu->addAction(actionCAT);
viewMenu->addSeparator(); viewMenu->addSeparator();
@ -841,6 +851,7 @@ public:
createInstanceToolbar(MainWindow); createInstanceToolbar(MainWindow);
MainWindow->updateToolsMenu(); MainWindow->updateToolsMenu();
MainWindow->updateThemeMenu();
retranslateUi(MainWindow); retranslateUi(MainWindow);
@ -1290,6 +1301,38 @@ void MainWindow::updateToolsMenu()
ui->actionLaunchInstance->setMenu(launchMenu); ui->actionLaunchInstance->setMenu(launchMenu);
} }
void MainWindow::updateThemeMenu()
{
QMenu *themeMenu = ui->actionChangeTheme->menu();
if (themeMenu) {
themeMenu->clear();
} else {
themeMenu = new QMenu(this);
}
auto themes = APPLICATION->getValidApplicationThemes();
QActionGroup* themesGroup = new QActionGroup( this );
for (auto* theme : themes) {
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]() {
APPLICATION->setApplicationTheme(theme->id(),false);
APPLICATION->settings()->set("ApplicationTheme", theme->id());
});
}
ui->actionChangeTheme->setMenu(themeMenu);
}
void MainWindow::repopulateAccountsMenu() void MainWindow::repopulateAccountsMenu()
{ {
accountMenu->clear(); accountMenu->clear();
@ -1920,6 +1963,7 @@ void MainWindow::globalSettingsClosed()
proxymodel->sort(0); proxymodel->sort(0);
updateMainToolBar(); updateMainToolBar();
updateToolsMenu(); updateToolsMenu();
updateThemeMenu();
updateStatusCenter(); updateStatusCenter();
// This needs to be done to prevent UI elements disappearing in the event the config is changed // 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: // but Prism Launcher exits abnormally, causing the window state to never be saved:

View File

@ -174,6 +174,8 @@ private slots:
void updateToolsMenu(); void updateToolsMenu();
void updateThemeMenu();
void instanceActivated(QModelIndex); void instanceActivated(QModelIndex);
void instanceChanged(const QModelIndex &current, const QModelIndex &previous); void instanceChanged(const QModelIndex &current, const QModelIndex &previous);