mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-20 12:39:13 +12:00
Add infrastructure for Qt settings window
This commit is contained in:
parent
d010d95e18
commit
ba049fc1c7
4 changed files with 34 additions and 3 deletions
|
@ -1,16 +1,23 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QCheckBox>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
|
#include <functional>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "config.hpp"
|
||||||
|
|
||||||
class ConfigWindow : public QDialog {
|
class ConfigWindow : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
using ConfigCallback = std::function<void()>;
|
||||||
|
|
||||||
enum class Theme : int {
|
enum class Theme : int {
|
||||||
System = 0,
|
System = 0,
|
||||||
Light = 1,
|
Light = 1,
|
||||||
|
@ -21,9 +28,15 @@ class ConfigWindow : public QDialog {
|
||||||
Theme currentTheme;
|
Theme currentTheme;
|
||||||
QComboBox* themeSelect = nullptr;
|
QComboBox* themeSelect = nullptr;
|
||||||
|
|
||||||
|
// The config class holds a copy of the emulator config which it edits and sends
|
||||||
|
// over to the emulator
|
||||||
|
EmulatorConfig config;
|
||||||
|
ConfigCallback updateConfig;
|
||||||
void setTheme(Theme theme);
|
void setTheme(Theme theme);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ConfigWindow(QWidget* parent = nullptr);
|
ConfigWindow(ConfigCallback callback, const EmulatorConfig& config, QWidget* parent = nullptr);
|
||||||
~ConfigWindow();
|
~ConfigWindow();
|
||||||
|
|
||||||
|
EmulatorConfig& getConfig() { return config; }
|
||||||
};
|
};
|
|
@ -44,6 +44,7 @@ class MainWindow : public QMainWindow {
|
||||||
EditCheat,
|
EditCheat,
|
||||||
PressTouchscreen,
|
PressTouchscreen,
|
||||||
ReleaseTouchscreen,
|
ReleaseTouchscreen,
|
||||||
|
UpdateConfig
|
||||||
};
|
};
|
||||||
|
|
||||||
// Tagged union representing our message queue messages
|
// Tagged union representing our message queue messages
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#include "panda_qt/config_window.hpp"
|
#include "panda_qt/config_window.hpp"
|
||||||
|
|
||||||
ConfigWindow::ConfigWindow(QWidget* parent) : QDialog(parent) {
|
ConfigWindow::ConfigWindow(ConfigCallback callback, const EmulatorConfig& emuConfig, QWidget* parent) : QDialog(parent), config(emuConfig) {
|
||||||
setWindowTitle(tr("Configuration"));
|
setWindowTitle(tr("Configuration"));
|
||||||
|
updateConfig = std::move(callback);
|
||||||
|
|
||||||
// Set up theme selection
|
// Set up theme selection
|
||||||
setTheme(Theme::Dark);
|
setTheme(Theme::Dark);
|
||||||
|
@ -15,6 +16,14 @@ ConfigWindow::ConfigWindow(QWidget* parent) : QDialog(parent) {
|
||||||
themeSelect->setGeometry(40, 40, 100, 50);
|
themeSelect->setGeometry(40, 40, 100, 50);
|
||||||
themeSelect->show();
|
themeSelect->show();
|
||||||
connect(themeSelect, &QComboBox::currentIndexChanged, this, [&](int index) { setTheme(static_cast<Theme>(index)); });
|
connect(themeSelect, &QComboBox::currentIndexChanged, this, [&](int index) { setTheme(static_cast<Theme>(index)); });
|
||||||
|
|
||||||
|
QCheckBox* useShaderJIT = new QCheckBox(tr("Enable Shader recompiler"), this);
|
||||||
|
useShaderJIT->setChecked(config.shaderJitEnabled);
|
||||||
|
|
||||||
|
connect(useShaderJIT, &QCheckBox::toggled, this, [this, useShaderJIT]() {
|
||||||
|
config.shaderJitEnabled = useShaderJIT->isChecked();
|
||||||
|
updateConfig();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigWindow::setTheme(Theme theme) {
|
void ConfigWindow::setTheme(Theme theme) {
|
||||||
|
|
|
@ -64,7 +64,14 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
|
||||||
|
|
||||||
// Set up misc objects
|
// Set up misc objects
|
||||||
aboutWindow = new AboutWindow(nullptr);
|
aboutWindow = new AboutWindow(nullptr);
|
||||||
configWindow = new ConfigWindow(this);
|
configWindow = new ConfigWindow(
|
||||||
|
[&]() {
|
||||||
|
EmulatorMessage message{.type = MessageType::UpdateConfig};
|
||||||
|
sendMessage(message);
|
||||||
|
},
|
||||||
|
emu->getConfig(), this
|
||||||
|
);
|
||||||
|
|
||||||
cheatsEditor = new CheatsWindow(emu, {}, this);
|
cheatsEditor = new CheatsWindow(emu, {}, this);
|
||||||
luaEditor = new TextEditorWindow(this, "script.lua", "");
|
luaEditor = new TextEditorWindow(this, "script.lua", "");
|
||||||
|
|
||||||
|
@ -282,6 +289,7 @@ void MainWindow::dispatchMessage(const EmulatorMessage& message) {
|
||||||
emu->getServiceManager().getHID().setTouchScreenPress(message.touchscreen.x, message.touchscreen.y);
|
emu->getServiceManager().getHID().setTouchScreenPress(message.touchscreen.x, message.touchscreen.y);
|
||||||
break;
|
break;
|
||||||
case MessageType::ReleaseTouchscreen: emu->getServiceManager().getHID().releaseTouchScreen(); break;
|
case MessageType::ReleaseTouchscreen: emu->getServiceManager().getHID().releaseTouchScreen(); break;
|
||||||
|
case MessageType::UpdateConfig: emu->getConfig() = configWindow->getConfig(); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue