Qt: Move shader settings into main settings window
Vicki Pfau vi@endrift.com
Fri, 07 Jul 2017 12:17:47 -0700
6 files changed,
47 insertions(+),
23 deletions(-)
M
src/platform/qt/SettingsView.cpp
→
src/platform/qt/SettingsView.cpp
@@ -11,6 +11,7 @@ #include "Display.h"
#include "GBAApp.h" #include "GBAKeyEditor.h" #include "InputController.h" +#include "ShaderSelector.h" #include "ShortcutView.h" #include <mgba/core/serialize.h>@@ -183,6 +184,20 @@ shortcutView->setController(shortcutController);
shortcutView->setInputController(inputController); m_ui.stackedWidget->addWidget(shortcutView); m_ui.tabs->addItem(tr("Shortcuts")); +} + +SettingsView::~SettingsView() { + if (m_shader) { + m_ui.stackedWidget->removeWidget(m_shader); + m_shader->setParent(nullptr); + } +} + +void SettingsView::setShaderSelector(ShaderSelector* shaderSelector) { + m_shader = shaderSelector; + m_ui.stackedWidget->addWidget(m_shader); + m_ui.tabs->addItem(tr("Shaders")); + connect(m_ui.buttonBox, &QDialogButtonBox::accepted, m_shader, &ShaderSelector::saved); } void SettingsView::selectBios(QLineEdit* bios) {
M
src/platform/qt/SettingsView.h
→
src/platform/qt/SettingsView.h
@@ -17,12 +17,16 @@
class ConfigController; class InputController; class ShortcutController; +class ShaderSelector; class SettingsView : public QDialog { Q_OBJECT public: SettingsView(ConfigController* controller, InputController* inputController, ShortcutController* shortcutController, QWidget* parent = nullptr); + ~SettingsView(); + + void setShaderSelector(ShaderSelector* shaderSelector); signals: void biosLoaded(int platform, const QString&);@@ -42,6 +46,7 @@ Ui::SettingsView m_ui;
ConfigController* m_controller; InputController* m_input; + ShaderSelector* m_shader = nullptr; void saveSetting(const char* key, const QAbstractButton*); void saveSetting(const char* key, const QComboBox*);
M
src/platform/qt/ShaderSelector.cpp
→
src/platform/qt/ShaderSelector.cpp
@@ -39,6 +39,9 @@
connect(m_ui.load, &QAbstractButton::clicked, this, &ShaderSelector::selectShader); connect(m_ui.unload, &QAbstractButton::clicked, this, &ShaderSelector::clearShader); connect(m_ui.buttonBox, &QDialogButtonBox::clicked, this, &ShaderSelector::buttonPressed); + connect(this, &ShaderSelector::saved, [this]() { + m_config->setOption("shader", m_shaderPath); + }); } ShaderSelector::~ShaderSelector() {@@ -86,7 +89,6 @@ void ShaderSelector::clearShader() {
m_display->clearShaders(); refreshShaders(); m_shaderPath = ""; - m_config->setOption("shader", nullptr); } void ShaderSelector::refreshShaders() {@@ -114,6 +116,10 @@
disconnect(this, &ShaderSelector::saved, 0, 0); disconnect(this, &ShaderSelector::reset, 0, 0); disconnect(this, &ShaderSelector::resetToDefault, 0, 0); + + connect(this, &ShaderSelector::saved, [this]() { + m_config->setOption("shader", m_shaderPath); + }); #if !defined(_WIN32) || defined(USE_EPOXY) if (m_shaders->preprocessShader) {@@ -264,7 +270,6 @@ case QDialogButtonBox::Reset:
emit reset(); break; case QDialogButtonBox::Ok: - m_config->setOption("shader", m_shaderPath); emit saved(); close(); break;
M
src/platform/qt/ShaderSelector.ui
→
src/platform/qt/ShaderSelector.ui
@@ -81,32 +81,35 @@ </property>
</widget> </item> <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <item> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> <widget class="QPushButton" name="unload"> <property name="text"> <string>Unload Shader</string> </property> </widget> </item> - <item> + <item row="0" column="1"> <widget class="QPushButton" name="load"> <property name="text"> <string>Load New Shader</string> </property> </widget> </item> + <item row="1" column="0" colspan="2"> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Reset|QDialogButtonBox::RestoreDefaults</set> + </property> + <property name="centerButtons"> + <bool>true</bool> + </property> + </widget> + </item> </layout> - </item> - <item> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons"> - <set>QDialogButtonBox::Ok|QDialogButtonBox::Reset|QDialogButtonBox::RestoreDefaults</set> - </property> - </widget> </item> </layout> </widget>
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -177,7 +177,6 @@ connect(this, &Window::startDrawing, m_display, &Display::startDrawing, Qt::QueuedConnection);
connect(this, &Window::shutdown, m_display, &Display::stopDrawing); connect(this, &Window::shutdown, m_controller, &GameController::closeGame); connect(this, &Window::shutdown, m_logView, &QWidget::hide); - connect(this, &Window::shutdown, m_shaderView, &QWidget::hide); connect(this, &Window::audioBufferSamplesChanged, m_controller, &GameController::setAudioBufferSamples); connect(this, &Window::sampleRateChanged, m_controller, &GameController::setAudioSampleRate); connect(this, &Window::fpsTargetChanged, m_controller, &GameController::setFPSTarget);@@ -460,6 +459,9 @@ }
void Window::openSettingsWindow() { SettingsView* settingsWindow = new SettingsView(m_config, &m_inputController, m_shortcutController); + if (m_display->supportsShaders()) { + settingsWindow->setShaderSelector(m_shaderView); + } connect(settingsWindow, &SettingsView::biosLoaded, m_controller, &GameController::loadBIOS); connect(settingsWindow, &SettingsView::audioDriverChanged, m_controller, &GameController::reloadAudioDriver); connect(settingsWindow, &SettingsView::displayDriverChanged, this, &Window::mustRestart);@@ -1295,13 +1297,6 @@ for (int i = 0; i <= 10; ++i) {
skip->addValue(QString::number(i), i, skipMenu); } m_config->updateOption("frameskip"); - - QAction* shaderView = new QAction(tr("Shader options..."), avMenu); - connect(shaderView, &QAction::triggered, m_shaderView, &QWidget::show); - if (!m_display->supportsShaders()) { - shaderView->setEnabled(false); - } - addControlledAction(avMenu, shaderView, "shaderSelector"); avMenu->addSeparator();