Krita Source Code Documentation
Loading...
Searching...
No Matches
KisKeyframeChannel Class Referenceabstract

KisKeyframeChannel stores and manages KisKeyframes. Maps units of time to virtual keyframe values. This class is a key piece of Krita's animation backend. Abstract base class of KisRasterKeyframeChannel, KisScalarKeyframeChannel, etc. More...

#include <kis_keyframe_channel.h>

+ Inheritance diagram for KisKeyframeChannel:

Classes

struct  Private
 

Signals

void sigAddedKeyframe (const KisKeyframeChannel *channel, int time)
 This signal is emitted just AFTER a keyframe was added to the channel.
 
void sigAnyKeyframeChange ()
 
void sigKeyframeAboutToBeRemoved (const KisKeyframeChannel *channel, int time)
 This signal is emitted just BEFORE a keyframe is removed from the channel.
 
void sigKeyframeChanged (const KisKeyframeChannel *channel, int time)
 This signal is emitted just AFTER a non-raster keyframe was changed its value.
 
void sigKeyframeHasBeenRemoved (const KisKeyframeChannel *channel, int time)
 This signal is emitted just AFTER a keyframe is removed from the channel.
 

Public Member Functions

KisKeyframeSP activeKeyframeAt (int time) const
 
template<class KeyframeType >
QSharedPointer< KeyframeType > activeKeyframeAt (int time) const
 
int activeKeyframeTime () const
 
int activeKeyframeTime (int time) const
 Get the time of the active keyframe. Useful for snapping any time to that of the most recent keyframe.
 
void addKeyframe (int time, KUndo2Command *parentUndoCmd=nullptr)
 Add a new keyframe to the channel at the specified time.
 
virtual KisTimeSpan affectedFrames (int time) const
 Get the set of frames affected by any changes to the value or content of the active keyframe at the given time.
 
virtual QRect affectedRect (int time) const =0
 
QSet< int > allKeyframeTimes () const
 Get a set of all integer times that map to a keyframe.
 
int channelHash () const
 Calculates a pseudo-unique hash based on the relevant internal state of the channel.
 
void copyKeyframe (int sourceTime, int targetTime, KUndo2Command *parentUndoCmd=nullptr)
 
int firstKeyframeTime () const
 
QString id () const
 
virtual KisTimeSpan identicalFrames (int time) const
 Get a span of times for which the channel gives identical results compared to frame at a given time. NOTE: This set may be different than the set of affected frames due to interpolation.
 
virtual void insertKeyframe (int time, KisKeyframeSP keyframe, KUndo2Command *parentUndoCmd=nullptr)
 Insert an existing keyframe into the channel at the specified time.
 
KisKeyframeSP keyframeAt (int time) const
 Get a keyframe at specified time. Used primarily when the value of a given keyframe is needed.
 
template<class KeyframeType >
QSharedPointer< KeyframeType > keyframeAt (int time) const
 
int keyframeCount () const
 
 KisKeyframeChannel (const KisKeyframeChannel &rhs)
 
 KisKeyframeChannel (const KoID &id, KisDefaultBoundsBaseSP bounds)
 
int lastKeyframeTime () const
 
virtual void loadXML (const QDomElement &channelNode)
 
int lookupKeyframeTime (KisKeyframeSP toLookup)
 Search for the time for a given keyframe. (Reverse map lookup, so use sparingly.)
 
void moveKeyframe (int sourceTime, int targetTime, KUndo2Command *parentUndoCmd=nullptr)
 
QString name () const
 
int nextKeyframeTime (const int time) const
 
KisNodeWSP node () const
 
int previousKeyframeTime (const int time) const
 
virtual void removeKeyframe (int time, KUndo2Command *parentUndoCmd=nullptr)
 Remove a keyframe from the channel at the specified time.
 
void setDefaultBounds (KisDefaultBoundsBaseSP bounds)
 
void setNode (KisNodeWSP node)
 
void swapKeyframes (int timeA, int timeB, KUndo2Command *parentUndoCmd=nullptr)
 
virtual QDomElement toXML (QDomDocument doc, const QString &layerFilename)
 
 ~KisKeyframeChannel () override
 

Static Public Member Functions

static KoID channelIdToKoId (const QString &id)
 
static void copyKeyframe (const KisKeyframeChannel *sourceChannel, int sourceTime, KisKeyframeChannel *targetChannel, int targetTime, KUndo2Command *parentUndoCmd=nullptr)
 Copy a keyframe across channel(s) at the specified times.
 
static void moveKeyframe (KisKeyframeChannel *sourceChannel, int sourceTime, KisKeyframeChannel *targetChannel, int targetTime, KUndo2Command *parentUndoCmd=nullptr)
 Move a keyframe across channel(s) at the specified times.
 
static void swapKeyframes (KisKeyframeChannel *channelA, int timeA, KisKeyframeChannel *channelB, int timeB, KUndo2Command *parentUndoCmd=nullptr)
 Swap two keyframes across channel(s) at the specified times.
 

Static Public Attributes

