252 } |
252 } |
253 |
253 |
254 // ============================================================================= |
254 // ============================================================================= |
255 // ----------------------------------------------------------------------------- |
255 // ----------------------------------------------------------------------------- |
256 int ForgeWindow::deleteSelection() |
256 int ForgeWindow::deleteSelection() |
257 { if (m_sel.size() == 0) |
257 { if (selection().isEmpty()) |
258 return 0; |
258 return 0; |
259 |
259 |
260 QList<LDObject*> selCopy = m_sel; |
260 QList<LDObject*> selCopy = selection(); |
261 int num = 0; |
261 int num = 0; |
262 |
262 |
263 // Delete the objects that were being selected |
263 // Delete the objects that were being selected |
264 for (LDObject * obj : selCopy) |
264 for (LDObject* obj : selCopy) |
265 { LDFile::current()->forgetObject (obj); |
265 { LDFile::current()->forgetObject (obj); |
266 ++num; |
266 ++num; |
267 delete obj; |
267 delete obj; |
268 } |
268 } |
269 |
269 |
380 } |
380 } |
381 |
381 |
382 // ============================================================================= |
382 // ============================================================================= |
383 // ----------------------------------------------------------------------------- |
383 // ----------------------------------------------------------------------------- |
384 void ForgeWindow::scrollToSelection() |
384 void ForgeWindow::scrollToSelection() |
385 { if (m_sel.size() == 0) |
385 { if (selection().isEmpty()) |
386 return; |
386 return; |
387 |
387 |
388 LDObject* obj = m_sel[m_sel.size() - 1]; |
388 LDObject* obj = selection().last(); |
389 ui->objectList->scrollToItem (obj->qObjListEntry); |
389 ui->objectList->scrollToItem (obj->qObjListEntry); |
390 } |
390 } |
391 |
391 |
392 // ============================================================================= |
392 // ============================================================================= |
393 // ----------------------------------------------------------------------------- |
393 // ----------------------------------------------------------------------------- |
399 // called during GL picking, in which case the GL renderer takes care |
399 // called during GL picking, in which case the GL renderer takes care |
400 // of the selection. |
400 // of the selection. |
401 if (m_renderer->picking()) |
401 if (m_renderer->picking()) |
402 return; |
402 return; |
403 |
403 |
404 QList<LDObject*> priorSelection = m_sel; |
404 QList<LDObject*> priorSelection = selection(); |
405 |
405 |
406 // Get the objects from the object list selection |
406 // Get the objects from the object list selection |
407 m_sel.clear(); |
407 LDFile::current()->clearSelection(); |
408 const QList<QListWidgetItem*> items = ui->objectList->selectedItems(); |
408 const QList<QListWidgetItem*> items = ui->objectList->selectedItems(); |
409 |
409 |
410 for (LDObject* obj : LDFile::current()->objects()) |
410 for (LDObject* obj : LDFile::current()->objects()) |
411 for (QListWidgetItem* item : items) |
411 { for (QListWidgetItem* item : items) |
412 { if (item == obj->qObjListEntry) |
412 { if (item == obj->qObjListEntry) |
413 { m_sel << obj; |
413 { obj->select(); |
414 break; |
414 break; |
415 } |
415 } |
416 } |
416 } |
|
417 } |
417 |
418 |
418 // Update the GL renderer |
419 // Update the GL renderer |
419 for (LDObject* obj : priorSelection) |
420 QList<LDObject*> compound = priorSelection + selection(); |
420 { obj->setSelected (false); |
421 removeDuplicates (compound); |
|
422 |
|
423 for (LDObject* obj : compound) |
421 m_renderer->compileObject (obj); |
424 m_renderer->compileObject (obj); |
422 } |
|
423 |
|
424 for (LDObject* obj : m_sel) |
|
425 { obj->setSelected (true); |
|
426 m_renderer->compileObject (obj); |
|
427 } |
|
428 |
425 |
429 m_renderer->update(); |
426 m_renderer->update(); |
430 } |
427 } |
431 |
428 |
432 // ============================================================================= |
429 // ============================================================================= |
441 void ForgeWindow::slot_quickColor() |
438 void ForgeWindow::slot_quickColor() |
442 { beginAction (null); |
439 { beginAction (null); |
443 QToolButton* button = static_cast<QToolButton*> (sender()); |
440 QToolButton* button = static_cast<QToolButton*> (sender()); |
444 LDColor* col = null; |
441 LDColor* col = null; |
445 |
442 |
446 for (const LDQuickColor & entry : m_quickColors) |
443 for (const LDQuickColor & entry : m_quickColors) |
447 { if (entry.toolButton() == button) |
444 { if (entry.toolButton() == button) |
448 { col = entry.color(); |
445 { col = entry.color(); |
449 break; |
446 break; |
450 } |
447 } |
451 } |
448 } |
453 if (col == null) |
450 if (col == null) |
454 return; |
451 return; |
455 |
452 |
456 short newColor = col->index; |
453 short newColor = col->index; |
457 |
454 |
458 for (LDObject * obj : m_sel) |
455 for (LDObject* obj : selection()) |
459 { if (obj->isColored() == false) |
456 { if (obj->isColored() == false) |
460 continue; // uncolored object |
457 continue; // uncolored object |
461 |
458 |
462 obj->setColor (newColor); |
459 obj->setColor (newColor); |
463 R()->compileObject (obj); |
460 R()->compileObject (obj); |
468 } |
465 } |
469 |
466 |
470 // ============================================================================= |
467 // ============================================================================= |
471 // ----------------------------------------------------------------------------- |
468 // ----------------------------------------------------------------------------- |
472 int ForgeWindow::getInsertionPoint() |
469 int ForgeWindow::getInsertionPoint() |
473 { if (m_sel.size() > 0) |
470 { // If we have a selection, put the item after it. |
474 { // If we have a selection, put the item after it. |
471 if (!selection().isEmpty()) |
475 return (m_sel[m_sel.size() - 1]->getIndex()) + 1; |
472 return selection().last()->getIndex() + 1; |
476 } |
|
477 |
473 |
478 // Otherwise place the object at the end. |
474 // Otherwise place the object at the end. |
479 return LDFile::current()->numObjs(); |
475 return LDFile::current()->numObjs(); |
480 } |
476 } |
481 |
477 |
496 // ============================================================================= |
492 // ============================================================================= |
497 // ----------------------------------------------------------------------------- |
493 // ----------------------------------------------------------------------------- |
498 void ForgeWindow::updateSelection() |
494 void ForgeWindow::updateSelection() |
499 { g_bSelectionLocked = true; |
495 { g_bSelectionLocked = true; |
500 |
496 |
501 for (LDObject * obj : LDFile::current()->objects()) |
497 for (LDObject* obj : LDFile::current()->objects()) |
502 obj->setSelected (false); |
498 obj->setSelected (false); |
503 |
499 |
504 ui->objectList->clearSelection(); |
500 ui->objectList->clearSelection(); |
505 |
501 |
506 for (LDObject * obj : m_sel) |
502 for (LDObject* obj : selection()) |
507 { if (obj->qObjListEntry == null) |
503 { if (obj->qObjListEntry == null) |
508 continue; |
504 continue; |
509 |
505 |
510 obj->qObjListEntry->setSelected (true); |
506 obj->qObjListEntry->setSelected (true); |
511 obj->setSelected (true); |
507 obj->setSelected (true); |
515 slot_selectionChanged(); |
511 slot_selectionChanged(); |
516 } |
512 } |
517 |
513 |
518 // ============================================================================= |
514 // ============================================================================= |
519 // ----------------------------------------------------------------------------- |
515 // ----------------------------------------------------------------------------- |
520 bool ForgeWindow::isSelected (LDObject* obj) |
|
521 { LDObject* needle = obj->topLevelParent(); |
|
522 |
|
523 for (LDObject * hay : m_sel) |
|
524 if (hay == needle) |
|
525 return true; |
|
526 |
|
527 return false; |
|
528 } |
|
529 |
|
530 short ForgeWindow::getSelectedColor() |
516 short ForgeWindow::getSelectedColor() |
531 { short result = -1; |
517 { short result = -1; |
532 |
518 |
533 for (LDObject * obj : m_sel) |
519 for (LDObject* obj : selection()) |
534 { if (obj->isColored() == false) |
520 { if (obj->isColored() == false) |
535 continue; // doesn't use color |
521 continue; // doesn't use color |
536 |
522 |
537 if (result != -1 && obj->color() != result) |
523 if (result != -1 && obj->color() != result) |
538 return -1; // No consensus in object color |
524 return -1; // No consensus in object color |
547 // ============================================================================= |
533 // ============================================================================= |
548 // ----------------------------------------------------------------------------- |
534 // ----------------------------------------------------------------------------- |
549 LDObject::Type ForgeWindow::uniformSelectedType() |
535 LDObject::Type ForgeWindow::uniformSelectedType() |
550 { LDObject::Type result = LDObject::Unidentified; |
536 { LDObject::Type result = LDObject::Unidentified; |
551 |
537 |
552 for (LDObject * obj : m_sel) |
538 for (LDObject * obj : selection()) |
553 { if (result != LDObject::Unidentified && obj->color() != result) |
539 { if (result != LDObject::Unidentified && obj->color() != result) |
554 return LDObject::Unidentified; |
540 return LDObject::Unidentified; |
555 |
541 |
556 if (result == LDObject::Unidentified) |
542 if (result == LDObject::Unidentified) |
557 result = obj->getType(); |
543 result = obj->getType(); |
577 } |
563 } |
578 |
564 |
579 // ============================================================================= |
565 // ============================================================================= |
580 // ----------------------------------------------------------------------------- |
566 // ----------------------------------------------------------------------------- |
581 void ForgeWindow::spawnContextMenu (const QPoint pos) |
567 void ForgeWindow::spawnContextMenu (const QPoint pos) |
582 { const bool single = (g_win->sel().size() == 1); |
568 { const bool single = (selection().size() == 1); |
583 LDObject* singleObj = (single) ? g_win->sel() [0] : null; |
569 LDObject* singleObj = (single) ? selection()[0] : null; |
584 |
570 |
585 QMenu* contextMenu = new QMenu; |
571 QMenu* contextMenu = new QMenu; |
586 |
572 |
587 if (single && singleObj->getType() != LDObject::Empty) |
573 if (single && singleObj->getType() != LDObject::Empty) |
588 { contextMenu->addAction (ACTION (Edit)); |
574 { contextMenu->addAction (ACTION (Edit)); |