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