aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <[email protected]>2025-04-09 14:25:25 +0200
committerEskil Abrahamsen Blomfeldt <[email protected]>2025-05-16 21:13:32 +0200
commit7c028a945c8daf6a620cbe7f792c0b587a1a86e1 (patch)
tree3a8f508812b5c99d21faec04ed071cbb4df35274
parentbcbd2173dcc33970d8ec17804276dcaf5c7c5eb6 (diff)
Support items that are visible for specific durations
This is a feature in Lottie, where layers pop into existence and pop out later on. We do this by animating the visibility of the item. Change-Id: Ieebab4e84f9254976b0de9759a1f0f4c8026210e Reviewed-by: Eirik Aavitsland <[email protected]>
-rw-r--r--src/quickvectorimage/generator/qquicknodeinfo_p.h2
-rw-r--r--src/quickvectorimage/generator/qquickqmlgenerator.cpp54
2 files changed, 36 insertions, 20 deletions
diff --git a/src/quickvectorimage/generator/qquicknodeinfo_p.h b/src/quickvectorimage/generator/qquicknodeinfo_p.h
index fea49db107..ec9cf391f5 100644
--- a/src/quickvectorimage/generator/qquicknodeinfo_p.h
+++ b/src/quickvectorimage/generator/qquicknodeinfo_p.h
@@ -36,6 +36,8 @@ struct NodeInfo
bool isDefaultOpacity = true;
bool isVisible = true;
bool isDisplayed = true; // TODO: Map to display enum in QtSvg
+ QQuickAnimatedProperty visibility = QQuickAnimatedProperty(QVariant::fromValue(true));
+ int visibilityEndTime = -1;
};
struct ImageNodeInfo : NodeInfo
diff --git a/src/quickvectorimage/generator/qquickqmlgenerator.cpp b/src/quickvectorimage/generator/qquickqmlgenerator.cpp
index e7595c315e..4cf246e351 100644
--- a/src/quickvectorimage/generator/qquickqmlgenerator.cpp
+++ b/src/quickvectorimage/generator/qquickqmlgenerator.cpp
@@ -135,6 +135,8 @@ QString QQuickQmlGenerator::generateNodeBase(const NodeInfo &info)
if (info.opacity.isAnimated())
generatePropertyAnimation(info.opacity, idString, QStringLiteral("opacity"));
+ generatePropertyAnimation(info.visibility, idString, QStringLiteral("visible"));
+
return idString;
}
@@ -319,29 +321,41 @@ void QQuickQmlGenerator::generatePropertyAnimation(const QQuickAnimatedProperty
const int time = it.key();
const QVariant &value = it.value();
- switch (animationType) {
- case AnimationType::Auto:
+ // We special case bools, with PauseAnimation and then a setter at the end
+ if (animationType == AnimationType::Auto && value.typeId() == QMetaType::Bool) {
+ stream() << "PauseAnimation { duration: " << (time - previousTime) << " }";
+ stream() << "ScriptAction {";
+ m_indentLevel++;
+
+ stream() << "script:" << targetName << "." << propertyName << " = " << value.toString();
+
+ m_indentLevel--;
+ stream() << "}";
+ } else {
+ switch (animationType) {
+ case AnimationType::Auto:
+ if (value.typeId() == QMetaType::QColor)
+ stream() << "ColorAnimation {";
+ else
+ stream() << "PropertyAnimation {";
+ break;
+ case AnimationType::ColorOpacity:
+ stream() << "ColorOpacityAnimation {";
+ break;
+ };
+ m_indentLevel++;
+
+ stream() << "target: " << targetName;
+ stream() << "property: \"" << propertyName << "\"";
if (value.typeId() == QMetaType::QColor)
- stream() << "ColorAnimation {";
+ stream() << "to: \"" << value.toString() << '"';
else
- stream() << "PropertyAnimation {";
- break;
- case AnimationType::ColorOpacity:
- stream() << "ColorOpacityAnimation {";
- break;
- };
- m_indentLevel++;
-
- stream() << "target: " << targetName;
- stream() << "property: \"" << propertyName << "\"";
- if (value.typeId() == QMetaType::QColor)
- stream() << "to: \"" << value.toString() << '"';
- else
- stream() << "to: " << value.toReal();
- stream() << "duration: " << (time - previousTime);
+ stream() << "to: " << value.toReal();
+ stream() << "duration: " << (time - previousTime);
- m_indentLevel--;
- stream() << "}";
+ m_indentLevel--;
+ stream() << "}";
+ }
previousTime = time;
}