src/ui/multiplyfactordialog.cpp

Sun, 10 Jan 2021 17:26:40 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 10 Jan 2021 17:26:40 +0200
changeset 98
ae14da3d883f
parent 88
14e51640c189
child 115
ed884a2fb009
permissions
-rw-r--r--

added translations to dependencies in CMakeLists... maybe that's the source of the trouble with translations getting emptied

81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #include "multiplyfactordialog.h"
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 #include "ui_multiplyfactordialog.h"
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 MultiplyFactorDialog::MultiplyFactorDialog(const glm::vec3& baseVector, QWidget* parent) :
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 QDialog{parent},
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 baseVector{baseVector},
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 preview{baseVector, parent, Vec3Editor::NoMultiplyButton}
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 ui = std::make_unique<Ui::MultiplyFactorDialog>();
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 ui->setupUi(this);
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 this->preview.setEnabled(false);
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 this->ui->previewGroupBox->setLayout(new QVBoxLayout{parent});
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 this->ui->previewGroupBox->layout()->addWidget(&this->preview);
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 connect(this->ui->invert, &QCheckBox::clicked, this, &MultiplyFactorDialog::updatePreview);
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 connect(this->ui->factor, qOverload<double>(&DoubleSpinBox::valueChanged), this, &MultiplyFactorDialog::updatePreview);
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17
88
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
18 /**
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
19 * @brief empty destructor, necessary because std::unique_ptr is used with a forward declaration
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
20 */
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 MultiplyFactorDialog::~MultiplyFactorDialog()
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24
88
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
25 /**
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
26 * @brief Computes the resulting vector
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
27 * @return the input vector multiplied by the specified vector
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
28 */
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 glm::vec3 MultiplyFactorDialog::value() const
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 glm::vec3 result = baseVector;
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 if (this->ui->invert->isChecked())
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 {
88
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
34 if (qFuzzyIsNull(this->ui->factor->value()))
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
35 {
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
36 constexpr double infinity = std::numeric_limits<double>::quiet_NaN();
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
37 result = {infinity, infinity, infinity};
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
38 }
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
39 else
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
40 {
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
41 result /= this->ui->factor->value();
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
42 }
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 else
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 result *= this->ui->factor->value();
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 return result;
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50
88
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
51 /**
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
52 * @brief Makes a string that is prefixed to the factor input.
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
53 * @param ui
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
54 * @return prefix string
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
55 */
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
56 QString prefixForFactorInput(const Ui::MultiplyFactorDialog& ui)
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
57 {
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
58 if (ui.invert->isChecked())
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
59 {
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
60 return "1 : ";
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
61 }
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
62 else
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
63 {
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
64 return "";
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
65 }
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
66 }
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
67
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
68 /**
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
69 * @brief Makes a string that is suffixed to the factor input.
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
70 * @param ui
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
71 * @return prefix string
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
72 */
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
73 QString suffixForFactorInput(const Ui::MultiplyFactorDialog& ui)
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
74 {
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
75 if (ui.invert->isChecked())
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
76 {
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
77 // render the actual factor that stuff gets effectively multiplied by
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
78 return " = " + QString::number(1.0 / (ui.factor->value()));
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
79 }
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
80 else
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
81 {
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
82 return "";
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
83 }
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
84 }
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
85
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
86 /**
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
87 * @brief Responds to changes in the value and updates previews accordingly
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
88 */
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
89 void MultiplyFactorDialog::updatePreview()
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
90 {
88
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
91 this->ui->factor->setPrefix(::prefixForFactorInput(*this->ui));
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
92 this->ui->factor->setSuffix(::suffixForFactorInput(*this->ui));
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
93 this->preview.setValue(this->value());
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
94 }

mercurial