| 1 | // Copyright (C) 2025 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include "qlottieroot_p.h" |
| 5 | #include "qlottielayer_p.h" |
| 6 | |
| 7 | #include <QJsonDocument> |
| 8 | #include <QJsonArray> |
| 9 | |
| 10 | QT_BEGIN_NAMESPACE |
| 11 | |
| 12 | QLottieRoot::QLottieRoot(const QLottieRoot &other) |
| 13 | : QLottieBase(other) |
| 14 | { |
| 15 | } |
| 16 | |
| 17 | QLottieBase *QLottieRoot::clone() const |
| 18 | { |
| 19 | return new QLottieRoot(*this); |
| 20 | } |
| 21 | |
| 22 | int QLottieRoot::parseSource(const QByteArray &jsonSource, const QUrl &fileSource) |
| 23 | { |
| 24 | QJsonDocument doc = QJsonDocument::fromJson(json: jsonSource); |
| 25 | QJsonObject rootObj = doc.object(); |
| 26 | m_definition = rootObj; |
| 27 | |
| 28 | if (rootObj.empty()) |
| 29 | return -1; |
| 30 | |
| 31 | QMap<QString, QJsonObject> assets; |
| 32 | QJsonArray jsonLayers = rootObj.value(key: QLatin1String("layers")).toArray(); |
| 33 | QJsonArray jsonAssets = rootObj.value(key: QLatin1String("assets")).toArray(); |
| 34 | m_frameRate = rootObj.value(key: QLatin1String("fr")).toVariant().toInt(); |
| 35 | m_startFrame = rootObj.value(key: QLatin1String("ip")).toVariant().toInt(); |
| 36 | m_endFrame = rootObj.value(key: QLatin1String("op")).toVariant().toInt(); |
| 37 | QJsonArray::const_iterator jsonAssetsIt = jsonAssets.constBegin(); |
| 38 | while (jsonAssetsIt != jsonAssets.constEnd()) { |
| 39 | QJsonObject jsonAsset = (*jsonAssetsIt).toObject(); |
| 40 | |
| 41 | jsonAsset.insert(key: QLatin1String("fileSource"), value: QJsonValue::fromVariant(variant: fileSource)); |
| 42 | QString id = jsonAsset.value(key: QLatin1String("id")).toString(); |
| 43 | assets.insert(key: id, value: jsonAsset); |
| 44 | jsonAssetsIt++; |
| 45 | } |
| 46 | |
| 47 | QLottieLayer::constructLayers(jsonLayers, parent: this, assets); |
| 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | void QLottieRoot::setStructureDumping(bool enabled) |
| 53 | { |
| 54 | m_structureDumping = enabled ? 1 : 0; |
| 55 | } |
| 56 | |
| 57 | QT_END_NAMESPACE |
| 58 |
