Wed, 22 Jun 2022 21:46:38 +0300
Rename Vec3Editor to VectorInput
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
1 | #include <QDialog> |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
2 | #include <QCheckBox> |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
3 | #include <QSignalBlocker> |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
4 | #include "vec3editor.h" |
252
da4876bfd822
Move some widgets into a static library
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
5 | #include "multiplyfactordialog.h" |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
6 | |
254
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
7 | VectorInput::VectorInput(const glm::vec3& value, QWidget* parent, QFlags<VectorInput::Flag> flags) : |
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
8 | VectorInput{parent, flags} |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
9 | { |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
10 | this->setValue(value); |
254
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
11 | } |
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
12 | |
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
13 | VectorInput::VectorInput(QWidget *parent, QFlags<Flag> flags) : |
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
14 | QWidget{parent} |
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
15 | { |
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
16 | |
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
17 | this->ui.setupUi(this); |
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
18 | if (flags.testFlag(NoMultiplyButton)) { |
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
19 | this->ui.multiply->setVisible(false); |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
20 | } |
254
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
21 | else { |
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
22 | connect(this->ui.multiply, &QPushButton::clicked, this, &VectorInput::multiplyPressed); |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
23 | } |
254
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
24 | for (QDoubleSpinBox* spinbox : this->spinboxes()) { |
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
25 | connect(spinbox, qOverload<double>(&QDoubleSpinBox::valueChanged), [&](double){ |
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
26 | Q_EMIT this->valueChanged(this->value()); |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
27 | }); |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
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 | } |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
30 | |
254
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
31 | VectorInput::~VectorInput() |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
32 | { |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
33 | } |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
34 | |
254
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
35 | glm::vec3 VectorInput::value() const |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
36 | { |
252
da4876bfd822
Move some widgets into a static library
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
37 | auto get = [](DoubleSpinBox* spinbox){ return static_cast<float>(spinbox->value()); }; |
254
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
38 | return {get(this->ui.x), get(this->ui.y), get(this->ui.z)}; |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
39 | } |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
40 | |
254
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
41 | void VectorInput::setValue(const glm::vec3& value) |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
42 | { |
254
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
43 | auto set = [](DoubleSpinBox* spinbox, float value){ |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
44 | QSignalBlocker blocker{spinbox}; |
252
da4876bfd822
Move some widgets into a static library
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
45 | spinbox->setValue(static_cast<qreal>(value)); |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
46 | }; |
254
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
47 | set(this->ui.x, value.x); |
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
48 | set(this->ui.y, value.y); |
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
49 | set(this->ui.z, value.z); |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
50 | Q_EMIT this->valueChanged(value); |
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 | |
254
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
53 | std::array<DoubleSpinBox*, 3> VectorInput::spinboxes() |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
54 | { |
254
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
55 | return {this->ui.x, this->ui.y, this->ui.z}; |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
56 | } |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
57 | |
254
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
58 | void VectorInput::multiplyPressed() |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
59 | { |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
60 | MultiplyFactorDialog dialog{this->value(), this}; |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
61 | const int dialogResult = dialog.exec(); |
254
b7b29cb82360
Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
62 | if (dialogResult == QDialog::Accepted) { |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
63 | this->setValue(dialog.value()); |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
64 | } |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
65 | } |