Commit 05cce0cc authored by Jouni Pentikäinen's avatar Jouni Pentikäinen
Browse files

Fix sharing keyframe data when duplicating animated layers

BUG: 372695
parent be71b5c4
......@@ -54,6 +54,15 @@ KisKeyframe::KisKeyframe(KisKeyframeChannel *channel, int time)
m_d->colorLabel = config.defaultFrameColorLabel();
}
KisKeyframe::KisKeyframe(const KisKeyframe *rhs, KisKeyframeChannel *channel)
: m_d(new Private(channel, rhs->time()))
{
m_d->interpolationMode = rhs->m_d->interpolationMode;
m_d->tangentsMode = rhs->m_d->tangentsMode;
m_d->leftTangent = rhs->m_d->leftTangent;
m_d->rightTangent = rhs->m_d->rightTangent;
m_d->colorLabel = rhs->m_d->colorLabel;
}
KisKeyframe::~KisKeyframe()
{}
......
......@@ -45,6 +45,12 @@ public:
KisKeyframe(KisKeyframeChannel *channel, int time);
virtual ~KisKeyframe();
/**
* Create a copy of the keyframe for insertion into given channel.
* Used when constructing a copy of a keyframe channel.
*/
virtual KisKeyframeSP cloneFor(KisKeyframeChannel *channel) const = 0;
int time() const;
void setTime(int time);
......@@ -61,6 +67,9 @@ public:
KisKeyframeChannel *channel() const;
protected:
KisKeyframe(const KisKeyframe *rhs, KisKeyframeChannel *channel);
private:
struct Private;
QScopedPointer<Private> m_d;
......
......@@ -43,7 +43,6 @@ struct KisKeyframeChannel::Private
{
Private() {}
Private(const Private &rhs, KisNodeWSP newParentNode) {
keys = rhs.keys;
node = newParentNode;
id = rhs.id;
defaultBounds = rhs.defaultBounds;
......@@ -67,6 +66,10 @@ KisKeyframeChannel::KisKeyframeChannel(const KisKeyframeChannel &rhs, KisNodeWSP
: m_d(new Private(*rhs.m_d, newParentNode))
{
KIS_ASSERT_RECOVER_NOOP(&rhs != this);
Q_FOREACH(KisKeyframeSP keyframe, rhs.m_d->keys) {
m_d->keys.insert(keyframe->time(), keyframe->cloneFor(this));
}
}
KisKeyframeChannel::~KisKeyframeChannel()
......
......@@ -33,7 +33,20 @@ struct KisRasterKeyframe : public KisKeyframe
, frameId(frameId)
{}
KisRasterKeyframe(const KisRasterKeyframe *rhs, KisRasterKeyframeChannel *channel)
: KisKeyframe(rhs, channel)
, frameId(rhs->frameId)
{}
int frameId;
KisKeyframeSP cloneFor(KisKeyframeChannel *channel) const
{
KisRasterKeyframeChannel *rasterChannel = dynamic_cast<KisRasterKeyframeChannel*>(channel);
Q_ASSERT(rasterChannel);
return toQShared(new KisRasterKeyframe(this, rasterChannel));
}
};
struct KisRasterKeyframeChannel::Private
......
......@@ -31,7 +31,17 @@ struct KisScalarKeyframe : public KisKeyframe
, value(value)
{}
KisScalarKeyframe(const KisScalarKeyframe *rhs, KisKeyframeChannel *channel)
: KisKeyframe(rhs, channel)
, value(rhs->value)
{}
qreal value;
KisKeyframeSP cloneFor(KisKeyframeChannel *channel) const
{
return toQShared(new KisScalarKeyframe(this, channel));
}
};
......
......@@ -29,7 +29,19 @@ struct KisTransformArgsKeyframe : public KisKeyframe
, args(args)
{}
KisTransformArgsKeyframe(const KisTransformArgsKeyframe *rhs, KisKeyframeChannel *channel)
: KisKeyframe(rhs, channel)
, args(rhs->args)
{}
ToolTransformArgs args;
KisKeyframeSP cloneFor(KisKeyframeChannel *channel) const
{
KisTransformArgsKeyframeChannel *argsChannel = dynamic_cast<KisTransformArgsKeyframeChannel*>(channel);
Q_ASSERT(argsChannel);
return toQShared(new KisTransformArgsKeyframe(this, channel));
}
};
KisTransformArgsKeyframeChannel::AddKeyframeCommand::AddKeyframeCommand(KisTransformArgsKeyframeChannel *channel, int time, const ToolTransformArgs &args, KUndo2Command *parentCommand)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment