1 | // Copyright (C) 2018 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "bmellipse_p.h" |
5 | |
6 | #include <QJsonObject> |
7 | #include <QRectF> |
8 | |
9 | #include "bmtrimpath_p.h" |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | BMEllipse::BMEllipse(const BMEllipse &other) |
14 | : BMShape(other) |
15 | { |
16 | m_position = other.m_position; |
17 | m_size = other.m_size; |
18 | } |
19 | |
20 | BMEllipse::BMEllipse(const QJsonObject &definition, const QVersionNumber &version, BMBase *parent) |
21 | { |
22 | setParent(parent); |
23 | construct(definition, version); |
24 | } |
25 | |
26 | BMBase *BMEllipse::clone() const |
27 | { |
28 | return new BMEllipse(*this); |
29 | } |
30 | |
31 | void BMEllipse::construct(const QJsonObject &definition, const QVersionNumber &version) |
32 | { |
33 | BMBase::parse(definition); |
34 | if (m_hidden) |
35 | return; |
36 | |
37 | qCDebug(lcLottieQtBodymovinParser) << "BMEllipse::construct():" << m_name; |
38 | |
39 | QJsonObject position = definition.value(key: QLatin1String("p" )).toObject(); |
40 | position = resolveExpression(definition: position); |
41 | m_position.construct(definition: position, version); |
42 | |
43 | QJsonObject size = definition.value(key: QLatin1String("s" )).toObject(); |
44 | size = resolveExpression(definition: size); |
45 | m_size.construct(definition: size, version); |
46 | |
47 | m_direction = definition.value(key: QLatin1String("d" )).toInt(); |
48 | } |
49 | |
50 | bool BMEllipse::acceptsTrim() const |
51 | { |
52 | return true; |
53 | } |
54 | |
55 | void BMEllipse::updateProperties(int frame) |
56 | { |
57 | m_position.update(frame); |
58 | m_size.update(frame); |
59 | |
60 | // AE uses center of a shape as it's position, |
61 | // in Qt a translation is needed |
62 | QPointF pos = QPointF(m_position.value().x() - m_size.value().width() / 2, |
63 | m_position.value().y() - m_size.value().height() / 2); |
64 | |
65 | m_path = QPainterPath(); |
66 | m_path.arcMoveTo(rect: QRectF(pos, m_size.value()), angle: 90); |
67 | m_path.arcTo(rect: QRectF(pos, m_size.value()), startAngle: 90, arcLength: 360); |
68 | |
69 | if (m_direction) |
70 | m_path = m_path.toReversed(); |
71 | } |
72 | |
73 | void BMEllipse::render(LottieRenderer &renderer) const |
74 | { |
75 | renderer.render(ellipse: *this); |
76 | } |
77 | |
78 | QPointF BMEllipse::position() const |
79 | { |
80 | return m_position.value(); |
81 | } |
82 | |
83 | QSizeF BMEllipse::size() const |
84 | { |
85 | return m_size.value(); |
86 | } |
87 | |
88 | QT_END_NAMESPACE |
89 | |