diff options
Diffstat (limited to 'src/declarative/util')
-rw-r--r-- | src/declarative/util/qmlfollow.cpp | 29 | ||||
-rw-r--r-- | src/declarative/util/qmlfollow.h | 3 |
2 files changed, 30 insertions, 2 deletions
diff --git a/src/declarative/util/qmlfollow.cpp b/src/declarative/util/qmlfollow.cpp index 998166a..8e5ae69 100644 --- a/src/declarative/util/qmlfollow.cpp +++ b/src/declarative/util/qmlfollow.cpp @@ -55,7 +55,7 @@ class QmlFollowPrivate : public QObjectPrivate public: QmlFollowPrivate() : sourceValue(0), maxVelocity(0), lastTime(0) - , mass(1.0), spring(0.), damping(0.), velocity(0), enabled(true), mode(Track), clock(this) {} + , mass(1.0), spring(0.), damping(0.), velocity(0), epsilon(0.005), enabled(true), mode(Track), clock(this) {} QmlMetaProperty property; qreal currentValue; @@ -67,6 +67,7 @@ public: qreal spring; qreal damping; qreal velocity; + qreal epsilon; bool enabled; enum Mode { @@ -111,7 +112,7 @@ void QmlFollowPrivate::tick(int time) } currentValue += velocity * 10.0 / 1000.0; } - if (qAbs(velocity) < 0.5 && qAbs(sourceValue - currentValue) < 0.5) { + if (qAbs(velocity) < epsilon && qAbs(sourceValue - currentValue) < epsilon) { velocity = 0.0; currentValue = sourceValue; clock.stop(); @@ -300,6 +301,30 @@ void QmlFollow::setDamping(qreal damping) d->damping = damping; } + +/*! + \qmlproperty qreal Follow::epsilon + This property holds the spring epsilon + + The epsilon is the rate and amount of change in the value which is close enough + to 0 to be considered equal to zero. This will depend on the usage of the value. + For pixel positions, 0.25 would suffice. For scale, 0.005 will suffice. + + The default is 0.005. Small performance improvements can result in tuning this + value. +*/ +qreal QmlFollow::epsilon() const +{ + Q_D(const QmlFollow); + return d->epsilon; +} + +void QmlFollow::setEpsilon(qreal epsilon) +{ + Q_D(QmlFollow); + d->epsilon = epsilon; +} + /*! \qmlproperty qreal Follow::followValue The current value. diff --git a/src/declarative/util/qmlfollow.h b/src/declarative/util/qmlfollow.h index aac4c01..bd9363a 100644 --- a/src/declarative/util/qmlfollow.h +++ b/src/declarative/util/qmlfollow.h @@ -63,6 +63,7 @@ class Q_DECLARATIVE_EXPORT QmlFollow : public QmlPropertyValueSource, Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity); Q_PROPERTY(qreal spring READ spring WRITE setSpring); Q_PROPERTY(qreal damping READ damping WRITE setDamping); + Q_PROPERTY(qreal epsilon READ epsilon WRITE setEpsilon); Q_PROPERTY(bool enabled READ enabled WRITE setEnabled); Q_PROPERTY(qreal followValue READ value NOTIFY valueChanged); @@ -80,6 +81,8 @@ public: void setSpring(qreal spring); qreal damping() const; void setDamping(qreal damping); + qreal epsilon() const; + void setEpsilon(qreal epsilon); bool enabled() const; void setEnabled(bool enabled); |