From 2bc788beea2f58dba75f8160d79b91e0d0fb1f99 Mon Sep 17 00:00:00 2001 From: Rosalie Wanders Date: Sun, 22 Jan 2023 13:52:30 +0100 Subject: [PATCH] RMG: expose & use GUI_Theme setting --- .../UserInterface/Dialog/SettingsDialog.cpp | 104 ++------------ .../UserInterface/Dialog/SettingsDialog.hpp | 1 - .../UserInterface/Dialog/SettingsDialog.ui | 131 ++++-------------- Source/RMG/UserInterface/MainWindow.cpp | 74 ++++++---- 4 files changed, 93 insertions(+), 217 deletions(-) diff --git a/Source/RMG/UserInterface/Dialog/SettingsDialog.cpp b/Source/RMG/UserInterface/Dialog/SettingsDialog.cpp index 55be36c6..6041f765 100644 --- a/Source/RMG/UserInterface/Dialog/SettingsDialog.cpp +++ b/Source/RMG/UserInterface/Dialog/SettingsDialog.cpp @@ -71,10 +71,6 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent) #endif // !UPDATER #endif // !DISCORD_RPC -#ifndef _WIN32 - this->innerInterfaceTabWidget->removeTab(4); -#endif - int width = CoreSettingsGetIntValue(SettingsID::GUI_SettingsDialogWidth); int height = CoreSettingsGetIntValue(SettingsID::GUI_SettingsDialogHeight); @@ -109,7 +105,7 @@ int SettingsDialog::currentIndex(void) } else if (currentIndex > 0) { // above interface tab - index += this->innerInterfaceTabWidget->count() - 0; + index += this->innerInterfaceTabWidget->count() - 1; } if (currentIndex == 3) @@ -124,10 +120,8 @@ int SettingsDialog::currentIndex(void) return index; } -#include void SettingsDialog::restoreDefaults(int stackedWidgetIndex) { - std::cout << "restoreDefaults: " << stackedWidgetIndex << std::endl; switch (stackedWidgetIndex) { default: @@ -145,35 +139,30 @@ void SettingsDialog::restoreDefaults(int stackedWidgetIndex) this->loadDefaultInterfaceOSDSettings(); break; case 4: -#ifdef _WIN32 - this->loadDefaultInterfaceStyleSettings(); - break; -#endif // _WIN32 - case 5: this->loadDefaultInterfaceMiscSettings(); break; - case 6: + case 5: this->loadDefaultHotkeySettings(); break; - case 7: + case 6: this->loadDefaultCoreSettings(); break; - case 8: + case 7: this->loadDefaultGameSettings(); break; - case 9: + case 8: this->loadDefaultGameCoreSettings(); break; - case 10: + case 9: this->loadDefaultGamePluginSettings(); break; - case 11: + case 10: this->loadDefaultPluginSettings(); break; - case 12: + case 11: this->loadDefaultDirectorySettings(); break; - case 13: + case 12: this->loadDefault64DDSettings(); break; } @@ -426,13 +415,9 @@ void SettingsDialog::loadInterfaceOSDSettings(void) this->osdDurationSpinBox->setValue(CoreSettingsGetIntValue(SettingsID::GUI_OnScreenDisplayDuration)); } -void SettingsDialog::loadInterfaceStyleSettings(void) -{ - this->commonInterfaceStyleSettings(SettingsDialogAction::LoadSettings); -} - void SettingsDialog::loadInterfaceMiscSettings(void) { + this->themeComboBox->setCurrentText(QString::fromStdString(CoreSettingsGetStringValue(SettingsID::GUI_Theme))); #ifdef UPDATER this->checkForUpdatesCheckBox->setChecked(CoreSettingsGetBoolValue(SettingsID::GUI_CheckForUpdates)); #endif // UPDATER @@ -572,13 +557,9 @@ void SettingsDialog::loadDefaultInterfaceOSDSettings(void) this->osdDurationSpinBox->setValue(CoreSettingsGetDefaultIntValue(SettingsID::GUI_OnScreenDisplayDuration)); } -void SettingsDialog::loadDefaultInterfaceStyleSettings(void) -{ - this->commonInterfaceStyleSettings(SettingsDialogAction::LoadDefaultSettings); -} - void SettingsDialog::loadDefaultInterfaceMiscSettings(void) { + this->themeComboBox->setCurrentText(QString::fromStdString(CoreSettingsGetDefaultStringValue(SettingsID::GUI_Theme))); #ifdef UPDATER this->checkForUpdatesCheckBox->setChecked(CoreSettingsGetDefaultBoolValue(SettingsID::GUI_CheckForUpdates)); #endif // UPDATER @@ -606,7 +587,6 @@ void SettingsDialog::saveSettings(void) this->saveInterfaceRomBrowserSettings(); this->saveInterfaceLogSettings(); this->saveInterfaceOSDSettings(); - this->saveInterfaceStyleSettings(); this->saveInterfaceMiscSettings(); } @@ -780,16 +760,9 @@ void SettingsDialog::saveInterfaceOSDSettings(void) CoreSettingsSetValue(SettingsID::GUI_OnScreenDisplayDuration, this->osdDurationSpinBox->value()); } -void SettingsDialog::saveInterfaceStyleSettings(void) -{ -#ifdef _WIN32 - CoreSettingsSetValue(SettingsID::GUI_Style, this->styleComboBox->currentData().toString().toStdString()); - CoreSettingsSetValue(SettingsID::GUI_IconTheme, this->iconThemeComboBox->currentText().toStdString()); -#endif // _WIN32 -} - void SettingsDialog::saveInterfaceMiscSettings(void) { + CoreSettingsSetValue(SettingsID::GUI_Theme, this->themeComboBox->currentText().toStdString()); #ifdef UPDATER CoreSettingsSetValue(SettingsID::GUI_CheckForUpdates, this->checkForUpdatesCheckBox->isChecked()); #endif // UPDATER @@ -963,63 +936,12 @@ void SettingsDialog::commonPluginSettings(SettingsDialogAction action) } } -void SettingsDialog::commonInterfaceStyleSettings(SettingsDialogAction action) -{ -#ifdef _WIN32 - this->styleComboBox->clear(); - this->styleComboBox->addItem("None", ""); - - QString currentStyle = action == SettingsDialogAction::LoadSettings ? - QString::fromStdString(CoreSettingsGetStringValue(SettingsID::GUI_Style)) : - QString::fromStdString(CoreSettingsGetDefaultStringValue(SettingsID::GUI_Style)); - - QString directory; - directory = QString::fromStdString(CoreGetSharedDataDirectory().string()); - directory += "\\Styles\\"; - - QStringList filter; - filter << "*.qss"; - - bool styleFound = false; - QDirIterator stylesDirectoryIter(directory, filter, QDir::Files, QDirIterator::NoIteratorFlags); - while (stylesDirectoryIter.hasNext()) - { - QString filePath = stylesDirectoryIter.next(); - QFileInfo fileInfo(filePath); - - this->styleComboBox->addItem(fileInfo.baseName(), filePath); - if (filePath == currentStyle) - { - styleFound = true; - this->styleComboBox->setCurrentText(fileInfo.baseName()); - } - } - - if (currentStyle.isEmpty()) - { - this->styleComboBox->setCurrentText("None"); - styleFound = true; - } - - if (!styleFound) - { - this->styleComboBox->addItem("", ""); - this->styleComboBox->setCurrentText(""); - } - - QString currentIconTheme = action == SettingsDialogAction::LoadSettings ? - QString::fromStdString(CoreSettingsGetStringValue(SettingsID::GUI_IconTheme)) : - QString::fromStdString(CoreSettingsGetDefaultStringValue(SettingsID::GUI_IconTheme)); - this->iconThemeComboBox->setCurrentText(currentIconTheme); -#endif // _WIN32 -} - void SettingsDialog::setIconsForEmulationInfoText(void) { QLabel* labels[] = { this->infoIconLabel_0, this->infoIconLabel_1, this->infoIconLabel_2, this->infoIconLabel_3, this->infoIconLabel_4, this->infoIconLabel_5, - this->infoIconLabel_6, this->infoIconLabel_7 + this->infoIconLabel_7 }; QIcon infoIcon = QIcon::fromTheme("information-line"); diff --git a/Source/RMG/UserInterface/Dialog/SettingsDialog.hpp b/Source/RMG/UserInterface/Dialog/SettingsDialog.hpp index 6363eba7..584399d2 100644 --- a/Source/RMG/UserInterface/Dialog/SettingsDialog.hpp +++ b/Source/RMG/UserInterface/Dialog/SettingsDialog.hpp @@ -107,7 +107,6 @@ class SettingsDialog : public QDialog, private Ui::SettingsDialog void commonHotkeySettings(SettingsDialogAction); void commonPluginSettings(SettingsDialogAction); - void commonInterfaceStyleSettings(SettingsDialogAction); void setIconsForEmulationInfoText(void); void hideEmulationInfoText(void); diff --git a/Source/RMG/UserInterface/Dialog/SettingsDialog.ui b/Source/RMG/UserInterface/Dialog/SettingsDialog.ui index aa12c64d..25ad20b1 100644 --- a/Source/RMG/UserInterface/Dialog/SettingsDialog.ui +++ b/Source/RMG/UserInterface/Dialog/SettingsDialog.ui @@ -396,112 +396,41 @@ - - - Styles - - - - - - - - Custom Style - - - - - - - - - - - - - - Icon Theme - - - - - - - - white - - - - - black - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - 0 - 0 - - - - - - - :/newPrefix/Resource/Info.ico - - - false - - - - - - - - 0 - 0 - - - - 1 - - - Changes will be applied on next application run - - - Qt::PlainText - - - - - - - Miscellaneous + + + + + + Theme + + + + + + + + Native + + + + + Fusion + + + + + Fusion Dark + + + + + + diff --git a/Source/RMG/UserInterface/MainWindow.cpp b/Source/RMG/UserInterface/MainWindow.cpp index 2ac004ac..6c0a0f0e 100644 --- a/Source/RMG/UserInterface/MainWindow.cpp +++ b/Source/RMG/UserInterface/MainWindow.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -211,10 +212,57 @@ void MainWindow::configureTheme(QApplication* app) { // set theme style QString fallbackStyleSheet = "QTableView { border: none; color: #0096d3; selection-color: #FFFFFF; selection-background-color: #0096d3; }"; - -#ifndef _WIN32 this->setStyleSheet(fallbackStyleSheet); + // set application theme + QString theme = QString::fromStdString(CoreSettingsGetStringValue(SettingsID::GUI_Theme)); + if (theme == "Fusion") + { + app->setPalette(QApplication::style()->standardPalette()); + app->setStyleSheet(QString()); + app->setStyle(QStyleFactory::create("Fusion")); + } + else if (theme == "Fusion Dark") + { + // adapted from https://gist.github.com/QuantumCD/6245215 + app->setStyle(QStyleFactory::create("Fusion")); + + const QColor lighterGray(75, 75, 75); + const QColor darkGray(53, 53, 53); + const QColor gray(128, 128, 128); + const QColor black(25, 25, 25); + const QColor blue(198, 238, 255); + + QPalette darkPalette; + darkPalette.setColor(QPalette::Window, darkGray); + darkPalette.setColor(QPalette::WindowText, Qt::white); + darkPalette.setColor(QPalette::Base, black); + darkPalette.setColor(QPalette::AlternateBase, darkGray); + darkPalette.setColor(QPalette::ToolTipBase, darkGray); + darkPalette.setColor(QPalette::ToolTipText, Qt::white); + darkPalette.setColor(QPalette::Text, Qt::white); + darkPalette.setColor(QPalette::Button, darkGray); + darkPalette.setColor(QPalette::ButtonText, Qt::white); + darkPalette.setColor(QPalette::Link, blue); + darkPalette.setColor(QPalette::Highlight, lighterGray); + darkPalette.setColor(QPalette::HighlightedText, Qt::white); + darkPalette.setColor(QPalette::PlaceholderText, QColor(Qt::white).darker()); + + darkPalette.setColor(QPalette::Active, QPalette::Button, darkGray); + darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, gray); + darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, gray); + darkPalette.setColor(QPalette::Disabled, QPalette::Text, gray); + darkPalette.setColor(QPalette::Disabled, QPalette::Light, darkGray); + + app->setPalette(darkPalette); + + app->setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }"); + } + else if (theme == "Native") + { + // do nothing + } + // set icon theme QString fallbackThemeName = QIcon::themeName(); QPalette palette = app->palette(); @@ -223,28 +271,6 @@ void MainWindow::configureTheme(QApplication* app) // fallback for icons we don't provide (i.e standard system icons) QIcon::setFallbackThemeName(fallbackThemeName); -#else // _WIN32 - - // set icon theme - QIcon::setThemeName(QString::fromStdString(CoreSettingsGetStringValue(SettingsID::GUI_IconTheme))); - - QString styleFilePath = QString::fromStdString(CoreSettingsGetStringValue(SettingsID::GUI_Style)); - QFile styleFile(styleFilePath); - - if (styleFilePath.isEmpty() || !styleFile.exists()) - { - this->setStyleSheet(fallbackStyleSheet); - return; - } - - if (!styleFile.open(QIODevice::ReadOnly)) - { - this->setStyleSheet(fallbackStyleSheet); - return; - } - - app->setStyleSheet(styleFile.readAll()); -#endif // _WIN32 } void MainWindow::showErrorMessage(QString text, QString details = "")