all repos — mgba @ c39162732d966e379c68a11fed6371276c3f9eb5

mGBA Game Boy Advance Emulator

src/platform/qt/SettingsView.cpp (view raw)

  1/* Copyright (c) 2013-2014 Jeffrey Pfau
  2 *
  3 * This Source Code Form is subject to the terms of the Mozilla Public
  4 * License, v. 2.0. If a copy of the MPL was not distributed with this
  5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6#include "SettingsView.h"
  7
  8#include "AudioProcessor.h"
  9#include "ConfigController.h"
 10#include "Display.h"
 11#include "GBAApp.h"
 12
 13using namespace QGBA;
 14
 15SettingsView::SettingsView(ConfigController* controller, QWidget* parent)
 16	: QDialog(parent)
 17	, m_controller(controller)
 18{
 19	m_ui.setupUi(this);
 20
 21	loadSetting("bios", m_ui.bios);
 22	loadSetting("useBios", m_ui.useBios);
 23	loadSetting("skipBios", m_ui.skipBios);
 24	loadSetting("audioBuffers", m_ui.audioBufferSize);
 25	loadSetting("sampleRate", m_ui.sampleRate);
 26	loadSetting("videoSync", m_ui.videoSync);
 27	loadSetting("audioSync", m_ui.audioSync);
 28	loadSetting("frameskip", m_ui.frameskip);
 29	loadSetting("fpsTarget", m_ui.fpsTarget);
 30	loadSetting("lockAspectRatio", m_ui.lockAspectRatio);
 31	loadSetting("volume", m_ui.volume);
 32	loadSetting("mute", m_ui.mute);
 33	loadSetting("rewindEnable", m_ui.rewind);
 34	loadSetting("rewindBufferInterval", m_ui.rewindInterval);
 35	loadSetting("rewindBufferCapacity", m_ui.rewindCapacity);
 36	loadSetting("resampleVideo", m_ui.resampleVideo);
 37	loadSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
 38	loadSetting("suspendScreensaver", m_ui.suspendScreensaver);
 39
 40	double fastForwardRatio = loadSetting("fastForwardRatio").toDouble();
 41	if (fastForwardRatio <= 0) {
 42		m_ui.fastForwardUnbounded->setChecked(true);
 43		m_ui.fastForwardRatio->setEnabled(false);
 44	} else {
 45		m_ui.fastForwardUnbounded->setChecked(false);
 46		m_ui.fastForwardRatio->setEnabled(true);
 47		m_ui.fastForwardRatio->setValue(fastForwardRatio);
 48	}
 49	connect(m_ui.fastForwardUnbounded, &QAbstractButton::toggled, [this](bool checked) {
 50		m_ui.fastForwardRatio->setEnabled(!checked);
 51	});
 52
 53	QString idleOptimization = loadSetting("idleOptimization");
 54	if (idleOptimization == "ignore") {
 55		m_ui.idleOptimization->setCurrentIndex(0);
 56	} else if (idleOptimization == "remove") {
 57		m_ui.idleOptimization->setCurrentIndex(1);
 58	} else if (idleOptimization == "detect") {
 59		m_ui.idleOptimization->setCurrentIndex(2);
 60	}
 61
 62	QVariant audioDriver = m_controller->getQtOption("audioDriver");
 63#ifdef BUILD_QT_MULTIMEDIA
 64	m_ui.audioDriver->addItem(tr("Qt Multimedia"), static_cast<int>(AudioProcessor::Driver::QT_MULTIMEDIA));
 65	if (!audioDriver.isNull() && audioDriver.toInt() == static_cast<int>(AudioProcessor::Driver::QT_MULTIMEDIA)) {
 66		m_ui.audioDriver->setCurrentIndex(m_ui.audioDriver->count() - 1);
 67	}
 68#endif
 69
 70#ifdef BUILD_SDL
 71	m_ui.audioDriver->addItem(tr("SDL"), static_cast<int>(AudioProcessor::Driver::SDL));
 72	if (audioDriver.isNull() || audioDriver.toInt() == static_cast<int>(AudioProcessor::Driver::SDL)) {
 73		m_ui.audioDriver->setCurrentIndex(m_ui.audioDriver->count() - 1);
 74	}
 75#endif
 76
 77	QVariant displayDriver = m_controller->getQtOption("displayDriver");
 78	m_ui.displayDriver->addItem(tr("Software (Qt)"), static_cast<int>(Display::Driver::QT));
 79	if (!displayDriver.isNull() && displayDriver.toInt() == static_cast<int>(Display::Driver::QT)) {
 80		m_ui.displayDriver->setCurrentIndex(m_ui.displayDriver->count() - 1);
 81	}
 82
 83#ifdef BUILD_GL
 84	m_ui.displayDriver->addItem(tr("OpenGL"), static_cast<int>(Display::Driver::OPENGL));
 85	if (displayDriver.isNull() || displayDriver.toInt() == static_cast<int>(Display::Driver::OPENGL)) {
 86		m_ui.displayDriver->setCurrentIndex(m_ui.displayDriver->count() - 1);
 87	}
 88#endif
 89
 90	connect(m_ui.biosBrowse, SIGNAL(clicked()), this, SLOT(selectBios()));
 91	connect(m_ui.buttonBox, SIGNAL(accepted()), this, SLOT(updateConfig()));
 92}
 93
 94void SettingsView::selectBios() {
 95	QString filename = GBAApp::app()->getOpenFileName(this, tr("Select BIOS"));
 96	if (!filename.isEmpty()) {
 97		m_ui.bios->setText(filename);
 98	}
 99}
100
101void SettingsView::updateConfig() {
102	saveSetting("bios", m_ui.bios);
103	saveSetting("useBios", m_ui.useBios);
104	saveSetting("skipBios", m_ui.skipBios);
105	saveSetting("audioBuffers", m_ui.audioBufferSize);
106	saveSetting("sampleRate", m_ui.sampleRate);
107	saveSetting("videoSync", m_ui.videoSync);
108	saveSetting("audioSync", m_ui.audioSync);
109	saveSetting("frameskip", m_ui.frameskip);
110	saveSetting("fpsTarget", m_ui.fpsTarget);
111	saveSetting("lockAspectRatio", m_ui.lockAspectRatio);
112	saveSetting("volume", m_ui.volume);
113	saveSetting("mute", m_ui.mute);
114	saveSetting("rewindEnable", m_ui.rewind);
115	saveSetting("rewindBufferInterval", m_ui.rewindInterval);
116	saveSetting("rewindBufferCapacity", m_ui.rewindCapacity);
117	saveSetting("resampleVideo", m_ui.resampleVideo);
118	saveSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
119	saveSetting("suspendScreensaver", m_ui.suspendScreensaver);
120
121	if (m_ui.fastForwardUnbounded->isChecked()) {
122		saveSetting("fastForwardRatio", "-1");
123	} else {
124		saveSetting("fastForwardRatio", m_ui.fastForwardRatio);
125	}
126
127	switch (m_ui.idleOptimization->currentIndex() + IDLE_LOOP_IGNORE) {
128	case IDLE_LOOP_IGNORE:
129		saveSetting("idleOptimization", "ignore");
130		break;
131	case IDLE_LOOP_REMOVE:
132		saveSetting("idleOptimization", "remove");
133		break;
134	case IDLE_LOOP_DETECT:
135		saveSetting("idleOptimization", "detect");
136		break;
137	}
138
139	QVariant audioDriver = m_ui.audioDriver->itemData(m_ui.audioDriver->currentIndex());
140	if (audioDriver != m_controller->getQtOption("audioDriver")) {
141		m_controller->setQtOption("audioDriver", audioDriver);
142		AudioProcessor::setDriver(static_cast<AudioProcessor::Driver>(audioDriver.toInt()));
143		emit audioDriverChanged();
144	}
145
146	QVariant displayDriver = m_ui.displayDriver->itemData(m_ui.displayDriver->currentIndex());
147	if (displayDriver != m_controller->getQtOption("displayDriver")) {
148		m_controller->setQtOption("displayDriver", displayDriver);
149		Display::setDriver(static_cast<Display::Driver>(displayDriver.toInt()));
150		emit displayDriverChanged();
151	}
152
153	m_controller->write();
154
155	emit biosLoaded(m_ui.bios->text());
156}
157
158void SettingsView::saveSetting(const char* key, const QAbstractButton* field) {
159	m_controller->setOption(key, field->isChecked());
160	m_controller->updateOption(key);
161}
162
163void SettingsView::saveSetting(const char* key, const QComboBox* field) {
164	saveSetting(key, field->lineEdit());
165}
166
167void SettingsView::saveSetting(const char* key, const QDoubleSpinBox* field) {
168	saveSetting(key, field->value());
169}
170
171void SettingsView::saveSetting(const char* key, const QLineEdit* field) {
172	saveSetting(key, field->text());
173}
174
175void SettingsView::saveSetting(const char* key, const QSlider* field) {
176	saveSetting(key, field->value());
177}
178
179void SettingsView::saveSetting(const char* key, const QSpinBox* field) {
180	saveSetting(key, field->value());
181}
182
183void SettingsView::saveSetting(const char* key, const QVariant& field) {
184	m_controller->setOption(key, field);
185	m_controller->updateOption(key);
186}
187
188void SettingsView::loadSetting(const char* key, QAbstractButton* field) {
189	QString option = loadSetting(key);
190	field->setChecked(!option.isNull() && option != "0");
191}
192
193void SettingsView::loadSetting(const char* key, QComboBox* field) {
194	loadSetting(key, field->lineEdit());
195}
196
197void SettingsView::loadSetting(const char* key, QDoubleSpinBox* field) {
198	QString option = loadSetting(key);
199	field->setValue(option.toDouble());
200}
201
202void SettingsView::loadSetting(const char* key, QLineEdit* field) {
203	QString option = loadSetting(key);
204	field->setText(option);
205}
206
207void SettingsView::loadSetting(const char* key, QSlider* field) {
208	QString option = loadSetting(key);
209	field->setValue(option.toInt());
210}
211
212void SettingsView::loadSetting(const char* key, QSpinBox* field) {
213	QString option = loadSetting(key);
214	field->setValue(option.toInt());
215}
216
217QString SettingsView::loadSetting(const char* key) {
218	return m_controller->getOption(key);
219}