RMG: expose & use GUI_Theme setting

This commit is contained in:
Rosalie Wanders
2023-01-22 13:52:30 +01:00
parent 4a0d20c1a1
commit 2bc788beea
4 changed files with 93 additions and 217 deletions
@@ -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 <iostream>
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");
@@ -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);
+30 -101
View File
@@ -396,112 +396,41 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_4">
<attribute name="title">
<string>Styles</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Custom Style</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="styleComboBox"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Icon Theme</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="iconThemeComboBox">
<item>
<property name="text">
<string>white</string>
</property>
</item>
<item>
<property name="text">
<string>black</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_9">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="emulationInfoLayout_4">
<item>
<widget class="QLabel" name="infoIconLabel_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap>:/newPrefix/Resource/Info.ico</pixmap>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_89">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="midLineWidth">
<number>1</number>
</property>
<property name="text">
<string>Changes will be applied on next application run</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string>Miscellaneous</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<widget class="QLabel" name="label_12">
<property name="text">
<string>Theme</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="themeComboBox">
<item>
<property name="text">
<string>Native</string>
</property>
</item>
<item>
<property name="text">
<string>Fusion</string>
</property>
</item>
<item>
<property name="text">
<string>Fusion Dark</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkForUpdatesCheckBox">
<property name="text">
+50 -24
View File
@@ -25,6 +25,7 @@
#include <QCoreApplication>
#include <QDesktopServices>
#include <QStyleFactory>
#include <QFileDialog>
#include <QMenuBar>
#include <QMessageBox>
@@ -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 = "")