| 230 } |
233 } |
| 231 |
234 |
| 232 str SetContentsDialog::text () const { |
235 str SetContentsDialog::text () const { |
| 233 return le_contents->text (); |
236 return le_contents->text (); |
| 234 } |
237 } |
| |
238 |
| |
239 // ======================================================================================================================================== |
| |
240 LDrawPathDialog::LDrawPathDialog (const bool validDefault, QWidget* parent, Qt::WindowFlags f) |
| |
241 : QDialog (parent, f), m_validDefault (validDefault) |
| |
242 { |
| |
243 QLabel* lb_description = null; |
| |
244 lb_resolution = new QLabel ("---"); |
| |
245 |
| |
246 if (validDefault == false) |
| |
247 lb_description = new QLabel ("Please input your LDraw directory"); |
| |
248 |
| |
249 QLabel* lb_path = new QLabel ("LDraw path:"); |
| |
250 le_path = new QLineEdit; |
| |
251 btn_findPath = new QPushButton; |
| |
252 btn_findPath->setIcon (getIcon ("folder")); |
| |
253 |
| |
254 btn_tryConfigure = new QPushButton ("Configure"); |
| |
255 btn_tryConfigure->setIcon (getIcon ("settings")); |
| |
256 |
| |
257 btn_cancel = new QPushButton; |
| |
258 |
| |
259 if (validDefault == false) { |
| |
260 btn_cancel->setText ("Exit"); |
| |
261 btn_cancel->setIcon (getIcon ("exit")); |
| |
262 } else { |
| |
263 btn_cancel->setText ("Cancel"); |
| |
264 btn_cancel->setIcon (getIcon ("cancel")); |
| |
265 } |
| |
266 |
| |
267 dbb_buttons = new QDialogButtonBox (QDialogButtonBox::Ok); |
| |
268 dbb_buttons->addButton (btn_tryConfigure, QDialogButtonBox::ActionRole); |
| |
269 dbb_buttons->addButton (btn_cancel, QDialogButtonBox::RejectRole); |
| |
270 okButton ()->setEnabled (false); |
| |
271 |
| |
272 QHBoxLayout* inputLayout = new QHBoxLayout; |
| |
273 inputLayout->addWidget (lb_path); |
| |
274 inputLayout->addWidget (le_path); |
| |
275 inputLayout->addWidget (btn_findPath); |
| |
276 |
| |
277 QVBoxLayout* mainLayout = new QVBoxLayout; |
| |
278 |
| |
279 if (validDefault == false) |
| |
280 mainLayout->addWidget (lb_description); |
| |
281 |
| |
282 mainLayout->addLayout (inputLayout); |
| |
283 mainLayout->addWidget (lb_resolution); |
| |
284 mainLayout->addWidget (dbb_buttons); |
| |
285 setLayout (mainLayout); |
| |
286 |
| |
287 connect (le_path, SIGNAL (textEdited ()), this, SLOT (slot_tryConfigure ())); |
| |
288 connect (btn_findPath, SIGNAL (clicked ()), this, SLOT (slot_findPath ())); |
| |
289 connect (btn_tryConfigure, SIGNAL (clicked ()), this, SLOT (slot_tryConfigure ())); |
| |
290 connect (dbb_buttons, SIGNAL (accepted ()), this, SLOT (accept ())); |
| |
291 connect (dbb_buttons, SIGNAL (rejected ()), this, (validDefault) ? SLOT (reject ()) : SLOT (slot_exit ())); |
| |
292 |
| |
293 setPath (io_ldpath); |
| |
294 if (validDefault) |
| |
295 slot_tryConfigure (); |
| |
296 } |
| |
297 |
| |
298 // ======================================================================================================================================== |
| |
299 QPushButton* LDrawPathDialog::okButton () { |
| |
300 return dbb_buttons->button (QDialogButtonBox::Ok); |
| |
301 } |
| |
302 |
| |
303 // ======================================================================================================================================== |
| |
304 void LDrawPathDialog::setPath (str path) { |
| |
305 le_path->setText (path); |
| |
306 } |
| |
307 |
| |
308 // ======================================================================================================================================== |
| |
309 str LDrawPathDialog::path () const { |
| |
310 return le_path->text (); |
| |
311 } |
| |
312 |
| |
313 // ======================================================================================================================================== |
| |
314 void LDrawPathDialog::slot_findPath () { |
| |
315 str newpath = QFileDialog::getExistingDirectory (this, "Find LDraw Path"); |
| |
316 |
| |
317 if (~newpath > 0 && newpath != path ()) { |
| |
318 setPath (newpath); |
| |
319 slot_tryConfigure (); |
| |
320 } |
| |
321 } |
| |
322 |
| |
323 |
| |
324 // ======================================================================================================================================== |
| |
325 void LDrawPathDialog::slot_exit () { |
| |
326 exit (1); |
| |
327 } |
| |
328 |
| |
329 // ======================================================================================================================================== |
| |
330 void LDrawPathDialog::slot_tryConfigure () { |
| |
331 if (LDPaths::tryConfigure (path ()) == false) { |
| |
332 lb_resolution->setText (fmt ("<span style=\"color:red; font-weight: bold;\">%s</span>", LDPaths::getError().chars ())); |
| |
333 okButton ()->setEnabled (false); |
| |
334 return; |
| |
335 } |
| |
336 |
| |
337 lb_resolution->setText ("<span style=\"color: #7A0; font-weight: bold;\">OK!</span>"); |
| |
338 okButton ()->setEnabled (true); |
| |
339 } |
| |
340 |
| |
341 // ============================================================================= |
| |
342 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| |
343 // ============================================================================= |
| |
344 NewPartDialog::NewPartDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) { |
| |
345 lb_brickIcon = new QLabel; |
| |
346 lb_brickIcon->setPixmap (getIcon ("brick")); |
| |
347 |
| |
348 lb_name = new QLabel ("Name:"); |
| |
349 le_name = new QLineEdit; |
| |
350 le_name->setMinimumWidth (320); |
| |
351 |
| |
352 lb_author = new QLabel ("Author:"); |
| |
353 le_author = new QLineEdit; |
| |
354 |
| |
355 rb_license = new RadioBox ("License", { |
| |
356 "CCAL Redistributable", |
| |
357 "Non-redistributable", |
| |
358 "None", |
| |
359 }, CCAL); |
| |
360 |
| |
361 rb_BFC = new RadioBox ("BFC Winding", { |
| |
362 "CCW", |
| |
363 "CW", |
| |
364 "None" |
| |
365 }, CCW); |
| |
366 |
| |
367 QHBoxLayout* boxes = new QHBoxLayout; |
| |
368 boxes->addWidget (rb_license); |
| |
369 boxes->addWidget (rb_BFC); |
| |
370 |
| |
371 QGridLayout* layout = new QGridLayout; |
| |
372 layout->addWidget (lb_brickIcon, 0, 0); |
| |
373 layout->addWidget (lb_name, 0, 1); |
| |
374 layout->addWidget (le_name, 0, 2); |
| |
375 layout->addWidget (lb_author, 1, 1); |
| |
376 layout->addWidget (le_author, 1, 2); |
| |
377 layout->addLayout (boxes, 2, 1, 1, 2); |
| |
378 layout->addWidget (makeButtonBox (*this), 3, 2); |
| |
379 |
| |
380 setLayout (layout); |
| |
381 setWindowTitle ("New Part"); |
| |
382 } |
| |
383 |
| |
384 // ============================================================================= |
| |
385 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| |
386 // ============================================================================= |
| |
387 void NewPartDialog::StaticDialog () { |
| |
388 NewPartDialog dlg (g_win); |
| |
389 if (dlg.exec ()) { |
| |
390 newFile (); |
| |
391 |
| |
392 short idx; |
| |
393 str author = dlg.le_author->text (); |
| |
394 vector<LDObject*>& objs = g_curfile->m_objs; |
| |
395 |
| |
396 idx = dlg.rb_BFC->value (); |
| |
397 const LDBFC::Type BFCType = |
| |
398 (idx == CCW) ? LDBFC::CertifyCCW : |
| |
399 (idx == CW) ? LDBFC::CertifyCW : |
| |
400 LDBFC::NoCertify; |
| |
401 |
| |
402 idx = dlg.rb_license->value (); |
| |
403 const char* license = |
| |
404 (idx == CCAL) ? "Redistributable under CCAL version 2.0 : see CAreadme.txt" : |
| |
405 (idx == NonCA) ? "Not redistributable : see NonCAreadme.txt" : |
| |
406 null; |
| |
407 |
| |
408 objs.push_back (new LDComment (dlg.le_name->text ())); |
| |
409 objs.push_back (new LDComment ("Name: <untitled>.dat")); |
| |
410 objs.push_back (new LDComment (fmt ("Author: %s", author.chars()))); |
| |
411 objs.push_back (new LDComment (fmt ("!LDRAW_ORG Unofficial_Part"))); |
| |
412 |
| |
413 if (license != null) |
| |
414 objs.push_back (new LDComment (fmt ("!LICENSE %s", license))); |
| |
415 |
| |
416 objs.push_back (new LDEmpty); |
| |
417 objs.push_back (new LDBFC (BFCType)); |
| |
418 objs.push_back (new LDEmpty); |
| |
419 |
| |
420 g_win->fullRefresh (); |
| |
421 } |
| |
422 } |