diff --git a/src/core/Animators/paintsettingsanimator.cpp b/src/core/Animators/paintsettingsanimator.cpp index 50b65d485..fd5fe8cd7 100644 --- a/src/core/Animators/paintsettingsanimator.cpp +++ b/src/core/Animators/paintsettingsanimator.cpp @@ -57,7 +57,8 @@ void PaintSettingsAnimator::prp_writeProperty_impl(eWriteStream& dst) const { mGradientTransform->prp_writeProperty_impl(dst); } -void PaintSettingsAnimator::prp_readProperty_impl(eReadStream& src) { +void PaintSettingsAnimator::prp_readProperty_impl(eReadStream& src) +{ mColor->prp_readProperty_impl(src); PaintType paintType; src.read(&paintType, sizeof(PaintType)); @@ -65,18 +66,27 @@ void PaintSettingsAnimator::prp_readProperty_impl(eReadStream& src) { int gradRWId; src >> gradRWId; int gradDocId; src >> gradDocId; SimpleTask::sScheduleContexted(this, [this, gradRWId, gradDocId]() { - const auto parentScene = getParentScene(); - if(!parentScene) return; + auto parentScene = getParentScene(); + if (!parentScene) { return; } SceneBoundGradient* gradient = nullptr; - if(gradRWId != -1) + if (gradRWId != -1) { gradient = parentScene->getGradientWithRWId(gradRWId); - if(!gradient && gradDocId != -1) + } + if (!gradient && gradDocId != -1) { gradient = parentScene->getGradientWithDocumentId(gradDocId); + if (!gradient) { // gradient is in a different scene + gradient = parentScene->getGradientWithDocumentSceneId(gradDocId); + const auto newGrad = parentScene->createNewGradient(); + const auto clipboard = enve::make_shared(gradient); + clipboard->paste(newGrad); + gradient = newGrad; + } + } setGradientVar(gradient); }); mGradientPoints->prp_readProperty_impl(src); - if(src.evFileVersion() > 7) { + if (src.evFileVersion() > 7) { mGradientTransform->prp_readProperty_impl(src); } setPaintType(paintType); diff --git a/src/core/canvas.cpp b/src/core/canvas.cpp index 2414b1db8..8e103c71d 100644 --- a/src/core/canvas.cpp +++ b/src/core/canvas.cpp @@ -1403,6 +1403,16 @@ SceneBoundGradient *Canvas::getGradientWithDocumentId(const int id) const return nullptr; } +SceneBoundGradient *Canvas::getGradientWithDocumentSceneId(const int id) const +{ + for (const auto &scene : mDocument.fScenes) { + for (const auto &grad : scene->mGradients) { + if (grad->getDocumentId() == id) { return grad.get(); } + } + } + return nullptr; +} + void Canvas::addNullObject(NullObject* const obj) { mNullObjects.append(obj); diff --git a/src/core/canvas.h b/src/core/canvas.h index d5253274f..98f8f3f9a 100644 --- a/src/core/canvas.h +++ b/src/core/canvas.h @@ -702,6 +702,7 @@ class CORE_EXPORT Canvas : public CanvasBase SceneBoundGradient * getGradientWithRWId(const int rwId) const; SceneBoundGradient * getGradientWithDocumentId(const int id) const; + SceneBoundGradient * getGradientWithDocumentSceneId(const int id) const; void addNullObject(NullObject* const obj); void removeNullObject(NullObject* const obj);