Allow the user to choose the UI theme
Mainly useful for those who want dark mode on Windows.
This commit is contained in:
parent
d48e5f2da0
commit
a7575ec7b3
|
@ -142,6 +142,7 @@ bool MouseHide;
|
||||||
int MouseHideSeconds;
|
int MouseHideSeconds;
|
||||||
|
|
||||||
bool PauseLostFocus;
|
bool PauseLostFocus;
|
||||||
|
std::string UITheme;
|
||||||
|
|
||||||
int64_t RTCOffset;
|
int64_t RTCOffset;
|
||||||
|
|
||||||
|
@ -344,6 +345,7 @@ ConfigEntry ConfigFile[] =
|
||||||
{"MouseHide", 1, &MouseHide, false, false},
|
{"MouseHide", 1, &MouseHide, false, false},
|
||||||
{"MouseHideSeconds", 0, &MouseHideSeconds, 5, false},
|
{"MouseHideSeconds", 0, &MouseHideSeconds, 5, false},
|
||||||
{"PauseLostFocus", 1, &PauseLostFocus, false, false},
|
{"PauseLostFocus", 1, &PauseLostFocus, false, false},
|
||||||
|
{"UITheme", 2, &UITheme, (std::string)"", false},
|
||||||
|
|
||||||
{"RTCOffset", 3, &RTCOffset, (int64_t)0, true},
|
{"RTCOffset", 3, &RTCOffset, (int64_t)0, true},
|
||||||
|
|
||||||
|
|
|
@ -185,6 +185,7 @@ extern bool EnableCheats;
|
||||||
extern bool MouseHide;
|
extern bool MouseHide;
|
||||||
extern int MouseHideSeconds;
|
extern int MouseHideSeconds;
|
||||||
extern bool PauseLostFocus;
|
extern bool PauseLostFocus;
|
||||||
|
extern std::string UITheme;
|
||||||
|
|
||||||
extern int64_t RTCOffset;
|
extern int64_t RTCOffset;
|
||||||
|
|
||||||
|
|
|
@ -16,15 +16,16 @@
|
||||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <QStyleFactory>
|
||||||
#include "InterfaceSettingsDialog.h"
|
#include "InterfaceSettingsDialog.h"
|
||||||
#include "ui_InterfaceSettingsDialog.h"
|
#include "ui_InterfaceSettingsDialog.h"
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "Platform.h"
|
#include "Platform.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
InterfaceSettingsDialog* InterfaceSettingsDialog::currentDlg = nullptr;
|
InterfaceSettingsDialog* InterfaceSettingsDialog::currentDlg = nullptr;
|
||||||
|
|
||||||
InterfaceSettingsDialog::InterfaceSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::InterfaceSettingsDialog)
|
InterfaceSettingsDialog::InterfaceSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::InterfaceSettingsDialog)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
@ -35,6 +36,18 @@ InterfaceSettingsDialog::InterfaceSettingsDialog(QWidget* parent) : QDialog(pare
|
||||||
ui->spinMouseHideSeconds->setValue(Config::MouseHideSeconds);
|
ui->spinMouseHideSeconds->setValue(Config::MouseHideSeconds);
|
||||||
ui->cbPauseLostFocus->setChecked(Config::PauseLostFocus != 0);
|
ui->cbPauseLostFocus->setChecked(Config::PauseLostFocus != 0);
|
||||||
ui->spinMaxFPS->setValue(Config::MaxFPS);
|
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()
|
InterfaceSettingsDialog::~InterfaceSettingsDialog()
|
||||||
|
@ -63,8 +76,16 @@ void InterfaceSettingsDialog::done(int r)
|
||||||
Config::PauseLostFocus = ui->cbPauseLostFocus->isChecked() ? 1:0;
|
Config::PauseLostFocus = ui->cbPauseLostFocus->isChecked() ? 1:0;
|
||||||
Config::MaxFPS = ui->spinMaxFPS->value();
|
Config::MaxFPS = ui->spinMaxFPS->value();
|
||||||
|
|
||||||
|
QString themeName = ui->cbxUITheme->currentData().toString();
|
||||||
|
Config::UITheme = themeName.toStdString();
|
||||||
|
|
||||||
Config::Save();
|
Config::Save();
|
||||||
|
|
||||||
|
if (!Config::UITheme.empty())
|
||||||
|
qApp->setStyle(themeName);
|
||||||
|
else
|
||||||
|
qApp->setStyle(*systemThemeName);
|
||||||
|
|
||||||
emit updateMouseTimer();
|
emit updateMouseTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>337</width>
|
<width>337</width>
|
||||||
<height>233</height>
|
<height>275</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -20,12 +20,29 @@
|
||||||
<string>Interface settings - melonDS</string>
|
<string>Interface settings - melonDS</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0">
|
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0">
|
||||||
<item alignment="Qt::AlignTop">
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox">
|
<widget class="QGroupBox" name="groupBox">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Main window</string>
|
<string>User interface</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="text">
|
||||||
|
<string>Theme</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>cbxUITheme</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="cbxUITheme"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="cbMouseHide">
|
<widget class="QCheckBox" name="cbMouseHide">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|
|
@ -114,6 +114,7 @@ QStringList NdsRomExtensions { ".nds", ".srl", ".dsi", ".ids" };
|
||||||
QString GbaRomMimeType = "application/x-gba-rom";
|
QString GbaRomMimeType = "application/x-gba-rom";
|
||||||
QStringList GbaRomExtensions { ".gba", ".agb" };
|
QStringList GbaRomExtensions { ".gba", ".agb" };
|
||||||
|
|
||||||
|
QString* systemThemeName;
|
||||||
|
|
||||||
// This list of supported archive formats is based on libarchive(3) version 3.6.2 (2022-12-09).
|
// This list of supported archive formats is based on libarchive(3) version 3.6.2 (2022-12-09).
|
||||||
QStringList ArchiveMimeTypes
|
QStringList ArchiveMimeTypes
|
||||||
|
@ -292,6 +293,11 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
qputenv("QT_SCALE_FACTOR", "1");
|
qputenv("QT_SCALE_FACTOR", "1");
|
||||||
|
|
||||||
|
#if QT_VERSION_MAJOR == 6 && defined(__WIN32__)
|
||||||
|
// Allow using the system dark theme palette on Windows
|
||||||
|
qputenv("QT_QPA_PLATFORM", "windows:darkmode=2");
|
||||||
|
#endif
|
||||||
|
|
||||||
printf("melonDS " MELONDS_VERSION "\n");
|
printf("melonDS " MELONDS_VERSION "\n");
|
||||||
printf(MELONDS_URL "\n");
|
printf(MELONDS_URL "\n");
|
||||||
|
|
||||||
|
@ -360,6 +366,12 @@ int main(int argc, char** argv)
|
||||||
camManager[0]->setXFlip(Config::Camera[0].XFlip);
|
camManager[0]->setXFlip(Config::Camera[0].XFlip);
|
||||||
camManager[1]->setXFlip(Config::Camera[1].XFlip);
|
camManager[1]->setXFlip(Config::Camera[1].XFlip);
|
||||||
|
|
||||||
|
systemThemeName = new QString(QApplication::style()->objectName());
|
||||||
|
|
||||||
|
if (!Config::UITheme.empty())
|
||||||
|
{
|
||||||
|
QApplication::setStyle(QString::fromStdString(Config::UITheme));
|
||||||
|
}
|
||||||
|
|
||||||
Input::JoystickID = Config::JoystickID;
|
Input::JoystickID = Config::JoystickID;
|
||||||
Input::OpenJoystick();
|
Input::OpenJoystick();
|
||||||
|
|
|
@ -44,4 +44,6 @@ public:
|
||||||
bool event(QEvent* event) override;
|
bool event(QEvent* event) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern QString* systemThemeName;
|
||||||
|
|
||||||
#endif // MAIN_H
|
#endif // MAIN_H
|
||||||
|
|
Loading…
Reference in New Issue