34 #include "Widgets.h" |
34 #include "Widgets.h" |
35 #include "Misc.h" |
35 #include "Misc.h" |
36 #include "Primitives.h" |
36 #include "Primitives.h" |
37 |
37 |
38 // ============================================================================= |
38 // ============================================================================= |
39 // ----------------------------------------------------------------------------- |
39 // |
40 class SubfileListItem : public QTreeWidgetItem |
40 class SubfileListItem : public QTreeWidgetItem |
41 { |
41 { |
42 PROPERTY (public, Primitive*, PrimitiveInfo, NO_OPS, STOCK_WRITE) |
42 PROPERTY (public, Primitive*, primitive, setPrimitive, STOCK_WRITE) |
43 |
43 |
44 public: |
44 public: |
45 SubfileListItem (QTreeWidgetItem* parent, Primitive* info) : |
45 SubfileListItem (QTreeWidgetItem* parent, Primitive* info) : |
46 QTreeWidgetItem (parent), |
46 QTreeWidgetItem (parent), |
47 m_PrimitiveInfo (info) {} |
47 m_primitive (info) {} |
48 |
48 |
49 SubfileListItem (QTreeWidget* parent, Primitive* info) : |
49 SubfileListItem (QTreeWidget* parent, Primitive* info) : |
50 QTreeWidgetItem (parent), |
50 QTreeWidgetItem (parent), |
51 m_PrimitiveInfo (info) {} |
51 m_primitive (info) {} |
52 }; |
52 }; |
53 |
53 |
54 // ============================================================================= |
54 // ============================================================================= |
55 // ----------------------------------------------------------------------------- |
55 // |
56 AddObjectDialog::AddObjectDialog (const LDObject::Type type, LDObject* obj, QWidget* parent) : |
56 AddObjectDialog::AddObjectDialog (const LDObject::Type type, LDObject* obj, QWidget* parent) : |
57 QDialog (parent) |
57 QDialog (parent) |
58 { |
58 { |
59 setlocale (LC_ALL, "C"); |
59 setlocale (LC_ALL, "C"); |
60 |
60 |
118 tw_subfileList->setHeaderLabel (tr ("Primitives")); |
118 tw_subfileList->setHeaderLabel (tr ("Primitives")); |
119 |
119 |
120 for (PrimitiveCategory* cat : g_PrimitiveCategories) |
120 for (PrimitiveCategory* cat : g_PrimitiveCategories) |
121 { |
121 { |
122 SubfileListItem* parentItem = new SubfileListItem (tw_subfileList, null); |
122 SubfileListItem* parentItem = new SubfileListItem (tw_subfileList, null); |
123 parentItem->setText (0, cat->getName()); |
123 parentItem->setText (0, cat->name()); |
124 QList<QTreeWidgetItem*> subfileItems; |
124 QList<QTreeWidgetItem*> subfileItems; |
125 |
125 |
126 for (Primitive& prim : cat->prims) |
126 for (Primitive& prim : cat->prims) |
127 { |
127 { |
128 SubfileListItem* item = new SubfileListItem (parentItem, &prim); |
128 SubfileListItem* item = new SubfileListItem (parentItem, &prim); |
129 item->setText (0, fmt ("%1 - %2", prim.name, prim.title)); |
129 item->setText (0, format ("%1 - %2", prim.name, prim.title)); |
130 subfileItems << item; |
130 subfileItems << item; |
131 |
131 |
132 // If this primitive is the one the current object points to, |
132 // If this primitive is the one the current object points to, |
133 // select it by default |
133 // select it by default |
134 if (obj && static_cast<LDSubfile*> (obj)->getFileInfo()->getName() == prim.name) |
134 if (obj && static_cast<LDSubfile*> (obj)->fileInfo()->name() == prim.name) |
135 tw_subfileList->setCurrentItem (item); |
135 tw_subfileList->setCurrentItem (item); |
136 } |
136 } |
137 |
137 |
138 tw_subfileList->addTopLevelItem (parentItem); |
138 tw_subfileList->addTopLevelItem (parentItem); |
139 } |
139 } |
144 le_subfileName->setFocus(); |
144 le_subfileName->setFocus(); |
145 |
145 |
146 if (obj) |
146 if (obj) |
147 { |
147 { |
148 LDSubfile* ref = static_cast<LDSubfile*> (obj); |
148 LDSubfile* ref = static_cast<LDSubfile*> (obj); |
149 le_subfileName->setText (ref->getFileInfo()->getName()); |
149 le_subfileName->setText (ref->fileInfo()->name()); |
150 } |
150 } |
151 } break; |
151 } break; |
152 |
152 |
153 default: |
153 default: |
154 { |
154 { |
155 critical (fmt ("Unhandled LDObject type %1 (%2) in AddObjectDialog", (int) type, typeName)); |
155 critical (format ("Unhandled LDObject type %1 (%2) in AddObjectDialog", (int) type, typeName)); |
156 } return; |
156 } return; |
157 } |
157 } |
158 |
158 |
159 QPixmap icon = getIcon (fmt ("add-%1", typeName)); |
159 QPixmap icon = getIcon (format ("add-%1", typeName)); |
160 LDObject* defaults = LDObject::getDefault (type); |
160 LDObject* defaults = LDObject::getDefault (type); |
161 |
161 |
162 lb_typeIcon = new QLabel; |
162 lb_typeIcon = new QLabel; |
163 lb_typeIcon->setPixmap (icon); |
163 lb_typeIcon->setPixmap (icon); |
164 |
164 |
165 // Show a color edit dialog for the types that actually use the color |
165 // Show a color edit dialog for the types that actually use the color |
166 if (defaults->isColored()) |
166 if (defaults->isColored()) |
167 { |
167 { |
168 if (obj != null) |
168 if (obj != null) |
169 colnum = obj->getColor(); |
169 colnum = obj->color(); |
170 else |
170 else |
171 colnum = (type == LDObject::ECondLine || type == LDObject::ELine) ? edgecolor : maincolor; |
171 colnum = (type == LDObject::ECondLine || type == LDObject::ELine) ? edgecolor : maincolor; |
172 |
172 |
173 pb_color = new QPushButton; |
173 pb_color = new QPushButton; |
174 setButtonBackground (pb_color, colnum); |
174 setButtonBackground (pb_color, colnum); |
259 QDialogButtonBox* bbx_buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel); |
259 QDialogButtonBox* bbx_buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel); |
260 QWidget::connect (bbx_buttons, SIGNAL (accepted()), this, SLOT (accept())); |
260 QWidget::connect (bbx_buttons, SIGNAL (accepted()), this, SLOT (accept())); |
261 QWidget::connect (bbx_buttons, SIGNAL (rejected()), this, SLOT (reject())); |
261 QWidget::connect (bbx_buttons, SIGNAL (rejected()), this, SLOT (reject())); |
262 layout->addWidget (bbx_buttons, 5, 0, 1, 4); |
262 layout->addWidget (bbx_buttons, 5, 0, 1, 4); |
263 setLayout (layout); |
263 setLayout (layout); |
264 setWindowTitle (fmt (tr ("Edit %1"), typeName)); |
264 setWindowTitle (format (tr ("Edit %1"), typeName)); |
265 |
265 |
266 setWindowIcon (icon); |
266 setWindowIcon (icon); |
267 defaults->deleteSelf(); |
267 defaults->destroy(); |
268 } |
268 } |
269 |
269 |
270 // ============================================================================= |
270 // ============================================================================= |
271 // ----------------------------------------------------------------------------- |
271 // ============================================================================= |
272 void AddObjectDialog::setButtonBackground (QPushButton* button, int colnum) |
272 void AddObjectDialog::setButtonBackground (QPushButton* button, int colnum) |
273 { |
273 { |
274 LDColor* col = getColor (colnum); |
274 LDColor* col = ::getColor (colnum); |
275 |
275 |
276 button->setIcon (getIcon ("palette")); |
276 button->setIcon (getIcon ("palette")); |
277 button->setAutoFillBackground (true); |
277 button->setAutoFillBackground (true); |
278 |
278 |
279 if (col) |
279 if (col) |
280 button->setStyleSheet (fmt ("background-color: %1", col->hexcode)); |
280 button->setStyleSheet (format ("background-color: %1", col->hexcode)); |
281 } |
281 } |
282 |
282 |
283 // ============================================================================= |
283 // ============================================================================= |
284 // ----------------------------------------------------------------------------- |
284 // ============================================================================= |
285 QString AddObjectDialog::currentSubfileName() |
285 QString AddObjectDialog::currentSubfileName() |
286 { |
286 { |
287 SubfileListItem* item = static_cast<SubfileListItem*> (tw_subfileList->currentItem()); |
287 SubfileListItem* item = static_cast<SubfileListItem*> (tw_subfileList->currentItem()); |
288 |
288 |
289 if (item->getPrimitiveInfo() == null) |
289 if (item->primitive() == null) |
290 return ""; // selected a heading |
290 return ""; // selected a heading |
291 |
291 |
292 return item->getPrimitiveInfo()->name; |
292 return item->primitive()->name; |
293 } |
293 } |
294 |
294 |
295 // ============================================================================= |
295 // ============================================================================= |
296 // ----------------------------------------------------------------------------- |
296 // ============================================================================= |
297 void AddObjectDialog::slot_colorButtonClicked() |
297 void AddObjectDialog::slot_colorButtonClicked() |
298 { |
298 { |
299 ColorSelector::selectColor (colnum, colnum, this); |
299 ColorSelector::selectColor (colnum, colnum, this); |
300 setButtonBackground (pb_color, colnum); |
300 setButtonBackground (pb_color, colnum); |
301 } |
301 } |
302 |
302 |
303 // ============================================================================= |
303 // ============================================================================= |
304 // ----------------------------------------------------------------------------- |
304 // ============================================================================= |
305 void AddObjectDialog::slot_subfileTypeChanged() |
305 void AddObjectDialog::slot_subfileTypeChanged() |
306 { |
306 { |
307 QString name = currentSubfileName(); |
307 QString name = currentSubfileName(); |
308 |
308 |
309 if (name.length() > 0) |
309 if (name.length() > 0) |
310 le_subfileName->setText (name); |
310 le_subfileName->setText (name); |
311 } |
311 } |
312 |
312 |
313 // ============================================================================= |
313 // ============================================================================= |
314 // ----------------------------------------------------------------------------- |
314 // ============================================================================= |
315 template<class T> static T* initObj (LDObject*& obj) |
315 template<class T> static T* initObj (LDObject*& obj) |
316 { |
316 { |
317 if (obj == null) |
317 if (obj == null) |
318 obj = new T; |
318 obj = new T; |
319 |
319 |
320 return static_cast<T*> (obj); |
320 return static_cast<T*> (obj); |
321 } |
321 } |
322 |
322 |
323 // ============================================================================= |
323 // ============================================================================= |
324 // ----------------------------------------------------------------------------- |
324 // ============================================================================= |
325 void AddObjectDialog::staticDialog (const LDObject::Type type, LDObject* obj) |
325 void AddObjectDialog::staticDialog (const LDObject::Type type, LDObject* obj) |
326 { |
326 { |
327 setlocale (LC_ALL, "C"); |
327 setlocale (LC_ALL, "C"); |
328 |
328 |
329 // FIXME: Redirect to Edit Raw |
329 // FIXME: Redirect to Edit Raw |
330 if (obj && obj->getType() == LDObject::EError) |
330 if (obj && obj->type() == LDObject::EError) |
331 return; |
331 return; |
332 |
332 |
333 if (type == LDObject::EEmpty) |
333 if (type == LDObject::EEmpty) |
334 return; // Nothing to edit with empties |
334 return; // Nothing to edit with empties |
335 |
335 |
336 const bool newObject = (obj == null); |
336 const bool newObject = (obj == null); |
337 Matrix transform = g_identity; |
337 Matrix transform = g_identity; |
338 AddObjectDialog dlg (type, obj); |
338 AddObjectDialog dlg (type, obj); |
339 |
339 |
340 assert (!obj || obj->getType() == type); |
340 assert (obj == null || obj->type() == type); |
341 |
341 |
342 if (dlg.exec() == false) |
342 if (dlg.exec() == false) |
343 return; |
343 return; |
344 |
344 |
345 if (type == LDObject::ESubfile) |
345 if (type == LDObject::ESubfile) |