src/gui.cpp

changeset 409
8da2563c645a
parent 402
ec95fc95e5f3
child 410
a5aebcf4a1c8
equal deleted inserted replaced
408:81dc5f6b9c73 409:8da2563c645a
222 // ============================================================================= 222 // =============================================================================
223 void ForgeWindow::updateTitle() { 223 void ForgeWindow::updateTitle() {
224 str title = fmt (APPNAME " %1", fullVersionString()); 224 str title = fmt (APPNAME " %1", fullVersionString());
225 225
226 // Append our current file if we have one 226 // Append our current file if we have one
227 if (LDOpenFile::current()) { 227 if (LDFile::current()) {
228 if (LDOpenFile::current()->name().length() > 0) 228 if (LDFile::current()->name().length() > 0)
229 title += fmt (": %1", basename (LDOpenFile::current()->name())); 229 title += fmt (": %1", basename (LDFile::current()->name()));
230 else 230 else
231 title += fmt (": <anonymous>"); 231 title += fmt (": <anonymous>");
232 232
233 if (LDOpenFile::current()->numObjs() > 0 && 233 if (LDFile::current()->numObjs() > 0 &&
234 LDOpenFile::current()->obj (0)->getType() == LDObject::Comment) 234 LDFile::current()->obj (0)->getType() == LDObject::Comment)
235 { 235 {
236 // Append title 236 // Append title
237 LDCommentObject* comm = static_cast<LDCommentObject*> (LDOpenFile::current()->obj (0)); 237 LDCommentObject* comm = static_cast<LDCommentObject*> (LDFile::current()->obj (0));
238 title += fmt (": %1", comm->text); 238 title += fmt (": %1", comm->text);
239 } 239 }
240 240
241 if (LDOpenFile::current()->history().pos() != LDOpenFile::current()->savePos()) 241 if (LDFile::current()->history().pos() != LDFile::current()->savePos())
242 title += '*'; 242 title += '*';
243 } 243 }
244 244
245 setWindowTitle (title); 245 setWindowTitle (title);
246 } 246 }
256 List<LDObject*> selCopy = m_sel; 256 List<LDObject*> selCopy = m_sel;
257 int num = 0; 257 int num = 0;
258 258
259 // Delete the objects that were being selected 259 // Delete the objects that were being selected
260 for (LDObject* obj : selCopy) { 260 for (LDObject* obj : selCopy) {
261 LDOpenFile::current()->forgetObject (obj); 261 LDFile::current()->forgetObject (obj);
262 ++num; 262 ++num;
263 delete obj; 263 delete obj;
264 } 264 }
265 265
266 refresh(); 266 refresh();
269 269
270 // ============================================================================= 270 // =============================================================================
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
272 // ============================================================================= 272 // =============================================================================
273 void ForgeWindow::buildObjList() { 273 void ForgeWindow::buildObjList() {
274 if (!LDOpenFile::current()) 274 if (!LDFile::current())
275 return; 275 return;
276 276
277 // Lock the selection while we do this so that refreshing the object list 277 // Lock the selection while we do this so that refreshing the object list
278 // doesn't trigger selection updating so that the selection doesn't get lost 278 // doesn't trigger selection updating so that the selection doesn't get lost
279 // while this is done. 279 // while this is done.
282 for (int i = 0; i < ui->objectList->count(); ++i) 282 for (int i = 0; i < ui->objectList->count(); ++i)
283 delete ui->objectList->item (i); 283 delete ui->objectList->item (i);
284 284
285 ui->objectList->clear(); 285 ui->objectList->clear();
286 286
287 for (LDObject* obj : LDOpenFile::current()->objs()) { 287 for (LDObject* obj : LDFile::current()->objs()) {
288 str descr; 288 str descr;
289 289
290 switch (obj->getType()) { 290 switch (obj->getType()) {
291 case LDObject::Comment: 291 case LDObject::Comment:
292 descr = static_cast<LDCommentObject*> (obj)->text; 292 descr = static_cast<LDCommentObject*> (obj)->text;
395 395
396 // ============================================================================= 396 // =============================================================================
397 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 397 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
398 // ============================================================================= 398 // =============================================================================
399 void ForgeWindow::slot_selectionChanged() { 399 void ForgeWindow::slot_selectionChanged() {
400 if (g_bSelectionLocked == true || LDOpenFile::current() == null) 400 if (g_bSelectionLocked == true || LDFile::current() == null)
401 return; 401 return;
402 402
403 // Update the shared selection array, though don't do this if this was 403 // Update the shared selection array, though don't do this if this was
404 // called during GL picking, in which case the GL renderer takes care 404 // called during GL picking, in which case the GL renderer takes care
405 // of the selection. 405 // of the selection.
410 410
411 // Get the objects from the object list selection 411 // Get the objects from the object list selection
412 m_sel.clear(); 412 m_sel.clear();
413 const QList<QListWidgetItem*> items = ui->objectList->selectedItems(); 413 const QList<QListWidgetItem*> items = ui->objectList->selectedItems();
414 414
415 for (LDObject* obj : LDOpenFile::current()->objs()) 415 for (LDObject* obj : LDFile::current()->objs())
416 for (QListWidgetItem* item : items) { 416 for (QListWidgetItem* item : items) {
417 if (item == obj->qObjListEntry) { 417 if (item == obj->qObjListEntry) {
418 m_sel << obj; 418 m_sel << obj;
419 break; 419 break;
420 } 420 }
479 // If we have a selection, put the item after it. 479 // If we have a selection, put the item after it.
480 return (m_sel[m_sel.size() - 1]->getIndex()) + 1; 480 return (m_sel[m_sel.size() - 1]->getIndex()) + 1;
481 } 481 }
482 482
483 // Otherwise place the object at the end. 483 // Otherwise place the object at the end.
484 return LDOpenFile::current()->numObjs(); 484 return LDFile::current()->numObjs();
485 } 485 }
486 486
487 // ============================================================================= 487 // =============================================================================
488 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 488 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
489 // ============================================================================= 489 // =============================================================================
501 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 501 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
502 // ============================================================================= 502 // =============================================================================
503 void ForgeWindow::updateSelection() { 503 void ForgeWindow::updateSelection() {
504 g_bSelectionLocked = true; 504 g_bSelectionLocked = true;
505 505
506 for (LDObject* obj : LDOpenFile::current()->objs()) 506 for (LDObject* obj : LDFile::current()->objs())
507 obj->setSelected (false); 507 obj->setSelected (false);
508 508
509 ui->objectList->clearSelection(); 509 ui->objectList->clearSelection();
510 for (LDObject* obj : m_sel) { 510 for (LDObject* obj : m_sel) {
511 if( obj->qObjListEntry == null ) 511 if( obj->qObjListEntry == null )
622 } 622 }
623 623
624 // ============================================================================= 624 // =============================================================================
625 void ForgeWindow::deleteObjVector (List<LDObject*> objs) { 625 void ForgeWindow::deleteObjVector (List<LDObject*> objs) {
626 for (LDObject* obj : objs) { 626 for (LDObject* obj : objs) {
627 LDOpenFile::current()->forgetObject (obj); 627 LDFile::current()->forgetObject (obj);
628 delete obj; 628 delete obj;
629 } 629 }
630 } 630 }
631 631
632 // ============================================================================= 632 // =============================================================================
633 void ForgeWindow::deleteByColor (const short colnum) { 633 void ForgeWindow::deleteByColor (const short colnum) {
634 List<LDObject*> objs; 634 List<LDObject*> objs;
635 for (LDObject* obj : LDOpenFile::current()->objs()) { 635 for (LDObject* obj : LDFile::current()->objs()) {
636 if (!obj->isColored() || obj->color() != colnum) 636 if (!obj->isColored() || obj->color() != colnum)
637 continue; 637 continue;
638 638
639 objs << obj; 639 objs << obj;
640 } 640 }
649 ACTION (ModeDraw)->setChecked (mode == Draw); 649 ACTION (ModeDraw)->setChecked (mode == Draw);
650 } 650 }
651 651
652 void ForgeWindow::slot_editObject (QListWidgetItem* listitem) { 652 void ForgeWindow::slot_editObject (QListWidgetItem* listitem) {
653 LDObject* obj = null; 653 LDObject* obj = null;
654 for (LDObject* it : *LDOpenFile::current()) { 654 for (LDObject* it : *LDFile::current()) {
655 if (it->qObjListEntry == listitem) { 655 if (it->qObjListEntry == listitem) {
656 obj = it; 656 obj = it;
657 break; 657 break;
658 } 658 }
659 } 659 }
682 } 682 }
683 683
684 // ============================================================================= 684 // =============================================================================
685 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 685 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
686 // ============================================================================= 686 // =============================================================================
687 void ForgeWindow::save (LDOpenFile* f, bool saveAs) { 687 void ForgeWindow::save (LDFile* f, bool saveAs) {
688 str path = f->name(); 688 str path = f->name();
689 689
690 if (path.length() == 0 || saveAs) { 690 if (path.length() == 0 || saveAs) {
691 path = QFileDialog::getSaveFileName (g_win, tr ("Save As"), 691 path = QFileDialog::getSaveFileName (g_win, tr ("Save As"),
692 LDOpenFile::current()->name(), tr ("LDraw files (*.dat *.ldr)")); 692 LDFile::current()->name(), tr ("LDraw files (*.dat *.ldr)"));
693 693
694 if (path.length() == 0) { 694 if (path.length() == 0) {
695 // User didn't give a file name. This happens if the user cancelled 695 // User didn't give a file name. This happens if the user cancelled
696 // saving in the save file dialog. Abort. 696 // saving in the save file dialog. Abort.
697 return; 697 return;
699 } 699 }
700 700
701 if (f->save (path)) { 701 if (f->save (path)) {
702 f->setName (path); 702 f->setName (path);
703 703
704 if (f == LDOpenFile::current()) 704 if (f == LDFile::current())
705 g_win->updateTitle(); 705 g_win->updateTitle();
706 706
707 log ("Saved to %1.", path); 707 log ("Saved to %1.", path);
708 708
709 // Add it to recent files 709 // Add it to recent files
780 780
781 // ============================================================================= 781 // =============================================================================
782 void makeColorSelector (QComboBox* box) { 782 void makeColorSelector (QComboBox* box) {
783 std::map<short, ulong> counts; 783 std::map<short, ulong> counts;
784 784
785 for (LDObject* obj : LDOpenFile::current()->objs()) { 785 for (LDObject* obj : LDFile::current()->objs()) {
786 if (!obj->isColored()) 786 if (!obj->isColored())
787 continue; 787 continue;
788 788
789 if (counts.find (obj->color()) == counts.end()) 789 if (counts.find (obj->color()) == counts.end())
790 counts[obj->color()] = 1; 790 counts[obj->color()] = 1;
823 #include "actions.h" 823 #include "actions.h"
824 824
825 void ForgeWindow::updateFileList() { 825 void ForgeWindow::updateFileList() {
826 ui->fileList->clear(); 826 ui->fileList->clear();
827 827
828 for (LDOpenFile* f : g_loadedFiles) { 828 for (LDFile* f : g_loadedFiles) {
829 /* 829 /*
830 if (f->implicit()) 830 if (f->implicit())
831 continue; 831 continue;
832 */ 832 */
833 833
837 837
838 updateFileListItem (f); 838 updateFileListItem (f);
839 } 839 }
840 } 840 }
841 841
842 void ForgeWindow::updateFileListItem (LDOpenFile* f) { 842 void ForgeWindow::updateFileListItem (LDFile* f) {
843 if (f->listItem() == null) { 843 if (f->listItem() == null) {
844 // We don't have a list item for this file, so the list 844 // We don't have a list item for this file, so the list
845 // doesn't exist yet. Create it - afterwards this will be 845 // doesn't exist yet. Create it - afterwards this will be
846 // up to date. 846 // up to date.
847 updateFileList(); 847 updateFileList();
852 if (f->name() == "") 852 if (f->name() == "")
853 name = "<anonymous>"; 853 name = "<anonymous>";
854 else 854 else
855 name = basename (f->name()); 855 name = basename (f->name());
856 856
857 if (f == LDOpenFile::current()) 857 if (f == LDFile::current())
858 ui->fileList->setCurrentItem (f->listItem()); 858 ui->fileList->setCurrentItem (f->listItem());
859 859
860 if (f->implicit()) 860 if (f->implicit())
861 f->listItem()->setForeground (QColor (96, 96, 96)); 861 f->listItem()->setForeground (QColor (96, 96, 96));
862 862
865 } 865 }
866 866
867 void ForgeWindow::beginAction (QAction* act) { 867 void ForgeWindow::beginAction (QAction* act) {
868 // Open the history so we can record the edits done during this action. 868 // Open the history so we can record the edits done during this action.
869 if (act != ACTION (Undo) && act != ACTION (Redo) && act != ACTION (Open)) 869 if (act != ACTION (Undo) && act != ACTION (Redo) && act != ACTION (Open))
870 LDOpenFile::current()->openHistory(); 870 LDFile::current()->openHistory();
871 } 871 }
872 872
873 void ForgeWindow::endAction() { 873 void ForgeWindow::endAction() {
874 // Close the history now. 874 // Close the history now.
875 LDOpenFile::current()->closeHistory(); 875 LDFile::current()->closeHistory();
876 updateFileListItem (LDOpenFile::current()); 876 updateFileListItem (LDFile::current());
877 } 877 }
878 878
879 void ForgeWindow::changeCurrentFile() { 879 void ForgeWindow::changeCurrentFile() {
880 LDOpenFile* f = null; 880 LDFile* f = null;
881 QListWidgetItem* item = ui->fileList->currentItem(); 881 QListWidgetItem* item = ui->fileList->currentItem();
882 882
883 for (LDOpenFile* it : g_loadedFiles) { 883 for (LDFile* it : g_loadedFiles) {
884 if (it->listItem() == item) { 884 if (it->listItem() == item) {
885 f = it; 885 f = it;
886 break; 886 break;
887 } 887 }
888 } 888 }
889 889
890 if (!f || f == LDOpenFile::current()) 890 if (!f || f == LDFile::current())
891 return; 891 return;
892 892
893 clearSelection(); 893 clearSelection();
894 LDOpenFile::setCurrent (f); 894 LDFile::setCurrent (f);
895 895
896 log ("Changed file to %1", basename (f->name())); 896 log ("Changed file to %1", basename (f->name()));
897 897
898 R()->setFile (f); 898 R()->setFile (f);
899 R()->update(); 899 R()->update();
901 } 901 }
902 902
903 void ForgeWindow::refreshObjectList() { 903 void ForgeWindow::refreshObjectList() {
904 #if 0 904 #if 0
905 ui->objectList->clear(); 905 ui->objectList->clear();
906 LDOpenFile* f = LDOpenFile::current(); 906 LDFile* f = LDFile::current();
907 907
908 for (LDObject* obj : *f) 908 for (LDObject* obj : *f)
909 ui->objectList->addItem (obj->qObjListEntry); 909 ui->objectList->addItem (obj->qObjListEntry);
910 #endif 910 #endif
911 911

mercurial