forked from suyu/suyu
shared_widget: Internalize extra setting configuration
This commit is contained in:
parent
cdb5dea269
commit
b11a2a206f
3 changed files with 66 additions and 48 deletions
|
@ -273,25 +273,6 @@ void ConfigureGraphics::Setup() {
|
||||||
hold_api.push_front(widget);
|
hold_api.push_front(widget);
|
||||||
shader_backend_combobox = widget->combobox;
|
shader_backend_combobox = widget->combobox;
|
||||||
shader_backend_widget = widget;
|
shader_backend_widget = widget;
|
||||||
} else if (setting->Id() == Settings::values.use_speed_limit.Id()) {
|
|
||||||
apply_funcs.push_front([setting, widget](bool powered_on) {
|
|
||||||
if (!setting->RuntimeModfiable() && powered_on) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
u16 value = QVariant(widget->line_edit->text()).value<u16>();
|
|
||||||
auto& speed_limit = Settings::values.speed_limit;
|
|
||||||
if (Settings::IsConfiguringGlobal()) {
|
|
||||||
speed_limit.SetValue(value);
|
|
||||||
} else {
|
|
||||||
bool using_global = !widget->restore_button->isVisible();
|
|
||||||
speed_limit.SetGlobal(using_global);
|
|
||||||
if (!using_global) {
|
|
||||||
speed_limit.SetValue(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
hold_graphics[setting->IsEnum()][setting_label] = widget;
|
|
||||||
} else if (setting->Id() == Settings::values.vsync_mode.Id()) {
|
} else if (setting->Id() == Settings::values.vsync_mode.Id()) {
|
||||||
vsync_mode_combobox = widget->combobox;
|
vsync_mode_combobox = widget->combobox;
|
||||||
hold_graphics[setting->IsEnum()][setting_label] = widget;
|
hold_graphics[setting->IsEnum()][setting_label] = widget;
|
||||||
|
|
|
@ -9,12 +9,18 @@
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <qabstractbutton.h>
|
#include <qabstractbutton.h>
|
||||||
|
#include "common/common_types.h"
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
|
#include "yuzu/configuration/configuration_shared.h"
|
||||||
#include "yuzu/configuration/shared_translation.h"
|
#include "yuzu/configuration/shared_translation.h"
|
||||||
#include "yuzu/configuration/shared_widget.h"
|
#include "yuzu/configuration/shared_widget.h"
|
||||||
|
|
||||||
namespace ConfigurationShared {
|
namespace ConfigurationShared {
|
||||||
|
|
||||||
|
static bool IsInt(const std::type_index& type) {
|
||||||
|
return type == typeid(u32) || type == typeid(s32) || type == typeid(u16) || type == typeid(s16);
|
||||||
|
}
|
||||||
|
|
||||||
QPushButton* Widget::CreateRestoreGlobalButton(Settings::BasicSetting& setting, QWidget* parent) {
|
QPushButton* Widget::CreateRestoreGlobalButton(Settings::BasicSetting& setting, QWidget* parent) {
|
||||||
QStyle* style = parent->style();
|
QStyle* style = parent->style();
|
||||||
QIcon* icon = new QIcon(style->standardIcon(QStyle::SP_DialogResetButton));
|
QIcon* icon = new QIcon(style->standardIcon(QStyle::SP_DialogResetButton));
|
||||||
|
@ -235,43 +241,63 @@ void Widget::CreateSlider(const QString& name, bool reversed, float multiplier,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::CreateCheckBoxWithLineEdit(const QString& label,
|
void Widget::CreateCheckBoxWithLineEdit(const QString& label, Settings::BasicSetting* other_setting,
|
||||||
const Settings::BasicSetting* other_setting,
|
|
||||||
std::function<void()>& load_func) {
|
std::function<void()>& load_func) {
|
||||||
|
if (other_setting == nullptr) {
|
||||||
|
LOG_WARNING(Frontend, "Extra setting is null or not an integer");
|
||||||
|
return;
|
||||||
|
}
|
||||||
created = true;
|
created = true;
|
||||||
|
|
||||||
CreateCheckBox(label, load_func);
|
std::function<void()> checkbox_load_func;
|
||||||
|
CreateCheckBox(label, checkbox_load_func);
|
||||||
|
|
||||||
QHBoxLayout* layout = reinterpret_cast<QHBoxLayout*>(this->layout());
|
QHBoxLayout* layout = reinterpret_cast<QHBoxLayout*>(this->layout());
|
||||||
|
const QString default_val = QString::fromStdString(other_setting->ToString());
|
||||||
|
|
||||||
line_edit = new QLineEdit(this);
|
line_edit = new QLineEdit(this);
|
||||||
line_edit->setText(QString::fromStdString(other_setting->ToString()));
|
line_edit->setText(default_val);
|
||||||
|
|
||||||
checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||||
|
|
||||||
layout->insertWidget(1, line_edit);
|
layout->insertWidget(1, line_edit);
|
||||||
|
|
||||||
QObject::connect(line_edit, &QLineEdit::textEdited,
|
if (Settings::IsConfiguringGlobal()) {
|
||||||
[=](const QString&) { checkbox->setCheckState(Qt::Checked); });
|
load_func = [=]() {
|
||||||
|
checkbox_load_func();
|
||||||
if (!Settings::IsConfiguringGlobal()) {
|
other_setting->LoadString(line_edit->text().toStdString());
|
||||||
QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) {
|
};
|
||||||
line_edit->setText(QString::fromStdString(other_setting->ToString()));
|
} else {
|
||||||
});
|
QObject::connect(restore_button, &QAbstractButton::clicked,
|
||||||
|
[=](bool) { line_edit->setText(default_val); });
|
||||||
|
|
||||||
QObject::connect(line_edit, &QLineEdit::textEdited, [=](const QString&) {
|
QObject::connect(line_edit, &QLineEdit::textEdited, [=](const QString&) {
|
||||||
restore_button->setEnabled(true);
|
restore_button->setEnabled(true);
|
||||||
restore_button->setVisible(true);
|
restore_button->setVisible(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
load_func = [=]() {
|
||||||
|
checkbox_load_func();
|
||||||
|
|
||||||
|
const bool using_global = !restore_button->isVisible();
|
||||||
|
other_setting->SetGlobal(using_global);
|
||||||
|
if (!using_global) {
|
||||||
|
other_setting->LoadString(line_edit->text().toStdString());
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::CreateCheckBoxWithSpinBox(const QString& label,
|
void Widget::CreateCheckBoxWithSpinBox(const QString& label, Settings::BasicSetting* other_setting,
|
||||||
const Settings::BasicSetting* other_setting,
|
|
||||||
std::function<void()>& load_func, const QString& suffix) {
|
std::function<void()>& load_func, const QString& suffix) {
|
||||||
|
if (other_setting == nullptr && IsInt(other_setting->TypeId())) {
|
||||||
|
LOG_WARNING(Frontend, "Extra setting is null or not an integer");
|
||||||
|
return;
|
||||||
|
}
|
||||||
created = true;
|
created = true;
|
||||||
|
|
||||||
CreateCheckBox(label, load_func);
|
std::function<void()> checkbox_load_func;
|
||||||
|
CreateCheckBox(label, checkbox_load_func);
|
||||||
checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||||
|
|
||||||
QHBoxLayout* layout = reinterpret_cast<QHBoxLayout*>(this->layout());
|
QHBoxLayout* layout = reinterpret_cast<QHBoxLayout*>(this->layout());
|
||||||
|
@ -279,17 +305,20 @@ void Widget::CreateCheckBoxWithSpinBox(const QString& label,
|
||||||
spinbox = new QSpinBox(this);
|
spinbox = new QSpinBox(this);
|
||||||
const int min_val = std::stoi(other_setting->MinVal());
|
const int min_val = std::stoi(other_setting->MinVal());
|
||||||
const int max_val = std::stoi(other_setting->MaxVal());
|
const int max_val = std::stoi(other_setting->MaxVal());
|
||||||
|
const int default_val = std::stoi(other_setting->ToString());
|
||||||
spinbox->setRange(min_val, max_val);
|
spinbox->setRange(min_val, max_val);
|
||||||
spinbox->setValue(std::stoi(other_setting->ToString()));
|
spinbox->setValue(default_val);
|
||||||
spinbox->setSuffix(suffix);
|
spinbox->setSuffix(suffix);
|
||||||
spinbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
spinbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||||
|
|
||||||
layout->insertWidget(1, spinbox);
|
layout->insertWidget(1, spinbox);
|
||||||
|
|
||||||
QObject::connect(spinbox, QOverload<int>::of(&QSpinBox::valueChanged),
|
if (Settings::IsConfiguringGlobal()) {
|
||||||
[this](int) { checkbox->setCheckState(Qt::Checked); });
|
load_func = [=]() {
|
||||||
|
checkbox_load_func();
|
||||||
if (!Settings::IsConfiguringGlobal()) {
|
other_setting->LoadString(std::to_string(spinbox->value()));
|
||||||
|
};
|
||||||
|
} else {
|
||||||
QObject::connect(restore_button, &QAbstractButton::clicked, [this, other_setting](bool) {
|
QObject::connect(restore_button, &QAbstractButton::clicked, [this, other_setting](bool) {
|
||||||
spinbox->setValue(std::stoi(other_setting->ToString()));
|
spinbox->setValue(std::stoi(other_setting->ToString()));
|
||||||
});
|
});
|
||||||
|
@ -298,6 +327,16 @@ void Widget::CreateCheckBoxWithSpinBox(const QString& label,
|
||||||
restore_button->setEnabled(true);
|
restore_button->setEnabled(true);
|
||||||
restore_button->setVisible(true);
|
restore_button->setVisible(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
load_func = [=]() {
|
||||||
|
checkbox_load_func();
|
||||||
|
|
||||||
|
const bool using_global = !restore_button->isVisible();
|
||||||
|
other_setting->SetGlobal(using_global);
|
||||||
|
if (!using_global) {
|
||||||
|
other_setting->LoadString(std::to_string(spinbox->value()));
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,7 +349,7 @@ Widget::~Widget() = default;
|
||||||
Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translations_,
|
Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translations_,
|
||||||
QWidget* parent_, bool runtime_lock,
|
QWidget* parent_, bool runtime_lock,
|
||||||
std::forward_list<std::function<void(bool)>>& apply_funcs, RequestType request,
|
std::forward_list<std::function<void(bool)>>& apply_funcs, RequestType request,
|
||||||
bool managed, float multiplier, const Settings::BasicSetting* other_setting,
|
bool managed, float multiplier, Settings::BasicSetting* other_setting,
|
||||||
const QString& format)
|
const QString& format)
|
||||||
: QWidget(parent_), parent{parent_}, translations{translations_}, setting{*setting_} {
|
: QWidget(parent_), parent{parent_}, translations{translations_}, setting{*setting_} {
|
||||||
if (!Settings::IsConfiguringGlobal() && !setting.Switchable()) {
|
if (!Settings::IsConfiguringGlobal() && !setting.Switchable()) {
|
||||||
|
@ -340,15 +379,15 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati
|
||||||
|
|
||||||
if (type == typeid(bool)) {
|
if (type == typeid(bool)) {
|
||||||
switch (request) {
|
switch (request) {
|
||||||
|
case RequestType::SpinBox:
|
||||||
|
CreateCheckBoxWithSpinBox(label, other_setting, load_func, format);
|
||||||
|
break;
|
||||||
case RequestType::Default:
|
case RequestType::Default:
|
||||||
CreateCheckBox(label, load_func);
|
CreateCheckBox(label, load_func);
|
||||||
break;
|
break;
|
||||||
case RequestType::LineEdit:
|
case RequestType::LineEdit:
|
||||||
CreateCheckBoxWithLineEdit(label, other_setting, load_func);
|
CreateCheckBoxWithLineEdit(label, other_setting, load_func);
|
||||||
break;
|
break;
|
||||||
case RequestType::SpinBox:
|
|
||||||
CreateCheckBoxWithSpinBox(label, other_setting, load_func, format);
|
|
||||||
break;
|
|
||||||
case RequestType::ComboBox:
|
case RequestType::ComboBox:
|
||||||
case RequestType::Slider:
|
case RequestType::Slider:
|
||||||
case RequestType::ReverseSlider:
|
case RequestType::ReverseSlider:
|
||||||
|
@ -377,7 +416,7 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!created) {
|
if (!created) {
|
||||||
LOG_ERROR(Frontend, "No widget was created for \"{}\"", setting.GetLabel());
|
LOG_WARNING(Frontend, "No widget was created for \"{}\"", setting.GetLabel());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ public:
|
||||||
Widget(Settings::BasicSetting* setting, const TranslationMap& translations, QWidget* parent,
|
Widget(Settings::BasicSetting* setting, const TranslationMap& translations, QWidget* parent,
|
||||||
bool runtime_lock, std::forward_list<std::function<void(bool)>>& apply_funcs,
|
bool runtime_lock, std::forward_list<std::function<void(bool)>>& apply_funcs,
|
||||||
RequestType request = RequestType::Default, bool managed = true, float multiplier = 1.0f,
|
RequestType request = RequestType::Default, bool managed = true, float multiplier = 1.0f,
|
||||||
const Settings::BasicSetting* other_setting = nullptr,
|
Settings::BasicSetting* other_setting = nullptr,
|
||||||
const QString& format = QStringLiteral(""));
|
const QString& format = QStringLiteral(""));
|
||||||
virtual ~Widget();
|
virtual ~Widget();
|
||||||
|
|
||||||
|
@ -51,11 +51,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void CreateCheckBox(const QString& label, std::function<void()>& load_func);
|
void CreateCheckBox(const QString& label, std::function<void()>& load_func);
|
||||||
void CreateCheckBoxWithLineEdit(const QString& label,
|
void CreateCheckBoxWithLineEdit(const QString& label, Settings::BasicSetting* other_setting,
|
||||||
const Settings::BasicSetting* other_setting,
|
|
||||||
std::function<void()>& load_func);
|
std::function<void()>& load_func);
|
||||||
void CreateCheckBoxWithSpinBox(const QString& label,
|
void CreateCheckBoxWithSpinBox(const QString& label, Settings::BasicSetting* other_setting,
|
||||||
const Settings::BasicSetting* other_setting,
|
|
||||||
std::function<void()>& load_func, const QString& suffix);
|
std::function<void()>& load_func, const QString& suffix);
|
||||||
void CreateCombobox(const QString& label, bool managed, std::function<void()>& load_func);
|
void CreateCombobox(const QString& label, bool managed, std::function<void()>& load_func);
|
||||||
void CreateLineEdit(const QString& label, bool managed, std::function<void()>& load_func);
|
void CreateLineEdit(const QString& label, bool managed, std::function<void()>& load_func);
|
||||||
|
|
Loading…
Reference in a new issue