shared_widget: Support checkbox + spinbox
This commit is contained in:
parent
def00e8c55
commit
97674bc888
|
@ -240,7 +240,7 @@ void ConfigureGraphics::Setup() {
|
|||
return new ConfigurationShared::Widget(
|
||||
setting, translations, this, runtime_lock, apply_funcs,
|
||||
ConfigurationShared::RequestType::LineEdit, true, 1.0f,
|
||||
Settings::values.speed_limit.ToString());
|
||||
&Settings::values.speed_limit, QString::fromStdString("%"));
|
||||
} else {
|
||||
return new ConfigurationShared::Widget(setting, translations, this, runtime_lock,
|
||||
apply_funcs);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QSizePolicy>
|
||||
#include <QSpinBox>
|
||||
#include <QWidget>
|
||||
#include <qabstractbutton.h>
|
||||
#include "common/settings.h"
|
||||
|
@ -234,7 +235,8 @@ void Widget::CreateSlider(const QString& name, bool reversed, float multiplier,
|
|||
}
|
||||
}
|
||||
|
||||
void Widget::CreateCheckBoxWithLineEdit(const QString& label, const std::string& text_box_default,
|
||||
void Widget::CreateCheckBoxWithLineEdit(const QString& label,
|
||||
const Settings::BasicSetting* other_setting,
|
||||
std::function<void()>& load_func) {
|
||||
created = true;
|
||||
|
||||
|
@ -243,7 +245,7 @@ void Widget::CreateCheckBoxWithLineEdit(const QString& label, const std::string&
|
|||
QHBoxLayout* layout = reinterpret_cast<QHBoxLayout*>(this->layout());
|
||||
|
||||
line_edit = new QLineEdit(this);
|
||||
line_edit->setText(QString::fromStdString(text_box_default));
|
||||
line_edit->setText(QString::fromStdString(other_setting->ToString()));
|
||||
|
||||
checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
|
||||
|
@ -254,7 +256,7 @@ void Widget::CreateCheckBoxWithLineEdit(const QString& label, const std::string&
|
|||
|
||||
if (!Settings::IsConfiguringGlobal()) {
|
||||
QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) {
|
||||
line_edit->setText(QString::fromStdString(text_box_default));
|
||||
line_edit->setText(QString::fromStdString(other_setting->ToString()));
|
||||
});
|
||||
|
||||
QObject::connect(line_edit, &QLineEdit::textEdited, [=](const QString&) {
|
||||
|
@ -264,6 +266,41 @@ void Widget::CreateCheckBoxWithLineEdit(const QString& label, const std::string&
|
|||
}
|
||||
}
|
||||
|
||||
void Widget::CreateCheckBoxWithSpinBox(const QString& label,
|
||||
const Settings::BasicSetting* other_setting,
|
||||
std::function<void()>& load_func, const QString& suffix) {
|
||||
created = true;
|
||||
|
||||
CreateCheckBox(label, load_func);
|
||||
checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
|
||||
QHBoxLayout* layout = reinterpret_cast<QHBoxLayout*>(this->layout());
|
||||
|
||||
spinbox = new QSpinBox(this);
|
||||
const int min_val = std::stoi(other_setting->MinVal());
|
||||
const int max_val = std::stoi(other_setting->MaxVal());
|
||||
spinbox->setRange(min_val, max_val);
|
||||
spinbox->setValue(std::stoi(other_setting->ToString()));
|
||||
spinbox->setSuffix(suffix);
|
||||
spinbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
|
||||
layout->insertWidget(1, spinbox);
|
||||
|
||||
QObject::connect(spinbox, QOverload<int>::of(&QSpinBox::valueChanged),
|
||||
[this](int) { checkbox->setCheckState(Qt::Checked); });
|
||||
|
||||
if (!Settings::IsConfiguringGlobal()) {
|
||||
QObject::connect(restore_button, &QAbstractButton::clicked, [this, other_setting](bool) {
|
||||
spinbox->setValue(std::stoi(other_setting->ToString()));
|
||||
});
|
||||
|
||||
QObject::connect(spinbox, QOverload<int>::of(&QSpinBox::valueChanged), [this](int) {
|
||||
restore_button->setEnabled(true);
|
||||
restore_button->setVisible(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
bool Widget::Valid() {
|
||||
return created;
|
||||
}
|
||||
|
@ -273,7 +310,8 @@ Widget::~Widget() = default;
|
|||
Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translations_,
|
||||
QWidget* parent_, bool runtime_lock,
|
||||
std::forward_list<std::function<void(bool)>>& apply_funcs, RequestType request,
|
||||
bool managed, float multiplier, const std::string& text_box_default)
|
||||
bool managed, float multiplier, const Settings::BasicSetting* other_setting,
|
||||
const QString& format)
|
||||
: QWidget(parent_), parent{parent_}, translations{translations_}, setting{*setting_} {
|
||||
if (!Settings::IsConfiguringGlobal() && !setting.Switchable()) {
|
||||
LOG_DEBUG(Frontend, "\"{}\" is not switchable, skipping...", setting.GetLabel());
|
||||
|
@ -306,8 +344,10 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati
|
|||
CreateCheckBox(label, load_func);
|
||||
break;
|
||||
case RequestType::LineEdit:
|
||||
CreateCheckBoxWithLineEdit(label, other_setting, load_func);
|
||||
break;
|
||||
case RequestType::SpinBox:
|
||||
CreateCheckBoxWithLineEdit(label, text_box_default, load_func);
|
||||
CreateCheckBoxWithSpinBox(label, other_setting, load_func, format);
|
||||
break;
|
||||
case RequestType::ComboBox:
|
||||
case RequestType::Slider:
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "yuzu/configuration/shared_translation.h"
|
||||
|
||||
class QPushButton;
|
||||
class QSpinBox;
|
||||
class QComboBox;
|
||||
class QLineEdit;
|
||||
class QSlider;
|
||||
|
@ -32,7 +33,8 @@ public:
|
|||
Widget(Settings::BasicSetting* setting, const TranslationMap& translations, QWidget* parent,
|
||||
bool runtime_lock, std::forward_list<std::function<void(bool)>>& apply_funcs,
|
||||
RequestType request = RequestType::Default, bool managed = true, float multiplier = 1.0f,
|
||||
const std::string& text_box_default = "");
|
||||
const Settings::BasicSetting* other_setting = nullptr,
|
||||
const QString& format = QStringLiteral(""));
|
||||
virtual ~Widget();
|
||||
|
||||
bool Valid();
|
||||
|
@ -42,16 +44,19 @@ public:
|
|||
|
||||
QPushButton* restore_button{};
|
||||
QLineEdit* line_edit{};
|
||||
QSpinBox* spinbox{};
|
||||
QCheckBox* checkbox{};
|
||||
QSlider* slider{};
|
||||
QComboBox* combobox{};
|
||||
|
||||
private:
|
||||
void CreateCheckBox(const QString& label, std::function<void()>& load_func);
|
||||
void CreateCheckBoxWithLineEdit(const QString& label, const std::string& text_box_default,
|
||||
void CreateCheckBoxWithLineEdit(const QString& label,
|
||||
const Settings::BasicSetting* other_setting,
|
||||
std::function<void()>& load_func);
|
||||
void CreateCheckBoxWithSpinBox(const QString& label, const std::string& text_box_default,
|
||||
std::function<void()>& load_func);
|
||||
void CreateCheckBoxWithSpinBox(const QString& label,
|
||||
const Settings::BasicSetting* other_setting,
|
||||
std::function<void()>& load_func, const QString& suffix);
|
||||
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 CreateSlider(const QString& label, bool reversed, float multiplier,
|
||||
|
|
Loading…
Reference in New Issue