shared_widget: Make button creation static
This commit is contained in:
parent
8c03ae793e
commit
c1748b229a
2 changed files with 12 additions and 10 deletions
|
@ -14,10 +14,10 @@
|
||||||
|
|
||||||
namespace ConfigurationShared {
|
namespace ConfigurationShared {
|
||||||
|
|
||||||
void Widget::CreateRestoreGlobalButton() {
|
QPushButton* Widget::CreateRestoreGlobalButton(Settings::BasicSetting& setting, QWidget* parent) {
|
||||||
QStyle* style = this->style();
|
QStyle* style = parent->style();
|
||||||
QIcon* icon = new QIcon(style->standardIcon(QStyle::SP_DialogResetButton));
|
QIcon* icon = new QIcon(style->standardIcon(QStyle::SP_DialogResetButton));
|
||||||
restore_button = new QPushButton(*icon, QStringLiteral(""), this);
|
QPushButton* restore_button = new QPushButton(*icon, QStringLiteral(""), parent);
|
||||||
restore_button->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding);
|
restore_button->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding);
|
||||||
|
|
||||||
QSizePolicy sp_retain = restore_button->sizePolicy();
|
QSizePolicy sp_retain = restore_button->sizePolicy();
|
||||||
|
@ -26,6 +26,8 @@ void Widget::CreateRestoreGlobalButton() {
|
||||||
|
|
||||||
restore_button->setEnabled(!setting.UsingGlobal());
|
restore_button->setEnabled(!setting.UsingGlobal());
|
||||||
restore_button->setVisible(!setting.UsingGlobal());
|
restore_button->setVisible(!setting.UsingGlobal());
|
||||||
|
|
||||||
|
return restore_button;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::CreateCheckBox(const QString& label, std::function<void()>& load_func) {
|
void Widget::CreateCheckBox(const QString& label, std::function<void()>& load_func) {
|
||||||
|
@ -44,7 +46,7 @@ void Widget::CreateCheckBox(const QString& label, std::function<void()>& load_fu
|
||||||
setting.LoadString(checkbox->checkState() == Qt::Checked ? "true" : "false");
|
setting.LoadString(checkbox->checkState() == Qt::Checked ? "true" : "false");
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
CreateRestoreGlobalButton();
|
restore_button = CreateRestoreGlobalButton(setting, this);
|
||||||
layout->addWidget(restore_button);
|
layout->addWidget(restore_button);
|
||||||
|
|
||||||
QObject::connect(checkbox, &QCheckBox::stateChanged, [&](int) {
|
QObject::connect(checkbox, &QCheckBox::stateChanged, [&](int) {
|
||||||
|
@ -97,7 +99,7 @@ void Widget::CreateCombobox(const QString& label, bool managed, std::function<vo
|
||||||
if (Settings::IsConfiguringGlobal() && managed) {
|
if (Settings::IsConfiguringGlobal() && managed) {
|
||||||
load_func = [=]() { setting.LoadString(std::to_string(combobox->currentIndex())); };
|
load_func = [=]() { setting.LoadString(std::to_string(combobox->currentIndex())); };
|
||||||
} else if (managed) {
|
} else if (managed) {
|
||||||
CreateRestoreGlobalButton();
|
restore_button = CreateRestoreGlobalButton(setting, this);
|
||||||
layout->addWidget(restore_button);
|
layout->addWidget(restore_button);
|
||||||
|
|
||||||
QObject::connect(restore_button, &QAbstractButton::clicked, [&](bool) {
|
QObject::connect(restore_button, &QAbstractButton::clicked, [&](bool) {
|
||||||
|
@ -144,7 +146,7 @@ void Widget::CreateLineEdit(const QString& label, bool managed, std::function<vo
|
||||||
setting.LoadString(load_text);
|
setting.LoadString(load_text);
|
||||||
};
|
};
|
||||||
} else if (!managed) {
|
} else if (!managed) {
|
||||||
CreateRestoreGlobalButton();
|
restore_button = CreateRestoreGlobalButton(setting, this);
|
||||||
layout->addWidget(restore_button);
|
layout->addWidget(restore_button);
|
||||||
|
|
||||||
QObject::connect(restore_button, &QAbstractButton::clicked, [&](bool) {
|
QObject::connect(restore_button, &QAbstractButton::clicked, [&](bool) {
|
||||||
|
@ -207,7 +209,7 @@ void Widget::CreateSlider(const QString& name, bool reversed, float multiplier,
|
||||||
if (Settings::IsConfiguringGlobal()) {
|
if (Settings::IsConfiguringGlobal()) {
|
||||||
load_func = [=]() { setting.LoadString(std::to_string(slider->value())); };
|
load_func = [=]() { setting.LoadString(std::to_string(slider->value())); };
|
||||||
} else {
|
} else {
|
||||||
CreateRestoreGlobalButton();
|
restore_button = CreateRestoreGlobalButton(setting, this);
|
||||||
layout->addWidget(restore_button);
|
layout->addWidget(restore_button);
|
||||||
|
|
||||||
QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) {
|
QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) {
|
||||||
|
@ -340,7 +342,6 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati
|
||||||
}
|
}
|
||||||
|
|
||||||
apply_funcs.push_front([load_func, setting_](bool powered_on) {
|
apply_funcs.push_front([load_func, setting_](bool powered_on) {
|
||||||
LOG_DEBUG(Frontend, "{}", setting_->GetLabel());
|
|
||||||
if (setting_->RuntimeModfiable() || !powered_on) {
|
if (setting_->RuntimeModfiable() || !powered_on) {
|
||||||
load_func();
|
load_func();
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,9 @@ public:
|
||||||
|
|
||||||
bool Valid();
|
bool Valid();
|
||||||
|
|
||||||
|
[[nodiscard]] static QPushButton* CreateRestoreGlobalButton(Settings::BasicSetting& setting,
|
||||||
|
QWidget* parent);
|
||||||
|
|
||||||
QPushButton* restore_button{};
|
QPushButton* restore_button{};
|
||||||
QLineEdit* line_edit{};
|
QLineEdit* line_edit{};
|
||||||
QCheckBox* checkbox{};
|
QCheckBox* checkbox{};
|
||||||
|
@ -54,8 +57,6 @@ private:
|
||||||
void CreateSlider(const QString& label, bool reversed, float multiplier,
|
void CreateSlider(const QString& label, bool reversed, float multiplier,
|
||||||
std::function<void()>& load_func);
|
std::function<void()>& load_func);
|
||||||
|
|
||||||
void CreateRestoreGlobalButton();
|
|
||||||
|
|
||||||
QWidget* parent;
|
QWidget* parent;
|
||||||
const TranslationMap& translations;
|
const TranslationMap& translations;
|
||||||
Settings::BasicSetting& setting;
|
Settings::BasicSetting& setting;
|
||||||
|
|
Loading…
Reference in a new issue