static const KoID Opacity = KoID("opacity", ki18n("Opacity"))
 
static const KoID PositionX = KoID("transform_pos_x", ki18n("Position (X)"))
 
static const KoID PositionY = KoID("transform_pos_y", ki18n("Position (Y)"))
 
static const KoID Raster = KoID("content", ki18n("Content"))
 
static const KoID RotationX = KoID("transform_rotation_x", ki18n("Rotation (X)"))
 
static const KoID RotationY = KoID("transform_rotation_y", ki18n("Rotation (Y)"))
 
static const KoID RotationZ = KoID("transform_rotation_z", ki18n("Rotation (Z)"))
 
static const KoID ScaleX = KoID("transform_scale_x", ki18n("Scale (X)"))
 
static const KoID ScaleY = KoID("transform_scale_y", ki18n("Scale (Y)"))
 
static const KoID ShearX = KoID("transform_shear_x", ki18n("Shear (X)"))
 
static const KoID ShearY = KoID("transform_shear_y", ki18n("Shear (Y)"))
 
static const KoID TransformArguments
 

Protected Types

typedef QMap< int, KisKeyframeSPTimeKeyframeMap
 

Protected Member Functions

const TimeKeyframeMapconstKeys () const
 
int currentTime () const
 
TimeKeyframeMapkeys ()
 
virtual void removeKeyframeImpl (int time, KUndo2Command *parentUndoCmd)
 
Q_DECL_DEPRECATED void workaroundBrokenFrameTimeBug (int *time)
 Between Krita 4.1 and 4.4 Krita had a bug which resulted in creating frames with negative time stamp. The bug has been fixed, but there might be some files still in the wild.
 

Private Member Functions

virtual KisKeyframeSP createKeyframe ()=0
 Virtual keyframe creation function. Derived classes implement this function based on the needs of their specific KisKeyframe subclasses.
 
virtual QPair< int, KisKeyframeSPloadKeyframe (const QDomElement &keyframeNode)=0
 
virtual void saveKeyframe (KisKeyframeSP keyframe, QDomElement keyframeElement, const QString &layerFilename)=0
 

Private Attributes

QScopedPointer< Privatem_d
 

Detailed Description

KisKeyframeChannel stores and manages KisKeyframes. Maps units of time to virtual keyframe values. This class is a key piece of Krita's animation backend. Abstract base class of KisRasterKeyframeChannel, KisScalarKeyframeChannel, etc.

Definition at line 32 of file kis_keyframe_channel.h.

Member Typedef Documentation

◆ TimeKeyframeMap

typedef QMap<int, KisKeyframeSP> KisKeyframeChannel::TimeKeyframeMap
protected

Definition at line 173 of file kis_keyframe_channel.h.

Constructor & Destructor Documentation

◆ KisKeyframeChannel() [1/2]

KisKeyframeChannel::KisKeyframeChannel ( const KoID & id,
KisDefaultBoundsBaseSP bounds )

Definition at line 94 of file kis_keyframe_channel.cpp.

95 : m_d(new Private(id, bounds))
96{
97 // Added keyframes should fire channel updated signal..
99 Q_EMIT sigAnyKeyframeChange();
100 });
101
103 Q_EMIT sigAnyKeyframeChange();
104 });
105
107 Q_EMIT sigAnyKeyframeChange();
108 });
109}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KisKeyframeChannel stores and manages KisKeyframes. Maps units of time to virtual keyframe values....
void sigAnyKeyframeChange()
QScopedPointer< Private > m_d
void sigKeyframeHasBeenRemoved(const KisKeyframeChannel *channel, int time)
This signal is emitted just AFTER a keyframe is removed from the channel.
void sigKeyframeChanged(const KisKeyframeChannel *channel, int time)
This signal is emitted just AFTER a non-raster keyframe was changed its value.
void sigAddedKeyframe(const KisKeyframeChannel *channel, int time)
This signal is emitted just AFTER a keyframe was added to the channel.
#define bounds(x, a, b)

References connect(), sigAddedKeyframe(), sigAnyKeyframeChange(), sigKeyframeChanged(), and sigKeyframeHasBeenRemoved().

◆ KisKeyframeChannel() [2/2]

KisKeyframeChannel::KisKeyframeChannel ( const KisKeyframeChannel & rhs)

Definition at line 111 of file kis_keyframe_channel.cpp.

112 : KisKeyframeChannel(rhs.m_d->id, new KisDefaultBounds(nullptr))
113{
114 m_d.reset(new Private(*rhs.m_d));
115}
KisKeyframeChannel(const KoID &id, KisDefaultBoundsBaseSP bounds)

References m_d.

◆ ~KisKeyframeChannel()

KisKeyframeChannel::~KisKeyframeChannel ( )
override

Definition at line 117 of file kis_keyframe_channel.cpp.

118{
119}

Member Function Documentation

◆ activeKeyframeAt() [1/2]

KisKeyframeSP KisKeyframeChannel::activeKeyframeAt ( int time) const
inline

Definition at line 82 of file kis_keyframe_channel.h.

