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(
|
return new ConfigurationShared::Widget(
|
||||||
setting, translations, this, runtime_lock, apply_funcs,
|
setting, translations, this, runtime_lock, apply_funcs,
|
||||||
ConfigurationShared::RequestType::LineEdit, true, 1.0f,
|
ConfigurationShared::RequestType::LineEdit, true, 1.0f,
|
||||||
Settings::values.speed_limit.ToString());
|
&Settings::values.speed_limit, QString::fromStdString("%"));
|
||||||
} else {
|
} else {
|
||||||
return new ConfigurationShared::Widget(setting, translations, this, runtime_lock,
|
return new ConfigurationShared::Widget(setting, translations, this, runtime_lock,
|
||||||
apply_funcs);
|
apply_funcs);
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QSizePolicy>
|
#include <QSizePolicy>
|
||||||
|
#include <QSpinBox>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <qabstractbutton.h>
|
#include <qabstractbutton.h>
|
||||||
#include "common/settings.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) {
|
std::function<void()>& load_func) {
|
||||||
created = true;
|
created = true;
|
||||||
|
|
||||||
|
@ -243,7 +245,7 @@ void Widget::CreateCheckBoxWithLineEdit(const QString& label, const std::string&
|
||||||
QHBoxLayout* layout = reinterpret_cast<QHBoxLayout*>(this->layout());
|
QHBoxLayout* layout = reinterpret_cast<QHBoxLayout*>(this->layout());
|
||||||
|
|
||||||
line_edit = new QLineEdit(this);
|
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);
|
checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||||
|
|
||||||
|
@ -254,7 +256,7 @@ void Widget::CreateCheckBoxWithLineEdit(const QString& label, const std::string&
|
||||||
|
|
||||||
if (!Settings::IsConfiguringGlobal()) {
|
if (!Settings::IsConfiguringGlobal()) {
|
||||||
QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) {
|
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&) {
|
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() {
|
bool Widget::Valid() {
|
||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
@ -273,7 +310,8 @@ 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 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_} {
|
: QWidget(parent_), parent{parent_}, translations{translations_}, setting{*setting_} {
|
||||||
if (!Settings::IsConfiguringGlobal() && !setting.Switchable()) {
|
if (!Settings::IsConfiguringGlobal() && !setting.Switchable()) {
|
||||||
LOG_DEBUG(Frontend, "\"{}\" is not switchable, skipping...", setting.GetLabel());
|
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);
|
CreateCheckBox(label, load_func);
|
||||||
break;
|
break;
|
||||||
case RequestType::LineEdit:
|
case RequestType::LineEdit:
|
||||||
|
CreateCheckBoxWithLineEdit(label, other_setting, load_func);
|
||||||
|
break;
|
||||||
case RequestType::SpinBox:
|
case RequestType::SpinBox:
|
||||||
CreateCheckBoxWithLineEdit(label, text_box_default, load_func);
|
CreateCheckBoxWithSpinBox(label, other_setting, load_func, format);
|
||||||
break;
|
break;
|
||||||
case RequestType::ComboBox:
|
case RequestType::ComboBox:
|
||||||
case RequestType::Slider:
|
case RequestType::Slider:
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "yuzu/configuration/shared_translation.h"
|
#include "yuzu/configuration/shared_translation.h"
|
||||||
|
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
|
class QSpinBox;
|
||||||
class QComboBox;
|
class QComboBox;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
class QSlider;
|
class QSlider;
|
||||||
|
@ -32,7 +33,8 @@ 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 std::string& text_box_default = "");
|
const Settings::BasicSetting* other_setting = nullptr,
|
||||||
|
const QString& format = QStringLiteral(""));
|
||||||
virtual ~Widget();
|
virtual ~Widget();
|
||||||
|
|
||||||
bool Valid();
|
bool Valid();
|
||||||
|
@ -42,16 +44,19 @@ public:
|
||||||
|
|
||||||
QPushButton* restore_button{};
|
QPushButton* restore_button{};
|
||||||
QLineEdit* line_edit{};
|
QLineEdit* line_edit{};
|
||||||
|
QSpinBox* spinbox{};
|
||||||
QCheckBox* checkbox{};
|
QCheckBox* checkbox{};
|
||||||
QSlider* slider{};
|
QSlider* slider{};
|
||||||
QComboBox* combobox{};
|
QComboBox* combobox{};
|
||||||
|
|
||||||
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, const std::string& text_box_default,
|
void CreateCheckBoxWithLineEdit(const QString& label,
|
||||||
std::function<void()>& load_func);
|
const Settings::BasicSetting* other_setting,
|
||||||
void CreateCheckBoxWithSpinBox(const QString& label, const std::string& text_box_default,
|
|
||||||
std::function<void()>& load_func);
|
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 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);
|
||||||
void CreateSlider(const QString& label, bool reversed, float multiplier,
|
void CreateSlider(const QString& label, bool reversed, float multiplier,
|
||||||
|
|
Reference in New Issue