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__
93#if defined(PENCIL2D_RELEASE_BUILD)
94#define PENCIL_WINDOW_TITLE QString("[*]Pencil2D v%1").arg(APP_VERSION)
95#elif defined(PENCIL2D_NIGHTLY_BUILD)
96#define PENCIL_WINDOW_TITLE QString("[*]Pencil2D Nightly Build %1").arg(BUILD_DATE)
98#define PENCIL_WINDOW_TITLE QString("[*]Pencil2D Development Build %1").arg(BUILD_DATE)
103MainWindow2::MainWindow2(
QWidget* parent) :
111 mEditor =
new Editor(
this);
112 mEditor->setScribbleArea(ui->scribbleArea);
117 ui->scribbleArea->setEditor(mEditor);
118 ui->scribbleArea->init();
120 ui->statusBar->setEditor(mEditor);
121 ui->statusBar->updateZoomStatus();
122 ui->statusBar->setVisible(mEditor->preference()->isOn(SETTING::SHOW_STATUS_BAR));
125 mCommands->setCore(mEditor);
130 setupKeyboardShortcuts();
135 currentLayerChanged();
137 connect(mEditor, &Editor::needSave,
this, &MainWindow2::autoSave);
139 mEditor->tools()->setDefaultTool();
140 ui->background->init(mEditor->preference());
142 setWindowTitle(PENCIL_WINDOW_TITLE);
145MainWindow2::~MainWindow2()
150void MainWindow2::createDockWidgets()
156 mColorBox->
setToolTip(
tr(
"color palette:<br>use <b>(C)</b><br>toggle at cursor"));
164 mColorPalette->setCore(mEditor);
185 mStartIcon =
QIcon(
":icons/controls/play.png");
186 mStopIcon =
QIcon(
":icons/controls/stop.png");
191 pWidget->setFeatures(QDockWidget::DockWidgetFeature::DockWidgetClosable |
192 QDockWidget::DockWidgetFeature::DockWidgetMovable |
193 QDockWidget::DockWidgetFeature::DockWidgetFloatable);
196 pWidget->setEditor(mEditor);
198 qDebug() <<
"Init Dock widget: " << pWidget->objectName();
218 makeConnections(mEditor, ui->scribbleArea);
219 makeConnections(mEditor);
220 makeConnections(mEditor, mTimeLine);
221 makeConnections(mEditor, mColorBox);
222 makeConnections(mEditor, mColorInspector);
223 makeConnections(mEditor, mColorPalette);
224 makeConnections(mEditor, mToolOptions);
225 makeConnections(mEditor, ui->statusBar);
229 w->setFloating(
false);
235void MainWindow2::createMenus()
268 replaceUndoRedoActions();
274 connect(mEditor->select(), &SelectionManager::selectionChanged,
this, &MainWindow2::selectionChanged);
290 connect(ui->actionChangeLineColorCurrent_keyframe, &
QAction::triggered, mCommands, &ActionCommands::changeKeyframeLineColor);
291 connect(ui->actionChangeLineColorAll_keyframes_on_layer, &
QAction::triggered, mCommands, &ActionCommands::changeallKeyframeLineColor);
294 QList<QAction*> visibilityActions = ui->menuLayer_Visibility->actions();
296 visibilityGroup->setExclusive(
true);
297 for (
int i = 0; i < visibilityActions.
size(); i++) {
298 QAction* action = visibilityActions[i];
299 visibilityGroup->addAction(action);
302 visibilityActions[mEditor->preference()->getInt(SETTING::LAYER_VISIBILITY)]->setChecked(
true);
303 connect(mEditor->preference(), &PreferenceManager::optionChanged, [=](SETTING e) {
304 if (e == SETTING::LAYER_VISIBILITY) {
305 visibilityActions[mEditor->preference()->getInt(SETTING::LAYER_VISIBILITY)]->setChecked(true);
311 connect(ui->actionZoom_Out, &
QAction::triggered, mCommands, &ActionCommands::ZoomOut);
312 connect(ui->actionRotate_Clockwise, &
QAction::triggered, mCommands, &ActionCommands::rotateClockwise);
313 connect(ui->actionRotate_Anticlockwise, &
QAction::triggered, mCommands, &ActionCommands::rotateCounterClockwise);
314 connect(ui->actionReset_Rotation, &
QAction::triggered, mEditor->view(), &ViewManager::resetRotation);
315 connect(ui->actionReset_View, &
QAction::triggered, mEditor->view(), &ViewManager::resetView);
316 connect(ui->actionCenter_View, &
QAction::triggered, mEditor->view(), &ViewManager::centerView);
317 connect(ui->actionZoom400, &
QAction::triggered, mEditor->view(), &ViewManager::scale400);
318 connect(ui->actionZoom300, &
QAction::triggered, mEditor->view(), &ViewManager::scale300);
319 connect(ui->actionZoom200, &
QAction::triggered, mEditor->view(), &ViewManager::scale200);
320 connect(ui->actionZoom100, &
QAction::triggered, mEditor->view(), &ViewManager::scale100);
321 connect(ui->actionZoom50, &
QAction::triggered, mEditor->view(), &ViewManager::scale50);
322 connect(ui->actionZoom33, &
QAction::triggered, mEditor->view(), &ViewManager::scale33);
323 connect(ui->actionZoom25, &
QAction::triggered, mEditor->view(), &ViewManager::scale25);
324 connect(ui->actionHorizontal_Flip, &
QAction::triggered, mEditor->view(), &ViewManager::flipHorizontal);
325 connect(ui->actionVertical_Flip, &
QAction::triggered, mEditor->view(), &ViewManager::flipVertical);
326 connect(mEditor->view(), &ViewManager::viewFlipped,
this, &MainWindow2::viewFlipped);
330 bindPreferenceSetting(ui->actionStatusBar, prefs, SETTING::SHOW_STATUS_BAR);
331 bindPreferenceSetting(ui->actionThreePointPerspective, prefs, SETTING::OVERLAY_PERSPECTIVE3);
332 bindPreferenceSetting(ui->actionTwoPointPerspective, prefs, SETTING::OVERLAY_PERSPECTIVE2);
333 bindPreferenceSetting(ui->actionOnePointPerspective, prefs, SETTING::OVERLAY_PERSPECTIVE1);
334 bindPreferenceSetting(ui->actionSafeAreas, prefs, SETTING::OVERLAY_SAFE);
335 bindPreferenceSetting(ui->actionGoldenRatio, prefs, SETTING::OVERLAY_GOLDEN);
336 bindPreferenceSetting(ui->actionThirds, prefs, SETTING::OVERLAY_THIRDS);
337 bindPreferenceSetting(ui->actionCenter, prefs, SETTING::OVERLAY_CENTER);
338 bindPreferenceSetting(ui->actionGrid, prefs, SETTING::GRID);
339 bindPreferenceSetting(ui->actionShowOutlinesOnly, prefs, SETTING::OUTLINES);
340 bindPreferenceSetting(ui->actionShowInvisibleLines, prefs, SETTING::INVISIBLE_LINES);
341 bindPreferenceSetting(ui->actionOnionPrev, prefs, SETTING::PREV_ONION);
342 bindPreferenceSetting(ui->actionOnionNext, prefs, SETTING::NEXT_ONION);
344 bool enableSafeArea = (prefs->isOn(SETTING::ACTION_SAFE_ON) || prefs->isOn(SETTING::TITLE_SAFE_ON));
345 ui->actionSafeAreas->setEnabled(enableSafeArea);
347 auto perspectiveLinesAngleGroup =
new QActionGroup(
this);
348 perspectiveLinesAngleGroup->setExclusive(
true);
349 perspectiveLinesAngleGroup->addAction(ui->action2Degrees);
350 perspectiveLinesAngleGroup->addAction(ui->action3Degrees);
351 perspectiveLinesAngleGroup->addAction(ui->action5Degrees);
352 perspectiveLinesAngleGroup->addAction(ui->action7_5Degrees);
353 perspectiveLinesAngleGroup->addAction(ui->action10Degrees);
354 perspectiveLinesAngleGroup->addAction(ui->action15Degrees);
355 perspectiveLinesAngleGroup->addAction(ui->action20Degrees);
356 perspectiveLinesAngleGroup->addAction(ui->action30Degrees);
358 if (action == ui->action2Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 2);
359 else if (action == ui->action3Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 3);
360 else if (action == ui->action5Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 5);
361 else if (action == ui->action7_5Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 7);
362 else if (action == ui->action10Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 10);
363 else if (action == ui->action15Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 15);
364 else if (action == ui->action20Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 20);
365 else if (action == ui->action30Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 30);
366 else Q_UNREACHABLE();
367 emit mEditor->view()->viewChanged();
370 switch (prefs->getInt(SETTING::OVERLAY_ANGLE)) {
371 case 2: ui->action2Degrees->setChecked(
true);
break;
372 case 3: ui->action3Degrees->setChecked(
true);
break;
373 case 5: ui->action5Degrees->setChecked(
true);
break;
374 case 7: ui->action7_5Degrees->setChecked(
true);
break;
375 case 10: ui->action10Degrees->setChecked(
true);
break;
376 case 15: ui->action15Degrees->setChecked(
true);
break;
377 case 20: ui->action20Degrees->setChecked(
true);
break;
378 case 30: ui->action30Degrees->setChecked(
true);
break;
385 connect(ui->actionLoop, &
QAction::triggered, pPlaybackManager, &PlaybackManager::setLooping);
386 connect(ui->actionLoopControl, &
QAction::triggered, pPlaybackManager, &PlaybackManager::enableRangedPlayback);
387 connect(pPlaybackManager, &PlaybackManager::loopStateChanged, ui->actionLoop, &
QAction::setChecked);
388 connect(pPlaybackManager, &PlaybackManager::loopStateChanged, mTimeLine, &TimeLine::setLoop);
389 connect(pPlaybackManager, &PlaybackManager::rangedPlaybackStateChanged, ui->actionLoopControl, &
QAction::setChecked);
390 connect(pPlaybackManager, &PlaybackManager::rangedPlaybackStateChanged, mTimeLine, &TimeLine::setRangeState);
391 connect(pPlaybackManager, &PlaybackManager::playStateChanged, mTimeLine, &TimeLine::setPlaying);
392 connect(pPlaybackManager, &PlaybackManager::playStateChanged,
this, &MainWindow2::changePlayState);
394 connect(ui->actionFlip_inbetween, &
QAction::triggered, pPlaybackManager, &PlaybackManager::playFlipInBetween);
395 connect(ui->actionFlip_rolling, &
QAction::triggered, pPlaybackManager, &PlaybackManager::playFlipRoll);
398 connect(ui->actionRemove_Frame, &
QAction::triggered, mCommands, &ActionCommands::removeKey);
399 connect(ui->actionAdd_Frame_Exposure, &
QAction::triggered, mCommands, &ActionCommands::addExposureToSelectedFrames);
400 connect(ui->actionSubtract_Frame_Exposure, &
QAction::triggered, mCommands, &ActionCommands::subtractExposureFromSelectedFrames);
401 connect(ui->actionNext_Frame, &
QAction::triggered, mCommands, &ActionCommands::GotoNextFrame);
402 connect(ui->actionPrevious_Frame, &
QAction::triggered, mCommands, &ActionCommands::GotoPrevFrame);
403 connect(ui->actionNext_KeyFrame, &
QAction::triggered, mCommands, &ActionCommands::GotoNextKeyFrame);
404 connect(ui->actionPrev_KeyFrame, &
QAction::triggered, mCommands, &ActionCommands::GotoPrevKeyFrame);
405 connect(ui->actionDuplicate_Frame, &
QAction::triggered, mCommands, &ActionCommands::duplicateKey);
406 connect(ui->actionMove_Frame_Forward, &
QAction::triggered, mCommands, &ActionCommands::moveFrameForward);
407 connect(ui->actionMove_Frame_Backward, &
QAction::triggered, mCommands, &ActionCommands::moveFrameBackward);
409 connect(ui->actionReverse_Frames_Order, &
QAction::triggered, mCommands, &ActionCommands::reverseSelectedFrames);
410 connect(ui->actionRemove_Frames, &
QAction::triggered, mCommands, &ActionCommands::removeSelectedFrames);
414 toolsActionGroup->setExclusive(
true);
415 toolsActionGroup->addAction(ui->actionMove);
416 toolsActionGroup->addAction(ui->actionSelect);
417 toolsActionGroup->addAction(ui->actionBrush);
418 toolsActionGroup->addAction(ui->actionPolyline);
419 toolsActionGroup->addAction(ui->actionSmudge);
420 toolsActionGroup->addAction(ui->actionPen);
421 toolsActionGroup->addAction(ui->actionHand);
422 toolsActionGroup->addAction(ui->actionPencil);
423 toolsActionGroup->addAction(ui->actionBucket);
424 toolsActionGroup->addAction(ui->actionEyedropper);
425 toolsActionGroup->addAction(ui->actionEraser);
426 toolsActionGroup->addAction(ui->actionResetToolsDefault);
429 if (action == ui->actionMove) mToolBox->setActiveTool(MOVE);
430 else if (action == ui->actionSelect) mToolBox->setActiveTool(SELECT);
431 else if (action == ui->actionBrush) mToolBox->setActiveTool(BRUSH);
432 else if (action == ui->actionPolyline) mToolBox->setActiveTool(POLYLINE);
433 else if (action == ui->actionSmudge) mToolBox->setActiveTool(SMUDGE);
434 else if (action == ui->actionPen) mToolBox->setActiveTool(PEN);
435 else if (action == ui->actionHand) mToolBox->setActiveTool(HAND);
436 else if (action == ui->actionPencil) mToolBox->setActiveTool(PENCIL);
437 else if (action == ui->actionBucket) mToolBox->setActiveTool(BUCKET);
438 else if (action == ui->actionEyedropper) mToolBox->setActiveTool(EYEDROPPER);
439 else if (action == ui->actionEraser) mToolBox->setActiveTool(ERASER);
440 else if (action == ui->actionResetToolsDefault) mCommands->resetAllTools();
441 else Q_UNREACHABLE();
445 QMenu* winMenu = ui->menuWindows;
446 const std::vector<QAction*> actions
448 mToolBox->toggleViewAction(),
449 mToolOptions->toggleViewAction(),
450 mColorBox->toggleViewAction(),
451 mColorPalette->toggleViewAction(),
452 mTimeLine->toggleViewAction(),
453 mColorInspector->toggleViewAction(),
454 mOnionSkinWidget->toggleViewAction()
457 for (
QAction* action : actions)
460 winMenu->insertAction(ui->menuToolbars->menuAction(), action);
462 winMenu->insertSeparator(ui->menuToolbars->menuAction());
463 connect(ui->actionResetWindows, &
QAction::triggered,
this, &MainWindow2::resetAndDockAllSubWidgets);
464 connect(ui->actionLockWindows, &
QAction::toggled,
this, &MainWindow2::lockWidgets);
465 bindPreferenceSetting(ui->actionLockWindows, prefs, SETTING::LAYOUT_LOCK);
469 connect(ui->actionQuick_Guide, &
QAction::triggered, mCommands, &ActionCommands::quickGuide);
473 connect(ui->actionCheck_for_Updates, &
QAction::triggered, mCommands, &ActionCommands::checkForUpdates);
474 connect(ui->actionReport_Bug, &
QAction::triggered, mCommands, &ActionCommands::reportbug);
475 connect(ui->actionOpen_Temporary_Directory, &
QAction::triggered, mCommands, &ActionCommands::openTemporaryDirectory);
480 mRecentFileMenu->loadFromDisk();
481 ui->menuFile->insertMenu(ui->actionSave, mRecentFileMenu);
483 connect(mRecentFileMenu, &RecentFileMenu::loadRecentFile,
this, &MainWindow2::openFile);
486void MainWindow2::replaceUndoRedoActions()
488 ui->menuEdit->removeAction(ui->actionUndo);
489 ui->menuEdit->removeAction(ui->actionRedo);
490 ui->actionUndo = mEditor->undoRedo()->createUndoAction(
this, ui->actionUndo->icon());
491 ui->actionRedo = mEditor->undoRedo()->createRedoAction(
this, ui->actionRedo->icon());
492 ui->menuEdit->insertAction(ui->actionCut, ui->actionUndo);
493 ui->menuEdit->insertAction(ui->actionCut, ui->actionRedo);
496void MainWindow2::setOpacity(
int opacity)
498 mEditor->preference()->set(SETTING::WINDOW_OPACITY, 100 - opacity);
502void MainWindow2::updateSaveState()
506 ui->statusBar->updateModifiedStatus(hasUnsavedChanges);
509void MainWindow2::updateBackupActionState()
511 mEditor->undoRedo()->updateUndoAction(ui->actionUndo);
512 mEditor->undoRedo()->updateRedoAction(ui->actionRedo);
515void MainWindow2::openPegAlignDialog()
517 if (mPegAlign !=
nullptr)
520 tr(
"Dialog is already open!"),
530 flags &= (
~Qt::WindowContextHelpButtonHint);
539void MainWindow2::openLayerOpacityDialog()
541 if (mLayerOpacityDialog !=
nullptr)
544 tr(
"Dialog is already open!"),
550 mLayerOpacityDialog->setCore(mEditor);
551 mLayerOpacityDialog->initUI();
553 mLayerOpacityDialog->
show();
557 mLayerOpacityDialog =
nullptr;
561void MainWindow2::openAddTranspToPaperDialog()
563 if (mAddTranspToPaper)
566 mAddTranspToPaper->
raise();
571 mAddTranspToPaper->setCore(mEditor);
572 mAddTranspToPaper->initUI();
574 mAddTranspToPaper->
show();
580 mSuppressAutoSaveDialog =
true;
581 mAddTranspToPaper->traceScannedDrawings();
582 mSuppressAutoSaveDialog =
false;
585 mAddTranspToPaper =
nullptr;
589void MainWindow2::openRepositionDialog()
591 if (mEditor->layers()->currentLayer()->getSelectedFramesByPos().
count() < 2)
594 tr(
"Please select at least 2 frames!"),
598 if (mReposDialog !=
nullptr)
606 hideQuestionMark(*mReposDialog);
607 mReposDialog->setCore(mEditor);
608 mReposDialog->initUI();
609 mEditor->tools()->setCurrentTool(ToolType::MOVE);
611 mReposDialog->
show();
614void MainWindow2::closeRepositionDialog()
617 mReposDialog =
nullptr;
620void MainWindow2::currentLayerChanged()
622 bool isBitmap = (mEditor->layers()->currentLayer()->type() == Layer::BITMAP);
623 ui->menuChange_line_color->setEnabled(isBitmap);
625 bool isVector = (mEditor->layers()->currentLayer()->type() == Layer::VECTOR);
626 ui->actionShowInvisibleLines->setEnabled(isVector);
627 ui->actionShowOutlinesOnly->setEnabled(isVector);
630void MainWindow2::selectionChanged()
632 bool somethingSelected = mEditor->select()->somethingSelected();
633 ui->menuSelection->setEnabled(somethingSelected);
636void MainWindow2::viewFlipped()
638 ui->actionHorizontal_Flip->setChecked(mEditor->view()->isFlipHorizontal());
639 ui->actionVertical_Flip->setChecked(mEditor->view()->isFlipVertical());
658 m2ndCloseEvent =
true;
666void MainWindow2::newDocument()
668 if (maybeSave() && !tryLoadPreset())
674void MainWindow2::openDocument()
683 openObject(fileName);
687bool MainWindow2::saveAsNewDocument()
694 return saveObject(fileName);
697void MainWindow2::openStartupFile(
const QString& filename)
699 if (tryRecoverUnsavedProject())
704 if (!filename.
isEmpty() && openObject(filename))
709 loadMostRecent() || tryLoadPreset();
712void MainWindow2::openFile(
const QString& filename)
716 openObject(filename);
720bool MainWindow2::openObject(
const QString& strFilePath)
723 hideQuestionMark(progress);
727 Status s = mEditor->openObject(strFilePath, [&progress](
int p)
729 progress.setValue(p);
731 }, [&progress](
int max)
733 progress.setRange(0, max);
738 ErrorDialog errorDialog(s.title(), s.description(), s.details().str());
740 emptyDocumentWhenErrorOccurred();
745 settings.setValue(LAST_PCLX_PATH, mEditor->object()->filePath());
748 if (!mEditor->object()->filePath().
isEmpty())
750 mRecentFileMenu->addRecentFile(mEditor->object()->filePath());
751 mRecentFileMenu->saveToDisk();
758 ui->statusBar->updateModifiedStatus(
false);
760 progress.setValue(progress.maximum());
763 updateBackupActionState();
765 if (!
QFileInfo(strFilePath).isWritable())
768 tr(
"This program does not currently have permission to write to the file you have selected. "
769 "Please make sure you have write permission for this file before attempting to save it. "
770 "Alternatively, you can use the Save As... menu option to save to a writable location."),
777bool MainWindow2::saveObject(
QString strSavedFileName)
780 hideQuestionMark(progress);
784 mEditor->prepareSave();
788 connect(&fm, &FileManager::progressChanged, [&progress](
int p)
790 progress.setValue(p);
793 connect(&fm, &FileManager::progressRangeChanged, [&progress](
int max)
795 progress.setRange(0, max + 3);
798 Status st = fm.save(mEditor->object(), strSavedFileName);
803#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
808 errorLogFolder.mkpath(
"./logs");
809 errorLogFolder.cd(
"logs");
817 out << st.details().str();
822 st.description().append(
tr(
"<br><br>An error has occurred and your file may not have saved successfully."
823 "\nIf you believe that this error is an issue with Pencil2D, please create a new issue at:"
824 "<br><a href='https://github.com/pencil2d/pencil/issues'>https://github.com/pencil2d/pencil/issues</a><br>"
825 "Please be sure to include the following details in your issue:")), st.details().html());
830 mEditor->object()->setFilePath(strSavedFileName);
831 mEditor->object()->setModified(
false);
833 mEditor->clearTemporary();
836 settings.setValue(LAST_PCLX_PATH, strSavedFileName);
838 mRecentFileMenu->addRecentFile(strSavedFileName);
839 mRecentFileMenu->saveToDisk();
841 mTimeLine->updateContent();
846 progress.setValue(progress.maximum());
848 mEditor->resetAutoSaveCounter();
853bool MainWindow2::saveDocument()
855 if (!mEditor->object()->filePath().
isEmpty())
856 return saveObject(mEditor->object()->filePath());
858 return saveAsNewDocument();
861bool MainWindow2::maybeSave()
869 tr(
"This animation has been modified.\n Do you want to save your changes?"),
872 return saveDocument();
877bool MainWindow2::autoSave()
879 if (!mEditor->object()->filePath().
isEmpty())
881 return saveDocument();
884 if (mEditor->autoSaveNeverAskAgain())
887 if(mSuppressAutoSaveDialog)
892 msgBox.setWindowTitle(
tr(
"AutoSave Reminder"));
893 msgBox.setText(
tr(
"The animation is not saved yet.\n Do you want to save now?"));
898 int ret = msgBox.exec();
901 return saveDocument();
905 mEditor->dontAskAutoSave(
true);
911void MainWindow2::emptyDocumentWhenErrorOccurred()
919void MainWindow2::importImage()
923 if (strFilePath.
isEmpty()) {
return; }
924 if (!QFile::exists(strFilePath)) {
return; }
927 OnScopeExit(
delete positionDialog)
929 positionDialog->
exec();
937 Status st = mEditor->importImage(strFilePath, importImageConfig);
940 ErrorDialog errorDialog(st.title(), st.description(), st.details().html());
945 ui->scribbleArea->updateFrame();
946 mTimeLine->updateContent();
949void MainWindow2::importImageSequence()
951 mSuppressAutoSaveDialog =
true;
954 OnScopeExit(
delete imageSeqDialog)
955 imageSeqDialog->setCore(mEditor);
959 imageSeqDialog->
exec();
966 OnScopeExit(
delete positionDialog)
968 positionDialog->
exec();
974 imageSeqDialog->importArbitrarySequence(positionDialog->importConfig());
976 mSuppressAutoSaveDialog =
false;
979void MainWindow2::importPredefinedImageSet()
982 OnScopeExit(
delete imageSeqDialog)
983 imageSeqDialog->setCore(mEditor);
987 mSuppressAutoSaveDialog =
true;
988 imageSeqDialog->
exec();
995 OnScopeExit(
delete positionDialog)
997 positionDialog->
exec();
1003 imageSeqDialog->importPredefinedSet(positionDialog->importConfig());
1004 mSuppressAutoSaveDialog =
false;
1007void MainWindow2::importLayers()
1010 importLayers->setCore(mEditor);
1012 importLayers->
open();
1015void MainWindow2::importAnimatedImage()
1018 mSuppressAutoSaveDialog =
true;
1020 mCommands->importAnimatedImage();
1022 mSuppressAutoSaveDialog =
false;
1025void MainWindow2::lockWidgets(
bool shouldLock)
1029 : (QDockWidget::DockWidgetFeature::DockWidgetClosable |
1030 QDockWidget::DockWidgetFeature::DockWidgetMovable |
1031 QDockWidget::DockWidgetFeature::DockWidgetFloatable);
1035 d->setFeatures(feat);
1036 d->lock(shouldLock);
1040void MainWindow2::preferences()
1045 mPrefDialog->
raise();
1051 mPrefDialog->init(mEditor->preference());
1053 connect(mPrefDialog, &PreferencesDialog::windowOpacityChange,
this, &MainWindow2::setOpacity);
1054 connect(mPrefDialog, &PreferencesDialog::soundScrubChanged, mEditor->playback(), &PlaybackManager::setSoundScrubActive);
1055 connect(mPrefDialog, &PreferencesDialog::soundScrubMsecChanged, mEditor->playback(), &PlaybackManager::setSoundScrubMsec);
1058 clearKeyboardShortcuts();
1059 setupKeyboardShortcuts();
1060 mPrefDialog =
nullptr;
1063 mPrefDialog->
show();
1066void MainWindow2::resetAndDockAllSubWidgets()
1069 settings.remove(SETTING_WINDOW_GEOMETRY);
1070 settings.remove(SETTING_WINDOW_STATE);
1074 dock->setFloating(
false);
1088void MainWindow2::newObject()
1090 auto object =
new Object();
1094 object->addNewCameraLayer();
1095 object->addNewBitmapLayer();
1099 object->data()->setCurrentLayer(1);
1101 mEditor->setObject(
object);
1107 updateBackupActionState();
1110bool MainWindow2::newObjectFromPresets(
int presetIndex)
1112 QString presetFilePath = PresetDialog::getPresetPath(presetIndex);
1120 Object*
object = fm.load(presetFilePath);
1122 if (!fm.error().ok() ||
object ==
nullptr)
1127 mEditor->setObject(
object);
1128 object->setFilePath(
QString());
1132 updateBackupActionState();
1137bool MainWindow2::loadMostRecent()
1139 if(!mEditor->preference()->isOn(SETTING::LOAD_MOST_RECENT))
1145 QString myPath = settings.value(LAST_PCLX_PATH,
QVariant(
"")).toString();
1146 if (myPath.
isEmpty() || !QFile::exists(myPath))
1150 return openObject(myPath);
1153bool MainWindow2::tryLoadPreset()
1155 if (!mEditor->preference()->isOn(SETTING::ASK_FOR_PRESET))
1157 int defaultPreset = mEditor->preference()->getInt(SETTING::DEFAULT_PRESET);
1158 return newObjectFromPresets(defaultPreset);
1170 int presetIndex = presetDialog->getPresetIndex();
1171 if (presetDialog->shouldAlwaysUse())
1173 mEditor->preference()->set(SETTING::ASK_FOR_PRESET, false);
1174 mEditor->preference()->set(SETTING::DEFAULT_PRESET, presetIndex);
1176 if (!newObjectFromPresets(presetIndex))
1181 presetDialog->
open();
1185void MainWindow2::closeDialogs()
1192void MainWindow2::readSettings()
1196 QVariant winGeometry = settings.
value(SETTING_WINDOW_GEOMETRY);
1202 int opacity = mEditor->preference()->getInt(SETTING::WINDOW_OPACITY);
1203 setOpacity(100 - opacity);
1205 bool isWindowsLocked = mEditor->preference()->isOn(SETTING::LAYOUT_LOCK);
1206 lockWidgets(isWindowsLocked);
1209void MainWindow2::writeSettings()
1212 settings.setValue(SETTING_WINDOW_GEOMETRY,
saveGeometry());
1213 settings.setValue(SETTING_WINDOW_STATE,
saveState());
1216void MainWindow2::setupKeyboardShortcuts()
1218 checkExistingShortcuts();
1222 strCommandName =
QString(
"shortcuts/") + strCommandName;
1228 ui->actionNew->setShortcut(cmdKeySeq(CMD_NEW_FILE));
1229 ui->actionOpen->setShortcut(cmdKeySeq(CMD_OPEN_FILE));
1230 ui->actionSave->setShortcut(cmdKeySeq(CMD_SAVE_FILE));
1231 ui->actionSave_as->setShortcut(cmdKeySeq(CMD_SAVE_AS));
1233 ui->actionImport_Image->setShortcut(cmdKeySeq(CMD_IMPORT_IMAGE));
1234 ui->actionImport_ImageSeq->setShortcut(cmdKeySeq(CMD_IMPORT_IMAGE_SEQ));
1235 ui->actionImport_ImageSeqNum->setShortcut(cmdKeySeq(CMD_IMPORT_IMAGE_PREDEFINED_SET));
1236 ui->actionImport_MovieVideo->setShortcut(cmdKeySeq(CMD_IMPORT_MOVIE_VIDEO));
1237 ui->actionImport_AnimatedImage->setShortcut(cmdKeySeq(CMD_IMPORT_ANIMATED_IMAGE));
1238 ui->actionImportLayers_from_pclx->setShortcut(cmdKeySeq(CMD_IMPORT_LAYERS));
1239 ui->actionImport_Sound->setShortcut(cmdKeySeq(CMD_IMPORT_SOUND));
1240 ui->actionImport_MovieAudio->setShortcut(cmdKeySeq(CMD_IMPORT_MOVIE_AUDIO));
1241 ui->actionImport_Append_Palette->setShortcut(cmdKeySeq(CMD_IMPORT_PALETTE));
1242 ui->actionImport_Replace_Palette->setShortcut(cmdKeySeq(CMD_IMPORT_PALETTE_REPLACE));
1244 ui->actionExport_Image->setShortcut(cmdKeySeq(CMD_EXPORT_IMAGE));
1245 ui->actionExport_ImageSeq->setShortcut(cmdKeySeq(CMD_EXPORT_IMAGE_SEQ));
1246 ui->actionExport_Movie->setShortcut(cmdKeySeq(CMD_EXPORT_MOVIE));
1247 ui->actionExport_Animated_GIF->setShortcut(cmdKeySeq(CMD_EXPORT_GIF));
1248 ui->actionExport_Palette->setShortcut(cmdKeySeq(CMD_EXPORT_PALETTE));
1251 ui->actionUndo->setShortcut(cmdKeySeq(CMD_UNDO));
1252 ui->actionRedo->setShortcut(cmdKeySeq(CMD_REDO));
1253 ui->actionCut->setShortcut(cmdKeySeq(CMD_CUT));
1254 ui->actionCopy->setShortcut(cmdKeySeq(CMD_COPY));
1255 ui->actionPaste_Previous->setShortcut(cmdKeySeq(CMD_PASTE_FROM_PREVIOUS));
1256 ui->actionPaste->setShortcut(cmdKeySeq(CMD_PASTE));
1257 ui->actionClearFrame->setShortcut(cmdKeySeq(CMD_CLEAR_FRAME));
1258 ui->actionFlip_X->setShortcut(cmdKeySeq(CMD_SELECTION_FLIP_HORIZONTAL));
1259 ui->actionFlip_Y->setShortcut(cmdKeySeq(CMD_SELECTION_FLIP_VERTICAL));
1260 ui->actionSelect_All->setShortcut(cmdKeySeq(CMD_SELECT_ALL));
1261 ui->actionDeselect_All->setShortcut(cmdKeySeq(CMD_DESELECT_ALL));
1262 ui->actionPegbarAlignment->setShortcut(cmdKeySeq(CMD_PEGBAR_ALIGNMENT));
1263 ui->actionPreference->setShortcut(cmdKeySeq(CMD_PREFERENCE));
1266 ui->actionResetWindows->setShortcut(cmdKeySeq(CMD_RESET_WINDOWS));
1267 ui->actionLockWindows->setShortcut(cmdKeySeq(CMD_LOCK_WINDOWS));
1268 ui->actionReset_View->setShortcut(cmdKeySeq(CMD_RESET_ZOOM_ROTATE));
1269 ui->actionCenter_View->setShortcut(cmdKeySeq(CMD_CENTER_VIEW));
1270 ui->actionZoom_In->setShortcut(cmdKeySeq(CMD_ZOOM_IN));
1271 ui->actionZoom_Out->setShortcut(cmdKeySeq(CMD_ZOOM_OUT));
1272 ui->actionZoom400->setShortcut(cmdKeySeq(CMD_ZOOM_400));
1273 ui->actionZoom300->setShortcut(cmdKeySeq(CMD_ZOOM_300));
1274 ui->actionZoom200->setShortcut(cmdKeySeq(CMD_ZOOM_200));
1275 ui->actionZoom100->setShortcut(cmdKeySeq(CMD_ZOOM_100));
1276 ui->actionZoom50->setShortcut(cmdKeySeq(CMD_ZOOM_50));
1277 ui->actionZoom33->setShortcut(cmdKeySeq(CMD_ZOOM_33));
1278 ui->actionZoom25->setShortcut(cmdKeySeq(CMD_ZOOM_25));
1279 ui->actionRotate_Clockwise->setShortcut(cmdKeySeq(CMD_ROTATE_CLOCK));
1280 ui->actionRotate_Anticlockwise->setShortcut(cmdKeySeq(CMD_ROTATE_ANTI_CLOCK));
1281 ui->actionReset_Rotation->setShortcut(cmdKeySeq(CMD_RESET_ROTATION));
1282 ui->actionHorizontal_Flip->setShortcut(cmdKeySeq(CMD_FLIP_HORIZONTAL));
1283 ui->actionVertical_Flip->setShortcut(cmdKeySeq(CMD_FLIP_VERTICAL));
1284 ui->actionGrid->setShortcut(cmdKeySeq(CMD_GRID));
1285 ui->actionCenter->setShortcut(cmdKeySeq(CMD_OVERLAY_CENTER));
1286 ui->actionThirds->setShortcut(cmdKeySeq(CMD_OVERLAY_THIRDS));
1287 ui->actionGoldenRatio->setShortcut(cmdKeySeq(CMD_OVERLAY_GOLDEN_RATIO));
1288 ui->actionSafeAreas->setShortcut(cmdKeySeq(CMD_OVERLAY_SAFE_AREAS));
1289 ui->actionOnePointPerspective->setShortcut(cmdKeySeq(CMD_OVERLAY_ONE_POINT_PERSPECTIVE));
1290 ui->actionTwoPointPerspective->setShortcut(cmdKeySeq(CMD_OVERLAY_TWO_POINT_PERSPECTIVE));
1291 ui->actionThreePointPerspective->setShortcut(cmdKeySeq(CMD_OVERLAY_THREE_POINT_PERSPECTIVE));
1292 ui->actionOnionPrev->setShortcut(cmdKeySeq(CMD_ONIONSKIN_PREV));
1293 ui->actionOnionNext->setShortcut(cmdKeySeq(CMD_ONIONSKIN_NEXT));
1294 ui->actionStatusBar->setShortcut(cmdKeySeq(CMD_TOGGLE_STATUS_BAR));
1297 ui->actionPlay->setShortcut(cmdKeySeq(CMD_PLAY));
1298 ui->actionLoop->setShortcut(cmdKeySeq(CMD_LOOP));
1299 ui->actionLoopControl->setShortcut(cmdKeySeq(CMD_LOOP_CONTROL));
1300 ui->actionPrevious_Frame->setShortcut(cmdKeySeq(CMD_GOTO_PREV_FRAME));
1301 ui->actionNext_Frame->setShortcut(cmdKeySeq(CMD_GOTO_NEXT_FRAME));
1302 ui->actionPrev_KeyFrame->setShortcut(cmdKeySeq(CMD_GOTO_PREV_KEY_FRAME));
1303 ui->actionNext_KeyFrame->setShortcut(cmdKeySeq(CMD_GOTO_NEXT_KEY_FRAME));
1304 ui->actionAdd_Frame->setShortcut(cmdKeySeq(CMD_ADD_FRAME));
1305 ui->actionDuplicate_Frame->setShortcut(cmdKeySeq(CMD_DUPLICATE_FRAME));
1306 ui->actionRemove_Frame->setShortcut(cmdKeySeq(CMD_REMOVE_FRAME));
1307 ui->actionAdd_Frame_Exposure->setShortcut(cmdKeySeq(CMD_SELECTION_ADD_FRAME_EXPOSURE));
1308 ui->actionSubtract_Frame_Exposure->setShortcut(cmdKeySeq(CMD_SELECTION_SUBTRACT_FRAME_EXPOSURE));
1309 ui->actionReverse_Frames_Order->setShortcut(cmdKeySeq(CMD_REVERSE_SELECTED_FRAMES));
1310 ui->actionRemove_Frames->setShortcut(cmdKeySeq(CMD_REMOVE_SELECTED_FRAMES));
1311 ui->actionMove_Frame_Backward->setShortcut(cmdKeySeq(CMD_MOVE_FRAME_BACKWARD));
1312 ui->actionMove_Frame_Forward->setShortcut(cmdKeySeq(CMD_MOVE_FRAME_FORWARD));
1313 ui->actionFlip_inbetween->setShortcut(cmdKeySeq(CMD_FLIP_INBETWEEN));
1314 ui->actionFlip_rolling->setShortcut(cmdKeySeq(CMD_FLIP_ROLLING));
1315 ui->actionReposition_Selected_Frames->setShortcut(cmdKeySeq(CMD_SELECTION_REPOSITION_FRAMES));
1318 ui->actionMove->setShortcut(cmdKeySeq(CMD_TOOL_MOVE));
1319 ui->actionSelect->setShortcut(cmdKeySeq(CMD_TOOL_SELECT));
1320 ui->actionBrush->setShortcut(cmdKeySeq(CMD_TOOL_BRUSH));
1321 ui->actionPolyline->setShortcut(cmdKeySeq(CMD_TOOL_POLYLINE));
1322 ui->actionSmudge->setShortcut(cmdKeySeq(CMD_TOOL_SMUDGE));
1323 ui->actionPen->setShortcut(cmdKeySeq(CMD_TOOL_PEN));
1324 ui->actionHand->setShortcut(cmdKeySeq(CMD_TOOL_HAND));
1325 ui->actionPencil->setShortcut(cmdKeySeq(CMD_TOOL_PENCIL));
1326 ui->actionBucket->setShortcut(cmdKeySeq(CMD_TOOL_BUCKET));
1327 ui->actionEyedropper->setShortcut(cmdKeySeq(CMD_TOOL_EYEDROPPER));
1328 ui->actionEraser->setShortcut(cmdKeySeq(CMD_TOOL_ERASER));
1329 ui->actionResetToolsDefault->setShortcut(cmdKeySeq(CMD_RESET_ALL_TOOLS));
1331 ui->actionMove->installEventFilter(shortcutFilter);
1332 ui->actionMove->installEventFilter(shortcutFilter);
1333 ui->actionSelect->installEventFilter(shortcutFilter);
1334 ui->actionBrush->installEventFilter(shortcutFilter);
1335 ui->actionPolyline->installEventFilter(shortcutFilter);
1336 ui->actionSmudge->installEventFilter(shortcutFilter);
1337 ui->actionPen->installEventFilter(shortcutFilter);
1338 ui->actionHand->installEventFilter(shortcutFilter);
1339 ui->actionPencil->installEventFilter(shortcutFilter);
1340 ui->actionBucket->installEventFilter(shortcutFilter);
1341 ui->actionEyedropper->installEventFilter(shortcutFilter);
1342 ui->actionEraser->installEventFilter(shortcutFilter);
1345 ui->actionNew_Bitmap_Layer->setShortcut(cmdKeySeq(CMD_NEW_BITMAP_LAYER));
1346 ui->actionNew_Vector_Layer->setShortcut(cmdKeySeq(CMD_NEW_VECTOR_LAYER));
1347 ui->actionNew_Camera_Layer->setShortcut(cmdKeySeq(CMD_NEW_CAMERA_LAYER));
1348 ui->actionNew_Sound_Layer->setShortcut(cmdKeySeq(CMD_NEW_SOUND_LAYER));
1349 ui->actionDelete_Current_Layer->setShortcut(cmdKeySeq(CMD_DELETE_CUR_LAYER));
1350 ui->actionChangeLineColorCurrent_keyframe->setShortcut(cmdKeySeq(CMD_CHANGE_LINE_COLOR_KEYFRAME));
1351 ui->actionChangeLineColorAll_keyframes_on_layer->setShortcut(cmdKeySeq(CMD_CHANGE_LINE_COLOR_LAYER));
1352 ui->actionChangeLayerOpacity->setShortcut(cmdKeySeq(CMD_CHANGE_LAYER_OPACITY));
1354 ui->actionVisibilityCurrentLayerOnly->setShortcut(cmdKeySeq(CMD_CURRENT_LAYER_VISIBILITY));
1355 ui->actionVisibilityRelative->setShortcut(cmdKeySeq(CMD_RELATIVE_LAYER_VISIBILITY));
1356 ui->actionVisibilityAll->setShortcut(cmdKeySeq(CMD_ALL_LAYER_VISIBILITY));
1358 mToolBox->toggleViewAction()->setShortcut(cmdKeySeq(CMD_TOGGLE_TOOLBOX));
1366 ui->actionHelp->setShortcut(cmdKeySeq(CMD_HELP));
1367 ui->actionExit->setShortcut(cmdKeySeq(CMD_EXIT));
1370void MainWindow2::clearKeyboardShortcuts()
1373 for (
QAction* action : actionList)
1379void MainWindow2::exportPalette()
1384 mEditor->object()->exportPalette(filePath);
1388void MainWindow2::importPalette()
1393 mEditor->object()->importPalette(filePath);
1394 mColorPalette->refreshColorList();
1395 mColorPalette->adjustSwatches();
1396 mEditor->color()->setColorNumber(0);
1400void MainWindow2::openPalette()
1402 for (
int i = 0; i < mEditor->object()->getColorCount(); i++)
1404 if (!mEditor->object()->isColorInUse(i))
1410 msgBox.
setText(
tr(
"Opening a palette will replace the old palette.\n"
1411 "Color(s) in strokes will be altered by this action!"));
1427 mEditor->object()->openPalette(filePath);
1428 mColorPalette->refreshColorList();
1429 mEditor->color()->setColorNumber(0);
1432void MainWindow2::makeConnections(
Editor* editor)
1434 connect(editor->undoRedo(), &UndoRedoManager::didUpdateUndoStack,
this, &MainWindow2::updateSaveState);
1435 connect(editor->undoRedo(), &UndoRedoManager::didUpdateUndoStack,
this, &MainWindow2::updateBackupActionState);
1436 connect(editor, &Editor::needDisplayInfo,
this, &MainWindow2::displayMessageBox);
1437 connect(editor, &Editor::needDisplayInfoNoTitle,
this, &MainWindow2::displayMessageBoxNoTitle);
1438 connect(editor->layers(), &LayerManager::currentLayerChanged,
this, &MainWindow2::currentLayerChanged);
1439 connect(editor->select(), &SelectionManager::selectionChanged,
this, &MainWindow2::selectionChanged);
1440 connect(editor, &Editor::canCopyChanged,
this, [=](
bool canCopy) {
1441 ui->actionCopy->setEnabled(canCopy);
1442 ui->actionCut->setEnabled(canCopy);
1447void MainWindow2::makeConnections(
Editor* editor,
ColorBox* colorBox)
1449 connect(colorBox, &ColorBox::colorChanged, editor->color(), &ColorManager::setFrontColor);
1450 connect(editor->color(), &ColorManager::colorChanged, colorBox, &ColorBox::setColor);
1455 connect(colorInspector, &ColorInspector::colorChanged, editor->color(), &ColorManager::setFrontColor);
1456 connect(editor->color(), &ColorManager::colorChanged, colorInspector, &ColorInspector::setColor);
1461 connect(editor->tools(), &ToolManager::toolChanged, scribbleArea, &ScribbleArea::updateToolCursor);
1462 connect(editor->tools(), &ToolManager::toolChanged, mToolBox, &ToolBoxDockWidget::setActiveTool);
1463 connect(editor->tools(), &ToolManager::toolPropertyChanged, scribbleArea, &ScribbleArea::updateToolCursor);
1475void MainWindow2::makeConnections(
Editor* pEditor,
TimeLine* pTimeline)
1478 connect(pTimeline, &TimeLine::duplicateLayerClick, mCommands, &ActionCommands::duplicateLayer);
1479 connect(pTimeline, &TimeLine::duplicateKeyClick, mCommands, &ActionCommands::duplicateKey);
1481 connect(pTimeline, &TimeLine::soundClick, pPlaybackManager, &PlaybackManager::enableSound);
1482 connect(pTimeline, &TimeLine::fpsChanged, pPlaybackManager, &PlaybackManager::setFps);
1483 connect(pTimeline, &TimeLine::fpsChanged, pEditor, &Editor::setFps);
1486 connect(pTimeline, &TimeLine::removeKeyClick, mCommands, &ActionCommands::removeKey);
1488 connect(pTimeline, &TimeLine::newBitmapLayer, mCommands, &ActionCommands::addNewBitmapLayer);
1489 connect(pTimeline, &TimeLine::newVectorLayer, mCommands, &ActionCommands::addNewVectorLayer);
1490 connect(pTimeline, &TimeLine::newSoundLayer, mCommands, &ActionCommands::addNewSoundLayer);
1491 connect(pTimeline, &TimeLine::newCameraLayer, mCommands, &ActionCommands::addNewCameraLayer);
1492 connect(mTimeLine, &TimeLine::playButtonTriggered, mCommands, &ActionCommands::PlayStop);
1493 connect(pTimeline, &TimeLine::deleteCurrentLayerClick, mCommands, &ActionCommands::deleteCurrentLayer);
1497 connect(pTimeline, &TimeLine::selectionChanged,
this, &MainWindow2::updateCopyCutPasteEnabled);
1499 connect(mEditor->select(), &SelectionManager::selectionChanged,
this, &MainWindow2::updateCopyCutPasteEnabled);
1501 connect(pEditor->layers(), &LayerManager::currentLayerChanged, pTimeline, &TimeLine::updateUI);
1503 connect(pEditor->sound(), &SoundManager::soundClipDurationChanged, pTimeline, &TimeLine::updateUI);
1508 connect(pEditor, &Editor::objectLoaded, pTimeline, &TimeLine::onObjectLoaded);
1509 connect(pEditor, &Editor::updateTimeLine, pTimeline, &TimeLine::updateUI);
1510 connect(pEditor, &Editor::updateTimeLineCached, pTimeline, &TimeLine::updateUICached);
1512 connect(pEditor->layers(), &LayerManager::currentLayerChanged,
this, &MainWindow2::updateLayerMenu);
1513 connect(pEditor->layers(), &LayerManager::currentLayerChanged, mToolOptions, &ToolOptionWidget::updateUI);
1522 toolOptions->makeConnectionToEditor(editor);
1527 connect(pEditor, &Editor::objectLoaded, pColorPalette, &ColorPaletteWidget::updateUI);
1530 ScribbleArea* pScribbleArea = pEditor->getScribbleArea();
1532 connect(pColorPalette, &ColorPaletteWidget::colorNumberChanged, pColorManager, &ColorManager::setColorNumber);
1533 connect(pColorManager, &ColorManager::colorNumberChanged, pScribbleArea, &ScribbleArea::paletteColorChanged);
1534 connect(pColorManager, &ColorManager::colorNumberChanged, pColorPalette, &ColorPaletteWidget::selectColorNumber);
1537void MainWindow2::makeConnections(
Editor* editor,
StatusBar *statusBar)
1546void MainWindow2::updateCopyCutPasteEnabled()
1548 bool canCopy = mEditor->canCopy();
1549 bool canPaste = mEditor->canPaste();
1551 ui->actionCopy->setEnabled(canCopy);
1552 ui->actionCut->setEnabled(canCopy);
1553 ui->actionPaste->setEnabled(canPaste);
1556void MainWindow2::updateLayerMenu()
1558 ui->actionDelete_Current_Layer->setEnabled(mEditor->layers()->canDeleteLayer(mEditor->currentLayerIndex()));
1561void MainWindow2::changePlayState(
bool isPlaying)
1565 ui->actionPlay->setText(
tr(
"Stop"));
1566 ui->actionPlay->setIcon(mStopIcon);
1570 ui->actionPlay->setText(
tr(
"Play"));
1571 ui->actionPlay->setIcon(mStartIcon);
1576void MainWindow2::importMovieVideo()
1579 mSuppressAutoSaveDialog =
true;
1581 mCommands->importMovieVideo();
1583 mSuppressAutoSaveDialog =
false;
1586bool MainWindow2::event(
QEvent* event)
1594void MainWindow2::displayMessageBox(
const QString& title,
const QString& body)
1599void MainWindow2::displayMessageBoxNoTitle(
const QString& body)
1604bool MainWindow2::tryRecoverUnsavedProject()
1607 QStringList recoverables = fm.searchForUnsavedProjects();
1609 if (recoverables.empty())
1614 QString caption =
tr(
"Restore Project?");
1615 QString text =
tr(
"Pencil2D didn't close correctly. Would you like to restore the project?");
1617 QString recoverPath = recoverables[0];
1628 hideQuestionMark(*msgBox);
1635void MainWindow2::startProjectRecovery(
int result)
1650 Object* o = fm.recoverUnsavedProject(recoverPath);
1651 if (!fm.error().ok())
1653 Q_ASSERT(o ==
nullptr);
1654 const QString title =
tr(
"Recovery Failed.");
1655 const QString text =
tr(
"Sorry! Pencil2D is unable to restore your project");
1661 mEditor->setObject(o);
1663 updateBackupActionState();
1665 const QString title =
tr(
"Recovery Succeeded!");
1666 const QString text =
tr(
"Please save your work immediately to prevent loss of data");
1670void MainWindow2::createToolbars()
1675 mMainToolbar->
addAction(ui->actionOpen);
1676 mMainToolbar->
addAction(ui->actionSave);
1678 mMainToolbar->
addAction(ui->actionUndo);
1679 mMainToolbar->
addAction(ui->actionRedo);
1682 mMainToolbar->
addAction(ui->actionCopy);
1683 mMainToolbar->
addAction(ui->actionPaste);
1684 mMainToolbar->
addAction(ui->actionClearFrame);
1688 mViewToolbar->
addAction(ui->actionZoom_In);
1689 mViewToolbar->
addAction(ui->actionZoom_Out);
1690 mViewToolbar->
addAction(ui->actionReset_View);
1692 mViewToolbar->
addAction(ui->actionHorizontal_Flip);
1693 mViewToolbar->
addAction(ui->actionVertical_Flip);
1695 mViewToolbar->
addAction(ui->actionShowInvisibleLines);
1696 mViewToolbar->
addAction(ui->actionShowOutlinesOnly);
1700 mOverlayToolbar->
addAction(ui->actionGrid);
1701 mOverlayToolbar->
addAction(ui->actionCenter);
1702 mOverlayToolbar->
addAction(ui->actionThirds);
1703 mOverlayToolbar->
addAction(ui->actionGoldenRatio);
1704 mOverlayToolbar->
addAction(ui->actionSafeAreas);
1705 mOverlayToolbar->
addAction(ui->actionOnePointPerspective);
1706 mOverlayToolbar->
addAction(ui->actionTwoPointPerspective);
1707 mOverlayToolbar->
addAction(ui->actionThreePointPerspective);
1713 perspectiveLinesAngleButton->
setDefaultAction(ui->menuPerspectiveLinesAngle->menuAction());
1715 mOverlayToolbar->
addWidget(perspectiveLinesAngleButton);
1717 mToolbars = { mMainToolbar, mViewToolbar, mOverlayToolbar };
1721 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 open(QObject *receiver, const char *member)
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)
QVariant property(const char *name) const const
QObject * sender() const const
bool setProperty(const char *name, const QVariant &value)
QString tr(const char *sourceText, const char *disambiguation, int n)
QString writableLocation(QStandardPaths::StandardLocation type)
bool isEmpty() const const
QString & prepend(QChar ch)
void keySequence(QWindow *window, const QKeySequence &keySequence)
char * toString(const T &value)
QByteArray toByteArray() const const
QString toString() const const