2023-05-08 22:37:03 -04:00
|
|
|
#include <functional>
|
2023-05-10 17:57:25 -04:00
|
|
|
#include <limits>
|
2023-05-08 22:37:03 -04:00
|
|
|
#include <QCheckBox>
|
2023-05-10 17:57:25 -04:00
|
|
|
#include <QDateTimeEdit>
|
2023-05-08 22:37:03 -04:00
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QSizePolicy>
|
2023-05-09 15:46:07 -04:00
|
|
|
#include <QSpinBox>
|
2023-05-08 22:37:03 -04:00
|
|
|
#include <QWidget>
|
|
|
|
#include <qabstractbutton.h>
|
2023-05-10 17:57:25 -04:00
|
|
|
#include <qabstractspinbox.h>
|
2023-06-09 16:53:26 -04:00
|
|
|
#include <qboxlayout.h>
|
2023-05-10 17:57:25 -04:00
|
|
|
#include <qnamespace.h>
|
2023-06-09 16:53:26 -04:00
|
|
|
#include <qpushbutton.h>
|
2023-05-10 17:57:25 -04:00
|
|
|
#include <qvalidator.h>
|
2023-05-09 16:36:09 -04:00
|
|
|
#include "common/common_types.h"
|
2023-05-08 22:37:03 -04:00
|
|
|
#include "common/settings.h"
|
2023-05-09 16:36:09 -04:00
|
|
|
#include "yuzu/configuration/configuration_shared.h"
|
2023-05-08 22:37:03 -04:00
|
|
|
#include "yuzu/configuration/shared_translation.h"
|
|
|
|
#include "yuzu/configuration/shared_widget.h"
|
|
|
|
|
|
|
|
namespace ConfigurationShared {
|
|
|
|
|
2023-05-09 14:26:03 -04:00
|
|
|
QPushButton* Widget::CreateRestoreGlobalButton(Settings::BasicSetting& setting, QWidget* parent) {
|
|
|
|
QStyle* style = parent->style();
|
2023-05-08 22:37:03 -04:00
|
|
|
QIcon* icon = new QIcon(style->standardIcon(QStyle::SP_DialogResetButton));
|
2023-05-09 14:26:03 -04:00
|
|
|
QPushButton* restore_button = new QPushButton(*icon, QStringLiteral(""), parent);
|
2023-05-10 17:57:25 -04:00
|
|
|
restore_button->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
|
2023-05-08 22:37:03 -04:00
|
|
|
|
|
|
|
QSizePolicy sp_retain = restore_button->sizePolicy();
|
|
|
|
sp_retain.setRetainSizeWhenHidden(true);
|
|
|
|
restore_button->setSizePolicy(sp_retain);
|
|
|
|
|
|
|
|
restore_button->setEnabled(!setting.UsingGlobal());
|
|
|
|
restore_button->setVisible(!setting.UsingGlobal());
|
2023-05-09 14:26:03 -04:00
|
|
|
|
|
|
|
return restore_button;
|
2023-05-08 22:37:03 -04:00
|
|
|
}
|
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
QLabel* Widget::CreateLabel(const QString& text) {
|
|
|
|
QLabel* qt_label = new QLabel(text, this->parent);
|
|
|
|
qt_label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
|
|
|
return qt_label;
|
|
|
|
}
|
|
|
|
|
|
|
|
QHBoxLayout* Widget::CreateCheckBox(Settings::BasicSetting* bool_setting, const QString& label,
|
|
|
|
std::function<void()>& load_func, bool managed) {
|
2023-05-08 22:37:03 -04:00
|
|
|
created = true;
|
|
|
|
|
|
|
|
QHBoxLayout* layout = new QHBoxLayout(this);
|
|
|
|
|
|
|
|
checkbox = new QCheckBox(label, this);
|
2023-06-09 16:53:26 -04:00
|
|
|
checkbox->setCheckState(bool_setting->ToString() == "true" ? Qt::CheckState::Checked
|
|
|
|
: Qt::CheckState::Unchecked);
|
|
|
|
checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
2023-05-08 22:37:03 -04:00
|
|
|
|
|
|
|
layout->addWidget(checkbox);
|
2023-06-09 16:53:26 -04:00
|
|
|
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
|
|
if (!managed) {
|
|
|
|
return layout;
|
|
|
|
}
|
|
|
|
|
2023-05-08 22:37:03 -04:00
|
|
|
if (Settings::IsConfiguringGlobal()) {
|
|
|
|
load_func = [=]() {
|
2023-06-09 16:53:26 -04:00
|
|
|
bool_setting->LoadString(checkbox->checkState() == Qt::Checked ? "true" : "false");
|
2023-05-08 22:37:03 -04:00
|
|
|
};
|
|
|
|
} else {
|
2023-06-09 16:53:26 -04:00
|
|
|
restore_button = CreateRestoreGlobalButton(*bool_setting, this);
|
2023-05-08 22:37:03 -04:00
|
|
|
layout->addWidget(restore_button);
|
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
QObject::connect(checkbox, &QCheckBox::stateChanged, [=](int) {
|
2023-05-08 22:37:03 -04:00
|
|
|
restore_button->setVisible(true);
|
|
|
|
restore_button->setEnabled(true);
|
|
|
|
});
|
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) {
|
|
|
|
checkbox->setCheckState(bool_setting->ToStringGlobal() == "true" ? Qt::Checked
|
|
|
|
: Qt::Unchecked);
|
2023-05-08 22:37:03 -04:00
|
|
|
restore_button->setEnabled(false);
|
|
|
|
restore_button->setVisible(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
load_func = [=]() {
|
|
|
|
bool using_global = !restore_button->isEnabled();
|
2023-06-09 16:53:26 -04:00
|
|
|
bool_setting->SetGlobal(using_global);
|
2023-05-08 22:37:03 -04:00
|
|
|
if (!using_global) {
|
2023-06-09 16:53:26 -04:00
|
|
|
bool_setting->LoadString(checkbox->checkState() == Qt::Checked ? "true" : "false");
|
2023-05-08 22:37:03 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
return layout;
|
2023-05-08 22:37:03 -04:00
|
|
|
}
|
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
void Widget::CreateCombobox(const QString& label, std::function<void()>& load_func, bool managed,
|
|
|
|
Settings::BasicSetting* const other_setting) {
|
2023-05-08 22:37:03 -04:00
|
|
|
created = true;
|
|
|
|
|
|
|
|
const auto type = setting.TypeId();
|
|
|
|
|
|
|
|
QLayout* layout = new QHBoxLayout(this);
|
|
|
|
|
|
|
|
QLabel* qt_label = new QLabel(label, this);
|
|
|
|
combobox = new QComboBox(this);
|
|
|
|
|
|
|
|
std::forward_list<QString> combobox_enumerations = ComboboxEnumeration(type, this);
|
|
|
|
for (const auto& item : combobox_enumerations) {
|
|
|
|
combobox->addItem(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
layout->addWidget(qt_label);
|
|
|
|
layout->addWidget(combobox);
|
|
|
|
|
|
|
|
layout->setSpacing(6);
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
|
|
combobox->setCurrentIndex(std::stoi(setting.ToString()));
|
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
if (!managed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Settings::IsConfiguringGlobal()) {
|
2023-05-08 22:37:03 -04:00
|
|
|
load_func = [=]() { setting.LoadString(std::to_string(combobox->currentIndex())); };
|
2023-06-09 16:53:26 -04:00
|
|
|
} else {
|
2023-05-09 14:26:03 -04:00
|
|
|
restore_button = CreateRestoreGlobalButton(setting, this);
|
2023-05-08 22:37:03 -04:00
|
|
|
layout->addWidget(restore_button);
|
|
|
|
|
|
|
|
QObject::connect(restore_button, &QAbstractButton::clicked, [&](bool) {
|
|
|
|
restore_button->setEnabled(false);
|
|
|
|
restore_button->setVisible(false);
|
|
|
|
|
|
|
|
combobox->setCurrentIndex(std::stoi(setting.ToStringGlobal()));
|
|
|
|
});
|
|
|
|
|
|
|
|
QObject::connect(combobox, QOverload<int>::of(&QComboBox::activated), [=](int) {
|
|
|
|
restore_button->setEnabled(true);
|
|
|
|
restore_button->setVisible(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
load_func = [=]() {
|
|
|
|
bool using_global = !restore_button->isEnabled();
|
|
|
|
setting.SetGlobal(using_global);
|
|
|
|
if (!using_global) {
|
|
|
|
setting.LoadString(std::to_string(combobox->currentIndex()));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
void Widget::CreateLineEdit(const QString& label, std::function<void()>& load_func, bool managed,
|
|
|
|
Settings::BasicSetting* other_setting) {
|
|
|
|
const bool has_checkbox = other_setting != nullptr;
|
|
|
|
if (has_checkbox && other_setting->TypeId() != typeid(bool)) {
|
|
|
|
LOG_WARNING(Frontend, "Extra setting requested but setting is not boolean");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-05-08 22:37:03 -04:00
|
|
|
created = true;
|
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
QHBoxLayout* layout{nullptr};
|
|
|
|
std::function<void()> checkbox_load_func = []() {};
|
|
|
|
|
|
|
|
if (has_checkbox) {
|
|
|
|
layout = CreateCheckBox(other_setting, label, checkbox_load_func, managed);
|
|
|
|
} else {
|
|
|
|
layout = new QHBoxLayout(this);
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
QLabel* q_label = CreateLabel(label);
|
|
|
|
layout->addWidget(q_label);
|
|
|
|
}
|
2023-05-08 22:37:03 -04:00
|
|
|
|
|
|
|
const QString text = QString::fromStdString(setting.ToString());
|
2023-06-09 16:53:26 -04:00
|
|
|
line_edit = new QLineEdit(this);
|
2023-05-08 22:37:03 -04:00
|
|
|
line_edit->setText(text);
|
|
|
|
|
|
|
|
layout->addWidget(line_edit);
|
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
if (!managed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Settings::IsConfiguringGlobal()) {
|
2023-05-08 22:37:03 -04:00
|
|
|
load_func = [=]() {
|
2023-06-09 16:53:26 -04:00
|
|
|
checkbox_load_func();
|
|
|
|
|
2023-05-08 22:37:03 -04:00
|
|
|
std::string load_text = line_edit->text().toStdString();
|
|
|
|
setting.LoadString(load_text);
|
|
|
|
};
|
2023-06-09 16:53:26 -04:00
|
|
|
} else {
|
|
|
|
if (!has_checkbox) {
|
|
|
|
restore_button = CreateRestoreGlobalButton(setting, this);
|
|
|
|
layout->addWidget(restore_button);
|
|
|
|
}
|
2023-05-08 22:37:03 -04:00
|
|
|
|
|
|
|
QObject::connect(restore_button, &QAbstractButton::clicked, [&](bool) {
|
|
|
|
restore_button->setEnabled(false);
|
|
|
|
restore_button->setVisible(false);
|
|
|
|
|
|
|
|
line_edit->setText(QString::fromStdString(setting.ToStringGlobal()));
|
|
|
|
});
|
|
|
|
|
|
|
|
QObject::connect(line_edit, &QLineEdit::textChanged, [&](QString) {
|
|
|
|
restore_button->setEnabled(true);
|
|
|
|
restore_button->setVisible(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
load_func = [=]() {
|
2023-06-09 16:53:26 -04:00
|
|
|
checkbox_load_func();
|
|
|
|
|
2023-05-08 22:37:03 -04:00
|
|
|
bool using_global = !restore_button->isEnabled();
|
|
|
|
setting.SetGlobal(using_global);
|
|
|
|
if (!using_global) {
|
|
|
|
setting.LoadString(line_edit->text().toStdString());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
void Widget::CreateSlider(const QString& label, bool reversed, float multiplier,
|
|
|
|
std::function<void()>& load_func, bool managed,
|
|
|
|
Settings::BasicSetting* const other_setting) {
|
2023-05-08 22:37:03 -04:00
|
|
|
created = true;
|
|
|
|
|
|
|
|
QHBoxLayout* layout = new QHBoxLayout(this);
|
|
|
|
slider = new QSlider(Qt::Horizontal, this);
|
2023-06-09 16:53:26 -04:00
|
|
|
QLabel* qt_label = new QLabel(label, this);
|
2023-05-08 22:37:03 -04:00
|
|
|
QLabel* feedback = new QLabel(this);
|
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
layout->addWidget(qt_label);
|
2023-05-08 22:37:03 -04:00
|
|
|
layout->addWidget(slider);
|
|
|
|
layout->addWidget(feedback);
|
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
qt_label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
2023-05-08 22:37:03 -04:00
|
|
|
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
|
|
int max_val = std::stoi(setting.MaxVal());
|
|
|
|
|
|
|
|
QObject::connect(slider, &QAbstractSlider::valueChanged, [=](int value) {
|
|
|
|
int present = (reversed ? max_val - value : value) * multiplier;
|
|
|
|
feedback->setText(
|
|
|
|
QStringLiteral("%1%").arg(QString::fromStdString(std::to_string(present))));
|
|
|
|
});
|
|
|
|
|
|
|
|
slider->setValue(std::stoi(setting.ToString()));
|
|
|
|
slider->setMinimum(std::stoi(setting.MinVal()));
|
|
|
|
slider->setMaximum(max_val);
|
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
slider->setInvertedAppearance(reversed);
|
|
|
|
|
|
|
|
if (!managed) {
|
|
|
|
return;
|
2023-05-08 22:37:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Settings::IsConfiguringGlobal()) {
|
|
|
|
load_func = [=]() { setting.LoadString(std::to_string(slider->value())); };
|
|
|
|
} else {
|
2023-05-09 14:26:03 -04:00
|
|
|
restore_button = CreateRestoreGlobalButton(setting, this);
|
2023-05-08 22:37:03 -04:00
|
|
|
layout->addWidget(restore_button);
|
|
|
|
|
|
|
|
QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) {
|
|
|
|
slider->setValue(std::stoi(setting.ToStringGlobal()));
|
|
|
|
|
|
|
|
restore_button->setEnabled(false);
|
|
|
|
restore_button->setVisible(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
QObject::connect(slider, &QAbstractSlider::sliderMoved, [=](int) {
|
|
|
|
restore_button->setEnabled(true);
|
|
|
|
restore_button->setVisible(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
load_func = [=]() {
|
|
|
|
bool using_global = !restore_button->isEnabled();
|
|
|
|
setting.SetGlobal(using_global);
|
|
|
|
if (!using_global) {
|
|
|
|
setting.LoadString(std::to_string(slider->value()));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
void Widget::CreateSpinBox(const QString& label, std::function<void()>& load_func, bool managed,
|
|
|
|
const std::string& suffix, Settings::BasicSetting* other_setting) {
|
|
|
|
const bool has_checkbox = other_setting != nullptr;
|
|
|
|
if (has_checkbox && other_setting->TypeId() != typeid(bool)) {
|
|
|
|
LOG_WARNING(Frontend, "Extra setting requested but setting is not boolean");
|
2023-05-10 17:57:25 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
created = true;
|
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
QHBoxLayout* layout{nullptr};
|
|
|
|
std::function<void()> checkbox_load_func = []() {};
|
|
|
|
QLabel* q_label{nullptr};
|
2023-05-10 17:57:25 -04:00
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
if (has_checkbox) {
|
|
|
|
layout = CreateCheckBox(other_setting, label, checkbox_load_func, managed);
|
|
|
|
} else {
|
|
|
|
layout = new QHBoxLayout(this);
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
q_label = CreateLabel(label);
|
|
|
|
layout->addWidget(q_label);
|
|
|
|
}
|
2023-05-10 17:57:25 -04:00
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
const int min_val = std::stoi(setting.MinVal());
|
|
|
|
const int max_val = std::stoi(setting.MaxVal());
|
|
|
|
const int default_val = std::stoi(setting.ToString());
|
2023-05-10 17:57:25 -04:00
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
spinbox = new QSpinBox(this);
|
|
|
|
spinbox->setRange(min_val, max_val);
|
|
|
|
spinbox->setValue(default_val);
|
|
|
|
spinbox->setSuffix(QString::fromStdString(suffix));
|
|
|
|
spinbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
2023-05-10 17:57:25 -04:00
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
layout->insertWidget(1, spinbox);
|
2023-05-10 17:57:25 -04:00
|
|
|
|
|
|
|
if (Settings::IsConfiguringGlobal()) {
|
|
|
|
load_func = [=]() {
|
|
|
|
checkbox_load_func();
|
2023-06-09 16:53:26 -04:00
|
|
|
setting.LoadString(std::to_string(spinbox->value()));
|
2023-05-10 17:57:25 -04:00
|
|
|
};
|
|
|
|
} else {
|
2023-06-09 16:53:26 -04:00
|
|
|
if (!has_checkbox) {
|
|
|
|
restore_button = CreateRestoreGlobalButton(setting, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
QObject::connect(restore_button, &QAbstractButton::clicked,
|
|
|
|
[this](bool) { spinbox->setValue(std::stoi(setting.ToStringGlobal())); });
|
2023-05-10 17:57:25 -04:00
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
QObject::connect(spinbox, QOverload<int>::of(&QSpinBox::valueChanged), [this](int) {
|
2023-05-10 17:57:25 -04:00
|
|
|
restore_button->setEnabled(true);
|
|
|
|
restore_button->setVisible(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
load_func = [=]() {
|
|
|
|
checkbox_load_func();
|
|
|
|
|
|
|
|
const bool using_global = !restore_button->isEnabled();
|
2023-06-09 16:53:26 -04:00
|
|
|
setting.SetGlobal(using_global);
|
2023-05-10 17:57:25 -04:00
|
|
|
if (!using_global) {
|
2023-06-09 16:53:26 -04:00
|
|
|
setting.LoadString(std::to_string(spinbox->value()));
|
2023-05-10 17:57:25 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
void Widget::CreateHexEdit(const QString& label, std::function<void()>& load_func, bool managed,
|
|
|
|
Settings::BasicSetting* const other_setting) {
|
|
|
|
CreateLineEdit(label, load_func, false, other_setting);
|
|
|
|
if (!created || !managed) {
|
2023-05-09 16:36:09 -04:00
|
|
|
return;
|
|
|
|
}
|
2023-05-08 22:37:03 -04:00
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
QLayout* layout = this->layout();
|
|
|
|
|
|
|
|
auto to_hex = [=](const std::string& input) {
|
|
|
|
return QString::fromStdString(fmt::format("{:08x}", std::stoi(input)));
|
|
|
|
};
|
|
|
|
|
|
|
|
QRegExpValidator* regex =
|
|
|
|
new QRegExpValidator{QRegExp{QStringLiteral("^[0-9a-fA-F]{0,8}$")}, line_edit};
|
2023-05-08 22:37:03 -04:00
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
const QString default_val = to_hex(setting.ToString());
|
2023-05-08 22:37:03 -04:00
|
|
|
|
2023-05-09 16:36:09 -04:00
|
|
|
line_edit->setText(default_val);
|
2023-06-09 16:53:26 -04:00
|
|
|
line_edit->setMaxLength(8);
|
|
|
|
line_edit->setValidator(regex);
|
2023-05-08 22:37:03 -04:00
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
auto hex_to_dec = [=]() -> std::string {
|
|
|
|
return std::to_string(std::stoul(line_edit->text().toStdString(), nullptr, 16));
|
|
|
|
};
|
2023-05-08 22:37:03 -04:00
|
|
|
|
2023-05-09 16:36:09 -04:00
|
|
|
if (Settings::IsConfiguringGlobal()) {
|
|
|
|
load_func = [=]() {
|
2023-06-09 16:53:26 -04:00
|
|
|
other_setting->LoadString(checkbox->checkState() == Qt::Checked ? "true" : "false");
|
|
|
|
setting.LoadString(hex_to_dec());
|
2023-05-09 16:36:09 -04:00
|
|
|
};
|
|
|
|
} else {
|
2023-06-09 16:53:26 -04:00
|
|
|
restore_button = CreateRestoreGlobalButton(setting, this);
|
|
|
|
layout->addWidget(restore_button);
|
|
|
|
|
2023-05-10 17:57:25 -04:00
|
|
|
QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) {
|
2023-06-09 16:53:26 -04:00
|
|
|
line_edit->setText(to_hex(setting.ToStringGlobal()));
|
|
|
|
checkbox->setCheckState(other_setting->ToStringGlobal() == "true" ? Qt::Checked
|
|
|
|
: Qt::Unchecked);
|
|
|
|
|
|
|
|
restore_button->setEnabled(false);
|
|
|
|
restore_button->setVisible(false);
|
2023-05-10 17:57:25 -04:00
|
|
|
});
|
2023-05-08 22:37:03 -04:00
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
QObject::connect(line_edit, &QLineEdit::textEdited, [&]() {
|
2023-05-08 22:37:03 -04:00
|
|
|
restore_button->setEnabled(true);
|
|
|
|
restore_button->setVisible(true);
|
|
|
|
});
|
2023-05-09 16:36:09 -04:00
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
QObject::connect(checkbox, &QAbstractButton::clicked, [&]() {
|
2023-05-09 15:46:07 -04:00
|
|
|
restore_button->setEnabled(true);
|
|
|
|
restore_button->setVisible(true);
|
|
|
|
});
|
2023-05-09 16:36:09 -04:00
|
|
|
|
|
|
|
load_func = [=]() {
|
2023-05-10 17:57:25 -04:00
|
|
|
const bool using_global = !restore_button->isEnabled();
|
2023-05-09 16:36:09 -04:00
|
|
|
other_setting->SetGlobal(using_global);
|
2023-06-09 16:53:26 -04:00
|
|
|
setting.SetGlobal(using_global);
|
|
|
|
|
2023-05-09 16:36:09 -04:00
|
|
|
if (!using_global) {
|
2023-06-09 16:53:26 -04:00
|
|
|
other_setting->LoadString(checkbox->checkState() == Qt::Checked ? "true" : "false");
|
|
|
|
setting.LoadString(hex_to_dec());
|
2023-05-09 16:36:09 -04:00
|
|
|
}
|
|
|
|
};
|
2023-05-09 15:46:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
void Widget::CreateDateTimeEdit(const QString& label, std::function<void()>& load_func,
|
|
|
|
bool managed, bool restrict,
|
|
|
|
Settings::BasicSetting* const other_setting) {
|
|
|
|
const bool has_checkbox = other_setting != nullptr;
|
|
|
|
if ((restrict && !has_checkbox) || (has_checkbox && other_setting->TypeId() != typeid(bool))) {
|
|
|
|
LOG_WARNING(Frontend, "Extra setting or restrict requested but is not boolean");
|
2023-05-10 17:57:25 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
created = true;
|
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
QHBoxLayout* layout{nullptr};
|
|
|
|
std::function<void()> checkbox_load_func = []() {};
|
|
|
|
|
|
|
|
if (has_checkbox) {
|
|
|
|
layout = CreateCheckBox(other_setting, label, checkbox_load_func, managed);
|
|
|
|
} else {
|
|
|
|
layout = new QHBoxLayout(this);
|
|
|
|
QLabel* q_label = CreateLabel(label);
|
|
|
|
layout->addWidget(q_label);
|
|
|
|
}
|
2023-05-10 17:57:25 -04:00
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
const bool disabled = other_setting->ToString() != "true";
|
2023-05-10 17:57:25 -04:00
|
|
|
const long long current_time = QDateTime::currentSecsSinceEpoch();
|
2023-06-09 16:53:26 -04:00
|
|
|
const s64 the_time = disabled ? current_time : std::stoll(setting.ToString());
|
2023-05-10 17:57:25 -04:00
|
|
|
const auto default_val = QDateTime::fromSecsSinceEpoch(the_time);
|
|
|
|
|
|
|
|
date_time_edit = new QDateTimeEdit(this);
|
|
|
|
date_time_edit->setDateTime(default_val);
|
|
|
|
date_time_edit->setMinimumDateTime(QDateTime::fromSecsSinceEpoch(0));
|
|
|
|
date_time_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
|
|
|
|
|
|
|
layout->insertWidget(1, date_time_edit);
|
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
if (!managed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-05-10 17:57:25 -04:00
|
|
|
if (Settings::IsConfiguringGlobal()) {
|
|
|
|
load_func = [=]() {
|
|
|
|
checkbox_load_func();
|
2023-06-09 16:53:26 -04:00
|
|
|
if (restrict && checkbox->checkState() == Qt::Unchecked) {
|
2023-05-10 17:57:25 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
other_setting->LoadString(
|
|
|
|
std::to_string(date_time_edit->dateTime().toSecsSinceEpoch()));
|
|
|
|
};
|
|
|
|
} else {
|
2023-06-09 16:53:26 -04:00
|
|
|
if (!has_checkbox) {
|
|
|
|
restore_button = CreateRestoreGlobalButton(setting, this);
|
|
|
|
layout->addWidget(restore_button);
|
|
|
|
}
|
|
|
|
|
2023-05-10 17:57:25 -04:00
|
|
|
auto get_clear_val = [=]() {
|
|
|
|
return QDateTime::fromSecsSinceEpoch([=]() {
|
2023-06-09 16:53:26 -04:00
|
|
|
if (restrict && checkbox->checkState() == Qt::Checked) {
|
2023-05-10 17:57:25 -04:00
|
|
|
return std::stoll(other_setting->ToStringGlobal());
|
|
|
|
}
|
|
|
|
return current_time;
|
|
|
|
}());
|
|
|
|
};
|
|
|
|
|
|
|
|
QObject::connect(restore_button, &QAbstractButton::clicked,
|
|
|
|
[=](bool) { date_time_edit->setDateTime(get_clear_val()); });
|
|
|
|
|
|
|
|
QObject::connect(date_time_edit, &QDateTimeEdit::editingFinished, [=]() {
|
|
|
|
if (date_time_edit->dateTime() != get_clear_val()) {
|
|
|
|
restore_button->setEnabled(true);
|
|
|
|
restore_button->setVisible(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
load_func = [=]() {
|
|
|
|
checkbox_load_func();
|
2023-06-09 16:53:26 -04:00
|
|
|
if (restrict && checkbox->checkState() == Qt::Unchecked) {
|
2023-05-10 17:57:25 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool using_global = !restore_button->isEnabled();
|
|
|
|
other_setting->SetGlobal(using_global);
|
|
|
|
if (!using_global) {
|
|
|
|
other_setting->LoadString(
|
|
|
|
std::to_string(date_time_edit->dateTime().toSecsSinceEpoch()));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-08 22:37:03 -04:00
|
|
|
bool Widget::Valid() {
|
|
|
|
return created;
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget::~Widget() = default;
|
|
|
|
|
2023-06-09 16:53:26 -04:00
|
|
|
Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translations_,
|
|
|
|
QWidget* parent_, std::forward_list<std::function<void(bool)>>& apply_funcs_)
|
|
|
|
: QWidget(parent_), parent{parent_}, translations{translations_}, setting{*setting_},
|
|
|
|
apply_funcs{apply_funcs_} {}
|
|
|
|
|
2023-05-08 22:37:03 -04:00
|
|
|
Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translations_,
|
|
|
|
QWidget* parent_, bool runtime_lock,
|
2023-06-09 16:53:26 -04:00
|
|
|
std::forward_list<std::function<void(bool)>>& apply_funcs_, RequestType request,
|
2023-05-09 16:36:09 -04:00
|
|
|
bool managed, float multiplier, Settings::BasicSetting* other_setting,
|
2023-05-10 17:57:25 -04:00
|
|
|
const std::string& string)
|
2023-06-09 16:53:26 -04:00
|
|
|
: QWidget(parent_), parent{parent_}, translations{translations_}, setting{*setting_},
|
|
|
|
apply_funcs{apply_funcs_} {
|
2023-05-08 22:37:03 -04:00
|
|
|
if (!Settings::IsConfiguringGlobal() && !setting.Switchable()) {
|
|
|
|
LOG_DEBUG(Frontend, "\"{}\" is not switchable, skipping...", setting.GetLabel());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto type = setting.TypeId();
|
|
|
|
const int id = setting.Id();
|
|
|
|
|
|
|
|
const auto [label, tooltip] = [&]() {
|
|
|
|
const auto& setting_label = setting.GetLabel();
|
|
|
|
if (translations.contains(id)) {
|
|
|
|
return std::pair{translations.at(id).first, translations.at(id).second};
|
|
|
|
}
|
|
|
|
LOG_WARNING(Frontend, "Translation table lacks entry for \"{}\"", setting_label);
|
|
|
|
return std::pair{QString::fromStdString(setting_label), QStringLiteral("")};
|
|
|
|
}();
|
|
|
|
|
|
|
|
if (label == QStringLiteral("")) {
|
|
|
|
LOG_DEBUG(Frontend, "Translation table has emtpy entry for \"{}\", skipping...",
|
|
|
|
setting.GetLabel());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::function<void()> load_func = []() {};
|
|
|
|
|
|
|
|
if (type == typeid(bool)) {
|
|
|
|
switch (request) {
|
|
|
|
case RequestType::Default:
|
2023-06-09 16:53:26 -04:00
|
|
|
CreateCheckBox(&setting, label, load_func, managed);
|
2023-05-08 22:37:03 -04:00
|
|
|
break;
|
2023-06-09 16:53:26 -04:00
|
|
|
default:
|
|
|
|
LOG_WARNING(Frontend, "Requested widget is unimplemented.");
|
2023-05-08 22:37:03 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (setting.IsEnum()) {
|
2023-06-09 16:53:26 -04:00
|
|
|
CreateCombobox(label, load_func, managed);
|
|
|
|
} else if (type == typeid(u32) || type == typeid(int) || type == typeid(u16) ||
|
|
|
|
type == typeid(s64)) {
|
2023-05-08 22:37:03 -04:00
|
|
|
switch (request) {
|
|
|
|
case RequestType::Slider:
|
|
|
|
case RequestType::ReverseSlider:
|
2023-06-09 16:53:26 -04:00
|
|
|
CreateSlider(label, request == RequestType::ReverseSlider, multiplier, load_func,
|
|
|
|
managed);
|
2023-05-08 22:37:03 -04:00
|
|
|
break;
|
|
|
|
case RequestType::LineEdit:
|
|
|
|
case RequestType::Default:
|
2023-06-09 16:53:26 -04:00
|
|
|
CreateLineEdit(label, load_func, managed);
|
2023-05-08 22:37:03 -04:00
|
|
|
break;
|
|
|
|
case RequestType::ComboBox:
|
2023-06-09 16:53:26 -04:00
|
|
|
CreateCombobox(label, load_func, managed);
|
2023-05-08 22:37:03 -04:00
|
|
|
break;
|
2023-05-10 17:57:25 -04:00
|
|
|
case RequestType::DateTimeEdit:
|
2023-06-09 16:53:26 -04:00
|
|
|
CreateDateTimeEdit(label, load_func, managed, true, other_setting);
|
|
|
|
break;
|
2023-05-08 22:37:03 -04:00
|
|
|
case RequestType::SpinBox:
|
2023-06-09 16:53:26 -04:00
|
|
|
CreateSpinBox(label, load_func, managed, string, other_setting);
|
|
|
|
break;
|
2023-05-10 17:57:25 -04:00
|
|
|
case RequestType::HexEdit:
|
2023-06-09 16:53:26 -04:00
|
|
|
CreateHexEdit(label, load_func, managed, other_setting);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOG_WARNING(Frontend, "Requested widget is unimplemented.");
|
2023-05-08 22:37:03 -04:00
|
|
|
break;
|
|
|
|
}
|
2023-05-10 17:57:25 -04:00
|
|
|
} else if (type == typeid(std::string)) {
|
2023-06-09 16:53:26 -04:00
|
|
|
CreateLineEdit(label, load_func, managed);
|
2023-05-08 22:37:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!created) {
|
2023-05-09 16:36:09 -04:00
|
|
|
LOG_WARNING(Frontend, "No widget was created for \"{}\"", setting.GetLabel());
|
2023-05-08 22:37:03 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
apply_funcs.push_front([load_func, setting_](bool powered_on) {
|
|
|
|
if (setting_->RuntimeModfiable() || !powered_on) {
|
|
|
|
load_func();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
bool enable = runtime_lock || setting.RuntimeModfiable();
|
|
|
|
if (setting.Switchable() && Settings::IsConfiguringGlobal() && !runtime_lock) {
|
|
|
|
enable &= setting.UsingGlobal();
|
|
|
|
}
|
|
|
|
this->setEnabled(enable);
|
|
|
|
|
|
|
|
this->setVisible(Settings::IsConfiguringGlobal() || setting.Switchable());
|
|
|
|
|
|
|
|
this->setToolTip(tooltip);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ConfigurationShared
|