Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_keyframe_channel.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Jouni Pentikäinen <joupent@gmail.com>
3 * SPDX-FileCopyrightText: 2020 Emmet O 'Neill <emmetoneill.pdx@gmail.com>
4 * SPDX-FileCopyrightText: 2020 Eoin O 'Neill <eoinoneill1991@gmail.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#ifndef KIS_KEYFRAME_CHANNEL_H
10#define KIS_KEYFRAME_CHANNEL_H
11
12#include <QVariant>
13#include <QDomElement>
14#include <kundo2command.h>
15
16#include "kis_types.h"
17#include "KoID.h"
18#include "kis_keyframe.h"
19#include "kis_default_bounds.h"
21
22#include "kritaimage_export.h"
23
24class KisTimeSpan;
25
26
32class KRITAIMAGE_EXPORT KisKeyframeChannel : public QObject
33{
34 Q_OBJECT
35
36public:
37 static const KoID Raster;
38 static const KoID Opacity;
40 static const KoID PositionX;
41 static const KoID PositionY;
42 static const KoID ScaleX;
43 static const KoID ScaleY;
44 static const KoID ShearX;
45 static const KoID ShearY;
46 static const KoID RotationX;
47 static const KoID RotationY;
48 static const KoID RotationZ;
49
52 ~KisKeyframeChannel() override;
53
55 void addKeyframe(int time, KUndo2Command *parentUndoCmd = nullptr);
56
58 virtual void insertKeyframe(int time, KisKeyframeSP keyframe, KUndo2Command *parentUndoCmd = nullptr);
59
61 virtual void removeKeyframe(int time, KUndo2Command *parentUndoCmd = nullptr);
62
63 // Inter-channel operations..
65 static void moveKeyframe(KisKeyframeChannel *sourceChannel, int sourceTime, KisKeyframeChannel *targetChannel, int targetTime, KUndo2Command* parentUndoCmd = nullptr);
66
68 static void copyKeyframe(const KisKeyframeChannel *sourceChannel, int sourceTime, KisKeyframeChannel *targetChannel, int targetTime, KUndo2Command* parentUndoCmd = nullptr);
69
71 static void swapKeyframes(KisKeyframeChannel *channelA, int timeA, KisKeyframeChannel *channelB, int timeB, KUndo2Command* parentUndoCmd = nullptr);
72
73 // Intra-channel convenience methods..
74 void moveKeyframe(int sourceTime, int targetTime, KUndo2Command* parentUndoCmd = nullptr) { moveKeyframe(this, sourceTime, this, targetTime, parentUndoCmd); }
75 void copyKeyframe(int sourceTime, int targetTime, KUndo2Command* parentUndoCmd = nullptr) { copyKeyframe(this, sourceTime, this, targetTime, parentUndoCmd); }
76 void swapKeyframes(int timeA, int timeB, KUndo2Command* parentUndoCmd = nullptr) { swapKeyframes(this, timeA, this, timeB, parentUndoCmd); }
77
78 // Keyframe methods..
81 KisKeyframeSP keyframeAt(int time) const;
82 KisKeyframeSP activeKeyframeAt(int time) const { return keyframeAt(activeKeyframeTime(time)); }
83
84 // Quick casting convenience templates..
85 template <class KeyframeType>
87 return keyframeAt(time).dynamicCast<KeyframeType>();
88 }
89
90 template <class KeyframeType>
92 return activeKeyframeAt(time).dynamicCast<KeyframeType>();
93 }
94
95 int keyframeCount() const;
96
97 // Time methods..
102 int activeKeyframeTime(int time) const;
103 int activeKeyframeTime() const { return activeKeyframeTime(currentTime()); }
104
110 int lookupKeyframeTime(KisKeyframeSP toLookup);
111
112 int firstKeyframeTime() const;
113 int previousKeyframeTime(const int time) const;
114 int nextKeyframeTime(const int time) const;
115 int lastKeyframeTime() const;
116
118 QSet<int> allKeyframeTimes() const;
119
120 QString id() const;
121 QString name() const;
122
123 void setNode(KisNodeWSP node);
124 KisNodeWSP node() const;
125 void setDefaultBounds(KisDefaultBoundsBaseSP bounds);
126
129 int channelHash() const;
130
133 virtual KisTimeSpan affectedFrames(int time) const;
134
140 virtual KisTimeSpan identicalFrames(int time) const;
141
145 virtual QRect affectedRect(int time) const = 0;
146
147 virtual QDomElement toXML(QDomDocument doc, const QString &layerFilename);
148 virtual void loadXML(const QDomElement &channelNode);
149
150 static KoID channelIdToKoId(const QString &id);
151
152Q_SIGNALS:
154 void sigAddedKeyframe(const KisKeyframeChannel *channel, int time);
155
157 void sigKeyframeAboutToBeRemoved(const KisKeyframeChannel *channel, int time);
158
160 void sigKeyframeHasBeenRemoved(const KisKeyframeChannel *channel, int time);
161
163 void sigKeyframeChanged(const KisKeyframeChannel *channel, int time);
164
171
172protected:
173 typedef QMap<int, KisKeyframeSP> TimeKeyframeMap;
174 TimeKeyframeMap &keys();
175 const TimeKeyframeMap &constKeys() const;
176 int currentTime() const;
177
182 virtual void removeKeyframeImpl(int time, KUndo2Command *parentUndoCmd);
183
191 Q_DECL_DEPRECATED void workaroundBrokenFrameTimeBug(int *time);
192
193private:
194 struct Private;
195 QScopedPointer<Private> m_d;
196
202 virtual QPair<int, KisKeyframeSP> loadKeyframe(const QDomElement &keyframeNode) = 0;
203 virtual void saveKeyframe(KisKeyframeSP keyframe, QDomElement keyframeElement, const QString &layerFilename) = 0;
204};
205
206#endif // KIS_KEYFRAME_CHANNEL_H
KisKeyframeChannel stores and manages KisKeyframes. Maps units of time to virtual keyframe values....
void swapKeyframes(int timeA, int timeB, KUndo2Command *parentUndoCmd=nullptr)
static const KoID RotationY
static const KoID Raster
virtual KisKeyframeSP createKeyframe()=0
Virtual keyframe creation function. Derived classes implement this function based on the needs of the...
static const KoID ScaleY
void sigAnyKeyframeChange()
virtual QPair< int, KisKeyframeSP > loadKeyframe(const QDomElement &keyframeNode)=0
static const KoID RotationZ
void moveKeyframe(int sourceTime, int targetTime, KUndo2Command *parentUndoCmd=nullptr)
QMap< int, KisKeyframeSP > TimeKeyframeMap
static const KoID Opacity
static const KoID TransformArguments
QScopedPointer< Private > m_d
static const KoID ScaleX
virtual void saveKeyframe(KisKeyframeSP keyframe, QDomElement keyframeElement, const QString &layerFilename)=0
static const KoID RotationX
QSharedPointer< KeyframeType > keyframeAt(int time) const
void sigKeyframeHasBeenRemoved(const KisKeyframeChannel *channel, int time)
This signal is emitted just AFTER a keyframe is removed from the channel.
QSharedPointer< KeyframeType > activeKeyframeAt(int time) const
KisKeyframeSP activeKeyframeAt(int time) const
void sigKeyframeAboutToBeRemoved(const KisKeyframeChannel *channel, int time)
This signal is emitted just BEFORE a keyframe is removed from the channel.
static const KoID PositionX
static const KoID PositionY
void sigKeyframeChanged(const KisKeyframeChannel *channel, int time)
This signal is emitted just AFTER a non-raster keyframe was changed its value.
static const KoID ShearX
void copyKeyframe(int sourceTime, int targetTime, KUndo2Command *parentUndoCmd=nullptr)
virtual QRect affectedRect(int time) const =0
static const KoID ShearY
void sigAddedKeyframe(const KisKeyframeChannel *channel, int time)
This signal is emitted just AFTER a keyframe was added to the channel.
Definition KoID.h:30
#define bounds(x, a, b)