Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_time_span.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include "kis_time_span.h"
8
9#include <QDebug>
11#include "kis_node.h"
12#include "kis_layer_utils.h"
14
16 qRegisterMetaType<KisTimeSpan>("KisTimeSpan");
17}
18
19QDebug operator<<(QDebug dbg, const KisTimeSpan &r)
20{
21 dbg.nospace() << "KisTimeSpan(" << r.start() << ", " << r.end() << ")";
22
23 return dbg.space();
24}
25
27{
29
31 [&range, time] (const KisNode *node) {
32 if (node->visible()) {
33 range &= calculateNodeIdenticalFrames(node, time);
34 }
35 });
36
37 return range;
38}
39
41{
42 KisTimeSpan range;
43
45 [&range, time] (const KisNode *node) {
46 if (node->visible()) {
47 range |= calculateNodeIdenticalFrames(node, time);
48 }
49 });
50
51 return range;
52}
53
55{
57
58 const QMap<QString, KisKeyframeChannel*> channels =
59 node->keyframeChannels();
60
61 Q_FOREACH (const KisKeyframeChannel *channel, channels) {
62 // Intersection
63 range &= channel->identicalFrames(time);
64 }
65
66 return range;
67}
68
70{
71 KisTimeSpan range;
72
73 if (!node->visible()) return range;
74
75 const QMap<QString, KisKeyframeChannel*> channels =
76 node->keyframeChannels();
77
78 // TODO: channels should report to the image which channel exactly has changed
79 // to avoid the dirty range to be stretched into infinity!
80
81 if (channels.isEmpty() ||
82 !channels.contains(KisKeyframeChannel::Raster.id())) {
83 range = KisTimeSpan::infinite(0);
84 return range;
85 }
86
87 Q_FOREACH (const KisKeyframeChannel *channel, channels) {
88 // Union
89 range |= channel->affectedFrames(time);
90 }
91
92 return range;
93}
94
95namespace KisDomUtils {
96
97void saveValue(QDomElement *parent, const QString &tag, const KisTimeSpan &range)
98{
99 QDomDocument doc = parent->ownerDocument();
100 QDomElement e = doc.createElement(tag);
101 parent->appendChild(e);
102
103 e.setAttribute("type", "timerange");
104
105 if (range.isValid()) {
106 e.setAttribute("from", toString(range.start()));
107
108 if (!range.isInfinite()) {
109 e.setAttribute("to", toString(range.end()));
110 }
111 }
112}
113
114
115bool loadValue(const QDomElement &parent, const QString &tag, KisTimeSpan *range)
116{
117 QDomElement e;
118 if (!findOnlyElement(parent, tag, &e)) return false;
119
120 if (!Private::checkType(e, "timerange")) return false;
121
122 int start = toInt(e.attribute("from", "-1"));
123 int end = toInt(e.attribute("to", "-1"));
124
125 if (start == -1) {
126 *range = KisTimeSpan();
127 } else if (end == -1) {
128 *range = KisTimeSpan::infinite(start);
129 } else {
130 *range = KisTimeSpan::fromTimeToTime(start, end);
131 }
132 return true;
133}
134
135}
KisKeyframeChannel stores and manages KisKeyframes. Maps units of time to virtual keyframe values....
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....
static const KoID Raster
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...
int start() const
bool isInfinite() const
static KisTimeSpan calculateNodeIdenticalFrames(const KisNode *node, int time)
static KisTimeSpan calculateNodeAffectedFrames(const KisNode *node, int time)
static KisTimeSpan infinite(int start)
static KisTimeSpan calculateIdenticalFramesRecursive(const KisNode *node, int time)
static KisTimeSpan calculateAffectedFramesRecursive(const KisNode *node, int time)
int end() const
static KisTimeSpan fromTimeToTime(int start, int end)
bool isValid() const
QString id() const
Definition KoID.cpp:63
QDebug operator<<(QDebug dbg, const KisTimeSpan &r)
KIS_DECLARE_STATIC_INITIALIZER
bool checkType(const QDomElement &e, const QString &expectedType)
void saveValue(QDomElement *parent, const QString &tag, const QSize &size)
bool findOnlyElement(const QDomElement &parent, const QString &tag, QDomElement *el, QStringList *errorMessages)
int toInt(const QString &str, bool *ok=nullptr)
bool loadValue(const QDomElement &e, float *v)
QString toString(const QString &value)
void recursiveApplyNodes(NodePointer node, Functor func)
QMap< QString, KisKeyframeChannel * > keyframeChannels
virtual bool visible(bool recursive=false) const