src/dialogs/circularprimitiveeditor.cpp

Tue, 19 Jun 2018 21:57:39 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 19 Jun 2018 21:57:39 +0300
changeset 1409
2d4649fd9a20
parent 1408
0d6162662040
child 1412
f5eb947a2e7f
permissions
-rw-r--r--

fixed chord triangle count formula

1406
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
1 /*
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
2 * LDForge: LDraw parts authoring CAD
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
3 * Copyright (C) 2013 - 2018 Teemu Piippo
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
4 *
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
5 * This program is free software: you can redistribute it and/or modify
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
6 * it under the terms of the GNU General Public License as published by
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
8 * (at your option) any later version.
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
9 *
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
10 * This program is distributed in the hope that it will be useful,
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
13 * GNU General Public License for more details.
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
14 *
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
15 * You should have received a copy of the GNU General Public License
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
17 */
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
18
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
19 #include "circularprimitiveeditor.h"
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
20 #include "ui_circularprimitiveeditor.h"
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
21 #include "../primitives.h"
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
22
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
23 // offsetof doesn't work if this doesn't hold true
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
24 static_assert(std::is_standard_layout<Ui_CircularPrimitiveEditor>::value, "UI type is not of standard layout");
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25
1406
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
26 // Contains offsets to radio buttons and the choice they represent.
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
27 static const struct
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
28 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
29 std::ptrdiff_t offset;
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
30 PrimitiveModel::Type primitiveType;
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
31
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
32 QRadioButton* resolve(Ui_CircularPrimitiveEditor& ui) const
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
33 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
34 // Find the radio button by pointer arithmetic
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
35 return *reinterpret_cast<QRadioButton**>(reinterpret_cast<char*>(&ui) + offset);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
36 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
37 } radioButtonMap[] = {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
38 #define MAP_RADIO_BUTTON(widget, type) { offsetof(Ui_CircularPrimitiveEditor, widget), PrimitiveModel::type }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
39 MAP_RADIO_BUTTON(circle, Circle),
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
40 MAP_RADIO_BUTTON(cylinder, Cylinder),
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
41 MAP_RADIO_BUTTON(disc, Disc),
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
42 MAP_RADIO_BUTTON(discNegative, DiscNegative),
1407
22bc5862cb56 added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents: 1406
diff changeset
43 MAP_RADIO_BUTTON(cylinderClosed, CylinderClosed),
22bc5862cb56 added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents: 1406
diff changeset
44 MAP_RADIO_BUTTON(cylinderOpen, CylinderOpen),
1408
0d6162662040 fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents: 1407
diff changeset
45 MAP_RADIO_BUTTON(chord, Chord),
1406
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
46 #undef MAP_RADIO_BUTTON
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
47 };
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
48
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
49 /*
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
50 * Constructs a new circular primitive editor and sets up connections.
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
51 */
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
52 CircularPrimitiveEditor::CircularPrimitiveEditor(LDCircularPrimitive* primitive, QWidget* parent) :
1395
23551de3da36 separated the color button into a new widget
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
53 QDialog {parent},
1406
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
54 ui {*new Ui_CircularPrimitiveEditor},
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
55 primitive {primitive}
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 {
1395
23551de3da36 separated the color button into a new widget
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
57 ui.setupUi(this);
1406
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
58
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
59 // Set the initial values of the dialog
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
60 updateWidgets();
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
61
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
62 if (primitive)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
63 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
64 // Store the original state of the object. If the user presses "Reset" then the object is restored
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
65 // from this archive.
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
66 Serializer serializer {originalState, Serializer::Store};
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
67 primitive->serialize(serializer);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
68 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
69
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
70 for (const auto& mapping : ::radioButtonMap)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
71 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
72 QRadioButton* button = mapping.resolve(ui);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
73
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
74 // If the radio button gets checked, update the type of the circular primitive.
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
75 connect(
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
76 button,
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
77 &QRadioButton::toggled,
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
78 [&](bool checked)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
79 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
80 if (checked and this->primitive)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
81 this->primitive->setPrimitiveType(mapping.primitiveType);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
82 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
83 );
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
84 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
85
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
86 // Connect various widgets so that changing them changes the primitive object.
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
87 connect(
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
88 ui.segments,
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
89 qOverload<int>(&QSpinBox::valueChanged),
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
90 [&](int newSegments)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
91 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
92 if (this->primitive)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
93 this->primitive->setSegments(newSegments);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
94 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
95 );
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
96 connect(
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
97 ui.divisions,
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
98 &QComboBox::currentTextChanged,
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
99 [&](const QString& newDivisions)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
100 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
101 if (this->primitive)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
102 this->primitive->setDivisions(newDivisions.toInt());
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
103 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
104 );
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
105 connect(
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
106 ui.color,
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
107 &ColorButton::colorChanged,
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
108 [&](LDColor newColor)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
109 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
110 if (this->primitive)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
111 this->primitive->setColor(newColor);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
112 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
113 );
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
114 connect(
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
115 ui.matrix,
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
116 &MatrixEditor::matrixChanged,
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
117 [&](const QMatrix4x4& newMatrix)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
118 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
119 if (this->primitive)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
120 this->primitive->setTransformationMatrix(newMatrix);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
121 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
122 );
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
123 // Connect the reset button, "reset button" here meaning any button with the reset role.
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
124 connect(
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
125 ui.buttonBox,
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
126 &QDialogButtonBox::clicked,
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
127 [&](QAbstractButton* button)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
128 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
129 if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::ResetRole)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
130 reset();
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
131 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
132 );
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
133
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
134 if (this->primitive)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
135 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
136 // If the primitive is changed by some other thing (e.g. by resetting it), update the widgets.
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
137 connect(this->primitive, &LDObject::modified, this, &CircularPrimitiveEditor::updateWidgets);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
138
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
139 // If the object is deleted, then destroy the dialog.
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
140 connect(this->primitive, &LDObject::destroyed, this, &QDialog::reject);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
141 }
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
142 }
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
143
1406
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
144 /*
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
145 * Frees the user interface memory after the dialog is destroyed.
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
146 */
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
147 CircularPrimitiveEditor::~CircularPrimitiveEditor()
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
148 {
1395
23551de3da36 separated the color button into a new widget
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
149 delete &ui;
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
150 }
1406
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
151
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
152 /*
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
153 * Updates the widgets of the editor to reflect the properites of the object being modified.
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
154 */
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
155 void CircularPrimitiveEditor::updateWidgets()
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
156 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
157 setEnabled(primitive != nullptr);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
158
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
159 if (primitive)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
160 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
161 for (const auto& mapping : ::radioButtonMap)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
162 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
163 // Choose the correct radio button
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
164 QRadioButton* button = mapping.resolve(ui);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
165 withSignalsBlocked(button, [&]()
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
166 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
167 button->setChecked(primitive->primitiveType() == mapping.primitiveType);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
168 });
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
169 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
170
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
171 // Set the values of the form.
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
172 withSignalsBlocked(ui.segments, [&](){ ui.segments->setValue(primitive->segments()); });
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
173 withSignalsBlocked(ui.divisions, [&]()
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
174 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
175 ui.divisions->setCurrentText(QString::number(primitive->divisions()));
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
176 });
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
177 withSignalsBlocked(ui.color, [&](){ ui.color->setColor(primitive->color()); });
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
178 withSignalsBlocked(ui.matrix, [&](){ ui.matrix->setMatrix(primitive->transformationMatrix()); });
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
179 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
180 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
181
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
182 /*
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
183 * Resets the object being modified. The object will emit a signal that is connected to updateWidgets.
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
184 */
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
185 void CircularPrimitiveEditor::reset()
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
186 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
187 if (primitive)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
188 primitive->restore(originalState); // Restoring does not change 'originalState'
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
189 }

mercurial