mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-26 07:35:41 +00:00
Qt: Hook up console settings
This commit is contained in:
parent
62e1829ec9
commit
77a47c87d2
|
@ -1,8 +1,17 @@
|
|||
#include "consolesettingswidget.h"
|
||||
#include "settingwidgetbinder.h"
|
||||
|
||||
ConsoleSettingsWidget::ConsoleSettingsWidget(QWidget* parent /*= nullptr*/) : QWidget(parent)
|
||||
ConsoleSettingsWidget::ConsoleSettingsWidget(QtHostInterface* host_interface, QWidget* parent /* = nullptr */)
|
||||
: QWidget(parent), m_host_interface(host_interface)
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
|
||||
SettingWidgetBinder::BindWidgetToSetting(m_host_interface, m_ui.region, &Settings::region);
|
||||
SettingWidgetBinder::BindWidgetToSetting(m_host_interface, m_ui.biosPath, &Settings::bios_path);
|
||||
SettingWidgetBinder::BindWidgetToSetting(m_host_interface, m_ui.enableTTYOutput, &Settings::bios_patch_tty_enable);
|
||||
SettingWidgetBinder::BindWidgetToSetting(m_host_interface, m_ui.fastBoot, &Settings::bios_patch_fast_boot);
|
||||
SettingWidgetBinder::BindWidgetToSetting(m_host_interface, m_ui.enableSpeedLimiter, &Settings::speed_limiter_enabled);
|
||||
SettingWidgetBinder::BindWidgetToSetting(m_host_interface, m_ui.pauseOnStart, &Settings::start_paused);
|
||||
}
|
||||
|
||||
ConsoleSettingsWidget::~ConsoleSettingsWidget() = default;
|
||||
|
|
|
@ -4,14 +4,18 @@
|
|||
|
||||
#include "ui_consolesettingswidget.h"
|
||||
|
||||
class QtHostInterface;
|
||||
|
||||
class ConsoleSettingsWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConsoleSettingsWidget(QWidget* parent = nullptr);
|
||||
explicit ConsoleSettingsWidget(QtHostInterface* host_interface, QWidget* parent = nullptr);
|
||||
~ConsoleSettingsWidget();
|
||||
|
||||
private:
|
||||
Ui::ConsoleSettingsWidget m_ui;
|
||||
|
||||
QtHostInterface* m_host_interface;
|
||||
};
|
||||
|
|
|
@ -41,12 +41,12 @@
|
|||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>NTSC-U (US)</string>
|
||||
<string>NTSC-J (Japan)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>NTSC-J (Japan)</string>
|
||||
<string>NTSC-U (US)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
<ClCompile Include="settingsdialog.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="settingwidgetbinder.h" />
|
||||
<QtMoc Include="consolesettingswidget.h" />
|
||||
<QtMoc Include="gamelistsettingswidget.h" />
|
||||
<QtMoc Include="gamelistwidget.h" />
|
||||
|
|
|
@ -11,30 +11,41 @@
|
|||
<ClCompile Include="gamelistsettingswidget.cpp" />
|
||||
<ClCompile Include="qtsettingsinterface.cpp" />
|
||||
<ClCompile Include="qtutils.cpp" />
|
||||
<ClCompile Include="$(IntDir)moc_consolesettingswidget.cpp" />
|
||||
<ClCompile Include="$(IntDir)moc_gamelistsettingswidget.cpp" />
|
||||
<ClCompile Include="$(IntDir)moc_gamelistwidget.cpp" />
|
||||
<ClCompile Include="$(IntDir)moc_mainwindow.cpp" />
|
||||
<ClCompile Include="$(IntDir)moc_opengldisplaywindow.cpp" />
|
||||
<ClCompile Include="$(IntDir)moc_qthostinterface.cpp" />
|
||||
<ClCompile Include="$(IntDir)moc_settingsdialog.cpp" />
|
||||
<ClCompile Include="$(IntDir)qrc_icons.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="mainwindow.h" />
|
||||
<ClInclude Include="gamelistwidget.h" />
|
||||
<ClInclude Include="settingsdialog.h" />
|
||||
<ClInclude Include="consolesettingswidget.h" />
|
||||
<ClInclude Include="opengldisplaywindow.h" />
|
||||
<ClInclude Include="qthostinterface.h" />
|
||||
<ClInclude Include="gamelistsettingswidget.h" />
|
||||
<ClInclude Include="qtsettingsinterface.h" />
|
||||
<ClInclude Include="qtutils.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="consolesettingswidget.ui" />
|
||||
<None Include="gamelistsettingswidget.ui" />
|
||||
<None Include="mainwindow.ui" />
|
||||
<None Include="settingsdialog.ui" />
|
||||
<None Include="resources\icons.qrc">
|
||||
<Filter>resources</Filter>
|
||||
</None>
|
||||
<ClInclude Include="settingwidgetbinder.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="resources">
|
||||
<UniqueIdentifier>{3b2587ae-ce3b-4eb5-ada2-237e853620cf}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtResource Include="resources\icons.qrc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtMoc Include="consolesettingswidget.h" />
|
||||
<QtMoc Include="gamelistsettingswidget.h" />
|
||||
<QtMoc Include="gamelistwidget.h" />
|
||||
<QtMoc Include="mainwindow.h" />
|
||||
<QtMoc Include="opengldisplaywindow.h" />
|
||||
<QtMoc Include="qthostinterface.h" />
|
||||
<QtMoc Include="settingsdialog.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtUi Include="consolesettingswidget.ui" />
|
||||
<QtUi Include="gamelistsettingswidget.ui" />
|
||||
<QtUi Include="mainwindow.ui" />
|
||||
<QtUi Include="settingsdialog.ui" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -36,10 +36,15 @@ void QtHostInterface::ReportMessage(const char* message)
|
|||
|
||||
void QtHostInterface::setDefaultSettings()
|
||||
{
|
||||
QtSettingsInterface si(m_qsettings);
|
||||
m_settings.SetDefaults();
|
||||
updateQSettings();
|
||||
}
|
||||
|
||||
void QtHostInterface::updateQSettings()
|
||||
{
|
||||
QtSettingsInterface si(m_qsettings);
|
||||
m_settings.Save(si);
|
||||
m_qsettings.sync();
|
||||
// m_qsettings.sync();
|
||||
}
|
||||
|
||||
void QtHostInterface::applySettings()
|
||||
|
@ -69,6 +74,8 @@ void QtHostInterface::checkSettings()
|
|||
m_qsettings.setValue(settings_version_key, expected_version);
|
||||
setDefaultSettings();
|
||||
}
|
||||
|
||||
applySettings();
|
||||
}
|
||||
|
||||
void QtHostInterface::createGameList()
|
||||
|
|
|
@ -25,8 +25,13 @@ public:
|
|||
const QSettings& getQSettings() const { return m_qsettings; }
|
||||
QSettings& getQSettings() { return m_qsettings; }
|
||||
void setDefaultSettings();
|
||||
void updateQSettings();
|
||||
void applySettings();
|
||||
|
||||
const Settings& GetCoreSettings() const { return m_settings; }
|
||||
Settings& GetCoreSettings() { return m_settings; }
|
||||
//void UpdateCoreSettingsGPU();
|
||||
|
||||
const GameList* getGameList() const { return m_game_list.get(); }
|
||||
GameList* getGameList() { return m_game_list.get(); }
|
||||
void updateGameListDatabase(bool refresh_list = true);
|
||||
|
|
|
@ -9,7 +9,7 @@ SettingsDialog::SettingsDialog(QtHostInterface* host_interface, QWidget* parent
|
|||
{
|
||||
m_ui.setupUi(this);
|
||||
|
||||
m_console_settings = new ConsoleSettingsWidget(m_ui.settingsContainer);
|
||||
m_console_settings = new ConsoleSettingsWidget(host_interface, m_ui.settingsContainer);
|
||||
m_game_list_settings = new GameListSettingsWidget(host_interface, m_ui.settingsContainer);
|
||||
m_cpu_settings = new QWidget(m_ui.settingsContainer);
|
||||
m_gpu_settings = new QWidget(m_ui.settingsContainer);
|
||||
|
|
|
@ -102,7 +102,7 @@
|
|||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults</set>
|
||||
<set>QDialogButtonBox::Close|QDialogButtonBox::RestoreDefaults</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
139
src/duckstation-qt/settingwidgetbinder.h
Normal file
139
src/duckstation-qt/settingwidgetbinder.h
Normal file
|
@ -0,0 +1,139 @@
|
|||
#pragma once
|
||||
#include <type_traits>
|
||||
|
||||
#include "core/settings.h"
|
||||
#include "qthostinterface.h"
|
||||
|
||||
#include <QtWidgets/QCheckBox>
|
||||
#include <QtWidgets/QComboBox>
|
||||
#include <QtWidgets/QLineEdit>
|
||||
|
||||
namespace SettingWidgetBinder {
|
||||
|
||||
template<typename T>
|
||||
struct SettingAccessor
|
||||
{
|
||||
static bool getBoolValue(const T* widget);
|
||||
static void setBoolValue(T* widget, bool value);
|
||||
|
||||
static int getIntValue(const T* widget);
|
||||
static void setIntValue(T* widget, int value);
|
||||
|
||||
static QString getStringValue(const T* widget);
|
||||
static void setStringValue(T* widget, const QString& value);
|
||||
|
||||
template<typename F>
|
||||
static void connectValueChanged(T* widget, F func);
|
||||
};
|
||||
|
||||
template<>
|
||||
struct SettingAccessor<QLineEdit>
|
||||
{
|
||||
static bool getBoolValue(const QLineEdit* widget) { return widget->text().toInt() != 0; }
|
||||
static void setBoolValue(QLineEdit* widget, bool value)
|
||||
{
|
||||
widget->setText(value ? QStringLiteral("1") : QStringLiteral("0"));
|
||||
}
|
||||
|
||||
static int getIntValue(const QLineEdit* widget) { return widget->text().toInt(); }
|
||||
static void setIntValue(QLineEdit* widget, int value) { widget->setText(QStringLiteral("%1").arg(value)); }
|
||||
|
||||
static QString getStringValue(const QLineEdit* widget) { return widget->text(); }
|
||||
static void setStringValue(QLineEdit* widget, const QString& value) { widget->setText(value); }
|
||||
|
||||
template<typename F>
|
||||
static void connectValueChanged(QLineEdit* widget, F func)
|
||||
{
|
||||
widget->connect(widget, &QLineEdit::textChanged, func);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct SettingAccessor<QComboBox>
|
||||
{
|
||||
static bool getBoolValue(const QComboBox* widget) { return widget->currentText() > 0; }
|
||||
static void setBoolValue(QComboBox* widget, bool value) { widget->setCurrentIndex(value ? 1 : 0); }
|
||||
|
||||
static int getIntValue(const QComboBox* widget) { return widget->currentIndex(); }
|
||||
static void setIntValue(QComboBox* widget, int value) { widget->setCurrentIndex(value); }
|
||||
|
||||
static QString getStringValue(const QComboBox* widget) { return widget->currentText(); }
|
||||
static void setStringValue(QComboBox* widget, const QString& value) { widget->setCurrentText(value); }
|
||||
|
||||
template<typename F>
|
||||
static void connectValueChanged(QComboBox* widget, F func)
|
||||
{
|
||||
widget->connect(widget, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), func);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct SettingAccessor<QCheckBox>
|
||||
{
|
||||
static bool getBoolValue(const QCheckBox* widget) { return widget->isChecked(); }
|
||||
static void setBoolValue(QCheckBox* widget, bool value) { widget->setChecked(value); }
|
||||
|
||||
static int getIntValue(const QCheckBox* widget) { return widget->isChecked() ? 1 : 0; }
|
||||
static void setIntValue(QCheckBox* widget, int value) { widget->setChecked(value != 0); }
|
||||
|
||||
static QString getStringValue(const QCheckBox* widget)
|
||||
{
|
||||
return widget->isChecked() ? QStringLiteral("1") : QStringLiteral("0");
|
||||
}
|
||||
static void setStringValue(QCheckBox* widget, const QString& value) { widget->setChecked(value.toInt() != 0); }
|
||||
|
||||
template<typename F>
|
||||
static void connectValueChanged(QCheckBox* widget, F func)
|
||||
{
|
||||
widget->connect(widget, &QCheckBox::stateChanged, func);
|
||||
}
|
||||
};
|
||||
|
||||
/// Binds a widget's value to a setting, updating it when the value changes.
|
||||
// template<typename WidgetType, typename DataType, typename = void>
|
||||
// void BindWidgetToSetting(QtHostInterface* hi, WidgetType* widget, DataType Settings::*settings_ptr);
|
||||
|
||||
template<typename WidgetType>
|
||||
void BindWidgetToSetting(QtHostInterface* hi, WidgetType* widget, bool Settings::*settings_ptr)
|
||||
{
|
||||
using Accessor = SettingAccessor<WidgetType>;
|
||||
|
||||
Accessor::setBoolValue(widget, hi->GetCoreSettings().*settings_ptr);
|
||||
|
||||
Accessor::connectValueChanged(widget, [hi, widget, settings_ptr]() {
|
||||
(hi->GetCoreSettings().*settings_ptr) = Accessor::getBoolValue(widget);
|
||||
hi->updateQSettings();
|
||||
});
|
||||
}
|
||||
|
||||
template<typename WidgetType>
|
||||
void BindWidgetToSetting(QtHostInterface* hi, WidgetType* widget, std::string Settings::*settings_ptr)
|
||||
{
|
||||
using Accessor = SettingAccessor<WidgetType>;
|
||||
|
||||
Accessor::setStringValue(widget, QString::fromStdString(hi->GetCoreSettings().*settings_ptr));
|
||||
|
||||
Accessor::connectValueChanged(widget, [hi, widget, settings_ptr]() {
|
||||
const QString value = Accessor::getStringValue(widget);
|
||||
(hi->GetCoreSettings().*settings_ptr) = value.toStdString();
|
||||
hi->updateQSettings();
|
||||
});
|
||||
}
|
||||
|
||||
template<typename WidgetType, typename DataType>
|
||||
void BindWidgetToSetting(QtHostInterface* hi, WidgetType* widget, DataType Settings::*settings_ptr,
|
||||
std::enable_if_t<std::is_enum_v<DataType>, int>* v = nullptr)
|
||||
{
|
||||
using Accessor = SettingAccessor<WidgetType>;
|
||||
using UnderlyingType = std::underlying_type_t<DataType>;
|
||||
|
||||
Accessor::setIntValue(widget, static_cast<int>(static_cast<UnderlyingType>(hi->GetCoreSettings().*settings_ptr)));
|
||||
|
||||
Accessor::connectValueChanged(widget, [hi, widget, settings_ptr](int) {
|
||||
const int value = Accessor::getIntValue(widget);
|
||||
(hi->GetCoreSettings().*settings_ptr) = static_cast<DataType>(static_cast<UnderlyingType>(value));
|
||||
hi->updateQSettings();
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace SettingWidgetBinder
|
Loading…
Reference in a new issue