19#include "mainwindow2.h"
20#include "ui_mainwindow2.h"
23#include <QActionGroup>
29#include <QProgressDialog>
30#include <QTabletEvent>
31#include <QStandardPaths>
41#include "pencilsettings.h"
45#include "filemanager.h"
46#include "colormanager.h"
47#include "layermanager.h"
48#include "toolmanager.h"
49#include "playbackmanager.h"
50#include "selectionmanager.h"
51#include "soundmanager.h"
52#include "viewmanager.h"
53#include "selectionmanager.h"
54#include "undoredomanager.h"
56#include "actioncommands.h"
57#include "fileformat.h"
59#include "undoredocommand.h"
63#include "colorinspector.h"
64#include "colorpalettewidget.h"
65#include "tooloptionwidget.h"
66#include "preferencesdialog.h"
69#include "onionskinwidget.h"
70#include "pegbaralignmentdialog.h"
71#include "addtransparencytopaperdialog.h"
72#include "repositionframesdialog.h"
74#include "errordialog.h"
75#include "filedialog.h"
76#include "importimageseqdialog.h"
77#include "importlayersdialog.h"
78#include "importpositiondialog.h"
79#include "layeropacitydialog.h"
80#include "recentfilemenu.h"
81#include "shortcutfilter.h"
83#include "presetdialog.h"
84#include "pegbaralignmentdialog.h"
88#define BUILD_DATE S__GIT_TIMESTAMP
90#define BUILD_DATE __DATE__
96 if (version.startsWith(
"99.0.0")) {
97 return QString(
"[*]Pencil2D Nightly Build %1").
arg(BUILD_DATE);
98 }
else if (version ==
"0.0.0.0") {
99 return QString(
"[*]Pencil2D Development Build %1").
arg(BUILD_DATE);
101 return QString(
"[*]Pencil2D %1").
arg(APP_VERSION);
108MainWindow2::MainWindow2(
QWidget* parent) :
116 mEditor =
new Editor(
this);
117 mEditor->setScribbleArea(ui->scribbleArea);
122 ui->scribbleArea->setEditor(mEditor);
123 ui->scribbleArea->init();
125 ui->statusBar->setEditor(mEditor);
126 ui->statusBar->updateZoomStatus();
127 ui->statusBar->setVisible(mEditor->preference()->isOn(SETTING::SHOW_STATUS_BAR));
130 mCommands->setCore(mEditor);
135 setupKeyboardShortcuts();
140 currentLayerChanged();
142 connect(mEditor, &Editor::needSave,
this, &MainWindow2::autoSave);
144 mEditor->tools()->setDefaultTool();
145 ui->background->init(mEditor->preference());
147 setWindowTitle(getWindowTitle());
150MainWindow2::~MainWindow2()
155void MainWindow2::createDockWidgets()
161 mColorBox->
setToolTip(
tr(
"color palette:<br>use <b>(C)</b><br>toggle at cursor"));
169 mColorPalette->setCore(mEditor);
190 mStartIcon =
QIcon(
":icons/controls/play.png");
191 mStopIcon =
QIcon(
":icons/controls/stop.png");
196 pWidget->setFeatures(QDockWidget::DockWidgetFeature::DockWidgetClosable |
197 QDockWidget::DockWidgetFeature::DockWidgetMovable |
198 QDockWidget::DockWidgetFeature::DockWidgetFloatable);
201 pWidget->setEditor(mEditor);
203 qDebug() <<
"Init Dock widget: " << pWidget->objectName();
223 makeConnections(mEditor, ui->scribbleArea);
224 makeConnections(mEditor);
225 makeConnections(mEditor, mTimeLine);
226 makeConnections(mEditor, mColorBox);
227 makeConnections(mEditor, mColorInspector);
228 makeConnections(mEditor, mColorPalette);
229 makeConnections(mEditor, mToolOptions);
230 makeConnections(mEditor, ui->statusBar);
234 w->setFloating(
false);
240void MainWindow2::createMenus()
273 replaceUndoRedoActions();
279 connect(mEditor->select(), &SelectionManager::selectionChanged,
this, &MainWindow2::selectionChanged);
295 connect(ui->actionChangeLineColorCurrent_keyframe, &
QAction::triggered, mCommands, &ActionCommands::changeKeyframeLineColor);
296 connect(ui->actionChangeLineColorAll_keyframes_on_layer, &
QAction::triggered, mCommands, &ActionCommands::changeallKeyframeLineColor);
299 QList<QAction*> visibilityActions = ui->menuLayer_Visibility->actions();
301 visibilityGroup->setExclusive(
true);
302 for (
int i = 0; i < visibilityActions.
size(); i++) {
303 QAction* action = visibilityActions[i];
304 visibilityGroup->addAction(action);
307 visibilityActions[mEditor->preference()->getInt(SETTING::LAYER_VISIBILITY)]->setChecked(
true);
308 connect(mEditor->preference(), &PreferenceManager::optionChanged, [=](SETTING e) {
309 if (e == SETTING::LAYER_VISIBILITY) {
310 visibilityActions[mEditor->preference()->getInt(SETTING::LAYER_VISIBILITY)]->setChecked(true);
316 connect(ui->actionZoom_Out, &
QAction::triggered, mCommands, &ActionCommands::ZoomOut);
317 connect(ui->actionRotate_Clockwise, &
QAction::triggered, mCommands, &ActionCommands::rotateClockwise);
318 connect(ui->actionRotate_Anticlockwise, &
QAction::triggered, mCommands, &ActionCommands::rotateCounterClockwise);
319 connect(ui->actionReset_Rotation, &
QAction::triggered, mEditor->view(), &ViewManager::resetRotation);
320 connect(ui->actionReset_View, &
QAction::triggered, mEditor->view(), &ViewManager::resetView);
321 connect(ui->actionCenter_View, &
QAction::triggered, mEditor->view(), &ViewManager::centerView);
322 connect(ui->actionZoom400, &
QAction::triggered, mEditor->view(), &ViewManager::scale400);
323 connect(ui->actionZoom300, &
QAction::triggered, mEditor->view(), &ViewManager::scale300);
324 connect(ui->actionZoom200, &
QAction::triggered, mEditor->view(), &ViewManager::scale200);
325 connect(ui->actionZoom100, &
QAction::triggered, mEditor->view(), &ViewManager::scale100);
326 connect(ui->actionZoom50, &
QAction::triggered, mEditor->view(), &ViewManager::scale50);
327 connect(ui->actionZoom33, &
QAction::triggered, mEditor->view(), &ViewManager::scale33);
328 connect(ui->actionZoom25, &
QAction::triggered, mEditor->view(), &ViewManager::scale25);
329 connect(ui->actionHorizontal_Flip, &
QAction::triggered, mEditor->view(), &ViewManager::flipHorizontal);
330 connect(ui->actionVertical_Flip, &
QAction::triggered, mEditor->view(), &ViewManager::flipVertical);
331 connect(mEditor->view(), &ViewManager::viewFlipped,
this, &MainWindow2::viewFlipped);
335 bindPreferenceSetting(ui->actionStatusBar, prefs, SETTING::SHOW_STATUS_BAR);
336 bindPreferenceSetting(ui->actionThreePointPerspective, prefs, SETTING::OVERLAY_PERSPECTIVE3);
337 bindPreferenceSetting(ui->actionTwoPointPerspective, prefs, SETTING::OVERLAY_PERSPECTIVE2);
338 bindPreferenceSetting(ui->actionOnePointPerspective, prefs, SETTING::OVERLAY_PERSPECTIVE1);
339 bindPreferenceSetting(ui->actionSafeAreas, prefs, SETTING::OVERLAY_SAFE);
340 bindPreferenceSetting(ui->actionGoldenRatio, prefs, SETTING::OVERLAY_GOLDEN);
341 bindPreferenceSetting(ui->actionThirds, prefs, SETTING::OVERLAY_THIRDS);
342 bindPreferenceSetting(ui->actionCenter, prefs, SETTING::OVERLAY_CENTER);
343 bindPreferenceSetting(ui->actionGrid, prefs, SETTING::GRID);
344 bindPreferenceSetting(ui->actionShowOutlinesOnly, prefs, SETTING::OUTLINES);
345 bindPreferenceSetting(ui->actionShowInvisibleLines, prefs, SETTING::INVISIBLE_LINES);
346 bindPreferenceSetting(ui->actionOnionPrev, prefs, SETTING::PREV_ONION);
347 bindPreferenceSetting(ui->actionOnionNext, prefs, SETTING::NEXT_ONION);
349 bool enableSafeArea = (prefs->isOn(SETTING::ACTION_SAFE_ON) || prefs->isOn(SETTING::TITLE_SAFE_ON));
350 ui->actionSafeAreas->setEnabled(enableSafeArea);
352 auto perspectiveLinesAngleGroup =
new QActionGroup(
this);
353 perspectiveLinesAngleGroup->setExclusive(
true);
354 perspectiveLinesAngleGroup->addAction(ui->action2Degrees);
355 perspectiveLinesAngleGroup->addAction(ui->action3Degrees);
356 perspectiveLinesAngleGroup->addAction(ui->action5Degrees);
357 perspectiveLinesAngleGroup->addAction(ui->action7_5Degrees);
358 perspectiveLinesAngleGroup->addAction(ui->action10Degrees);
359 perspectiveLinesAngleGroup->addAction(ui->action15Degrees);
360 perspectiveLinesAngleGroup->addAction(ui->action20Degrees);
361 perspectiveLinesAngleGroup->addAction(ui->action30Degrees);
363 if (action == ui->action2Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 2);
364 else if (action == ui->action3Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 3);
365 else if (action == ui->action5Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 5);
366 else if (action == ui->action7_5Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 7);
367 else if (action == ui->action10Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 10);
368 else if (action == ui->action15Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 15);
369 else if (action == ui->action20Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 20);
370 else if (action == ui->action30Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 30);
371 else Q_UNREACHABLE();
372 emit mEditor->view()->viewChanged();
375 switch (prefs->getInt(SETTING::OVERLAY_ANGLE)) {
376 case 2: ui->action2Degrees->setChecked(
true);
break;
377 case 3: ui->action3Degrees->setChecked(
true);
break;
378 case 5: ui->action5Degrees->setChecked(
true);
break;
379 case 7: ui->action7_5Degrees->setChecked(
true);
break;
380 case 10: ui->action10Degrees->setChecked(
true);
break;
381 case 15: ui->action15Degrees->setChecked(
true);
break;
382 case 20: ui->action20Degrees->setChecked(
true);
break;
383 case 30: ui->action30Degrees->setChecked(
true);
break;
390 connect(ui->actionLoop, &
QAction::triggered, pPlaybackManager, &PlaybackManager::setLooping);
391 connect(ui->actionLoopControl, &
QAction::triggered, pPlaybackManager, &PlaybackManager::enableRangedPlayback);
392 connect(pPlaybackManager, &PlaybackManager::loopStateChanged, ui->actionLoop, &
QAction::setChecked);
393 connect(pPlaybackManager, &PlaybackManager::loopStateChanged, mTimeLine, &TimeLine::setLoop);
394 connect(pPlaybackManager, &PlaybackManager::rangedPlaybackStateChanged, ui->actionLoopControl, &
QAction::setChecked);
395 connect(pPlaybackManager, &PlaybackManager::rangedPlaybackStateChanged, mTimeLine, &TimeLine::setRangeState);
396 connect(pPlaybackManager, &PlaybackManager::playStateChanged, mTimeLine, &TimeLine::setPlaying);
397 connect(pPlaybackManager, &PlaybackManager::playStateChanged,
this, &MainWindow2::changePlayState);
399 connect(ui->actionFlip_inbetween, &
QAction::triggered, pPlaybackManager, &PlaybackManager::playFlipInBetween);
400 connect(ui->actionFlip_rolling, &
QAction::triggered, pPlaybackManager, &PlaybackManager::playFlipRoll);
403 connect(ui->actionRemove_Frame, &
QAction::triggered, mCommands, &ActionCommands::removeKey);
404 connect(ui->actionAdd_Frame_Exposure, &
QAction::triggered, mCommands, &ActionCommands::addExposureToSelectedFrames);
405 connect(ui->actionSubtract_Frame_Exposure, &
QAction::triggered, mCommands, &ActionCommands::subtractExposureFromSelectedFrames);
406 connect(ui->actionNext_Frame, &
QAction::triggered, mCommands, &ActionCommands::GotoNextFrame);
407 connect(ui->actionPrevious_Frame, &
QAction::triggered, mCommands, &ActionCommands::GotoPrevFrame);
408 connect(ui->actionNext_KeyFrame, &
QAction::triggered, mCommands, &ActionCommands::GotoNextKeyFrame);
409 connect(ui->actionPrev_KeyFrame, &
QAction::triggered, mCommands, &ActionCommands::GotoPrevKeyFrame);
410 connect(ui->actionDuplicate_Frame, &
QAction::triggered, mCommands, &ActionCommands::duplicateKey);
411 connect(ui->actionMove_Frame_Forward, &
QAction::triggered, mCommands, &ActionCommands::moveFrameForward);
412 connect(ui->actionMove_Frame_Backward, &
QAction::triggered, mCommands, &ActionCommands::moveFrameBackward);
414 connect(ui->actionReverse_Frames_Order, &
QAction::triggered, mCommands, &ActionCommands::reverseSelectedFrames);
415 connect(ui->actionRemove_Frames, &
QAction::triggered, mCommands, &ActionCommands::removeSelectedFrames);
419 toolsActionGroup->setExclusive(
true);
420 toolsActionGroup->addAction(ui->actionMove);
421 toolsActionGroup->addAction(ui->actionSelect);
422 toolsActionGroup->addAction(ui->actionBrush);
423 toolsActionGroup->addAction(ui->actionPolyline);
424 toolsActionGroup->addAction(ui->actionSmudge);
425 toolsActionGroup->addAction(ui->actionPen);
426 toolsActionGroup->addAction(ui->actionHand);
427 toolsActionGroup->addAction(ui->actionPencil);
428 toolsActionGroup->addAction(ui->actionBucket);
429 toolsActionGroup->addAction(ui->actionEyedropper);
430 toolsActionGroup->addAction(ui->actionEraser);
431 toolsActionGroup->addAction(ui->actionResetToolsDefault);
434 if (action == ui->actionMove) mToolBox->setActiveTool(MOVE);
435 else if (action == ui->actionSelect) mToolBox->setActiveTool(SELECT);
436 else if (action == ui->actionBrush) mToolBox->setActiveTool(BRUSH);
437 else if (action == ui->actionPolyline) mToolBox->setActiveTool(POLYLINE);
438 else if (action == ui->actionSmudge) mToolBox->setActiveTool(SMUDGE);
439 else if (action == ui->actionPen) mToolBox->setActiveTool(PEN);
440 else if (action == ui->actionHand) mToolBox->setActiveTool(HAND);
441 else if (action == ui->actionPencil) mToolBox->setActiveTool(PENCIL);
442 else if (action == ui->actionBucket) mToolBox->setActiveTool(BUCKET);
443 else if (action == ui->actionEyedropper) mToolBox->setActiveTool(EYEDROPPER);
444 else if (action == ui->actionEraser) mToolBox->setActiveTool(ERASER);
445 else if (action == ui->actionResetToolsDefault) mCommands->resetAllTools();
446 else Q_UNREACHABLE();
450 QMenu* winMenu = ui->menuWindows;
451 const std::vector<QAction*> actions
453 mToolBox->toggleViewAction(),
454 mToolOptions->toggleViewAction(),
455 mColorBox->toggleViewAction(),
456 mColorPalette->toggleViewAction(),
457 mTimeLine->toggleViewAction(),
458 mColorInspector->toggleViewAction(),
459 mOnionSkinWidget->toggleViewAction()
462 for (
QAction* action : actions)
465 winMenu->insertAction(ui->menuToolbars->menuAction(), action);
467 winMenu->insertSeparator(ui->menuToolbars->menuAction());
468 connect(ui->actionResetWindows, &
QAction::triggered,
this, &MainWindow2::resetAndDockAllSubWidgets);
469 connect(ui->actionLockWindows, &
QAction::toggled,
this, &MainWindow2::lockWidgets);
470 bindPreferenceSetting(ui->actionLockWindows, prefs, SETTING::LAYOUT_LOCK);
474 connect(ui->actionQuick_Guide, &
QAction::triggered, mCommands, &ActionCommands::quickGuide);
478 connect(ui->actionCheck_for_Updates, &
QAction::triggered, mCommands, &ActionCommands::checkForUpdates);
479 connect(ui->actionReport_Bug, &
QAction::triggered, mCommands, &ActionCommands::reportbug);
480 connect(ui->actionOpen_Temporary_Directory, &
QAction::triggered, mCommands, &ActionCommands::openTemporaryDirectory);
485 mRecentFileMenu->loadFromDisk();
486 ui->menuFile->insertMenu(ui->actionSave, mRecentFileMenu);
488 connect(mRecentFileMenu, &RecentFileMenu::loadRecentFile,
this, &MainWindow2::openFile);
491void MainWindow2::replaceUndoRedoActions()
493 ui->menuEdit->removeAction(ui->actionUndo);
494 ui->menuEdit->removeAction(ui->actionRedo);
495 ui->actionUndo = mEditor->undoRedo()->createUndoAction(
this, ui->actionUndo->icon());
496 ui->actionRedo = mEditor->undoRedo()->createRedoAction(
this, ui->actionRedo->icon());
497 ui->menuEdit->insertAction(ui->actionCut, ui->actionUndo);
498 ui->menuEdit->insertAction(ui->actionCut, ui->actionRedo);
501void MainWindow2::setOpacity(
int opacity)
503 mEditor->preference()->set(SETTING::WINDOW_OPACITY, 100 - opacity);
507void MainWindow2::updateSaveState()
511 ui->statusBar->updateModifiedStatus(hasUnsavedChanges);
514void MainWindow2::updateBackupActionState()
516 mEditor->undoRedo()->updateUndoAction(ui->actionUndo);
517 mEditor->undoRedo()->updateRedoAction(ui->actionRedo);
520void MainWindow2::openPegAlignDialog()
522 if (mPegAlign !=
nullptr)
525 tr(
"Dialog is already open!"),
535 flags &= (
~Qt::WindowContextHelpButtonHint);
544void MainWindow2::openLayerOpacityDialog()
546 if (mLayerOpacityDialog !=
nullptr)
549 tr(
"Dialog is already open!"),
555 mLayerOpacityDialog->setCore(mEditor);
556 mLayerOpacityDialog->initUI();
558 mLayerOpacityDialog->
show();
562 mLayerOpacityDialog =
nullptr;
566void MainWindow2::openAddTranspToPaperDialog()
568 if (mAddTranspToPaper)
571 mAddTranspToPaper->
raise();
576 mAddTranspToPaper->setCore(mEditor);
577 mAddTranspToPaper->initUI();
579 mAddTranspToPaper->
show();
585 mSuppressAutoSaveDialog =
true;
586 mAddTranspToPaper->traceScannedDrawings();
587 mSuppressAutoSaveDialog =
false;
590 mAddTranspToPaper =
nullptr;
594void MainWindow2::openRepositionDialog()
596 if (mEditor->layers()->currentLayer()->getSelectedFramesByPos().
count() < 2)
599 tr(
"Please select at least 2 frames!"),
603 if (mReposDialog !=
nullptr)
611 hideQuestionMark(*mReposDialog);
612 mReposDialog->setCore(mEditor);
613 mReposDialog->initUI();
614 mEditor->tools()->setCurrentTool(ToolType::MOVE);
616 mReposDialog->
show();
619void MainWindow2::closeRepositionDialog()
622 mReposDialog =
nullptr;
625void MainWindow2::currentLayerChanged()
627 bool isBitmap = (mEditor->layers()->currentLayer()->type() == Layer::BITMAP);
628 ui->menuChange_line_color->setEnabled(isBitmap);
630 bool isVector = (mEditor->layers()->currentLayer()->type() == Layer::VECTOR);
631 ui->actionShowInvisibleLines->setEnabled(isVector);
632 ui->actionShowOutlinesOnly->setEnabled(isVector);
635void MainWindow2::selectionChanged()
637 bool somethingSelected = mEditor->select()->somethingSelected();
638 ui->menuSelection->setEnabled(somethingSelected);
641void MainWindow2::viewFlipped()
643 ui->actionHorizontal_Flip->setChecked(mEditor->view()->isFlipHorizontal());
644 ui->actionVertical_Flip->setChecked(mEditor->view()->isFlipVertical());
663 m2ndCloseEvent =
true;
671void MainWindow2::newDocument()
673 if (maybeSave() && !tryLoadPreset())
679void MainWindow2::openDocument()
688 openObject(fileName);
692bool MainWindow2::saveAsNewDocument()
699 return saveObject(fileName);
702void MainWindow2::openStartupFile(
const QString& filename)
704 if (checkForRecoverableProjects())
709 if (!filename.
isEmpty() && openObject(filename))
714 loadMostRecent() || tryLoadPreset();
717void MainWindow2::openFile(
const QString& filename)
721 openObject(filename);
725bool MainWindow2::openObject(
const QString& strFilePath)
728 hideQuestionMark(progress);
732 Status s = mEditor->openObject(strFilePath, [&progress](
int p)
734 progress.setValue(p);
736 }, [&progress](
int max)
738 progress.setRange(0, max);
743 ErrorDialog errorDialog(s.title(), s.description(), s.details().str());
745 emptyDocumentWhenErrorOccurred();
750 settings.setValue(LAST_PCLX_PATH, mEditor->object()->filePath());
753 if (!mEditor->object()->filePath().
isEmpty())
755 mRecentFileMenu->addRecentFile(mEditor->object()->filePath());
756 mRecentFileMenu->saveToDisk();
763 ui->statusBar->updateModifiedStatus(
false);
765 progress.setValue(progress.maximum());
768 updateBackupActionState();
770 if (!
QFileInfo(strFilePath).isWritable())
773 tr(
"This program does not currently have permission to write to the file you have selected. "
774 "Please make sure you have write permission for this file before attempting to save it. "
775 "Alternatively, you can use the Save As... menu option to save to a writable location."),
782bool MainWindow2::saveObject(
QString strSavedFileName)
785 hideQuestionMark(progress);
789 mEditor->prepareSave();
793 connect(&fm, &FileManager::progressChanged, [&progress](
int p)
795 progress.setValue(p);
798 connect(&fm, &FileManager::progressRangeChanged, [&progress](
int max)
800 progress.setRange(0, max + 3);
803 Status st = fm.save(mEditor->object(), strSavedFileName);
808#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
813 errorLogFolder.mkpath(
"./logs");
814 errorLogFolder.cd(
"logs");
822 out << st.details().str();
827 st.description().append(
tr(
"<br><br>An error has occurred and your file may not have saved successfully."
828 "\nIf you believe that this error is an issue with Pencil2D, please create a new issue at:"
829 "<br><a href='https://github.com/pencil2d/pencil/issues'>https://github.com/pencil2d/pencil/issues</a><br>"
830 "Please be sure to include the following details in your issue:")), st.details().html());
835 mEditor->object()->setFilePath(strSavedFileName);
836 mEditor->object()->setModified(
false);
838 mEditor->clearTemporary();
841 settings.setValue(LAST_PCLX_PATH, strSavedFileName);
843 mRecentFileMenu->addRecentFile(strSavedFileName);
844 mRecentFileMenu->saveToDisk();
846 mTimeLine->updateContent();
851 progress.setValue(progress.maximum());
853 mEditor->resetAutoSaveCounter();
858bool MainWindow2::saveDocument()
860 if (!mEditor->object()->filePath().
isEmpty())
861 return saveObject(mEditor->object()->filePath());
863 return saveAsNewDocument();
866bool MainWindow2::maybeSave()
874 tr(
"This animation has been modified.\n Do you want to save your changes?"),
877 return saveDocument();
882bool MainWindow2::autoSave()
884 if (!mEditor->object()->filePath().
isEmpty())
886 return saveDocument();
889 if (mEditor->autoSaveNeverAskAgain())
892 if(mSuppressAutoSaveDialog)
897 msgBox.setWindowTitle(
tr(
"AutoSave Reminder"));
898 msgBox.setText(
tr(
"The animation is not saved yet.\n Do you want to save now?"));
903 int ret = msgBox.exec();
906 return saveDocument();
910 mEditor->dontAskAutoSave(
true);
916void MainWindow2::emptyDocumentWhenErrorOccurred()
924void MainWindow2::importImage()
928 if (strFilePath.
isEmpty()) {
return; }
929 if (!QFile::exists(strFilePath)) {
return; }
932 OnScopeExit(
delete positionDialog)
934 positionDialog->
exec();
942 Status st = mEditor->importImage(strFilePath, importImageConfig);
945 ErrorDialog errorDialog(st.title(), st.description(), st.details().html());
950 ui->scribbleArea->updateFrame();
951 mTimeLine->updateContent();
954void MainWindow2::importImageSequence()
956 mSuppressAutoSaveDialog =
true;
959 OnScopeExit(
delete imageSeqDialog)
960 imageSeqDialog->setCore(mEditor);
964 imageSeqDialog->
exec();
971 OnScopeExit(
delete positionDialog)
973 positionDialog->
exec();
979 imageSeqDialog->importArbitrarySequence(positionDialog->importConfig());
981 mSuppressAutoSaveDialog =
false;
984void MainWindow2::importPredefinedImageSet()
987 OnScopeExit(
delete imageSeqDialog)
988 imageSeqDialog->setCore(mEditor);
992 mSuppressAutoSaveDialog =
true;
993 imageSeqDialog->
exec();
1000 OnScopeExit(
delete positionDialog)
1002 positionDialog->
exec();
1008 imageSeqDialog->importPredefinedSet(positionDialog->importConfig());
1009 mSuppressAutoSaveDialog =
false;
1012void MainWindow2::importLayers()
1015 importLayers->setCore(mEditor);
1017 importLayers->
open();
1020void MainWindow2::importAnimatedImage()
1023 mSuppressAutoSaveDialog =
true;
1025 mCommands->importAnimatedImage();
1027 mSuppressAutoSaveDialog =
false;
1030void MainWindow2::lockWidgets(
bool shouldLock)
1034 : (QDockWidget::DockWidgetFeature::DockWidgetClosable |
1035 QDockWidget::DockWidgetFeature::DockWidgetMovable |
1036 QDockWidget::DockWidgetFeature::DockWidgetFloatable);
1040 d->setFeatures(feat);
1041 d->lock(shouldLock);
1045void MainWindow2::preferences()
1050 mPrefDialog->
raise();
1056 mPrefDialog->init(mEditor->preference());
1058 connect(mPrefDialog, &PreferencesDialog::windowOpacityChange,
this, &MainWindow2::setOpacity);
1059 connect(mPrefDialog, &PreferencesDialog::soundScrubChanged, mEditor->playback(), &PlaybackManager::setSoundScrubActive);
1060 connect(mPrefDialog, &PreferencesDialog::soundScrubMsecChanged, mEditor->playback(), &PlaybackManager::setSoundScrubMsec);
1063 clearKeyboardShortcuts();
1064 setupKeyboardShortcuts();
1065 mPrefDialog =
nullptr;
1068 mPrefDialog->
show();
1071void MainWindow2::resetAndDockAllSubWidgets()
1074 settings.remove(SETTING_WINDOW_GEOMETRY);
1075 settings.remove(SETTING_WINDOW_STATE);
1079 dock->setFloating(
false);
1093void MainWindow2::newObject()
1095 auto object =
new Object();
1099 object->addNewCameraLayer();
1100 object->addNewBitmapLayer();
1104 object->data()->setCurrentLayer(1);
1106 mEditor->setObject(
object);
1111 updateBackupActionState();
1114bool MainWindow2::newObjectFromPresets(
int presetIndex)
1116 QString presetFilePath = PresetDialog::getPresetPath(presetIndex);
1124 Object*
object = fm.load(presetFilePath);
1126 if (!fm.error().ok() ||
object ==
nullptr)
1131 mEditor->setObject(
object);
1132 object->setFilePath(
QString());
1136 updateBackupActionState();
1141bool MainWindow2::loadMostRecent()
1143 if(!mEditor->preference()->isOn(SETTING::LOAD_MOST_RECENT))
1149 QString myPath = settings.value(LAST_PCLX_PATH,
QVariant(
"")).toString();
1150 if (myPath.
isEmpty() || !QFile::exists(myPath))
1154 return openObject(myPath);
1157bool MainWindow2::tryLoadPreset()
1159 if (!mEditor->preference()->isOn(SETTING::ASK_FOR_PRESET))
1161 int defaultPreset = mEditor->preference()->getInt(SETTING::DEFAULT_PRESET);
1162 return newObjectFromPresets(defaultPreset);
1174 int presetIndex = presetDialog->getPresetIndex();
1175 if (presetDialog->shouldAlwaysUse())
1177 mEditor->preference()->set(SETTING::ASK_FOR_PRESET, false);
1178 mEditor->preference()->set(SETTING::DEFAULT_PRESET, presetIndex);
1180 if (!newObjectFromPresets(presetIndex))
1185 presetDialog->
open();
1189void MainWindow2::closeDialogs()
1196void MainWindow2::readSettings()
1200 QVariant winGeometry = settings.
value(SETTING_WINDOW_GEOMETRY);
1206 int opacity = mEditor->preference()->getInt(SETTING::WINDOW_OPACITY);
1207 setOpacity(100 - opacity);
1209 bool isWindowsLocked = mEditor->preference()->isOn(SETTING::LAYOUT_LOCK);
1210 lockWidgets(isWindowsLocked);
1213void MainWindow2::writeSettings()
1216 settings.setValue(SETTING_WINDOW_GEOMETRY,
saveGeometry());
1217 settings.setValue(SETTING_WINDOW_STATE,
saveState());
1220void MainWindow2::setupKeyboardShortcuts()
1222 checkExistingShortcuts();
1226 strCommandName =
QString(
"shortcuts/") + strCommandName;
1232 ui->actionNew->setShortcut(cmdKeySeq(CMD_NEW_FILE));
1233 ui->actionOpen->setShortcut(cmdKeySeq(CMD_OPEN_FILE));
1234 ui->actionSave->setShortcut(cmdKeySeq(CMD_SAVE_FILE));
1235 ui->actionSave_as->setShortcut(cmdKeySeq(CMD_SAVE_AS));
1237 ui->actionImport_Image->setShortcut(cmdKeySeq(CMD_IMPORT_IMAGE));
1238 ui->actionImport_ImageSeq->setShortcut(cmdKeySeq(CMD_IMPORT_IMAGE_SEQ));
1239 ui->actionImport_ImageSeqNum->setShortcut(cmdKeySeq(CMD_IMPORT_IMAGE_PREDEFINED_SET));
1240 ui->actionImport_MovieVideo->setShortcut(cmdKeySeq(CMD_IMPORT_MOVIE_VIDEO));
1241 ui->actionImport_AnimatedImage->setShortcut(cmdKeySeq(CMD_IMPORT_ANIMATED_IMAGE));
1242 ui->actionImportLayers_from_pclx->setShortcut(cmdKeySeq(CMD_IMPORT_LAYERS));
1243 ui->actionImport_Sound->setShortcut(cmdKeySeq(CMD_IMPORT_SOUND));
1244 ui->actionImport_MovieAudio->setShortcut(cmdKeySeq(CMD_IMPORT_MOVIE_AUDIO));
1245 ui->actionImport_Append_Palette->setShortcut(cmdKeySeq(CMD_IMPORT_PALETTE));
1246 ui->actionImport_Replace_Palette->setShortcut(cmdKeySeq(CMD_IMPORT_PALETTE_REPLACE));
1248 ui->actionExport_Image->setShortcut(cmdKeySeq(CMD_EXPORT_IMAGE));
1249 ui->actionExport_ImageSeq->setShortcut(cmdKeySeq(CMD_EXPORT_IMAGE_SEQ));
1250 ui->actionExport_Movie->setShortcut(cmdKeySeq(CMD_EXPORT_MOVIE));
1251 ui->actionExport_Animated_GIF->setShortcut(cmdKeySeq(CMD_EXPORT_GIF));
1252 ui->actionExport_Palette->setShortcut(cmdKeySeq(CMD_EXPORT_PALETTE));
1255 ui->actionUndo->setShortcut(cmdKeySeq(CMD_UNDO));
1256 ui->actionRedo->setShortcut(cmdKeySeq(CMD_REDO));
1257 ui->actionCut->setShortcut(cmdKeySeq(CMD_CUT));
1258 ui->actionCopy->setShortcut(cmdKeySeq(CMD_COPY));
1259 ui->actionPaste_Previous->setShortcut(cmdKeySeq(CMD_PASTE_FROM_PREVIOUS));
1260 ui->actionPaste->setShortcut(cmdKeySeq(CMD_PASTE));
1261 ui->actionClearFrame->setShortcut(cmdKeySeq(CMD_CLEAR_FRAME));
1262 ui->actionFlip_X->setShortcut(cmdKeySeq(CMD_SELECTION_FLIP_HORIZONTAL));
1263 ui->actionFlip_Y->setShortcut(cmdKeySeq(CMD_SELECTION_FLIP_VERTICAL));
1264 ui->actionSelect_All->setShortcut(cmdKeySeq(CMD_SELECT_ALL));
1265 ui->actionDeselect_All->setShortcut(cmdKeySeq(CMD_DESELECT_ALL));
1266 ui->actionPegbarAlignment->setShortcut(cmdKeySeq(CMD_PEGBAR_ALIGNMENT));
1267 ui->actionPreference->setShortcut(cmdKeySeq(CMD_PREFERENCE));
1270 ui->actionResetWindows->setShortcut(cmdKeySeq(CMD_RESET_WINDOWS));
1271 ui->actionLockWindows->setShortcut(cmdKeySeq(CMD_LOCK_WINDOWS));
1272 ui->actionReset_View->setShortcut(cmdKeySeq(CMD_RESET_ZOOM_ROTATE));
1273 ui->actionCenter_View->setShortcut(cmdKeySeq(CMD_CENTER_VIEW));
1274 ui->actionZoom_In->setShortcut(cmdKeySeq(CMD_ZOOM_IN));
1275 ui->actionZoom_Out->setShortcut(cmdKeySeq(CMD_ZOOM_OUT));
1276 ui->actionZoom400->setShortcut(cmdKeySeq(CMD_ZOOM_400));
1277 ui->actionZoom300->setShortcut(cmdKeySeq(CMD_ZOOM_300));
1278 ui->actionZoom200->setShortcut(cmdKeySeq(CMD_ZOOM_200));
1279 ui->actionZoom100->setShortcut(cmdKeySeq(CMD_ZOOM_100));
1280 ui->actionZoom50->setShortcut(cmdKeySeq(CMD_ZOOM_50));
1281 ui->actionZoom33->setShortcut(cmdKeySeq(CMD_ZOOM_33));
1282 ui->actionZoom25->setShortcut(cmdKeySeq(CMD_ZOOM_25));
1283 ui->actionRotate_Clockwise->setShortcut(cmdKeySeq(CMD_ROTATE_CLOCK));
1284 ui->actionRotate_Anticlockwise->setShortcut(cmdKeySeq(CMD_ROTATE_ANTI_CLOCK));
1285 ui->actionReset_Rotation->setShortcut(cmdKeySeq(CMD_RESET_ROTATION));
1286 ui->actionHorizontal_Flip->setShortcut(cmdKeySeq(CMD_FLIP_HORIZONTAL));
1287 ui->actionVertical_Flip->setShortcut(cmdKeySeq(CMD_FLIP_VERTICAL));
1288 ui->actionGrid->setShortcut(cmdKeySeq(CMD_GRID));
1289 ui->actionCenter->setShortcut(cmdKeySeq(CMD_OVERLAY_CENTER));
1290 ui->actionThirds->setShortcut(cmdKeySeq(CMD_OVERLAY_THIRDS));
1291 ui->actionGoldenRatio->setShortcut(cmdKeySeq(CMD_OVERLAY_GOLDEN_RATIO));
1292 ui->actionSafeAreas->setShortcut(cmdKeySeq(CMD_OVERLAY_SAFE_AREAS));
1293 ui->actionOnePointPerspective->setShortcut(cmdKeySeq(CMD_OVERLAY_ONE_POINT_PERSPECTIVE));
1294 ui->actionTwoPointPerspective->setShortcut(cmdKeySeq(CMD_OVERLAY_TWO_POINT_PERSPECTIVE));
1295 ui->actionThreePointPerspective->setShortcut(cmdKeySeq(CMD_OVERLAY_THREE_POINT_PERSPECTIVE));
1296 ui->actionOnionPrev->setShortcut(cmdKeySeq(CMD_ONIONSKIN_PREV));
1297 ui->actionOnionNext->setShortcut(cmdKeySeq(CMD_ONIONSKIN_NEXT));
1298 ui->actionStatusBar->setShortcut(cmdKeySeq(CMD_TOGGLE_STATUS_BAR));
1301 ui->actionPlay->setShortcut(cmdKeySeq(CMD_PLAY));
1302 ui->actionLoop->setShortcut(cmdKeySeq(CMD_LOOP));
1303 ui->actionLoopControl->setShortcut(cmdKeySeq(CMD_LOOP_CONTROL));
1304 ui->actionPrevious_Frame->setShortcut(cmdKeySeq(CMD_GOTO_PREV_FRAME));
1305 ui->actionNext_Frame->setShortcut(cmdKeySeq(CMD_GOTO_NEXT_FRAME));
1306 ui->actionPrev_KeyFrame->setShortcut(cmdKeySeq(CMD_GOTO_PREV_KEY_FRAME));
1307 ui->actionNext_KeyFrame->setShortcut(cmdKeySeq(CMD_GOTO_NEXT_KEY_FRAME));
1308 ui->actionAdd_Frame->setShortcut(cmdKeySeq(CMD_ADD_FRAME));
1309 ui->actionDuplicate_Frame->setShortcut(cmdKeySeq(CMD_DUPLICATE_FRAME));
1310 ui->actionRemove_Frame->setShortcut(cmdKeySeq(CMD_REMOVE_FRAME));
1311 ui->actionAdd_Frame_Exposure->setShortcut(cmdKeySeq(CMD_SELECTION_ADD_FRAME_EXPOSURE));
1312 ui->actionSubtract_Frame_Exposure->setShortcut(cmdKeySeq(CMD_SELECTION_SUBTRACT_FRAME_EXPOSURE));
1313 ui->actionReverse_Frames_Order->setShortcut(cmdKeySeq(CMD_REVERSE_SELECTED_FRAMES));
1314 ui->actionRemove_Frames->setShortcut(cmdKeySeq(CMD_REMOVE_SELECTED_FRAMES));
1315 ui->actionMove_Frame_Backward->setShortcut(cmdKeySeq(CMD_MOVE_FRAME_BACKWARD));
1316 ui->actionMove_Frame_Forward->setShortcut(cmdKeySeq(CMD_MOVE_FRAME_FORWARD));
1317 ui->actionFlip_inbetween->setShortcut(cmdKeySeq(CMD_FLIP_INBETWEEN));
1318 ui->actionFlip_rolling->setShortcut(cmdKeySeq(CMD_FLIP_ROLLING));
1319 ui->actionReposition_Selected_Frames->setShortcut(cmdKeySeq(CMD_SELECTION_REPOSITION_FRAMES));
1322 ui->actionMove->setShortcut(cmdKeySeq(CMD_TOOL_MOVE));
1323 ui->actionSelect->setShortcut(cmdKeySeq(CMD_TOOL_SELECT));
1324 ui->actionBrush->setShortcut(cmdKeySeq(CMD_TOOL_BRUSH));
1325 ui->actionPolyline->setShortcut(cmdKeySeq(CMD_TOOL_POLYLINE));
1326 ui->actionSmudge->setShortcut(cmdKeySeq(CMD_TOOL_SMUDGE));
1327 ui->actionPen->setShortcut(cmdKeySeq(CMD_TOOL_PEN));
1328 ui->actionHand->setShortcut(cmdKeySeq(CMD_TOOL_HAND));
1329 ui->actionPencil->setShortcut(cmdKeySeq(CMD_TOOL_PENCIL));
1330 ui->actionBucket->setShortcut(cmdKeySeq(CMD_TOOL_BUCKET));
1331 ui->actionEyedropper->setShortcut(cmdKeySeq(CMD_TOOL_EYEDROPPER));
1332 ui->actionEraser->setShortcut(cmdKeySeq(CMD_TOOL_ERASER));
1333 ui->actionResetToolsDefault->setShortcut(cmdKeySeq(CMD_RESET_ALL_TOOLS));
1335 ui->actionMove->installEventFilter(shortcutFilter);
1336 ui->actionMove->installEventFilter(shortcutFilter);
1337 ui->actionSelect->installEventFilter(shortcutFilter);
1338 ui->actionBrush->installEventFilter(shortcutFilter);
1339 ui->actionPolyline->installEventFilter(shortcutFilter);
1340 ui->actionSmudge->installEventFilter(shortcutFilter);
1341 ui->actionPen->installEventFilter(shortcutFilter);
1342 ui->actionHand->installEventFilter(shortcutFilter);
1343 ui->actionPencil->installEventFilter(shortcutFilter);
1344 ui->actionBucket->installEventFilter(shortcutFilter);
1345 ui->actionEyedropper->installEventFilter(shortcutFilter);
1346 ui->actionEraser->installEventFilter(shortcutFilter);
1349 ui->actionNew_Bitmap_Layer->setShortcut(cmdKeySeq(CMD_NEW_BITMAP_LAYER));
1350 ui->actionNew_Vector_Layer->setShortcut(cmdKeySeq(CMD_NEW_VECTOR_LAYER));
1351 ui->actionNew_Camera_Layer->setShortcut(cmdKeySeq(CMD_NEW_CAMERA_LAYER));
1352 ui->actionNew_Sound_Layer->setShortcut(cmdKeySeq(CMD_NEW_SOUND_LAYER));
1353 ui->actionDelete_Current_Layer->setShortcut(cmdKeySeq(CMD_DELETE_CUR_LAYER));
1354 ui->actionChangeLineColorCurrent_keyframe->setShortcut(cmdKeySeq(CMD_CHANGE_LINE_COLOR_KEYFRAME));
1355 ui->actionChangeLineColorAll_keyframes_on_layer->setShortcut(cmdKeySeq(CMD_CHANGE_LINE_COLOR_LAYER));
1356 ui->actionChangeLayerOpacity->setShortcut(cmdKeySeq(CMD_CHANGE_LAYER_OPACITY));
1358 ui->actionVisibilityCurrentLayerOnly->setShortcut(cmdKeySeq(CMD_CURRENT_LAYER_VISIBILITY));
1359 ui->actionVisibilityRelative->setShortcut(cmdKeySeq(CMD_RELATIVE_LAYER_VISIBILITY));
1360 ui->actionVisibilityAll->setShortcut(cmdKeySeq(CMD_ALL_LAYER_VISIBILITY));
1362 mToolBox->toggleViewAction()->setShortcut(cmdKeySeq(CMD_TOGGLE_TOOLBOX));
1370 ui->actionHelp->setShortcut(cmdKeySeq(CMD_HELP));
1371 ui->actionExit->setShortcut(cmdKeySeq(CMD_EXIT));
1374void MainWindow2::clearKeyboardShortcuts()
1377 for (
QAction* action : actionList)
1383void MainWindow2::exportPalette()
1388 mEditor->object()->exportPalette(filePath);
1392void MainWindow2::importPalette()
1397 mEditor->object()->importPalette(filePath);
1398 mColorPalette->refreshColorList();
1399 mColorPalette->adjustSwatches();
1400 mEditor->color()->setColorNumber(0);
1404void MainWindow2::openPalette()
1406 for (
int i = 0; i < mEditor->object()->getColorCount(); i++)
1408 if (!mEditor->object()->isColorInUse(i))
1414 msgBox.
setText(
tr(
"Opening a palette will replace the old palette.\n"
1415 "Color(s) in strokes will be altered by this action!"));
1431 mEditor->object()->openPalette(filePath);
1432 mColorPalette->refreshColorList();
1433 mEditor->color()->setColorNumber(0);
1436void MainWindow2::makeConnections(
Editor* editor)
1438 connect(editor->undoRedo(), &UndoRedoManager::didUpdateUndoStack,
this, &MainWindow2::updateSaveState);
1439 connect(editor->undoRedo(), &UndoRedoManager::didUpdateUndoStack,
this, &MainWindow2::updateBackupActionState);
1440 connect(editor, &Editor::needDisplayInfo,
this, &MainWindow2::displayMessageBox);
1441 connect(editor, &Editor::needDisplayInfoNoTitle,
this, &MainWindow2::displayMessageBoxNoTitle);
1442 connect(editor->layers(), &LayerManager::currentLayerChanged,
this, &MainWindow2::currentLayerChanged);
1443 connect(editor->select(), &SelectionManager::selectionChanged,
this, &MainWindow2::selectionChanged);
1444 connect(editor, &Editor::canCopyChanged,
this, [=](
bool canCopy) {
1445 ui->actionCopy->setEnabled(canCopy);
1446 ui->actionCut->setEnabled(canCopy);
1451void MainWindow2::makeConnections(
Editor* editor,
ColorBox* colorBox)
1453 connect(colorBox, &ColorBox::colorChanged, editor->color(), &ColorManager::setFrontColor);
1454 connect(editor->color(), &ColorManager::colorChanged, colorBox, &ColorBox::setColor);
1459 connect(colorInspector, &ColorInspector::colorChanged, editor->color(), &ColorManager::setFrontColor);
1460 connect(editor->color(), &ColorManager::colorChanged, colorInspector, &ColorInspector::setColor);
1465 connect(editor->tools(), &ToolManager::toolChanged, scribbleArea, &ScribbleArea::updateToolCursor);
1466 connect(editor->tools(), &ToolManager::toolChanged, mToolBox, &ToolBoxDockWidget::setActiveTool);
1477void MainWindow2::makeConnections(
Editor* pEditor,
TimeLine* pTimeline)
1480 connect(pTimeline, &TimeLine::duplicateLayerClick, mCommands, &ActionCommands::duplicateLayer);
1481 connect(pTimeline, &TimeLine::duplicateKeyClick, mCommands, &ActionCommands::duplicateKey);
1483 connect(pTimeline, &TimeLine::soundClick, pPlaybackManager, &PlaybackManager::enableSound);
1484 connect(pTimeline, &TimeLine::fpsChanged, pPlaybackManager, &PlaybackManager::setFps);
1485 connect(pTimeline, &TimeLine::fpsChanged, pEditor, &Editor::setFps);
1488 connect(pTimeline, &TimeLine::removeKeyClick, mCommands, &ActionCommands::removeKey);
1490 connect(pTimeline, &TimeLine::newBitmapLayer, mCommands, &ActionCommands::addNewBitmapLayer);
1491 connect(pTimeline, &TimeLine::newVectorLayer, mCommands, &ActionCommands::addNewVectorLayer);
1492 connect(pTimeline, &TimeLine::newSoundLayer, mCommands, &ActionCommands::addNewSoundLayer);
1493 connect(pTimeline, &TimeLine::newCameraLayer, mCommands, &ActionCommands::addNewCameraLayer);
1494 connect(mTimeLine, &TimeLine::playButtonTriggered, mCommands, &ActionCommands::PlayStop);
1495 connect(pTimeline, &TimeLine::deleteCurrentLayerClick, mCommands, &ActionCommands::deleteCurrentLayer);
1499 connect(pTimeline, &TimeLine::selectionChanged,
this, &MainWindow2::updateCopyCutPasteEnabled);
1501 connect(mEditor->select(), &SelectionManager::selectionChanged,
this, &MainWindow2::updateCopyCutPasteEnabled);
1503 connect(pEditor->layers(), &LayerManager::currentLayerChanged, pTimeline, &TimeLine::updateUI);
1505 connect(pEditor->sound(), &SoundManager::soundClipDurationChanged, pTimeline, &TimeLine::updateUI);
1510 connect(pEditor, &Editor::objectLoaded, pTimeline, &TimeLine::onObjectLoaded);
1511 connect(pEditor, &Editor::updateTimeLine, pTimeline, &TimeLine::updateUI);
1512 connect(pEditor, &Editor::updateTimeLineCached, pTimeline, &TimeLine::updateUICached);
1514 connect(pEditor->layers(), &LayerManager::currentLayerChanged,
this, &MainWindow2::updateLayerMenu);
1523 toolOptions->makeConnectionToEditor(editor);
1528 connect(pEditor, &Editor::objectLoaded, pColorPalette, &ColorPaletteWidget::updateUI);
1531 ScribbleArea* pScribbleArea = pEditor->getScribbleArea();
1533 connect(pColorPalette, &ColorPaletteWidget::colorNumberChanged, pColorManager, &ColorManager::setColorNumber);
1534 connect(pColorManager, &ColorManager::colorNumberChanged, pScribbleArea, &ScribbleArea::paletteColorChanged);
1535 connect(pColorManager, &ColorManager::colorNumberChanged, pColorPalette, &ColorPaletteWidget::selectColorNumber);
1538void MainWindow2::makeConnections(
Editor* editor,
StatusBar *statusBar)
1547void MainWindow2::updateCopyCutPasteEnabled()
1549 bool canCopy = mEditor->canCopy();
1550 bool canPaste = mEditor->canPaste();
1552 ui->actionCopy->setEnabled(canCopy);
1553 ui->actionCut->setEnabled(canCopy);
1554 ui->actionPaste->setEnabled(canPaste);
1557void MainWindow2::updateLayerMenu()
1559 ui->actionDelete_Current_Layer->setEnabled(mEditor->layers()->canDeleteLayer(mEditor->currentLayerIndex()));
1562void MainWindow2::changePlayState(
bool isPlaying)
1566 ui->actionPlay->setText(
tr(
"Stop"));
1567 ui->actionPlay->setIcon(mStopIcon);
1571 ui->actionPlay->setText(
tr(
"Play"));
1572 ui->actionPlay->setIcon(mStartIcon);
1577void MainWindow2::importMovieVideo()
1580 mSuppressAutoSaveDialog =
true;
1582 mCommands->importMovieVideo();
1584 mSuppressAutoSaveDialog =
false;
1587bool MainWindow2::event(
QEvent* event)
1595void MainWindow2::displayMessageBox(
const QString& title,
const QString& body)
1600void MainWindow2::displayMessageBoxNoTitle(
const QString& body)
1605bool MainWindow2::checkForRecoverableProjects()
1608 QStringList recoverables = fm.searchForUnsavedProjects();
1610 if (recoverables.empty())
1615 foreach (
const QString path, recoverables)
1617 if (tryRecoverProject(path))
1626bool MainWindow2::tryRecoverProject(
const QString recoverPath)
1628 QString caption =
tr(
"Restore Project?");
1629 QString text =
tr(
"Pencil2D didn't close correctly. Would you like to restore the project?");
1632 hideQuestionMark(msgBox);
1641 int result = msgBox.
exec();
1651 return startProjectRecovery(recoverPath);
1659bool MainWindow2::startProjectRecovery(
const QString recoverPath)
1662 Object* o = fm.recoverUnsavedProject(recoverPath);
1663 if (!fm.error().ok())
1665 Q_ASSERT(o ==
nullptr);
1666 const QString title =
tr(
"Recovery Failed.");
1667 const QString text =
tr(
"Sorry! Pencil2D is unable to restore your project");
1673 mEditor->setObject(o);
1675 updateBackupActionState();
1677 const QString title =
tr(
"Recovery Succeeded!");
1678 const QString text =
tr(
"Please save your work immediately to prevent loss of data");
1684void MainWindow2::createToolbars()
1689 mMainToolbar->
addAction(ui->actionOpen);
1690 mMainToolbar->
addAction(ui->actionSave);
1692 mMainToolbar->
addAction(ui->actionUndo);
1693 mMainToolbar->
addAction(ui->actionRedo);
1696 mMainToolbar->
addAction(ui->actionCopy);
1697 mMainToolbar->
addAction(ui->actionPaste);
1698 mMainToolbar->
addAction(ui->actionClearFrame);
1702 mViewToolbar->
addAction(ui->actionZoom_In);
1703 mViewToolbar->
addAction(ui->actionZoom_Out);
1704 mViewToolbar->
addAction(ui->actionReset_View);
1706 mViewToolbar->
addAction(ui->actionHorizontal_Flip);
1707 mViewToolbar->
addAction(ui->actionVertical_Flip);
1709 mViewToolbar->
addAction(ui->actionShowInvisibleLines);
1710 mViewToolbar->
addAction(ui->actionShowOutlinesOnly);
1714 mOverlayToolbar->
addAction(ui->actionGrid);
1715 mOverlayToolbar->
addAction(ui->actionCenter);
1716 mOverlayToolbar->
addAction(ui->actionThirds);
1717 mOverlayToolbar->
addAction(ui->actionGoldenRatio);
1718 mOverlayToolbar->
addAction(ui->actionSafeAreas);
1719 mOverlayToolbar->
addAction(ui->actionOnePointPerspective);
1720 mOverlayToolbar->
addAction(ui->actionTwoPointPerspective);
1721 mOverlayToolbar->
addAction(ui->actionThreePointPerspective);
1727 perspectiveLinesAngleButton->
setDefaultAction(ui->menuPerspectiveLinesAngle->menuAction());
1729 mOverlayToolbar->
addWidget(perspectiveLinesAngleButton);
1731 mToolbars = { mMainToolbar, mViewToolbar, mOverlayToolbar };
1735 ui->menuToolbars->addAction(tb->toggleViewAction());
Status insertKeyFrameAtCurrentPosition()
Will insert a keyframe at the current position and push connected frames to the right.
void framesModified()
This should be emitted after modifying multiple frames.
void frameModified(int frameNumber)
This should be emitted after modifying the frame content.
void scrubbed(int frameNumber)
This should be emitted after scrubbing.
static QString getSaveFileName(QWidget *parent, FileType fileType, const QString &caption=QString())
Shows a file dialog which allows the user to select a file save path.
static QString getOpenFileName(QWidget *parent, FileType fileType, const QString &caption=QString())
Shows a file dialog which allows the user to select a file to open.
void notifyAnimationLengthChanged()
This should be emitted whenever the animation length frames, eg.
void windowActivated()
Emitted when window regains focus.
void onScrubbed(int frameNumber)
Frame scrubbed, invalidate relevant cache.
void onViewChanged()
View updated, invalidate relevant cache.
void onObjectLoaded()
Object updated, invalidate all cache.
void onFramesModified()
Multiple frames modified, invalidate cache for affected frames.
void onPlayStateChanged()
Playstate changed, invalidate relevant cache.
void onLayerChanged()
Layer changed, invalidate relevant cache.
void onFrameModified(int frameNumber)
Frame modified, invalidate cache for frame if any.
The status bar of Pencil2D's main window.
void updateToolStatus(ToolType tool)
Updates the status bar with information about the current tool.
void zoomChanged(double scale)
This signal is sent when the user chooses a new zoom level through the status bar.
void updateZoomStatus()
Updates the zoom level displayed in the status bar.
void extendLength(int frame)
Extends the timeline frame length if necessary.
bool hasUnsavedChanges() const
Checks whether there are unsaved changes.
void setShortcut(const QKeySequence &shortcut)
void toggled(bool checked)
void triggered(bool checked)
void triggered(QAction *action)
void processEvents(QEventLoop::ProcessEventsFlags flags)
QDateTime currentDateTime()
void setTimeSpec(Qt::TimeSpec spec)
QString toString(Qt::DateFormat format) const const
void finished(int result)
QEvent::Type type() const const
int count(const T &value) const const
void addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget)
void addToolBar(Qt::ToolBarArea area, QToolBar *toolbar)
void setDockNestingEnabled(bool enabled)
virtual bool event(QEvent *event) override
bool restoreState(const QByteArray &state, int version)
QByteArray saveState(int version) const const
QStatusBar * statusBar() const const
virtual int exec() override
void setIconPixmap(const QPixmap &pixmap)
void setInformativeText(const QString &text)
void setWindowModality(Qt::WindowModality windowModality)
void setWindowTitle(const QString &title)
void setText(const QString &text)
QMessageBox::StandardButton warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setObjectName(const QString &name)
QString tr(const char *sourceText, const char *disambiguation, int n)
QString writableLocation(QStandardPaths::StandardLocation type)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
bool isEmpty() const const
QString & prepend(QChar ch)
void keySequence(QWindow *window, const QKeySequence &keySequence)
char * toString(const T &value)
QByteArray toByteArray() const const