Sat, 08 Apr 2023 12:55:11 +0300
Fix BFC formatting not working due to being evaluated after comment format
264
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
254
diff
changeset
|
1 | #include <ui_multiplyfactordialog.h> |
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
254
diff
changeset
|
2 | #include "widgets/multiplyfactordialog.h" |
81
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}, |
254
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
7 | preview{baseVector, parent, VectorInput::NoMultiplyButton} |
81
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); |
115 | 14 | connect( |
15 | this->ui->invert, | |
16 | &QCheckBox::clicked, | |
17 | this, | |
18 | &MultiplyFactorDialog::updatePreview); | |
19 | connect( | |
20 | this->ui->factor, | |
21 | qOverload<double>(&DoubleSpinBox::valueChanged), | |
22 | this, | |
23 | &MultiplyFactorDialog::updatePreview); | |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
24 | } |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
25 | |
88
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
26 | /** |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
27 | * @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
|
28 | */ |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
29 | MultiplyFactorDialog::~MultiplyFactorDialog() |
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 | } |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
32 | |
88
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
33 | /** |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
34 | * @brief Computes the resulting vector |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
35 | * @return the input vector multiplied by the specified vector |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
36 | */ |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
37 | glm::vec3 MultiplyFactorDialog::value() const |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
38 | { |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
39 | glm::vec3 result = baseVector; |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
40 | if (this->ui->invert->isChecked()) |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
41 | { |
88
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
42 | if (qFuzzyIsNull(this->ui->factor->value())) |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
43 | { |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
44 | constexpr double infinity = std::numeric_limits<double>::quiet_NaN(); |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
45 | result = {infinity, infinity, infinity}; |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
46 | } |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
47 | else |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
48 | { |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
49 | result /= this->ui->factor->value(); |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
50 | } |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
51 | } |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
52 | else |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
53 | { |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
54 | result *= this->ui->factor->value(); |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
55 | } |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
56 | return result; |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
57 | } |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
58 | |
88
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 | * @brief Makes a string that is prefixed to the factor input. |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
61 | * @param ui |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
62 | * @return prefix string |
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 | QString prefixForFactorInput(const Ui::MultiplyFactorDialog& ui) |
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 | if (ui.invert->isChecked()) |
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 | return "1 : "; |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
69 | } |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
70 | else |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
71 | { |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
72 | return ""; |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
73 | } |
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 | |
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 | * @brief Makes a string that is suffixed to the factor input. |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
78 | * @param ui |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
79 | * @return prefix string |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
80 | */ |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
81 | QString suffixForFactorInput(const Ui::MultiplyFactorDialog& ui) |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
82 | { |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
83 | if (ui.invert->isChecked()) |
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 | // render the actual factor that stuff gets effectively multiplied by |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
86 | return " = " + QString::number(1.0 / (ui.factor->value())); |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
87 | } |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
88 | else |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
89 | { |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
90 | return ""; |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
91 | } |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
92 | } |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
93 | |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
94 | /** |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
95 | * @brief Responds to changes in the value and updates previews accordingly |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
96 | */ |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
97 | void MultiplyFactorDialog::updatePreview() |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
98 | { |
88
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
99 | this->ui->factor->setPrefix(::prefixForFactorInput(*this->ui)); |
14e51640c189
finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
100 | this->ui->factor->setSuffix(::suffixForFactorInput(*this->ui)); |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
101 | this->preview.setValue(this->value()); |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
102 | } |