summaryrefslogtreecommitdiffstats
path: root/src/declarative/util
diff options
context:
space:
mode:
authorPaul Olav Tvete <paul.tvete@nokia.com>2010-08-19 10:04:39 (GMT)
committerPaul Olav Tvete <paul.tvete@nokia.com>2010-08-19 10:04:39 (GMT)
commita226143eeda6771efc4f0df6955351336735cb60 (patch)
treea279f87d74f5929e36fe6a3aa5e4f4d843b32458 /src/declarative/util
parentc02ad51733d0a2885ddb39cb7e3b09355ab97213 (diff)
parentffbce9839f8be5c2f21cc66b617dbeb0a47af269 (diff)
downloadQt-a226143eeda6771efc4f0df6955351336735cb60.zip
Qt-a226143eeda6771efc4f0df6955351336735cb60.tar.gz
Qt-a226143eeda6771efc4f0df6955351336735cb60.tar.bz2
Merge remote branch 'qt/master' into lighthouse-master
Diffstat (limited to 'src/declarative/util')
-rw-r--r--src/declarative/util/qdeclarativeanimation.cpp52
-rw-r--r--src/declarative/util/qdeclarativebehavior.cpp9
-rw-r--r--src/declarative/util/qdeclarativelistmodel.cpp48
-rw-r--r--src/declarative/util/qdeclarativelistmodel_p_p.h3
-rw-r--r--src/declarative/util/qdeclarativepixmapcache.cpp2
-rw-r--r--src/declarative/util/qdeclarativepropertymap.cpp19
-rw-r--r--src/declarative/util/qdeclarativesmoothedanimation.cpp2
-rw-r--r--src/declarative/util/qdeclarativespringanimation.cpp231
-rw-r--r--src/declarative/util/qdeclarativespringanimation_p.h17
-rw-r--r--src/declarative/util/qdeclarativestate.cpp5
-rw-r--r--src/declarative/util/qdeclarativestategroup.cpp4
-rw-r--r--src/declarative/util/qdeclarativetransition.cpp23
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel.cpp10
13 files changed, 221 insertions, 204 deletions
diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp
index 6a9cf95..a747706 100644
--- a/src/declarative/util/qdeclarativeanimation.cpp
+++ b/src/declarative/util/qdeclarativeanimation.cpp
@@ -645,12 +645,13 @@ QAbstractAnimation *QDeclarativePauseAnimation::qtAnimation()
Like any other animation element, a ColorAnimation can be applied in a
number of ways, including transitions, behaviors and property value
- sources. The \l PropertyAnimation documentation shows a variety of methods
+ sources. The \l {QML Animation} documentation shows a variety of methods
for creating animations.
- When used in a transition, ColorAnimation will by default animate
- all properties of type color that have changed. If a \l{PropertyAnimation::}{property}
- or \l{PropertyAnimation::}{properties} are explicitly set for the animation,
+ For convenience, when a ColorAnimation is used in a \l Transition, it will
+ animate any \c color properties that have been modified during the state
+ change. If a \l{PropertyAnimation::}{property} or
+ \l{PropertyAnimation::}{properties} are explicitly set for the animation,
then those are used instead.
\sa {QML Animation}, {declarative/animation/basics}{Animation basics example}
@@ -1143,7 +1144,7 @@ void QDeclarativePropertyAction::transition(QDeclarativeStateActions &actions,
Like any other animation element, a NumberAnimation can be applied in a
number of ways, including transitions, behaviors and property value
- sources. The \l PropertyAnimation documentation shows a variety of methods
+ sources. The \l {QML Animation} documentation shows a variety of methods
for creating animations.
Note that NumberAnimation may not animate smoothly if there are irregular
@@ -1244,6 +1245,11 @@ void QDeclarativeNumberAnimation::setTo(qreal t)
Vector3dAnimation is a specialized PropertyAnimation that defines an
animation to be applied when a Vector3d value changes.
+ Like any other animation element, a Vector3dAnimation can be applied in a
+ number of ways, including transitions, behaviors and property value
+ sources. The \l {QML Animation} documentation shows a variety of methods
+ for creating animations.
+
\sa {QML Animation}, {declarative/animation/basics}{Animation basics example}
*/
@@ -1323,7 +1329,7 @@ void QDeclarativeVector3dAnimation::setTo(QVector3D t)
\snippet doc/src/snippets/declarative/rotationanimation.qml 0
- Notice the RotationAnimation did not need to set a \l {RotationAnimation::}{target}
+ Notice the RotationAnimation did not need to set a \l target
value. As a convenience, when used in a transition, RotationAnimation will rotate all
properties named "rotation" or "angle". You can override this by providing
your own properties via \l {PropertyAnimation::properties}{properties} or
@@ -1331,7 +1337,7 @@ void QDeclarativeVector3dAnimation::setTo(QVector3D t)
Like any other animation element, a RotationAnimation can be applied in a
number of ways, including transitions, behaviors and property value
- sources. The \l PropertyAnimation documentation shows a variety of methods
+ sources. The \l {QML Animation} documentation shows a variety of methods
for creating animations.
\sa {QML Animation}, {declarative/animation/basics}{Animation basics example}
@@ -1554,7 +1560,7 @@ QDeclarativeListProperty<QDeclarativeAbstractAnimation> QDeclarativeAnimationGro
Like any other animation element, a SequentialAnimation can be applied in a
number of ways, including transitions, behaviors and property value
- sources. The \l PropertyAnimation documentation shows a variety of methods
+ sources. The \l {QML Animation} documentation shows a variety of methods
for creating animations.
\note Once an animation has been grouped into a SequentialAnimation or
@@ -1623,7 +1629,7 @@ void QDeclarativeSequentialAnimation::transition(QDeclarativeStateActions &actio
Like any other animation element, a ParallelAnimation can be applied in a
number of ways, including transitions, behaviors and property value
- sources. The \l PropertyAnimation documentation shows a variety of methods
+ sources. The \l {QML Animation} documentation shows a variety of methods
for creating animations.
\note Once an animation has been grouped into a SequentialAnimation or
@@ -2396,8 +2402,7 @@ void QDeclarativePropertyAnimation::transition(QDeclarativeStateActions &actions
\inherits Animation
\brief The ParentAnimation element animates changes in parent values.
- ParentAnimation defines an animation to applied when a ParentChange
- occurs. This allows parent changes to be smoothly animated.
+ ParentAnimation is used to animate a parent change for an \l Item.
For example, the following ParentChange changes \c blueRect to become
a child of \c redRect when it is clicked. The inclusion of the
@@ -2415,10 +2420,16 @@ void QDeclarativePropertyAnimation::transition(QDeclarativeStateActions &actions
to animate the parent change via another item that does not have clipping
enabled. Such an item can be set using the \l via property.
- By default, when used in a transition, ParentAnimation animates all parent
- changes. This can be overridden by setting a specific target item using the
+ For convenience, when a ParentAnimation is used in a \l Transition, it will
+ animate any ParentChange that has occurred during the state change.
+ This can be overridden by setting a specific target item using the
\l target property.
+ Like any other animation element, a ParentAnimation can be applied in a
+ number of ways, including transitions, behaviors and property value
+ sources. The \l {QML Animation} documentation shows a variety of methods
+ for creating animations.
+
\sa {QML Animation}, {declarative/animation/basics}{Animation basics example}
*/
@@ -2750,14 +2761,23 @@ QAbstractAnimation *QDeclarativeParentAnimation::qtAnimation()
\inherits Animation
\brief The AnchorAnimation element animates changes in anchor values.
- AnchorAnimation is used to animate an AnchorChange. It will anchor all
- anchor changes specified in a \l State.
+ AnchorAnimation is used to animate an anchor change.
In the following snippet we animate the addition of a right anchor to a \l Rectangle:
\snippet doc/src/snippets/declarative/anchoranimation.qml 0
- \sa AnchorChanges
+ For convenience, when an AnchorAnimation is used in a \l Transition, it will
+ animate any AnchorChanges that have occurred during the state change.
+ This can be overridden by setting a specific target item using the
+ \l target property.
+
+ Like any other animation element, an AnchorAnimation can be applied in a
+ number of ways, including transitions, behaviors and property value
+ sources. The \l {QML Animation} documentation shows a variety of methods
+ for creating animations.
+
+ \sa {QML Animation}, AnchorChanges
*/
QDeclarativeAnchorAnimation::QDeclarativeAnchorAnimation(QObject *parent)
diff --git a/src/declarative/util/qdeclarativebehavior.cpp b/src/declarative/util/qdeclarativebehavior.cpp
index fadb2ae..1e7f81a 100644
--- a/src/declarative/util/qdeclarativebehavior.cpp
+++ b/src/declarative/util/qdeclarativebehavior.cpp
@@ -84,12 +84,15 @@ public:
\snippet doc/src/snippets/declarative/behavior.qml 0
- To run multiple animations within a Behavior, use ParallelAnimation or
+ Note that a property cannot have more than one assigned Behavior. To provide
+ multiple animations within a Behavior, use ParallelAnimation or
SequentialAnimation.
- Note that a property cannot have more than one assigned Behavior.
+ If a \l{QML States}{state change} has a \l Transition that matches the same property as a
+ Behavior, the \l Transition animation overrides the Behavior for that
+ state change.
- \sa {Property Behaviors}, {declarative/animation/behaviors}{Behavior example}, QtDeclarative
+ \sa {QML Animation}, {declarative/animation/behaviors}{Behavior example}, QtDeclarative
*/
diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp
index 3ede335..3a6a5b0 100644
--- a/src/declarative/util/qdeclarativelistmodel.cpp
+++ b/src/declarative/util/qdeclarativelistmodel.cpp
@@ -108,9 +108,9 @@ QDeclarativeListModelParser::ListInstruction *QDeclarativeListModelParser::ListM
\snippet doc/src/snippets/declarative/listmodel-modify.qml delegate
- When creating content dynamically, note that the set of available properties cannot be changed
- except by first clearing the model. Whatever properties are first added to the model are then the
- only permitted properties in the model until it is cleared.
+ Note that when creating content dynamically the set of available properties cannot be changed
+ once set. Whatever properties are first added to the model are the
+ only permitted properties in the model.
\section2 Using threaded list models with WorkerScript
@@ -283,8 +283,7 @@ int QDeclarativeListModel::count() const
/*!
\qmlmethod ListModel::clear()
- Deletes all content from the model. The properties are cleared such that
- different properties may be set on subsequent additions.
+ Deletes all content from the model.
\sa append() remove()
*/
@@ -708,7 +707,7 @@ void QDeclarativeListModelParser::setCustomData(QObject *obj, const QByteArray &
{
ModelNode *n = nodes.top();
ModelNode *n2 = new ModelNode;
- n->values << qVariantFromValue(n2);
+ n->values << QVariant::fromValue(n2);
nodes.push(n2);
if (processingSet)
n->isArray = true;
@@ -864,7 +863,7 @@ QScriptValue FlatListModel::get(int index) const
QHash<int, QVariant> row = m_values.at(index);
for (QHash<int, QVariant>::ConstIterator iter = row.begin(); iter != row.end(); ++iter)
- rv.setProperty(m_roles.value(iter.key()), qScriptValueFromValue(scriptEngine, iter.value()));
+ rv.setProperty(m_roles.value(iter.key()), scriptEngine->toScriptValue(iter.value()));
return rv;
}
@@ -945,13 +944,14 @@ bool FlatListModel::addValue(const QScriptValue &value, QHash<int, QVariant> *ro
}
NestedListModel::NestedListModel(QDeclarativeListModel *base)
- : _root(0), m_listModel(base), _rolesOk(false)
+ : _root(0), m_ownsRoot(false), m_listModel(base), _rolesOk(false)
{
}
NestedListModel::~NestedListModel()
{
- delete _root;
+ if (m_ownsRoot)
+ delete _root;
}
QVariant NestedListModel::valueForNode(ModelNode *node, bool *hasNested) const
@@ -1051,8 +1051,8 @@ void NestedListModel::clear()
_rolesOk = false;
roleStrings.clear();
- delete _root;
- _root = 0;
+ if (_root)
+ _root->clear();
}
void NestedListModel::remove(int index)
@@ -1067,12 +1067,14 @@ void NestedListModel::remove(int index)
bool NestedListModel::insert(int index, const QScriptValue& valuemap)
{
- if (!_root)
+ if (!_root) {
_root = new ModelNode;
+ m_ownsRoot = true;
+ }
ModelNode *mn = new ModelNode;
mn->setObjectValue(valuemap);
- _root->values.insert(index,qVariantFromValue(mn));
+ _root->values.insert(index,QVariant::fromValue(mn));
return true;
}
@@ -1099,11 +1101,13 @@ void NestedListModel::move(int from, int to, int n)
bool NestedListModel::append(const QScriptValue& valuemap)
{
- if (!_root)
+ if (!_root) {
_root = new ModelNode;
+ m_ownsRoot = true;
+ }
ModelNode *mn = new ModelNode;
mn->setObjectValue(valuemap);
- _root->values << qVariantFromValue(mn);
+ _root->values << QVariant::fromValue(mn);
return true;
}
@@ -1205,16 +1209,22 @@ ModelNode::ModelNode()
ModelNode::~ModelNode()
{
- qDeleteAll(properties.values());
+ clear();
+ if (modelCache) { modelCache->m_nested->_root = 0/* ==this */; delete modelCache; modelCache = 0; }
+ if (objectCache) { delete objectCache; objectCache = 0; }
+}
+void ModelNode::clear()
+{
ModelNode *node;
for (int ii = 0; ii < values.count(); ++ii) {
node = qvariant_cast<ModelNode *>(values.at(ii));
if (node) { delete node; node = 0; }
}
+ values.clear();
- if (modelCache) { modelCache->m_nested->_root = 0/* ==this */; delete modelCache; modelCache = 0; }
- if (objectCache) { delete objectCache; objectCache = 0; }
+ qDeleteAll(properties.values());
+ properties.clear();
}
void ModelNode::setObjectValue(const QScriptValue& valuemap) {
@@ -1252,7 +1262,7 @@ void ModelNode::setListValue(const QScriptValue& valuelist) {
} else {
value->values << v.toVariant();
}
- values.append(qVariantFromValue(value));
+ values.append(QVariant::fromValue(value));
}
}
diff --git a/src/declarative/util/qdeclarativelistmodel_p_p.h b/src/declarative/util/qdeclarativelistmodel_p_p.h
index 532eefa..8231414 100644
--- a/src/declarative/util/qdeclarativelistmodel_p_p.h
+++ b/src/declarative/util/qdeclarativelistmodel_p_p.h
@@ -130,6 +130,7 @@ public:
void checkRoles() const;
ModelNode *_root;
+ bool m_ownsRoot;
QDeclarativeListModel *m_listModel;
private:
@@ -157,6 +158,8 @@ struct ModelNode
QList<QVariant> values;
QHash<QString, ModelNode *> properties;
+ void clear();
+
QDeclarativeListModel *model(const NestedListModel *model) {
if (!modelCache) {
modelCache = new QDeclarativeListModel;
diff --git a/src/declarative/util/qdeclarativepixmapcache.cpp b/src/declarative/util/qdeclarativepixmapcache.cpp
index 9ced14f..de2de21 100644
--- a/src/declarative/util/qdeclarativepixmapcache.cpp
+++ b/src/declarative/util/qdeclarativepixmapcache.cpp
@@ -525,6 +525,7 @@ void QDeclarativePixmapReader::cancel(QDeclarativePixmapReply *reply)
mutex.lock();
if (reply->loading) {
cancelled.append(reply);
+ reply->data = 0;
// XXX
if (threadObject) threadObject->processJobs();
} else {
@@ -738,7 +739,6 @@ void QDeclarativePixmapData::release()
if (refCount == 0) {
if (reply) {
- reply->data = 0;
reply->reader->cancel(reply);
reply = 0;
}
diff --git a/src/declarative/util/qdeclarativepropertymap.cpp b/src/declarative/util/qdeclarativepropertymap.cpp
index 919727f..6b43040 100644
--- a/src/declarative/util/qdeclarativepropertymap.cpp
+++ b/src/declarative/util/qdeclarativepropertymap.cpp
@@ -104,22 +104,25 @@ void QDeclarativePropertyMapMetaObject::propertyCreated(int, QMetaPropertyBuilde
The following example shows how you might declare data in C++ and then
access it in QML.
- Setup in C++:
+ In the C++ file:
\code
- //create our data
+ // create our data
QDeclarativePropertyMap ownerData;
ownerData.insert("name", QVariant(QString("John Smith")));
ownerData.insert("phone", QVariant(QString("555-5555")));
- //expose it to the UI layer
- QDeclarativeContext *ctxt = view->rootContext();
- ctxt->setProperty("owner", &data);
+ // expose it to the UI layer
+ QDeclarativeView view;
+ QDeclarativeContext *ctxt = view.rootContext();
+ ctxt->setContextProperty("owner", &ownerData);
+
+ view.setSource(QUrl::fromLocalFile("main.qml"));
+ view.show();
\endcode
- Then, in QML:
+ Then, in \c main.qml:
\code
- Text { text: owner.name }
- Text { text: owner.phone }
+ Text { text: owner.name + " " + owner.phone }
\endcode
The binding is dynamic - whenever a key's value is updated, anything bound to that
diff --git a/src/declarative/util/qdeclarativesmoothedanimation.cpp b/src/declarative/util/qdeclarativesmoothedanimation.cpp
index 727f427..30e1491 100644
--- a/src/declarative/util/qdeclarativesmoothedanimation.cpp
+++ b/src/declarative/util/qdeclarativesmoothedanimation.cpp
@@ -287,7 +287,7 @@ void QSmoothedAnimation::init()
Like any other animation element, a SmoothedAnimation can be applied in a
number of ways, including transitions, behaviors and property value
- sources. The \l PropertyAnimation documentation shows a variety of methods
+ sources. The \l {QML Animation} documentation shows a variety of methods
for creating animations.
\sa SpringAnimation, NumberAnimation, {QML Animation}, {declarative/animation/basics}{Animation basics example}
diff --git a/src/declarative/util/qdeclarativespringanimation.cpp b/src/declarative/util/qdeclarativespringanimation.cpp
index 8ce4832..6f4ac51 100644
--- a/src/declarative/util/qdeclarativespringanimation.cpp
+++ b/src/declarative/util/qdeclarativespringanimation.cpp
@@ -54,36 +54,32 @@
QT_BEGIN_NAMESPACE
-
-class QDeclarativeSpringAnimationPrivate : public QDeclarativeAbstractAnimationPrivate
+class QDeclarativeSpringAnimationPrivate : public QDeclarativePropertyAnimationPrivate
{
Q_DECLARE_PUBLIC(QDeclarativeSpringAnimation)
public:
- QDeclarativeSpringAnimationPrivate()
- : currentValue(0), to(0), from(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)
- , fromDefined(false), toDefined(false)
- , mode(Track), clock(this) {}
-
- qreal currentValue;
- qreal to;
- qreal from;
+
+
+ struct SpringAnimation {
+ SpringAnimation()
+ : currentValue(0), to(0), velocity(0){}
+ qreal currentValue;
+ qreal to;
+ qreal velocity;
+ };
+ QHash<QDeclarativeProperty, SpringAnimation> activeAnimations;
+
qreal maxVelocity;
qreal velocityms;
int lastTime;
qreal mass;
qreal spring;
qreal damping;
- qreal velocity;
qreal epsilon;
qreal modulus;
bool useMass : 1;
bool haveModulus : 1;
- bool enabled : 1;
- bool fromDefined : 1;
- bool toDefined : 1;
enum Mode {
Track,
@@ -92,38 +88,68 @@ public:
};
Mode mode;
- void tick(int);
+ QDeclarativeSpringAnimationPrivate()
+ : maxVelocity(0), velocityms(0), lastTime(0)
+ , mass(1.0), spring(0.), damping(0.), epsilon(0.01)
+ , modulus(0.0), useMass(false), haveModulus(false)
+ , mode(Track), clock(0)
+ { }
+
+ void tick(int time);
+ bool animate(const QDeclarativeProperty &property, SpringAnimation &animation, int elapsed);
void updateMode();
- QTickAnimationProxy<QDeclarativeSpringAnimationPrivate, &QDeclarativeSpringAnimationPrivate::tick> clock;
+ typedef QTickAnimationProxy<QDeclarativeSpringAnimationPrivate, &QDeclarativeSpringAnimationPrivate::tick> Clock;
+ Clock *clock;
};
void QDeclarativeSpringAnimationPrivate::tick(int time)
{
if (mode == Track) {
- clock.stop();
+ clock->stop();
return;
}
-
int elapsed = time - lastTime;
if (!elapsed)
return;
- qreal srcVal = to;
+
+ if (mode == Spring) {
+ if (elapsed < 16) // capped at 62fps.
+ return;
+ int count = elapsed / 16;
+ lastTime = time - (elapsed - count * 16);
+ } else {
+ lastTime = time;
+ }
+
+ QMutableHashIterator<QDeclarativeProperty, SpringAnimation> it(activeAnimations);
+ while (it.hasNext()) {
+ it.next();
+ if (animate(it.key(), it.value(), elapsed))
+ it.remove();
+ }
+
+ if (activeAnimations.isEmpty())
+ clock->stop();
+}
+
+bool QDeclarativeSpringAnimationPrivate::animate(const QDeclarativeProperty &property, SpringAnimation &animation, int elapsed)
+{
+
+ qreal srcVal = animation.to;
bool stop = false;
if (haveModulus) {
- currentValue = fmod(currentValue, modulus);
+ animation.currentValue = fmod(animation.currentValue, modulus);
srcVal = fmod(srcVal, modulus);
}
if (mode == Spring) {
- if (elapsed < 16) // capped at 62fps.
- return;
// Real men solve the spring DEs using RK4.
// We'll do something much simpler which gives a result that looks fine.
int count = elapsed / 16;
for (int i = 0; i < count; ++i) {
- qreal diff = srcVal - currentValue;
+ qreal diff = srcVal - animation.currentValue;
if (haveModulus && qAbs(diff) > modulus / 2) {
if (diff < 0)
diff += modulus;
@@ -131,32 +157,31 @@ void QDeclarativeSpringAnimationPrivate::tick(int time)
diff -= modulus;
}
if (useMass)
- velocity = velocity + (spring * diff - damping * velocity) / mass;
+ animation.velocity = animation.velocity + (spring * diff - damping * animation.velocity) / mass;
else
- velocity = velocity + spring * diff - damping * velocity;
+ animation.velocity = animation.velocity + spring * diff - damping * animation.velocity;
if (maxVelocity > 0.) {
// limit velocity
- if (velocity > maxVelocity)
- velocity = maxVelocity;
- else if (velocity < -maxVelocity)
- velocity = -maxVelocity;
+ if (animation.velocity > maxVelocity)
+ animation.velocity = maxVelocity;
+ else if (animation.velocity < -maxVelocity)
+ animation.velocity = -maxVelocity;
}
- currentValue += velocity * 16.0 / 1000.0;
+ animation.currentValue += animation.velocity * 16.0 / 1000.0;
if (haveModulus) {
- currentValue = fmod(currentValue, modulus);
- if (currentValue < 0.0)
- currentValue += modulus;
+ animation.currentValue = fmod(animation.currentValue, modulus);
+ if (animation.currentValue < 0.0)
+ animation.currentValue += modulus;
}
}
- if (qAbs(velocity) < epsilon && qAbs(srcVal - currentValue) < epsilon) {
- velocity = 0.0;
- currentValue = srcVal;
+ if (qAbs(animation.velocity) < epsilon && qAbs(srcVal - animation.currentValue) < epsilon) {
+ animation.velocity = 0.0;
+ animation.currentValue = srcVal;
stop = true;
}
- lastTime = time - (elapsed - count * 16);
} else {
qreal moveBy = elapsed * velocityms;
- qreal diff = srcVal - currentValue;
+ qreal diff = srcVal - animation.currentValue;
if (haveModulus && qAbs(diff) > modulus / 2) {
if (diff < 0)
diff += modulus;
@@ -164,33 +189,31 @@ void QDeclarativeSpringAnimationPrivate::tick(int time)
diff -= modulus;
}
if (diff > 0) {
- currentValue += moveBy;
+ animation.currentValue += moveBy;
if (haveModulus)
- currentValue = fmod(currentValue, modulus);
- if (currentValue > to) {
- currentValue = to;
+ animation.currentValue = fmod(animation.currentValue, modulus);
+ if (animation.currentValue > animation.to) {
+ animation.currentValue = animation.to;
stop = true;
}
} else {
- currentValue -= moveBy;
- if (haveModulus && currentValue < 0.0)
- currentValue = fmod(currentValue, modulus) + modulus;
- if (currentValue < to) {
- currentValue = to;
+ animation.currentValue -= moveBy;
+ if (haveModulus && animation.currentValue < 0.0)
+ animation.currentValue = fmod(animation.currentValue, modulus) + modulus;
+ if (animation.currentValue < animation.to) {
+ animation.currentValue = animation.to;
stop = true;
}
}
- lastTime = time;
}
- qreal old_to = to;
+ qreal old_to = animation.to;
- QDeclarativePropertyPrivate::write(defaultProperty, currentValue,
+ QDeclarativePropertyPrivate::write(property, animation.currentValue,
QDeclarativePropertyPrivate::BypassInterceptor |
QDeclarativePropertyPrivate::DontRemoveBinding);
- if (stop && old_to == to) // do not stop if we got restarted
- clock.stop();
+ return (stop && old_to == animation.to); // do not stop if we got restarted
}
void QDeclarativeSpringAnimationPrivate::updateMode()
@@ -205,6 +228,7 @@ void QDeclarativeSpringAnimationPrivate::updateMode()
/*!
\qmlclass SpringAnimation QDeclarativeSpringAnimation
+ \inherits Animation
\since 4.7
\brief The SpringAnimation element allows a property to track a value in a spring-like motion.
@@ -223,86 +247,23 @@ void QDeclarativeSpringAnimationPrivate::updateMode()
Like any other animation element, a SpringAnimation can be applied in a
number of ways, including transitions, behaviors and property value
- sources. The \l PropertyAnimation documentation shows a variety of methods
+ sources. The \l {QML Animation} documentation shows a variety of methods
for creating animations.
\sa SmoothedAnimation, {QML Animation}, {declarative/animation/basics}{Animation basics example}, {declarative/toys/clocks}{Clocks example}
*/
QDeclarativeSpringAnimation::QDeclarativeSpringAnimation(QObject *parent)
-: QDeclarativeAbstractAnimation(*(new QDeclarativeSpringAnimationPrivate),parent)
-{
-}
-
-QDeclarativeSpringAnimation::~QDeclarativeSpringAnimation()
-{
-}
-
-void QDeclarativeSpringAnimation::setTarget(const QDeclarativeProperty &property)
+: QDeclarativeNumberAnimation(*(new QDeclarativeSpringAnimationPrivate),parent)
{
Q_D(QDeclarativeSpringAnimation);
- d->defaultProperty = property;
- d->currentValue = property.read().toReal();
- if (!d->avoidPropertyValueSourceStart) {
- setRunning(true);
- }
-}
-
-qreal QDeclarativeSpringAnimation::to() const
-{
- Q_D(const QDeclarativeSpringAnimation);
- return d->toDefined ? d->to : 0;
-}
-
-/*!
- \qmlproperty real SpringAnimation::to
-
- This property holds the value at which the animation will end.
-
- If not set, the animation will continue until it reaches the
- value that is being tracked.
-*/
-
-void QDeclarativeSpringAnimation::setTo(qreal value)
-{
- Q_D(QDeclarativeSpringAnimation);
- if (d->to == value)
- return;
-
- d->to = value;
- d->toDefined = true;
- d->lastTime = 0;
- emit toChanged(value);
+ d->clock = new QDeclarativeSpringAnimationPrivate::Clock(d, this);
}
-qreal QDeclarativeSpringAnimation::from() const
-{
- Q_D(const QDeclarativeSpringAnimation);
- return d->fromDefined ? d->from : 0;
-}
-
-/*!
- \qmlproperty real SpringAnimation::from
-
- This property holds the value from which the animation will begin.
-
- If not set, the animation will start whenever the tracked value has
- changed, regardless of its value.
-*/
-
-void QDeclarativeSpringAnimation::setFrom(qreal value)
+QDeclarativeSpringAnimation::~QDeclarativeSpringAnimation()
{
- Q_D(QDeclarativeSpringAnimation);
- if (d->from == value)
- return;
-
- d->currentValue = d->from = value;
- d->fromDefined = true;
- d->lastTime = 0;
- emit fromChanged(value);
}
-
/*!
\qmlproperty real SpringAnimation::velocity
@@ -452,17 +413,25 @@ void QDeclarativeSpringAnimation::transition(QDeclarativeStateActions &actions,
Q_D(QDeclarativeSpringAnimation);
Q_UNUSED(direction);
- if (d->clock.state() != QAbstractAnimation::Running)
+ if (d->clock->state() != QAbstractAnimation::Running) {
d->lastTime = 0;
+ }
- if (!actions.isEmpty()) {
- for (int i = 0; i < actions.size(); ++i) {
- if (!d->toDefined)
- d->to = actions.at(i).toValue.toReal();
- if (!d->fromDefined)
- d->currentValue = actions.at(i).fromValue.toReal();
- if (d->mode != QDeclarativeSpringAnimationPrivate::Track)
- modified << d->defaultProperty;
+ QDeclarativeNumberAnimation::transition(actions, modified, direction);
+
+ if (!d->actions)
+ return;
+
+ if (!d->actions->isEmpty()) {
+ for (int i = 0; i < d->actions->size(); ++i) {
+ const QDeclarativeProperty &property = d->actions->at(i).property;
+ QDeclarativeSpringAnimationPrivate::SpringAnimation &animation
+ = d->activeAnimations[property];
+ animation.to = d->actions->at(i).toValue.toReal();
+ if (d->fromIsDefined)
+ animation.currentValue = d->actions->at(i).fromValue.toReal();
+ else
+ animation.currentValue = property.read().toReal();
}
}
}
@@ -471,7 +440,7 @@ void QDeclarativeSpringAnimation::transition(QDeclarativeStateActions &actions,
QAbstractAnimation *QDeclarativeSpringAnimation::qtAnimation()
{
Q_D(QDeclarativeSpringAnimation);
- return &d->clock;
+ return d->clock;
}
QT_END_NAMESPACE
diff --git a/src/declarative/util/qdeclarativespringanimation_p.h b/src/declarative/util/qdeclarativespringanimation_p.h
index 6f574ef..ee276ec 100644
--- a/src/declarative/util/qdeclarativespringanimation_p.h
+++ b/src/declarative/util/qdeclarativespringanimation_p.h
@@ -54,14 +54,12 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDeclarativeSpringAnimationPrivate;
-class Q_AUTOTEST_EXPORT QDeclarativeSpringAnimation : public QDeclarativeAbstractAnimation
+class Q_AUTOTEST_EXPORT QDeclarativeSpringAnimation : public QDeclarativeNumberAnimation
{
Q_OBJECT
Q_DECLARE_PRIVATE(QDeclarativeSpringAnimation)
Q_INTERFACES(QDeclarativePropertyValueSource)
- Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged)
- Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged)
Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity)
Q_PROPERTY(qreal spring READ spring WRITE setSpring)
Q_PROPERTY(qreal damping READ damping WRITE setDamping)
@@ -73,14 +71,6 @@ public:
QDeclarativeSpringAnimation(QObject *parent=0);
~QDeclarativeSpringAnimation();
- virtual void setTarget(const QDeclarativeProperty &);
-
- qreal to() const;
- void setTo(qreal value);
-
- qreal from() const;
- void setFrom(qreal value);
-
qreal velocity() const;
void setVelocity(qreal velocity);
@@ -99,9 +89,6 @@ public:
qreal modulus() const;
void setModulus(qreal modulus);
- bool enabled() const;
- void setEnabled(bool enabled);
-
virtual void transition(QDeclarativeStateActions &actions,
QDeclarativeProperties &modified,
TransitionDirection direction);
@@ -110,8 +97,6 @@ protected:
virtual QAbstractAnimation *qtAnimation();
Q_SIGNALS:
- void toChanged(qreal);
- void fromChanged(qreal);
void modulusChanged();
void massChanged();
void syncChanged();
diff --git a/src/declarative/util/qdeclarativestate.cpp b/src/declarative/util/qdeclarativestate.cpp
index 0d43d21..028bacb 100644
--- a/src/declarative/util/qdeclarativestate.cpp
+++ b/src/declarative/util/qdeclarativestate.cpp
@@ -154,13 +154,14 @@ QDeclarativeStateOperation::QDeclarativeStateOperation(QObjectPrivate &dd, QObje
Notice the default state is referred to using an empty string ("").
- States are commonly used together with \l {state-transitions}{Transitions} to provide
+ States are commonly used together with \l {Transitions} to provide
animations when state changes occur.
\note Setting the state of an object from within another state of the same object is
not allowed.
- \sa {declarative/animation/states}{states example}, {qmlstates}{States}, {state-transitions}{Transitions}, QtDeclarative
+ \sa {declarative/animation/states}{states example}, {qmlstates}{States},
+ {qdeclarativeanimation.html#transitions}{QML Transitions}, QtDeclarative
*/
/*!
diff --git a/src/declarative/util/qdeclarativestategroup.cpp b/src/declarative/util/qdeclarativestategroup.cpp
index 67cd12e..1c1e964 100644
--- a/src/declarative/util/qdeclarativestategroup.cpp
+++ b/src/declarative/util/qdeclarativestategroup.cpp
@@ -112,7 +112,7 @@ public:
}
\endqml
- \sa {qmlstate}{States} {state-transitions}{Transitions}, {QtDeclarative}
+ \sa {qmlstate}{States} {Transitions}, {QtDeclarative}
*/
QDeclarativeStateGroup::QDeclarativeStateGroup(QObject *parent)
@@ -204,7 +204,7 @@ void QDeclarativeStateGroupPrivate::clear_states(QDeclarativeListProperty<QDecla
}
\endqml
- \sa {state-transitions}{Transitions}
+ \sa {Transitions}
*/
QDeclarativeListProperty<QDeclarativeTransition> QDeclarativeStateGroup::transitionsProperty()
{
diff --git a/src/declarative/util/qdeclarativetransition.cpp b/src/declarative/util/qdeclarativetransition.cpp
index 582191b..aa1426c 100644
--- a/src/declarative/util/qdeclarativetransition.cpp
+++ b/src/declarative/util/qdeclarativetransition.cpp
@@ -60,12 +60,25 @@ QT_BEGIN_NAMESPACE
For example, the following \l Rectangle has two states: the default state, and
an added "moved" state. In the "moved state, the rectangle's position changes
- to (50, 50). The added \l Transition specifies that when the rectangle
+ to (50, 50). The added Transition specifies that when the rectangle
changes between the default and the "moved" state, any changes
to the \c x and \c y properties should be animated, using an \c Easing.InOutQuad.
-
+
\snippet doc/src/snippets/declarative/transition.qml 0
+ Notice the example does not require \l{PropertyAnimation::}{to} and
+ \l{PropertyAnimation::}{from} values for the NumberAnimation. As a convenience,
+ these properties are automatically set to the values of \c x and \c y before
+ and after the state change; the \c from values are provided by
+ the current values of \c x and \c y, and the \c to values are provided by
+ the PropertyChanges object. If you wish, you can provide \l{PropertyAnimation::}{to} and
+ \l{PropertyAnimation::}{from} values anyway to override the default values.
+
+ By default, a Transition's animations are applied for any state change in the
+ parent item. The Transition \l {Transition::}{from} and \l {Transition::}{to}
+ values can be set to restrict the animations to only be applied when changing
+ from one particular state to another.
+
To define multiple transitions, specify \l Item::transitions as a list:
\qml
@@ -78,7 +91,11 @@ QT_BEGIN_NAMESPACE
}
\endqml
- \sa {declarative/animation/states}{states example}, {qmlstates}{States}, {state-transitions}{Transitions}, {QtDeclarative}
+ If a state change has a Transition that matches the same property as a
+ \l Behavior, the Transition animation overrides the \l Behavior for that
+ state change.
+
+ \sa {QML Animation}, {declarative/animation/states}{states example}, {qmlstates}{States}, {QtDeclarative}
*/
/*!
diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp
index 7c1e1fd..ece3d3a 100644
--- a/src/declarative/util/qdeclarativexmllistmodel.cpp
+++ b/src/declarative/util/qdeclarativexmllistmodel.cpp
@@ -560,7 +560,7 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty<QDecla
ListView {
width: 180; height: 300
model: xmlModel
- delegate: Text { text: title + " (" + pubDate + ")" }
+ delegate: Text { text: title + ": " + pubDate }
}
\endqml
@@ -809,7 +809,7 @@ QScriptValue QDeclarativeXmlListModel::get(int index) const
QScriptValue sv = sengine->newObject();
for (int i=0; i<d->roleObjects.count(); i++)
- sv.setProperty(d->roleObjects[i]->name(), qScriptValueFromValue(sengine, d->data.value(i).value(index)));
+ sv.setProperty(d->roleObjects[i]->name(), sengine->toScriptValue(d->data.value(i).value(index)));
return sv;
}
@@ -855,6 +855,12 @@ qreal QDeclarativeXmlListModel::progress() const
return d->progress;
}
+/*!
+ \qmlmethod void XmlListModel::errorString()
+
+ Returns a string description of the last error that occurred
+ if \l status is XmlListModel::Error.
+*/
QString QDeclarativeXmlListModel::errorString() const
{
Q_D(const QDeclarativeXmlListModel);