src/widgets/vertexobjecteditor.cpp

Sun, 10 Jun 2018 23:07:24 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 10 Jun 2018 23:07:24 +0300
changeset 1401
59b578c77111
parent 1395
23551de3da36
permissions
-rw-r--r--

fixed bugs regarding circular primitives

1302
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1298
diff changeset
1 /*
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1298
diff changeset
2 * LDForge: LDraw parts authoring CAD
1326
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1302
diff changeset
3 * Copyright (C) 2013 - 2018 Teemu Piippo
1302
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1298
diff changeset
4 *
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1298
diff changeset
5 * This program is free software: you can redistribute it and/or modify
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1298
diff changeset
6 * it under the terms of the GNU General Public License as published by
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1298
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1298
diff changeset
8 * (at your option) any later version.
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1298
diff changeset
9 *
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1298
diff changeset
10 * This program is distributed in the hope that it will be useful,
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1298
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1298
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1298
diff changeset
13 * GNU General Public License for more details.
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1298
diff changeset
14 *
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1298
diff changeset
15 * You should have received a copy of the GNU General Public License
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1298
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1298
diff changeset
17 */
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1298
diff changeset
18
1296
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 #include <QDoubleSpinBox>
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 #include "../linetypes/modelobject.h"
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 #include "vertexobjecteditor.h"
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 #include "ui_vertexobjecteditor.h"
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 #include "../dialogs/colorselector.h"
1297
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1296
diff changeset
24 #include "../guiutilities.h"
1296
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 VertexObjectEditor::VertexObjectEditor(LDObject* object, QWidget *parent) :
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 QDialog {parent},
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 ui {*new Ui_VertexObjectEditor},
1392
0541d9b21968 fix compiler warnings
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
29 vertexGrid {new QGridLayout},
0541d9b21968 fix compiler warnings
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
30 object {object}
1296
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 this->ui.setupUi(this);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 this->ui.verticesContainer->setLayout(this->vertexGrid);
1395
23551de3da36 separated the color button into a new widget
Teemu Piippo <teemu@hecknology.net>
parents: 1392
diff changeset
34 this->ui.colorButton->setColor(object->color());
1296
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 for (int i : range(0, 1, object->numVertices() - 1))
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 for (Axis axis : {X, Y, Z})
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 QDoubleSpinBox* spinbox = new QDoubleSpinBox;
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 spinbox->setMinimum(-1e6);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 spinbox->setMaximum(1e6);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 spinbox->setDecimals(5);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 this->vertexGrid->addWidget(spinbox, 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 for (int i : range(0, 1, object->numVertices() - 1))
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 for (Axis axis : {X, Y, Z})
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 QDoubleSpinBox* spinbox = this->spinboxAt(i, axis);
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 if (spinbox)
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55 spinbox->setValue(this->object->vertex(i)[axis]);
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 }
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
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
60 VertexObjectEditor::~VertexObjectEditor()
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 delete &this->ui;
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
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
65 QDoubleSpinBox* VertexObjectEditor::spinboxAt(int i, Axis axis)
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 QWidget* widget = this->vertexGrid->itemAtPosition(i, axis)->widget();
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
68 return qobject_cast<QDoubleSpinBox*>(widget);
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 void VertexObjectEditor::accept()
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
72 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
73 for (int i : range(0, 1, object->numVertices() - 1))
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
74 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
75 Vertex vertex;
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 for (Axis axis : {X, Y, Z})
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
78 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
79 QDoubleSpinBox* spinbox = this->spinboxAt(i, axis);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
80
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
81 if (spinbox)
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
82 vertex.setCoordinate(axis, spinbox->value());
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
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
85 this->object->setVertex(i, vertex);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
86 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
87
1395
23551de3da36 separated the color button into a new widget
Teemu Piippo <teemu@hecknology.net>
parents: 1392
diff changeset
88 this->object->setColor(ui.colorButton->color());
1296
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
89 QDialog::accept();
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
90 }

mercurial