src/dialogs/circularprimitiveeditor.cpp

Thu, 07 Feb 2019 13:45:07 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 07 Feb 2019 13:45:07 +0200
changeset 1438
988b6563d47d
parent 1418
503d4e7e27c9
permissions
-rw-r--r--

stuff

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(
1418
503d4e7e27c9 used the new CircularSectionEditor in CircularPrimitiveEditor
Teemu Piippo <teemu@hecknology.net>
parents: 1415
diff changeset
88 ui.section,
503d4e7e27c9 used the new CircularSectionEditor in CircularPrimitiveEditor
Teemu Piippo <teemu@hecknology.net>
parents: 1415
diff changeset
89 &CircularSectionEditor::sectionChanged,
503d4e7e27c9 used the new CircularSectionEditor in CircularPrimitiveEditor
Teemu Piippo <teemu@hecknology.net>
parents: 1415
diff changeset
90 [&](const CircularSection& newSection)
1406
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)
1418
503d4e7e27c9 used the new CircularSectionEditor in CircularPrimitiveEditor
Teemu Piippo <teemu@hecknology.net>
parents: 1415
diff changeset
93 this->primitive->setSection(newSection);
1406
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.color,
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
98 &ColorButton::colorChanged,
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
99 [&](LDColor newColor)
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->setColor(newColor);
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.matrix,
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
107 &MatrixEditor::matrixChanged,
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
108 [&](const QMatrix4x4& newMatrix)
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->setTransformationMatrix(newMatrix);
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 );
1412
f5eb947a2e7f added support for inverting circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1408
diff changeset
114 connect(ui.inverted, &QCheckBox::clicked, [&](bool checked)
f5eb947a2e7f added support for inverting circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1408
diff changeset
115 {
f5eb947a2e7f added support for inverting circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1408
diff changeset
116 if (this->primitive)
f5eb947a2e7f added support for inverting circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1408
diff changeset
117 this->primitive->setInverted(checked);
f5eb947a2e7f added support for inverting circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1408
diff changeset
118 });
1413
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
119 connect(ui.rotateCcw, &QPushButton::clicked, [&](){ rotate(-1); });
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
120 connect(ui.rotateCw, &QPushButton::clicked, [&](){ rotate(1); });
1406
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
121 // 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
122 connect(
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
123 ui.buttonBox,
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
124 &QDialogButtonBox::clicked,
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
125 [&](QAbstractButton* button)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
126 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
127 if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::ResetRole)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
128 reset();
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
129 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
130 );
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 if (this->primitive)
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 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
135 connect(this->primitive, &LDObject::modified, this, &CircularPrimitiveEditor::updateWidgets);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
136
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
137 // If the object is deleted, then destroy the dialog.
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
138 connect(this->primitive, &LDObject::destroyed, this, &QDialog::reject);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
139 }
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
140 }
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
141
1406
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 * Frees the user interface memory after the dialog is destroyed.
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 CircularPrimitiveEditor::~CircularPrimitiveEditor()
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
146 {
1395
23551de3da36 separated the color button into a new widget
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
147 delete &ui;
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
148 }
1406
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
149
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
150 /*
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
151 * 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
152 */
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
153 void CircularPrimitiveEditor::updateWidgets()
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 setEnabled(primitive != nullptr);
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 if (primitive)
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 for (const auto& mapping : ::radioButtonMap)
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 // Choose the correct radio button
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
162 QRadioButton* button = mapping.resolve(ui);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
163 withSignalsBlocked(button, [&]()
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
164 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
165 button->setChecked(primitive->primitiveType() == mapping.primitiveType);
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 }
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 // Set the values of the form.
1418
503d4e7e27c9 used the new CircularSectionEditor in CircularPrimitiveEditor
Teemu Piippo <teemu@hecknology.net>
parents: 1415
diff changeset
170 withSignalsBlocked(ui.section, [&](){ ui.section->setSection(primitive->section()); });
1406
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
171 withSignalsBlocked(ui.color, [&](){ ui.color->setColor(primitive->color()); });
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
172 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
173 withSignalsBlocked(ui.inverted, [&](){ ui.inverted->setChecked(primitive->isInverted()); });
1406
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 }
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 * 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
179 */
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
180 void CircularPrimitiveEditor::reset()
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 if (primitive)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
183 primitive->restore(originalState); // Restoring does not change 'originalState'
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1395
diff changeset
184 }
1413
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
185
1414
04db55860880 simplified
Teemu Piippo <teemu@hecknology.net>
parents: 1413
diff changeset
186 /*
04db55860880 simplified
Teemu Piippo <teemu@hecknology.net>
parents: 1413
diff changeset
187 * 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
188 */
1413
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
189 void CircularPrimitiveEditor::rotate(double factor)
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
190 {
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
191 if (primitive)
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
192 {
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
193 double angle = factor * 360.0 / primitive->divisions();
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
194 QMatrix4x4 matrix = primitive->transformationMatrix();
1415
006ced515057 simplified more
Teemu Piippo <teemu@hecknology.net>
parents: 1414
diff changeset
195 matrix.rotate(angle, 0, 1, 0);
1413
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
196 primitive->setTransformationMatrix(matrix);
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
197 }
6b0ca41c158f added buttons to rotate circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1412
diff changeset
198 }

mercurial