82{ return keyframeAt(activeKeyframeTime(time)); }
KisKeyframeSP keyframeAt(int time) const
Get a keyframe at specified time. Used primarily when the value of a given keyframe is needed.

◆ activeKeyframeAt() [2/2]

template<class KeyframeType >
QSharedPointer< KeyframeType > KisKeyframeChannel::activeKeyframeAt ( int time) const
inline

Definition at line 91 of file kis_keyframe_channel.h.

91 {
92 return activeKeyframeAt(time).dynamicCast<KeyframeType>();
93 }
KisKeyframeSP activeKeyframeAt(int time) const

◆ activeKeyframeTime() [1/2]

int KisKeyframeChannel::activeKeyframeTime ( ) const
inline

Definition at line 103 of file kis_keyframe_channel.h.

References activeKeyframeTime().

◆ activeKeyframeTime() [2/2]

int KisKeyframeChannel::activeKeyframeTime ( int time) const

Get the time of the active keyframe. Useful for snapping any time to that of the most recent keyframe.

Parameters
timeInput time. When not specified, currentTime() will be used.

Definition at line 233 of file kis_keyframe_channel.cpp.

234{
235 QMap<int, KisKeyframeSP>::const_iterator iter = const_cast<const QMap<int, KisKeyframeSP>*>(&m_d->keys)->upperBound(time);
236
237 // If the next keyframe is the first keyframe, that means there's no active frame.
238 if (iter == m_d->keys.constBegin()) {
239 return -1;
240 }
241
242 iter--;
243
244 if (iter == m_d->keys.constEnd()) {
245 return -1;
246 }
247
248 return iter.key();
249}

References m_d.

◆ addKeyframe()

void KisKeyframeChannel::addKeyframe ( int time,
KUndo2Command * parentUndoCmd = nullptr )

Add a new keyframe to the channel at the specified time.

Definition at line 121 of file kis_keyframe_channel.cpp.

122{
123 KisKeyframeSP keyframe = createKeyframe();
124 insertKeyframe(time, keyframe, parentUndoCmd);
125}
virtual KisKeyframeSP createKeyframe()=0
Virtual keyframe creation function. Derived classes implement this function based on the needs of the...
virtual void insertKeyframe(int time, KisKeyframeSP keyframe, KUndo2Command *parentUndoCmd=nullptr)
Insert an existing keyframe into the channel at the specified time.

References createKeyframe(), and insertKeyframe().

◆ affectedFrames()

KisTimeSpan KisKeyframeChannel::affectedFrames ( int time) const
virtual

Get the set of frames affected by any changes to the value or content of the active keyframe at the given time.

Reimplemented in KisScalarKeyframeChannel.

Definition at line 372 of file kis_keyframe_channel.cpp.

373{
374 if (m_d->keys.isEmpty()) return KisTimeSpan::infinite(0);
375
376 const int activeKeyTime = activeKeyframeTime(time);
377 const int nextKeyTime = nextKeyframeTime(time);
378
379 // Check for keyframe behind..
380 if (!keyframeAt(activeKeyTime)) {
381 return KisTimeSpan::fromTimeToTime(0, nextKeyTime - 1);
382 }
383
384 // Check for keyframe ahead..
385 if (!keyframeAt(nextKeyTime)) {
386 return KisTimeSpan::infinite(activeKeyTime);
387 }
388
389 return KisTimeSpan::fromTimeToTime(activeKeyTime, nextKeyTime - 1);
390}
int nextKeyframeTime(const int time) const
static KisTimeSpan infinite(int start)
static KisTimeSpan fromTimeToTime(int start, int end)

References activeKeyframeTime(), KisTimeSpan::fromTimeToTime(), KisTimeSpan::infinite(), keyframeAt(), m_d, and nextKeyframeTime().

◆ affectedRect()

virtual QRect KisKeyframeChannel::affectedRect ( int time) const
pure virtual

The rect that is affected by a frame at the given time

Implemented in KisRasterKeyframeChannel, and KisScalarKeyframeChannel.

◆ allKeyframeTimes()

QSet< int > KisKeyframeChannel::allKeyframeTimes ( ) const

Get a set of all integer times that map to a keyframe.

Definition at line 303 of file kis_keyframe_channel.cpp.

304{
305 QSet<int> frames;
306
307 TimeKeyframeMap::const_iterator it = m_d->keys.constBegin();
308 TimeKeyframeMap::const_iterator end = m_d->keys.constEnd();
309
310 while (it != end) {
311 frames.insert(it.key());
312 ++it;
313 }
314
315 return frames;
316}

References m_d.

◆ channelHash()

int KisKeyframeChannel::channelHash ( ) const

Calculates a pseudo-unique hash based on the relevant internal state of the channel.

Definition at line 357 of file kis_keyframe_channel.cpp.

358{
359 TimeKeyframeMap::const_iterator it = m_d->keys.constBegin();
360 TimeKeyframeMap::const_iterator end = m_d->keys.constEnd();
361
362 int hash = 0;
363
364 while (it != end) {
365 hash += it.key();
366 ++it;
367 }
368
369 return hash;
370}

