src/AddObjectDialog.cc

changeset 690
9e9c52ca955e
parent 644
93dcd1a0e4bd
equal deleted inserted replaced
689:397870c6ed38 690:9e9c52ca955e
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
66 case LDObject::EComment: 66 case LDObject::EComment:
67 { 67 {
68 le_comment = new QLineEdit; 68 le_comment = new QLineEdit;
69 69
70 if (obj) 70 if (obj)
71 le_comment->setText (static_cast<LDComment*> (obj)->text); 71 le_comment->setText (static_cast<LDComment*> (obj)->text());
72 72
73 le_comment->setMinimumWidth (384); 73 le_comment->setMinimumWidth (384);
74 } break; 74 } break;
75 75
76 case LDObject::ELine: 76 case LDObject::ELine:
102 { 102 {
103 // Separate these in two columns 103 // Separate these in two columns
104 if (i == LDBFC::NumStatements / 2) 104 if (i == LDBFC::NumStatements / 2)
105 rb_bfcType->rowBreak(); 105 rb_bfcType->rowBreak();
106 106
107 rb_bfcType->addButton (LDBFC::statements[i]); 107 rb_bfcType->addButton (LDBFC::k_statementStrings[i]);
108 } 108 }
109 109
110 if (obj) 110 if (obj)
111 rb_bfcType->setValue ( (int) static_cast<LDBFC*> (obj)->type); 111 rb_bfcType->setValue ( (int) static_cast<LDBFC*> (obj)->statement());
112 } break; 112 } break;
113 113
114 case LDObject::ESubfile: 114 case LDObject::ESubfile:
115 { 115 {
116 coordCount = 3; 116 coordCount = 3;
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);
196 // Apply coordinates 196 // Apply coordinates
197 if (obj) 197 if (obj)
198 { 198 {
199 for (int i = 0; i < coordCount / 3; ++i) 199 for (int i = 0; i < coordCount / 3; ++i)
200 for (int j = 0; j < 3; ++j) 200 for (int j = 0; j < 3; ++j)
201 dsb_coords[ (i * 3) + j]->setValue (obj->getVertex (i).getCoordinate (j)); 201 dsb_coords[ (i * 3) + j]->setValue (obj->vertex (i).getCoordinate (j));
202 } 202 }
203 203
204 break; 204 break;
205 205
206 case LDObject::EComment: 206 case LDObject::EComment:
231 Matrix defaultMatrix = g_identity; 231 Matrix defaultMatrix = g_identity;
232 232
233 if (mo) 233 if (mo)
234 { 234 {
235 for_axes (ax) 235 for_axes (ax)
236 dsb_coords[ax]->setValue (mo->getPosition()[ax]); 236 dsb_coords[ax]->setValue (mo->position()[ax]);
237 237
238 defaultMatrix = mo->getTransform(); 238 defaultMatrix = mo->transform();
239 } 239 }
240 240
241 le_matrix->setText (defaultMatrix.toString()); 241 le_matrix->setText (defaultMatrix.toString());
242 layout->addWidget (lb_matrix, 4, 1); 242 layout->addWidget (lb_matrix, 4, 1);
243 layout->addWidget (le_matrix, 4, 2, 1, 3); 243 layout->addWidget (le_matrix, 4, 2, 1, 3);
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)
361 switch (type) 361 switch (type)
362 { 362 {
363 case LDObject::EComment: 363 case LDObject::EComment:
364 { 364 {
365 LDComment* comm = initObj<LDComment> (obj); 365 LDComment* comm = initObj<LDComment> (obj);
366 comm->text = dlg.le_comment->text(); 366 comm->setText (dlg.le_comment->text());
367 } 367 }
368 break; 368 break;
369 369
370 case LDObject::ELine: 370 case LDObject::ELine:
371 case LDObject::ETriangle: 371 case LDObject::ETriangle:
387 } break; 387 } break;
388 388
389 case LDObject::EBFC: 389 case LDObject::EBFC:
390 { 390 {
391 LDBFC* bfc = initObj<LDBFC> (obj); 391 LDBFC* bfc = initObj<LDBFC> (obj);
392 bfc->type = (LDBFC::Type) dlg.rb_bfcType->value(); 392 bfc->setStatement ((LDBFC::Statement) dlg.rb_bfcType->value());
393 } break; 393 } break;
394 394
395 case LDObject::EVertex: 395 case LDObject::EVertex:
396 { 396 {
397 LDVertex* vert = initObj<LDVertex> (obj); 397 LDVertex* vert = initObj<LDVertex> (obj);
410 410
411 LDDocument* file = getDocument (name); 411 LDDocument* file = getDocument (name);
412 412
413 if (!file) 413 if (!file)
414 { 414 {
415 critical (fmt ("Couldn't open `%1': %2", name, strerror (errno))); 415 critical (format ("Couldn't open `%1': %2", name, strerror (errno)));
416 return; 416 return;
417 } 417 }
418 418
419 LDSubfile* ref = initObj<LDSubfile> (obj); 419 LDSubfile* ref = initObj<LDSubfile> (obj);
420 assert (ref); 420 assert (ref);

mercurial