1// Copyright (C) 2017 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#ifndef QT3DANIMATION_QKEYFRAME_H
5#define QT3DANIMATION_QKEYFRAME_H
6
7#include <QtGui/qvector2d.h>
8#include <Qt3DAnimation/qt3danimation_global.h>
9
10QT_BEGIN_NAMESPACE
11
12namespace Qt3DAnimation {
13
14class QKeyFrame
15{
16public:
17 enum InterpolationType : quint8 {
18 ConstantInterpolation,
19 LinearInterpolation,
20 BezierInterpolation
21 };
22
23 constexpr QKeyFrame() noexcept
24 : m_coordinates()
25 , m_leftControlPoint()
26 , m_rightControlPoint()
27 , m_interpolationType(BezierInterpolation)
28 {
29 }
30
31 constexpr explicit QKeyFrame(QVector2D coords) noexcept
32 : m_coordinates(coords)
33 , m_leftControlPoint()
34 , m_rightControlPoint()
35 , m_interpolationType(LinearInterpolation)
36 {
37 }
38
39 constexpr explicit QKeyFrame(QVector2D coords,
40 QVector2D lh,
41 QVector2D rh) noexcept
42 : m_coordinates(coords)
43 , m_leftControlPoint(lh)
44 , m_rightControlPoint(rh)
45 , m_interpolationType(BezierInterpolation)
46 {
47 }
48
49 void setCoordinates(QVector2D coords) noexcept
50 {
51 m_coordinates = coords;
52 }
53
54 constexpr QVector2D coordinates() const noexcept
55 {
56 return m_coordinates;
57 }
58
59 void setLeftControlPoint(QVector2D lh) noexcept
60 {
61 m_leftControlPoint = lh;
62 }
63
64 constexpr QVector2D leftControlPoint() const noexcept
65 {
66 return m_leftControlPoint;
67 }
68
69 void setRightControlPoint(QVector2D rh) noexcept
70 {
71 m_rightControlPoint = rh;
72 }
73
74 constexpr QVector2D rightControlPoint() const noexcept
75 {
76 return m_rightControlPoint;
77 }
78
79 void setInterpolationType(InterpolationType interp) noexcept
80 {
81 m_interpolationType = interp;
82 }
83
84 constexpr InterpolationType interpolationType() const noexcept
85 {
86 return m_interpolationType;
87 }
88
89 friend inline bool operator==(const QKeyFrame &, const QKeyFrame &) noexcept;
90 friend inline bool operator!=(const QKeyFrame &, const QKeyFrame &) noexcept;
91
92private:
93 QVector2D m_coordinates;
94 QVector2D m_leftControlPoint;
95 QVector2D m_rightControlPoint;
96 InterpolationType m_interpolationType;
97};
98
99QT3D_DECLARE_TYPEINFO(Qt3DAnimation, QKeyFrame, Q_PRIMITIVE_TYPE)
100
101inline bool operator==(const QKeyFrame &lhs, const QKeyFrame &rhs) noexcept
102{
103 if (lhs.m_interpolationType != rhs.m_interpolationType)
104 return false;
105
106 if (lhs.m_interpolationType == QKeyFrame::BezierInterpolation) {
107 return lhs.m_coordinates == rhs.m_coordinates &&
108 lhs.m_leftControlPoint == rhs.m_leftControlPoint &&
109 lhs.m_rightControlPoint == rhs.m_rightControlPoint;
110 }
111
112 return lhs.m_coordinates == rhs.m_coordinates;
113}
114
115inline bool operator!=(const QKeyFrame &lhs, const QKeyFrame &rhs) noexcept
116{
117 return !(lhs == rhs);
118}
119
120} // namespace Qt3DAnimation
121
122QT_END_NAMESPACE
123
124#endif // QT3DANIMATION_QKEYFRAME_H
125

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