src/dialogs/circularprimitiveeditor.cpp

Tue, 19 Jun 2018 23:59:05 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 19 Jun 2018 23:59:05 +0300
changeset 1414
04db55860880
parent 1413
6b0ca41c158f
child 1415
006ced515057
permissions
-rw-r--r--

simplified

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 );
1412
f5eb947a2e7f added support for inverting circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1408
diff changeset
123 connect(ui.inverted, &QCheckBox::clicked, [&](bool checked)
f5eb947a2e7f added support for inverting circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1408
diff changeset
124 {
f5eb947a2e7f added support for inverting circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1408
diff changeset
125 if (this->primitive)
f5eb947a2e7f added support for inverting circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1408
diff changeset
126 this->primitive->setInverted(checked);
f5eb947a2e7f added support for inverting circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1408
diff changeset
127 });
1413
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
128 connect(ui.rotateCcw, &QPushButton::clicked, [&](){ rotate(-1); });
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
129 connect(ui.rotateCw, &QPushButton::clicked, [&](){ rotate(1); });
1406
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
130 // 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
131 connect(
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
132 ui.buttonBox,
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
133 &QDialogButtonBox::clicked,
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
134 [&](QAbstractButton* button)
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 (ui.buttonBox->buttonRole(button) == QDialogButtonBox::ResetRole)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
137 reset();
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 );
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
140
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
141 if (this->primitive)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
142 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
143 // 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
144 connect(this->primitive, &LDObject::modified, this, &CircularPrimitiveEditor::updateWidgets);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
145
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
146 // If the object is deleted, then destroy the dialog.
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
147 connect(this->primitive, &LDObject::destroyed, this, &QDialog::reject);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
148 }
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
149 }
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 * Frees the user interface memory after the dialog is destroyed.
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
153 */
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
154 CircularPrimitiveEditor::~CircularPrimitiveEditor()
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
155 {
1395
23551de3da36 separated the color button into a new widget
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
156 delete &ui;
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
157 }
1406
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 /*
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
160 * 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
161 */
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
162 void CircularPrimitiveEditor::updateWidgets()
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
163 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
164 setEnabled(primitive != nullptr);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
165
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
166 if (primitive)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
167 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
168 for (const auto& mapping : ::radioButtonMap)
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 // Choose the correct radio button
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
171 QRadioButton* button = mapping.resolve(ui);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
172 withSignalsBlocked(button, [&]()
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
173 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
174 button->setChecked(primitive->primitiveType() == mapping.primitiveType);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
175 });
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
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
178 // Set the values of the form.
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
179 withSignalsBlocked(ui.segments, [&](){ ui.segments->setValue(primitive->segments()); });
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
180 withSignalsBlocked(ui.divisions, [&]()
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 ui.divisions->setCurrentText(QString::number(primitive->divisions()));
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
183 });
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
184 withSignalsBlocked(ui.color, [&](){ ui.color->setColor(primitive->color()); });
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
185 withSignalsBlocked(ui.matrix, [&](){ ui.matrix->setMatrix(primitive->transformationMatrix()); });
1412
f5eb947a2e7f added support for inverting circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1408
diff changeset
186 withSignalsBlocked(ui.inverted, [&](){ ui.inverted->setChecked(primitive->isInverted()); });
1406
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
187 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
188 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
189
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
190 /*
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
191 * 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
192 */
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
193 void CircularPrimitiveEditor::reset()
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
194 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
195 if (primitive)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
196 primitive->restore(originalState); // Restoring does not change 'originalState'
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
197 }
1413
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
198
1414
04db55860880 simplified
Teemu Piippo <teemu@hecknology.net>
parents: 1413
diff changeset
199 /*
04db55860880 simplified
Teemu Piippo <teemu@hecknology.net>
parents: 1413
diff changeset
200 * Rotates the primitive around its origin. The angle depends on its resolution and the passed 'factor' parameter.
04db55860880 simplified
Teemu Piippo <teemu@hecknology.net>
parents: 1413
diff changeset
201 */
1413
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
202 void CircularPrimitiveEditor::rotate(double factor)
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
203 {
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
204 if (primitive)
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
205 {
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
206 double angle = factor * 360.0 / primitive->divisions();
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
207 QMatrix4x4 matrix = primitive->transformationMatrix();
1414
04db55860880 simplified
Teemu Piippo <teemu@hecknology.net>
parents: 1413
diff changeset
208 matrix.rotate(QQuaternion::fromAxisAndAngle({0.0f, 1.0f, 0.0f}, angle));
1413
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
209 primitive->setTransformationMatrix(matrix);
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
210 }
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
211 }

mercurial