1/****************************************************************************
2**
3** Copyright (C) 2017 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#ifndef QT3DANIMATION_QKEYFRAME_H
41#define QT3DANIMATION_QKEYFRAME_H
42
43#include <QtGui/qvector2d.h>
44#include <Qt3DAnimation/qt3danimation_global.h>
45
46QT_BEGIN_NAMESPACE
47
48namespace Qt3DAnimation {
49
50class QKeyFrame
51{
52public:
53 enum InterpolationType : quint8 {
54 ConstantInterpolation,
55 LinearInterpolation,
56 BezierInterpolation
57 };
58
59 Q_DECL_CONSTEXPR QKeyFrame() Q_DECL_NOTHROW
60 : m_coordinates()
61 , m_leftControlPoint()
62 , m_rightControlPoint()
63 , m_interpolationType(BezierInterpolation)
64 {
65 }
66
67 Q_DECL_CONSTEXPR explicit QKeyFrame(QVector2D coords) Q_DECL_NOTHROW
68 : m_coordinates(coords)
69 , m_leftControlPoint()
70 , m_rightControlPoint()
71 , m_interpolationType(LinearInterpolation)
72 {
73 }
74
75 Q_DECL_CONSTEXPR explicit QKeyFrame(QVector2D coords,
76 QVector2D lh,
77 QVector2D rh) Q_DECL_NOTHROW
78 : m_coordinates(coords)
79 , m_leftControlPoint(lh)
80 , m_rightControlPoint(rh)
81 , m_interpolationType(BezierInterpolation)
82 {
83 }
84
85 void setCoordinates(QVector2D coords) Q_DECL_NOTHROW
86 {
87 m_coordinates = coords;
88 }
89
90 Q_DECL_CONSTEXPR QVector2D coordinates() const Q_DECL_NOTHROW
91 {
92 return m_coordinates;
93 }
94
95 void setLeftControlPoint(QVector2D lh) Q_DECL_NOTHROW
96 {
97 m_leftControlPoint = lh;
98 }
99
100 Q_DECL_CONSTEXPR QVector2D leftControlPoint() const Q_DECL_NOTHROW
101 {
102 return m_leftControlPoint;
103 }
104
105 void setRightControlPoint(QVector2D rh) Q_DECL_NOTHROW
106 {
107 m_rightControlPoint = rh;
108 }
109
110 Q_DECL_CONSTEXPR QVector2D rightControlPoint() const Q_DECL_NOTHROW
111 {
112 return m_rightControlPoint;
113 }
114
115 void setInterpolationType(InterpolationType interp) Q_DECL_NOTHROW
116 {
117 m_interpolationType = interp;
118 }
119
120 Q_DECL_CONSTEXPR InterpolationType interpolationType() const Q_DECL_NOTHROW
121 {
122 return m_interpolationType;
123 }
124
125 friend inline bool operator==(const QKeyFrame &, const QKeyFrame &) Q_DECL_NOTHROW;
126 friend inline bool operator!=(const QKeyFrame &, const QKeyFrame &) Q_DECL_NOTHROW;
127
128private:
129 QVector2D m_coordinates;
130 QVector2D m_leftControlPoint;
131 QVector2D m_rightControlPoint;
132 InterpolationType m_interpolationType;
133};
134
135QT3D_DECLARE_TYPEINFO(Qt3DAnimation, QKeyFrame, Q_PRIMITIVE_TYPE)
136
137inline bool operator==(const QKeyFrame &lhs, const QKeyFrame &rhs) Q_DECL_NOTHROW
138{
139 if (lhs.m_interpolationType != rhs.m_interpolationType)
140 return false;
141
142 if (lhs.m_interpolationType == QKeyFrame::BezierInterpolation) {
143 return lhs.m_coordinates == rhs.m_coordinates &&
144 lhs.m_leftControlPoint == rhs.m_leftControlPoint &&
145 lhs.m_rightControlPoint == rhs.m_rightControlPoint;
146 }
147
148 return lhs.m_coordinates == rhs.m_coordinates;
149}
150
151inline bool operator!=(const QKeyFrame &lhs, const QKeyFrame &rhs) Q_DECL_NOTHROW
152{
153 return !(lhs == rhs);
154}
155
156} // namespace Qt3DAnimation
157
158QT_END_NAMESPACE
159
160#endif // QT3DANIMATION_QKEYFRAME_H
161

source code of qt3d/src/animation/frontend/qkeyframe.h