References m_d.

◆ channelIdToKoId()

KoID KisKeyframeChannel::channelIdToKoId ( const QString & id)
static

Definition at line 38 of file kis_keyframe_channel.cpp.

39{
40 KoID channelId;
41
42 if (id == KisKeyframeChannel::Raster.id()) {
44 } else if (id == KisKeyframeChannel::Opacity.id()) {
46 } else if (id == KisKeyframeChannel::PositionX.id()) {
48 } else if (id == KisKeyframeChannel::PositionY.id()) {
50 } else if (id == KisKeyframeChannel::ScaleX.id()) {
52 } else if (id == KisKeyframeChannel::ScaleY.id()) {
54 } else if (id == KisKeyframeChannel::ShearX.id()) {
56 } else if (id == KisKeyframeChannel::ShearY.id()) {
58 } else if (id == KisKeyframeChannel::RotationX.id()) {
60 } else if (id == KisKeyframeChannel::RotationY.id()) {
62 } else if (id == KisKeyframeChannel::RotationZ.id()) {
64
65 } else {
66 channelId = KoID();
67 }
68
69 return channelId;
70}
static const KoID RotationY
static const KoID Raster
static const KoID ScaleY
static const KoID RotationZ
static const KoID Opacity
static const KoID ScaleX
static const KoID RotationX
static const KoID PositionX
static const KoID PositionY
static const KoID ShearX
static const KoID ShearY
Definition KoID.h:30

References Opacity, PositionX, PositionY, Raster, RotationX, RotationY, RotationZ, ScaleX, ScaleY, ShearX, and ShearY.

◆ constKeys()

const KisKeyframeChannel::TimeKeyframeMap & KisKeyframeChannel::constKeys ( ) const
protected

Definition at line 439 of file kis_keyframe_channel.cpp.

440{
441 return m_d->keys;
442}

References m_d.

◆ copyKeyframe() [1/2]

void KisKeyframeChannel::copyKeyframe ( const KisKeyframeChannel * sourceChannel,
int sourceTime,
KisKeyframeChannel * targetChannel,
int targetTime,
KUndo2Command * parentUndoCmd = nullptr )
static

Copy a keyframe across channel(s) at the specified times.

Definition at line 186 of file kis_keyframe_channel.cpp.

187{
188 KIS_ASSERT(sourceChannel && targetChannel);
189
190 KisKeyframeSP sourceKeyframe = sourceChannel->keyframeAt(sourceTime);
191 if (!sourceKeyframe) return;
192
193 KisKeyframeSP copiedKeyframe = sourceKeyframe->duplicate(targetChannel);
194 KIS_SAFE_ASSERT_RECOVER_RETURN(copiedKeyframe);
195
196 targetChannel->insertKeyframe(targetTime, copiedKeyframe, parentUndoCmd);
197}
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define KIS_ASSERT(cond)
Definition kis_assert.h:33

References insertKeyframe(), keyframeAt(), KIS_ASSERT, and KIS_SAFE_ASSERT_RECOVER_RETURN.

◆ copyKeyframe() [2/2]

void KisKeyframeChannel::copyKeyframe ( int sourceTime,
int targetTime,
KUndo2Command * parentUndoCmd = nullptr )
inline

Definition at line 75 of file kis_keyframe_channel.h.

75{ copyKeyframe(this, sourceTime, this, targetTime, parentUndoCmd); }
static void copyKeyframe(const KisKeyframeChannel *sourceChannel, int sourceTime, KisKeyframeChannel *targetChannel, int targetTime, KUndo2Command *parentUndoCmd=nullptr)
Copy a keyframe across channel(s) at the specified times.

References copyKeyframe().

◆ createKeyframe()

virtual KisKeyframeSP KisKeyframeChannel::createKeyframe ( )
privatepure virtual

Virtual keyframe creation function. Derived classes implement this function based on the needs of their specific KisKeyframe subclasses.

Implemented in KisRasterKeyframeChannel, and KisScalarKeyframeChannel.

◆ currentTime()

int KisKeyframeChannel::currentTime ( ) const
protected

Definition at line 444 of file kis_keyframe_channel.cpp.

445{
446 return m_d->bounds->currentTime();
447}

References m_d.

◆ firstKeyframeTime()

int KisKeyframeChannel::firstKeyframeTime ( ) const

Definition at line 258 of file kis_keyframe_channel.cpp.

259{
260 if (m_d->keys.isEmpty()) {
261 return -1;
262 } else {
263 return m_d->keys.firstKey();
264 }
265}

References m_d.

◆ id()

QString KisKeyframeChannel::id ( ) const

Definition at line 318 of file kis_keyframe_channel.cpp.

319{
320 return m_d->id.id();
321}

References m_d.

◆ identicalFrames()

KisTimeSpan KisKeyframeChannel::identicalFrames ( int time) const
virtual

Get a span of times for which the channel gives identical results compared to frame at a given time. NOTE: This set may be different than the set of affected frames due to interpolation.

