3#include "qml_material/token/motion.hpp"
10struct QML_MATERIAL_API AnimationSpec {
12 QML_VALUE_TYPE(animationSpec)
14 Q_PROPERTY(Kind kind MEMBER kind FINAL)
15 Q_PROPERTY(
int duration MEMBER duration FINAL)
16 Q_PROPERTY(
int delay MEMBER delay FINAL)
17 Q_PROPERTY(QEasingCurve easing MEMBER easing FINAL)
18 Q_PROPERTY(qreal stiffness MEMBER stiffness FINAL)
19 Q_PROPERTY(qreal dampingRatio MEMBER dampingRatio FINAL)
20 Q_PROPERTY(qreal threshold MEMBER threshold FINAL)
21 Q_PROPERTY(qreal velocityThreshold MEMBER velocityThreshold FINAL)
31 int duration = 300, delay = 0;
32 QEasingCurve easing { QEasingCurve::Linear };
33 qreal stiffness = 700, dampingRatio = .9, threshold = .01, velocityThreshold = .1;
35 bool operator==(
const AnimationSpec&)
const =
default;
37struct QML_MATERIAL_API DecaySpec {
39 QML_VALUE_TYPE(decaySpec)
41 Q_PROPERTY(qreal friction MEMBER friction FINAL)
42 Q_PROPERTY(qreal velocityThreshold MEMBER velocityThreshold FINAL)
44 qreal friction = 5, velocityThreshold = .1;
46 bool operator==(
const DecaySpec&)
const =
default;
48class QML_MATERIAL_API Motion :
public QObject {
53 using QObject::QObject;
54 Q_INVOKABLE
static AnimationSpec tween(
int duration, QEasingCurve easing = QEasingCurve(),
56 Q_INVOKABLE
static AnimationSpec spring(qreal stiffness = 700, qreal dampingRatio = .9);
57 Q_INVOKABLE
static AnimationSpec snap();
58 Q_INVOKABLE
static DecaySpec decay(qreal friction = 5, qreal velocityThreshold = .1);
62using Vector = QList<qreal>;
63enum class SpringCompletion
66 DisplacementAndVelocity
69 Vector value, velocity;
72 qreal value = 0, velocity = 0;
74QML_MATERIAL_API SpringSample sampleSpring(token::SpringSpec, qreal, qreal, qreal, qreal);
75QML_MATERIAL_API
int springDuration(token::SpringSpec, qreal, qreal, qreal, qreal);
76QML_MATERIAL_API
bool finite(
const Vector&);
77class QML_MATERIAL_API PreparedMotion {
79 static std::optional<PreparedMotion>
80 prepare(
const Vector& from,
const Vector& to,
const Vector& velocity, AnimationSpec,
81 const Vector& thresholds = {},
82 SpringCompletion = SpringCompletion::DisplacementAndVelocity);
83 static std::optional<PreparedMotion> decay(
const Vector& from,
const Vector& velocity,
85 Sample sample(qreal milliseconds)
const;
86 const Vector& target()
const {
return m_to; }
87 int duration()
const {
return m_duration; }
90 Vector m_from, m_to, m_velocity;
91 QList<int> m_durations;
93 std::optional<DecaySpec> m_decay;