From 2f218970ba64424308c12ba0eb8e545f6778fcbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole-Andr=C3=A9=20Rodlie?= Date: Tue, 27 Aug 2024 21:32:25 +0200 Subject: [PATCH] TransformEffects: support SVG #173 Only 'follow path' is supported. --- .../TransformEffects/followpatheffect.cpp | 28 ++++++++++++++++++ src/core/TransformEffects/followpatheffect.h | 6 ++++ .../transformeffectcollection.cpp | 29 +++++++++++++++++++ .../transformeffectcollection.h | 7 +++++ 4 files changed, 70 insertions(+) diff --git a/src/core/TransformEffects/followpatheffect.cpp b/src/core/TransformEffects/followpatheffect.cpp index 1e577464a..f4e4f8217 100644 --- a/src/core/TransformEffects/followpatheffect.cpp +++ b/src/core/TransformEffects/followpatheffect.cpp @@ -28,6 +28,7 @@ #include "Boxes/pathbox.h" #include "Animators/qrealanimator.h" #include "Animators/transformanimator.h" +#include "svgexporter.h" FollowPathEffect::FollowPathEffect() : TargetTransformEffect("follow path", TransformEffectType::followPath) { @@ -181,3 +182,30 @@ void FollowPathEffect::applyEffect(const qreal relFrame, posX += posXChange; //p1.x()*infl; posY += posYChange; //p1.y()*infl; } + +QDomElement FollowPathEffect::saveFollowPathSVG(SvgExporter &exp, + const FrameRange &visRange, + QDomElement &childElement, + QDomElement &parentElement) const +{ + const auto target = targetProperty()->getTarget(); + if (!target) { return parentElement; } + mComplete->saveQrealSVG(exp, + childElement, + visRange, + "transform", + 1., + false, + "", + "%1", + "", + "", + true, + mRotate->getValue(), + target->prp_getName()); + const auto transform = target->getBoxTransformAnimator(); + const auto transformed = transform->saveSVG(exp, + visRange, + parentElement); + return transformed; +} diff --git a/src/core/TransformEffects/followpatheffect.h b/src/core/TransformEffects/followpatheffect.h index 53a32d82b..9c9f55aca 100644 --- a/src/core/TransformEffects/followpatheffect.h +++ b/src/core/TransformEffects/followpatheffect.h @@ -42,6 +42,12 @@ class FollowPathEffect : public TargetTransformEffect { qreal &shearX, qreal &shearY, QMatrix& postTransform, BoundingBox* const parent) override; + + QDomElement saveFollowPathSVG(SvgExporter& exp, + const FrameRange& visRange, + QDomElement &childElement, + QDomElement &parentElement) const; + private: void setRotScaleAfterTargetChange( BoundingBox* const oldTarget, diff --git a/src/core/TransformEffects/transformeffectcollection.cpp b/src/core/TransformEffects/transformeffectcollection.cpp index 9fd184e16..b9e2c6f51 100644 --- a/src/core/TransformEffects/transformeffectcollection.cpp +++ b/src/core/TransformEffects/transformeffectcollection.cpp @@ -91,6 +91,35 @@ void TransformEffectCollection::prp_readProperty_impl(eReadStream &src) { } } +bool TransformEffectCollection::hasEffectsSVG() +{ + const auto& children = ca_getChildren(); + for (const auto& effect : children) { + if (const auto followPath = enve_cast(effect.get())) { + return true; + } + } + return false; +} + +QDomElement TransformEffectCollection::saveEffectsSVG(SvgExporter &exp, + const FrameRange &visRange, + QDomElement &childElement, + const QDomElement &parentElement) const +{ + QDomElement result = parentElement; + const auto& children = ca_getChildren(); + for (const auto& effect : children) { + if (const auto path = enve_cast(effect.get())) { + result = path->saveFollowPathSVG(exp, + visRange, + childElement, + result); + } + } + return result; +} + void TransformEffectCollection::applyEffects( const qreal relFrame, qreal& pivotX, qreal& pivotY, diff --git a/src/core/TransformEffects/transformeffectcollection.h b/src/core/TransformEffects/transformeffectcollection.h index d6ac7c071..0a27236cf 100644 --- a/src/core/TransformEffects/transformeffectcollection.h +++ b/src/core/TransformEffects/transformeffectcollection.h @@ -59,8 +59,15 @@ class CORE_EXPORT TransformEffectCollection : void prp_readProperty_impl(eReadStream &src); bool hasEffects(); + bool hasEffectsSVG(); + void readTransformEffect(eReadStream &target); + QDomElement saveEffectsSVG(SvgExporter& exp, + const FrameRange& visRange, + QDomElement &childElement, + const QDomElement &parentElement) const; + void applyEffects(const qreal relFrame, qreal& pivotX, qreal& pivotY, qreal& posX, qreal& posY,