20#include <QApplication>
23#include <QImageReader>
26#include <QTemporaryDir>
29#include "vectorimage.h"
30#include "bitmapimage.h"
32#include "layerbitmap.h"
33#include "layervector.h"
34#include "layercamera.h"
35#include "backupelement.h"
37#include "colormanager.h"
38#include "filemanager.h"
39#include "toolmanager.h"
40#include "layermanager.h"
41#include "playbackmanager.h"
42#include "viewmanager.h"
43#include "preferencemanager.h"
44#include "soundmanager.h"
45#include "selectionmanager.h"
46#include "overlaymanager.h"
47#include "clipboardmanager.h"
49#include "scribblearea.h"
98 mIsAutosave = mPreferenceManager->isOn(SETTING::AUTO_SAVE);
99 mAutosaveNumber = mPreferenceManager->getInt(SETTING::AUTO_SAVE_NUMBER);
104int Editor::currentFrame()
const
111 return mPlaybackManager->fps();
114void Editor::setFps(
int fps)
116 mPreferenceManager->set(SETTING::FPS, fps);
117 emit fpsChanged(fps);
120void Editor::makeConnections()
122 connect(mPreferenceManager, &PreferenceManager::optionChanged,
this, &Editor::settingUpdated);
125 connect(mLayerManager, &LayerManager::currentLayerWillChange,
this, &Editor::onCurrentLayerWillChange);
128void Editor::settingUpdated(SETTING setting)
132 case SETTING::AUTO_SAVE:
133 mIsAutosave = mPreferenceManager->isOn(SETTING::AUTO_SAVE);
135 case SETTING::AUTO_SAVE_NUMBER:
136 mAutosaveNumber = mPreferenceManager->getInt(SETTING::AUTO_SAVE_NUMBER);
138 case SETTING::ONION_TYPE:
140 emit updateTimeLineCached();
142 case SETTING::FRAME_POOL_SIZE:
143 mObject->setActiveFramePoolSize(mPreferenceManager->getInt(SETTING::FRAME_POOL_SIZE));
145 case SETTING::LAYER_VISIBILITY:
146 mScribbleArea->setLayerVisibility(
static_cast<LayerVisibility
>(mPreferenceManager->getInt(SETTING::LAYER_VISIBILITY)));
147 emit updateTimeLine();
154void Editor::onCurrentLayerWillChange(
int index)
156 Layer* newLayer = layers()->getLayer(index);
157 Layer* currentLayer = layers()->currentLayer();
158 Q_ASSERT(newLayer && currentLayer);
159 if (currentLayer->type() != newLayer->type()) {
161 mScribbleArea->applyTransformedSelection();
163 if (currentLayer->type() == Layer::VECTOR) {
164 auto keyFrame =
static_cast<VectorImage*
>(currentLayer->getLastKeyFrameAtPosition(mFrame));
171 select()->resetSelectionProperties();
177 if (mBackupIndex >= 0)
179 return mBackupList[mBackupIndex];
184void Editor::backup(
const QString& undoText)
187 if (mLastModifiedLayer > -1 && mLastModifiedFrame > 0)
189 if (layers()->currentLayer()->type() == Layer::SOUND)
191 frame = layers()->currentLayer()->getKeyFrameWhichCovers(mLastModifiedFrame);
192 if (frame !=
nullptr)
194 backup(mLastModifiedLayer, frame->pos(), undoText);
199 backup(mLastModifiedLayer, mLastModifiedFrame, undoText);
202 if (mLastModifiedLayer != layers()->currentLayerIndex() || mLastModifiedFrame != currentFrame())
204 if (layers()->currentLayer()->type() == Layer::SOUND)
206 frame = layers()->currentLayer()->getKeyFrameWhichCovers(currentFrame());
208 if (frame !=
nullptr)
210 backup(layers()->currentLayerIndex(), frame->pos(), undoText);
215 backup(layers()->currentLayerIndex(), currentFrame(), undoText);
220bool Editor::backup(
int backupLayer,
int backupFrame,
const QString& undoText)
222 while (mBackupList.
size() - 1 > mBackupIndex && !mBackupList.
empty())
226 while (mBackupList.
size() > 19)
232 Layer* layer = mObject->getLayer(backupLayer);
233 if (layer !=
nullptr)
235 if (layer->type() == Layer::BITMAP)
238 if (currentFrame() == 1)
240 int previous = layer->getPreviousKeyFramePosition(backupFrame);
241 bitmapImage =
static_cast<BitmapImage*
>(layer->getKeyFrameAt(previous));
243 if (bitmapImage !=
nullptr)
246 element->layerId = layer->id();
247 element->layer = backupLayer;
248 element->frame = bitmapImage->pos();
249 element->undoText = undoText;
250 element->somethingSelected = select()->somethingSelected();
251 element->mySelection = select()->mySelectionRect();
252 element->rotationAngle = select()->myRotation();
253 element->scaleX = select()->myScaleX();
254 element->scaleY = select()->myScaleY();
255 element->translation = select()->myTranslation();
256 element->selectionAnchor = select()->currentTransformAnchor();
258 mBackupList.
append(element);
266 else if (layer->type() == Layer::VECTOR)
269 if (vectorImage !=
nullptr)
272 element->layerId = layer->id();
273 element->layer = backupLayer;
274 element->frame = vectorImage->pos();
275 element->undoText = undoText;
276 element->somethingSelected = select()->somethingSelected();
277 element->mySelection = select()->mySelectionRect();
278 element->rotationAngle = select()->myRotation();
279 element->scaleX = select()->myScaleX();
280 element->scaleY = select()->myScaleY();
281 element->translation = select()->myTranslation();
282 element->selectionAnchor = select()->currentTransformAnchor();
283 mBackupList.
append(element);
291 else if (layer->type() == Layer::SOUND)
293 int previous = layer->getPreviousKeyFramePosition(backupFrame);
294 KeyFrame* key = layer->getLastKeyFrameAtPosition(backupFrame);
299 KeyFrame* previousKey = layer->getKeyFrameAt(previous);
302 if (key !=
nullptr) {
307 element->layerId = layer->id();
308 element->layer = backupLayer;
309 element->frame = backupFrame;
310 element->undoText = undoText;
311 element->fileName = clip->fileName();
312 element->originalName = clip->soundClipName();
313 mBackupList.
append(element);
324 updateAutoSaveCounter();
333 for (
int i = 0; i < mBackupList.
size(); i++)
339 switch (backupElement->type())
341 case BackupElement::BITMAP_MODIF:
342 bitmapElement = qobject_cast<BackupBitmapElement*>(backupElement);
343 Q_ASSERT(bitmapElement);
344 if (bitmapElement->layer > layerIndex)
346 bitmapElement->layer--;
349 else if (bitmapElement->layer != layerIndex)
354 case BackupElement::VECTOR_MODIF:
355 vectorElement = qobject_cast<BackupVectorElement*>(backupElement);
356 Q_ASSERT(vectorElement);
357 if (vectorElement->layer > layerIndex)
359 vectorElement->layer--;
362 else if (vectorElement->layer != layerIndex)
367 case BackupElement::SOUND_MODIF:
368 soundElement = qobject_cast<BackupSoundElement*>(backupElement);
369 Q_ASSERT(soundElement);
370 if (soundElement->layer > layerIndex)
372 soundElement->layer--;
375 else if (soundElement->layer != layerIndex)
383 if (i <= mBackupIndex)
387 delete mBackupList.
takeAt(i);
392void Editor::restoreKey()
394 BackupElement* lastBackupElement = mBackupList[mBackupIndex];
396 Layer* layer =
nullptr;
399 if (lastBackupElement->type() == BackupElement::BITMAP_MODIF)
402 layerIndex = lastBackupBitmapElement->layer;
403 frame = lastBackupBitmapElement->frame;
404 layer = object()->findLayerById(lastBackupBitmapElement->layerId);
405 addKeyFrame(layerIndex, frame);
406 dynamic_cast<LayerBitmap*
>(layer)->getBitmapImageAtFrame(frame)->paste(&lastBackupBitmapElement->bitmapImage);
409 if (lastBackupElement->type() == BackupElement::VECTOR_MODIF)
412 layerIndex = lastBackupVectorElement->layer;
413 frame = lastBackupVectorElement->frame;
414 layer = object()->findLayerById(layerIndex);
415 addKeyFrame(layerIndex, frame);
416 dynamic_cast<LayerVector*
>(layer)->getVectorImageAtFrame(frame)->paste(lastBackupVectorElement->vectorImage);
419 if (lastBackupElement->type() == BackupElement::SOUND_MODIF)
423 layerIndex = lastBackupSoundElement->layer;
424 frame = lastBackupSoundElement->frame;
426 strSoundFile = lastBackupSoundElement->fileName;
427 if (strSoundFile.
isEmpty())
return;
428 KeyFrame* key = addKeyFrame(layerIndex, frame);
432 Status st = sound()->loadSound(clip, lastBackupSoundElement->fileName);
433 clip->setSoundClipName(lastBackupSoundElement->originalName);
437 emit layers()->currentLayerChanged(layers()->currentLayerIndex());
445 if (!mBackupList.
empty() && mBackupIndex > -1)
447 if (mBackupIndex == mBackupList.
size() - 1)
449 BackupElement* lastBackupElement = mBackupList[mBackupIndex];
450 if (lastBackupElement->type() == BackupElement::BITMAP_MODIF)
453 if (backup(lastBackupBitmapElement->layer, lastBackupBitmapElement->frame,
"NoOp"))
458 if (lastBackupElement->type() == BackupElement::VECTOR_MODIF)
461 if (backup(lastBackupVectorElement->layer, lastBackupVectorElement->frame,
"NoOp"))
466 if (lastBackupElement->type() == BackupElement::SOUND_MODIF)
469 if (backup(lastBackupSoundElement->layer, lastBackupSoundElement->frame,
"NoOp"))
476 qDebug() <<
"Undo" << mBackupIndex;
477 mBackupList[mBackupIndex]->restore(
this);
486 if (!mBackupList.
empty() && mBackupIndex < mBackupList.
size() - 2)
490 mBackupList[mBackupIndex + 1]->restore(
this);
495void Editor::clearUndoStack()
502 mLastModifiedLayer = -1;
503 mLastModifiedFrame = -1;
506void Editor::updateAutoSaveCounter()
508 if (mIsAutosave ==
false)
512 if (mAutosaveCounter >= mAutosaveNumber)
514 resetAutoSaveCounter();
519void Editor::resetAutoSaveCounter()
521 mAutosaveCounter = 0;
526 Layer* currentLayer = layers()->currentLayer();
528 Q_ASSERT(currentLayer !=
nullptr);
530 if (!canCopy()) {
return; }
534 if (currentLayer->hasAnySelectedFrames() && !select()->somethingSelected()) {
536 }
else if (currentLayer->type() == Layer::BITMAP) {
537 BitmapImage* bitmapImage =
static_cast<BitmapImage*
>(currentLayer->getLastKeyFrameAtPosition(currentFrame()));
538 clipboards()->
copyBitmapImage(bitmapImage, select()->mySelectionRect());
539 }
else if (currentLayer->type() == Layer::VECTOR) {
540 VectorImage* vectorImage =
static_cast<VectorImage*
>(currentLayer->getLastKeyFrameAtPosition(currentFrame()));
545void Editor::copyAndCut()
549 Layer* currentLayer = layers()->currentLayer();
551 if (currentLayer->hasAnySelectedFrames() && !select()->somethingSelected()) {
553 currentLayer->removeKeyFrame(pos);
555 layers()->currentLayerChanged(currentLayerIndex());
556 emit updateTimeLine();
560 if (currentLayer->type() == Layer::BITMAP || currentLayer->type() == Layer::VECTOR) {
561 mScribbleArea->deleteSelection();
566void Editor::pasteFromPreviousFrame()
568 Layer* currentLayer = layers()->currentLayer();
569 int prevFrame = currentLayer->getPreviousKeyFramePosition(mFrame);
570 if (!currentLayer->keyExists(mFrame) || prevFrame == mFrame)
575 if (currentLayer->type() == Layer::BITMAP)
577 backup(
tr(
"Paste from Previous Keyframe"));
579 if (select()->somethingSelected())
582 pasteToCanvas(©, mFrame);
586 pasteToCanvas(bitmapImage, mFrame);
589 else if (currentLayer->type() == Layer::VECTOR)
591 backup(
tr(
"Paste from Previous Keyframe"));
593 pasteToCanvas(vectorImage, mFrame);
597void Editor::pasteToCanvas(
BitmapImage* bitmapImage,
int frameNumber)
599 Layer* currentLayer = layers()->currentLayer();
601 Q_ASSERT(currentLayer->type() == Layer::BITMAP);
603 if (select()->somethingSelected())
605 QRectF selection = select()->mySelectionRect();
606 if (bitmapImage->width() <= selection.
width() && bitmapImage->height() <= selection.
height())
608 bitmapImage->moveTopLeft(selection.
topLeft());
612 bitmapImage->transform(selection,
true);
616 BitmapImage *canvasImage =
static_cast<BitmapImage*
>(currentLayer->getLastKeyFrameAtPosition(frameNumber));
619 canvasImage->paste(bitmapImage);
623 select()->setSelection(bitmapImage->bounds());
627void Editor::pasteToCanvas(
VectorImage* vectorImage,
int frameNumber)
629 Layer* currentLayer = layers()->currentLayer();
631 Q_ASSERT(currentLayer->type() == Layer::VECTOR);
635 VectorImage* canvasImage =
static_cast<VectorImage*
>(currentLayer->getLastKeyFrameAtPosition(frameNumber));
636 canvasImage->
paste(*vectorImage);
637 select()->setSelection(vectorImage->getSelectionRect());
641void Editor::pasteToFrames()
643 auto clipboardFrames = clipboards()->getClipboardFrames();
644 Q_ASSERT(!clipboardFrames.empty());
645 Layer* currentLayer = layers()->currentLayer();
647 currentLayer->deselectAll();
649 int newPositionOffset = mFrame - clipboardFrames.cbegin()->first;
650 for (
auto it = clipboardFrames.cbegin(); it != clipboardFrames.cend(); ++it)
652 int newPosition = it->first + newPositionOffset;
654 KeyFrame* keyFrameNewPos = currentLayer->getKeyFrameWhichCovers(newPosition);
656 if (keyFrameNewPos !=
nullptr) {
660 currentLayer->moveSelectedFrames(1);
664 Q_ASSERT(it->second !=
nullptr);
667 KeyFrame* keyClone = it->second->clone();
668 currentLayer->addKeyFrame(newPosition, keyClone);
669 if (currentLayer->type() == Layer::SOUND)
671 auto soundClip =
static_cast<SoundClip*
>(keyClone);
672 sound()->loadSound(soundClip, soundClip->fileName());
675 currentLayer->setFrameSelected(keyClone->pos(),
true);
681 Layer* currentLayer = layers()->currentLayer();
683 Q_ASSERT(currentLayer !=
nullptr);
685 if (!canPaste()) {
return; }
687 if (clipboards()->getClipboardFrames().empty()) {
691 clipboards()->setFromSystemClipboard(mScribbleArea->getCentralPoint(), currentLayer);
693 BitmapImage clipboardImage = clipboards()->getBitmapClipboard();
694 VectorImage clipboardVectorImage = clipboards()->getVectorClipboard();
695 if (currentLayer->type() == Layer::BITMAP && clipboardImage.isLoaded()) {
696 pasteToCanvas(&clipboardImage, mFrame);
697 }
else if (currentLayer->type() == Layer::VECTOR && !clipboardVectorImage.isEmpty()) {
698 pasteToCanvas(&clipboardVectorImage, mFrame);
708void Editor::flipSelection(
bool flipVertical)
711 backup(
tr(
"Flip selection vertically"));
713 backup(
tr(
"Flip selection horizontally"));
715 mScribbleArea->flipSelection(flipVertical);
718void Editor::repositionImage(
QPoint transform,
int frame)
720 if (layers()->currentLayer()->type() == Layer::BITMAP)
724 QRect reposRect = layer->getFrameBounds(frame);
725 select()->setSelection(reposRect);
728 layer->repositionFrame(point, frame);
729 backup(layer->id(), frame,
tr(
"Reposition frame"));
733void Editor::setModified(
int layerNumber,
int frameNumber)
735 Layer* layer = object()->getLayer(layerNumber);
736 if (layer ==
nullptr) {
return; }
738 layer->setModified(frameNumber,
true);
740 mLastModifiedLayer = layerNumber;
741 mLastModifiedFrame = frameNumber;
746void Editor::clipboardChanged()
748 Layer* layer = layers()->currentLayer();
750 clipboards()->setFromSystemClipboard(mScribbleArea->getCentralPoint(), layer);
752 bool canCopyState = canCopy();
753 bool canPasteState = canPaste();
755 emit canCopyChanged(canCopyState);
756 emit canPasteChanged(canPasteState);
760 mScribbleArea->setLayerVisibility(visibility);
761 emit updateTimeLine();
764LayerVisibility Editor::layerVisibility()
766 return mScribbleArea->getLayerVisibility();
769qreal Editor::viewScaleInversed()
771 return view()->getViewScaleInverse();
774void Editor::increaseLayerVisibilityIndex()
776 mScribbleArea->increaseLayerVisibilityIndex();
777 emit updateTimeLine();
780void Editor::decreaseLayerVisibilityIndex()
782 mScribbleArea->decreaseLayerVisibilityIndex();
783 emit updateTimeLine();
788 mTemporaryDirs.
append(dir);
791void Editor::clearTemporary()
793 while(!mTemporaryDirs.
isEmpty())
801Status Editor::openObject(
const QString& strFilePath,
const std::function<
void(
int)>& progressChanged,
const std::function<
void(
int)>& progressRangeChanged)
804 Q_ASSERT(!strFilePath.
isEmpty());
807 dd <<
QString(
"Raw file path: %1").
arg(strFilePath);
808 dd <<
QString(
"Resolved file path: %1").
arg(fileInfo.absoluteFilePath());
809 if (fileInfo.isDir())
811 return Status(Status::ERROR_FILE_CANNOT_OPEN,
813 tr(
"Could not open file"),
814 tr(
"The file you have selected is a directory, so we are unable to open it. "
815 "If you are are trying to open a project that uses the old structure, "
816 "please open the file ending with .pcl, not the data folder."));
818 if (!fileInfo.exists())
820 return Status(Status::FILE_NOT_FOUND,
822 tr(
"Could not open file"),
823 tr(
"The file you have selected does not exist, so we are unable to open it. "
824 "Please make sure that you've entered the correct path and that the file is accessible and try again."));
826 if (!fileInfo.isReadable())
828 dd <<
QString(
"Permissions: 0x%1").
arg(fileInfo.permissions(), 0, 16);
829 return Status(Status::ERROR_FILE_CANNOT_OPEN,
831 tr(
"Could not open file"),
832 tr(
"This program does not have permission to read the file you have selected. "
833 "Please check that you have read permissions for this file and try again."));
838 connect(&fm, &FileManager::progressChanged, [&progress, &progressChanged](
int p)
840 progressChanged(progress = p);
842 connect(&fm, &FileManager::progressRangeChanged, [&progressRangeChanged](
int max)
844 progressRangeChanged(max + 3);
847 QString fullPath = fileInfo.absoluteFilePath();
849 Object*
object = fm.load(fullPath);
851 Status fmStatus = fm.error();
854 dd.collect(fmStatus.details());
855 fmStatus.setDetails(dd);
859 if (
object ==
nullptr)
861 return Status(Status::ERROR_FILE_CANNOT_OPEN,
863 tr(
"Could not open file"),
864 tr(
"An unknown error occurred while trying to load the file and we are not able to load your file."));
869 progressChanged(progress + 1);
872 setFps(playback()->fps());
881 if (newObject == mObject.get())
887 mObject.reset(newObject);
894 m->load(mObject.get());
901void Editor::updateObject()
903 setCurrentLayerIndex(mObject->data()->getCurrentLayer());
904 scrubTo(mObject->data()->getCurrentFrame());
906 mAutosaveCounter = 0;
907 mAutosaveNeverAskAgain =
false;
909 if (mPreferenceManager)
911 mObject->setActiveFramePoolSize(mPreferenceManager->getInt(SETTING::FRAME_POOL_SIZE));
914 emit updateLayerCount();
917Status Editor::importBitmapImage(
const QString& filePath,
int space)
921 Q_ASSERT(layers()->currentLayer()->type() == Layer::BITMAP);
922 auto layer =
static_cast<LayerBitmap*
>(layers()->currentLayer());
924 Status status = Status::OK;
926 dd <<
QString(
"Raw file path: %1").
arg(filePath);
931 QString format = reader.format();
934 dd <<
QString(
"QImageReader format: %1").
arg(format);
936 dd <<
QString(
"QImageReader ImageReaderError type: %1").
arg(reader.errorString());
939 switch(reader.error())
941 case QImageReader::ImageReaderError::FileNotFoundError:
942 errorDesc =
tr(
"File not found at path \"%1\". Please check the image is present at the specified location and try again.").
arg(filePath);
945 errorDesc =
tr(
"Image format is not supported. Please convert the image file to one of the following formats and try again:\n%1")
946 .
arg((
QString)reader.supportedImageFormats().join(
", "));
949 errorDesc =
tr(
"An error has occurred while reading the image. Please check that the file is a valid image and try again.");
952 status =
Status(Status::FAIL, dd,
tr(
"Import failed"), errorDesc);
955 const QPoint pos(view()->getImportView().dx() - (img.width() / 2),
956 view()->getImportView().dy() - (img.height() / 2));
958 while (reader.read(&img))
960 int frameNumber = mFrame;
961 if (!layer->keyExists(frameNumber))
965 BitmapImage* bitmapImage = layer->getBitmapImageAtFrame(frameNumber);
967 bitmapImage->paste(&importedBitmapImage);
971 frameNumber += space;
975 scrubTo(frameNumber);
977 backup(
tr(
"Import Image"));
980 if (!reader.supportsAnimation())
991 Q_ASSERT(layers()->currentLayer()->type() == Layer::VECTOR);
993 auto layer =
static_cast<LayerVector*
>(layers()->currentLayer());
995 Status status = Status::OK;
997 dd <<
QString(
"Raw file path: %1").
arg(filePath);
999 VectorImage* vectorImage = layer->getVectorImageAtFrame(currentFrame());
1000 if (vectorImage ==
nullptr)
1003 vectorImage = layer->getVectorImageAtFrame(currentFrame());
1007 bool ok = importedVectorImage.
read(filePath);
1011 vectorImage->
paste(importedVectorImage);
1014 backup(
tr(
"Import Image"));
1017 status =
Status(Status::FAIL, dd,
tr(
"Import failed"),
tr(
"You cannot import images into a vector layer."));
1025 Layer* layer = layers()->currentLayer();
1028 dd <<
QString(
"Raw file path: %1").
arg(filePath);
1030 if (view()->getImportFollowsCamera())
1034 QTransform transform = camera->getViewAtFrame(currentFrame());
1035 view()->setImportView(transform);
1037 switch (layer->type())
1040 return importBitmapImage(filePath);
1043 return importVectorImage(filePath);
1046 dd <<
QString(
"Current layer: %1").
arg(layer->type());
1047 return Status(Status::ERROR_INVALID_LAYER_TYPE, dd,
tr(
"Import failed"),
tr(
"You can only import images to a bitmap layer."));
1051Status Editor::importGIF(
const QString& filePath,
int numOfImages)
1053 Layer* layer = layers()->currentLayer();
1054 if (layer->type() != Layer::BITMAP)
1057 dd <<
QString(
"Raw file path: %1").
arg(filePath);
1058 dd <<
QString(
"Current layer: %1").
arg(layer->type());
1059 return Status(Status::ERROR_INVALID_LAYER_TYPE, dd,
tr(
"Import failed"),
tr(
"You can only import images to a bitmap layer."));
1061 return importBitmapImage(filePath, numOfImages);
1064void Editor::selectAll()
const
1066 Layer* layer = layers()->currentLayer();
1069 if (layer->type() == Layer::BITMAP)
1074 if (bitmapImage ==
nullptr) {
return; }
1076 rect = bitmapImage->bounds();
1078 else if (layer->type() == Layer::VECTOR)
1081 if (vectorImage !=
nullptr)
1084 rect = vectorImage->getSelectionRect();
1087 select()->setSelection(rect,
false);
1090void Editor::deselectAll()
const
1092 select()->resetSelectionProperties();
1094 Layer* layer = layers()->currentLayer();
1095 if (layer ==
nullptr) {
return; }
1097 if (layer->type() == Layer::VECTOR)
1100 if (vectorImage !=
nullptr)
1106 if (layer->hasAnySelectedFrames()) {
1107 layer->deselectAll();
1108 emit updateTimeLine();
1122void Editor::setCurrentLayerIndex(
int i)
1124 mCurrentLayerIndex = i;
1126 Layer* layer = mObject->getLayer(i);
1127 for (
auto mgr : mAllManagers)
1129 mgr->workingLayerChanged(layer);
1133void Editor::scrubTo(
int frame)
1135 if (frame < 1) { frame = 1; }
1143 if (mPlaybackManager && !mPlaybackManager->isPlaying())
1145 emit updateTimeLineCached();
1147 mObject->updateActiveFrames(frame);
1150void Editor::scrubForward()
1152 int nextFrame = mFrame + 1;
1153 if (!playback()->isPlaying()) {
1154 playback()->playScrub(nextFrame);
1159void Editor::scrubBackward()
1161 if (currentFrame() > 1)
1163 int previousFrame = mFrame - 1;
1164 if (!playback()->isPlaying()) {
1165 playback()->playScrub(previousFrame);
1167 scrubTo(previousFrame);
1173 return addKeyFrame(layers()->currentLayerIndex(), currentFrame());
1176KeyFrame* Editor::addKeyFrame(
int layerNumber,
int frameIndex)
1178 Layer* layer = mObject->getLayer(layerNumber);
1181 if (!layer->visible())
1183 mScribbleArea->showLayerNotVisibleWarning();
1188 while (layer->keyExists(frameIndex))
1190 if (layer->type() == Layer::SOUND
1191 && layer->getKeyFrameAt(frameIndex)->fileName().
isEmpty()
1192 && layer->removeKeyFrame(frameIndex))
1202 bool ok = layer->addNewKeyFrameAt(frameIndex);
1205 scrubTo(frameIndex);
1209 return layer->getKeyFrameAt(frameIndex);
1212void Editor::removeKey()
1214 Layer* layer = layers()->currentLayer();
1215 Q_ASSERT(layer !=
nullptr);
1217 if (!layer->visible())
1219 mScribbleArea->showLayerNotVisibleWarning();
1223 if (!layer->keyExistsWhichCovers(currentFrame()))
1229 backup(
tr(
"Remove frame"));
1232 layer->removeKeyFrame(currentFrame());
1234 emit layers()->currentLayerChanged(layers()->currentLayerIndex());
1237void Editor::scrubNextKeyFrame()
1239 Layer* currentLayer = layers()->currentLayer();
1240 Q_ASSERT(currentLayer);
1242 int nextPosition = currentLayer->getNextKeyFramePosition(currentFrame());
1243 if (currentFrame() >= currentLayer->getMaxKeyFramePosition()) nextPosition = currentFrame() + 1;
1244 scrubTo(nextPosition);
1247void Editor::scrubPreviousKeyFrame()
1249 Layer* layer = mObject->getLayer(layers()->currentLayerIndex());
1252 int prevPosition = layer->getPreviousKeyFramePosition(currentFrame());
1253 scrubTo(prevPosition);
1256void Editor::switchVisibilityOfLayer(
int layerNumber)
1258 Layer* layer = mObject->getLayer(layerNumber);
1259 if (layer !=
nullptr) layer->switchVisibility();
1262 emit updateTimeLine();
1265void Editor::swapLayers(
int i,
int j)
1267 bool didSwapLayer = mObject->swapLayers(i, j);
1268 if (!didSwapLayer) {
return; }
1272 layers()->setCurrentLayer(j + 1);
1276 layers()->setCurrentLayer(j - 1);
1278 emit updateTimeLine();
1282bool Editor::canSwapLayers(
int layerIndexLeft,
int layerIndexRight)
const
1284 return mObject->canSwapLayers(layerIndexLeft, layerIndexRight);
1287void Editor::prepareSave()
1289 for (
auto mgr : mAllManagers)
1291 mgr->save(mObject.get());
1295void Editor::clearCurrentFrame()
1297 mScribbleArea->clearImage();
1300bool Editor::canCopy()
const
1302 Layer* layer = layers()->currentLayer();
1303 KeyFrame* keyframe = layer->getLastKeyFrameAtPosition(mFrame);
1305 switch (layer->type())
1309 return canCopyFrames(layer);
1311 return canCopyBitmapImage(
static_cast<BitmapImage*
>(keyframe)) || canCopyFrames(layer);
1313 return canCopyVectorImage(
static_cast<VectorImage*
>(keyframe)) || canCopyFrames(layer);
1319bool Editor::canPaste()
const
1321 Layer* layer = layers()->currentLayer();
1322 auto clipboardMan = clipboards();
1323 auto layerType = layer->type();
1325 return (layerType == clipboardMan->framesLayerType() && !clipboardMan->framesIsEmpty()) ||
1326 (layerType == Layer::BITMAP && clipboardMan->getBitmapClipboard().isLoaded()) ||
1327 (layerType == Layer::VECTOR && !clipboardMan->getVectorClipboard().isEmpty());
1330bool Editor::canCopyFrames(
const Layer* layer)
const
1332 Q_ASSERT(layer !=
nullptr);
1333 return layer->hasAnySelectedFrames();
1336bool Editor::canCopyBitmapImage(
BitmapImage* bitmapImage)
const
1338 return bitmapImage !=
nullptr && bitmapImage->isLoaded() && !bitmapImage->bounds().
isEmpty();
1341bool Editor::canCopyVectorImage(
const VectorImage* vectorImage)
const
1343 return vectorImage !=
nullptr && !vectorImage->isEmpty();
void copySelectedFrames(const Layer *currentLayer)
Copy selected keyframes of any given layer and remember its type.
void copyVectorImage(const VectorImage *vectorImage)
Copy the entire vector image to clipboard, this operation does not yet support partial selections.
void copyBitmapImage(BitmapImage *image, QRectF selectionRect)
Copy bitmap image to clipboard and save its latest position Additionally only a part of the image wil...
void updateFrame(int frameNumber)
Will call update() and update the canvas Only call this directly If you need the cache to be intact a...
void updateCurrentFrame()
Will call update() and update the canvas Only call this directly If you need the cache to be intact a...
void frameModified(int frameNumber)
This should be emitted after modifying the frame content.
void scrubbed(int frameNumber)
This should be emitted after scrubbing.
void sanitizeBackupElementsAfterLayerDeletion(int layerIndex)
Restores integrity of the backup elements after a layer has been deleted.
void setLayerVisibility(LayerVisibility visibility)
The visibility value should match any of the VISIBILITY enum values.
bool newSelectionOfConnectedFrames(int position)
Make a selection from specified position until a blank spot appears The search is only looking forwar...
QList< int > selectedKeyFramesPositions() const
Get selected keyframe positions sorted by position.
void notifyAnimationLengthChanged()
This should be emitted whenever the animation length frames, eg.
void handleDrawingOnEmptyFrame()
Call this when starting to use a paint tool.
void onOnionSkinTypeChanged()
Onion skin type changed, all frames will be affected.
void updateCurrentFrame()
Update current frame.
void updateFrame(int frame)
Update frame.
void onLayerChanged()
Layer changed, invalidate relevant cache.
void deselectAll()
VectorImage::deselectAll.
void paste(VectorImage &)
VectorImage::paste.
bool read(QString filePath)
VectorImage::read.
void selectAll()
VectorImage::selectAll.
void append(const T &value)
bool isEmpty() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString tr(const char *sourceText, const char *disambiguation, int n)
bool isEmpty() const const
QPoint topLeft() const const
qreal height() const const
QRect toRect() const const
QPointF topLeft() const const
qreal width() const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
bool isEmpty() const const