summaryrefslogtreecommitdiffstats
path: root/src/yuzu/configuration/configuration_shared.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/yuzu/configuration/configuration_shared.cpp')
-rw-r--r--src/yuzu/configuration/configuration_shared.cpp177
1 files changed, 108 insertions, 69 deletions
diff --git a/src/yuzu/configuration/configuration_shared.cpp b/src/yuzu/configuration/configuration_shared.cpp
index 8d5ab8b4c..45165c2e9 100644
--- a/src/yuzu/configuration/configuration_shared.cpp
+++ b/src/yuzu/configuration/configuration_shared.cpp
@@ -2,119 +2,151 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <memory>
+#include <QBoxLayout>
#include <QCheckBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QObject>
+#include <QPushButton>
#include <QString>
+#include <QStyle>
#include <QWidget>
+#include <qabstractbutton.h>
#include <qcheckbox.h>
+#include <qcombobox.h>
#include <qnamespace.h>
+#include <qsizepolicy.h>
#include "common/settings.h"
#include "yuzu/configuration/configuration_shared.h"
#include "yuzu/configuration/configure_per_game.h"
#include "yuzu/configuration/shared_translation.h"
namespace ConfigurationShared {
+
+static QPushButton* CreateClearGlobalButton(QWidget* parent, Settings::BasicSetting* setting) {
+ QStyle* style = parent->style();
+ QIcon* icon = new QIcon(style->standardIcon(QStyle::SP_DialogResetButton));
+ QPushButton* button = new QPushButton(*icon, QStringLiteral(""), parent);
+ button->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding);
+
+ QSizePolicy sp_retain = button->sizePolicy();
+ sp_retain.setRetainSizeWhenHidden(true);
+ button->setSizePolicy(sp_retain);
+
+ button->setEnabled(!setting->UsingGlobal());
+ button->setVisible(!setting->UsingGlobal());
+
+ return button;
+}
+
static std::pair<QWidget*, std::function<void()>> CreateCheckBox(Settings::BasicSetting* setting,
const QString& label,
QWidget* parent,
std::list<CheckState>& trackers) {
+ QWidget* widget = new QWidget(parent);
+ QHBoxLayout* layout = new QHBoxLayout(widget);
+
QCheckBox* checkbox = new QCheckBox(label, parent);
checkbox->setObjectName(QString::fromStdString(setting->GetLabel()));
checkbox->setCheckState(setting->ToString() == "true" ? Qt::CheckState::Checked
: Qt::CheckState::Unchecked);
- CheckState* tracker{};
-
- // Per-game config highlight
- if (setting->Switchable() && !Settings::IsConfiguringGlobal()) {
- bool global_state = setting->ToStringGlobal() == "true";
- bool state = setting->ToString() == "true";
- bool global = setting->UsingGlobal();
- tracker = &trackers.emplace_front(CheckState{});
- SetColoredTristate(checkbox, global, state, global_state, *tracker);
- }
+ std::function<void()> load_func;
- auto load_func = [checkbox, setting, tracker]() {
- if (Settings::IsConfiguringGlobal()) {
+ layout->addWidget(checkbox);
+ if (Settings::IsConfiguringGlobal()) {
+ load_func = [setting, checkbox]() {
setting->LoadString(checkbox->checkState() == Qt::Checked ? "true" : "false");
- }
-
- if (Settings::IsConfiguringGlobal() || !setting->Switchable()) {
- return;
- }
+ };
+ } else {
+ auto* button = CreateClearGlobalButton(parent, setting);
+ layout->addWidget(button);
+
+ QObject::connect(checkbox, &QCheckBox::stateChanged, [button](int) {
+ button->setVisible(true);
+ button->setEnabled(true);
+ });
+
+ QObject::connect(button, &QAbstractButton::clicked, [checkbox, setting, button](bool) {
+ checkbox->setCheckState(setting->ToStringGlobal() == "true" ? Qt::Checked
+ : Qt::Unchecked);
+ button->setEnabled(false);
+ button->setVisible(false);
+ });
+
+ load_func = [setting, checkbox, button]() {
+ bool using_global = !button->isEnabled();
+ setting->SetGlobal(using_global);
+ if (!using_global) {
+ setting->LoadString(checkbox->checkState() == Qt::Checked ? "true" : "false");
+ }
+ };
+ }
- if (*tracker != CheckState::Global) {
- setting->SetGlobal(false);
- setting->LoadString(checkbox->checkState() == Qt::Checked ? "true" : "false");
- } else {
- setting->SetGlobal(true);
- }
- };
+ layout->setContentsMargins(0, 0, 0, 0);
- return {checkbox, load_func};
+ return {widget, load_func};
}
-static std::tuple<QWidget*, void*, std::function<void()>> CreateCombobox(
+static std::tuple<QWidget*, QComboBox*, QPushButton*, std::function<void()>> CreateCombobox(
Settings::BasicSetting* setting, const QString& label, QWidget* parent, bool managed) {
const auto type = setting->TypeId();
QWidget* group = new QWidget(parent);
group->setObjectName(QString::fromStdString(setting->GetLabel()));
- QLayout* combobox_layout = new QHBoxLayout(group);
+ QLayout* layout = new QHBoxLayout(group);
QLabel* qt_label = new QLabel(label, parent);
QComboBox* combobox = new QComboBox(parent);
+ QPushButton* button{nullptr};
+
std::forward_list<QString> combobox_enumerations = ComboboxEnumeration(type, parent);
for (const auto& item : combobox_enumerations) {
combobox->addItem(item);
}
- combobox_layout->addWidget(qt_label);
- combobox_layout->addWidget(combobox);
+ layout->addWidget(qt_label);
+ layout->addWidget(combobox);
- combobox_layout->setSpacing(6);
- combobox_layout->setContentsMargins(0, 0, 0, 0);
+ layout->setSpacing(6);
+ layout->setContentsMargins(0, 0, 0, 0);
- if (setting->Switchable() && !Settings::IsConfiguringGlobal() && managed) {
- int current = std::stoi(setting->ToString());
- int global_value = std::stoi(setting->ToStringGlobal());
- SetColoredComboBox(combobox, group, global_value);
- if (setting->UsingGlobal()) {
- combobox->setCurrentIndex(USE_GLOBAL_INDEX);
- } else {
- SetHighlight(group, true);
- combobox->setCurrentIndex(current + USE_GLOBAL_OFFSET);
- }
- } else {
- combobox->setCurrentIndex(std::stoi(setting->ToString()));
- }
+ combobox->setCurrentIndex(std::stoi(setting->ToString()));
std::function<void()> load_func = []() {};
- if (managed) {
- load_func = [combobox, setting]() {
- if (Settings::IsConfiguringGlobal()) {
- setting->LoadString(std::to_string(combobox->currentIndex()));
- }
- if (Settings::IsConfiguringGlobal() || !setting->Switchable()) {
- return;
- }
+ if (Settings::IsConfiguringGlobal() && managed) {
+ load_func = [setting, combobox]() {
+ setting->LoadString(std::to_string(combobox->currentIndex()));
+ };
+ } else if (managed) {
+ button = CreateClearGlobalButton(parent, setting);
+ layout->addWidget(button);
+
+ QObject::connect(button, &QAbstractButton::clicked, [button, combobox, setting](bool) {
+ button->setEnabled(false);
+ button->setVisible(false);
+
+ combobox->setCurrentIndex(std::stoi(setting->ToStringGlobal()));
+ });
- bool using_global = combobox->currentIndex() == USE_GLOBAL_INDEX;
- int index = combobox->currentIndex() - USE_GLOBAL_OFFSET;
+ QObject::connect(combobox, QOverload<int>::of(&QComboBox::activated), [=](int) {
+ button->setEnabled(true);
+ button->setVisible(true);
+ });
+ load_func = [setting, combobox, button]() {
+ bool using_global = !button->isEnabled();
setting->SetGlobal(using_global);
if (!using_global) {
- setting->LoadString(std::to_string(index));
+ setting->LoadString(std::to_string(combobox->currentIndex()));
}
};
}
- return {group, combobox, load_func};
+ return {group, combobox, button, load_func};
}
static std::tuple<QWidget*, void*, std::function<void()>> CreateLineEdit(
@@ -136,7 +168,7 @@ static std::tuple<QWidget*, void*, std::function<void()>> CreateLineEdit(
q_label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
layout->addWidget(q_label);
- load_func = [&]() {
+ load_func = [line_edit, setting]() {
std::string load_text = line_edit->text().toStdString();
setting->LoadString(load_text);
};
@@ -157,7 +189,7 @@ static std::tuple<QWidget*, void*, std::function<void()>> CreateLineEdit(
checkbox->setCheckState(setting->UsingGlobal() ? Qt::Unchecked : Qt::Checked);
highlight_func(checkbox->checkState());
- load_func = [&]() {
+ load_func = [checkbox, setting, line_edit]() {
if (checkbox->checkState() == Qt::Checked) {
setting->SetGlobal(false);
@@ -176,12 +208,15 @@ static std::tuple<QWidget*, void*, std::function<void()>> CreateLineEdit(
return {widget, line_edit, load_func};
}
-std::pair<QWidget*, void*> CreateWidget(Settings::BasicSetting* setting,
- const TranslationMap& translations, QWidget* parent,
- bool runtime_lock,
- std::forward_list<std::function<void(bool)>>& apply_funcs,
- std::list<CheckState>& trackers, RequestType request,
- bool managed) {
+std::tuple<QWidget*, void*, QPushButton*> CreateWidget(
+ Settings::BasicSetting* setting, const TranslationMap& translations, QWidget* parent,
+ bool runtime_lock, std::forward_list<std::function<void(bool)>>& apply_funcs,
+ std::list<CheckState>& trackers, RequestType request, bool managed) {
+ if (!Settings::IsConfiguringGlobal() && !setting->Switchable()) {
+ LOG_DEBUG(Frontend, "\"{}\" is not switchable, skipping...", setting->GetLabel());
+ return {nullptr, nullptr, nullptr};
+ }
+
const auto type = setting->TypeId();
const int id = setting->Id();
QWidget* widget{nullptr};
@@ -201,9 +236,11 @@ std::pair<QWidget*, void*> CreateWidget(Settings::BasicSetting* setting,
if (label == QStringLiteral("")) {
LOG_DEBUG(Frontend, "Translation table has emtpy entry for \"{}\", skipping...",
setting->GetLabel());
- return {nullptr, nullptr};
+ return {nullptr, nullptr, nullptr};
}
+ QPushButton* button;
+
if (type == typeid(bool)) {
auto pair = CreateCheckBox(setting, label, parent, trackers);
widget = pair.first;
@@ -212,7 +249,8 @@ std::pair<QWidget*, void*> CreateWidget(Settings::BasicSetting* setting,
auto tuple = CreateCombobox(setting, label, parent, managed);
widget = std::get<0>(tuple);
extra = std::get<1>(tuple);
- load_func = std::get<2>(tuple);
+ button = std::get<2>(tuple);
+ load_func = std::get<3>(tuple);
} else if (type == typeid(u32) || type == typeid(int)) {
switch (request) {
case RequestType::Default: {
@@ -226,7 +264,8 @@ std::pair<QWidget*, void*> CreateWidget(Settings::BasicSetting* setting,
auto tuple = CreateCombobox(setting, label, parent, managed);
widget = std::get<0>(tuple);
extra = std::get<1>(tuple);
- load_func = std::get<2>(tuple);
+ button = std::get<2>(tuple);
+ load_func = std::get<3>(tuple);
break;
}
case RequestType::SpinBox:
@@ -238,7 +277,7 @@ std::pair<QWidget*, void*> CreateWidget(Settings::BasicSetting* setting,
if (widget == nullptr) {
LOG_ERROR(Frontend, "No widget was created for \"{}\"", setting->GetLabel());
- return {nullptr, nullptr};
+ return {nullptr, nullptr, nullptr};
}
apply_funcs.push_front([load_func, setting](bool powered_on) {
@@ -257,7 +296,7 @@ std::pair<QWidget*, void*> CreateWidget(Settings::BasicSetting* setting,
widget->setToolTip(tooltip);
- return {widget, extra};
+ return {widget, extra, button};
}
Tab::Tab(std::shared_ptr<std::forward_list<Tab*>> group_, QWidget* parent)