src/ui/multiplyfactordialog.cpp

changeset 88
14e51640c189
parent 81
62373840e33a
child 115
ed884a2fb009
--- a/src/ui/multiplyfactordialog.cpp	Wed Mar 25 16:07:20 2020 +0200
+++ b/src/ui/multiplyfactordialog.cpp	Mon May 11 12:18:04 2020 +0300
@@ -15,16 +15,31 @@
 	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())
 	{
-		result /= this->ui->factor->value();
+		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
 	{
@@ -33,7 +48,47 @@
 	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());
 }

mercurial