Sun, 17 Jun 2018 16:13:24 +0300
Circular primitive editor complete
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), |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
43 | #undef MAP_RADIO_BUTTON |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
44 | }; |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
45 | |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
46 | /* |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
47 | * Constructs a new circular primitive editor and sets up connections. |
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 | 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
|
50 | QDialog {parent}, |
1406
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
51 | ui {*new Ui_CircularPrimitiveEditor}, |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
52 | primitive {primitive} |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
53 | { |
1395
23551de3da36
separated the color button into a new widget
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
54 | ui.setupUi(this); |
1406
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
55 | |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
56 | // Set the initial values of the dialog |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
57 | updateWidgets(); |
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 | if (primitive) |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
60 | { |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
61 | // 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
|
62 | // from this archive. |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
63 | Serializer serializer {originalState, Serializer::Store}; |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
64 | primitive->serialize(serializer); |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
65 | } |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
66 | |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
67 | for (const auto& mapping : ::radioButtonMap) |
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 | QRadioButton* button = mapping.resolve(ui); |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
70 | |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
71 | // 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
|
72 | connect( |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
73 | button, |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
74 | &QRadioButton::toggled, |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
75 | [&](bool checked) |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
76 | { |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
77 | if (checked and this->primitive) |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
78 | this->primitive->setPrimitiveType(mapping.primitiveType); |
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 | ); |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
81 | } |
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 | // 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
|
84 | connect( |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
85 | ui.segments, |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
86 | qOverload<int>(&QSpinBox::valueChanged), |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
87 | [&](int newSegments) |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
88 | { |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
89 | if (this->primitive) |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
90 | this->primitive->setSegments(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 | ); |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
93 | connect( |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
94 | ui.divisions, |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
95 | &QComboBox::currentTextChanged, |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
96 | [&](const QString& newDivisions) |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
97 | { |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
98 | if (this->primitive) |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
99 | this->primitive->setDivisions(newDivisions.toInt()); |
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 | ); |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
102 | connect( |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
103 | ui.color, |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
104 | &ColorButton::colorChanged, |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
105 | [&](LDColor newColor) |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
106 | { |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
107 | if (this->primitive) |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
108 | this->primitive->setColor(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 | ); |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
111 | connect( |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
112 | ui.matrix, |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
113 | &MatrixEditor::matrixChanged, |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
114 | [&](const QMatrix4x4& newMatrix) |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
115 | { |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
116 | if (this->primitive) |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
117 | this->primitive->setTransformationMatrix(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 | ); |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
120 | // 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
|
121 | connect( |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
122 | ui.buttonBox, |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
123 | &QDialogButtonBox::clicked, |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
124 | [&](QAbstractButton* button) |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
125 | { |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
126 | if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::ResetRole) |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
127 | reset(); |
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 | ); |
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 | if (this->primitive) |
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 | // 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
|
134 | connect(this->primitive, &LDObject::modified, this, &CircularPrimitiveEditor::updateWidgets); |
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 object is deleted, then destroy the dialog. |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
137 | connect(this->primitive, &LDObject::destroyed, this, &QDialog::reject); |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
138 | } |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
139 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
140 | |
1406
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
141 | /* |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
142 | * Frees the user interface memory after the dialog is destroyed. |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
143 | */ |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
144 | CircularPrimitiveEditor::~CircularPrimitiveEditor() |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
145 | { |
1395
23551de3da36
separated the color button into a new widget
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
146 | delete &ui; |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
147 | } |
1406
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
148 | |
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 | * 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
|
151 | */ |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
152 | void CircularPrimitiveEditor::updateWidgets() |
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 | setEnabled(primitive != nullptr); |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
155 | |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
156 | if (primitive) |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
157 | { |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
158 | for (const auto& mapping : ::radioButtonMap) |
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 | // Choose the correct radio button |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
161 | QRadioButton* button = mapping.resolve(ui); |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
162 | withSignalsBlocked(button, [&]() |
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 | button->setChecked(primitive->primitiveType() == mapping.primitiveType); |
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 | } |
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 | // Set the values of the form. |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
169 | withSignalsBlocked(ui.segments, [&](){ ui.segments->setValue(primitive->segments()); }); |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
170 | withSignalsBlocked(ui.divisions, [&]() |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
171 | { |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
172 | ui.divisions->setCurrentText(QString::number(primitive->divisions())); |
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 | withSignalsBlocked(ui.color, [&](){ ui.color->setColor(primitive->color()); }); |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
175 | withSignalsBlocked(ui.matrix, [&](){ ui.matrix->setMatrix(primitive->transformationMatrix()); }); |
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 | |
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 | * 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
|
181 | */ |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
182 | void CircularPrimitiveEditor::reset() |
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 | if (primitive) |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
185 | primitive->restore(originalState); // Restoring does not change 'originalState' |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1395
diff
changeset
|
186 | } |