128 #include "actions.h" |
128 #include "actions.h" |
129 } |
129 } |
130 |
130 |
131 // ============================================================================= |
131 // ============================================================================= |
132 // ----------------------------------------------------------------------------- |
132 // ----------------------------------------------------------------------------- |
133 void ForgeWindow::invokeAction (QAction* act, void (*func) ()) |
133 void ForgeWindow::invokeAction (QAction* act, void (*func)()) |
134 { beginAction (act); |
134 { |
|
135 #ifdef DEBUG |
|
136 log ("Action %1 triggered", act->iconText()); |
|
137 #endif |
|
138 |
|
139 beginAction (act); |
135 (*func) (); |
140 (*func) (); |
136 endAction(); |
141 endAction(); |
137 } |
142 } |
138 |
143 |
139 // ============================================================================= |
144 // ============================================================================= |
152 |
157 |
153 m_recentFiles.clear(); |
158 m_recentFiles.clear(); |
154 |
159 |
155 QAction* first = null; |
160 QAction* first = null; |
156 |
161 |
157 for (const QVariant & it : io_recentfiles) |
162 for (const QVariant& it : io_recentfiles) |
158 { str file = it.toString(); |
163 { str file = it.toString(); |
159 QAction* recent = new QAction (getIcon ("open-recent"), file, this); |
164 QAction* recent = new QAction (getIcon ("open-recent"), file, this); |
160 |
165 |
161 connect (recent, SIGNAL (triggered()), this, SLOT (slot_recentFile())); |
166 connect (recent, SIGNAL (triggered()), this, SLOT (slot_recentFile())); |
162 ui->menuOpenRecent->insertAction (first, recent); |
167 ui->menuOpenRecent->insertAction (first, recent); |
569 LDObject* singleObj = (single) ? selection()[0] : null; |
574 LDObject* singleObj = (single) ? selection()[0] : null; |
570 |
575 |
571 QMenu* contextMenu = new QMenu; |
576 QMenu* contextMenu = new QMenu; |
572 |
577 |
573 if (single && singleObj->getType() != LDObject::Empty) |
578 if (single && singleObj->getType() != LDObject::Empty) |
574 { contextMenu->addAction (ACTION (Edit)); |
579 { contextMenu->addAction (ui->actionEdit); |
575 contextMenu->addSeparator(); |
580 contextMenu->addSeparator(); |
576 } |
581 } |
577 |
582 |
578 contextMenu->addAction (ACTION (Cut)); |
583 contextMenu->addAction (ui->actionCut); |
579 contextMenu->addAction (ACTION (Copy)); |
584 contextMenu->addAction (ui->actionCopy); |
580 contextMenu->addAction (ACTION (Paste)); |
585 contextMenu->addAction (ui->actionPaste); |
581 contextMenu->addAction (ACTION (Delete)); |
586 contextMenu->addAction (ui->actionDelete); |
582 contextMenu->addSeparator(); |
587 contextMenu->addSeparator(); |
583 contextMenu->addAction (ACTION (SetColor)); |
588 contextMenu->addAction (ui->actionSetColor); |
584 |
589 |
585 if (single) |
590 if (single) |
586 contextMenu->addAction (ACTION (EditRaw)); |
591 contextMenu->addAction (ui->actionEditRaw); |
587 |
592 |
588 contextMenu->addAction (ACTION (Borders)); |
593 contextMenu->addAction (ui->actionBorders); |
589 contextMenu->addAction (ACTION (SetOverlay)); |
594 contextMenu->addAction (ui->actionSetOverlay); |
590 contextMenu->addAction (ACTION (ClearOverlay)); |
595 contextMenu->addAction (ui->actionClearOverlay); |
591 contextMenu->addAction (ACTION (ModeSelect)); |
596 contextMenu->addAction (ui->actionModeSelect); |
592 contextMenu->addAction (ACTION (ModeDraw)); |
597 contextMenu->addAction (ui->actionModeDraw); |
593 contextMenu->addAction (ACTION (ModeCircle)); |
598 contextMenu->addAction (ui->actionModeCircle); |
594 |
599 |
595 if (R()->camera() != GL::Free) |
600 if (R()->camera() != GL::Free) |
596 { contextMenu->addSeparator(); |
601 { contextMenu->addSeparator(); |
597 contextMenu->addAction (ACTION (SetDrawDepth)); |
602 contextMenu->addAction (ui->actionSetDrawDepth); |
598 } |
603 } |
599 |
604 |
600 contextMenu->exec (pos); |
605 contextMenu->exec (pos); |
601 } |
606 } |
602 |
607 |
626 |
631 |
627 // ============================================================================= |
632 // ============================================================================= |
628 // ----------------------------------------------------------------------------- |
633 // ----------------------------------------------------------------------------- |
629 void ForgeWindow::updateEditModeActions() |
634 void ForgeWindow::updateEditModeActions() |
630 { const EditMode mode = R()->getEditMode(); |
635 { const EditMode mode = R()->getEditMode(); |
631 ACTION (ModeSelect)->setChecked (mode == Select); |
636 ui->actionModeSelect->setChecked (mode == Select); |
632 ACTION (ModeDraw)->setChecked (mode == Draw); |
637 ui->actionModeDraw->setChecked (mode == Draw); |
633 ACTION (ModeCircle)->setChecked (mode == CircleMode); |
638 ui->actionModeCircle->setChecked (mode == CircleMode); |
634 } |
639 } |
635 |
640 |
636 // ============================================================================= |
641 // ============================================================================= |
637 // ----------------------------------------------------------------------------- |
642 // ----------------------------------------------------------------------------- |
638 void ForgeWindow::slot_editObject (QListWidgetItem* listitem) |
643 void ForgeWindow::slot_editObject (QListWidgetItem* listitem) |
854 f->getListItem()->setIcon (f->hasUnsavedChanges() ? getIcon ("file-save") : QIcon()); |
859 f->getListItem()->setIcon (f->hasUnsavedChanges() ? getIcon ("file-save") : QIcon()); |
855 } |
860 } |
856 |
861 |
857 void ForgeWindow::beginAction (QAction* act) |
862 void ForgeWindow::beginAction (QAction* act) |
858 { // Open the history so we can record the edits done during this action. |
863 { // Open the history so we can record the edits done during this action. |
859 if (act == ACTION (Undo) || act == ACTION (Redo) || act == ACTION (Open)) |
864 if (act == ui->actionUndo || act == ui->actionRedo || act == ui->actionOpen) |
860 LDFile::current()->getHistory()->setIgnoring (true); |
865 LDFile::current()->getHistory()->setIgnoring (true); |
861 } |
866 } |
862 |
867 |
863 void ForgeWindow::endAction() |
868 void ForgeWindow::endAction() |
864 { // Close the history now. |
869 { // Close the history now. |
904 #endif |
909 #endif |
905 |
910 |
906 buildObjList(); |
911 buildObjList(); |
907 } |
912 } |
908 |
913 |
|
914 void ForgeWindow::updateActions() |
|
915 { History* his = LDFile::current()->getHistory(); |
|
916 int pos = his->getPosition(); |
|
917 ui->actionUndo->setEnabled (pos != -1); |
|
918 ui->actionRedo->setEnabled (pos < (long) his->getSize() - 1); |
|
919 ui->actionAxes->setChecked (gl_axes); |
|
920 ui->actionBFCView->setChecked (gl_colorbfc); |
|
921 } |
|
922 |
909 QImage imageFromScreencap (uchar* data, int w, int h) |
923 QImage imageFromScreencap (uchar* data, int w, int h) |
910 { // GL and Qt formats have R and B swapped. Also, GL flips Y - correct it as well. |
924 { // GL and Qt formats have R and B swapped. Also, GL flips Y - correct it as well. |
911 return QImage (data, w, h, QImage::Format_ARGB32).rgbSwapped().mirrored(); |
925 return QImage (data, w, h, QImage::Format_ARGB32).rgbSwapped().mirrored(); |
912 } |
926 } |
913 |
927 |