pineapple-src/src/yuzu/configuration/configure_dialog.cpp

202 lines
7.5 KiB
C++
Raw Normal View History

2020-12-28 15:15:37 +00:00
// Copyright 2016 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
2021-10-09 00:29:53 +00:00
#include <memory>
2021-05-21 07:31:35 +00:00
#include <QAbstractButton>
#include <QDialogButtonBox>
2020-12-28 15:15:37 +00:00
#include <QHash>
#include <QListWidgetItem>
2021-05-21 07:31:35 +00:00
#include <QPushButton>
2020-12-28 15:15:37 +00:00
#include <QSignalBlocker>
2021-07-09 01:27:40 +00:00
#include <QTabWidget>
2021-10-09 00:29:53 +00:00
#include "common/logging/log.h"
2021-04-15 02:05:28 +00:00
#include "common/settings.h"
2020-12-28 15:15:37 +00:00
#include "core/core.h"
#include "ui_configure.h"
#include "yuzu/configuration/config.h"
2021-10-09 00:29:53 +00:00
#include "yuzu/configuration/configure_audio.h"
#include "yuzu/configuration/configure_cpu.h"
#include "yuzu/configuration/configure_debug_tab.h"
2020-12-28 15:15:37 +00:00
#include "yuzu/configuration/configure_dialog.h"
2021-10-09 00:29:53 +00:00
#include "yuzu/configuration/configure_filesystem.h"
#include "yuzu/configuration/configure_general.h"
#include "yuzu/configuration/configure_graphics.h"
#include "yuzu/configuration/configure_graphics_advanced.h"
#include "yuzu/configuration/configure_hotkeys.h"
#include "yuzu/configuration/configure_input.h"
2020-12-28 15:15:37 +00:00
#include "yuzu/configuration/configure_input_player.h"
2021-10-09 00:29:53 +00:00
#include "yuzu/configuration/configure_network.h"
#include "yuzu/configuration/configure_profile_manager.h"
#include "yuzu/configuration/configure_system.h"
#include "yuzu/configuration/configure_ui.h"
#include "yuzu/configuration/configure_web.h"
2020-12-28 15:15:37 +00:00
#include "yuzu/hotkeys.h"
ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry,
2021-10-09 00:29:53 +00:00
InputCommon::InputSubsystem* input_subsystem,
Core::System& system_)
2021-10-16 00:35:29 +00:00
: QDialog(parent), ui{std::make_unique<Ui::ConfigureDialog>()},
2021-10-09 00:29:53 +00:00
registry(registry), system{system_}, audio_tab{std::make_unique<ConfigureAudio>(system_,
this)},
cpu_tab{std::make_unique<ConfigureCpu>(system_, this)},
debug_tab_tab{std::make_unique<ConfigureDebugTab>(system_, this)},
filesystem_tab{std::make_unique<ConfigureFilesystem>(this)},
general_tab{std::make_unique<ConfigureGeneral>(system_, this)},
graphics_tab{std::make_unique<ConfigureGraphics>(system_, this)},
graphics_advanced_tab{std::make_unique<ConfigureGraphicsAdvanced>(system_, this)},
2021-12-29 20:59:21 +00:00
hotkeys_tab{std::make_unique<ConfigureHotkeys>(system_.HIDCore(), this)},
2021-10-09 00:29:53 +00:00
input_tab{std::make_unique<ConfigureInput>(system_, this)},
network_tab{std::make_unique<ConfigureNetwork>(system_, this)},
profile_tab{std::make_unique<ConfigureProfileManager>(system_, this)},
system_tab{std::make_unique<ConfigureSystem>(system_, this)},
ui_tab{std::make_unique<ConfigureUi>(system_, this)}, web_tab{std::make_unique<ConfigureWeb>(
this)} {
2020-12-28 15:15:37 +00:00
Settings::SetConfiguringGlobal(true);
ui->setupUi(this);
2021-10-09 00:29:53 +00:00
ui->tabWidget->addTab(audio_tab.get(), tr("Audio"));
ui->tabWidget->addTab(cpu_tab.get(), tr("CPU"));
ui->tabWidget->addTab(debug_tab_tab.get(), tr("Debug"));
ui->tabWidget->addTab(filesystem_tab.get(), tr("Filesystem"));
ui->tabWidget->addTab(general_tab.get(), tr("General"));
ui->tabWidget->addTab(graphics_tab.get(), tr("Graphics"));
ui->tabWidget->addTab(graphics_advanced_tab.get(), tr("GraphicsAdvanced"));
ui->tabWidget->addTab(hotkeys_tab.get(), tr("Hotkeys"));
ui->tabWidget->addTab(input_tab.get(), tr("Controls"));
ui->tabWidget->addTab(profile_tab.get(), tr("Profiles"));
ui->tabWidget->addTab(network_tab.get(), tr("Network"));
ui->tabWidget->addTab(system_tab.get(), tr("System"));
ui->tabWidget->addTab(ui_tab.get(), tr("Game List"));
ui->tabWidget->addTab(web_tab.get(), tr("Web"));
hotkeys_tab->Populate(registry);
2020-12-28 15:15:37 +00:00
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
2021-11-05 15:31:40 +00:00
input_tab->Initialize(input_subsystem);
2020-12-28 15:15:37 +00:00
2021-10-09 00:29:53 +00:00
general_tab->SetResetCallback([&] { this->close(); });
2021-06-04 08:40:16 +00:00
2020-12-28 15:15:37 +00:00
SetConfiguration();
PopulateSelectionList();
2021-10-27 03:22:08 +00:00
connect(ui->tabWidget, &QTabWidget::currentChanged, this, [this](int index) {
if (index != -1) {
debug_tab_tab->SetCurrentIndex(0);
}
});
2021-10-09 00:29:53 +00:00
connect(ui_tab.get(), &ConfigureUi::LanguageChanged, this, &ConfigureDialog::OnLanguageChanged);
2020-12-28 15:15:37 +00:00
connect(ui->selectorList, &QListWidget::itemSelectionChanged, this,
&ConfigureDialog::UpdateVisibleTabs);
2021-10-09 00:29:53 +00:00
if (system.IsPoweredOn()) {
2021-05-21 07:31:35 +00:00
QPushButton* apply_button = ui->buttonBox->addButton(QDialogButtonBox::Apply);
connect(apply_button, &QAbstractButton::clicked, this,
&ConfigureDialog::HandleApplyButtonClicked);
}
2020-12-28 15:15:37 +00:00
adjustSize();
ui->selectorList->setCurrentRow(0);
}
ConfigureDialog::~ConfigureDialog() = default;
void ConfigureDialog::SetConfiguration() {}
void ConfigureDialog::ApplyConfiguration() {
2021-10-09 00:29:53 +00:00
general_tab->ApplyConfiguration();
ui_tab->ApplyConfiguration();
system_tab->ApplyConfiguration();
profile_tab->ApplyConfiguration();
2022-02-02 04:57:17 +00:00
filesystem_tab->ApplyConfiguration();
2021-10-09 00:29:53 +00:00
input_tab->ApplyConfiguration();
hotkeys_tab->ApplyConfiguration(registry);
cpu_tab->ApplyConfiguration();
graphics_tab->ApplyConfiguration();
graphics_advanced_tab->ApplyConfiguration();
audio_tab->ApplyConfiguration();
debug_tab_tab->ApplyConfiguration();
web_tab->ApplyConfiguration();
network_tab->ApplyConfiguration();
system.ApplySettings();
2020-12-28 15:15:37 +00:00
Settings::LogSettings();
}
void ConfigureDialog::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QDialog::changeEvent(event);
}
void ConfigureDialog::RetranslateUI() {
const int old_row = ui->selectorList->currentRow();
const int old_index = ui->tabWidget->currentIndex();
ui->retranslateUi(this);
PopulateSelectionList();
ui->selectorList->setCurrentRow(old_row);
UpdateVisibleTabs();
ui->tabWidget->setCurrentIndex(old_index);
}
2021-05-21 07:31:35 +00:00
void ConfigureDialog::HandleApplyButtonClicked() {
UISettings::values.configuration_applied = true;
ApplyConfiguration();
}
2020-12-28 15:15:37 +00:00
Q_DECLARE_METATYPE(QList<QWidget*>);
void ConfigureDialog::PopulateSelectionList() {
const std::array<std::pair<QString, QList<QWidget*>>, 6> items{
2021-10-09 00:29:53 +00:00
{{tr("General"),
{general_tab.get(), hotkeys_tab.get(), ui_tab.get(), web_tab.get(), debug_tab_tab.get()}},
{tr("System"),
{system_tab.get(), profile_tab.get(), network_tab.get(), filesystem_tab.get()}},
{tr("CPU"), {cpu_tab.get()}},
{tr("Graphics"), {graphics_tab.get(), graphics_advanced_tab.get()}},
{tr("Audio"), {audio_tab.get()}},
{tr("Controls"), input_tab->GetSubTabs()}},
2020-12-28 15:15:37 +00:00
};
[[maybe_unused]] const QSignalBlocker blocker(ui->selectorList);
ui->selectorList->clear();
for (const auto& entry : items) {
auto* const item = new QListWidgetItem(entry.first);
item->setData(Qt::UserRole, QVariant::fromValue(entry.second));
ui->selectorList->addItem(item);
}
}
void ConfigureDialog::OnLanguageChanged(const QString& locale) {
emit LanguageChanged(locale);
// first apply the configuration, and then restore the display
ApplyConfiguration();
RetranslateUI();
SetConfiguration();
}
void ConfigureDialog::UpdateVisibleTabs() {
const auto items = ui->selectorList->selectedItems();
if (items.isEmpty()) {
return;
}
[[maybe_unused]] const QSignalBlocker blocker(ui->tabWidget);
ui->tabWidget->clear();
2021-01-15 00:27:20 +00:00
const auto tabs = qvariant_cast<QList<QWidget*>>(items[0]->data(Qt::UserRole));
2020-12-28 15:15:37 +00:00
2021-01-15 00:27:20 +00:00
for (auto* const tab : tabs) {
2021-10-09 00:29:53 +00:00
LOG_DEBUG(Frontend, "{}", tab->accessibleName().toStdString());
2020-12-28 15:15:37 +00:00
ui->tabWidget->addTab(tab, tab->accessibleName());
}
}