widgets/vec3editor.cpp

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

mercurial