src/addObjectDialog.cpp

changeset 538
2f85d4d286e5
parent 526
b29b6fc45ba9
child 539
72ad83a67165
equal deleted inserted replaced
537:1add0ee96fb3 538:2f85d4d286e5
51 // ============================================================================= 51 // =============================================================================
52 // ----------------------------------------------------------------------------- 52 // -----------------------------------------------------------------------------
53 AddObjectDialog::AddObjectDialog (const LDObject::Type type, LDObject* obj, QWidget* parent) : QDialog (parent) 53 AddObjectDialog::AddObjectDialog (const LDObject::Type type, LDObject* obj, QWidget* parent) : QDialog (parent)
54 { setlocale (LC_ALL, "C"); 54 { setlocale (LC_ALL, "C");
55 55
56 short coordCount = 0; 56 int coordCount = 0;
57 str typeName = LDObject::typeName (type); 57 str typeName = LDObject::typeName (type);
58 58
59 switch (type) 59 switch (type)
60 { case LDObject::Comment: 60 { case LDObject::Comment:
61 le_comment = new QLineEdit; 61 le_comment = new QLineEdit;
102 case LDObject::Subfile: 102 case LDObject::Subfile:
103 coordCount = 3; 103 coordCount = 3;
104 104
105 // If the primitive lister is busy writing data, we have to wait 105 // If the primitive lister is busy writing data, we have to wait
106 // for that to happen first. This should be quite considerably rare. 106 // for that to happen first. This should be quite considerably rare.
107 while (primitiveLoaderBusy()) 107 while (isPrimitiveLoaderBusy())
108 ; 108 ;
109 109
110 tw_subfileList = new QTreeWidget(); 110 tw_subfileList = new QTreeWidget();
111 tw_subfileList->setHeaderLabel (tr ("Primitives")); 111 tw_subfileList->setHeaderLabel (tr ("Primitives"));
112 112
162 pb_color = new QPushButton; 162 pb_color = new QPushButton;
163 setButtonBackground (pb_color, colnum); 163 setButtonBackground (pb_color, colnum);
164 connect (pb_color, SIGNAL (clicked()), this, SLOT (slot_colorButtonClicked())); 164 connect (pb_color, SIGNAL (clicked()), this, SLOT (slot_colorButtonClicked()));
165 } 165 }
166 166
167 for (short i = 0; i < coordCount; ++i) 167 for (int i = 0; i < coordCount; ++i)
168 { dsb_coords[i] = new QDoubleSpinBox; 168 { dsb_coords[i] = new QDoubleSpinBox;
169 dsb_coords[i]->setDecimals (5); 169 dsb_coords[i]->setDecimals (5);
170 dsb_coords[i]->setMinimum (-10000.0); 170 dsb_coords[i]->setMinimum (-10000.0);
171 dsb_coords[i]->setMaximum (10000.0); 171 dsb_coords[i]->setMaximum (10000.0);
172 } 172 }
180 case LDObject::Triangle: 180 case LDObject::Triangle:
181 case LDObject::Quad: 181 case LDObject::Quad:
182 182
183 // Apply coordinates 183 // Apply coordinates
184 if (obj) 184 if (obj)
185 { for (short i = 0; i < coordCount / 3; ++i) 185 { for (int i = 0; i < coordCount / 3; ++i)
186 for (short j = 0; j < 3; ++j) 186 for (int j = 0; j < 3; ++j)
187 dsb_coords[ (i * 3) + j]->setValue (obj->getVertex (i).coord (j)); 187 dsb_coords[ (i * 3) + j]->setValue (obj->getVertex (i).coord (j));
188 } 188 }
189 189
190 break; 190 break;
191 191
231 layout->addWidget (pb_color, 1, 0); 231 layout->addWidget (pb_color, 1, 0);
232 232
233 if (coordCount > 0) 233 if (coordCount > 0)
234 { QGridLayout* const qCoordLayout = new QGridLayout; 234 { QGridLayout* const qCoordLayout = new QGridLayout;
235 235
236 for (short i = 0; i < coordCount; ++i) 236 for (int i = 0; i < coordCount; ++i)
237 qCoordLayout->addWidget (dsb_coords[i], (i / 3), (i % 3)); 237 qCoordLayout->addWidget (dsb_coords[i], (i / 3), (i % 3));
238 238
239 layout->addLayout (qCoordLayout, 0, 1, (coordCount / 3), 3); 239 layout->addLayout (qCoordLayout, 0, 1, (coordCount / 3), 3);
240 } 240 }
241 241
250 delete defaults; 250 delete defaults;
251 } 251 }
252 252
253 // ============================================================================= 253 // =============================================================================
254 // ----------------------------------------------------------------------------- 254 // -----------------------------------------------------------------------------
255 void AddObjectDialog::setButtonBackground (QPushButton* button, short colnum) 255 void AddObjectDialog::setButtonBackground (QPushButton* button, int colnum)
256 { LDColor* col = getColor (colnum); 256 { LDColor* col = getColor (colnum);
257 257
258 button->setIcon (getIcon ("palette")); 258 button->setIcon (getIcon ("palette"));
259 button->setAutoFillBackground (true); 259 button->setAutoFillBackground (true);
260 260
274 } 274 }
275 275
276 // ============================================================================= 276 // =============================================================================
277 // ----------------------------------------------------------------------------- 277 // -----------------------------------------------------------------------------
278 void AddObjectDialog::slot_colorButtonClicked() 278 void AddObjectDialog::slot_colorButtonClicked()
279 { ColorSelector::getColor (colnum, colnum, this); 279 { ColorSelector::selectColor (colnum, colnum, this);
280 setButtonBackground (pb_color, colnum); 280 setButtonBackground (pb_color, colnum);
281 } 281 }
282 282
283 // ============================================================================= 283 // =============================================================================
284 // ----------------------------------------------------------------------------- 284 // -----------------------------------------------------------------------------
346 case LDObject::CndLine: 346 case LDObject::CndLine:
347 347
348 if (!obj) 348 if (!obj)
349 obj = LDObject::getDefault (type); 349 obj = LDObject::getDefault (type);
350 350
351 for (short i = 0; i < obj->vertices(); ++i) 351 for (int i = 0; i < obj->vertices(); ++i)
352 { vertex v; 352 { vertex v;
353 353
354 for (const Axis ax : g_Axes) 354 for (const Axis ax : g_Axes)
355 v[ax] = dlg.dsb_coords[ (i * 3) + ax]->value(); 355 v[ax] = dlg.dsb_coords[ (i * 3) + ax]->value();
356 356
357 obj->setVertex (i, v); 357 obj->setVertex (i, v);
358 } 358 }
359 359
406 if (newObject) 406 if (newObject)
407 { int idx = g_win->getInsertionPoint(); 407 { int idx = g_win->getInsertionPoint();
408 LDFile::current()->insertObj (idx, obj); 408 LDFile::current()->insertObj (idx, obj);
409 } 409 }
410 410
411 g_win->fullRefresh(); 411 g_win->doFullRefresh();
412 } 412 }

mercurial