1/****************************************************************************
2**
3** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qclipanimator.h"
41#include "qclipanimator_p.h"
42#include <Qt3DAnimation/qabstractanimationclip.h>
43#include <Qt3DAnimation/qchannelmapper.h>
44#include <Qt3DAnimation/qclock.h>
45
46QT_BEGIN_NAMESPACE
47
48namespace Qt3DAnimation {
49
50QClipAnimatorPrivate::QClipAnimatorPrivate()
51 : Qt3DAnimation::QAbstractClipAnimatorPrivate()
52 , m_clip(nullptr)
53{
54}
55
56bool QClipAnimatorPrivate::canPlay() const
57{
58 if (m_clip && m_mapper)
59 return true;
60
61 qWarning(msg: "ClipAnimators need a clip and a mapper to be played");
62 return false;
63}
64
65/*!
66 \qmltype ClipAnimator
67 \instantiates Qt3DAnimation::QClipAnimator
68 \inqmlmodule Qt3D.Animation
69 \inherits AbstractClipAnimator
70 \since 5.9
71
72 \brief ClipAnimator is a component providing simple animation playback capabilities.
73
74 An instance of ClipAnimator can be aggregated by an Entity to add the ability to play back
75 animation clips and to apply the calculated animation values to properties of QObjects.
76
77 The animation key frame data is provided via the clip property. This can be created
78 programmatically with AnimationClip or loaded from file with AnimationClipLoader.
79
80 In order to apply the values played back from the channels of data in the animation clip, the
81 clip animator needs to have a ChannelMapper object assigned to the channelMapper property.
82
83 The properties for controlling the animator are provided by the AbstractClipAnimator base
84 class.
85
86 \sa {Qt3DAnimation::QAbstractClipAnimator}{AbstractClipAnimator}, {Qt3DAnimation::QAbstractAnimationClip}{AbstractAnimationClip}, {Qt3DAnimation::QChannelMapper}{ChannelMapper}, {Qt3DAnimation::QBlendedClipAnimator}{BlendedClipAnimator}
87*/
88
89/*!
90 \class Qt3DAnimation::QClipAnimator
91 \inherits Qt3DAnimation::QAbstractClipAnimator
92
93 \inmodule Qt3DAnimation
94 \since 5.9
95
96 \brief QClipAnimator is a component providing simple animation playback capabilities.
97
98 An instance of QClipAnimator can be aggregated by a QEntity to add the ability to play back
99 animation clips and to apply the calculated animation values to properties of QObjects.
100
101 The animation key frame data is provided via the clip property. This can be created
102 programmatically with QAnimationClip or loaded from file with QAnimationClipLoader.
103
104 In order to apply the values played back from the channels of data in the animation clip, the
105 clip animator needs to have a QChannelMapper object assigned to the channelMapper property.
106
107 The properties for controlling the animator are provided by the QAbstractClipAnimator base
108 class.
109
110 \sa Qt3DAnimation::QAbstractClipAnimator, Qt3DAnimation::QAbstractAnimationClip,
111 Qt3DAnimation::QChannelMapper, Qt3DAnimation::QBlendedClipAnimator
112*/
113
114QClipAnimator::QClipAnimator(Qt3DCore::QNode *parent)
115 : Qt3DAnimation::QAbstractClipAnimator(*new QClipAnimatorPrivate, parent)
116{
117}
118
119/*! \internal */
120QClipAnimator::QClipAnimator(QClipAnimatorPrivate &dd, Qt3DCore::QNode *parent)
121 : Qt3DAnimation::QAbstractClipAnimator(dd, parent)
122{
123}
124
125QClipAnimator::~QClipAnimator()
126{
127}
128
129/*!
130 \qmlproperty var Qt3D.Animation::ClipAnimator::clip
131
132 This property holds the animation clip which contains the key frame data to be played back.
133 The key frame data can be specified in either an AnimationClip or AnimationClipLoader.
134*/
135/*!
136 \property QClipAnimator::clip
137
138 This property holds the animation clip which contains the key frame data to be played back.
139 The key frame data can be specified in either a QAnimationClip or QAnimationClipLoader.
140*/
141QAbstractAnimationClip *QClipAnimator::clip() const
142{
143 Q_D(const QClipAnimator);
144 return d->m_clip;
145}
146
147void QClipAnimator::setClip(QAbstractAnimationClip *clip)
148{
149 Q_D(QClipAnimator);
150 if (d->m_clip == clip)
151 return;
152
153 if (d->m_clip)
154 d->unregisterDestructionHelper(node: d->m_clip);
155
156 if (clip && !clip->parent())
157 clip->setParent(this);
158 d->m_clip = clip;
159
160 // Ensures proper bookkeeping
161 if (d->m_clip)
162 d->registerDestructionHelper(node: d->m_clip, func: &QClipAnimator::setClip, d->m_clip);
163 emit clipChanged(clip);
164}
165
166/*! \internal */
167Qt3DCore::QNodeCreatedChangeBasePtr QClipAnimator::createNodeCreationChange() const
168{
169 auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QClipAnimatorData>::create(arguments: this);
170 auto &data = creationChange->data;
171 Q_D(const QClipAnimator);
172 data.clipId = Qt3DCore::qIdForNode(node: d->m_clip);
173 data.mapperId = Qt3DCore::qIdForNode(node: d->m_mapper);
174 data.clockId = Qt3DCore::qIdForNode(node: d->m_clock);
175 data.running = d->m_running;
176 data.loops = d->m_loops;
177 data.normalizedTime = d->m_normalizedTime;
178 return creationChange;
179}
180
181} // namespace Qt3DAnimation
182
183QT_END_NAMESPACE
184

source code of qt3d/src/animation/frontend/qclipanimator.cpp