pineapple/src/yuzu/configuration/configure_dialog.cpp

198 lines
7.6 KiB
C++
Raw Normal View History

2022-07-27 20:06:50 +02:00
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2020-12-28 16:15:37 +01:00
2021-10-09 02:29:53 +02:00
#include <memory>
#include "common/logging/log.h"
2021-04-15 04:05:28 +02:00
#include "common/settings.h"
2020-12-28 16:15:37 +01:00
#include "core/core.h"
#include "ui_configure.h"
#include "yuzu/configuration/config.h"
2021-10-09 02:29:53 +02:00
#include "yuzu/configuration/configure_audio.h"
#include "yuzu/configuration/configure_cpu.h"
#include "yuzu/configuration/configure_debug_tab.h"
2020-12-28 16:15:37 +01:00
#include "yuzu/configuration/configure_dialog.h"
2021-10-09 02:29:53 +02: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 16:15:37 +01:00
#include "yuzu/configuration/configure_input_player.h"
2021-10-09 02:29:53 +02: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 16:15:37 +01:00
#include "yuzu/hotkeys.h"
2022-04-17 12:38:11 +02:00
#include "yuzu/uisettings.h"
2020-12-28 16:15:37 +01:00
2022-06-15 19:54:21 +02:00
ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_,
2021-10-09 02:29:53 +02:00
InputCommon::InputSubsystem* input_subsystem,
2022-07-26 03:25:01 +02:00
Core::System& system_, bool enable_web_config)
: QDialog(parent), ui{std::make_unique<Ui::ConfigureDialog>()},
registry(registry_), system{system_}, audio_tab{std::make_unique<ConfigureAudio>(system_,
this)},
2021-10-09 02:29:53 +02:00
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 21:59:21 +01:00
hotkeys_tab{std::make_unique<ConfigureHotkeys>(system_.HIDCore(), this)},
2021-10-09 02:29:53 +02: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 16:15:37 +01:00
Settings::SetConfiguringGlobal(true);
ui->setupUi(this);
2021-10-09 02:29:53 +02: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"));
2022-07-26 03:25:01 +02:00
web_tab->SetWebServiceConfigEnabled(enable_web_config);
2021-10-09 02:29:53 +02:00
hotkeys_tab->Populate(registry);
2020-12-28 16:15:37 +01:00
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
2021-11-05 16:31:40 +01:00
input_tab->Initialize(input_subsystem);
2020-12-28 16:15:37 +01:00
2021-10-09 02:29:53 +02:00
general_tab->SetResetCallback([&] { this->close(); });
2021-06-04 10:40:16 +02:00
2020-12-28 16:15:37 +01:00
SetConfiguration();
PopulateSelectionList();
2021-10-27 05:22:08 +02:00
connect(ui->tabWidget, &QTabWidget::currentChanged, this, [this](int index) {
if (index != -1) {
debug_tab_tab->SetCurrentIndex(0);
}
});
2021-10-09 02:29:53 +02:00
connect(ui_tab.get(), &ConfigureUi::LanguageChanged, this, &ConfigureDialog::OnLanguageChanged);
2020-12-28 16:15:37 +01:00
connect(ui->selectorList, &QListWidget::itemSelectionChanged, this,
&ConfigureDialog::UpdateVisibleTabs);
2021-10-09 02:29:53 +02:00
if (system.IsPoweredOn()) {
2021-05-21 09:31:35 +02:00
QPushButton* apply_button = ui->buttonBox->addButton(QDialogButtonBox::Apply);
connect(apply_button, &QAbstractButton::clicked, this,
&ConfigureDialog::HandleApplyButtonClicked);
}
2020-12-28 16:15:37 +01:00
adjustSize();
ui->selectorList->setCurrentRow(0);
}
ConfigureDialog::~ConfigureDialog() = default;
void ConfigureDialog::SetConfiguration() {}
void ConfigureDialog::ApplyConfiguration() {
2021-10-09 02:29:53 +02:00
general_tab->ApplyConfiguration();
ui_tab->ApplyConfiguration();
system_tab->ApplyConfiguration();
profile_tab->ApplyConfiguration();
2022-02-02 05:57:17 +01:00
filesystem_tab->ApplyConfiguration();
2021-10-09 02:29:53 +02: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 16:15:37 +01: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 09:31:35 +02:00
void ConfigureDialog::HandleApplyButtonClicked() {
UISettings::values.configuration_applied = true;
ApplyConfiguration();
}
2020-12-28 16:15:37 +01:00
Q_DECLARE_METATYPE(QList<QWidget*>);
void ConfigureDialog::PopulateSelectionList() {
const std::array<std::pair<QString, QList<QWidget*>>, 6> items{
2021-10-09 02:29:53 +02: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 16:15:37 +01: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);
2022-04-17 12:38:11 +02:00
// Reloading the game list is needed to force retranslation.
UISettings::values.is_game_list_reload_pending = true;
2020-12-28 16:15:37 +01:00
// 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 01:27:20 +01:00
const auto tabs = qvariant_cast<QList<QWidget*>>(items[0]->data(Qt::UserRole));
2020-12-28 16:15:37 +01:00
2021-01-15 01:27:20 +01:00
for (auto* const tab : tabs) {
2021-10-09 02:29:53 +02:00
LOG_DEBUG(Frontend, "{}", tab->accessibleName().toStdString());
2020-12-28 16:15:37 +01:00
ui->tabWidget->addTab(tab, tab->accessibleName());
}
}