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 "ConfigController.h"
9
10#include <QFileDialog>
11
12using namespace QGBA;
13
14SettingsView::SettingsView(ConfigController* controller, QWidget* parent)
15 : QWidget(parent)
16 , m_controller(controller)
17{
18 m_ui.setupUi(this);
19
20 loadSetting("bios", m_ui.bios);
21 loadSetting("skipBios", m_ui.skipBios);
22 loadSetting("audioBuffers", m_ui.audioBufferSize);
23 loadSetting("videoSync", m_ui.videoSync);
24 loadSetting("audioSync", m_ui.audioSync);
25 loadSetting("frameskip", m_ui.frameskip);
26 loadSetting("fpsTarget", m_ui.fpsTarget);
27 loadSetting("lockAspectRatio", m_ui.lockAspectRatio);
28 loadSetting("rewindEnable", m_ui.rewind);
29 loadSetting("rewindBufferInterval", m_ui.rewindInterval);
30 loadSetting("rewindBufferCapacity", m_ui.rewindCapacity);
31 loadSetting("resampleVideo", m_ui.resampleVideo);
32
33 connect(m_ui.biosBrowse, SIGNAL(clicked()), this, SLOT(selectBios()));
34 connect(m_ui.buttonBox, SIGNAL(accepted()), this, SLOT(updateConfig()));
35}
36
37void SettingsView::selectBios() {
38 QString filename = QFileDialog::getOpenFileName(this, tr("Select BIOS"));
39 if (!filename.isEmpty()) {
40 m_ui.bios->setText(filename);
41 }
42}
43
44void SettingsView::updateConfig() {
45 saveSetting("bios", m_ui.bios);
46 saveSetting("skipBios", m_ui.skipBios);
47 saveSetting("audioBuffers", m_ui.audioBufferSize);
48 saveSetting("videoSync", m_ui.videoSync);
49 saveSetting("audioSync", m_ui.audioSync);
50 saveSetting("frameskip", m_ui.frameskip);
51 saveSetting("fpsTarget", m_ui.fpsTarget);
52 saveSetting("lockAspectRatio", m_ui.lockAspectRatio);
53 saveSetting("rewindEnable", m_ui.rewind);
54 saveSetting("rewindBufferInterval", m_ui.rewindInterval);
55 saveSetting("rewindBufferCapacity", m_ui.rewindCapacity);
56 saveSetting("resampleVideo", m_ui.resampleVideo);
57 m_controller->write();
58
59 emit biosLoaded(m_ui.bios->text());
60}
61
62void SettingsView::saveSetting(const char* key, const QAbstractButton* field) {
63 m_controller->setOption(key, field->isChecked());
64 m_controller->updateOption(key);
65}
66
67void SettingsView::saveSetting(const char* key, const QComboBox* field) {
68 saveSetting(key, field->lineEdit());
69}
70
71void SettingsView::saveSetting(const char* key, const QLineEdit* field) {
72 m_controller->setOption(key, field->text());
73 m_controller->updateOption(key);
74}
75
76void SettingsView::saveSetting(const char* key, const QSpinBox* field) {
77 m_controller->setOption(key, field->cleanText());
78 m_controller->updateOption(key);
79}
80
81void SettingsView::loadSetting(const char* key, QAbstractButton* field) {
82 QString option = m_controller->getOption(key);
83 field->setChecked(option != "0");
84}
85
86void SettingsView::loadSetting(const char* key, QComboBox* field) {
87 loadSetting(key, field->lineEdit());
88}
89
90void SettingsView::loadSetting(const char* key, QLineEdit* field) {
91 QString option = m_controller->getOption(key);
92 field->setText(option);
93}
94
95void SettingsView::loadSetting(const char* key, QSpinBox* field) {
96 QString option = m_controller->getOption(key);
97 field->setValue(option.toInt());
98}