src/widgets/vertexobjecteditor.cpp

changeset 1297
389516787a4c
parent 1296
aee618d087ff
child 1298
dbc8bb2a4d84
equal deleted inserted replaced
1296:aee618d087ff 1297:389516787a4c
1 #include <QDoubleSpinBox> 1 #include <QDoubleSpinBox>
2 #include "../linetypes/modelobject.h" 2 #include "../linetypes/modelobject.h"
3 #include "vertexobjecteditor.h" 3 #include "vertexobjecteditor.h"
4 #include "ui_vertexobjecteditor.h" 4 #include "ui_vertexobjecteditor.h"
5 #include "../dialogs/colorselector.h" 5 #include "../dialogs/colorselector.h"
6 #include "../guiutilities.h"
6 7
7 VertexObjectEditor::VertexObjectEditor(LDObject* object, QWidget *parent) : 8 VertexObjectEditor::VertexObjectEditor(LDObject* object, QWidget *parent) :
8 QDialog {parent}, 9 QDialog {parent},
9 object {object}, 10 object {object},
10 ui {*new Ui_VertexObjectEditor}, 11 ui {*new Ui_VertexObjectEditor},
11 vertexGrid {new QGridLayout} 12 vertexGrid {new QGridLayout}
12 { 13 {
13 this->ui.setupUi(this); 14 this->ui.setupUi(this);
14 this->ui.verticesContainer->setLayout(this->vertexGrid); 15 this->ui.verticesContainer->setLayout(this->vertexGrid);
15 connect( 16 this->currentColor = this->object->color();
16 this->ui.color, 17 ::setupColorButton(parent, this->ui.color, &this->currentColor);
17 &QPushButton::clicked,
18 [&]()
19 {
20 ColorSelector::selectColor(this, this->currentColor, this->currentColor);
21 this->setColorButton(this->currentColor);
22 }
23 );
24 18
25 for (int i : range(0, 1, object->numVertices() - 1)) 19 for (int i : range(0, 1, object->numVertices() - 1))
26 { 20 {
27 for (Axis axis : {X, Y, Z}) 21 for (Axis axis : {X, Y, Z})
28 { 22 {
42 36
43 if (spinbox) 37 if (spinbox)
44 spinbox->setValue(this->object->vertex(i)[axis]); 38 spinbox->setValue(this->object->vertex(i)[axis]);
45 } 39 }
46 } 40 }
47
48 this->currentColor = this->object->color();
49 this->setColorButton(this->object->color());
50 } 41 }
51 42
52 VertexObjectEditor::~VertexObjectEditor() 43 VertexObjectEditor::~VertexObjectEditor()
53 { 44 {
54 delete &this->ui; 45 delete &this->ui;
55 }
56
57 void VertexObjectEditor::setColorButton(LDColor color)
58 {
59 if (color.isValid())
60 {
61 this->ui.color->setText(color.name());
62 this->ui.color->setStyleSheet(format("background-color: %1", color.hexcode()));
63 this->ui.color->setStyleSheet(format("color: %1", color.edgeColor().name()));
64 }
65 else
66 {
67 this->ui.color->setText("");
68 this->ui.color->setStyleSheet("");
69 }
70 } 46 }
71 47
72 QDoubleSpinBox* VertexObjectEditor::spinboxAt(int i, Axis axis) 48 QDoubleSpinBox* VertexObjectEditor::spinboxAt(int i, Axis axis)
73 { 49 {
74 QWidget* widget = this->vertexGrid->itemAtPosition(i, axis)->widget(); 50 QWidget* widget = this->vertexGrid->itemAtPosition(i, axis)->widget();

mercurial