widgets/vec3editor.cpp

Sat, 02 Jul 2022 19:03:57 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sat, 02 Jul 2022 19:03:57 +0300
changeset 315
23b47902d857
parent 264
76a025db4948
permissions
-rw-r--r--

Improve preview of cylinder extrusion

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>
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: 255
diff changeset
4 #include "widgets/vec3editor.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: 255
diff changeset
5 #include "widgets/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 this->ui.setupUi(this);
b7b29cb82360 Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 252
diff changeset
17 if (flags.testFlag(NoMultiplyButton)) {
b7b29cb82360 Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 252
diff changeset
18 this->ui.multiply->setVisible(false);
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 }
254
b7b29cb82360 Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 252
diff changeset
20 else {
b7b29cb82360 Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 252
diff changeset
21 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
22 }
254
b7b29cb82360 Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 252
diff changeset
23 for (QDoubleSpinBox* spinbox : this->spinboxes()) {
b7b29cb82360 Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 252
diff changeset
24 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
25 Q_EMIT this->valueChanged(this->value());
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
26 });
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
27 }
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29
254
b7b29cb82360 Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 252
diff changeset
30 VectorInput::~VectorInput()
81
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 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33
254
b7b29cb82360 Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 252
diff changeset
34 glm::vec3 VectorInput::value() const
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 {
252
da4876bfd822 Move some widgets into a static library
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
36 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
37 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
38 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39
254
b7b29cb82360 Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 252
diff changeset
40 void VectorInput::setValue(const glm::vec3& value)
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 {
254
b7b29cb82360 Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 252
diff changeset
42 auto set = [](DoubleSpinBox* spinbox, float value){
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 QSignalBlocker blocker{spinbox};
252
da4876bfd822 Move some widgets into a static library
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
44 spinbox->setValue(static_cast<qreal>(value));
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 };
254
b7b29cb82360 Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 252
diff changeset
46 set(this->ui.x, value.x);
b7b29cb82360 Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 252
diff changeset
47 set(this->ui.y, value.y);
b7b29cb82360 Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 252
diff changeset
48 set(this->ui.z, value.z);
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 Q_EMIT this->valueChanged(value);
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51
255
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
52 qreal VectorInput::x() const
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
53 {
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
54 return this->ui.x->value();
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
55 }
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
56
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
57 qreal VectorInput::y() const
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
58 {
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
59 return this->ui.y->value();
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
60 }
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
61
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
62 qreal VectorInput::z() const
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
63 {
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
64 return this->ui.z->value();
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
65 }
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
66
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
67 void VectorInput::setX(qreal x)
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
68 {
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
69 this->ui.x->setValue(x);
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
70 }
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
71
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
72 void VectorInput::setY(qreal y)
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
73 {
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
74 this->ui.y->setValue(y);
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
75 }
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
76
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
77 void VectorInput::setZ(qreal z)
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
78 {
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
79 this->ui.z->setValue(z);
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
80 }
5188f8a74a5c Add x, y, z properties to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 254
diff changeset
81
254
b7b29cb82360 Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 252
diff changeset
82 std::array<DoubleSpinBox*, 3> VectorInput::spinboxes()
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
83 {
254
b7b29cb82360 Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 252
diff changeset
84 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
85 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
86
254
b7b29cb82360 Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 252
diff changeset
87 void VectorInput::multiplyPressed()
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
88 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
89 MultiplyFactorDialog dialog{this->value(), this};
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
90 const int dialogResult = dialog.exec();
254
b7b29cb82360 Rename Vec3Editor to VectorInput
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 252
diff changeset
91 if (dialogResult == QDialog::Accepted) {
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
92 this->setValue(dialog.value());
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
93 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
94 }

mercurial