Reimplemented in KisScalarKeyframeChannel.

Definition at line 392 of file kis_keyframe_channel.cpp.

393{
394 return affectedFrames(time);
395}
virtual KisTimeSpan affectedFrames(int time) const
Get the set of frames affected by any changes to the value or content of the active keyframe at the g...

References affectedFrames().

◆ insertKeyframe()

void KisKeyframeChannel::insertKeyframe ( int time,
KisKeyframeSP keyframe,
KUndo2Command * parentUndoCmd = nullptr )
virtual

Insert an existing keyframe into the channel at the specified time.

Reimplemented in KisRasterKeyframeChannel, and KisScalarKeyframeChannel.

Definition at line 127 of file kis_keyframe_channel.cpp.

128{
129 KIS_ASSERT(time >= 0);
130 KIS_ASSERT(keyframe);
131
132 if (m_d->keys.contains(time)) {
133 // Properly remove overwritten frames.
134 removeKeyframe(time, parentUndoCmd);
135 }
136
137 if (parentUndoCmd) {
138 KUndo2Command* cmd =
140 new KisInsertKeyframeCommand(this, time, keyframe), parentUndoCmd);
141 Q_UNUSED(cmd);
142 }
143
144 m_d->keys.insert(time, keyframe);
145 Q_EMIT sigAddedKeyframe(this, time);
146}
virtual void removeKeyframe(int time, KUndo2Command *parentUndoCmd=nullptr)
Remove a keyframe from the channel at the specified time.

References KIS_ASSERT, m_d, removeKeyframe(), and sigAddedKeyframe().

◆ keyframeAt() [1/2]

KisKeyframeSP KisKeyframeChannel::keyframeAt ( int time) const

Get a keyframe at specified time. Used primarily when the value of a given keyframe is needed.

Definition at line 218 of file kis_keyframe_channel.cpp.

219{
220 QMap<int, KisKeyframeSP>::const_iterator iter = m_d->keys.constFind(time);
221 if (iter != m_d->keys.constEnd()) {
222 return iter.value();
223 } else {
224 return KisKeyframeSP();
225 }
226}
QSharedPointer< KisKeyframe > KisKeyframeSP
Definition kis_types.h:296

References m_d.

◆ keyframeAt() [2/2]

template<class KeyframeType >
QSharedPointer< KeyframeType > KisKeyframeChannel::keyframeAt ( int time) const
inline

Definition at line 86 of file kis_keyframe_channel.h.

86 {
87 return keyframeAt(time).dynamicCast<KeyframeType>();
88 }

◆ keyframeCount()

int KisKeyframeChannel::keyframeCount ( ) const

Definition at line 228 of file kis_keyframe_channel.cpp.

229{
230 return m_d->keys.count();
231}

References m_d.

◆ keys()

KisKeyframeChannel::TimeKeyframeMap & KisKeyframeChannel::keys ( )
protected

Definition at line 434 of file kis_keyframe_channel.cpp.

435{
436 return m_d->keys;
437}

References m_d.

◆ lastKeyframeTime()

int KisKeyframeChannel::lastKeyframeTime ( ) const

Definition at line 294 of file kis_keyframe_channel.cpp.

295{
296 if (m_d->keys.isEmpty()) {
297 return -1;
298 }
299
300 return m_d->keys.lastKey();
301}

References m_d.

◆ loadKeyframe()

virtual QPair< int, KisKeyframeSP > KisKeyframeChannel::loadKeyframe ( const QDomElement & keyframeNode)
privatepure virtual

◆ loadXML()

void KisKeyframeChannel::loadXML ( const QDomElement & channelNode)
virtual

Reimplemented in KisRasterKeyframeChannel.

Definition at line 418 of file kis_keyframe_channel.cpp.

419{
420 for (QDomElement keyframeNode = channelNode.firstChildElement(); !keyframeNode.isNull(); keyframeNode = keyframeNode.nextSiblingElement()) {
421 if (keyframeNode.nodeName().toUpper() != "KEYFRAME") continue;
422
423 QPair<int, KisKeyframeSP> timeKeyPair = loadKeyframe(keyframeNode);
424 KIS_SAFE_ASSERT_RECOVER(timeKeyPair.second) { continue; }
425
426 if (keyframeNode.hasAttribute("color-label")) {
427 timeKeyPair.second->setColorLabel(keyframeNode.attribute("color-label").toUInt());
428 }
429
430 insertKeyframe(timeKeyPair.first, timeKeyPair.second);
431 }
432}
virtual QPair< int, KisKeyframeSP > loadKeyframe(const QDomElement &keyframeNode)=0
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126

References insertKeyframe(), KIS_SAFE_ASSERT_RECOVER, and loadKeyframe().

◆ lookupKeyframeTime()

int KisKeyframeChannel::lookupKeyframeTime ( KisKeyframeSP toLookup)

Search for the time for a given keyframe. (Reverse map lookup, so use sparingly.)

