summaryrefslogtreecommitdiffstats
path: root/src/declarative/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/util')
-rw-r--r--src/declarative/util/qdeclarativespringfollow.cpp47
-rw-r--r--src/declarative/util/qdeclarativespringfollow_p.h14
2 files changed, 35 insertions, 26 deletions
diff --git a/src/declarative/util/qdeclarativespringfollow.cpp b/src/declarative/util/qdeclarativespringfollow.cpp
index c42261d..7921735 100644
--- a/src/declarative/util/qdeclarativespringfollow.cpp
+++ b/src/declarative/util/qdeclarativespringfollow.cpp
@@ -59,13 +59,13 @@ class QDeclarativeSpringFollowPrivate : public QObjectPrivate
Q_DECLARE_PUBLIC(QDeclarativeSpringFollow)
public:
QDeclarativeSpringFollowPrivate()
- : currentValue(0), sourceValue(0), maxVelocity(0), lastTime(0)
+ : currentValue(0), to(0), maxVelocity(0), lastTime(0)
, mass(1.0), spring(0.), damping(0.), velocity(0), epsilon(0.01)
, modulus(0.0), useMass(false), haveModulus(false), enabled(true), mode(Track), clock(this) {}
QDeclarativeProperty property;
qreal currentValue;
- qreal sourceValue;
+ qreal to;
qreal maxVelocity;
qreal velocityms;
int lastTime;
@@ -102,7 +102,7 @@ void QDeclarativeSpringFollowPrivate::tick(int time)
int elapsed = time - lastTime;
if (!elapsed)
return;
- qreal srcVal = sourceValue;
+ qreal srcVal = to;
if (haveModulus) {
currentValue = fmod(currentValue, modulus);
srcVal = fmod(srcVal, modulus);
@@ -158,16 +158,16 @@ void QDeclarativeSpringFollowPrivate::tick(int time)
currentValue += moveBy;
if (haveModulus)
currentValue = fmod(currentValue, modulus);
- if (currentValue > sourceValue) {
- currentValue = sourceValue;
+ if (currentValue > to) {
+ currentValue = to;
clock.stop();
}
} else {
currentValue -= moveBy;
if (haveModulus && currentValue < 0.0)
currentValue = fmod(currentValue, modulus) + modulus;
- if (currentValue < sourceValue) {
- currentValue = sourceValue;
+ if (currentValue < to) {
+ currentValue = to;
clock.stop();
}
}
@@ -196,9 +196,9 @@ void QDeclarativeSpringFollowPrivate::start()
Q_Q(QDeclarativeSpringFollow);
if (mode == QDeclarativeSpringFollowPrivate::Track) {
- currentValue = sourceValue;
+ currentValue = to;
property.write(currentValue);
- } else if (sourceValue != currentValue && clock.state() != QAbstractAnimation::Running) {
+ } else if (to != currentValue && clock.state() != QAbstractAnimation::Running) {
lastTime = 0;
currentValue = property.read().toReal();
clock.start(); // infinity??
@@ -239,7 +239,7 @@ void QDeclarativeSpringFollowPrivate::stop()
x: rect1.width
width: 20; height: 20
color: "#ff0000"
- SpringFollow on y { source: rect1.y; velocity: 200 }
+ SpringFollow on y { to: rect1.y; velocity: 200 }
}
\endcode
*/
@@ -260,26 +260,26 @@ void QDeclarativeSpringFollow::setTarget(const QDeclarativeProperty &property)
d->currentValue = property.read().toReal();
}
-qreal QDeclarativeSpringFollow::sourceValue() const
+qreal QDeclarativeSpringFollow::to() const
{
Q_D(const QDeclarativeSpringFollow);
- return d->sourceValue;
+ return d->to;
}
/*!
- \qmlproperty qreal SpringFollow::source
- This property holds the source value which will be tracked.
+ \qmlproperty qreal SpringFollow::to
+ This property holds the target value which will be tracked.
Bind to a property in order to track its changes.
*/
-void QDeclarativeSpringFollow::setSourceValue(qreal value)
+void QDeclarativeSpringFollow::setTo(qreal value)
{
Q_D(QDeclarativeSpringFollow);
- if (d->clock.state() == QAbstractAnimation::Running && d->sourceValue == value)
+ if (d->clock.state() == QAbstractAnimation::Running && d->to == value)
return;
- d->sourceValue = value;
+ d->to = value;
d->start();
}
@@ -307,7 +307,7 @@ void QDeclarativeSpringFollow::setVelocity(qreal velocity)
This property holds the spring constant
The spring constant describes how strongly the target is pulled towards the
- source. Setting spring to 0 turns off spring tracking. Useful values 0 - 5.0
+ source. Setting spring to 0 turns off spring tracking. Useful values 0 - 5.0
When a spring constant is set and the velocity property is greater than 0,
velocity limits the maximum speed.
@@ -417,13 +417,10 @@ void QDeclarativeSpringFollow::setMass(qreal mass)
}
/*!
- \qmlproperty qreal SpringFollow::value
- The current value.
-*/
-
-/*!
\qmlproperty bool SpringFollow::enabled
This property holds whether the target will track the source.
+
+ The default value of this property is 'true'.
*/
bool QDeclarativeSpringFollow::enabled() const
{
@@ -454,6 +451,10 @@ bool QDeclarativeSpringFollow::inSync() const
return d->enabled && d->clock.state() != QAbstractAnimation::Running;
}
+/*!
+ \qmlproperty qreal SpringFollow::value
+ The current value.
+*/
qreal QDeclarativeSpringFollow::value() const
{
Q_D(const QDeclarativeSpringFollow);
diff --git a/src/declarative/util/qdeclarativespringfollow_p.h b/src/declarative/util/qdeclarativespringfollow_p.h
index 2ac0d82..b829c57 100644
--- a/src/declarative/util/qdeclarativespringfollow_p.h
+++ b/src/declarative/util/qdeclarativespringfollow_p.h
@@ -59,7 +59,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeSpringFollow : public QObject,
Q_DECLARE_PRIVATE(QDeclarativeSpringFollow)
Q_INTERFACES(QDeclarativePropertyValueSource)
- Q_PROPERTY(qreal source READ sourceValue WRITE setSourceValue)
+ Q_PROPERTY(qreal to READ to WRITE setTo)
Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity)
Q_PROPERTY(qreal spring READ spring WRITE setSpring)
Q_PROPERTY(qreal damping READ damping WRITE setDamping)
@@ -76,22 +76,30 @@ public:
virtual void setTarget(const QDeclarativeProperty &);
- qreal sourceValue() const;
- void setSourceValue(qreal value);
+ qreal to() const;
+ void setTo(qreal value);
+
qreal velocity() const;
void setVelocity(qreal velocity);
+
qreal spring() const;
void setSpring(qreal spring);
+
qreal damping() const;
void setDamping(qreal damping);
+
qreal epsilon() const;
void setEpsilon(qreal epsilon);
+
qreal mass() const;
void setMass(qreal modulus);
+
qreal modulus() const;
void setModulus(qreal modulus);
+
bool enabled() const;
void setEnabled(bool enabled);
+
bool inSync() const;
qreal value() const;