src/addObjectDialog.cc

changeset 861
83426c5fa732
parent 847
274a7fac44fc
child 864
34033bc2ffb6
equal deleted inserted replaced
860:a496e72af069 861:83426c5fa732
98 case OBJ_Subfile: 98 case OBJ_Subfile:
99 { 99 {
100 coordCount = 3; 100 coordCount = 3;
101 tw_subfileList = new QTreeWidget(); 101 tw_subfileList = new QTreeWidget();
102 tw_subfileList->setHeaderLabel (tr ("Primitives")); 102 tw_subfileList->setHeaderLabel (tr ("Primitives"));
103 populatePrimitives (tw_subfileList, (obj != null ? obj.staticCast<LDSubfile>()->fileInfo()->name() : "")); 103 PopulatePrimitives (tw_subfileList, (obj != null ? obj.staticCast<LDSubfile>()->fileInfo()->name() : ""));
104 104
105 connect (tw_subfileList, SIGNAL (itemSelectionChanged()), this, SLOT (slot_subfileTypeChanged())); 105 connect (tw_subfileList, SIGNAL (itemSelectionChanged()), this, SLOT (slot_subfileTypeChanged()));
106 lb_subfileName = new QLabel ("File:"); 106 lb_subfileName = new QLabel ("File:");
107 le_subfileName = new QLineEdit; 107 le_subfileName = new QLineEdit;
108 le_subfileName->setFocus(); 108 le_subfileName->setFocus();
114 } 114 }
115 } break; 115 } break;
116 116
117 default: 117 default:
118 { 118 {
119 critical (format ("Unhandled LDObject type %1 (%2) in AddObjectDialog", (int) type, typeName)); 119 CriticalError (format ("Unhandled LDObject type %1 (%2) in AddObjectDialog", (int) type, typeName));
120 } return; 120 } return;
121 } 121 }
122 122
123 QPixmap icon = getIcon (format ("add-%1", typeName)); 123 QPixmap icon = GetIcon (format ("add-%1", typeName));
124 LDObjectPtr defaults = LDObject::getDefault (type); 124 LDObjectPtr defaults = LDObject::getDefault (type);
125 125
126 lb_typeIcon = new QLabel; 126 lb_typeIcon = new QLabel;
127 lb_typeIcon->setPixmap (icon); 127 lb_typeIcon->setPixmap (icon);
128 128
129 // Show a color edit dialog for the types that actually use the color 129 // Show a color edit dialog for the types that actually use the color
130 if (defaults->isColored()) 130 if (defaults->isColored())
131 { 131 {
132 if (obj != null) 132 if (obj != null)
133 _color = obj->color(); 133 m_color = obj->color();
134 else 134 else
135 _color = (type == OBJ_CondLine or type == OBJ_Line) ? edgecolor() : maincolor(); 135 m_color = (type == OBJ_CondLine or type == OBJ_Line) ? EdgeColor() : MainColor();
136 136
137 pb_color = new QPushButton; 137 pb_color = new QPushButton;
138 setButtonBackground (pb_color, _color); 138 setButtonBackground (pb_color, m_color);
139 connect (pb_color, SIGNAL (clicked()), this, SLOT (slot_colorButtonClicked())); 139 connect (pb_color, SIGNAL (clicked()), this, SLOT (slot_colorButtonClicked()));
140 } 140 }
141 141
142 for (int i = 0; i < coordCount; ++i) 142 for (int i = 0; i < coordCount; ++i)
143 { 143 {
191 { 191 {
192 LDMatrixObjectPtr mo = obj.dynamicCast<LDMatrixObject>(); 192 LDMatrixObjectPtr mo = obj.dynamicCast<LDMatrixObject>();
193 QLabel* lb_matrix = new QLabel ("Matrix:"); 193 QLabel* lb_matrix = new QLabel ("Matrix:");
194 le_matrix = new QLineEdit; 194 le_matrix = new QLineEdit;
195 // le_matrix->setValidator (new QDoubleValidator); 195 // le_matrix->setValidator (new QDoubleValidator);
196 Matrix defaultMatrix = g_identity; 196 Matrix defaultMatrix = IdentityMatrix;
197 197
198 if (mo != null) 198 if (mo != null)
199 { 199 {
200 mo->position().apply ([&](Axis ax, double value) 200 mo->position().apply ([&](Axis ax, double value)
201 { 201 {
234 234
235 // ============================================================================= 235 // =============================================================================
236 // ============================================================================= 236 // =============================================================================
237 void AddObjectDialog::setButtonBackground (QPushButton* button, LDColor color) 237 void AddObjectDialog::setButtonBackground (QPushButton* button, LDColor color)
238 { 238 {
239 button->setIcon (getIcon ("palette")); 239 button->setIcon (GetIcon ("palette"));
240 button->setAutoFillBackground (true); 240 button->setAutoFillBackground (true);
241 241
242 if (color != null) 242 if (color != null)
243 button->setStyleSheet (format ("background-color: %1", color.hexcode())); 243 button->setStyleSheet (format ("background-color: %1", color.hexcode()));
244 } 244 }
257 257
258 // ============================================================================= 258 // =============================================================================
259 // ============================================================================= 259 // =============================================================================
260 void AddObjectDialog::slot_colorButtonClicked() 260 void AddObjectDialog::slot_colorButtonClicked()
261 { 261 {
262 ColorSelector::selectColor (_color, _color, this); 262 ColorSelector::selectColor (m_color, m_color, this);
263 setButtonBackground (pb_color, _color); 263 setButtonBackground (pb_color, m_color);
264 } 264 }
265 265
266 // ============================================================================= 266 // =============================================================================
267 // ============================================================================= 267 // =============================================================================
268 void AddObjectDialog::slot_subfileTypeChanged() 268 void AddObjectDialog::slot_subfileTypeChanged()
274 } 274 }
275 275
276 // ============================================================================= 276 // =============================================================================
277 // ============================================================================= 277 // =============================================================================
278 template<typename T> 278 template<typename T>
279 static QSharedPointer<T> initObj (LDObjectPtr& obj) 279 static QSharedPointer<T> InitObject (LDObjectPtr& obj)
280 { 280 {
281 if (obj == null) 281 if (obj == null)
282 obj = spawn<T>(); 282 obj = LDSpawn<T>();
283 283
284 return obj.staticCast<T>(); 284 return obj.staticCast<T>();
285 } 285 }
286 286
287 // ============================================================================= 287 // =============================================================================
296 296
297 if (type == OBJ_Empty) 297 if (type == OBJ_Empty)
298 return; // Nothing to edit with empties 298 return; // Nothing to edit with empties
299 299
300 const bool newObject = (obj == null); 300 const bool newObject = (obj == null);
301 Matrix transform = g_identity; 301 Matrix transform = IdentityMatrix;
302 AddObjectDialog dlg (type, obj); 302 AddObjectDialog dlg (type, obj);
303 303
304 assert (obj == null or obj->type() == type); 304 assert (obj == null or obj->type() == type);
305 305
306 if (dlg.exec() == QDialog::Rejected) 306 if (dlg.exec() == QDialog::Rejected)
324 324
325 switch (type) 325 switch (type)
326 { 326 {
327 case OBJ_Comment: 327 case OBJ_Comment:
328 { 328 {
329 LDCommentPtr comm = initObj<LDComment> (obj); 329 LDCommentPtr comm = InitObject<LDComment> (obj);
330 comm->setText (dlg.le_comment->text()); 330 comm->setText (dlg.le_comment->text());
331 } 331 }
332 break; 332 break;
333 333
334 case OBJ_Line: 334 case OBJ_Line:
352 } 352 }
353 } break; 353 } break;
354 354
355 case OBJ_BFC: 355 case OBJ_BFC:
356 { 356 {
357 LDBFCPtr bfc = initObj<LDBFC> (obj); 357 LDBFCPtr bfc = InitObject<LDBFC> (obj);
358 assert (within (dlg.rb_bfcType->value(), 0, int (BFCStatement::NumValues) - 1)); 358 assert (within (dlg.rb_bfcType->value(), 0, int (BFCStatement::NumValues) - 1));
359 bfc->setStatement (BFCStatement (dlg.rb_bfcType->value())); 359 bfc->setStatement (BFCStatement (dlg.rb_bfcType->value()));
360 } break; 360 } break;
361 361
362 case OBJ_Vertex: 362 case OBJ_Vertex:
363 { 363 {
364 LDVertexPtr vert = initObj<LDVertex> (obj); 364 LDVertexPtr vert = InitObject<LDVertex> (obj);
365 vert->pos.apply ([&](Axis ax, double& value) { value = dlg.dsb_coords[ax]->value(); }); 365 vert->pos.apply ([&](Axis ax, double& value) { value = dlg.dsb_coords[ax]->value(); });
366 } 366 }
367 break; 367 break;
368 368
369 case OBJ_Subfile: 369 case OBJ_Subfile:
371 QString name = dlg.le_subfileName->text(); 371 QString name = dlg.le_subfileName->text();
372 372
373 if (name.length() == 0) 373 if (name.length() == 0)
374 return; // no subfile filename 374 return; // no subfile filename
375 375
376 LDDocumentPtr file = getDocument (name); 376 LDDocumentPtr file = GetDocument (name);
377 377
378 if (not file) 378 if (not file)
379 { 379 {
380 critical (format ("Couldn't open `%1': %2", name, strerror (errno))); 380 CriticalError (format ("Couldn't open `%1': %2", name, strerror (errno)));
381 return; 381 return;
382 } 382 }
383 383
384 LDSubfilePtr ref = initObj<LDSubfile> (obj); 384 LDSubfilePtr ref = InitObject<LDSubfile> (obj);
385 assert (ref); 385 assert (ref);
386 386
387 for_axes (ax) 387 for_axes (ax)
388 ref->setCoordinate (ax, dlg.dsb_coords[ax]->value()); 388 ref->setCoordinate (ax, dlg.dsb_coords[ax]->value());
389 389
394 default: 394 default:
395 break; 395 break;
396 } 396 }
397 397
398 if (obj->isColored()) 398 if (obj->isColored())
399 obj->setColor (dlg._color); 399 obj->setColor (dlg.m_color);
400 400
401 if (newObject) 401 if (newObject)
402 { 402 {
403 int idx = g_win->getInsertionPoint(); 403 int idx = g_win->getInsertionPoint();
404 getCurrentDocument()->insertObj (idx, obj); 404 CurrentDocument()->insertObj (idx, obj);
405 } 405 }
406 406
407 g_win->refresh(); 407 g_win->refresh();
408 } 408 }

mercurial