Allow the user to choose the UI theme

Mainly useful for those who want dark mode on Windows.
This commit is contained in:
Nadia Holmquist Pedersen
2024-02-07 20:12:23 +01:00
parent d48e5f2da0
commit a7575ec7b3
6 changed files with 59 additions and 4 deletions

View File

@ -16,15 +16,16 @@
with melonDS. If not, see http://www.gnu.org/licenses/.
*/
#include <QStyleFactory>
#include "InterfaceSettingsDialog.h"
#include "ui_InterfaceSettingsDialog.h"
#include "types.h"
#include "Platform.h"
#include "Config.h"
#include "main.h"
InterfaceSettingsDialog* InterfaceSettingsDialog::currentDlg = nullptr;
InterfaceSettingsDialog::InterfaceSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::InterfaceSettingsDialog)
{
ui->setupUi(this);
@ -35,6 +36,18 @@ InterfaceSettingsDialog::InterfaceSettingsDialog(QWidget* parent) : QDialog(pare
ui->spinMouseHideSeconds->setValue(Config::MouseHideSeconds);
ui->cbPauseLostFocus->setChecked(Config::PauseLostFocus != 0);
ui->spinMaxFPS->setValue(Config::MaxFPS);
const QList<QString> themeKeys = QStyleFactory::keys();
const QString currentTheme = qApp->style()->objectName();
ui->cbxUITheme->addItem("System default", "");
for (int i = 0; i < themeKeys.length(); i++)
{
ui->cbxUITheme->addItem(themeKeys[i], themeKeys[i]);
if (!Config::UITheme.empty() && themeKeys[i].compare(currentTheme, Qt::CaseInsensitive) == 0)
ui->cbxUITheme->setCurrentIndex(i + 1);
}
}
InterfaceSettingsDialog::~InterfaceSettingsDialog()
@ -63,8 +76,16 @@ void InterfaceSettingsDialog::done(int r)
Config::PauseLostFocus = ui->cbPauseLostFocus->isChecked() ? 1:0;
Config::MaxFPS = ui->spinMaxFPS->value();
QString themeName = ui->cbxUITheme->currentData().toString();
Config::UITheme = themeName.toStdString();
Config::Save();
if (!Config::UITheme.empty())
qApp->setStyle(themeName);
else
qApp->setStyle(*systemThemeName);
emit updateMouseTimer();
}