mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Qt: Implement graphics window and controls
This commit is contained in:
49
Source/Core/DolphinQt2/Config/Graphics/GraphicsBool.cpp
Normal file
49
Source/Core/DolphinQt2/Config/Graphics/GraphicsBool.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "DolphinQt2/Config/Graphics/GraphicsBool.h"
|
||||
|
||||
#include "Core/Config/Config.h"
|
||||
|
||||
#include <QFont>
|
||||
|
||||
GraphicsBool::GraphicsBool(const QString& label, const Config::ConfigInfo<bool>& setting,
|
||||
bool reverse)
|
||||
: QCheckBox(label), m_setting(setting), m_reverse(reverse)
|
||||
{
|
||||
connect(this, &QCheckBox::toggled, this, &GraphicsBool::Update);
|
||||
setChecked(Config::Get(m_setting) ^ reverse);
|
||||
|
||||
if (Config::GetActiveLayerForConfig(m_setting) != Config::LayerType::Base)
|
||||
{
|
||||
QFont bf = font();
|
||||
bf.setBold(true);
|
||||
setFont(bf);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsBool::Update()
|
||||
{
|
||||
Config::SetBaseOrCurrent(m_setting, static_cast<bool>(isChecked() ^ m_reverse));
|
||||
}
|
||||
|
||||
GraphicsBoolEx::GraphicsBoolEx(const QString& label, const Config::ConfigInfo<bool>& setting,
|
||||
bool reverse)
|
||||
: QRadioButton(label), m_setting(setting), m_reverse(reverse)
|
||||
{
|
||||
connect(this, &QCheckBox::toggled, this, &GraphicsBoolEx::Update);
|
||||
setChecked(Config::Get(m_setting) ^ reverse);
|
||||
|
||||
if (Config::GetActiveLayerForConfig(m_setting) != Config::LayerType::Base)
|
||||
{
|
||||
QFont bf = font();
|
||||
bf.setBold(true);
|
||||
setFont(bf);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsBoolEx::Update()
|
||||
{
|
||||
Config::SetBaseOrCurrent(m_setting, static_cast<bool>(isChecked() ^ m_reverse));
|
||||
}
|
41
Source/Core/DolphinQt2/Config/Graphics/GraphicsBool.h
Normal file
41
Source/Core/DolphinQt2/Config/Graphics/GraphicsBool.h
Normal file
@ -0,0 +1,41 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QRadioButton>
|
||||
|
||||
namespace Config
|
||||
{
|
||||
template <typename T>
|
||||
struct ConfigInfo;
|
||||
};
|
||||
|
||||
class GraphicsBool : public QCheckBox
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
GraphicsBool(const QString& label, const Config::ConfigInfo<bool>& setting, bool reverse = false);
|
||||
|
||||
private:
|
||||
void Update();
|
||||
|
||||
const Config::ConfigInfo<bool>& m_setting;
|
||||
bool m_reverse;
|
||||
};
|
||||
|
||||
class GraphicsBoolEx : public QRadioButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
GraphicsBoolEx(const QString& label, const Config::ConfigInfo<bool>& setting,
|
||||
bool reverse = false);
|
||||
|
||||
private:
|
||||
void Update();
|
||||
|
||||
const Config::ConfigInfo<bool>& m_setting;
|
||||
bool m_reverse;
|
||||
};
|
28
Source/Core/DolphinQt2/Config/Graphics/GraphicsChoice.cpp
Normal file
28
Source/Core/DolphinQt2/Config/Graphics/GraphicsChoice.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "DolphinQt2/Config/Graphics/GraphicsChoice.h"
|
||||
|
||||
#include "Core/Config/Config.h"
|
||||
|
||||
GraphicsChoice::GraphicsChoice(const QStringList& options, const Config::ConfigInfo<int>& setting)
|
||||
: m_setting(setting)
|
||||
{
|
||||
addItems(options);
|
||||
connect(this, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
||||
&GraphicsChoice::Update);
|
||||
setCurrentIndex(Config::Get(m_setting));
|
||||
|
||||
if (Config::GetActiveLayerForConfig(m_setting) != Config::LayerType::Base)
|
||||
{
|
||||
QFont bf = font();
|
||||
bf.setBold(true);
|
||||
setFont(bf);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsChoice::Update(int choice)
|
||||
{
|
||||
Config::SetBaseOrCurrent(m_setting, choice);
|
||||
}
|
24
Source/Core/DolphinQt2/Config/Graphics/GraphicsChoice.h
Normal file
24
Source/Core/DolphinQt2/Config/Graphics/GraphicsChoice.h
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QComboBox>
|
||||
|
||||
namespace Config
|
||||
{
|
||||
template <typename T>
|
||||
struct ConfigInfo;
|
||||
};
|
||||
|
||||
class GraphicsChoice : public QComboBox
|
||||
{
|
||||
public:
|
||||
GraphicsChoice(const QStringList& options, const Config::ConfigInfo<int>& setting);
|
||||
|
||||
private:
|
||||
void Update(int choice);
|
||||
|
||||
const Config::ConfigInfo<int>& m_setting;
|
||||
};
|
25
Source/Core/DolphinQt2/Config/Graphics/GraphicsSlider.cpp
Normal file
25
Source/Core/DolphinQt2/Config/Graphics/GraphicsSlider.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "DolphinQt2/Config/Graphics/GraphicsSlider.h"
|
||||
|
||||
#include "Core/Config/Config.h"
|
||||
|
||||
GraphicsSlider::GraphicsSlider(int minimum, int maximum, const Config::ConfigInfo<int>& setting,
|
||||
int tick)
|
||||
: QSlider(Qt::Horizontal), m_setting(setting)
|
||||
{
|
||||
setMinimum(minimum);
|
||||
setMaximum(maximum);
|
||||
setTickInterval(tick);
|
||||
|
||||
setValue(Config::Get(setting));
|
||||
|
||||
connect(this, &GraphicsSlider::valueChanged, this, &GraphicsSlider::Update);
|
||||
}
|
||||
|
||||
void GraphicsSlider::Update(int value)
|
||||
{
|
||||
Config::SetBaseOrCurrent(m_setting, value);
|
||||
}
|
23
Source/Core/DolphinQt2/Config/Graphics/GraphicsSlider.h
Normal file
23
Source/Core/DolphinQt2/Config/Graphics/GraphicsSlider.h
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QSlider>
|
||||
|
||||
namespace Config
|
||||
{
|
||||
template <typename T>
|
||||
struct ConfigInfo;
|
||||
};
|
||||
|
||||
class GraphicsSlider : public QSlider
|
||||
{
|
||||
public:
|
||||
GraphicsSlider(int minimum, int maximum, const Config::ConfigInfo<int>& setting, int tick = 0);
|
||||
void Update(int value);
|
||||
|
||||
private:
|
||||
const Config::ConfigInfo<int>& m_setting;
|
||||
};
|
23
Source/Core/DolphinQt2/Config/Graphics/GraphicsWidget.cpp
Normal file
23
Source/Core/DolphinQt2/Config/Graphics/GraphicsWidget.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "DolphinQt2/Config/Graphics/GraphicsWidget.h"
|
||||
|
||||
#include <QEvent>
|
||||
#include <QFormLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "DolphinQt2/Config/Graphics/GraphicsWindow.h"
|
||||
|
||||
GraphicsWidget::GraphicsWidget(GraphicsWindow* parent)
|
||||
{
|
||||
parent->RegisterWidget(this);
|
||||
}
|
||||
|
||||
void GraphicsWidget::AddDescription(QWidget* widget, const char* description)
|
||||
{
|
||||
emit DescriptionAdded(widget, description);
|
||||
}
|
34
Source/Core/DolphinQt2/Config/Graphics/GraphicsWidget.h
Normal file
34
Source/Core/DolphinQt2/Config/Graphics/GraphicsWidget.h
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class GraphicsWindow;
|
||||
class QFormLayout;
|
||||
class QGroupBox;
|
||||
class QLabel;
|
||||
|
||||
class GraphicsWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GraphicsWidget(GraphicsWindow* parent);
|
||||
|
||||
signals:
|
||||
void DescriptionAdded(QWidget* widget, const char* description);
|
||||
|
||||
protected:
|
||||
void AddWidget(const QString& name, QWidget* widget);
|
||||
void AddWidget(QWidget* widget);
|
||||
|
||||
void AddDescription(QWidget* widget, const char* description);
|
||||
|
||||
virtual void LoadSettings() = 0;
|
||||
virtual void SaveSettings() = 0;
|
||||
|
||||
private:
|
||||
QFormLayout* m_main_layout;
|
||||
};
|
113
Source/Core/DolphinQt2/Config/Graphics/GraphicsWindow.cpp
Normal file
113
Source/Core/DolphinQt2/Config/Graphics/GraphicsWindow.cpp
Normal file
@ -0,0 +1,113 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "DolphinQt2/Config/Graphics/GraphicsWindow.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QEvent>
|
||||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
#include <QTabWidget>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "Core/ConfigManager.h"
|
||||
#include "DolphinQt2/Config/Graphics/AdvancedWidget.h"
|
||||
#include "DolphinQt2/Config/Graphics/EnhancementsWidget.h"
|
||||
#include "DolphinQt2/Config/Graphics/GeneralWidget.h"
|
||||
#include "DolphinQt2/Config/Graphics/HacksWidget.h"
|
||||
#include "DolphinQt2/MainWindow.h"
|
||||
|
||||
GraphicsWindow::GraphicsWindow(X11Utils::XRRConfiguration* xrr_config, MainWindow* parent)
|
||||
: QDialog(parent), m_xrr_config(xrr_config)
|
||||
{
|
||||
CreateMainLayout();
|
||||
ConnectWidgets();
|
||||
|
||||
setWindowTitle(tr("Graphics"));
|
||||
setWindowFlags(Qt::Window);
|
||||
|
||||
OnBackendChanged(QString::fromStdString(SConfig::GetInstance().m_strVideoBackend));
|
||||
|
||||
connect(parent, &MainWindow::EmulationStarted, this, &GraphicsWindow::EmulationStarted);
|
||||
connect(parent, &MainWindow::EmulationStopped, this, &GraphicsWindow::EmulationStopped);
|
||||
}
|
||||
|
||||
void GraphicsWindow::CreateMainLayout()
|
||||
{
|
||||
auto* main_layout = new QVBoxLayout();
|
||||
auto* description_box = new QGroupBox(tr("Description"));
|
||||
auto* description_layout = new QVBoxLayout();
|
||||
m_description =
|
||||
new QLabel(tr("Move the mouse pointer over an option to display a detailed description."));
|
||||
m_tab_widget = new QTabWidget();
|
||||
m_button_box = new QDialogButtonBox(QDialogButtonBox::Ok);
|
||||
|
||||
description_box->setLayout(description_layout);
|
||||
description_box->setMinimumHeight(205);
|
||||
|
||||
m_description->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
m_description->setWordWrap(true);
|
||||
m_description->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
||||
|
||||
description_layout->addWidget(m_description);
|
||||
|
||||
main_layout->addWidget(m_tab_widget);
|
||||
main_layout->addWidget(description_box);
|
||||
main_layout->addWidget(m_button_box);
|
||||
|
||||
auto* general_widget = new GeneralWidget(m_xrr_config, this);
|
||||
auto* enhancements_widget = new EnhancementsWidget(this);
|
||||
auto* hacks_widget = new HacksWidget(this);
|
||||
auto* advanced_widget = new AdvancedWidget(this);
|
||||
|
||||
connect(general_widget, &GeneralWidget::BackendChanged, this, &GraphicsWindow::OnBackendChanged);
|
||||
|
||||
m_tab_widget->addTab(general_widget, tr("General"));
|
||||
m_tab_widget->addTab(enhancements_widget, tr("Enhancements"));
|
||||
m_tab_widget->addTab(hacks_widget, tr("Hacks"));
|
||||
m_tab_widget->addTab(advanced_widget, tr("Advanced"));
|
||||
|
||||
setLayout(main_layout);
|
||||
}
|
||||
|
||||
void GraphicsWindow::ConnectWidgets()
|
||||
{
|
||||
connect(m_button_box, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
}
|
||||
|
||||
void GraphicsWindow::OnBackendChanged(const QString& backend)
|
||||
{
|
||||
setWindowTitle(tr("Dolphin %1 Graphics Configuration").arg(backend));
|
||||
emit BackendChanged(backend);
|
||||
}
|
||||
|
||||
void GraphicsWindow::RegisterWidget(GraphicsWidget* widget)
|
||||
{
|
||||
connect(widget, &GraphicsWidget::DescriptionAdded, this, &GraphicsWindow::OnDescriptionAdded);
|
||||
}
|
||||
|
||||
void GraphicsWindow::OnDescriptionAdded(QWidget* widget, const char* description)
|
||||
{
|
||||
m_widget_descriptions[widget] = description;
|
||||
widget->installEventFilter(this);
|
||||
}
|
||||
|
||||
bool GraphicsWindow::eventFilter(QObject* object, QEvent* event)
|
||||
{
|
||||
if (!m_widget_descriptions.contains(object))
|
||||
return false;
|
||||
if (event->type() == QEvent::Enter)
|
||||
{
|
||||
m_description->setText(tr(m_widget_descriptions[object]));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (event->type() == QEvent::Leave)
|
||||
{
|
||||
m_description->setText(
|
||||
tr("Move the mouse pointer over an option to display a detailed description."));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
47
Source/Core/DolphinQt2/Config/Graphics/GraphicsWindow.h
Normal file
47
Source/Core/DolphinQt2/Config/Graphics/GraphicsWindow.h
Normal file
@ -0,0 +1,47 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include <QHash>
|
||||
|
||||
class GraphicsWidget;
|
||||
class MainWindow;
|
||||
class QLabel;
|
||||
class QTabWidget;
|
||||
class QDialogButtonBox;
|
||||
|
||||
namespace X11Utils
|
||||
{
|
||||
class XRRConfiguration;
|
||||
}
|
||||
|
||||
class GraphicsWindow final : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GraphicsWindow(X11Utils::XRRConfiguration* xrr_config, MainWindow* parent);
|
||||
|
||||
void RegisterWidget(GraphicsWidget* widget);
|
||||
bool eventFilter(QObject* object, QEvent* event) override;
|
||||
signals:
|
||||
void BackendChanged(const QString& backend);
|
||||
void EmulationStarted();
|
||||
void EmulationStopped();
|
||||
|
||||
private:
|
||||
void CreateMainLayout();
|
||||
void ConnectWidgets();
|
||||
void OnBackendChanged(const QString& backend);
|
||||
void OnDescriptionAdded(QWidget* widget, const char* description);
|
||||
|
||||
QTabWidget* m_tab_widget;
|
||||
QLabel* m_description;
|
||||
QDialogButtonBox* m_button_box;
|
||||
|
||||
X11Utils::XRRConfiguration* m_xrr_config;
|
||||
|
||||
QHash<QObject*, const char*> m_widget_descriptions;
|
||||
};
|
Reference in New Issue
Block a user