Parameters
toLookup- the keyframe to look up the time for.
Returns
Returns the time of the keyframe.

Definition at line 251 of file kis_keyframe_channel.cpp.

252{
253 int time = m_d->keys.key(toLookup, -1);
254 KIS_ASSERT(time >= 0);
255 return time;
256}

References KIS_ASSERT, and m_d.

◆ moveKeyframe() [1/2]

void KisKeyframeChannel::moveKeyframe ( int sourceTime,
int targetTime,
KUndo2Command * parentUndoCmd = nullptr )
inline

Definition at line 74 of file kis_keyframe_channel.h.

74{ moveKeyframe(this, sourceTime, this, targetTime, parentUndoCmd); }
static void moveKeyframe(KisKeyframeChannel *sourceChannel, int sourceTime, KisKeyframeChannel *targetChannel, int targetTime, KUndo2Command *parentUndoCmd=nullptr)
Move a keyframe across channel(s) at the specified times.

References moveKeyframe().

◆ moveKeyframe() [2/2]

void KisKeyframeChannel::moveKeyframe ( KisKeyframeChannel * sourceChannel,
int sourceTime,
KisKeyframeChannel * targetChannel,
int targetTime,
KUndo2Command * parentUndoCmd = nullptr )
static

Move a keyframe across channel(s) at the specified times.

Definition at line 167 of file kis_keyframe_channel.cpp.

168{
169 KIS_ASSERT(sourceChannel && targetChannel);
170
171 KisKeyframeSP sourceKeyframe = sourceChannel->keyframeAt(sourceTime);
172 if (!sourceKeyframe) return;
173
174 sourceChannel->removeKeyframe(sourceTime, parentUndoCmd);
175
176 KisKeyframeSP targetKeyframe = sourceKeyframe;
177 if (sourceChannel != targetChannel) {
178 // When "moving" Keyframes between channels, a new copy is made for that channel.
179 targetKeyframe = sourceKeyframe->duplicate(targetChannel);
180 KIS_SAFE_ASSERT_RECOVER_RETURN(targetKeyframe);
181 }
182
183 targetChannel->insertKeyframe(targetTime, targetKeyframe, parentUndoCmd);
184}

References insertKeyframe(), keyframeAt(), KIS_ASSERT, KIS_SAFE_ASSERT_RECOVER_RETURN, and removeKeyframe().

◆ name()

QString KisKeyframeChannel::name ( ) const

Definition at line 323 of file kis_keyframe_channel.cpp.

324{
325 return m_d->id.name();
326}

References m_d.

◆ nextKeyframeTime()

int KisKeyframeChannel::nextKeyframeTime ( const int time) const

Definition at line 283 of file kis_keyframe_channel.cpp.

284{
285 QMap<int, KisKeyframeSP>::const_iterator iter = const_cast<const QMap<int, KisKeyframeSP>*>(&m_d->keys)->upperBound(time);
286
287 if (iter == m_d->keys.constEnd()) {
288 return -1;
289 }
290
291 return iter.key();
292}

References m_d.

◆ node()

KisNodeWSP KisKeyframeChannel::node ( ) const

Definition at line 348 of file kis_keyframe_channel.cpp.

349{
350 return m_d->parentNode;
351}

References m_d.

◆ previousKeyframeTime()

int KisKeyframeChannel::previousKeyframeTime ( const int time) const

Definition at line 267 of file kis_keyframe_channel.cpp.

268{
269 if (!keyframeAt(time)) {
270 return activeKeyframeTime(time);
271 }
272
273 QMap<int, KisKeyframeSP>::const_iterator iter = m_d->keys.constFind(time);
274
275 if (iter == m_d->keys.constBegin() || iter == m_d->keys.constEnd()) {
276 return -1;
277 }
278
279 iter--;
280 return iter.key();
281}

References activeKeyframeTime(), keyframeAt(), and m_d.

◆ removeKeyframe()

void KisKeyframeChannel::removeKeyframe ( int time,
KUndo2Command * parentUndoCmd = nullptr )
virtual

Remove a keyframe from the channel at the specified time.

Reimplemented in KisRasterKeyframeChannel, and KisScalarKeyframeChannel.

Definition at line 161 of file kis_keyframe_channel.cpp.

162{
163 Q_EMIT sigKeyframeAboutToBeRemoved(this, time);
164 removeKeyframeImpl(time, parentUndoCmd);
165}
virtual void removeKeyframeImpl(int time, KUndo2Command *parentUndoCmd)
void sigKeyframeAboutToBeRemoved(const KisKeyframeChannel *channel, int time)
This signal is emitted just BEFORE a keyframe is removed from the channel.

References removeKeyframeImpl(), and sigKeyframeAboutToBeRemoved().

◆ removeKeyframeImpl()

void KisKeyframeChannel::removeKeyframeImpl ( int time,
KUndo2Command * parentUndoCmd )
protectedvirtual

Actual implementation of the frame removal that does everything except of the signal emission (that should be emitted before the removal)

Definition at line 148 of file kis_keyframe_channel.cpp.

