Sun, 13 Mar 2022 20:26:28 +0200
add ui file to object editor
#include "multiplyfactordialog.h" #include "ui_multiplyfactordialog.h" MultiplyFactorDialog::MultiplyFactorDialog(const glm::vec3& baseVector, QWidget* parent) : QDialog{parent}, baseVector{baseVector}, preview{baseVector, parent, Vec3Editor::NoMultiplyButton} { ui = std::make_unique<Ui::MultiplyFactorDialog>(); ui->setupUi(this); this->preview.setEnabled(false); this->ui->previewGroupBox->setLayout(new QVBoxLayout{parent}); this->ui->previewGroupBox->layout()->addWidget(&this->preview); connect( this->ui->invert, &QCheckBox::clicked, this, &MultiplyFactorDialog::updatePreview); connect( this->ui->factor, qOverload<double>(&DoubleSpinBox::valueChanged), this, &MultiplyFactorDialog::updatePreview); } /** * @brief empty destructor, necessary because std::unique_ptr is used with a forward declaration */ MultiplyFactorDialog::~MultiplyFactorDialog() { } /** * @brief Computes the resulting vector * @return the input vector multiplied by the specified vector */ glm::vec3 MultiplyFactorDialog::value() const { glm::vec3 result = baseVector; if (this->ui->invert->isChecked()) { if (qFuzzyIsNull(this->ui->factor->value())) { constexpr double infinity = std::numeric_limits<double>::quiet_NaN(); result = {infinity, infinity, infinity}; } else { result /= this->ui->factor->value(); } } else { result *= this->ui->factor->value(); } return result; } /** * @brief Makes a string that is prefixed to the factor input. * @param ui * @return prefix string */ QString prefixForFactorInput(const Ui::MultiplyFactorDialog& ui) { if (ui.invert->isChecked()) { return "1 : "; } else { return ""; } } /** * @brief Makes a string that is suffixed to the factor input. * @param ui * @return prefix string */ QString suffixForFactorInput(const Ui::MultiplyFactorDialog& ui) { if (ui.invert->isChecked()) { // render the actual factor that stuff gets effectively multiplied by return " = " + QString::number(1.0 / (ui.factor->value())); } else { return ""; } } /** * @brief Responds to changes in the value and updates previews accordingly */ void MultiplyFactorDialog::updatePreview() { this->ui->factor->setPrefix(::prefixForFactorInput(*this->ui)); this->ui->factor->setSuffix(::suffixForFactorInput(*this->ui)); this->preview.setValue(this->value()); }