src/widgets/vec3editor.cpp

changeset 81
62373840e33a
child 86
4bec0525ef1b
equal deleted inserted replaced
80:764381756899 81:62373840e33a
1 #include <QDialog>
2 #include <QCheckBox>
3 #include <QSignalBlocker>
4 #include "vec3editor.h"
5 #include "ui_vec3editor.h"
6 #include "../ui/multiplyfactordialog.h"
7
8 Vec3Editor::Vec3Editor(const glm::vec3& value, QWidget *parent, QFlags<Flag> flags) :
9 QWidget{parent},
10 ui{new Ui::Vec3Editor}
11 {
12 this->ui->setupUi(this);
13 this->setValue(value);
14 if (flags.testFlag(NoMultiplyButton))
15 {
16 this->ui->multiply->setVisible(false);
17 }
18 else
19 {
20 connect(this->ui->multiply, &QPushButton::clicked, this, &Vec3Editor::multiplyPressed);
21 }
22 }
23
24 Vec3Editor::~Vec3Editor()
25 {
26 }
27
28 glm::vec3 Vec3Editor::value() const
29 {
30 auto get = [](DoubleSpinBox* spinbox){ return toFloat(spinbox->value()); };
31 return {get(this->ui->x), get(this->ui->y), get(this->ui->z)};
32 }
33
34 void Vec3Editor::setValue(const glm::vec3& value)
35 {
36 auto set = [](DoubleSpinBox* spinbox, float value)
37 {
38 QSignalBlocker blocker{spinbox};
39 spinbox->setValue(toQreal(value));
40 };
41 set(this->ui->x, value.x);
42 set(this->ui->y, value.y);
43 set(this->ui->z, value.z);
44 Q_EMIT this->valueChanged(value);
45 }
46
47 std::array<DoubleSpinBox*, 3> Vec3Editor::spinboxes()
48 {
49 return {this->ui->x, this->ui->y, this->ui->z};
50 }
51
52 void Vec3Editor::multiplyPressed()
53 {
54 MultiplyFactorDialog dialog{this->value(), this};
55 const int dialogResult = dialog.exec();
56 if (dialogResult == QDialog::Accepted)
57 {
58 this->setValue(dialog.value());
59 }
60 }

mercurial