src/widgets/vertexobjecteditor.cpp

Sat, 24 Mar 2018 13:48:50 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 24 Mar 2018 13:48:50 +0200
changeset 1332
1fffb24d4ffe
parent 1326
69a90bd2dba2
child 1366
69087b1e123b
child 1392
0541d9b21968
permissions
-rw-r--r--

replaced remaining DIRSLASH, Dirname and Basename uses with Qt file info stuff

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 object {object},
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 ui {*new Ui_VertexObjectEditor},
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 vertexGrid {new QGridLayout}
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);
1297
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1296
diff changeset
34 this->currentColor = this->object->color();
1298
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
35 setColorButton(this->ui.color, this->currentColor);
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
36
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
37 connect(
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
38 this->ui.color,
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
39 &QPushButton::clicked,
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
40 [&]()
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
41 {
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
42 if (ColorSelector::selectColor(this, this->currentColor, this->currentColor))
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
43 ::setColorButton(this->ui.color, this->currentColor);
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
44 }
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
45 );
1296
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 for (int i : range(0, 1, object->numVertices() - 1))
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 for (Axis axis : {X, Y, Z})
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 QDoubleSpinBox* spinbox = new QDoubleSpinBox;
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52 spinbox->setMinimum(-1e6);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 spinbox->setMaximum(1e6);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 spinbox->setDecimals(5);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55 this->vertexGrid->addWidget(spinbox, 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 for (int i : range(0, 1, object->numVertices() - 1))
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 for (Axis axis : {X, Y, Z})
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
63 QDoubleSpinBox* spinbox = this->spinboxAt(i, axis);
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 if (spinbox)
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
66 spinbox->setValue(this->object->vertex(i)[axis]);
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 }
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 VertexObjectEditor::~VertexObjectEditor()
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 delete &this->ui;
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
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
76 QDoubleSpinBox* VertexObjectEditor::spinboxAt(int i, Axis axis)
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 QWidget* widget = this->vertexGrid->itemAtPosition(i, axis)->widget();
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
79 return qobject_cast<QDoubleSpinBox*>(widget);
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
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
82 void VertexObjectEditor::accept()
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 (int i : range(0, 1, object->numVertices() - 1))
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 Vertex vertex;
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 for (Axis axis : {X, Y, Z})
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
89 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
90 QDoubleSpinBox* spinbox = this->spinboxAt(i, axis);
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 if (spinbox)
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
93 vertex.setCoordinate(axis, spinbox->value());
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
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
96 this->object->setVertex(i, vertex);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
97 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
98
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
99 this->object->setColor(this->currentColor);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
100 QDialog::accept();
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
101 }

mercurial