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