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"
85#include "autosaverbytime.h"
89#define BUILD_DATE S__GIT_TIMESTAMP
91#define BUILD_DATE __DATE__
97 if (version.startsWith(
"99.0.0")) {
98 return QString(
"[*]Pencil2D Nightly Build %1").
arg(BUILD_DATE);
99 }
else if (version ==
"0.0.0.0") {
100 return QString(
"[*]Pencil2D Development Build %1").
arg(BUILD_DATE);
102 return QString(
"[*]Pencil2D %1").
arg(APP_VERSION);
109MainWindow2::MainWindow2(
QWidget* parent) :
117 mEditor =
new Editor(
this);
118 mEditor->setScribbleArea(ui->scribbleArea);
123 ui->scribbleArea->setEditor(mEditor);
124 ui->scribbleArea->init();
126 ui->statusBar->setEditor(mEditor);
127 ui->statusBar->updateZoomStatus();
128 ui->statusBar->setVisible(mEditor->preference()->isOn(SETTING::SHOW_STATUS_BAR));
131 mCommands->setCore(mEditor);
136 setupKeyboardShortcuts();
141 currentLayerChanged();
143 connect(mEditor, &Editor::needSave,
this, &MainWindow2::autoSave);
146 connect(mAutoSaver, &AutosaverByTime::timeout,
this, &MainWindow2::autoSaveTimeout);
148 mEditor->tools()->setDefaultTool();
149 ui->background->init(mEditor->preference());
151 setWindowTitle(getWindowTitle());
154void MainWindow2::autoSaveTimeout()
157 fm.writeToWorkingFolder(mEditor->object());
160MainWindow2::~MainWindow2()
165void MainWindow2::createDockWidgets()
171 mColorBox->
setToolTip(
tr(
"color palette:<br>use <b>(C)</b><br>toggle at cursor"));
179 mColorPalette->setCore(mEditor);
200 mStartIcon =
QIcon(
":icons/controls/play.png");
201 mStopIcon =
QIcon(
":icons/controls/stop.png");
206 pWidget->setFeatures(QDockWidget::DockWidgetFeature::DockWidgetClosable |
207 QDockWidget::DockWidgetFeature::DockWidgetMovable |
208 QDockWidget::DockWidgetFeature::DockWidgetFloatable);
211 pWidget->setEditor(mEditor);
213 qDebug() <<
"Init Dock widget: " << pWidget->objectName();
233 makeConnections(mEditor, ui->scribbleArea);
234 makeConnections(mEditor);
235 makeConnections(mEditor, mTimeLine);
236 makeConnections(mEditor, mColorBox);
237 makeConnections(mEditor, mColorInspector);
238 makeConnections(mEditor, mColorPalette);
239 makeConnections(mEditor, mToolOptions);
240 makeConnections(mEditor, ui->statusBar);
244 if (w->isFloating()) {
252void MainWindow2::createMenus()
285 replaceUndoRedoActions();
291 connect(mEditor->select(), &SelectionManager::selectionChanged,
this, &MainWindow2::selectionChanged);
307 connect(ui->actionChangeLineColorCurrent_keyframe, &
QAction::triggered, mCommands, &ActionCommands::changeKeyframeLineColor);
308 connect(ui->actionChangeLineColorAll_keyframes_on_layer, &
QAction::triggered, mCommands, &ActionCommands::changeallKeyframeLineColor);
311 QList<QAction*> visibilityActions = ui->menuLayer_Visibility->actions();
313 visibilityGroup->setExclusive(
true);
314 for (
int i = 0; i < visibilityActions.
size(); i++) {
315 QAction* action = visibilityActions[i];
316 visibilityGroup->addAction(action);
319 visibilityActions[mEditor->preference()->getInt(SETTING::LAYER_VISIBILITY)]->setChecked(
true);
320 connect(mEditor->preference(), &PreferenceManager::optionChanged, [=](SETTING e) {
321 if (e == SETTING::LAYER_VISIBILITY) {
322 visibilityActions[mEditor->preference()->getInt(SETTING::LAYER_VISIBILITY)]->setChecked(true);
328 connect(ui->actionZoom_Out, &
QAction::triggered, mCommands, &ActionCommands::ZoomOut);
329 connect(ui->actionRotate_Clockwise, &
QAction::triggered, mCommands, &ActionCommands::rotateClockwise);
330 connect(ui->actionRotate_Anticlockwise, &
QAction::triggered, mCommands, &ActionCommands::rotateCounterClockwise);
331 connect(ui->actionReset_Rotation, &
QAction::triggered, mEditor->view(), &ViewManager::resetRotation);
332 connect(ui->actionReset_View, &
QAction::triggered, mEditor->view(), &ViewManager::resetView);
333 connect(ui->actionCenter_View, &
QAction::triggered, mEditor->view(), &ViewManager::centerView);
334 connect(ui->actionZoom400, &
QAction::triggered, mEditor->view(), &ViewManager::scale400);
335 connect(ui->actionZoom300, &
QAction::triggered, mEditor->view(), &ViewManager::scale300);
336 connect(ui->actionZoom200, &
QAction::triggered, mEditor->view(), &ViewManager::scale200);
337 connect(ui->actionZoom100, &
QAction::triggered, mEditor->view(), &ViewManager::scale100);
338 connect(ui->actionZoom50, &
QAction::triggered, mEditor->view(), &ViewManager::scale50);
339 connect(ui->actionZoom33, &
QAction::triggered, mEditor->view(), &ViewManager::scale33);
340 connect(ui->actionZoom25, &
QAction::triggered, mEditor->view(), &ViewManager::scale25);
341 connect(ui->actionHorizontal_Flip, &
QAction::triggered, mEditor->view(), &ViewManager::flipHorizontal);
342 connect(ui->actionVertical_Flip, &
QAction::triggered, mEditor->view(), &ViewManager::flipVertical);
343 connect(mEditor->view(), &ViewManager::viewFlipped,
this, &MainWindow2::viewFlipped);
347 bindPreferenceSetting(ui->actionStatusBar, prefs, SETTING::SHOW_STATUS_BAR);
348 bindPreferenceSetting(ui->actionThreePointPerspective, prefs, SETTING::OVERLAY_PERSPECTIVE3);
349 bindPreferenceSetting(ui->actionTwoPointPerspective, prefs, SETTING::OVERLAY_PERSPECTIVE2);
350 bindPreferenceSetting(ui->actionOnePointPerspective, prefs, SETTING::OVERLAY_PERSPECTIVE1);
351 bindPreferenceSetting(ui->actionSafeAreas, prefs, SETTING::OVERLAY_SAFE);
352 bindPreferenceSetting(ui->actionGoldenRatio, prefs, SETTING::OVERLAY_GOLDEN);
353 bindPreferenceSetting(ui->actionThirds, prefs, SETTING::OVERLAY_THIRDS);
354 bindPreferenceSetting(ui->actionCenter, prefs, SETTING::OVERLAY_CENTER);
355 bindPreferenceSetting(ui->actionGrid, prefs, SETTING::GRID);
356 bindPreferenceSetting(ui->actionShowOutlinesOnly, prefs, SETTING::OUTLINES);
357 bindPreferenceSetting(ui->actionShowInvisibleLines, prefs, SETTING::INVISIBLE_LINES);
358 bindPreferenceSetting(ui->actionOnionPrev, prefs, SETTING::PREV_ONION);
359 bindPreferenceSetting(ui->actionOnionNext, prefs, SETTING::NEXT_ONION);
361 bool enableSafeArea = (prefs->isOn(SETTING::ACTION_SAFE_ON) || prefs->isOn(SETTING::TITLE_SAFE_ON));
362 ui->actionSafeAreas->setEnabled(enableSafeArea);
364 auto perspectiveLinesAngleGroup =
new QActionGroup(
this);
365 perspectiveLinesAngleGroup->setExclusive(
true);
366 perspectiveLinesAngleGroup->addAction(ui->action2Degrees);
367 perspectiveLinesAngleGroup->addAction(ui->action3Degrees);
368 perspectiveLinesAngleGroup->addAction(ui->action5Degrees);
369 perspectiveLinesAngleGroup->addAction(ui->action7_5Degrees);
370 perspectiveLinesAngleGroup->addAction(ui->action10Degrees);
371 perspectiveLinesAngleGroup->addAction(ui->action15Degrees);
372 perspectiveLinesAngleGroup->addAction(ui->action20Degrees);
373 perspectiveLinesAngleGroup->addAction(ui->action30Degrees);
375 if (action == ui->action2Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 2);
376 else if (action == ui->action3Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 3);
377 else if (action == ui->action5Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 5);
378 else if (action == ui->action7_5Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 7);
379 else if (action == ui->action10Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 10);
380 else if (action == ui->action15Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 15);
381 else if (action == ui->action20Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 20);
382 else if (action == ui->action30Degrees) mEditor->preference()->set(SETTING::OVERLAY_ANGLE, 30);
383 else Q_UNREACHABLE();
384 emit mEditor->view()->viewChanged();
387 switch (prefs->getInt(SETTING::OVERLAY_ANGLE)) {
388 case 2: ui->action2Degrees->setChecked(
true);
break;
389 case 3: ui->action3Degrees->setChecked(
true);
break;
390 case 5: ui->action5Degrees->setChecked(
true);
break;
391 case 7: ui->action7_5Degrees->setChecked(
true);
break;
392 case 10: ui->action10Degrees->setChecked(
true);
break;
393 case 15: ui->action15Degrees->setChecked(
true);
break;
394 case 20: ui->action20Degrees->setChecked(
true);
break;
395 case 30: ui->action30Degrees->setChecked(
true);
break;
402 connect(ui->actionLoop, &
QAction::triggered, pPlaybackManager, &PlaybackManager::setLooping);
403 connect(ui->actionLoopControl, &
QAction::triggered, pPlaybackManager, &PlaybackManager::enableRangedPlayback);
404 connect(pPlaybackManager, &PlaybackManager::loopStateChanged, ui->actionLoop, &
QAction::setChecked);
405 connect(pPlaybackManager, &PlaybackManager::loopStateChanged, mTimeLine, &TimeLine::setLoop);
406 connect(pPlaybackManager, &PlaybackManager::rangedPlaybackStateChanged, ui->actionLoopControl, &
QAction::setChecked);
407 connect(pPlaybackManager, &PlaybackManager::rangedPlaybackStateChanged, mTimeLine, &TimeLine::setRangeState);
408 connect(pPlaybackManager, &PlaybackManager::playStateChanged, mTimeLine, &TimeLine::setPlaying);
409 connect(pPlaybackManager, &PlaybackManager::playStateChanged,
this, &MainWindow2::changePlayState);
411 connect(ui->actionFlip_inbetween, &
QAction::triggered, pPlaybackManager, &PlaybackManager::playFlipInBetween);
412 connect(ui->actionFlip_rolling, &
QAction::triggered, pPlaybackManager, &PlaybackManager::playFlipRoll);
415 connect(ui->actionRemove_Frame, &
QAction::triggered, mCommands, &ActionCommands::removeKey);
416 connect(ui->actionAdd_Frame_Exposure, &
QAction::triggered, mCommands, &ActionCommands::addExposureToSelectedFrames);
417 connect(ui->actionSubtract_Frame_Exposure, &
QAction::triggered, mCommands, &ActionCommands::subtractExposureFromSelectedFrames);
418 connect(ui->actionNext_Frame, &
QAction::triggered, mCommands, &ActionCommands::GotoNextFrame);
419 connect(ui->actionPrevious_Frame, &
QAction::triggered, mCommands, &ActionCommands::GotoPrevFrame);
420 connect(ui->actionNext_KeyFrame, &
QAction::triggered, mCommands, &ActionCommands::GotoNextKeyFrame);
421 connect(ui->actionPrev_KeyFrame, &
QAction::triggered, mCommands, &ActionCommands::GotoPrevKeyFrame);
422 connect(ui->actionDuplicate_Frame, &
QAction::triggered, mCommands, &ActionCommands::duplicateKey);
423 connect(ui->actionMove_Frame_Forward, &
QAction::triggered, mCommands, &ActionCommands::moveFrameForward);
424 connect(ui->actionMove_Frame_Backward, &
QAction::triggered, mCommands, &ActionCommands::moveFrameBackward);
426 connect(ui->actionReverse_Frames_Order, &
QAction::triggered, mCommands, &ActionCommands::reverseSelectedFrames);
427 connect(ui->actionRemove_Frames, &
QAction::triggered, mCommands, &ActionCommands::removeSelectedFrames);
431 toolsActionGroup->setExclusive(
true);
432 toolsActionGroup->addAction(ui->actionMove);
433 toolsActionGroup->addAction(ui->actionSelect);
434 toolsActionGroup->addAction(ui->actionBrush);
435 toolsActionGroup->addAction(ui->actionPolyline);
436 toolsActionGroup->addAction(ui->actionSmudge);
437 toolsActionGroup->addAction(ui->actionPen);
438 toolsActionGroup->addAction(ui->actionHand);
439 toolsActionGroup->addAction(ui->actionPencil);
440 toolsActionGroup->addAction(ui->actionBucket);
441 toolsActionGroup->addAction(ui->actionEyedropper);
442 toolsActionGroup->addAction(ui->actionEraser);
443 toolsActionGroup->addAction(ui->actionResetToolsDefault);
446 if (action == ui->actionMove) mToolBox->setActiveTool(MOVE);
447 else if (action == ui->actionSelect) mToolBox->setActiveTool(SELECT);
448 else if (action == ui->actionBrush) mToolBox->setActiveTool(BRUSH);
449 else if (action == ui->actionPolyline) mToolBox->setActiveTool(POLYLINE);
450 else if (action == ui->actionSmudge) mToolBox->setActiveTool(SMUDGE);
451 else if (action == ui->actionPen) mToolBox->setActiveTool(PEN);
452 else if (action == ui->actionHand) mToolBox->setActiveTool(HAND);
453 else if (action == ui->actionPencil) mToolBox->setActiveTool(PENCIL);
454 else if (action == ui->actionBucket) mToolBox->setActiveTool(BUCKET);
455 else if (action == ui->actionEyedropper) mToolBox->setActiveTool(EYEDROPPER);
456 else if (action == ui->actionEraser) mToolBox->setActiveTool(ERASER);
457 else if (action == ui->actionResetToolsDefault) mCommands->resetAllTools();
458 else Q_UNREACHABLE();
462 QMenu* winMenu = ui->menuWindows;
463 const std::vector<QAction*> actions
465 mToolBox->toggleViewAction(),
466 mToolOptions->toggleViewAction(),
467 mColorBox->toggleViewAction(),
468 mColorPalette->toggleViewAction(),
469 mTimeLine->toggleViewAction(),
470 mColorInspector->toggleViewAction(),
471 mOnionSkinWidget->toggleViewAction()
474 for (
QAction* action : actions)
477 winMenu->insertAction(ui->menuToolbars->menuAction(), action);
479 winMenu->insertSeparator(ui->menuToolbars->menuAction());
480 connect(ui->actionResetWindows, &
QAction::triggered,
this, &MainWindow2::resetAndDockAllSubWidgets);
481 connect(ui->actionLockWindows, &
QAction::toggled,
this, &MainWindow2::lockWidgets);
482 bindPreferenceSetting(ui->actionLockWindows, prefs, SETTING::LAYOUT_LOCK);
486 connect(ui->actionQuick_Guide, &
QAction::triggered, mCommands, &ActionCommands::quickGuide);
490 connect(ui->actionCheck_for_Updates, &
QAction::triggered, mCommands, &ActionCommands::checkForUpdates);
491 connect(ui->actionReport_Bug, &
QAction::triggered, mCommands, &ActionCommands::reportbug);
492 connect(ui->actionOpen_Temporary_Directory, &
QAction::triggered, mCommands, &ActionCommands::openTemporaryDirectory);
497 mRecentFileMenu->loadFromDisk();
498 ui->menuFile->insertMenu(ui->actionSave, mRecentFileMenu);
500 connect(mRecentFileMenu, &RecentFileMenu::loadRecentFile,
this, &MainWindow2::openFile);
503void MainWindow2::replaceUndoRedoActions()
505 ui->menuEdit->removeAction(ui->actionUndo);
506 ui->menuEdit->removeAction(ui->actionRedo);
507 ui->actionUndo = mEditor->undoRedo()->createUndoAction(
this, ui->actionUndo->icon());
508 ui->actionRedo = mEditor->undoRedo()->createRedoAction(
this, ui->actionRedo->icon());
509 ui->menuEdit->insertAction(ui->actionCut, ui->actionUndo);
510 ui->menuEdit->insertAction(ui->actionCut, ui->actionRedo);
513void MainWindow2::setOpacity(
int opacity)
515 mEditor->preference()->set(SETTING::WINDOW_OPACITY, 100 - opacity);
519void MainWindow2::updateSaveState()
523 ui->statusBar->updateModifiedStatus(hasUnsavedChanges);
526void MainWindow2::updateBackupActionState()
528 mEditor->undoRedo()->updateUndoAction(ui->actionUndo);
529 mEditor->undoRedo()->updateRedoAction(ui->actionRedo);
532void MainWindow2::openPegAlignDialog()
534 if (mPegAlign !=
nullptr)
537 tr(
"Dialog is already open!"),
547 flags &= (
~Qt::WindowContextHelpButtonHint);
556void MainWindow2::openLayerOpacityDialog()
558 if (mLayerOpacityDialog !=
nullptr)
561 tr(
"Dialog is already open!"),
567 mLayerOpacityDialog->setCore(mEditor);
568 mLayerOpacityDialog->initUI();
570 mLayerOpacityDialog->
show();
574 mLayerOpacityDialog =
nullptr;
578void MainWindow2::openAddTranspToPaperDialog()
580 if (mAddTranspToPaper)
583 mAddTranspToPaper->
raise();
588 mAddTranspToPaper->setCore(mEditor);
589 mAddTranspToPaper->initUI();
591 mAddTranspToPaper->
show();
597 mSuppressAutoSaveDialog =
true;
598 mAddTranspToPaper->traceScannedDrawings();
599 mSuppressAutoSaveDialog =
false;
602 mAddTranspToPaper =
nullptr;
606void MainWindow2::openRepositionDialog()
608 if (mEditor->layers()->currentLayer()->getSelectedFramesByPos().
count() < 2)
611 tr(
"Please select at least 2 frames!"),
615 if (mReposDialog !=
nullptr)
623 hideQuestionMark(*mReposDialog);
624 mReposDialog->setCore(mEditor);
625 mReposDialog->initUI();
626 mEditor->tools()->setCurrentTool(ToolType::MOVE);
628 mReposDialog->
show();
631void MainWindow2::closeRepositionDialog()
634 mReposDialog =
nullptr;
637void MainWindow2::currentLayerChanged()
639 bool isBitmap = (mEditor->layers()->currentLayer()->type() == Layer::BITMAP);
640 ui->menuChange_line_color->setEnabled(isBitmap);
642 bool isVector = (mEditor->layers()->currentLayer()->type() == Layer::VECTOR);
643 ui->actionShowInvisibleLines->setEnabled(isVector);
644 ui->actionShowOutlinesOnly->setEnabled(isVector);
647void MainWindow2::selectionChanged()
649 bool somethingSelected = mEditor->select()->somethingSelected();
650 ui->menuSelection->setEnabled(somethingSelected);
653void MainWindow2::viewFlipped()
655 ui->actionHorizontal_Flip->setChecked(mEditor->view()->isFlipHorizontal());
656 ui->actionVertical_Flip->setChecked(mEditor->view()->isFlipVertical());
675 m2ndCloseEvent =
true;
683void MainWindow2::newDocument()
685 if (maybeSave() && !tryLoadPreset())
691void MainWindow2::openDocument()
700 openObject(fileName);
704bool MainWindow2::saveAsNewDocument()
711 return saveObject(fileName);
714void MainWindow2::openStartupFile(
const QString& filename)
716 if (checkForRecoverableProjects())
721 if (!filename.
isEmpty() && openObject(filename))
726 loadMostRecent() || tryLoadPreset();
729void MainWindow2::openFile(
const QString& filename)
733 openObject(filename);
737bool MainWindow2::openObject(
const QString& strFilePath)
740 hideQuestionMark(progress);
744 Status s = mEditor->openObject(strFilePath, [&progress](
int p)
746 progress.setValue(p);
748 }, [&progress](
int max)
750 progress.setRange(0, max);
755 ErrorDialog errorDialog(s.title(), s.description(), s.details().str());
757 emptyDocumentWhenErrorOccurred();
762 settings.setValue(LAST_PCLX_PATH, mEditor->object()->filePath());
765 if (!mEditor->object()->filePath().
isEmpty())
767 mRecentFileMenu->addRecentFile(mEditor->object()->filePath());
768 mRecentFileMenu->saveToDisk();
775 ui->statusBar->updateModifiedStatus(
false);
777 progress.setValue(progress.maximum());
780 updateBackupActionState();
782 if (!
QFileInfo(strFilePath).isWritable())
785 tr(
"This program does not currently have permission to write to the file you have selected. "
786 "Please make sure you have write permission for this file before attempting to save it. "
787 "Alternatively, you can use the Save As... menu option to save to a writable location."),
794bool MainWindow2::saveObject(
QString strSavedFileName)
797 hideQuestionMark(progress);
801 mEditor->prepareSave();
805 connect(&fm, &FileManager::progressChanged, [&progress](
int p)
807 progress.setValue(p);
810 connect(&fm, &FileManager::progressRangeChanged, [&progress](
int max)
812 progress.setRange(0, max + 3);
815 Status st = fm.save(mEditor->object(), strSavedFileName);
820#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
825 errorLogFolder.mkpath(
"./logs");
826 errorLogFolder.cd(
"logs");
834 out << st.details().str();
839 st.description().append(
tr(
"<br><br>An error has occurred and your file may not have saved successfully."
840 "\nIf you believe that this error is an issue with Pencil2D, please create a new issue at:"
841 "<br><a href='https://github.com/pencil2d/pencil/issues'>https://github.com/pencil2d/pencil/issues</a><br>"
842 "Please be sure to include the following details in your issue:")), st.details().html());
847 mEditor->object()->setFilePath(strSavedFileName);
848 mEditor->object()->setModified(
false);
850 mEditor->clearTemporary();
853 settings.setValue(LAST_PCLX_PATH, strSavedFileName);
855 mRecentFileMenu->addRecentFile(strSavedFileName);
856 mRecentFileMenu->saveToDisk();
858 mTimeLine->updateContent();
863 progress.setValue(progress.maximum());
865 mEditor->resetAutoSaveCounter();
870bool MainWindow2::saveDocument()
872 if (!mEditor->object()->filePath().
isEmpty())
873 return saveObject(mEditor->object()->filePath());
875 return saveAsNewDocument();
878bool MainWindow2::maybeSave()
886 tr(
"This animation has been modified.\n Do you want to save your changes?"),
889 return saveDocument();
894bool MainWindow2::autoSave()
896 if (!mEditor->object()->filePath().
isEmpty())
898 return saveDocument();
901 if (mEditor->autoSaveNeverAskAgain())
904 if(mSuppressAutoSaveDialog)
909 msgBox.setWindowTitle(
tr(
"AutoSave Reminder"));
910 msgBox.setText(
tr(
"The animation is not saved yet.\n Do you want to save now?"));
915 int ret = msgBox.exec();
918 return saveDocument();
922 mEditor->dontAskAutoSave(
true);
928void MainWindow2::emptyDocumentWhenErrorOccurred()
936void MainWindow2::importImage()
940 if (strFilePath.
isEmpty()) {
return; }
941 if (!QFile::exists(strFilePath)) {
return; }
944 OnScopeExit(
delete positionDialog)
946 positionDialog->
exec();
954 Status st = mEditor->importImage(strFilePath, importImageConfig);
957 ErrorDialog errorDialog(st.title(), st.description(), st.details().html());
962 ui->scribbleArea->updateFrame();
963 mTimeLine->updateContent();
966void MainWindow2::importImageSequence()
968 mSuppressAutoSaveDialog =
true;
971 OnScopeExit(
delete imageSeqDialog)
972 imageSeqDialog->setCore(mEditor);
976 imageSeqDialog->
exec();
983 OnScopeExit(
delete positionDialog)
985 positionDialog->
exec();
991 imageSeqDialog->importArbitrarySequence(positionDialog->importConfig());
993 mSuppressAutoSaveDialog =
false;
996void MainWindow2::importPredefinedImageSet()
999 OnScopeExit(
delete imageSeqDialog)
1000 imageSeqDialog->setCore(mEditor);
1004 mSuppressAutoSaveDialog =
true;
1005 imageSeqDialog->
exec();
1012 OnScopeExit(
delete positionDialog)
1014 positionDialog->
exec();
1020 imageSeqDialog->importPredefinedSet(positionDialog->importConfig());
1021 mSuppressAutoSaveDialog =
false;
1024void MainWindow2::importLayers()
1027 importLayers->setCore(mEditor);
1029 importLayers->
open();
1032void MainWindow2::importAnimatedImage()
1035 mSuppressAutoSaveDialog =
true;
1037 mCommands->importAnimatedImage();
1039 mSuppressAutoSaveDialog =
false;
1042void MainWindow2::lockWidgets(
bool shouldLock)
1046 : (QDockWidget::DockWidgetFeature::DockWidgetClosable |
1047 QDockWidget::DockWidgetFeature::DockWidgetMovable |
1048 QDockWidget::DockWidgetFeature::DockWidgetFloatable);
1052 d->setFeatures(feat);
1053 d->lock(shouldLock);
1057void MainWindow2::preferences()
1062 mPrefDialog->
raise();
1068 mPrefDialog->init(mEditor->preference());
1070 connect(mPrefDialog, &PreferencesDialog::windowOpacityChange,
this, &MainWindow2::setOpacity);
1071 connect(mPrefDialog, &PreferencesDialog::soundScrubChanged, mEditor->playback(), &PlaybackManager::setSoundScrubActive);
1072 connect(mPrefDialog, &PreferencesDialog::soundScrubMsecChanged, mEditor->playback(), &PlaybackManager::setSoundScrubMsec);
1075 clearKeyboardShortcuts();
1076 setupKeyboardShortcuts();
1077 mPrefDialog =
nullptr;
1080 mPrefDialog->
show();
1083void MainWindow2::resetAndDockAllSubWidgets()
1086 settings.remove(SETTING_WINDOW_GEOMETRY);
1087 settings.remove(SETTING_WINDOW_STATE);
1091 dock->setFloating(
false);
1105void MainWindow2::newObject()
1107 auto object =
new Object();
1111 object->addNewCameraLayer();
1112 object->addNewBitmapLayer();
1116 object->data()->setCurrentLayer(1);
1118 mEditor->setObject(
object);
1123 updateBackupActionState();
1126bool MainWindow2::newObjectFromPresets(
int presetIndex)
1128 QString presetFilePath = PresetDialog::getPresetPath(presetIndex);
1136 Object*
object = fm.load(presetFilePath);
1138 if (!fm.error().ok() ||
object ==
nullptr)
1143 mEditor->setObject(
object);
1144 object->setFilePath(
QString());
1148 updateBackupActionState();
1153bool MainWindow2::loadMostRecent()
1155 if(!mEditor->preference()->isOn(SETTING::LOAD_MOST_RECENT))
1161 QString myPath = settings.value(LAST_PCLX_PATH,
QVariant(
"")).toString();
1162 if (myPath.
isEmpty() || !QFile::exists(myPath))
1166 return openObject(myPath);
1169bool MainWindow2::tryLoadPreset()
1171 if (!mEditor->preference()->isOn(SETTING::ASK_FOR_PRESET))
1173 int defaultPreset = mEditor->preference()->getInt(SETTING::DEFAULT_PRESET);
1174 return newObjectFromPresets(defaultPreset);
1186 int presetIndex = presetDialog->getPresetIndex();
1187 if (presetDialog->shouldAlwaysUse())
1189 mEditor->preference()->set(SETTING::ASK_FOR_PRESET, false);
1190 mEditor->preference()->set(SETTING::DEFAULT_PRESET, presetIndex);
1192 if (!newObjectFromPresets(presetIndex))
1197 presetDialog->
open();
1201void MainWindow2::closeDialogs()
1208void MainWindow2::readSettings()
1212 QVariant winGeometry = settings.
value(SETTING_WINDOW_GEOMETRY);
1218 int opacity = mEditor->preference()->getInt(SETTING::WINDOW_OPACITY);
1219 setOpacity(100 - opacity);
1221 bool isWindowsLocked = mEditor->preference()->isOn(SETTING::LAYOUT_LOCK);
1222 lockWidgets(isWindowsLocked);
1225void MainWindow2::writeSettings()
1228 settings.setValue(SETTING_WINDOW_GEOMETRY,
saveGeometry());
1229 settings.setValue(SETTING_WINDOW_STATE,
saveState());
1232void MainWindow2::setupKeyboardShortcuts()
1234 checkExistingShortcuts();
1238 strCommandName =
QString(
"shortcuts/") + strCommandName;
1244 ui->actionNew->setShortcut(cmdKeySeq(CMD_NEW_FILE));
1245 ui->actionOpen->setShortcut(cmdKeySeq(CMD_OPEN_FILE));
1246 ui->actionSave->setShortcut(cmdKeySeq(CMD_SAVE_FILE));
1247 ui->actionSave_as->setShortcut(cmdKeySeq(CMD_SAVE_AS));
1249 ui->actionImport_Image->setShortcut(cmdKeySeq(CMD_IMPORT_IMAGE));
1250 ui->actionImport_ImageSeq->setShortcut(cmdKeySeq(CMD_IMPORT_IMAGE_SEQ));
1251 ui->actionImport_ImageSeqNum->setShortcut(cmdKeySeq(CMD_IMPORT_IMAGE_PREDEFINED_SET));
1252 ui->actionImport_MovieVideo->setShortcut(cmdKeySeq(CMD_IMPORT_MOVIE_VIDEO));
1253 ui->actionImport_AnimatedImage->setShortcut(cmdKeySeq(CMD_IMPORT_ANIMATED_IMAGE));
1254 ui->actionImportLayers_from_pclx->setShortcut(cmdKeySeq(CMD_IMPORT_LAYERS));
1255 ui->actionImport_Sound->setShortcut(cmdKeySeq(CMD_IMPORT_SOUND));
1256 ui->actionImport_MovieAudio->setShortcut(cmdKeySeq(CMD_IMPORT_MOVIE_AUDIO));
1257 ui->actionImport_Append_Palette->setShortcut(cmdKeySeq(CMD_IMPORT_PALETTE));
1258 ui->actionImport_Replace_Palette->setShortcut(cmdKeySeq(CMD_IMPORT_PALETTE_REPLACE));
1260 ui->actionExport_Image->setShortcut(cmdKeySeq(CMD_EXPORT_IMAGE));
1261 ui->actionExport_ImageSeq->setShortcut(cmdKeySeq(CMD_EXPORT_IMAGE_SEQ));
1262 ui->actionExport_Movie->setShortcut(cmdKeySeq(CMD_EXPORT_MOVIE));
1263 ui->actionExport_Animated_GIF->setShortcut(cmdKeySeq(CMD_EXPORT_GIF));
1264 ui->actionExport_Palette->setShortcut(cmdKeySeq(CMD_EXPORT_PALETTE));
1267 ui->actionUndo->setShortcut(cmdKeySeq(CMD_UNDO));
1268 ui->actionRedo->setShortcut(cmdKeySeq(CMD_REDO));
1269 ui->actionCut->setShortcut(cmdKeySeq(CMD_CUT));
1270 ui->actionCopy->setShortcut(cmdKeySeq(CMD_COPY));
1271 ui->actionPaste_Previous->setShortcut(cmdKeySeq(CMD_PASTE_FROM_PREVIOUS));
1272 ui->actionPaste->setShortcut(cmdKeySeq(CMD_PASTE));
1273 ui->actionClearFrame->setShortcut(cmdKeySeq(CMD_CLEAR_FRAME));
1274 ui->actionFlip_X->setShortcut(cmdKeySeq(CMD_SELECTION_FLIP_HORIZONTAL));
1275 ui->actionFlip_Y->setShortcut(cmdKeySeq(CMD_SELECTION_FLIP_VERTICAL));
1276 ui->actionSelect_All->setShortcut(cmdKeySeq(CMD_SELECT_ALL));
1277 ui->actionDeselect_All->setShortcut(cmdKeySeq(CMD_DESELECT_ALL));
1278 ui->actionPegbarAlignment->setShortcut(cmdKeySeq(CMD_PEGBAR_ALIGNMENT));
1279 ui->actionPreference->setShortcut(cmdKeySeq(CMD_PREFERENCE));
1282 ui->actionResetWindows->setShortcut(cmdKeySeq(CMD_RESET_WINDOWS));
1283 ui->actionLockWindows->setShortcut(cmdKeySeq(CMD_LOCK_WINDOWS));
1284 ui->actionReset_View->setShortcut(cmdKeySeq(CMD_RESET_ZOOM_ROTATE));
1285 ui->actionCenter_View->setShortcut(cmdKeySeq(CMD_CENTER_VIEW));
1286 ui->actionZoom_In->setShortcut(cmdKeySeq(CMD_ZOOM_IN));
1287 ui->actionZoom_Out->setShortcut(cmdKeySeq(CMD_ZOOM_OUT));
1288 ui->actionZoom400->setShortcut(cmdKeySeq(CMD_ZOOM_400));
1289 ui->actionZoom300->setShortcut(cmdKeySeq(CMD_ZOOM_300));
1290 ui->actionZoom200->setShortcut(cmdKeySeq(CMD_ZOOM_200));
1291 ui->actionZoom100->setShortcut(cmdKeySeq(CMD_ZOOM_100));
1292 ui->actionZoom50->setShortcut(cmdKeySeq(CMD_ZOOM_50));
1293 ui->actionZoom33->setShortcut(cmdKeySeq(CMD_ZOOM_33));
1294 ui->actionZoom25->setShortcut(cmdKeySeq(CMD_ZOOM_25));
1295 ui->actionRotate_Clockwise->setShortcut(cmdKeySeq(CMD_ROTATE_CLOCK));
1296 ui->actionRotate_Anticlockwise->setShortcut(cmdKeySeq(CMD_ROTATE_ANTI_CLOCK));
1297 ui->actionReset_Rotation->setShortcut(cmdKeySeq(CMD_RESET_ROTATION));
1298 ui->actionHorizontal_Flip->setShortcut(cmdKeySeq(CMD_FLIP_HORIZONTAL));
1299 ui->actionVertical_Flip->setShortcut(cmdKeySeq(CMD_FLIP_VERTICAL));
1300 ui->actionGrid->setShortcut(cmdKeySeq(CMD_GRID));
1301 ui->actionCenter->setShortcut(cmdKeySeq(CMD_OVERLAY_CENTER));
1302 ui->actionThirds->setShortcut(cmdKeySeq(CMD_OVERLAY_THIRDS));
1303 ui->actionGoldenRatio->setShortcut(cmdKeySeq(CMD_OVERLAY_GOLDEN_RATIO));
1304 ui->actionSafeAreas->setShortcut(cmdKeySeq(CMD_OVERLAY_SAFE_AREAS));
1305 ui->actionOnePointPerspective->setShortcut(cmdKeySeq(CMD_OVERLAY_ONE_POINT_PERSPECTIVE));
1306 ui->actionTwoPointPerspective->setShortcut(cmdKeySeq(CMD_OVERLAY_TWO_POINT_PERSPECTIVE));
1307 ui->actionThreePointPerspective->setShortcut(cmdKeySeq(CMD_OVERLAY_THREE_POINT_PERSPECTIVE));
1308 ui->actionOnionPrev->setShortcut(cmdKeySeq(CMD_ONIONSKIN_PREV));
1309 ui->actionOnionNext->setShortcut(cmdKeySeq(CMD_ONIONSKIN_NEXT));
1310 ui->actionStatusBar->setShortcut(cmdKeySeq(CMD_TOGGLE_STATUS_BAR));
1313 ui->actionPlay->setShortcut(cmdKeySeq(CMD_PLAY));
1314 ui->actionLoop->setShortcut(cmdKeySeq(CMD_LOOP));
1315 ui->actionLoopControl->setShortcut(cmdKeySeq(CMD_LOOP_CONTROL));
1316 ui->actionPrevious_Frame->setShortcut(cmdKeySeq(CMD_GOTO_PREV_FRAME));
1317 ui->actionNext_Frame->setShortcut(cmdKeySeq(CMD_GOTO_NEXT_FRAME));
1318 ui->actionPrev_KeyFrame->setShortcut(cmdKeySeq(CMD_GOTO_PREV_KEY_FRAME));
1319 ui->actionNext_KeyFrame->setShortcut(cmdKeySeq(CMD_GOTO_NEXT_KEY_FRAME));
1320 ui->actionAdd_Frame->setShortcut(cmdKeySeq(CMD_ADD_FRAME));
1321 ui->actionDuplicate_Frame->setShortcut(cmdKeySeq(CMD_DUPLICATE_FRAME));
1322 ui->actionRemove_Frame->setShortcut(cmdKeySeq(CMD_REMOVE_FRAME));
1323 ui->actionAdd_Frame_Exposure->setShortcut(cmdKeySeq(CMD_SELECTION_ADD_FRAME_EXPOSURE));
1324 ui->actionSubtract_Frame_Exposure->setShortcut(cmdKeySeq(CMD_SELECTION_SUBTRACT_FRAME_EXPOSURE));
1325 ui->actionReverse_Frames_Order->setShortcut(cmdKeySeq(CMD_REVERSE_SELECTED_FRAMES));
1326 ui->actionRemove_Frames->setShortcut(cmdKeySeq(CMD_REMOVE_SELECTED_FRAMES));
1327 ui->actionMove_Frame_Backward->setShortcut(cmdKeySeq(CMD_MOVE_FRAME_BACKWARD));
1328 ui->actionMove_Frame_Forward->setShortcut(cmdKeySeq(CMD_MOVE_FRAME_FORWARD));
1329 ui->actionFlip_inbetween->setShortcut(cmdKeySeq(CMD_FLIP_INBETWEEN));
1330 ui->actionFlip_rolling->setShortcut(cmdKeySeq(CMD_FLIP_ROLLING));
1331 ui->actionReposition_Selected_Frames->setShortcut(cmdKeySeq(CMD_SELECTION_REPOSITION_FRAMES));
1334 ui->actionMove->setShortcut(cmdKeySeq(CMD_TOOL_MOVE));
1335 ui->actionSelect->setShortcut(cmdKeySeq(CMD_TOOL_SELECT));
1336 ui->actionBrush->setShortcut(cmdKeySeq(CMD_TOOL_BRUSH));
1337 ui->actionPolyline->setShortcut(cmdKeySeq(CMD_TOOL_POLYLINE));
1338 ui->actionSmudge->setShortcut(cmdKeySeq(CMD_TOOL_SMUDGE));
1339 ui->actionPen->setShortcut(cmdKeySeq(CMD_TOOL_PEN));
1340 ui->actionHand->setShortcut(cmdKeySeq(CMD_TOOL_HAND));
1341 ui->actionPencil->setShortcut(cmdKeySeq(CMD_TOOL_PENCIL));
1342 ui->actionBucket->setShortcut(cmdKeySeq(CMD_TOOL_BUCKET));
1343 ui->actionEyedropper->setShortcut(cmdKeySeq(CMD_TOOL_EYEDROPPER));
1344 ui->actionEraser->setShortcut(cmdKeySeq(CMD_TOOL_ERASER));
1345 ui->actionResetToolsDefault->setShortcut(cmdKeySeq(CMD_RESET_ALL_TOOLS));
1347 ui->actionMove->installEventFilter(shortcutFilter);
1348 ui->actionMove->installEventFilter(shortcutFilter);
1349 ui->actionSelect->installEventFilter(shortcutFilter);
1350 ui->actionBrush->installEventFilter(shortcutFilter);
1351 ui->actionPolyline->installEventFilter(shortcutFilter);
1352 ui->actionSmudge->installEventFilter(shortcutFilter);
1353 ui->actionPen->installEventFilter(shortcutFilter);
1354 ui->actionHand->installEventFilter(shortcutFilter);
1355 ui->actionPencil->installEventFilter(shortcutFilter);
1356 ui->actionBucket->installEventFilter(shortcutFilter);
1357 ui->actionEyedropper->installEventFilter(shortcutFilter);
1358 ui->actionEraser->installEventFilter(shortcutFilter);
1361 ui->actionNew_Bitmap_Layer->setShortcut(cmdKeySeq(CMD_NEW_BITMAP_LAYER));
1362 ui->actionNew_Vector_Layer->setShortcut(cmdKeySeq(CMD_NEW_VECTOR_LAYER));
1363 ui->actionNew_Camera_Layer->setShortcut(cmdKeySeq(CMD_NEW_CAMERA_LAYER));
1364 ui->actionNew_Sound_Layer->setShortcut(cmdKeySeq(CMD_NEW_SOUND_LAYER));
1365 ui->actionDelete_Current_Layer->setShortcut(cmdKeySeq(CMD_DELETE_CUR_LAYER));
1366 ui->actionChangeLineColorCurrent_keyframe->setShortcut(cmdKeySeq(CMD_CHANGE_LINE_COLOR_KEYFRAME));
1367 ui->actionChangeLineColorAll_keyframes_on_layer->setShortcut(cmdKeySeq(CMD_CHANGE_LINE_COLOR_LAYER));
1368 ui->actionChangeLayerOpacity->setShortcut(cmdKeySeq(CMD_CHANGE_LAYER_OPACITY));
1370 ui->actionVisibilityCurrentLayerOnly->setShortcut(cmdKeySeq(CMD_CURRENT_LAYER_VISIBILITY));
1371 ui->actionVisibilityRelative->setShortcut(cmdKeySeq(CMD_RELATIVE_LAYER_VISIBILITY));
1372 ui->actionVisibilityAll->setShortcut(cmdKeySeq(CMD_ALL_LAYER_VISIBILITY));
1374 mToolBox->toggleViewAction()->setShortcut(cmdKeySeq(CMD_TOGGLE_TOOLBOX));
1382 ui->actionHelp->setShortcut(cmdKeySeq(CMD_HELP));
1383 ui->actionExit->setShortcut(cmdKeySeq(CMD_EXIT));
1386void MainWindow2::clearKeyboardShortcuts()
1389 for (
QAction* action : actionList)
1395void MainWindow2::exportPalette()
1400 mEditor->object()->exportPalette(filePath);
1404void MainWindow2::importPalette()
1409 mEditor->object()->importPalette(filePath);
1410 mColorPalette->refreshColorList();
1411 mColorPalette->adjustSwatches();
1412 mEditor->color()->setColorNumber(0);
1416void MainWindow2::openPalette()
1418 for (
int i = 0; i < mEditor->object()->getColorCount(); i++)
1420 if (!mEditor->object()->isColorInUse(i))
1426 msgBox.
setText(
tr(
"Opening a palette will replace the old palette.\n"
1427 "Color(s) in strokes will be altered by this action!"));
1443 mEditor->object()->openPalette(filePath);
1444 mColorPalette->refreshColorList();
1445 mEditor->color()->setColorNumber(0);
1448void MainWindow2::makeConnections(
Editor* editor)
1450 connect(editor->undoRedo(), &UndoRedoManager::didUpdateUndoStack,
this, &MainWindow2::updateSaveState);
1451 connect(editor->undoRedo(), &UndoRedoManager::didUpdateUndoStack,
this, &MainWindow2::updateBackupActionState);
1452 connect(editor, &Editor::needDisplayInfo,
this, &MainWindow2::displayMessageBox);
1453 connect(editor, &Editor::needDisplayInfoNoTitle,
this, &MainWindow2::displayMessageBoxNoTitle);
1454 connect(editor->layers(), &LayerManager::currentLayerChanged,
this, &MainWindow2::currentLayerChanged);
1455 connect(editor->select(), &SelectionManager::selectionChanged,
this, &MainWindow2::selectionChanged);
1456 connect(editor, &Editor::canCopyChanged,
this, [=](
bool canCopy) {
1457 ui->actionCopy->setEnabled(canCopy);
1458 ui->actionCut->setEnabled(canCopy);
1463void MainWindow2::makeConnections(
Editor* editor,
ColorBox* colorBox)
1465 connect(colorBox, &ColorBox::colorChanged, editor->color(), &ColorManager::setFrontColor);
1466 connect(editor->color(), &ColorManager::colorChanged, colorBox, &ColorBox::setColor);
1471 connect(colorInspector, &ColorInspector::colorChanged, editor->color(), &ColorManager::setFrontColor);
1472 connect(editor->color(), &ColorManager::colorChanged, colorInspector, &ColorInspector::setColor);
1477 connect(editor->tools(), &ToolManager::toolChanged, scribbleArea, &ScribbleArea::updateToolCursor);
1478 connect(editor->tools(), &ToolManager::toolChanged, mToolBox, &ToolBoxDockWidget::setActiveTool);
1489void MainWindow2::makeConnections(
Editor* pEditor,
TimeLine* pTimeline)
1492 connect(pTimeline, &TimeLine::duplicateLayerClick, mCommands, &ActionCommands::duplicateLayer);
1493 connect(pTimeline, &TimeLine::duplicateKeyClick, mCommands, &ActionCommands::duplicateKey);
1495 connect(pTimeline, &TimeLine::soundClick, pPlaybackManager, &PlaybackManager::enableSound);
1496 connect(pTimeline, &TimeLine::fpsChanged, pPlaybackManager, &PlaybackManager::setFps);
1497 connect(pTimeline, &TimeLine::fpsChanged, pEditor, &Editor::setFps);
1500 connect(pTimeline, &TimeLine::removeKeyClick, mCommands, &ActionCommands::removeKey);
1502 connect(pTimeline, &TimeLine::newBitmapLayer, mCommands, &ActionCommands::addNewBitmapLayer);
1503 connect(pTimeline, &TimeLine::newVectorLayer, mCommands, &ActionCommands::addNewVectorLayer);
1504 connect(pTimeline, &TimeLine::newSoundLayer, mCommands, &ActionCommands::addNewSoundLayer);
1505 connect(pTimeline, &TimeLine::newCameraLayer, mCommands, &ActionCommands::addNewCameraLayer);
1506 connect(mTimeLine, &TimeLine::playButtonTriggered, mCommands, &ActionCommands::PlayStop);
1507 connect(pTimeline, &TimeLine::deleteCurrentLayerClick, mCommands, &ActionCommands::deleteCurrentLayer);
1511 connect(pTimeline, &TimeLine::selectionChanged,
this, &MainWindow2::updateCopyCutPasteEnabled);
1513 connect(mEditor->select(), &SelectionManager::selectionChanged,
this, &MainWindow2::updateCopyCutPasteEnabled);
1515 connect(pEditor->layers(), &LayerManager::currentLayerChanged, pTimeline, &TimeLine::updateUI);
1517 connect(pEditor->sound(), &SoundManager::soundClipDurationChanged, pTimeline, &TimeLine::updateUI);
1522 connect(pEditor, &Editor::objectLoaded, pTimeline, &TimeLine::onObjectLoaded);
1523 connect(pEditor, &Editor::updateTimeLine, pTimeline, &TimeLine::updateUI);
1524 connect(pEditor, &Editor::updateTimeLineCached, pTimeline, &TimeLine::updateUICached);
1526 connect(pEditor->layers(), &LayerManager::currentLayerChanged,
this, &MainWindow2::updateLayerMenu);
1535 toolOptions->makeConnectionToEditor(editor);
1540 connect(pEditor, &Editor::objectLoaded, pColorPalette, &ColorPaletteWidget::updateUI);
1543 ScribbleArea* pScribbleArea = pEditor->getScribbleArea();
1545 connect(pColorPalette, &ColorPaletteWidget::colorNumberChanged, pColorManager, &ColorManager::setColorNumber);
1546 connect(pColorManager, &ColorManager::colorNumberChanged, pScribbleArea, &ScribbleArea::paletteColorChanged);
1547 connect(pColorManager, &ColorManager::colorNumberChanged, pColorPalette, &ColorPaletteWidget::selectColorNumber);
1550void MainWindow2::makeConnections(
Editor* editor,
StatusBar *statusBar)
1559void MainWindow2::updateCopyCutPasteEnabled()
1561 bool canCopy = mEditor->canCopy();
1562 bool canPaste = mEditor->canPaste();
1564 ui->actionCopy->setEnabled(canCopy);
1565 ui->actionCut->setEnabled(canCopy);
1566 ui->actionPaste->setEnabled(canPaste);
1569void MainWindow2::updateLayerMenu()
1571 ui->actionDelete_Current_Layer->setEnabled(mEditor->layers()->canDeleteLayer(mEditor->currentLayerIndex()));
1574void MainWindow2::changePlayState(
bool isPlaying)
1578 ui->actionPlay->setText(
tr(
"Stop"));
1579 ui->actionPlay->setIcon(mStopIcon);
1583 ui->actionPlay->setText(
tr(
"Play"));
1584 ui->actionPlay->setIcon(mStartIcon);
1589void MainWindow2::importMovieVideo()
1592 mSuppressAutoSaveDialog =
true;
1594 mCommands->importMovieVideo();
1596 mSuppressAutoSaveDialog =
false;
1599bool MainWindow2::event(
QEvent* event)
1607void MainWindow2::displayMessageBox(
const QString& title,
const QString& body)
1612void MainWindow2::displayMessageBoxNoTitle(
const QString& body)
1617bool MainWindow2::checkForRecoverableProjects()
1620 QStringList recoverables = fm.searchForUnsavedProjects();
1622 foreach (
const QString path, recoverables)
1624 if (tryRecoverProject(path))
1633bool MainWindow2::tryRecoverProject(
const QString recoverPath)
1635 QString caption =
tr(
"Restore Project?");
1636 QString text =
tr(
"Pencil2D didn't close correctly. Would you like to restore the project?");
1639 hideQuestionMark(msgBox);
1648 int result = msgBox.
exec();
1658 return startProjectRecovery(recoverPath);
1666bool MainWindow2::startProjectRecovery(
const QString recoverPath)
1669 Object* o = fm.recoverUnsavedProject(recoverPath);
1670 if (!fm.error().ok())
1672 Q_ASSERT(o ==
nullptr);
1673 const QString title =
tr(
"Recovery Failed.");
1674 const QString text =
tr(
"Sorry! Pencil2D is unable to restore your project");
1680 mEditor->setObject(o);
1682 updateBackupActionState();
1684 const QString title =
tr(
"Recovery Succeeded!");
1685 const QString text =
tr(
"Please save your work immediately to prevent loss of data");
1691void MainWindow2::createToolbars()
1696 mMainToolbar->
addAction(ui->actionOpen);
1697 mMainToolbar->
addAction(ui->actionSave);
1699 mMainToolbar->
addAction(ui->actionUndo);
1700 mMainToolbar->
addAction(ui->actionRedo);
1703 mMainToolbar->
addAction(ui->actionCopy);
1704 mMainToolbar->
addAction(ui->actionPaste);
1705 mMainToolbar->
addAction(ui->actionClearFrame);
1709 mViewToolbar->
addAction(ui->actionZoom_In);
1710 mViewToolbar->
addAction(ui->actionZoom_Out);
1711 mViewToolbar->
addAction(ui->actionReset_View);
1713 mViewToolbar->
addAction(ui->actionHorizontal_Flip);
1714 mViewToolbar->
addAction(ui->actionVertical_Flip);
1716 mViewToolbar->
addAction(ui->actionShowInvisibleLines);
1717 mViewToolbar->
addAction(ui->actionShowOutlinesOnly);
1721 mOverlayToolbar->
addAction(ui->actionGrid);
1722 mOverlayToolbar->
addAction(ui->actionCenter);
1723 mOverlayToolbar->
addAction(ui->actionThirds);
1724 mOverlayToolbar->
addAction(ui->actionGoldenRatio);
1725 mOverlayToolbar->
addAction(ui->actionSafeAreas);
1726 mOverlayToolbar->
addAction(ui->actionOnePointPerspective);
1727 mOverlayToolbar->
addAction(ui->actionTwoPointPerspective);
1728 mOverlayToolbar->
addAction(ui->actionThreePointPerspective);
1734 perspectiveLinesAngleButton->
setDefaultAction(ui->menuPerspectiveLinesAngle->menuAction());
1736 mOverlayToolbar->
addWidget(perspectiveLinesAngleButton);
1738 mToolbars = { mMainToolbar, mViewToolbar, mOverlayToolbar };
1742 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