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#include "GBAKeyEditor.h"
13#include "InputController.h"
14#include "ShaderSelector.h"
15#include "ShortcutView.h"
16
17#include <mgba/core/serialize.h>
18#include <mgba/core/version.h>
19#include <mgba/internal/gba/gba.h>
20
21using namespace QGBA;
22
23#ifdef M_CORE_GB
24QList<enum GBModel> SettingsView::s_gbModelList;
25#endif
26
27SettingsView::SettingsView(ConfigController* controller, InputController* inputController, ShortcutController* shortcutController, QWidget* parent)
28 : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
29 , m_controller(controller)
30{
31 m_ui.setupUi(this);
32
33#ifdef M_CORE_GB
34 if (s_gbModelList.isEmpty()) {
35 // NB: Keep in sync with SettingsView.ui
36 s_gbModelList.append(GB_MODEL_AUTODETECT);
37 s_gbModelList.append(GB_MODEL_DMG);
38 s_gbModelList.append(GB_MODEL_SGB);
39 s_gbModelList.append(GB_MODEL_CGB);
40 s_gbModelList.append(GB_MODEL_AGB);
41 }
42#endif
43
44 reloadConfig();
45
46 if (m_ui.savegamePath->text().isEmpty()) {
47 m_ui.savegameSameDir->setChecked(true);
48 }
49 connect(m_ui.savegameSameDir, &QAbstractButton::toggled, [this] (bool e) {
50 if (e) {
51 m_ui.savegamePath->clear();
52 }
53 });
54 connect(m_ui.savegameBrowse, &QAbstractButton::pressed, [this] () {
55 QString path = GBAApp::app()->getOpenDirectoryName(this, "Select directory");
56 if (!path.isNull()) {
57 m_ui.savegameSameDir->setChecked(false);
58 m_ui.savegamePath->setText(path);
59 }
60 });
61
62 if (m_ui.savestatePath->text().isEmpty()) {
63 m_ui.savestateSameDir->setChecked(true);
64 }
65 connect(m_ui.savestateSameDir, &QAbstractButton::toggled, [this] (bool e) {
66 if (e) {
67 m_ui.savestatePath->clear();
68 }
69 });
70 connect(m_ui.savestateBrowse, &QAbstractButton::pressed, [this] () {
71 QString path = GBAApp::app()->getOpenDirectoryName(this, "Select directory");
72 if (!path.isNull()) {
73 m_ui.savestateSameDir->setChecked(false);
74 m_ui.savestatePath->setText(path);
75 }
76 });
77
78 if (m_ui.screenshotPath->text().isEmpty()) {
79 m_ui.screenshotSameDir->setChecked(true);
80 }
81 connect(m_ui.screenshotSameDir, &QAbstractButton::toggled, [this] (bool e) {
82 if (e) {
83 m_ui.screenshotPath->clear();
84 }
85 });
86 connect(m_ui.screenshotBrowse, &QAbstractButton::pressed, [this] () {
87 QString path = GBAApp::app()->getOpenDirectoryName(this, "Select directory");
88 if (!path.isNull()) {
89 m_ui.screenshotSameDir->setChecked(false);
90 m_ui.screenshotPath->setText(path);
91 }
92 });
93
94 if (m_ui.patchPath->text().isEmpty()) {
95 m_ui.patchSameDir->setChecked(true);
96 }
97 connect(m_ui.patchSameDir, &QAbstractButton::toggled, [this] (bool e) {
98 if (e) {
99 m_ui.patchPath->clear();
100 }
101 });
102 connect(m_ui.patchBrowse, &QAbstractButton::pressed, [this] () {
103 QString path = GBAApp::app()->getOpenDirectoryName(this, "Select directory");
104 if (!path.isNull()) {
105 m_ui.patchSameDir->setChecked(false);
106 m_ui.patchPath->setText(path);
107 }
108 });
109 connect(m_ui.clearCache, &QAbstractButton::pressed, this, &SettingsView::libraryCleared);
110
111 // TODO: Move to reloadConfig()
112 QVariant audioDriver = m_controller->getQtOption("audioDriver");
113#ifdef BUILD_QT_MULTIMEDIA
114 m_ui.audioDriver->addItem(tr("Qt Multimedia"), static_cast<int>(AudioProcessor::Driver::QT_MULTIMEDIA));
115 if (!audioDriver.isNull() && audioDriver.toInt() == static_cast<int>(AudioProcessor::Driver::QT_MULTIMEDIA)) {
116 m_ui.audioDriver->setCurrentIndex(m_ui.audioDriver->count() - 1);
117 }
118#endif
119
120#ifdef BUILD_SDL
121 m_ui.audioDriver->addItem(tr("SDL"), static_cast<int>(AudioProcessor::Driver::SDL));
122 if (audioDriver.isNull() || audioDriver.toInt() == static_cast<int>(AudioProcessor::Driver::SDL)) {
123 m_ui.audioDriver->setCurrentIndex(m_ui.audioDriver->count() - 1);
124 }
125#endif
126
127 // TODO: Move to reloadConfig()
128 QVariant displayDriver = m_controller->getQtOption("displayDriver");
129 m_ui.displayDriver->addItem(tr("Software (Qt)"), static_cast<int>(Display::Driver::QT));
130 if (!displayDriver.isNull() && displayDriver.toInt() == static_cast<int>(Display::Driver::QT)) {
131 m_ui.displayDriver->setCurrentIndex(m_ui.displayDriver->count() - 1);
132 }
133
134#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
135 m_ui.displayDriver->addItem(tr("OpenGL"), static_cast<int>(Display::Driver::OPENGL));
136 if (displayDriver.isNull() || displayDriver.toInt() == static_cast<int>(Display::Driver::OPENGL)) {
137 m_ui.displayDriver->setCurrentIndex(m_ui.displayDriver->count() - 1);
138 }
139#endif
140
141#ifdef BUILD_GL
142 m_ui.displayDriver->addItem(tr("OpenGL (force version 1.x)"), static_cast<int>(Display::Driver::OPENGL1));
143 if (!displayDriver.isNull() && displayDriver.toInt() == static_cast<int>(Display::Driver::OPENGL1)) {
144 m_ui.displayDriver->setCurrentIndex(m_ui.displayDriver->count() - 1);
145 }
146#endif
147
148 // TODO: Move to reloadConfig()
149 QVariant cameraDriver = m_controller->getQtOption("cameraDriver");
150 m_ui.cameraDriver->addItem(tr("None (Still Image)"), static_cast<int>(InputController::CameraDriver::NONE));
151 if (cameraDriver.isNull() || cameraDriver.toInt() == static_cast<int>(InputController::CameraDriver::NONE)) {
152 m_ui.cameraDriver->setCurrentIndex(m_ui.cameraDriver->count() - 1);
153 }
154
155#ifdef BUILD_QT_MULTIMEDIA
156 m_ui.cameraDriver->addItem(tr("Qt Multimedia"), static_cast<int>(InputController::CameraDriver::QT_MULTIMEDIA));
157 if (!cameraDriver.isNull() && cameraDriver.toInt() == static_cast<int>(InputController::CameraDriver::QT_MULTIMEDIA)) {
158 m_ui.cameraDriver->setCurrentIndex(m_ui.cameraDriver->count() - 1);
159 }
160#endif
161
162#ifdef M_CORE_GBA
163 connect(m_ui.gbaBiosBrowse, &QPushButton::clicked, [this]() {
164 selectBios(m_ui.gbaBios);
165 });
166#else
167 m_ui.gbaBiosBrowse->hide();
168#endif
169
170#ifdef M_CORE_GB
171 connect(m_ui.gbBiosBrowse, &QPushButton::clicked, [this]() {
172 selectBios(m_ui.gbBios);
173 });
174 connect(m_ui.gbcBiosBrowse, &QPushButton::clicked, [this]() {
175 selectBios(m_ui.gbcBios);
176 });
177 connect(m_ui.sgbBiosBrowse, &QPushButton::clicked, [this]() {
178 selectBios(m_ui.sgbBios);
179 });
180
181 QList<QColor> defaultColors;
182 defaultColors.append(QColor(0xF8, 0xF8, 0xF8));
183 defaultColors.append(QColor(0xA8, 0xA8, 0xA8));
184 defaultColors.append(QColor(0x50, 0x50, 0x50));
185 defaultColors.append(QColor(0x00, 0x00, 0x00));
186 bool ok;
187 if (m_controller->getOption("gb.pal[0]").toUInt(&ok) || ok) {
188 defaultColors[0] = QColor::fromRgb(m_controller->getOption("gb.pal[0]").toUInt());
189 }
190 if (m_controller->getOption("gb.pal[1]").toUInt(&ok) || ok) {
191 defaultColors[1] = QColor::fromRgb(m_controller->getOption("gb.pal[1]").toUInt());
192 }
193 if (m_controller->getOption("gb.pal[2]").toUInt(&ok) || ok) {
194 defaultColors[2] = QColor::fromRgb(m_controller->getOption("gb.pal[2]").toUInt());
195 }
196 if (m_controller->getOption("gb.pal[3]").toUInt(&ok) || ok) {
197 defaultColors[3] = QColor::fromRgb(m_controller->getOption("gb.pal[3]").toUInt());
198 }
199 m_colorPickers[0] = ColorPicker(m_ui.color0, defaultColors[0]);
200 m_colorPickers[1] = ColorPicker(m_ui.color1, defaultColors[1]);
201 m_colorPickers[2] = ColorPicker(m_ui.color2, defaultColors[2]);
202 m_colorPickers[3] = ColorPicker(m_ui.color3, defaultColors[3]);
203 for (int colorId = 0; colorId < 4; ++colorId) {
204 connect(&m_colorPickers[colorId], &ColorPicker::colorChanged, this, [this, colorId](const QColor& color) {
205 m_gbColors[colorId] = color.rgb();
206 });
207 }
208#else
209 m_ui.gbBiosBrowse->hide();
210 m_ui.gbcBiosBrowse->hide();
211 m_ui.sgbBiosBrowse->hide();
212 m_ui.gb->hide();
213#endif
214
215 GBAKeyEditor* editor = new GBAKeyEditor(inputController, InputController::KEYBOARD, QString(), this);
216 m_ui.stackedWidget->addWidget(editor);
217 m_ui.tabs->addItem(tr("Keyboard"));
218 connect(m_ui.buttonBox, &QDialogButtonBox::accepted, editor, &GBAKeyEditor::save);
219
220 GBAKeyEditor* buttonEditor = nullptr;
221#ifdef BUILD_SDL
222 inputController->recalibrateAxes();
223 const char* profile = inputController->profileForType(SDL_BINDING_BUTTON);
224 buttonEditor = new GBAKeyEditor(inputController, SDL_BINDING_BUTTON, profile);
225 m_ui.stackedWidget->addWidget(buttonEditor);
226 m_ui.tabs->addItem(tr("Controllers"));
227 connect(m_ui.buttonBox, &QDialogButtonBox::accepted, buttonEditor, &GBAKeyEditor::save);
228#endif
229
230 connect(m_ui.buttonBox, &QDialogButtonBox::accepted, this, &SettingsView::updateConfig);
231 connect(m_ui.buttonBox, &QDialogButtonBox::clicked, [this, editor, buttonEditor](QAbstractButton* button) {
232 if (m_ui.buttonBox->buttonRole(button) == QDialogButtonBox::ApplyRole) {
233 updateConfig();
234 editor->save();
235 if (buttonEditor) {
236 buttonEditor->save();
237 }
238 }
239 });
240
241 m_ui.languages->setItemData(0, QLocale("en"));
242 QDir ts(":/translations/");
243 for (auto name : ts.entryList()) {
244 if (!name.endsWith(".qm") || !name.startsWith(binaryName)) {
245 continue;
246 }
247 QLocale locale(name.remove(QString("%0-").arg(binaryName)).remove(".qm"));
248 m_ui.languages->addItem(locale.nativeLanguageName(), locale);
249 if (locale == QLocale()) {
250 m_ui.languages->setCurrentIndex(m_ui.languages->count() - 1);
251 }
252 }
253
254 ShortcutView* shortcutView = new ShortcutView();
255 shortcutView->setController(shortcutController);
256 shortcutView->setInputController(inputController);
257 m_ui.stackedWidget->addWidget(shortcutView);
258 m_ui.tabs->addItem(tr("Shortcuts"));
259}
260
261SettingsView::~SettingsView() {
262#if defined(BUILD_GL) || defined(BUILD_GLES)
263 setShaderSelector(nullptr);
264#endif
265}
266
267void SettingsView::setShaderSelector(ShaderSelector* shaderSelector) {
268#if defined(BUILD_GL) || defined(BUILD_GLES)
269 if (m_shader) {
270 auto items = m_ui.tabs->findItems(tr("Shaders"), Qt::MatchFixedString);
271 for (const auto& item : items) {
272 m_ui.tabs->removeItemWidget(item);
273 }
274 m_ui.stackedWidget->removeWidget(m_shader);
275 m_shader->setParent(nullptr);
276 }
277 m_shader = shaderSelector;
278 if (shaderSelector) {
279 m_ui.stackedWidget->addWidget(m_shader);
280 m_ui.tabs->addItem(tr("Shaders"));
281 connect(m_ui.buttonBox, &QDialogButtonBox::accepted, m_shader, &ShaderSelector::saved);
282 }
283#endif
284}
285
286void SettingsView::selectBios(QLineEdit* bios) {
287 QString filename = GBAApp::app()->getOpenFileName(this, tr("Select BIOS"));
288 if (!filename.isEmpty()) {
289 bios->setText(filename);
290 }
291}
292
293void SettingsView::updateConfig() {
294 saveSetting("gba.bios", m_ui.gbaBios);
295 saveSetting("gb.bios", m_ui.gbBios);
296 saveSetting("gbc.bios", m_ui.gbcBios);
297 saveSetting("sgb.bios", m_ui.sgbBios);
298 saveSetting("useBios", m_ui.useBios);
299 saveSetting("skipBios", m_ui.skipBios);
300 saveSetting("audioBuffers", m_ui.audioBufferSize);
301 saveSetting("sampleRate", m_ui.sampleRate);
302 saveSetting("videoSync", m_ui.videoSync);
303 saveSetting("audioSync", m_ui.audioSync);
304 saveSetting("frameskip", m_ui.frameskip);
305 saveSetting("fpsTarget", m_ui.fpsTarget);
306 saveSetting("autofireThreshold", m_ui.autofireThreshold);
307 saveSetting("lockAspectRatio", m_ui.lockAspectRatio);
308 saveSetting("lockIntegerScaling", m_ui.lockIntegerScaling);
309 saveSetting("volume", m_ui.volume);
310 saveSetting("mute", m_ui.mute);
311 saveSetting("rewindEnable", m_ui.rewind);
312 saveSetting("rewindBufferCapacity", m_ui.rewindCapacity);
313 saveSetting("rewindSave", m_ui.rewindSave);
314 saveSetting("resampleVideo", m_ui.resampleVideo);
315 saveSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
316 saveSetting("suspendScreensaver", m_ui.suspendScreensaver);
317 saveSetting("pauseOnFocusLost", m_ui.pauseOnFocusLost);
318 saveSetting("savegamePath", m_ui.savegamePath);
319 saveSetting("savestatePath", m_ui.savestatePath);
320 saveSetting("screenshotPath", m_ui.screenshotPath);
321 saveSetting("patchPath", m_ui.patchPath);
322 saveSetting("libraryStyle", m_ui.libraryStyle->currentIndex());
323 saveSetting("showLibrary", m_ui.showLibrary);
324 saveSetting("preload", m_ui.preload);
325
326 if (m_ui.fastForwardUnbounded->isChecked()) {
327 saveSetting("fastForwardRatio", "-1");
328 } else {
329 saveSetting("fastForwardRatio", m_ui.fastForwardRatio);
330 }
331
332 switch (m_ui.idleOptimization->currentIndex() + IDLE_LOOP_IGNORE) {
333 case IDLE_LOOP_IGNORE:
334 saveSetting("idleOptimization", "ignore");
335 break;
336 case IDLE_LOOP_REMOVE:
337 saveSetting("idleOptimization", "remove");
338 break;
339 case IDLE_LOOP_DETECT:
340 saveSetting("idleOptimization", "detect");
341 break;
342 }
343
344 int loadState = SAVESTATE_RTC;
345 loadState |= m_ui.loadStateScreenshot->isChecked() ? SAVESTATE_SCREENSHOT : 0;
346 loadState |= m_ui.loadStateSave->isChecked() ? SAVESTATE_SAVEDATA : 0;
347 loadState |= m_ui.loadStateCheats->isChecked() ? SAVESTATE_CHEATS : 0;
348 saveSetting("loadStateExtdata", loadState);
349
350 int saveState = SAVESTATE_RTC | SAVESTATE_METADATA;
351 saveState |= m_ui.saveStateScreenshot->isChecked() ? SAVESTATE_SCREENSHOT : 0;
352 saveState |= m_ui.saveStateSave->isChecked() ? SAVESTATE_SAVEDATA : 0;
353 saveState |= m_ui.saveStateCheats->isChecked() ? SAVESTATE_CHEATS : 0;
354 saveSetting("saveStateExtdata", saveState);
355
356 QVariant audioDriver = m_ui.audioDriver->itemData(m_ui.audioDriver->currentIndex());
357 if (audioDriver != m_controller->getQtOption("audioDriver")) {
358 m_controller->setQtOption("audioDriver", audioDriver);
359 AudioProcessor::setDriver(static_cast<AudioProcessor::Driver>(audioDriver.toInt()));
360 emit audioDriverChanged();
361 }
362
363 QVariant displayDriver = m_ui.displayDriver->itemData(m_ui.displayDriver->currentIndex());
364 if (displayDriver != m_controller->getQtOption("displayDriver")) {
365 m_controller->setQtOption("displayDriver", displayDriver);
366 Display::setDriver(static_cast<Display::Driver>(displayDriver.toInt()));
367 setShaderSelector(nullptr);
368 emit displayDriverChanged();
369 }
370
371 QVariant cameraDriver = m_ui.cameraDriver->itemData(m_ui.cameraDriver->currentIndex());
372 if (cameraDriver != m_controller->getQtOption("cameraDriver")) {
373 m_controller->setQtOption("cameraDriver", cameraDriver);
374 emit cameraDriverChanged();
375 }
376
377 QLocale language = m_ui.languages->itemData(m_ui.languages->currentIndex()).toLocale();
378 if (language != m_controller->getQtOption("language").toLocale() && !(language.bcp47Name() == QLocale::system().bcp47Name() && m_controller->getQtOption("language").isNull())) {
379 m_controller->setQtOption("language", language.bcp47Name());
380 emit languageChanged();
381 }
382
383#ifdef M_CORE_GB
384 GBModel modelGB = s_gbModelList[m_ui.gbModel->currentIndex()];
385 m_controller->setOption("gb.model", GBModelToName(modelGB));
386
387 GBModel modelSGB = s_gbModelList[m_ui.sgbModel->currentIndex()];
388 m_controller->setOption("sgb.model", GBModelToName(modelSGB));
389
390 GBModel modelCGB = s_gbModelList[m_ui.cgbModel->currentIndex()];
391 m_controller->setOption("cgb.model", GBModelToName(modelCGB));
392
393 if (m_gbColors[0] | m_gbColors[1] | m_gbColors[2] | m_gbColors[3]) {
394 m_controller->setOption("gb.pal[0]", m_gbColors[0]);
395 m_controller->setOption("gb.pal[1]", m_gbColors[1]);
396 m_controller->setOption("gb.pal[2]", m_gbColors[2]);
397 m_controller->setOption("gb.pal[3]", m_gbColors[3]);
398 }
399#endif
400
401 m_controller->write();
402
403 emit pathsChanged();
404 emit biosLoaded(PLATFORM_GBA, m_ui.gbaBios->text());
405}
406
407void SettingsView::reloadConfig() {
408 loadSetting("bios", m_ui.gbaBios);
409 loadSetting("gba.bios", m_ui.gbaBios);
410 loadSetting("gb.bios", m_ui.gbBios);
411 loadSetting("gbc.bios", m_ui.gbcBios);
412 loadSetting("sgb.bios", m_ui.sgbBios);
413 loadSetting("useBios", m_ui.useBios);
414 loadSetting("skipBios", m_ui.skipBios);
415 loadSetting("audioBuffers", m_ui.audioBufferSize);
416 loadSetting("sampleRate", m_ui.sampleRate);
417 loadSetting("videoSync", m_ui.videoSync);
418 loadSetting("audioSync", m_ui.audioSync);
419 loadSetting("frameskip", m_ui.frameskip);
420 loadSetting("fpsTarget", m_ui.fpsTarget);
421 loadSetting("autofireThreshold", m_ui.autofireThreshold);
422 loadSetting("lockAspectRatio", m_ui.lockAspectRatio);
423 loadSetting("lockIntegerScaling", m_ui.lockIntegerScaling);
424 loadSetting("volume", m_ui.volume);
425 loadSetting("mute", m_ui.mute);
426 loadSetting("rewindEnable", m_ui.rewind);
427 loadSetting("rewindBufferCapacity", m_ui.rewindCapacity);
428 loadSetting("rewindSave", m_ui.rewindSave);
429 loadSetting("resampleVideo", m_ui.resampleVideo);
430 loadSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
431 loadSetting("suspendScreensaver", m_ui.suspendScreensaver);
432 loadSetting("pauseOnFocusLost", m_ui.pauseOnFocusLost);
433 loadSetting("savegamePath", m_ui.savegamePath);
434 loadSetting("savestatePath", m_ui.savestatePath);
435 loadSetting("screenshotPath", m_ui.screenshotPath);
436 loadSetting("patchPath", m_ui.patchPath);
437 loadSetting("showLibrary", m_ui.showLibrary);
438 loadSetting("preload", m_ui.preload);
439
440 m_ui.libraryStyle->setCurrentIndex(loadSetting("libraryStyle").toInt());
441
442 double fastForwardRatio = loadSetting("fastForwardRatio").toDouble();
443 if (fastForwardRatio <= 0) {
444 m_ui.fastForwardUnbounded->setChecked(true);
445 m_ui.fastForwardRatio->setEnabled(false);
446 } else {
447 m_ui.fastForwardUnbounded->setChecked(false);
448 m_ui.fastForwardRatio->setEnabled(true);
449 m_ui.fastForwardRatio->setValue(fastForwardRatio);
450 }
451
452 QString idleOptimization = loadSetting("idleOptimization");
453 if (idleOptimization == "ignore") {
454 m_ui.idleOptimization->setCurrentIndex(0);
455 } else if (idleOptimization == "remove") {
456 m_ui.idleOptimization->setCurrentIndex(1);
457 } else if (idleOptimization == "detect") {
458 m_ui.idleOptimization->setCurrentIndex(2);
459 }
460
461 bool ok;
462 int loadState = loadSetting("loadStateExtdata").toInt(&ok);
463 if (!ok) {
464 loadState = SAVESTATE_SCREENSHOT | SAVESTATE_RTC;
465 }
466 m_ui.loadStateScreenshot->setChecked(loadState & SAVESTATE_SCREENSHOT);
467 m_ui.loadStateSave->setChecked(loadState & SAVESTATE_SAVEDATA);
468 m_ui.loadStateCheats->setChecked(loadState & SAVESTATE_CHEATS);
469
470 int saveState = loadSetting("saveStateExtdata").toInt(&ok);
471 if (!ok) {
472 saveState = SAVESTATE_SCREENSHOT | SAVESTATE_SAVEDATA | SAVESTATE_CHEATS | SAVESTATE_RTC | SAVESTATE_METADATA;
473 }
474 m_ui.saveStateScreenshot->setChecked(saveState & SAVESTATE_SCREENSHOT);
475 m_ui.saveStateSave->setChecked(saveState & SAVESTATE_SAVEDATA);
476 m_ui.saveStateCheats->setChecked(saveState & SAVESTATE_CHEATS);
477
478#ifdef M_CORE_GB
479 QString modelGB = m_controller->getOption("gb.model");
480 if (!modelGB.isNull()) {
481 GBModel model = GBNameToModel(modelGB.toUtf8().constData());
482 int index = s_gbModelList.indexOf(model);
483 m_ui.gbModel->setCurrentIndex(index >= 0 ? index : 0);
484 }
485
486 QString modelSGB = m_controller->getOption("sgb.model");
487 if (!modelSGB.isNull()) {
488 GBModel model = GBNameToModel(modelSGB.toUtf8().constData());
489 int index = s_gbModelList.indexOf(model);
490 m_ui.sgbModel->setCurrentIndex(index >= 0 ? index : 0);
491 }
492
493 QString modelCGB = m_controller->getOption("cgb.model");
494 if (!modelCGB.isNull()) {
495 GBModel model = GBNameToModel(modelCGB.toUtf8().constData());
496 int index = s_gbModelList.indexOf(model);
497 m_ui.cgbModel->setCurrentIndex(index >= 0 ? index : 0);
498 }
499#endif
500}
501
502void SettingsView::saveSetting(const char* key, const QAbstractButton* field) {
503 m_controller->setOption(key, field->isChecked());
504 m_controller->updateOption(key);
505}
506
507void SettingsView::saveSetting(const char* key, const QComboBox* field) {
508 saveSetting(key, field->lineEdit());
509}
510
511void SettingsView::saveSetting(const char* key, const QDoubleSpinBox* field) {
512 saveSetting(key, field->value());
513}
514
515void SettingsView::saveSetting(const char* key, const QLineEdit* field) {
516 saveSetting(key, field->text());
517}
518
519void SettingsView::saveSetting(const char* key, const QSlider* field) {
520 saveSetting(key, field->value());
521}
522
523void SettingsView::saveSetting(const char* key, const QSpinBox* field) {
524 saveSetting(key, field->value());
525}
526
527void SettingsView::saveSetting(const char* key, const QVariant& field) {
528 m_controller->setOption(key, field);
529 m_controller->updateOption(key);
530}
531
532void SettingsView::loadSetting(const char* key, QAbstractButton* field) {
533 QString option = loadSetting(key);
534 field->setChecked(!option.isNull() && option != "0");
535}
536
537void SettingsView::loadSetting(const char* key, QComboBox* field) {
538 loadSetting(key, field->lineEdit());
539}
540
541void SettingsView::loadSetting(const char* key, QDoubleSpinBox* field) {
542 QString option = loadSetting(key);
543 field->setValue(option.toDouble());
544}
545
546void SettingsView::loadSetting(const char* key, QLineEdit* field) {
547 QString option = loadSetting(key);
548 field->setText(option);
549}
550
551void SettingsView::loadSetting(const char* key, QSlider* field) {
552 QString option = loadSetting(key);
553 field->setValue(option.toInt());
554}
555
556void SettingsView::loadSetting(const char* key, QSpinBox* field) {
557 QString option = loadSetting(key);
558 field->setValue(option.toInt());
559}
560
561QString SettingsView::loadSetting(const char* key) {
562 return m_controller->getOption(key);
563}