src/widgets/vertexobjecteditor.cpp

Sat, 17 Mar 2018 23:59:15 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 17 Mar 2018 23:59:15 +0200
changeset 1296
aee618d087ff
child 1297
389516787a4c
permissions
-rw-r--r--

Added vertex object editing dialog

1296
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #include <QDoubleSpinBox>
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 #include "../linetypes/modelobject.h"
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3 #include "vertexobjecteditor.h"
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 #include "ui_vertexobjecteditor.h"
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 #include "../dialogs/colorselector.h"
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 VertexObjectEditor::VertexObjectEditor(LDObject* object, QWidget *parent) :
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 QDialog {parent},
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 object {object},
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 ui {*new Ui_VertexObjectEditor},
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 vertexGrid {new QGridLayout}
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 this->ui.setupUi(this);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 this->ui.verticesContainer->setLayout(this->vertexGrid);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 connect(
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 this->ui.color,
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 &QPushButton::clicked,
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 [&]()
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 ColorSelector::selectColor(this, this->currentColor, this->currentColor);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 this->setColorButton(this->currentColor);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 );
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 for (int i : range(0, 1, object->numVertices() - 1))
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 for (Axis axis : {X, Y, Z})
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 QDoubleSpinBox* spinbox = new QDoubleSpinBox;
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 spinbox->setMinimum(-1e6);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 spinbox->setMaximum(1e6);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 spinbox->setDecimals(5);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 this->vertexGrid->addWidget(spinbox, i, axis);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 for (int i : range(0, 1, object->numVertices() - 1))
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 for (Axis axis : {X, Y, Z})
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 QDoubleSpinBox* spinbox = this->spinboxAt(i, axis);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 if (spinbox)
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 spinbox->setValue(this->object->vertex(i)[axis]);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 this->currentColor = this->object->color();
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 this->setColorButton(this->object->color());
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52 VertexObjectEditor::~VertexObjectEditor()
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 delete &this->ui;
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
57 void VertexObjectEditor::setColorButton(LDColor color)
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
59 if (color.isValid())
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
60 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
61 this->ui.color->setText(color.name());
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62 this->ui.color->setStyleSheet(format("background-color: %1", color.hexcode()));
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
63 this->ui.color->setStyleSheet(format("color: %1", color.edgeColor().name()));
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
64 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
65 else
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
66 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
67 this->ui.color->setText("");
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
68 this->ui.color->setStyleSheet("");
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
69 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
70 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
71
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
72 QDoubleSpinBox* VertexObjectEditor::spinboxAt(int i, Axis axis)
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
73 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
74 QWidget* widget = this->vertexGrid->itemAtPosition(i, axis)->widget();
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
75 return qobject_cast<QDoubleSpinBox*>(widget);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
76 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
77
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
78 void VertexObjectEditor::accept()
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
79 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
80 for (int i : range(0, 1, object->numVertices() - 1))
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
81 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
82 Vertex vertex;
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
83
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
84 for (Axis axis : {X, Y, Z})
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
85 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
86 QDoubleSpinBox* spinbox = this->spinboxAt(i, axis);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
87
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
88 if (spinbox)
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
89 vertex.setCoordinate(axis, spinbox->value());
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
90 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
91
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
92 this->object->setVertex(i, vertex);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
93 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
94
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
95 this->object->setColor(this->currentColor);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
96 QDialog::accept();
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
97 }

mercurial