| 
									
										
										
										
											2017-06-16 01:42:12 +02:00
										 |  |  | // Copyright 2017 Dolphin Emulator Project
 | 
					
						
							|  |  |  | // Licensed under GPLv2+
 | 
					
						
							|  |  |  | // Refer to the license.txt file included.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-07 00:40:15 +02:00
										 |  |  | #include "DolphinQt/Config/Graphics/GraphicsWindow.h"
 | 
					
						
							| 
									
										
										
										
											2017-06-16 01:42:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <QDialogButtonBox>
 | 
					
						
							|  |  |  | #include <QEvent>
 | 
					
						
							|  |  |  | #include <QGroupBox>
 | 
					
						
							|  |  |  | #include <QLabel>
 | 
					
						
							|  |  |  | #include <QTabWidget>
 | 
					
						
							|  |  |  | #include <QVBoxLayout>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "Core/ConfigManager.h"
 | 
					
						
							| 
									
										
										
										
											2018-05-19 17:44:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-07 00:40:15 +02:00
										 |  |  | #include "DolphinQt/Config/Graphics/AdvancedWidget.h"
 | 
					
						
							|  |  |  | #include "DolphinQt/Config/Graphics/EnhancementsWidget.h"
 | 
					
						
							|  |  |  | #include "DolphinQt/Config/Graphics/GeneralWidget.h"
 | 
					
						
							|  |  |  | #include "DolphinQt/Config/Graphics/HacksWidget.h"
 | 
					
						
							|  |  |  | #include "DolphinQt/Config/Graphics/SoftwareRendererWidget.h"
 | 
					
						
							|  |  |  | #include "DolphinQt/MainWindow.h"
 | 
					
						
							|  |  |  | #include "DolphinQt/QtUtils/WrapInScrollArea.h"
 | 
					
						
							| 
									
										
										
										
											2018-05-19 17:44:22 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "VideoCommon/VideoBackendBase.h"
 | 
					
						
							| 
									
										
										
										
											2018-05-08 17:20:08 +02:00
										 |  |  | #include "VideoCommon/VideoConfig.h"
 | 
					
						
							| 
									
										
										
										
											2017-06-16 01:42:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | GraphicsWindow::GraphicsWindow(X11Utils::XRRConfiguration* xrr_config, MainWindow* parent) | 
					
						
							|  |  |  |     : QDialog(parent), m_xrr_config(xrr_config) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 03:33:53 +02:00
										 |  |  |   // GraphicsWindow initialization is heavy due to dependencies on the graphics subsystem.
 | 
					
						
							|  |  |  |   // To prevent blocking startup, we create the layout and children at first show time.
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GraphicsWindow::Initialize() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (m_lazy_initialized) | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   m_lazy_initialized = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-16 01:42:12 +02:00
										 |  |  |   CreateMainLayout(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   setWindowTitle(tr("Graphics")); | 
					
						
							| 
									
										
										
										
											2017-09-04 19:50:24 +02:00
										 |  |  |   setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); | 
					
						
							| 
									
										
										
										
											2017-06-16 01:42:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   OnBackendChanged(QString::fromStdString(SConfig::GetInstance().m_strVideoBackend)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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(); | 
					
						
							| 
									
										
										
										
											2018-03-20 10:12:11 +01:00
										 |  |  |   m_button_box = new QDialogButtonBox(QDialogButtonBox::Close); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   connect(m_button_box, &QDialogButtonBox::rejected, this, &QDialog::reject); | 
					
						
							| 
									
										
										
										
											2017-06-16 01:42:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   description_box->setLayout(description_layout); | 
					
						
							| 
									
										
										
										
											2018-03-26 04:25:36 +02:00
										 |  |  |   description_box->setFixedHeight(200); | 
					
						
							| 
									
										
										
										
											2017-06-16 01:42:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-16 01:43:14 +02:00
										 |  |  |   m_general_widget = new GeneralWidget(m_xrr_config, this); | 
					
						
							|  |  |  |   m_enhancements_widget = new EnhancementsWidget(this); | 
					
						
							|  |  |  |   m_hacks_widget = new HacksWidget(this); | 
					
						
							|  |  |  |   m_advanced_widget = new AdvancedWidget(this); | 
					
						
							|  |  |  |   m_software_renderer = new SoftwareRendererWidget(this); | 
					
						
							| 
									
										
										
										
											2017-06-16 01:42:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-16 01:43:14 +02:00
										 |  |  |   connect(m_general_widget, &GeneralWidget::BackendChanged, this, | 
					
						
							|  |  |  |           &GraphicsWindow::OnBackendChanged); | 
					
						
							|  |  |  |   connect(m_software_renderer, &SoftwareRendererWidget::BackendChanged, this, | 
					
						
							|  |  |  |           &GraphicsWindow::OnBackendChanged); | 
					
						
							| 
									
										
										
										
											2017-06-16 01:42:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-08 17:39:03 +02:00
										 |  |  |   m_wrapped_general = GetWrappedWidget(m_general_widget, this, 50, 305); | 
					
						
							|  |  |  |   m_wrapped_enhancements = GetWrappedWidget(m_enhancements_widget, this, 50, 305); | 
					
						
							|  |  |  |   m_wrapped_hacks = GetWrappedWidget(m_hacks_widget, this, 50, 305); | 
					
						
							|  |  |  |   m_wrapped_advanced = GetWrappedWidget(m_advanced_widget, this, 50, 305); | 
					
						
							|  |  |  |   m_wrapped_software = GetWrappedWidget(m_software_renderer, this, 50, 305); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-16 01:43:14 +02:00
										 |  |  |   if (SConfig::GetInstance().m_strVideoBackend != "Software Renderer") | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2018-05-08 17:39:03 +02:00
										 |  |  |     m_tab_widget->addTab(m_wrapped_general, tr("General")); | 
					
						
							|  |  |  |     m_tab_widget->addTab(m_wrapped_enhancements, tr("Enhancements")); | 
					
						
							|  |  |  |     m_tab_widget->addTab(m_wrapped_hacks, tr("Hacks")); | 
					
						
							|  |  |  |     m_tab_widget->addTab(m_wrapped_advanced, tr("Advanced")); | 
					
						
							| 
									
										
										
										
											2017-06-16 01:43:14 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2018-05-08 17:39:03 +02:00
										 |  |  |     m_tab_widget->addTab(m_wrapped_software, tr("Software Renderer")); | 
					
						
							| 
									
										
										
										
											2017-06-16 01:43:14 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-06-16 01:42:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   setLayout(main_layout); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-19 17:52:53 +02:00
										 |  |  | void GraphicsWindow::OnBackendChanged(const QString& backend_name) | 
					
						
							| 
									
										
										
										
											2017-06-16 01:42:12 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-19 17:52:53 +02:00
										 |  |  |   SConfig::GetInstance().m_strVideoBackend = backend_name.toStdString(); | 
					
						
							| 
									
										
										
										
											2018-09-28 14:22:18 +10:00
										 |  |  |   VideoBackendBase::PopulateBackendInfo(); | 
					
						
							| 
									
										
										
										
											2018-05-19 17:52:53 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-30 04:28:45 -04:00
										 |  |  |   setWindowTitle( | 
					
						
							|  |  |  |       tr("%1 Graphics Configuration").arg(tr(g_video_backend->GetDisplayName().c_str()))); | 
					
						
							| 
									
										
										
										
											2018-05-19 17:52:53 +02:00
										 |  |  |   if (backend_name == QStringLiteral("Software Renderer") && m_tab_widget->count() > 1) | 
					
						
							| 
									
										
										
										
											2017-06-16 01:43:14 +02:00
										 |  |  |   { | 
					
						
							|  |  |  |     m_tab_widget->clear(); | 
					
						
							| 
									
										
										
										
											2018-05-08 17:39:03 +02:00
										 |  |  |     m_tab_widget->addTab(m_wrapped_software, tr("Software Renderer")); | 
					
						
							| 
									
										
										
										
											2017-06-16 01:43:14 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-19 17:52:53 +02:00
										 |  |  |   if (backend_name != QStringLiteral("Software Renderer") && m_tab_widget->count() == 1) | 
					
						
							| 
									
										
										
										
											2017-06-16 01:43:14 +02:00
										 |  |  |   { | 
					
						
							|  |  |  |     m_tab_widget->clear(); | 
					
						
							| 
									
										
										
										
											2018-05-08 17:39:03 +02:00
										 |  |  |     m_tab_widget->addTab(m_wrapped_general, tr("General")); | 
					
						
							|  |  |  |     m_tab_widget->addTab(m_wrapped_enhancements, tr("Enhancements")); | 
					
						
							|  |  |  |     m_tab_widget->addTab(m_wrapped_hacks, tr("Hacks")); | 
					
						
							|  |  |  |     m_tab_widget->addTab(m_wrapped_advanced, tr("Advanced")); | 
					
						
							| 
									
										
										
										
											2017-06-16 01:43:14 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-19 17:52:53 +02:00
										 |  |  |   emit BackendChanged(backend_name); | 
					
						
							| 
									
										
										
										
											2017-06-16 01:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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; | 
					
						
							| 
									
										
										
										
											2017-06-16 01:43:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-16 01:42:12 +02:00
										 |  |  |   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; | 
					
						
							|  |  |  | } |