1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
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 http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#include "qabstractanimation.h"
38#include "Qt3DAnimation/private/qabstractanimation_p.h"
39
40QT_BEGIN_NAMESPACE
41
42namespace Qt3DAnimation {
43
44/*!
45 \class Qt3DAnimation::QAbstractAnimation
46 \brief An abstract base class for Qt3D animations.
47 \inmodule Qt3DAnimation
48 \since 5.9
49 \inherits QObject
50
51 Qt3DAnimation::QAbstractAnimation is an abstract base class for all animations.
52 Qt3DAnimation::QAbstractAnimation can not be directly instantiated, but rather
53 through its subclasses. QAbstractAnimation specifies common properties
54 for all Qt3D animations, such as animation name and type, current position and animation
55 duration, while leaving the actual animating for the subclasses.
56*/
57
58/*!
59 \qmltype AbstractAnimation
60 \brief An abstract base type for Qt3D animations.
61 \inqmlmodule Qt3D.Animation
62 \since 5.9
63 \instantiates Qt3DAnimation::QAbstractAnimation
64
65 AbstractAnimation is an abstract base type for all animations.
66 AbstractAnimation can not be directly instantiated, but rather
67 through its subtypes. AbstractAnimation specifies common properties
68 for all Qt3D animations, such as animation type, current position and animation
69 duration, while leaving the actual animating for the subtypes.
70*/
71/*!
72 \enum QAbstractAnimation::AnimationType
73
74 This enumeration specifies the type of the animation
75 \value KeyframeAnimation Simple keyframe animation implementation for QTransform
76 \value MorphingAnimation Blend-shape morphing animation
77 \value VertexBlendAnimation Vertex-blend animation
78*/
79/*!
80 \property Qt3DAnimation::QAbstractAnimation::animationName
81 Holds the name of the animation.
82*/
83/*!
84 \property Qt3DAnimation::QAbstractAnimation::animationType
85 Holds the type of the animation.
86*/
87/*!
88 \property Qt3DAnimation::QAbstractAnimation::position
89 Holds the current position of the animation.
90*/
91/*!
92 \property Qt3DAnimation::QAbstractAnimation::duration
93 Holds the duration of the animation.
94*/
95
96/*!
97 \qmlproperty string AbstractAnimation::animationName
98 Holds the name of the animation.
99*/
100/*!
101 \qmlproperty enumeration AbstractAnimation::animationType
102 Holds the type of the animation.
103 \list
104 \li KeyframeAnimation
105 \li MorphingAnimation
106 \li VertexBlendAnimation
107 \endlist
108*/
109/*!
110 \qmlproperty real AbstractAnimation::position
111 Holds the current position of the animation.
112*/
113/*!
114 \qmlproperty real AbstractAnimation::duration
115 Holds the duration of the animation.
116*/
117
118QAbstractAnimationPrivate::QAbstractAnimationPrivate(QAbstractAnimation::AnimationType type)
119 : QObjectPrivate()
120 , m_animationType(type)
121 , m_position(0.0f)
122 , m_duration(0.0f)
123{
124
125}
126
127QAbstractAnimation::QAbstractAnimation(QAbstractAnimationPrivate &dd, QObject *parent)
128 : QObject(dd, parent)
129{
130
131}
132
133QString QAbstractAnimation::animationName() const
134{
135 Q_D(const QAbstractAnimation);
136 return d->m_animationName;
137}
138
139QAbstractAnimation::AnimationType QAbstractAnimation::animationType() const
140{
141 Q_D(const QAbstractAnimation);
142 return d->m_animationType;
143}
144
145float QAbstractAnimation::position() const
146{
147 Q_D(const QAbstractAnimation);
148 return d->m_position;
149}
150
151float QAbstractAnimation::duration() const
152{
153 Q_D(const QAbstractAnimation);
154 return d->m_duration;
155}
156
157void QAbstractAnimation::setAnimationName(const QString &name)
158{
159 Q_D(QAbstractAnimation);
160 if (name != d->m_animationName) {
161 d->m_animationName = name;
162 emit animationNameChanged(name);
163 }
164}
165
166void QAbstractAnimation::setPosition(float position)
167{
168 Q_D(QAbstractAnimation);
169 if (!qFuzzyCompare(position, d->m_position)) {
170 d->m_position = position;
171 emit positionChanged(position);
172 }
173}
174
175/*!
176 Sets the \a duration of the animation.
177*/
178void QAbstractAnimation::setDuration(float duration)
179{
180 Q_D(QAbstractAnimation);
181 if (!qFuzzyCompare(duration, d->m_duration)) {
182 d->m_duration = duration;
183 emit durationChanged(duration);
184 }
185}
186
187} // Qt3DAnimation
188
189QT_END_NAMESPACE
190

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