| 1 | // Copyright (C) 2018 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include "qlottieround_p.h" |
| 5 | |
| 6 | #include <QJsonObject> |
| 7 | |
| 8 | #include "qlottietrimpath_p.h" |
| 9 | |
| 10 | QT_BEGIN_NAMESPACE |
| 11 | |
| 12 | QLottieRound::QLottieRound(const QLottieRound &other) |
| 13 | : QLottieShape(other) |
| 14 | { |
| 15 | m_position = other.m_position; |
| 16 | m_radius = other.m_radius; |
| 17 | } |
| 18 | |
| 19 | QLottieRound::QLottieRound(const QJsonObject &definition, QLottieBase *parent) |
| 20 | { |
| 21 | setParent(parent); |
| 22 | construct(definition); |
| 23 | } |
| 24 | |
| 25 | QLottieBase *QLottieRound::clone() const |
| 26 | { |
| 27 | return new QLottieRound(*this); |
| 28 | } |
| 29 | |
| 30 | void QLottieRound::construct(const QJsonObject &definition) |
| 31 | { |
| 32 | QLottieBase::parse(definition); |
| 33 | if (m_hidden) |
| 34 | return; |
| 35 | |
| 36 | qCDebug(lcLottieQtLottieParser) << "QLottieRound::construct():" << m_name; |
| 37 | |
| 38 | QJsonObject position = definition.value(key: QLatin1String("p" )).toObject(); |
| 39 | position = resolveExpression(definition: position); |
| 40 | m_position.construct(definition: position); |
| 41 | |
| 42 | QJsonObject radius = definition.value(key: QLatin1String("r" )).toObject(); |
| 43 | radius = resolveExpression(definition: radius); |
| 44 | m_radius.construct(definition: radius); |
| 45 | } |
| 46 | |
| 47 | void QLottieRound::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 QLottieRound::render(QLottieRenderer &renderer) const |
| 68 | { |
| 69 | renderer.render(round: *this); |
| 70 | } |
| 71 | |
| 72 | bool QLottieRound::acceptsTrim() const |
| 73 | { |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | QPointF QLottieRound::position() const |
| 78 | { |
| 79 | return m_position.value(); |
| 80 | } |
| 81 | |
| 82 | qreal QLottieRound::radius() const |
| 83 | { |
| 84 | return m_radius.value(); |
| 85 | } |
| 86 | |
| 87 | QT_END_NAMESPACE |
| 88 | |