--- a/widgets/vec3editor.cpp Wed Jun 22 21:42:10 2022 +0300 +++ b/widgets/vec3editor.cpp Wed Jun 22 21:46:38 2022 +0300 @@ -2,66 +2,64 @@ #include <QCheckBox> #include <QSignalBlocker> #include "vec3editor.h" -#include "ui_vec3editor.h" #include "multiplyfactordialog.h" -Vec3Editor::Vec3Editor(const glm::vec3& value, QWidget *parent, QFlags<Flag> flags) : - QWidget{parent}, - ui{new Ui::Vec3Editor} +VectorInput::VectorInput(const glm::vec3& value, QWidget* parent, QFlags<VectorInput::Flag> flags) : + VectorInput{parent, flags} { - this->ui->setupUi(this); this->setValue(value); - if (flags.testFlag(NoMultiplyButton)) - { - this->ui->multiply->setVisible(false); +} + +VectorInput::VectorInput(QWidget *parent, QFlags<Flag> flags) : + QWidget{parent} +{ + + this->ui.setupUi(this); + if (flags.testFlag(NoMultiplyButton)) { + this->ui.multiply->setVisible(false); } - else - { - connect(this->ui->multiply, &QPushButton::clicked, this, &Vec3Editor::multiplyPressed); + else { + connect(this->ui.multiply, &QPushButton::clicked, this, &VectorInput::multiplyPressed); } - for (QDoubleSpinBox* spinbox : this->spinboxes()) - { - connect(spinbox, qOverload<double>(&QDoubleSpinBox::valueChanged), [&](double) - { + for (QDoubleSpinBox* spinbox : this->spinboxes()) { + connect(spinbox, qOverload<double>(&QDoubleSpinBox::valueChanged), [&](double){ Q_EMIT this->valueChanged(this->value()); }); } } -Vec3Editor::~Vec3Editor() +VectorInput::~VectorInput() { } -glm::vec3 Vec3Editor::value() const +glm::vec3 VectorInput::value() const { auto get = [](DoubleSpinBox* spinbox){ return static_cast<float>(spinbox->value()); }; - return {get(this->ui->x), get(this->ui->y), get(this->ui->z)}; + return {get(this->ui.x), get(this->ui.y), get(this->ui.z)}; } -void Vec3Editor::setValue(const glm::vec3& value) +void VectorInput::setValue(const glm::vec3& value) { - auto set = [](DoubleSpinBox* spinbox, float value) - { + auto set = [](DoubleSpinBox* spinbox, float value){ QSignalBlocker blocker{spinbox}; spinbox->setValue(static_cast<qreal>(value)); }; - set(this->ui->x, value.x); - set(this->ui->y, value.y); - set(this->ui->z, value.z); + set(this->ui.x, value.x); + set(this->ui.y, value.y); + set(this->ui.z, value.z); Q_EMIT this->valueChanged(value); } -std::array<DoubleSpinBox*, 3> Vec3Editor::spinboxes() +std::array<DoubleSpinBox*, 3> VectorInput::spinboxes() { - return {this->ui->x, this->ui->y, this->ui->z}; + return {this->ui.x, this->ui.y, this->ui.z}; } -void Vec3Editor::multiplyPressed() +void VectorInput::multiplyPressed() { MultiplyFactorDialog dialog{this->value(), this}; const int dialogResult = dialog.exec(); - if (dialogResult == QDialog::Accepted) - { + if (dialogResult == QDialog::Accepted) { this->setValue(dialog.value()); } }