149{
150 if (parentUndoCmd) {
151 KUndo2Command* cmd =
153 new KisRemoveKeyframeCommand(this, time), parentUndoCmd);
154 Q_UNUSED(cmd);
155 }
156
157 m_d->keys.remove(time);
158 Q_EMIT sigKeyframeHasBeenRemoved(this, time);
159}

References m_d, and sigKeyframeHasBeenRemoved().

◆ saveKeyframe()

virtual void KisKeyframeChannel::saveKeyframe ( KisKeyframeSP keyframe,
QDomElement keyframeElement,
const QString & layerFilename )
privatepure virtual

◆ setDefaultBounds()

void KisKeyframeChannel::setDefaultBounds ( KisDefaultBoundsBaseSP bounds)

Definition at line 353 of file kis_keyframe_channel.cpp.

353 {
354 m_d->bounds = bounds;
355}

References bounds, and m_d.

◆ setNode()

void KisKeyframeChannel::setNode ( KisNodeWSP node)

Definition at line 328 of file kis_keyframe_channel.cpp.

329{
330 if (m_d->parentNode.isValid()) { // Disconnect old..
335 }
336
337 m_d->parentNode = node;
339
340 if (m_d->parentNode) { // Connect new..
345 }
346}
KisSharedPtr< KisDefaultBoundsNodeWrapper > KisDefaultBoundsNodeWrapperSP
virtual void handleKeyframeChannelFrameAdded(const KisKeyframeChannel *channel, int time)
Definition kis_node.cpp:647
void handleKeyframeChannelFrameHasBeenRemoved(const KisKeyframeChannel *channel, int time)
Definition kis_node.cpp:663
void handleKeyframeChannelFrameAboutToBeRemoved(const KisKeyframeChannel *channel, int time)
Definition kis_node.cpp:657
virtual void handleKeyframeChannelFrameChange(const KisKeyframeChannel *channel, int time)
Definition kis_node.cpp:642

References connect(), KisNode::handleKeyframeChannelFrameAboutToBeRemoved(), KisNode::handleKeyframeChannelFrameAdded(), KisNode::handleKeyframeChannelFrameChange(), KisNode::handleKeyframeChannelFrameHasBeenRemoved(), m_d, node(), sigAddedKeyframe(), sigKeyframeAboutToBeRemoved(), sigKeyframeChanged(), and sigKeyframeHasBeenRemoved().

◆ sigAddedKeyframe

void KisKeyframeChannel::sigAddedKeyframe ( const KisKeyframeChannel * channel,
int time )
signal

This signal is emitted just AFTER a keyframe was added to the channel.

◆ sigAnyKeyframeChange

void KisKeyframeChannel::sigAnyKeyframeChange ( )
signal

This signal is an aggregate of the following signals:

  • sigAddedKeyframe
  • sigKeyframeHasBeenRemoved
  • sigKeyframeChanged

◆ sigKeyframeAboutToBeRemoved

void KisKeyframeChannel::sigKeyframeAboutToBeRemoved ( const KisKeyframeChannel * channel,
int time )
signal

This signal is emitted just BEFORE a keyframe is removed from the channel.

◆ sigKeyframeChanged

void KisKeyframeChannel::sigKeyframeChanged ( const KisKeyframeChannel * channel,
int time )
signal

This signal is emitted just AFTER a non-raster keyframe was changed its value.

◆ sigKeyframeHasBeenRemoved

void KisKeyframeChannel::sigKeyframeHasBeenRemoved ( const KisKeyframeChannel * channel,
int time )
signal

This signal is emitted just AFTER a keyframe is removed from the channel.

◆ swapKeyframes() [1/2]

void KisKeyframeChannel::swapKeyframes ( int timeA,
int timeB,
KUndo2Command * parentUndoCmd = nullptr )
inline

Definition at line 76 of file kis_keyframe_channel.h.

76{ swapKeyframes(this, timeA, this, timeB, parentUndoCmd); }
static void swapKeyframes(KisKeyframeChannel *channelA, int timeA, KisKeyframeChannel *channelB, int timeB, KUndo2Command *parentUndoCmd=nullptr)
Swap two keyframes across channel(s) at the specified times.

References swapKeyframes().

◆ swapKeyframes() [2/2]

void KisKeyframeChannel::swapKeyframes ( KisKeyframeChannel * channelA,
int timeA,
KisKeyframeChannel * channelB,
int timeB,
KUndo2Command * parentUndoCmd = nullptr )
static

Swap two keyframes across channel(s) at the specified times.

Definition at line 199 of file kis_keyframe_channel.cpp.

200{
201 KIS_ASSERT(channelA && channelB);
202
203 // Store B.
204 KisKeyframeSP keyframeB = channelB->keyframeAt(timeB);
205 if (!keyframeB) return;
206
207 // Move A -> B
208 moveKeyframe(channelA, timeA, channelB, timeB, parentUndoCmd);
209
210 // Insert B -> A
211 if (channelA != channelB) {
212 keyframeB = keyframeB->duplicate(channelA);
214 }
215 channelA->insertKeyframe(timeA, keyframeB, parentUndoCmd);
216}

