src/widgets/vertexobjecteditor.cpp

Sun, 18 Mar 2018 12:00:39 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 18 Mar 2018 12:00:39 +0200
changeset 1297
389516787a4c
parent 1296
aee618d087ff
child 1298
dbc8bb2a4d84
permissions
-rw-r--r--

added subfile reference editor

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"
1297
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1296
diff changeset
6 #include "../guiutilities.h"
1296
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 VertexObjectEditor::VertexObjectEditor(LDObject* object, QWidget *parent) :
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 QDialog {parent},
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 object {object},
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 ui {*new Ui_VertexObjectEditor},
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 vertexGrid {new QGridLayout}
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 this->ui.setupUi(this);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 this->ui.verticesContainer->setLayout(this->vertexGrid);
1297
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1296
diff changeset
16 this->currentColor = this->object->color();
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1296
diff changeset
17 ::setupColorButton(parent, this->ui.color, &this->currentColor);
1296
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 for (int i : range(0, 1, object->numVertices() - 1))
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 for (Axis axis : {X, Y, Z})
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 QDoubleSpinBox* spinbox = new QDoubleSpinBox;
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 spinbox->setMinimum(-1e6);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 spinbox->setMaximum(1e6);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 spinbox->setDecimals(5);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 this->vertexGrid->addWidget(spinbox, i, axis);
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 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 for (int i : range(0, 1, object->numVertices() - 1))
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 for (Axis axis : {X, Y, Z})
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 QDoubleSpinBox* spinbox = this->spinboxAt(i, axis);
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 if (spinbox)
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 spinbox->setValue(this->object->vertex(i)[axis]);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 }
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 }
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 VertexObjectEditor::~VertexObjectEditor()
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 delete &this->ui;
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 QDoubleSpinBox* VertexObjectEditor::spinboxAt(int i, Axis axis)
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 QWidget* widget = this->vertexGrid->itemAtPosition(i, axis)->widget();
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 return qobject_cast<QDoubleSpinBox*>(widget);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52 }
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 void VertexObjectEditor::accept()
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 for (int i : range(0, 1, object->numVertices() - 1))
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
57 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58 Vertex vertex;
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
59
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
60 for (Axis axis : {X, Y, Z})
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
61 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62 QDoubleSpinBox* spinbox = this->spinboxAt(i, axis);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
63
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
64 if (spinbox)
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
65 vertex.setCoordinate(axis, spinbox->value());
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
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
68 this->object->setVertex(i, vertex);
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 this->object->setColor(this->currentColor);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
72 QDialog::accept();
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
73 }

mercurial