src/MainWindow.cc

changeset 642
751a8df42842
parent 640
d4dda62c6600
child 644
93dcd1a0e4bd
equal deleted inserted replaced
641:425b169a82aa 642:751a8df42842
226 if (entry.isSeparator()) 226 if (entry.isSeparator())
227 ui->colorToolbar->addSeparator(); 227 ui->colorToolbar->addSeparator();
228 else 228 else
229 { 229 {
230 QToolButton* colorButton = new QToolButton; 230 QToolButton* colorButton = new QToolButton;
231 colorButton->setIcon (makeColorIcon (entry.getColor(), 22)); 231 colorButton->setIcon (makeColorIcon (entry.color(), 22));
232 colorButton->setIconSize (QSize (22, 22)); 232 colorButton->setIconSize (QSize (22, 22));
233 colorButton->setToolTip (entry.getColor()->name); 233 colorButton->setToolTip (entry.color()->name);
234 234
235 connect (colorButton, SIGNAL (clicked()), this, SLOT (slot_quickColor())); 235 connect (colorButton, SIGNAL (clicked()), this, SLOT (slot_quickColor()));
236 ui->colorToolbar->addWidget (colorButton); 236 ui->colorToolbar->addWidget (colorButton);
237 m_colorButtons << colorButton; 237 m_colorButtons << colorButton;
238 238
260 QString title = fmt (APPNAME " %1", fullVersionString()); 260 QString title = fmt (APPNAME " %1", fullVersionString());
261 261
262 // Append our current file if we have one 262 // Append our current file if we have one
263 if (getCurrentDocument()) 263 if (getCurrentDocument())
264 { 264 {
265 if (getCurrentDocument()->getName().length() > 0) 265 if (getCurrentDocument()->name().length() > 0)
266 title += fmt (": %1", basename (getCurrentDocument()->getName())); 266 title += fmt (": %1", basename (getCurrentDocument()->name()));
267 else 267 else
268 title += fmt (": <anonymous>"); 268 title += fmt (": <anonymous>");
269 269
270 if (getCurrentDocument()->getObjectCount() > 0 && 270 if (getCurrentDocument()->getObjectCount() > 0 &&
271 getCurrentDocument()->getObject (0)->type() == LDObject::EComment) 271 getCurrentDocument()->getObject (0)->type() == LDObject::EComment)
272 { 272 {
273 // Append title 273 // Append title
274 LDComment* comm = static_cast<LDComment*> (getCurrentDocument()->getObject (0)); 274 LDComment* comm = static_cast<LDComment*> (getCurrentDocument()->getObject (0));
275 title += fmt (": %1", comm->text); 275 title += fmt (": %1", comm->text());
276 } 276 }
277 277
278 if (getCurrentDocument()->getHistory()->getPosition() != getCurrentDocument()->getSavePosition()) 278 if (getCurrentDocument()->hasUnsavedChanges())
279 title += '*'; 279 title += '*';
280 } 280 }
281 281
282 #ifdef DEBUG 282 #ifdef DEBUG
283 title += " [debug build]"; 283 title += " [debug build]";
324 for (int i = 0; i < ui->objectList->count(); ++i) 324 for (int i = 0; i < ui->objectList->count(); ++i)
325 delete ui->objectList->item (i); 325 delete ui->objectList->item (i);
326 326
327 ui->objectList->clear(); 327 ui->objectList->clear();
328 328
329 for (LDObject* obj : getCurrentDocument()->getObjects()) 329 for (LDObject* obj : getCurrentDocument()->objects())
330 { 330 {
331 QString descr; 331 QString descr;
332 332
333 switch (obj->type()) 333 switch (obj->type())
334 { 334 {
335 case LDObject::EComment: 335 case LDObject::EComment:
336 { 336 {
337 descr = static_cast<LDComment*> (obj)->text; 337 descr = static_cast<LDComment*> (obj)->text();
338 338
339 // Remove leading whitespace 339 // Remove leading whitespace
340 while (descr[0] == ' ') 340 while (descr[0] == ' ')
341 descr.remove (0, 1); 341 descr.remove (0, 1);
342 342
375 375
376 case LDObject::ESubfile: 376 case LDObject::ESubfile:
377 { 377 {
378 LDSubfile* ref = static_cast<LDSubfile*> (obj); 378 LDSubfile* ref = static_cast<LDSubfile*> (obj);
379 379
380 descr = fmt ("%1 %2, (", ref->getFileInfo()->getDisplayName(), ref->getPosition().toString (true)); 380 descr = fmt ("%1 %2, (", ref->fileInfo()->getDisplayName(), ref->position().toString (true));
381 381
382 for (int i = 0; i < 9; ++i) 382 for (int i = 0; i < 9; ++i)
383 descr += fmt ("%1%2", ref->getTransform()[i], (i != 8) ? " " : ""); 383 descr += fmt ("%1%2", ref->transform()[i], (i != 8) ? " " : "");
384 384
385 descr += ')'; 385 descr += ')';
386 break; 386 break;
387 } 387 }
388 388
389 case LDObject::EBFC: 389 case LDObject::EBFC:
390 { 390 {
391 descr = LDBFC::k_statementStrings[static_cast<LDBFC*> (obj)->m_statement]; 391 descr = LDBFC::k_statementStrings[static_cast<LDBFC*> (obj)->statement()];
392 break; 392 break;
393 } 393 }
394 394
395 case LDObject::EOverlay: 395 case LDObject::EOverlay:
396 { 396 {
397 LDOverlay* ovl = static_cast<LDOverlay*> (obj); 397 LDOverlay* ovl = static_cast<LDOverlay*> (obj);
398 descr = fmt ("[%1] %2 (%3, %4), %5 x %6", g_CameraNames[ovl->getCamera()], 398 descr = fmt ("[%1] %2 (%3, %4), %5 x %6", g_CameraNames[ovl->camera()],
399 basename (ovl->getFileName()), ovl->getX(), ovl->getY(), 399 basename (ovl->fileName()), ovl->x(), ovl->y(),
400 ovl->getWidth(), ovl->getHeight()); 400 ovl->width(), ovl->height());
401 break; 401 break;
402 } 402 }
403 403
404 default: 404 default:
405 { 405 {
423 if (obj->type() == LDObject::EError) 423 if (obj->type() == LDObject::EError)
424 { 424 {
425 item->setBackground (QColor ("#AA0000")); 425 item->setBackground (QColor ("#AA0000"));
426 item->setForeground (QColor ("#FFAA00")); 426 item->setForeground (QColor ("#FFAA00"));
427 } 427 }
428 elif (lv_colorize && obj->isColored() && obj->getColor() != maincolor && obj->getColor() != edgecolor) 428 elif (lv_colorize && obj->isColored() && obj->color() != maincolor && obj->color() != edgecolor)
429 { 429 {
430 // If the object isn't in the main or edge color, draw this 430 // If the object isn't in the main or edge color, draw this
431 // list entry in said color. 431 // list entry in said color.
432 LDColor* col = getColor (obj->getColor()); 432 LDColor* col = getColor (obj->color());
433 433
434 if (col) 434 if (col)
435 item->setForeground (col->faceColor); 435 item->setForeground (col->faceColor);
436 } 436 }
437 437
472 472
473 // Get the objects from the object list selection 473 // Get the objects from the object list selection
474 getCurrentDocument()->clearSelection(); 474 getCurrentDocument()->clearSelection();
475 const QList<QListWidgetItem*> items = ui->objectList->selectedItems(); 475 const QList<QListWidgetItem*> items = ui->objectList->selectedItems();
476 476
477 for (LDObject* obj : getCurrentDocument()->getObjects()) 477 for (LDObject* obj : getCurrentDocument()->objects())
478 { 478 {
479 for (QListWidgetItem* item : items) 479 for (QListWidgetItem* item : items)
480 { 480 {
481 if (item == obj->qObjListEntry) 481 if (item == obj->qObjListEntry)
482 { 482 {
511 QToolButton* button = static_cast<QToolButton*> (sender()); 511 QToolButton* button = static_cast<QToolButton*> (sender());
512 LDColor* col = null; 512 LDColor* col = null;
513 513
514 for (const LDQuickColor& entry : m_quickColors) 514 for (const LDQuickColor& entry : m_quickColors)
515 { 515 {
516 if (entry.getToolButton() == button) 516 if (entry.toolButton() == button)
517 { 517 {
518 col = entry.getColor(); 518 col = entry.color();
519 break; 519 break;
520 } 520 }
521 } 521 }
522 522
523 if (col == null) 523 if (col == null)
570 // 570 //
571 void MainWindow::updateSelection() 571 void MainWindow::updateSelection()
572 { 572 {
573 g_isSelectionLocked = true; 573 g_isSelectionLocked = true;
574 574
575 for (LDObject* obj : getCurrentDocument()->getObjects()) 575 for (LDObject* obj : getCurrentDocument()->objects())
576 obj->setSelected (false); 576 obj->setSelected (false);
577 577
578 ui->objectList->clearSelection(); 578 ui->objectList->clearSelection();
579 579
580 for (LDObject* obj : selection()) 580 for (LDObject* obj : selection())
599 for (LDObject* obj : selection()) 599 for (LDObject* obj : selection())
600 { 600 {
601 if (obj->isColored() == false) 601 if (obj->isColored() == false)
602 continue; // doesn't use color 602 continue; // doesn't use color
603 603
604 if (result != -1 && obj->getColor() != result) 604 if (result != -1 && obj->color() != result)
605 return -1; // No consensus in object color 605 return -1; // No consensus in object color
606 606
607 if (result == -1) 607 if (result == -1)
608 result = obj->getColor(); 608 result = obj->color();
609 } 609 }
610 610
611 return result; 611 return result;
612 } 612 }
613 613
617 { 617 {
618 LDObject::Type result = LDObject::EUnidentified; 618 LDObject::Type result = LDObject::EUnidentified;
619 619
620 for (LDObject* obj : selection()) 620 for (LDObject* obj : selection())
621 { 621 {
622 if (result != LDObject::EUnidentified && obj->getColor() != result) 622 if (result != LDObject::EUnidentified && obj->color() != result)
623 return LDObject::EUnidentified; 623 return LDObject::EUnidentified;
624 624
625 if (result == LDObject::EUnidentified) 625 if (result == LDObject::EUnidentified)
626 result = obj->type(); 626 result = obj->type();
627 } 627 }
693 693
694 contextMenu->exec (pos); 694 contextMenu->exec (pos);
695 } 695 }
696 696
697 // ============================================================================= 697 // =============================================================================
698 // TODO: what the heh? 698 //
699 // 699 void MainWindow::deleteByColor (const int colnum)
700 void MainWindow::deleteObjects (LDObjectList objs) 700 {
701 { 701 LDObjectList objs;
702
703 for (LDObject* obj : getCurrentDocument()->objects())
704 {
705 if (!obj->isColored() || obj->color() != colnum)
706 continue;
707
708 objs << obj;
709 }
710
702 for (LDObject* obj : objs) 711 for (LDObject* obj : objs)
703 obj->destroy(); 712 obj->destroy();
704 } 713 }
705 714
706 // ============================================================================= 715 // =============================================================================
707 // 716 //
708 void MainWindow::deleteByColor (const int colnum)
709 {
710 LDObjectList objs;
711
712 for (LDObject* obj : getCurrentDocument()->getObjects())
713 {
714 if (!obj->isColored() || obj->getColor() != colnum)
715 continue;
716
717 objs << obj;
718 }
719
720 deleteObjects (objs);
721 }
722
723 // =============================================================================
724 //
725 void MainWindow::updateEditModeActions() 717 void MainWindow::updateEditModeActions()
726 { 718 {
727 const EditMode mode = R()->getEditMode(); 719 const EditMode mode = R()->editMode();
728 ui->actionModeSelect->setChecked (mode == ESelectMode); 720 ui->actionModeSelect->setChecked (mode == ESelectMode);
729 ui->actionModeDraw->setChecked (mode == EDrawMode); 721 ui->actionModeDraw->setChecked (mode == EDrawMode);
730 ui->actionModeCircle->setChecked (mode == ECircleMode); 722 ui->actionModeCircle->setChecked (mode == ECircleMode);
731 } 723 }
732 724
734 // 726 //
735 void MainWindow::slot_editObject (QListWidgetItem* listitem) 727 void MainWindow::slot_editObject (QListWidgetItem* listitem)
736 { 728 {
737 LDObject* obj = null; 729 LDObject* obj = null;
738 730
739 for (LDObject* it : getCurrentDocument()->getObjects()) 731 for (LDObject* it : getCurrentDocument()->objects())
740 { 732 {
741 if (it->qObjListEntry == listitem) 733 if (it->qObjListEntry == listitem)
742 { 734 {
743 obj = it; 735 obj = it;
744 break; 736 break;
750 742
751 // ============================================================================= 743 // =============================================================================
752 // 744 //
753 bool MainWindow::save (LDDocument* f, bool saveAs) 745 bool MainWindow::save (LDDocument* f, bool saveAs)
754 { 746 {
755 QString path = f->getFullPath(); 747 QString path = f->fullPath();
756 748
757 if (saveAs || path.isEmpty()) 749 if (saveAs || path.isEmpty())
758 { 750 {
759 QString name = f->getDefaultName(); 751 QString name = f->defaultName();
760 752
761 if (!f->getFullPath().isEmpty()) 753 if (!f->fullPath().isEmpty())
762 name = f->getFullPath(); 754 name = f->fullPath();
763 elif (!f->getName().isEmpty()) 755 elif (!f->name().isEmpty())
764 name = f->getName(); 756 name = f->name();
765 757
766 name.replace ("\\", "/"); 758 name.replace ("\\", "/");
767 path = QFileDialog::getSaveFileName (g_win, tr ("Save As"), 759 path = QFileDialog::getSaveFileName (g_win, tr ("Save As"),
768 name, tr ("LDraw files (*.dat *.ldr)")); 760 name, tr ("LDraw files (*.dat *.ldr)"));
769 761
870 // ============================================================================= 862 // =============================================================================
871 void makeColorComboBox (QComboBox* box) 863 void makeColorComboBox (QComboBox* box)
872 { 864 {
873 std::map<int, int> counts; 865 std::map<int, int> counts;
874 866
875 for (LDObject* obj : getCurrentDocument()->getObjects()) 867 for (LDObject* obj : getCurrentDocument()->objects())
876 { 868 {
877 if (!obj->isColored()) 869 if (!obj->isColored())
878 continue; 870 continue;
879 871
880 if (counts.find (obj->getColor()) == counts.end()) 872 if (counts.find (obj->color()) == counts.end())
881 counts[obj->getColor()] = 1; 873 counts[obj->color()] = 1;
882 else 874 else
883 counts[obj->getColor()]++; 875 counts[obj->color()]++;
884 } 876 }
885 877
886 box->clear(); 878 box->clear();
887 int row = 0; 879 int row = 0;
888 880
925 void MainWindow::updateDocumentListItem (LDDocument* f) 917 void MainWindow::updateDocumentListItem (LDDocument* f)
926 { 918 {
927 bool oldUpdatingTabs = m_updatingTabs; 919 bool oldUpdatingTabs = m_updatingTabs;
928 m_updatingTabs = true; 920 m_updatingTabs = true;
929 921
930 if (f->getTabIndex() == -1) 922 if (f->tabIndex() == -1)
931 { 923 {
932 // We don't have a list item for this file, so the list either doesn't 924 // We don't have a list item for this file, so the list either doesn't
933 // exist yet or is out of date. Build the list now. 925 // exist yet or is out of date. Build the list now.
934 updateDocumentList(); 926 updateDocumentList();
935 return; 927 return;
936 } 928 }
937 929
938 // If this is the current file, it also needs to be the selected item on 930 // If this is the current file, it also needs to be the selected item on
939 // the list. 931 // the list.
940 if (f == getCurrentDocument()) 932 if (f == getCurrentDocument())
941 m_tabs->setCurrentIndex (f->getTabIndex()); 933 m_tabs->setCurrentIndex (f->tabIndex());
942 934
943 m_tabs->setTabText (f->getTabIndex(), f->getDisplayName()); 935 m_tabs->setTabText (f->tabIndex(), f->getDisplayName());
944 936
945 // If the document.has unsaved changes, draw a little icon next to it to mark that. 937 // If the document.has unsaved changes, draw a little icon next to it to mark that.
946 m_tabs->setTabIcon (f->getTabIndex(), f->hasUnsavedChanges() ? getIcon ("file-save") : QIcon()); 938 m_tabs->setTabIcon (f->tabIndex(), f->hasUnsavedChanges() ? getIcon ("file-save") : QIcon());
947 m_updatingTabs = oldUpdatingTabs; 939 m_updatingTabs = oldUpdatingTabs;
948 } 940 }
949 941
950 // ============================================================================= 942 // =============================================================================
951 // A file is selected from the list of files on the left of the screen. Find out 943 // A file is selected from the list of files on the left of the screen. Find out
959 int tabIndex = m_tabs->currentIndex(); 951 int tabIndex = m_tabs->currentIndex();
960 952
961 // Find the file pointer of the item that was selected. 953 // Find the file pointer of the item that was selected.
962 for (LDDocument* it : g_loadedFiles) 954 for (LDDocument* it : g_loadedFiles)
963 { 955 {
964 if (it->getTabIndex() == tabIndex) 956 if (it->tabIndex() == tabIndex)
965 { 957 {
966 f = it; 958 f = it;
967 break; 959 break;
968 } 960 }
969 } 961 }
990 buildObjList(); 982 buildObjList();
991 } 983 }
992 984
993 void MainWindow::updateActions() 985 void MainWindow::updateActions()
994 { 986 {
995 History* his = getCurrentDocument()->getHistory(); 987 History* his = getCurrentDocument()->history();
996 int pos = his->getPosition(); 988 int pos = his->position();
997 ui->actionUndo->setEnabled (pos != -1); 989 ui->actionUndo->setEnabled (pos != -1);
998 ui->actionRedo->setEnabled (pos < (long) his->getSize() - 1); 990 ui->actionRedo->setEnabled (pos < (long) his->getSize() - 1);
999 ui->actionAxes->setChecked (gl_axes); 991 ui->actionAxes->setChecked (gl_axes);
1000 ui->actionBFCView->setChecked (gl_colorbfc); 992 ui->actionBFCView->setChecked (gl_colorbfc);
1001 ui->actionDrawAngles->setChecked (gl_drawangles); 993 ui->actionDrawAngles->setChecked (gl_drawangles);
1008 } 1000 }
1009 1001
1010 // ============================================================================= 1002 // =============================================================================
1011 // 1003 //
1012 LDQuickColor::LDQuickColor (LDColor* color, QToolButton* toolButton) : 1004 LDQuickColor::LDQuickColor (LDColor* color, QToolButton* toolButton) :
1013 m_Color (color), 1005 m_color (color),
1014 m_ToolButton (toolButton) {} 1006 m_toolButton (toolButton) {}
1015 1007
1016 LDQuickColor LDQuickColor::getSeparator() 1008 LDQuickColor LDQuickColor::getSeparator()
1017 { 1009 {
1018 return LDQuickColor (null, null); 1010 return LDQuickColor (null, null);
1019 } 1011 }
1020 1012
1021 bool LDQuickColor::isSeparator() const 1013 bool LDQuickColor::isSeparator() const
1022 { 1014 {
1023 return getColor() == null; 1015 return color() == null;
1024 } 1016 }

mercurial