Sat, 31 Mar 2018 18:41:24 +0300
start rework
1302 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
1326 | 3 | * Copyright (C) 2013 - 2018 Teemu Piippo |
1302 | 4 | * |
5 | * This program is free software: you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation, either version 3 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
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" |
1366 | 21 | #include "../model.h" |
1296
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
22 | #include "vertexobjecteditor.h" |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
23 | #include "ui_vertexobjecteditor.h" |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
24 | #include "../dialogs/colorselector.h" |
1297
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1296
diff
changeset
|
25 | #include "../guiutilities.h" |
1296
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
26 | |
1366 | 27 | VertexObjectEditor::VertexObjectEditor( |
28 | LDObject* object, | |
29 | Model* model, | |
30 | QWidget *parent | |
31 | ) : | |
1296
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
32 | QDialog {parent}, |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
33 | object {object}, |
1366 | 34 | model {model}, |
1296
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
35 | ui {*new Ui_VertexObjectEditor}, |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
36 | vertexGrid {new QGridLayout} |
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 | this->ui.setupUi(this); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
39 | this->ui.verticesContainer->setLayout(this->vertexGrid); |
1297
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1296
diff
changeset
|
40 | this->currentColor = this->object->color(); |
1298
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
41 | setColorButton(this->ui.color, this->currentColor); |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
42 | |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
43 | connect( |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
44 | this->ui.color, |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
45 | &QPushButton::clicked, |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
46 | [&]() |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
47 | { |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
48 | 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
|
49 | ::setColorButton(this->ui.color, this->currentColor); |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
50 | } |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
51 | ); |
1296
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 | for (int i : range(0, 1, object->numVertices() - 1)) |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
54 | { |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
55 | for (Axis axis : {X, Y, Z}) |
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 | QDoubleSpinBox* spinbox = new QDoubleSpinBox; |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
58 | spinbox->setMinimum(-1e6); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
59 | spinbox->setMaximum(1e6); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
60 | spinbox->setDecimals(5); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
61 | this->vertexGrid->addWidget(spinbox, i, axis); |
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 | } |
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 | for (int i : range(0, 1, object->numVertices() - 1)) |
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 | for (Axis axis : {X, Y, Z}) |
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 | QDoubleSpinBox* spinbox = this->spinboxAt(i, axis); |
1366 | 70 | Vertex vertex = this->model->map(this->object->vertex(i)); |
1296
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 | if (spinbox) |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
73 | spinbox->setValue(this->object->vertex(i)[axis]); |
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 | } |
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 | VertexObjectEditor::~VertexObjectEditor() |
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 | delete &this->ui; |
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 | |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
83 | QDoubleSpinBox* VertexObjectEditor::spinboxAt(int i, Axis axis) |
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 | QWidget* widget = this->vertexGrid->itemAtPosition(i, axis)->widget(); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
86 | return qobject_cast<QDoubleSpinBox*>(widget); |
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 | |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
89 | void VertexObjectEditor::accept() |
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 | for (int i : range(0, 1, object->numVertices() - 1)) |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
92 | { |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
93 | Vertex vertex; |
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 | for (Axis axis : {X, Y, Z}) |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
96 | { |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
97 | QDoubleSpinBox* spinbox = this->spinboxAt(i, axis); |
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 | if (spinbox) |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
100 | vertex.setCoordinate(axis, spinbox->value()); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
101 | } |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
102 | |
1366 | 103 | this->object->setVertex(i, this->model->unmap(vertex)); |
1296
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
104 | } |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
105 | |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
106 | this->object->setColor(this->currentColor); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
107 | QDialog::accept(); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
108 | } |