finetuning in multiplyfactordialog

Mon, 11 May 2020 12:18:04 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 11 May 2020 12:18:04 +0300
changeset 88
14e51640c189
parent 87
93ec4d630346
child 89
7abaf1d64719

finetuning in multiplyfactordialog

src/ui/multiplyfactordialog.cpp file | annotate | diff | comparison | revisions
src/ui/multiplyfactordialog.ui file | annotate | diff | comparison | revisions
--- 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());
 }
--- a/src/ui/multiplyfactordialog.ui	Wed Mar 25 16:07:20 2020 +0200
+++ b/src/ui/multiplyfactordialog.ui	Mon May 11 12:18:04 2020 +0300
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>436</width>
-    <height>128</height>
+    <width>286</width>
+    <height>169</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -15,38 +15,38 @@
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
-    <layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1">
-     <item>
-      <layout class="QFormLayout" name="formLayout">
-       <item row="0" column="0">
-        <widget class="QLabel" name="label">
-         <property name="text">
-          <string>Factor:</string>
-         </property>
-        </widget>
-       </item>
-       <item row="0" column="1">
-        <widget class="DoubleSpinBox" name="factor"/>
-       </item>
-       <item row="1" column="1">
-        <widget class="QCheckBox" name="invert">
-         <property name="text">
-          <string>Invert</string>
-         </property>
-        </widget>
-       </item>
-      </layout>
+    <layout class="QFormLayout" name="formLayout">
+     <item row="0" column="0">
+      <widget class="QLabel" name="label">
+       <property name="text">
+        <string>Factor:</string>
+       </property>
+      </widget>
      </item>
-     <item>
-      <widget class="QGroupBox" name="previewGroupBox">
-       <property name="title">
-        <string>Preview</string>
+     <item row="0" column="1">
+      <widget class="DoubleSpinBox" name="factor">
+       <property name="value">
+        <double>1.000000000000000</double>
+       </property>
+      </widget>
+     </item>
+     <item row="1" column="1">
+      <widget class="QCheckBox" name="invert">
+       <property name="text">
+        <string>Invert</string>
        </property>
       </widget>
      </item>
     </layout>
    </item>
    <item>
+    <widget class="QGroupBox" name="previewGroupBox">
+     <property name="title">
+      <string>Preview</string>
+     </property>
+    </widget>
+   </item>
+   <item>
     <widget class="QDialogButtonBox" name="buttonBox">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>

mercurial