7 #include "qqmlcontext.h"
10 #include <rive/core.hpp>
11 #include <rive/animation/state_machine_instance.hpp>
13 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
14 # include <QtQml/qqmlregistration.h>
118 class DynamicPropertyHolder :
public QObject
121 Q_PROPERTY(QVariant value READ value NOTIFY valueChanged)
129 explicit DynamicPropertyHolder(QObject *parent =
nullptr)
134 QVariant value()
const {
return m_value; }
136 void setValue(
const QVariant &value)
138 if (m_value != value) {
152 Q_INTERFACES(QQmlParserStatus)
156 Q_PROPERTY(QVariantList riveInputs READ riveInputs NOTIFY riveInputsChanged)
158 enum class RivePropertyType : short
164 Q_ENUM(RivePropertyType)
168 void generateStringInterface();
169 bool hasDirtyStateMachine()
const {
return m_dirty; }
171 Q_INVOKABLE
void setRiveProperty(
const QString &propertyName,
const QVariant &value);
172 Q_INVOKABLE QVariant getRiveProperty(
const QString &propertyName)
const;
173 Q_INVOKABLE
void callTrigger(
const QString &triggerName);
174 Q_INVOKABLE QObject *listenTo(
const QString &name);
176 void setStateMachineInstance(rive::StateMachineInstance *stateMachineInstance);
177 QVariantList riveInputs()
const;
179 const QString &riveQtArtboardName()
const;
180 void setRiveQtArtboardName(
const QString &newRiveQtArtboardName);
182 void initializeInternal();
187 void riveInputsChanged();
190 void activateTrigger();
191 void handlePropertyChanged();
194 void classBegin()
override;
195 void componentComplete()
override;
198 QString cleanUpRiveName(
const QString &name);
202 const QStringList reservedWords = {
"await",
"break",
"case",
"catch",
203 "class",
"const",
"continue",
"debugger",
204 "default",
"delete",
"do",
"else",
205 "export",
"extends",
"finally",
"for",
206 "function",
"if",
"import",
"in",
207 "instanceof",
"new",
"return",
"super",
208 "switch",
"this",
"throw",
"try",
209 "typeof",
"var",
"void",
"while",
210 "with",
"yield",
"enum",
"implements",
211 "interface",
"let",
"package",
"private",
212 "protected",
"public",
"static",
"riveQtArtboardName",
214 void connectStateMachineToProperties();
215 rive::StateMachineInstance *m_stateMachineInstance {
nullptr };
216 QMap<QString, rive::SMIInput *> m_inputMap;
218 bool m_dirty {
false };
219 bool m_isCompleted {
false };
220 bool m_hasGeneratedStringInterface {
false };
222 QVariantMap m_generatedRivePropertyMap;
223 QMap<QString, DynamicPropertyHolder *> m_dynamicProperties;
225 QPair<bool, QVariant> updateProperty(
const QString &propertyName,
const QVariant &propertyValue);
228 Q_DECLARE_METATYPE(RiveStateMachineInput::RivePropertyType)