References insertKeyframe(), keyframeAt(), KIS_ASSERT, KIS_SAFE_ASSERT_RECOVER_RETURN, and moveKeyframe().

◆ toXML()

QDomElement KisKeyframeChannel::toXML ( QDomDocument doc,
const QString & layerFilename )
virtual

Reimplemented in KisRasterKeyframeChannel.

Definition at line 397 of file kis_keyframe_channel.cpp.

398{
399 QDomElement channelElement = doc.createElement("channel");
400
401 channelElement.setAttribute("name", id());
402
403 Q_FOREACH (int time, m_d->keys.keys()) {
404 QDomElement keyframeElement = doc.createElement("keyframe");
405 KisKeyframeSP keyframe = keyframeAt(time);
406
407 keyframeElement.setAttribute("time", time);
408 keyframeElement.setAttribute("color-label", keyframe->colorLabel());
409
410 saveKeyframe(keyframe, keyframeElement, layerFilename);
411
412 channelElement.appendChild(keyframeElement);
413 }
414
415 return channelElement;
416}
virtual void saveKeyframe(KisKeyframeSP keyframe, QDomElement keyframeElement, const QString &layerFilename)=0

References keyframeAt(), m_d, and saveKeyframe().

◆ workaroundBrokenFrameTimeBug()

void KisKeyframeChannel::workaroundBrokenFrameTimeBug ( int * time)
protected

Between Krita 4.1 and 4.4 Krita had a bug which resulted in creating frames with negative time stamp. The bug has been fixed, but there might be some files still in the wild.

TODO: remove this workaround in Krita 5.0, when no such file are left :)

Definition at line 449 of file kis_keyframe_channel.cpp.

450{
451 if (*time < 0) {
452 qWarning() << "WARNING: Loading a file with negative animation frames!";
453 qWarning() << " The file has been saved with a buggy version of Krita.";
454 qWarning() << " All the frames with negative ids will be dropped!";
455 qWarning() << " " << ppVar(this->id()) << ppVar(*time);
456
457 m_d->haveBrokenFrameTimeBug = true;
458 *time = 0;
459 }
460
461 if (m_d->haveBrokenFrameTimeBug) {
462 while (keyframeAt(*time)) {
463 (*time)++;
464 }
465 }
466}
#define ppVar(var)
Definition kis_debug.h:155

References keyframeAt(), m_d, and ppVar.

Member Data Documentation

◆ m_d

QScopedPointer<Private> KisKeyframeChannel::m_d
private

Definition at line 195 of file kis_keyframe_channel.h.

◆ Opacity

const KoID KisKeyframeChannel::Opacity = KoID("opacity", ki18n("Opacity"))
static

Definition at line 38 of file kis_keyframe_channel.h.

◆ PositionX

const KoID KisKeyframeChannel::PositionX = KoID("transform_pos_x", ki18n("Position (X)"))
static

Definition at line 40 of file kis_keyframe_channel.h.

◆ PositionY

const KoID KisKeyframeChannel::PositionY = KoID("transform_pos_y", ki18n("Position (Y)"))
static

Definition at line 41 of file kis_keyframe_channel.h.

◆ Raster

const KoID KisKeyframeChannel::Raster = KoID("content", ki18n("Content"))
static

Definition at line 37 of file kis_keyframe_channel.h.

◆ RotationX

const KoID KisKeyframeChannel::RotationX = KoID("transform_rotation_x", ki18n("Rotation (X)"))
static

Definition at line 46 of file kis_keyframe_channel.h.

◆ RotationY

const KoID KisKeyframeChannel::RotationY = KoID("transform_rotation_y", ki18n("Rotation (Y)"))
static

Definition at line 47 of file kis_keyframe_channel.h.

◆ RotationZ

const KoID KisKeyframeChannel::RotationZ = KoID("transform_rotation_z", ki18n("Rotation (Z)"))
static

Definition at line 48 of file kis_keyframe_channel.h.

◆ ScaleX

const KoID KisKeyframeChannel::ScaleX = KoID("transform_scale_x", ki18n("Scale (X)"))
static

Definition at line 42 of file kis_keyframe_channel.h.

◆ ScaleY

const KoID KisKeyframeChannel::ScaleY = KoID("transform_scale_y", ki18n("Scale (Y)"))
static

Definition at line 43 of file kis_keyframe_channel.h.

◆ ShearX

const KoID KisKeyframeChannel::ShearX = KoID("transform_shear_x", ki18n("Shear (X)"))
static

Definition at line 44 of file kis_keyframe_channel.h.

◆ ShearY

const KoID KisKeyframeChannel::ShearY = KoID("transform_shear_y", ki18n("Shear (Y)"))
static

Definition at line 45 of file kis_keyframe_channel.h.

◆ TransformArguments

const KoID KisKeyframeChannel::TransformArguments
static

Definition at line 39 of file kis_keyframe_channel.h.


The documentation for this class was generated from the following files: