summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-08-13 08:34:30 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-08-13 08:35:28 (GMT)
commitb31ba48ffb7ee54949d7a5895de4e18a4e48ee5c (patch)
tree9dd89641040ef21852c0298e2db829efffb4580c /src
parentff14068a565396789bf43d4fbc752a643ebcb357 (diff)
downloadQt-b31ba48ffb7ee54949d7a5895de4e18a4e48ee5c.zip
Qt-b31ba48ffb7ee54949d7a5895de4e18a4e48ee5c.tar.gz
Qt-b31ba48ffb7ee54949d7a5895de4e18a4e48ee5c.tar.bz2
QPropertyAnimation: refactor of the default-value code
Diffstat (limited to 'src')
-rw-r--r--src/corelib/animation/qpropertyanimation.cpp5
-rw-r--r--src/corelib/animation/qvariantanimation.cpp65
-rw-r--r--src/corelib/animation/qvariantanimation_p.h4
3 files changed, 33 insertions, 41 deletions
diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp
index 598e994..51fd387 100644
--- a/src/corelib/animation/qpropertyanimation.cpp
+++ b/src/corelib/animation/qpropertyanimation.cpp
@@ -294,6 +294,11 @@ void QPropertyAnimation::updateState(QAbstractAnimation::State oldState,
// update the default start value
if (oldState == Stopped) {
d->setDefaultStartValue(d->target->property(d->propertyName.constData()));
+ //let's check if we have a start value and an end value
+ if (d->direction == Forward && !startValue().isValid() && !d->defaultStartEndValue.isValid())
+ qWarning("QPropertyAnimation::updateState: starting an animation without start value");
+ if (d->direction == Backward && !endValue().isValid() && !d->defaultStartEndValue.isValid())
+ qWarning("QPropertyAnimation::updateState: starting an animation without end value");
}
} else if (hash.value(key) == this) {
hash.remove(key);
diff --git a/src/corelib/animation/qvariantanimation.cpp b/src/corelib/animation/qvariantanimation.cpp
index e647318..fc11815 100644
--- a/src/corelib/animation/qvariantanimation.cpp
+++ b/src/corelib/animation/qvariantanimation.cpp
@@ -220,52 +220,39 @@ void QVariantAnimationPrivate::updateInterpolator()
*/
void QVariantAnimationPrivate::recalculateCurrentInterval(bool force/*=false*/)
{
- // can't interpolate if we have only 1 key value
- if ((keyValues.count() + (defaultStartValue.isValid() ? 1 : 0)) <=1)
+ // can't interpolate if we don't have at least 2 values
+ if ((keyValues.count() + (defaultStartEndValue.isValid() ? 1 : 0)) < 2)
return;
const qreal progress = easing.valueForProgress(((duration == 0) ? qreal(1) : qreal(currentTime) / qreal(duration)));
- if (force || progress < currentInterval.start.first || progress > currentInterval.end.first) {
+ //0 and 1 are still the boundaries
+ if (force || (currentInterval.start.first > 0 && progress < currentInterval.start.first)
+ || (currentInterval.end.first < 1 && progress > currentInterval.end.first)) {
//let's update currentInterval
QVariantAnimation::KeyValues::const_iterator it = qLowerBound(keyValues.constBegin(),
- keyValues.constEnd(),
- qMakePair(progress, QVariant()),
- animationValueLessThan);
- if (it == keyValues.constEnd()) {
- if (direction == QVariantAnimation::Backward && defaultStartValue.isValid()) {
- --it;
- if (it->first == 1) {
- //we have an end value (item with progress = 1)
- currentInterval.start = *(it-1);
- currentInterval.end = *it;
- } else if (direction == QVariantAnimation::Backward && defaultStartValue.isValid()) {
- //the default start value should be used as the default end value
- currentInterval.start = *it;
- currentInterval.end = qMakePair(qreal(1), defaultStartValue);
- } else {
- ///This should not happen
- }
- }
- } else if (it == keyValues.constBegin()) {
- if (it+1 != keyValues.constEnd() && (it->first == progress || it->first == 0)) {
- //the item pointed to by it is the start element in the range
- //we also test if the current element is for progress 0 (ie the real start) because
- //some easing curves might get the progress below 0.
+ keyValues.constEnd(),
+ qMakePair(progress, QVariant()),
+ animationValueLessThan);
+ if (it == keyValues.constBegin()) {
+ //the item pointed to by it is the start element in the range
+ if (it->first == 0 && keyValues.count() > 1) {
currentInterval.start = *it;
currentInterval.end = *(it+1);
- } else if (defaultStartValue.isValid()) {
- if (direction == QVariantAnimation::Forward) {
- //we should have an end value
- currentInterval.start = qMakePair(qreal(0), defaultStartValue);
- currentInterval.end = *it;
- } else {
- //we should have a start value
- currentInterval.start = *it;
- currentInterval.end = qMakePair(qreal(1), defaultStartValue);
- }
} else {
- ///this should not happen
+ currentInterval.start = qMakePair(qreal(0), defaultStartEndValue);
+ currentInterval.end = *it;
+ }
+ } else if (it == keyValues.constEnd()) {
+ --it; //position the iterator on the last item
+ if (it->first == 1 && keyValues.count() > 1) {
+ //we have an end value (item with progress = 1)
+ currentInterval.start = *(it-1);
+ currentInterval.end = *it;
+ } else {
+ //we use the default end value here
+ currentInterval.start = *it;
+ currentInterval.end = qMakePair(qreal(1), defaultStartEndValue);
}
} else {
currentInterval.start = *(it-1);
@@ -329,9 +316,9 @@ void QVariantAnimationPrivate::setValueAt(qreal step, const QVariant &value)
recalculateCurrentInterval(/*force=*/true);
}
-void QVariantAnimationPrivate::setDefaultStartValue(const QVariant &value)
+void QVariantAnimationPrivate::setDefaultStartEndValue(const QVariant &value)
{
- defaultStartValue = value;
+ defaultStartEndValue = value;
recalculateCurrentInterval(/*force=*/true);
}
diff --git a/src/corelib/animation/qvariantanimation_p.h b/src/corelib/animation/qvariantanimation_p.h
index 9c9d25b..ef57a4c 100644
--- a/src/corelib/animation/qvariantanimation_p.h
+++ b/src/corelib/animation/qvariantanimation_p.h
@@ -76,14 +76,14 @@ public:
return q->d_func();
}
- void setDefaultStartValue(const QVariant &value);
+ void setDefaultStartEndValue(const QVariant &value);
int duration;
QEasingCurve easing;
QVariantAnimation::KeyValues keyValues;
QVariant currentValue;
- QVariant defaultStartValue;
+ QVariant defaultStartEndValue;
//this is used to keep track of the KeyValue interval in which we currently are
struct