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