aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickvectorimage/qquickvectorimage_p.h
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <[email protected]>2025-04-07 14:44:51 +0200
committerEskil Abrahamsen Blomfeldt <[email protected]>2025-05-14 14:49:28 +0200
commit0a848c1f26f82bfc2259beb104691c41c3547b5f (patch)
tree6f200463e1e6bf69e96d7d38de9d884027b6ac9d /src/quickvectorimage/qquickvectorimage_p.h
parent711b4d7a383a79d8b73ced106f82228e664fd8ef (diff)
Add API to VectorImage for controlling animations
A lot of animations will just be a single time line that you is intended to be controlled from the outside (and formats like Lottie does not support anything beyond this), so we need some API to match the general Animation API so that you can restart, pause/resume and change the number of times an animation loops. We do this by adding a group of properties called "animations" that can be used to control all the animations in the document at once. We generate this both in the QML file from *toqml and also in VectorImage itself. [ChangeLog][QtQuickVectorImage] Added some API to the VectorImage for looping, stopping, pausing and resuming animations. Fixes: QTBUG-135265 Change-Id: Id372c00110d165d02db357ce77eb1dec504cffb8 Reviewed-by: Eirik Aavitsland <[email protected]>
Diffstat (limited to 'src/quickvectorimage/qquickvectorimage_p.h')
-rw-r--r--src/quickvectorimage/qquickvectorimage_p.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/quickvectorimage/qquickvectorimage_p.h b/src/quickvectorimage/qquickvectorimage_p.h
index cce935d3ea..a997f2e8ba 100644
--- a/src/quickvectorimage/qquickvectorimage_p.h
+++ b/src/quickvectorimage/qquickvectorimage_p.h
@@ -16,11 +16,13 @@
//
#include <QQuickItem>
+#include <QtQuick/private/qquickanimation_p.h>
#include <QtQuickVectorImage/qtquickvectorimageexports.h>
QT_BEGIN_NAMESPACE
class QQuickVectorImagePrivate;
+class QQuickVectorImageAnimations;
class Q_QUICKVECTORIMAGE_EXPORT QQuickVectorImage : public QQuickItem
{
@@ -29,6 +31,7 @@ class Q_QUICKVECTORIMAGE_EXPORT QQuickVectorImage : public QQuickItem
Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
Q_PROPERTY(RendererType preferredRendererType READ preferredRendererType WRITE setPreferredRendererType NOTIFY preferredRendererTypeChanged)
+ Q_PROPERTY(QQuickVectorImageAnimations *animations READ animations CONSTANT REVISION(6, 10) FINAL)
QML_NAMED_ELEMENT(VectorImage)
public:
@@ -57,6 +60,8 @@ public:
RendererType preferredRendererType() const;
void setPreferredRendererType(RendererType newPreferredRendererType);
+ QQuickVectorImageAnimations *animations();
+
signals:
void sourceChanged();
void fillModeChanged();
@@ -65,12 +70,44 @@ signals:
private slots:
void updateSvgItemScale();
+ void updateAnimationProperties();
private:
Q_DISABLE_COPY(QQuickVectorImage)
Q_DECLARE_PRIVATE(QQuickVectorImage)
};
+class Q_QUICKVECTORIMAGE_EXPORT QQuickVectorImageAnimations : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopsChanged FINAL)
+ Q_PROPERTY(bool paused READ paused WRITE setPaused NOTIFY pausedChanged FINAL)
+
+ QML_ANONYMOUS
+ QML_ADDED_IN_VERSION(6, 10)
+public:
+ QQuickVectorImageAnimations(QObject *parent = nullptr) : QObject(parent) {}
+
+ int loops() const;
+
+ void setLoops(int loops);
+
+ bool paused() const;
+ void setPaused(bool paused);
+
+ Q_INVOKABLE void restart();
+
+Q_SIGNALS:
+ void loopsChanged();
+ void enabledChanged();
+ void pausedChanged();
+
+private:
+ int m_loops = 1;
+ bool m_paused = false;
+};
+
QT_END_NAMESPACE
#endif // QQUICKVECTORIMAGE_P_H