summaryrefslogtreecommitdiffstats
path: root/src/declarative/util/qdeclarativebehavior.cpp
diff options
context:
space:
mode:
authormae <qt-info@nokia.com>2010-07-06 13:41:49 (GMT)
committermae <qt-info@nokia.com>2010-07-07 11:47:17 (GMT)
commitcb406a116bf2237c743ac05882fb06927c70359c (patch)
treee3b9bbe6b62793e24ef7edb0b1c13f234032177c /src/declarative/util/qdeclarativebehavior.cpp
parentf5dca266bbf75abe24f39ac8e4d96796529afd77 (diff)
downloadQt-cb406a116bf2237c743ac05882fb06927c70359c.zip
Qt-cb406a116bf2237c743ac05882fb06927c70359c.tar.gz
Qt-cb406a116bf2237c743ac05882fb06927c70359c.tar.bz2
Added QDeclarativeSpringAnimation
The QDeclarativeSpringAnimation is a replacement for QDeclarativeSpringFollow. The idea is to remove the Follows quickly. Follows used to have an inSync property. In order to provide an alternative mechanism, the commit also fixes the running property for animations which are controlled by a behavior. Previously running would always return false and never change. Now running does change and indicates that the animation is running indeed.
Diffstat (limited to 'src/declarative/util/qdeclarativebehavior.cpp')
-rw-r--r--src/declarative/util/qdeclarativebehavior.cpp27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/declarative/util/qdeclarativebehavior.cpp b/src/declarative/util/qdeclarativebehavior.cpp
index 047993e..4480e75 100644
--- a/src/declarative/util/qdeclarativebehavior.cpp
+++ b/src/declarative/util/qdeclarativebehavior.cpp
@@ -58,7 +58,8 @@ class QDeclarativeBehaviorPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QDeclarativeBehavior)
public:
- QDeclarativeBehaviorPrivate() : animation(0), enabled(true), finalized(false) {}
+ QDeclarativeBehaviorPrivate() : animation(0), enabled(true), finalized(false)
+ , blockRunningChanged(false) {}
QDeclarativeProperty property;
QVariant currentValue;
@@ -66,6 +67,7 @@ public:
QDeclarativeGuard<QDeclarativeAbstractAnimation> animation;
bool enabled;
bool finalized;
+ bool blockRunningChanged;
};
/*!
@@ -132,9 +134,26 @@ void QDeclarativeBehavior::setAnimation(QDeclarativeAbstractAnimation *animation
if (d->animation) {
d->animation->setDefaultTarget(d->property);
d->animation->setDisableUserControl();
+ connect(d->animation->qtAnimation(),
+ SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)),
+ this,
+ SLOT(qtAnimationStateChanged(QAbstractAnimation::State,QAbstractAnimation::State)));
+ connect(this,
+ SIGNAL(qtAnimationRunningChanged(bool)),
+ d->animation,
+ SLOT(behaviorControlRunningChanged(bool)));
}
}
+
+void QDeclarativeBehavior::qtAnimationStateChanged(QAbstractAnimation::State newState,QAbstractAnimation::State)
+{
+ Q_D(QDeclarativeBehavior);
+ if (!d->blockRunningChanged)
+ emit qtAnimationRunningChanged(newState == QAbstractAnimation::Running);
+}
+
+
/*!
\qmlproperty bool Behavior::enabled
Whether the Behavior will be triggered when the property it is tracking changes.
@@ -173,8 +192,11 @@ void QDeclarativeBehavior::write(const QVariant &value)
d->currentValue = d->property.read();
d->targetValue = value;
- if (d->animation->qtAnimation()->duration() != -1)
+ if (d->animation->qtAnimation()->duration() != -1
+ && d->animation->qtAnimation()->state() != QAbstractAnimation::Stopped) {
+ d->blockRunningChanged = true;
d->animation->qtAnimation()->stop();
+ }
QDeclarativeStateOperation::ActionList actions;
QDeclarativeAction action;
@@ -186,6 +208,7 @@ void QDeclarativeBehavior::write(const QVariant &value)
QList<QDeclarativeProperty> after;
d->animation->transition(actions, after, QDeclarativeAbstractAnimation::Forward);
d->animation->qtAnimation()->start();
+ d->blockRunningChanged = false;
if (!after.contains(d->property))
QDeclarativePropertyPrivate::write(d->property, value, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding);
}