About
Contact
QtCreator
KDevelop
Solarized
1
// Copyright (C) 2018 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4
#include
"qlottiebasictransform_p.h"
5
6
#include <QJsonObject>
7
8
#include
"qlottieconstants_p.h"
9
10
QT_BEGIN_NAMESPACE
11
12
QLottieBasicTransform
::
QLottieBasicTransform
(
const
QLottieBasicTransform
&
other
)
13
:
QLottieShape
(
other
)
14
{
15
m_direction
=
other
.
m_direction
;
16
m_anchorPoint
=
other
.
m_anchorPoint
;
17
m_splitPosition
=
other
.
m_splitPosition
;
18
m_position
=
other
.
m_position
;
19
m_xPos
=
other
.
m_xPos
;
20
m_yPos
=
other
.
m_yPos
;
21
m_scale
=
other
.
m_scale
;
22
m_rotation
=
other
.
m_rotation
;
23
m_opacity
=
other
.
m_opacity
;
24
}
25
26
QLottieBasicTransform
::
QLottieBasicTransform
(
const
QJsonObject
&
definition
,
27
QLottieBase
*
parent
)
28
{
29
setParent
(
parent
);
30
construct
(
definition
);
31
}
32
33
QLottieBase
*
QLottieBasicTransform
::
clone
()
const
34
{
35
return
new
QLottieBasicTransform
(
*
this
);
36
}
37
38
void
QLottieBasicTransform
::
construct
(
const
QJsonObject
&
definition
)
39
{
40
QLottieBase
::
parse
(
definition
);
41
42
qCDebug
(
lcLottieQtLottieParser
)
43
<<
"QLottieBasicTransform::construct():"
<<
m_name
;
44
45
QJsonObject
anchors
=
definition
.
value
(
key:
QLatin1String
(
"a"
)).
toObject
();
46
anchors
=
resolveExpression
(
definition:
anchors
);
47
m_anchorPoint
.
construct
(
definition:
anchors
);
48
49
if
(
definition
.
value
(
key:
QLatin1String
(
"p"
)).
toObject
().
contains
(
key:
QLatin1String
(
"s"
))) {
50
QJsonObject
posX
=
definition
.
value
(
key:
QLatin1String
(
"p"
)).
toObject
().
value
(
key:
QLatin1String
(
"x"
)).
toObject
();
51
posX
=
resolveExpression
(
definition:
posX
);
52
m_xPos
.
construct
(
definition:
posX
);
53
54
QJsonObject
posY
=
definition
.
value
(
key:
QLatin1String
(
"p"
)).
toObject
().
value
(
key:
QLatin1String
(
"y"
)).
toObject
();
55
posY
=
resolveExpression
(
definition:
posY
);
56
m_yPos
.
construct
(
definition:
posY
);
57
58
m_splitPosition
=
true
;
59
}
else
{
60
QJsonObject
position
=
definition
.
value
(
key:
QLatin1String
(
"p"
)).
toObject
();
61
position
=
resolveExpression
(
definition:
position
);
62
m_position
.
construct
(
definition:
position
);
63
}
64
65
if
(
definition
.
contains
(
key:
QLatin1String
(
"s"
))) {
66
QJsonObject
scale
=
definition
.
value
(
key:
QLatin1String
(
"s"
)).
toObject
();
67
scale
=
resolveExpression
(
definition:
scale
);
68
m_scale
.
construct
(
definition:
scale
);
69
}
else
{
70
m_scale
.
setValue
(
QPointF
(
100
,
100
));
71
}
72
73
QJsonObject
rotation
=
definition
.
value
(
key:
QLatin1String
(
"r"
)).
toObject
();
74
rotation
=
resolveExpression
(
definition:
rotation
);
75
m_rotation
.
construct
(
definition:
rotation
);
76
77
// If this is the base class for QLottieRepeaterTransform,
78
// opacity is not present
79
if
(
definition
.
contains
(
key:
QLatin1String
(
"o"
))) {
80
QJsonObject
opacity
=
definition
.
value
(
key:
QLatin1String
(
"o"
)).
toObject
();
81
opacity
=
resolveExpression
(
definition:
opacity
);
82
m_opacity
.
construct
(
definition:
opacity
);
83
}
else
{
84
m_opacity
.
setValue
(
100
);
85
}
86
}
87
88
void
QLottieBasicTransform
::
updateProperties
(
int
frame
)
89
{
90
if
(
m_splitPosition
) {
91
m_xPos
.
update
(
frame
);
92
m_yPos
.
update
(
frame
);
93
}
else
94
m_position
.
update
(
frame
);
95
m_anchorPoint
.
update
(
frame
);
96
m_scale
.
update
(
frame
);
97
m_rotation
.
update
(
frame
);
98
m_opacity
.
update
(
frame
);
99
}
100
101
void
QLottieBasicTransform
::
render
(
QLottieRenderer
&
renderer
)
const
102
{
103
renderer
.
render
(
trans:
*
this
);
104
}
105
106
QPointF
QLottieBasicTransform
::
anchorPoint
()
const
107
{
108
return
m_anchorPoint
.
value
();
109
}
110
111
QPointF
QLottieBasicTransform
::
position
()
const
112
{
113
if
(
m_splitPosition
)
114
return
QPointF
(
m_xPos
.
value
(),
m_yPos
.
value
());
115
else
116
return
m_position
.
value
();
117
}
118
119
QPointF
QLottieBasicTransform
::
scale
()
const
120
{
121
// Scale the value to 0..1 to be suitable for Qt
122
return
m_scale
.
value
()
/
100.0
;
123
}
124
125
qreal
QLottieBasicTransform
::
rotation
()
const
126
{
127
return
m_rotation
.
value
();
128
}
129
130
qreal
QLottieBasicTransform
::
opacity
()
const
131
{
132
// Scale the value to 0..1 to be suitable for Qt
133
return
m_opacity
.
value
() /
100.0
;
134
}
135
136
QT_END_NAMESPACE
137