src/gui.cpp

changeset 538
2f85d4d286e5
parent 530
f9476dbd87ec
child 539
72ad83a67165
equal deleted inserted replaced
537:1add0ee96fb3 538:2f85d4d286e5
48 #include "messagelog.h" 48 #include "messagelog.h"
49 #include "config.h" 49 #include "config.h"
50 #include "ui_ldforge.h" 50 #include "ui_ldforge.h"
51 #include "moc_gui.cpp" 51 #include "moc_gui.cpp"
52 52
53 static bool g_bSelectionLocked = false; 53 static bool g_isSelectionLocked = false;
54 54
55 cfg (Bool, lv_colorize, true); 55 cfg (Bool, lv_colorize, true);
56 cfg (String, gui_colortoolbar, "16:24:|:1:2:4:14:0:15:|:33:34:36:46"); 56 cfg (String, gui_colortoolbar, "16:24:|:1:2:4:14:0:15:|:33:34:36:46");
57 cfg (Bool, gui_implicitfiles, false); 57 cfg (Bool, gui_implicitfiles, false);
58 extern_cfg (List, io_recentfiles); 58 extern_cfg (List, io_recentfiles);
229 { if (LDFile::current()->name().length() > 0) 229 { if (LDFile::current()->name().length() > 0)
230 title += fmt (": %1", basename (LDFile::current()->name())); 230 title += fmt (": %1", basename (LDFile::current()->name()));
231 else 231 else
232 title += fmt (": <anonymous>"); 232 title += fmt (": <anonymous>");
233 233
234 if (LDFile::current()->numObjs() > 0 && 234 if (LDFile::current()->getObjectCount() > 0 &&
235 LDFile::current()->obj (0)->getType() == LDObject::Comment) 235 LDFile::current()->getObject (0)->getType() == LDObject::Comment)
236 { // Append title 236 { // Append title
237 LDComment* comm = static_cast<LDComment*> (LDFile::current()->obj (0)); 237 LDComment* comm = static_cast<LDComment*> (LDFile::current()->getObject (0));
238 title += fmt (": %1", comm->text); 238 title += fmt (": %1", comm->text);
239 } 239 }
240 240
241 if (LDFile::current()->history().pos() != LDFile::current()->savePos()) 241 if (LDFile::current()->history().pos() != LDFile::current()->savePos())
242 title += '*'; 242 title += '*';
274 return; 274 return;
275 275
276 // Lock the selection while we do this so that refreshing the object list 276 // Lock the selection while we do this so that refreshing the object list
277 // doesn't trigger selection updating so that the selection doesn't get lost 277 // doesn't trigger selection updating so that the selection doesn't get lost
278 // while this is done. 278 // while this is done.
279 g_bSelectionLocked = true; 279 g_isSelectionLocked = true;
280 280
281 for (int i = 0; i < ui->objectList->count(); ++i) 281 for (int i = 0; i < ui->objectList->count(); ++i)
282 delete ui->objectList->item (i); 282 delete ui->objectList->item (i);
283 283
284 ui->objectList->clear(); 284 ui->objectList->clear();
300 300
301 case LDObject::Line: 301 case LDObject::Line:
302 case LDObject::Triangle: 302 case LDObject::Triangle:
303 case LDObject::Quad: 303 case LDObject::Quad:
304 case LDObject::CndLine: 304 case LDObject::CndLine:
305 { for (short i = 0; i < obj->vertices(); ++i) 305 { for (int i = 0; i < obj->vertices(); ++i)
306 { if (i != 0) 306 { if (i != 0)
307 descr += ", "; 307 descr += ", ";
308 308
309 descr += obj->getVertex (i).stringRep (true); 309 descr += obj->getVertex (i).stringRep (true);
310 } 310 }
339 basename (ovl->filename()), ovl->x(), ovl->y(), ovl->width(), ovl->height()); 339 basename (ovl->filename()), ovl->x(), ovl->y(), ovl->width(), ovl->height());
340 } 340 }
341 break; 341 break;
342 342
343 default: 343 default:
344 { descr = obj->typeName(); 344 { descr = obj->getTypeName();
345 } break; 345 } break;
346 } 346 }
347 347
348 QListWidgetItem* item = new QListWidgetItem (descr); 348 QListWidgetItem* item = new QListWidgetItem (descr);
349 item->setIcon (getIcon (obj->typeName())); 349 item->setIcon (getIcon (obj->getTypeName()));
350 350
351 // Use italic font if hidden 351 // Use italic font if hidden
352 if (obj->hidden()) 352 if (obj->hidden())
353 { QFont font = item->font(); 353 { QFont font = item->font();
354 font.setItalic (true); 354 font.setItalic (true);
371 371
372 obj->qObjListEntry = item; 372 obj->qObjListEntry = item;
373 ui->objectList->insertItem (ui->objectList->count(), item); 373 ui->objectList->insertItem (ui->objectList->count(), item);
374 } 374 }
375 375
376 g_bSelectionLocked = false; 376 g_isSelectionLocked = false;
377 updateSelection(); 377 updateSelection();
378 scrollToSelection(); 378 scrollToSelection();
379 } 379 }
380 380
381 // ============================================================================= 381 // =============================================================================
389 } 389 }
390 390
391 // ============================================================================= 391 // =============================================================================
392 // ----------------------------------------------------------------------------- 392 // -----------------------------------------------------------------------------
393 void ForgeWindow::slot_selectionChanged() 393 void ForgeWindow::slot_selectionChanged()
394 { if (g_bSelectionLocked == true || LDFile::current() == null) 394 { if (g_isSelectionLocked == true || LDFile::current() == null)
395 return; 395 return;
396 396
397 // Update the shared selection array, though don't do this if this was 397 // Update the shared selection array, though don't do this if this was
398 // called during GL picking, in which case the GL renderer takes care 398 // called during GL picking, in which case the GL renderer takes care
399 // of the selection. 399 // of the selection.
447 } 447 }
448 448
449 if (col == null) 449 if (col == null)
450 return; 450 return;
451 451
452 short newColor = col->index; 452 int newColor = col->index;
453 453
454 for (LDObject* obj : selection()) 454 for (LDObject* obj : selection())
455 { if (obj->isColored() == false) 455 { if (obj->isColored() == false)
456 continue; // uncolored object 456 continue; // uncolored object
457 457
469 { // If we have a selection, put the item after it. 469 { // If we have a selection, put the item after it.
470 if (!selection().isEmpty()) 470 if (!selection().isEmpty())
471 return selection().last()->getIndex() + 1; 471 return selection().last()->getIndex() + 1;
472 472
473 // Otherwise place the object at the end. 473 // Otherwise place the object at the end.
474 return LDFile::current()->numObjs(); 474 return LDFile::current()->getObjectCount();
475 } 475 }
476 476
477 // ============================================================================= 477 // =============================================================================
478 // ----------------------------------------------------------------------------- 478 // -----------------------------------------------------------------------------
479 void ForgeWindow::fullRefresh() 479 void ForgeWindow::doFullRefresh()
480 { buildObjList(); 480 { buildObjList();
481 m_renderer->hardRefresh(); 481 m_renderer->hardRefresh();
482 } 482 }
483 483
484 // ============================================================================= 484 // =============================================================================
489 } 489 }
490 490
491 // ============================================================================= 491 // =============================================================================
492 // ----------------------------------------------------------------------------- 492 // -----------------------------------------------------------------------------
493 void ForgeWindow::updateSelection() 493 void ForgeWindow::updateSelection()
494 { g_bSelectionLocked = true; 494 { g_isSelectionLocked = true;
495 495
496 for (LDObject* obj : LDFile::current()->objects()) 496 for (LDObject* obj : LDFile::current()->objects())
497 obj->setSelected (false); 497 obj->setSelected (false);
498 498
499 ui->objectList->clearSelection(); 499 ui->objectList->clearSelection();
504 504
505 obj->qObjListEntry->setSelected (true); 505 obj->qObjListEntry->setSelected (true);
506 obj->setSelected (true); 506 obj->setSelected (true);
507 } 507 }
508 508
509 g_bSelectionLocked = false; 509 g_isSelectionLocked = false;
510 slot_selectionChanged(); 510 slot_selectionChanged();
511 } 511 }
512 512
513 // ============================================================================= 513 // =============================================================================
514 // ----------------------------------------------------------------------------- 514 // -----------------------------------------------------------------------------
515 short ForgeWindow::getSelectedColor() 515 int ForgeWindow::getSelectedColor()
516 { short result = -1; 516 { int result = -1;
517 517
518 for (LDObject* obj : selection()) 518 for (LDObject* obj : selection())
519 { if (obj->isColored() == false) 519 { if (obj->isColored() == false)
520 continue; // doesn't use color 520 continue; // doesn't use color
521 521
529 return result; 529 return result;
530 } 530 }
531 531
532 // ============================================================================= 532 // =============================================================================
533 // ----------------------------------------------------------------------------- 533 // -----------------------------------------------------------------------------
534 LDObject::Type ForgeWindow::uniformSelectedType() 534 LDObject::Type ForgeWindow::getUniformSelectedType()
535 { LDObject::Type result = LDObject::Unidentified; 535 { LDObject::Type result = LDObject::Unidentified;
536 536
537 for (LDObject * obj : selection()) 537 for (LDObject * obj : selection())
538 { if (result != LDObject::Unidentified && obj->color() != result) 538 { if (result != LDObject::Unidentified && obj->color() != result)
539 return LDObject::Unidentified; 539 return LDObject::Unidentified;
599 contextMenu->exec (pos); 599 contextMenu->exec (pos);
600 } 600 }
601 601
602 // ============================================================================= 602 // =============================================================================
603 // ----------------------------------------------------------------------------- 603 // -----------------------------------------------------------------------------
604 void ForgeWindow::deleteObjVector (QList<LDObject*> objs) 604 void ForgeWindow::deleteObjects (QList<LDObject*> objs)
605 { for (LDObject * obj : objs) 605 { for (LDObject * obj : objs)
606 { LDFile::current()->forgetObject (obj); 606 { LDFile::current()->forgetObject (obj);
607 delete obj; 607 delete obj;
608 } 608 }
609 } 609 }
610 610
611 // ============================================================================= 611 // =============================================================================
612 // ----------------------------------------------------------------------------- 612 // -----------------------------------------------------------------------------
613 void ForgeWindow::deleteByColor (const short colnum) 613 void ForgeWindow::deleteByColor (const int colnum)
614 { QList<LDObject*> objs; 614 { QList<LDObject*> objs;
615 615
616 for (LDObject * obj : LDFile::current()->objects()) 616 for (LDObject * obj : LDFile::current()->objects())
617 { if (!obj->isColored() || obj->color() != colnum) 617 { if (!obj->isColored() || obj->color() != colnum)
618 continue; 618 continue;
619 619
620 objs << obj; 620 objs << obj;
621 } 621 }
622 622
623 deleteObjVector (objs); 623 deleteObjects (objs);
624 } 624 }
625 625
626 // ============================================================================= 626 // =============================================================================
627 // ----------------------------------------------------------------------------- 627 // -----------------------------------------------------------------------------
628 void ForgeWindow::updateEditModeActions() 628 void ForgeWindow::updateEditModeActions()

mercurial