1// Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qclipanimator.h"
5#include "qclipanimator_p.h"
6#include <Qt3DAnimation/qabstractanimationclip.h>
7#include <Qt3DAnimation/qchannelmapper.h>
8#include <Qt3DAnimation/qclock.h>
9
10QT_BEGIN_NAMESPACE
11
12namespace Qt3DAnimation {
13
14QClipAnimatorPrivate::QClipAnimatorPrivate()
15 : Qt3DAnimation::QAbstractClipAnimatorPrivate()
16 , m_clip(nullptr)
17{
18}
19
20bool QClipAnimatorPrivate::canPlay() const
21{
22 if (m_clip && m_mapper)
23 return true;
24
25 qWarning(msg: "ClipAnimators need a clip and a mapper to be played");
26 return false;
27}
28
29/*!
30 \qmltype ClipAnimator
31 \instantiates Qt3DAnimation::QClipAnimator
32 \inqmlmodule Qt3D.Animation
33 \inherits AbstractClipAnimator
34 \since 5.9
35
36 \brief ClipAnimator is a component providing simple animation playback capabilities.
37
38 An instance of ClipAnimator can be aggregated by an Entity to add the ability to play back
39 animation clips and to apply the calculated animation values to properties of QObjects.
40
41 The animation key frame data is provided via the clip property. This can be created
42 programmatically with AnimationClip or loaded from file with AnimationClipLoader.
43
44 In order to apply the values played back from the channels of data in the animation clip, the
45 clip animator needs to have a ChannelMapper object assigned to the channelMapper property.
46
47 The properties for controlling the animator are provided by the AbstractClipAnimator base
48 class.
49
50 \sa {Qt3DAnimation::QAbstractClipAnimator}{AbstractClipAnimator}, {Qt3DAnimation::QAbstractAnimationClip}{AbstractAnimationClip}, {Qt3DAnimation::QChannelMapper}{ChannelMapper}, {Qt3DAnimation::QBlendedClipAnimator}{BlendedClipAnimator}
51*/
52
53/*!
54 \class Qt3DAnimation::QClipAnimator
55 \inherits Qt3DAnimation::QAbstractClipAnimator
56
57 \inmodule Qt3DAnimation
58 \since 5.9
59
60 \brief QClipAnimator is a component providing simple animation playback capabilities.
61
62 An instance of QClipAnimator can be aggregated by a QEntity to add the ability to play back
63 animation clips and to apply the calculated animation values to properties of QObjects.
64
65 The animation key frame data is provided via the clip property. This can be created
66 programmatically with QAnimationClip or loaded from file with QAnimationClipLoader.
67
68 In order to apply the values played back from the channels of data in the animation clip, the
69 clip animator needs to have a QChannelMapper object assigned to the channelMapper property.
70
71 The properties for controlling the animator are provided by the QAbstractClipAnimator base
72 class.
73
74 \sa Qt3DAnimation::QAbstractClipAnimator, Qt3DAnimation::QAbstractAnimationClip,
75 Qt3DAnimation::QChannelMapper, Qt3DAnimation::QBlendedClipAnimator
76*/
77
78QClipAnimator::QClipAnimator(Qt3DCore::QNode *parent)
79 : Qt3DAnimation::QAbstractClipAnimator(*new QClipAnimatorPrivate, parent)
80{
81}
82
83/*! \internal */
84QClipAnimator::QClipAnimator(QClipAnimatorPrivate &dd, Qt3DCore::QNode *parent)
85 : Qt3DAnimation::QAbstractClipAnimator(dd, parent)
86{
87}
88
89QClipAnimator::~QClipAnimator()
90{
91}
92
93/*!
94 \qmlproperty var Qt3D.Animation::ClipAnimator::clip
95
96 This property holds the animation clip which contains the key frame data to be played back.
97 The key frame data can be specified in either an AnimationClip or AnimationClipLoader.
98*/
99/*!
100 \property QClipAnimator::clip
101
102 This property holds the animation clip which contains the key frame data to be played back.
103 The key frame data can be specified in either a QAnimationClip or QAnimationClipLoader.
104*/
105QAbstractAnimationClip *QClipAnimator::clip() const
106{
107 Q_D(const QClipAnimator);
108 return d->m_clip;
109}
110
111void QClipAnimator::setClip(QAbstractAnimationClip *clip)
112{
113 Q_D(QClipAnimator);
114 if (d->m_clip == clip)
115 return;
116
117 if (d->m_clip)
118 d->unregisterDestructionHelper(node: d->m_clip);
119
120 if (clip && !clip->parent())
121 clip->setParent(this);
122 d->m_clip = clip;
123
124 // Ensures proper bookkeeping
125 if (d->m_clip)
126 d->registerDestructionHelper(node: d->m_clip, func: &QClipAnimator::setClip, d->m_clip);
127 emit clipChanged(clip);
128}
129
130} // namespace Qt3DAnimation
131
132QT_END_NAMESPACE
133
134#include "moc_qclipanimator.cpp"
135

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