1 /* |
1 /* |
2 * LDForge: LDraw parts authoring CAD |
2 * LDForge: LDraw parts authoring CAD |
3 * Copyright (C) 2013 Santeri Piippo |
3 * Copyright (C) 2013 Santeri Piippo |
4 * |
4 * |
5 * This program is free software: you can redistribute it and/or modify |
5 * This program is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License as published by |
6 * it under the terms of the GNU General Public License as published by |
7 * the Free Software Foundation, either version 3 of the License, or |
7 * the Free Software Foundation, either version 3 of the License, or |
8 * (at your option) any later version. |
8 * (at your option) any later version. |
9 * |
9 * |
10 * This program is distributed in the hope that it will be useful, |
10 * This program is distributed in the hope that it will be useful, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 * GNU General Public License for more details. |
13 * GNU General Public License for more details. |
14 * |
14 * |
15 * You should have received a copy of the GNU General Public License |
15 * You should have received a copy of the GNU General Public License |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 */ |
17 */ |
18 |
18 |
19 #include <QGridLayout> |
19 #include <QGridLayout> |
123 connect (ui->action##N, SIGNAL (triggered()), this, SLOT (slot_action())); \ |
122 connect (ui->action##N, SIGNAL (triggered()), this, SLOT (slot_action())); \ |
124 ui->action##N->setShortcut (key_##N); |
123 ui->action##N->setShortcut (key_##N); |
125 #include "actions.h" |
124 #include "actions.h" |
126 } |
125 } |
127 |
126 |
|
127 // ============================================================================= |
|
128 // ----------------------------------------------------------------------------- |
128 void ForgeWindow::slot_action() { |
129 void ForgeWindow::slot_action() { |
129 // Find out which action triggered this |
130 // Find out which action triggered this |
130 #define act(N) if (sender() == ui->action##N) invokeAction (ui->action##N, &actiondef_##N); |
131 #define act(N) if (sender() == ui->action##N) invokeAction (ui->action##N, &actiondef_##N); |
131 #include "actions.h" |
132 #include "actions.h" |
132 } |
133 } |
133 |
134 |
|
135 // ============================================================================= |
|
136 // ----------------------------------------------------------------------------- |
134 void ForgeWindow::invokeAction (QAction* act, void (*func)()) { |
137 void ForgeWindow::invokeAction (QAction* act, void (*func)()) { |
135 beginAction (act); |
138 beginAction (act); |
136 (*func)(); |
139 (*func)(); |
137 endAction(); |
140 endAction(); |
138 } |
141 } |
139 |
142 |
140 // ============================================================================= |
143 // ============================================================================= |
|
144 // ----------------------------------------------------------------------------- |
141 void ForgeWindow::slot_lastSecondCleanup() { |
145 void ForgeWindow::slot_lastSecondCleanup() { |
142 delete m_renderer; |
146 delete m_renderer; |
143 delete ui; |
147 delete ui; |
144 } |
148 } |
145 |
149 |
146 // ============================================================================= |
150 // ============================================================================= |
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
151 // ----------------------------------------------------------------------------- |
148 // ============================================================================= |
|
149 void ForgeWindow::updateRecentFilesMenu() { |
152 void ForgeWindow::updateRecentFilesMenu() { |
150 QStringList files = io_recentfiles.value.split ("@", QString::SkipEmptyParts); |
153 QStringList files = io_recentfiles.value.split ("@", QString::SkipEmptyParts); |
151 QStringListIterator it (files); |
154 QStringListIterator it (files); |
152 |
155 |
153 // First, clear any items in the recent files menu |
156 // First, clear any items in the recent files menu |
165 m_recentFiles << recent; |
168 m_recentFiles << recent; |
166 } |
169 } |
167 } |
170 } |
168 |
171 |
169 // ============================================================================= |
172 // ============================================================================= |
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
173 // ----------------------------------------------------------------------------- |
171 // ============================================================================= |
|
172 List<LDQuickColor> quickColorsFromConfig() { |
174 List<LDQuickColor> quickColorsFromConfig() { |
173 List<LDQuickColor> colors; |
175 List<LDQuickColor> colors; |
174 |
176 |
175 for (str colorname : gui_colortoolbar.value.split (":")) { |
177 for (str colorname : gui_colortoolbar.value.split (":")) { |
176 if (colorname == "|") { |
178 if (colorname == "|") { |
184 |
186 |
185 return colors; |
187 return colors; |
186 } |
188 } |
187 |
189 |
188 // ============================================================================= |
190 // ============================================================================= |
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
191 // ----------------------------------------------------------------------------- |
190 // ============================================================================= |
|
191 void ForgeWindow::updateToolBars() { |
192 void ForgeWindow::updateToolBars() { |
192 m_colorButtons.clear(); |
193 m_colorButtons.clear(); |
193 ui->colorToolbar->clear(); |
194 ui->colorToolbar->clear(); |
194 |
195 |
195 for (LDQuickColor& entry : m_quickColors) { |
196 for (LDQuickColor& entry : m_quickColors) { |
211 |
212 |
212 updateGridToolBar(); |
213 updateGridToolBar(); |
213 } |
214 } |
214 |
215 |
215 // ============================================================================= |
216 // ============================================================================= |
216 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
217 // ----------------------------------------------------------------------------- |
217 // ============================================================================= |
|
218 void ForgeWindow::updateGridToolBar() { |
218 void ForgeWindow::updateGridToolBar() { |
219 // Ensure that the current grid - and only the current grid - is selected. |
219 // Ensure that the current grid - and only the current grid - is selected. |
220 ui->actionGridCoarse->setChecked (grid == Grid::Coarse); |
220 ui->actionGridCoarse->setChecked (grid == Grid::Coarse); |
221 ui->actionGridMedium->setChecked (grid == Grid::Medium); |
221 ui->actionGridMedium->setChecked (grid == Grid::Medium); |
222 ui->actionGridFine->setChecked (grid == Grid::Fine); |
222 ui->actionGridFine->setChecked (grid == Grid::Fine); |
223 } |
223 } |
224 |
224 |
225 // ============================================================================= |
225 // ============================================================================= |
226 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
226 // ----------------------------------------------------------------------------- |
227 // ============================================================================= |
|
228 void ForgeWindow::updateTitle() { |
227 void ForgeWindow::updateTitle() { |
229 str title = fmt (APPNAME " %1", fullVersionString()); |
228 str title = fmt (APPNAME " %1", fullVersionString()); |
230 |
229 |
231 // Append our current file if we have one |
230 // Append our current file if we have one |
232 if (LDFile::current()) { |
231 if (LDFile::current()) { |
249 |
248 |
250 setWindowTitle (title); |
249 setWindowTitle (title); |
251 } |
250 } |
252 |
251 |
253 // ============================================================================= |
252 // ============================================================================= |
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
253 // ----------------------------------------------------------------------------- |
255 // ============================================================================= |
254 int ForgeWindow::deleteSelection() { |
256 int ForgeWindow::deleteSelection() |
|
257 { |
|
258 if (m_sel.size() == 0) |
255 if (m_sel.size() == 0) |
259 return 0; |
256 return 0; |
260 |
257 |
261 List<LDObject*> selCopy = m_sel; |
258 List<LDObject*> selCopy = m_sel; |
262 int num = 0; |
259 int num = 0; |
271 refresh(); |
268 refresh(); |
272 return num; |
269 return num; |
273 } |
270 } |
274 |
271 |
275 // ============================================================================= |
272 // ============================================================================= |
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
273 // ----------------------------------------------------------------------------- |
277 // ============================================================================= |
|
278 void ForgeWindow::buildObjList() { |
274 void ForgeWindow::buildObjList() { |
279 if (!LDFile::current()) |
275 if (!LDFile::current()) |
280 return; |
276 return; |
281 |
277 |
282 // Lock the selection while we do this so that refreshing the object list |
278 // Lock the selection while we do this so that refreshing the object list |
355 descr = obj->typeName(); |
351 descr = obj->typeName(); |
356 break; |
352 break; |
357 } |
353 } |
358 |
354 |
359 // Put it into brackets if it's hidden |
355 // Put it into brackets if it's hidden |
360 if (obj->hidden()) { |
356 if (obj->hidden()) |
361 descr = fmt ("[[ %1 ]]", descr); |
357 descr = fmt ("[[ %1 ]]", descr); |
362 } |
|
363 |
358 |
364 QListWidgetItem* item = new QListWidgetItem (descr); |
359 QListWidgetItem* item = new QListWidgetItem (descr); |
365 item->setIcon (getIcon (obj->typeName())); |
360 item->setIcon (getIcon (obj->typeName())); |
366 |
361 |
367 // Color gibberish orange on red so it stands out. |
362 // Color gibberish orange on red so it stands out. |
386 updateSelection(); |
381 updateSelection(); |
387 scrollToSelection(); |
382 scrollToSelection(); |
388 } |
383 } |
389 |
384 |
390 // ============================================================================= |
385 // ============================================================================= |
391 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
386 // ----------------------------------------------------------------------------- |
392 // ============================================================================= |
|
393 void ForgeWindow::scrollToSelection() { |
387 void ForgeWindow::scrollToSelection() { |
394 if (m_sel.size() == 0) |
388 if (m_sel.size() == 0) |
395 return; |
389 return; |
396 |
390 |
397 LDObject* obj = m_sel[m_sel.size() - 1]; |
391 LDObject* obj = m_sel[m_sel.size() - 1]; |
398 ui->objectList->scrollToItem (obj->qObjListEntry); |
392 ui->objectList->scrollToItem (obj->qObjListEntry); |
399 } |
393 } |
400 |
394 |
401 // ============================================================================= |
395 // ============================================================================= |
402 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
396 // ----------------------------------------------------------------------------- |
403 // ============================================================================= |
|
404 void ForgeWindow::slot_selectionChanged() { |
397 void ForgeWindow::slot_selectionChanged() { |
405 if (g_bSelectionLocked == true || LDFile::current() == null) |
398 if (g_bSelectionLocked == true || LDFile::current() == null) |
406 return; |
399 return; |
407 |
400 |
408 // Update the shared selection array, though don't do this if this was |
401 // Update the shared selection array, though don't do this if this was |
438 |
431 |
439 m_renderer->update(); |
432 m_renderer->update(); |
440 } |
433 } |
441 |
434 |
442 // ============================================================================= |
435 // ============================================================================= |
|
436 // ----------------------------------------------------------------------------- |
443 void ForgeWindow::slot_recentFile() { |
437 void ForgeWindow::slot_recentFile() { |
444 QAction* qAct = static_cast<QAction*> (sender()); |
438 QAction* qAct = static_cast<QAction*> (sender()); |
445 openMainFile (qAct->text()); |
439 openMainFile (qAct->text()); |
446 } |
440 } |
447 |
441 |
448 // ============================================================================= |
442 // ============================================================================= |
449 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
443 // ----------------------------------------------------------------------------- |
450 // ============================================================================= |
|
451 void ForgeWindow::slot_quickColor() { |
444 void ForgeWindow::slot_quickColor() { |
452 beginAction (null); |
445 beginAction (null); |
453 QToolButton* button = static_cast<QToolButton*> (sender()); |
446 QToolButton* button = static_cast<QToolButton*> (sender()); |
454 LDColor* col = null; |
447 LDColor* col = null; |
455 |
448 |
476 refresh(); |
469 refresh(); |
477 endAction(); |
470 endAction(); |
478 } |
471 } |
479 |
472 |
480 // ============================================================================= |
473 // ============================================================================= |
481 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
474 // ----------------------------------------------------------------------------- |
482 // ============================================================================= |
|
483 ulong ForgeWindow::getInsertionPoint() { |
475 ulong ForgeWindow::getInsertionPoint() { |
484 if (m_sel.size() > 0) { |
476 if (m_sel.size() > 0) { |
485 // If we have a selection, put the item after it. |
477 // If we have a selection, put the item after it. |
486 return (m_sel[m_sel.size() - 1]->getIndex()) + 1; |
478 return (m_sel[m_sel.size() - 1]->getIndex()) + 1; |
487 } |
479 } |
489 // Otherwise place the object at the end. |
481 // Otherwise place the object at the end. |
490 return LDFile::current()->numObjs(); |
482 return LDFile::current()->numObjs(); |
491 } |
483 } |
492 |
484 |
493 // ============================================================================= |
485 // ============================================================================= |
494 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
486 // ----------------------------------------------------------------------------- |
495 // ============================================================================= |
|
496 void ForgeWindow::fullRefresh() { |
487 void ForgeWindow::fullRefresh() { |
497 buildObjList(); |
488 buildObjList(); |
498 m_renderer->hardRefresh(); |
489 m_renderer->hardRefresh(); |
499 } |
490 } |
500 |
491 |
502 buildObjList(); |
493 buildObjList(); |
503 m_renderer->update(); |
494 m_renderer->update(); |
504 } |
495 } |
505 |
496 |
506 // ============================================================================= |
497 // ============================================================================= |
507 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
498 // ----------------------------------------------------------------------------- |
508 // ============================================================================= |
|
509 void ForgeWindow::updateSelection() { |
499 void ForgeWindow::updateSelection() { |
510 g_bSelectionLocked = true; |
500 g_bSelectionLocked = true; |
511 |
501 |
512 for (LDObject* obj : LDFile::current()->objs()) |
502 for (LDObject* obj : LDFile::current()->objs()) |
513 obj->setSelected (false); |
503 obj->setSelected (false); |
524 g_bSelectionLocked = false; |
514 g_bSelectionLocked = false; |
525 slot_selectionChanged(); |
515 slot_selectionChanged(); |
526 } |
516 } |
527 |
517 |
528 // ============================================================================= |
518 // ============================================================================= |
529 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
519 // ----------------------------------------------------------------------------- |
530 // ============================================================================= |
|
531 bool ForgeWindow::isSelected (LDObject* obj) { |
520 bool ForgeWindow::isSelected (LDObject* obj) { |
532 LDObject* needle = obj->topLevelParent(); |
521 LDObject* needle = obj->topLevelParent(); |
533 |
522 |
534 for (LDObject* hay : m_sel) |
523 for (LDObject* hay : m_sel) |
535 if (hay == needle) |
524 if (hay == needle) |
554 |
543 |
555 return result; |
544 return result; |
556 } |
545 } |
557 |
546 |
558 // ============================================================================= |
547 // ============================================================================= |
559 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
548 // ----------------------------------------------------------------------------- |
560 // ============================================================================= |
|
561 LDObject::Type ForgeWindow::uniformSelectedType() { |
549 LDObject::Type ForgeWindow::uniformSelectedType() { |
562 LDObject::Type result = LDObject::Unidentified; |
550 LDObject::Type result = LDObject::Unidentified; |
563 |
551 |
564 for (LDObject* obj : m_sel) { |
552 for (LDObject* obj : m_sel) { |
565 if (result != LDObject::Unidentified && obj->color() != result) |
553 if (result != LDObject::Unidentified && obj->color() != result) |
588 |
575 |
589 ev->accept(); |
576 ev->accept(); |
590 } |
577 } |
591 |
578 |
592 // ============================================================================= |
579 // ============================================================================= |
593 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
580 // ----------------------------------------------------------------------------- |
594 // ============================================================================= |
|
595 void ForgeWindow::spawnContextMenu (const QPoint pos) { |
581 void ForgeWindow::spawnContextMenu (const QPoint pos) { |
596 const bool single = (g_win->sel().size() == 1); |
582 const bool single = (g_win->sel().size() == 1); |
597 LDObject* singleObj = (single) ? g_win->sel()[0] : null; |
583 LDObject* singleObj = (single) ? g_win->sel()[0] : null; |
598 |
584 |
599 QMenu* contextMenu = new QMenu; |
585 QMenu* contextMenu = new QMenu; |
626 |
612 |
627 contextMenu->exec (pos); |
613 contextMenu->exec (pos); |
628 } |
614 } |
629 |
615 |
630 // ============================================================================= |
616 // ============================================================================= |
|
617 // ----------------------------------------------------------------------------- |
631 void ForgeWindow::deleteObjVector (List<LDObject*> objs) { |
618 void ForgeWindow::deleteObjVector (List<LDObject*> objs) { |
632 for (LDObject* obj : objs) { |
619 for (LDObject* obj : objs) { |
633 LDFile::current()->forgetObject (obj); |
620 LDFile::current()->forgetObject (obj); |
634 delete obj; |
621 delete obj; |
635 } |
622 } |
636 } |
623 } |
637 |
624 |
638 // ============================================================================= |
625 // ============================================================================= |
|
626 // ----------------------------------------------------------------------------- |
639 void ForgeWindow::deleteByColor (const short colnum) { |
627 void ForgeWindow::deleteByColor (const short colnum) { |
640 List<LDObject*> objs; |
628 List<LDObject*> objs; |
641 for (LDObject* obj : LDFile::current()->objs()) { |
629 for (LDObject* obj : LDFile::current()->objs()) { |
642 if (!obj->isColored() || obj->color() != colnum) |
630 if (!obj->isColored() || obj->color() != colnum) |
643 continue; |
631 continue; |
647 |
635 |
648 deleteObjVector (objs); |
636 deleteObjVector (objs); |
649 } |
637 } |
650 |
638 |
651 // ============================================================================= |
639 // ============================================================================= |
|
640 // ----------------------------------------------------------------------------- |
652 void ForgeWindow::updateEditModeActions() { |
641 void ForgeWindow::updateEditModeActions() { |
653 const EditMode mode = R()->editMode(); |
642 const EditMode mode = R()->editMode(); |
654 ACTION (ModeSelect)->setChecked (mode == Select); |
643 ACTION (ModeSelect)->setChecked (mode == Select); |
655 ACTION (ModeDraw)->setChecked (mode == Draw); |
644 ACTION (ModeDraw)->setChecked (mode == Draw); |
656 } |
645 } |
657 |
646 |
|
647 // ============================================================================= |
|
648 // ----------------------------------------------------------------------------- |
658 void ForgeWindow::slot_editObject (QListWidgetItem* listitem) { |
649 void ForgeWindow::slot_editObject (QListWidgetItem* listitem) { |
659 LDObject* obj = null; |
650 LDObject* obj = null; |
660 for (LDObject* it : *LDFile::current()) { |
651 for (LDObject* it : *LDFile::current()) { |
661 if (it->qObjListEntry == listitem) { |
652 if (it->qObjListEntry == listitem) { |
662 obj = it; |
653 obj = it; |
665 } |
656 } |
666 |
657 |
667 AddObjectDialog::staticDialog (obj->getType(), obj); |
658 AddObjectDialog::staticDialog (obj->getType(), obj); |
668 } |
659 } |
669 |
660 |
|
661 // ============================================================================= |
|
662 // ----------------------------------------------------------------------------- |
670 void ForgeWindow::primitiveLoaderStart (ulong max) { |
663 void ForgeWindow::primitiveLoaderStart (ulong max) { |
671 m_primLoaderWidget->show(); |
664 m_primLoaderWidget->show(); |
672 m_primLoaderBar->setRange (0, max); |
665 m_primLoaderBar->setRange (0, max); |
673 m_primLoaderBar->setValue (0); |
666 m_primLoaderBar->setValue (0); |
674 m_primLoaderBar->setFormat ("%p%"); |
667 m_primLoaderBar->setFormat ("%p%"); |
675 } |
668 } |
676 |
669 |
|
670 // ============================================================================= |
|
671 // ----------------------------------------------------------------------------- |
677 void ForgeWindow::primitiveLoaderUpdate (ulong prog) { |
672 void ForgeWindow::primitiveLoaderUpdate (ulong prog) { |
678 m_primLoaderBar->setValue (prog); |
673 m_primLoaderBar->setValue (prog); |
679 } |
674 } |
680 |
675 |
|
676 // ============================================================================= |
|
677 // ----------------------------------------------------------------------------- |
681 void ForgeWindow::primitiveLoaderEnd() { |
678 void ForgeWindow::primitiveLoaderEnd() { |
682 QTimer* hidetimer = new QTimer; |
679 QTimer* hidetimer = new QTimer; |
683 connect (hidetimer, SIGNAL (timeout()), m_primLoaderWidget, SLOT (hide())); |
680 connect (hidetimer, SIGNAL (timeout()), m_primLoaderWidget, SLOT (hide())); |
684 hidetimer->setSingleShot (true); |
681 hidetimer->setSingleShot (true); |
685 hidetimer->start (1500); |
682 hidetimer->start (1500); |
686 m_primLoaderBar->setFormat (tr ("Done")); |
683 m_primLoaderBar->setFormat (tr ("Done")); |
687 log (tr ("Primitives scanned: %1 primitives listed"), m_primLoaderBar->value()); |
684 log (tr ("Primitives scanned: %1 primitives listed"), m_primLoaderBar->value()); |
688 } |
685 } |
689 |
686 |
690 // ============================================================================= |
687 // ============================================================================= |
691 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
688 // ----------------------------------------------------------------------------- |
692 // ============================================================================= |
|
693 void ForgeWindow::save (LDFile* f, bool saveAs) { |
689 void ForgeWindow::save (LDFile* f, bool saveAs) { |
694 str path = f->name(); |
690 str path = f->name(); |
695 |
691 |
696 if (path.length() == 0 || saveAs) { |
692 if (path.length() == 0 || saveAs) { |
697 path = QFileDialog::getSaveFileName (g_win, tr ("Save As"), |
693 path = QFileDialog::getSaveFileName (g_win, tr ("Save As"), |
740 void ObjectList::contextMenuEvent (QContextMenuEvent* ev) { |
736 void ObjectList::contextMenuEvent (QContextMenuEvent* ev) { |
741 g_win->spawnContextMenu (ev->globalPos()); |
737 g_win->spawnContextMenu (ev->globalPos()); |
742 } |
738 } |
743 |
739 |
744 // ============================================================================= |
740 // ============================================================================= |
745 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
741 // ----------------------------------------------------------------------------- |
746 // ============================================================================= |
|
747 QPixmap getIcon (str iconName) { |
742 QPixmap getIcon (str iconName) { |
748 return (QPixmap (fmt (":/icons/%1.png", iconName))); |
743 return (QPixmap (fmt (":/icons/%1.png", iconName))); |
749 } |
744 } |
750 |
745 |
751 // ============================================================================= |
746 // ============================================================================= |
830 |
825 |
831 void ForgeWindow::updateFileList() { |
826 void ForgeWindow::updateFileList() { |
832 ui->fileList->clear(); |
827 ui->fileList->clear(); |
833 |
828 |
834 for (LDFile* f : g_loadedFiles) { |
829 for (LDFile* f : g_loadedFiles) { |
835 /* Don't list implicit files unless explicitly desired. */ |
830 // Don't list implicit files unless explicitly desired. |
836 if (f->implicit() && !gui_implicitfiles) |
831 if (f->implicit() && !gui_implicitfiles) |
837 continue; |
832 continue; |
838 |
833 |
839 /* Add an item to the list for this file and store a pointer to it in |
834 // Add an item to the list for this file and store a pointer to it in |
840 * the file, so we can find files by the list item. */ |
835 // the file, so we can find files by the list item. |
841 ui->fileList->addItem (""); |
836 ui->fileList->addItem (""); |
842 QListWidgetItem* item = ui->fileList->item (ui->fileList->count() - 1); |
837 QListWidgetItem* item = ui->fileList->item (ui->fileList->count() - 1); |
843 f->setListItem (item); |
838 f->setListItem (item); |
844 |
839 |
845 updateFileListItem (f); |
840 updateFileListItem (f); |
846 } |
841 } |
847 } |
842 } |
848 |
843 |
849 void ForgeWindow::updateFileListItem (LDFile* f) { |
844 void ForgeWindow::updateFileListItem (LDFile* f) { |
850 if (f->listItem() == null) { |
845 if (f->listItem() == null) { |
851 /* We don't have a list item for this file, so the list either doesn't |
846 // We don't have a list item for this file, so the list either doesn't |
852 * exist yet or is out of date. Build the list now. */ |
847 // exist yet or is out of date. Build the list now. |
853 updateFileList(); |
848 updateFileList(); |
854 return; |
849 return; |
855 } |
850 } |
856 |
851 |
857 /* If this is the current file, it also needs to be the selected item on |
852 // If this is the current file, it also needs to be the selected item on |
858 * the list. */ |
853 // the list. |
859 if (f == LDFile::current()) |
854 if (f == LDFile::current()) |
860 ui->fileList->setCurrentItem (f->listItem()); |
855 ui->fileList->setCurrentItem (f->listItem()); |
861 |
856 |
862 /* If we list implicit files, draw them with a shade of gray to make them |
857 // If we list implicit files, draw them with a shade of gray to make them |
863 * distinct. */ |
858 // distinct. |
864 if (f->implicit()) |
859 if (f->implicit()) |
865 f->listItem()->setForeground (QColor (96, 96, 96)); |
860 f->listItem()->setForeground (QColor (96, 96, 96)); |
866 |
861 |
867 f->listItem()->setText (f->getShortName()); |
862 f->listItem()->setText (f->getShortName()); |
868 |
863 |
869 /* If the file has unsaved changes, draw a little icon next to it to mark that. */ |
864 // If the file has unsaved changes, draw a little icon next to it to mark that. |
870 f->listItem()->setIcon (f->hasUnsavedChanges() ? getIcon ("file-save") : QIcon()); |
865 f->listItem()->setIcon (f->hasUnsavedChanges() ? getIcon ("file-save") : QIcon()); |
871 } |
866 } |
872 |
867 |
873 void ForgeWindow::beginAction (QAction* act) { |
868 void ForgeWindow::beginAction (QAction* act) { |
874 // Open the history so we can record the edits done during this action. |
869 // Open the history so we can record the edits done during this action. |
878 |
873 |
879 void ForgeWindow::endAction() { |
874 void ForgeWindow::endAction() { |
880 // Close the history now. |
875 // Close the history now. |
881 LDFile::current()->closeHistory(); |
876 LDFile::current()->closeHistory(); |
882 |
877 |
883 /* Update the list item of the current file - we may need to draw an icon |
878 // Update the list item of the current file - we may need to draw an icon |
884 * now that marks it as having unsaved changes. */ |
879 // now that marks it as having unsaved changes. |
885 updateFileListItem (LDFile::current()); |
880 updateFileListItem (LDFile::current()); |
886 } |
881 } |
887 |
882 |
888 // ============================================================================= |
883 // ============================================================================= |
889 /* A file is selected from the list of files on the left of the screen. Find out |
884 // A file is selected from the list of files on the left of the screen. Find out |
890 * which file was picked and change to it. |
885 // which file was picked and change to it. |
891 */ |
|
892 void ForgeWindow::changeCurrentFile() { |
886 void ForgeWindow::changeCurrentFile() { |
893 LDFile* f = null; |
887 LDFile* f = null; |
894 QListWidgetItem* item = ui->fileList->currentItem(); |
888 QListWidgetItem* item = ui->fileList->currentItem(); |
895 |
889 |
896 /* Find the file pointer of the item that was selected. */ |
890 // Find the file pointer of the item that was selected. |
897 for (LDFile* it : g_loadedFiles) { |
891 for (LDFile* it : g_loadedFiles) { |
898 if (it->listItem() == item) { |
892 if (it->listItem() == item) { |
899 f = it; |
893 f = it; |
900 break; |
894 break; |
901 } |
895 } |
902 } |
896 } |
903 |
897 |
904 /* If we picked the same file we're currently on, we don't need to do |
898 // If we picked the same file we're currently on, we don't need to do |
905 * anything. */ |
899 // anything. |
906 if (!f || f == LDFile::current()) |
900 if (!f || f == LDFile::current()) |
907 return; |
901 return; |
908 |
902 |
909 LDFile::setCurrent (f); |
903 LDFile::setCurrent (f); |
910 } |
904 } |