summaryrefslogtreecommitdiffstats
path: root/src/corelib/animation/qvariantanimation.cpp
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-05-27 09:48:20 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-05-27 09:48:57 (GMT)
commit0bcfa7aa496d460c72862369662560c49eb55f17 (patch)
treeec037b77dc2156962722918a9a7a31265770b3f5 /src/corelib/animation/qvariantanimation.cpp
parent00ffd16d367a19f958149b3b4ec5f5c5e6b71f9b (diff)
downloadQt-0bcfa7aa496d460c72862369662560c49eb55f17.zip
Qt-0bcfa7aa496d460c72862369662560c49eb55f17.tar.gz
Qt-0bcfa7aa496d460c72862369662560c49eb55f17.tar.bz2
small refactor to change the interpolator at the same time as the
current interval in the variant animations
Diffstat (limited to 'src/corelib/animation/qvariantanimation.cpp')
-rw-r--r--src/corelib/animation/qvariantanimation.cpp43
1 files changed, 29 insertions, 14 deletions
diff --git a/src/corelib/animation/qvariantanimation.cpp b/src/corelib/animation/qvariantanimation.cpp
index 239add9..e973ec5 100644
--- a/src/corelib/animation/qvariantanimation.cpp
+++ b/src/corelib/animation/qvariantanimation.cpp
@@ -144,6 +144,11 @@ static bool animationValueLessThan(const QVariantAnimation::KeyValue &p1, const
return p1.first < p2.first;
}
+static QVariant defaultInterpolator(const void *, const void *, qreal)
+{
+ return QVariant();
+}
+
template<> Q_INLINE_TEMPLATE QRect _q_interpolate(const QRect &f, const QRect &t, qreal progress)
{
QRect ret;
@@ -174,6 +179,13 @@ template<> Q_INLINE_TEMPLATE QLineF _q_interpolate(const QLineF &f, const QLineF
return QLineF( _q_interpolate(f.p1(), t.p1(), progress), _q_interpolate(f.p2(), t.p2(), progress));
}
+QVariantAnimationPrivate::QVariantAnimationPrivate() : duration(250), hasStartValue(false),
+ interpolator(&defaultInterpolator),
+ changedSignalMask(1 << QVariantAnimation::staticMetaObject.indexOfSignal("valueChanged(QVariant)"))
+{
+ //we keep the mask so that we emit valueChanged only when needed (for performance reasons)
+}
+
void QVariantAnimationPrivate::convertValues(int t)
{
//this ensures that all the keyValues are of type t
@@ -186,7 +198,20 @@ void QVariantAnimationPrivate::convertValues(int t)
currentInterval.end.second.convert(static_cast<QVariant::Type>(t));
//... and the interpolator
- interpolator = 0;
+ updateInterpolator();
+}
+
+void QVariantAnimationPrivate::updateInterpolator()
+{
+ int type = currentInterval.start.second.userType();
+ if (type == currentInterval.end.second.userType())
+ interpolator = getInterpolator(type);
+ else
+ interpolator = 0;
+
+ //we make sure that the interpolator is always set to something
+ if (!interpolator)
+ interpolator = &defaultInterpolator;
}
/*!
@@ -224,6 +249,7 @@ void QVariantAnimationPrivate::recalculateCurrentInterval(bool force/*=false*/)
// update all the values of the currentInterval
currentInterval.start = *itStart;
currentInterval.end = *itEnd;
+ updateInterpolator();
}
}
setCurrentValueForProgress(progress);
@@ -295,7 +321,6 @@ void QVariantAnimationPrivate::setDefaultStartValue(const QVariant &value)
*/
QVariantAnimation::QVariantAnimation(QObject *parent) : QAbstractAnimation(*new QVariantAnimationPrivate, parent)
{
- d_func()->init();
}
/*!
@@ -303,7 +328,6 @@ QVariantAnimation::QVariantAnimation(QObject *parent) : QAbstractAnimation(*new
*/
QVariantAnimation::QVariantAnimation(QVariantAnimationPrivate &dd, QObject *parent) : QAbstractAnimation(dd, parent)
{
- d_func()->init();
}
/*!
@@ -629,15 +653,7 @@ void QVariantAnimation::updateState(QAbstractAnimation::State oldState,
*/
QVariant QVariantAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
{
- Q_D(const QVariantAnimation);
- if (d->interpolator == 0) {
- if (from.userType() == to.userType())
- d->interpolator = QVariantAnimationPrivate::getInterpolator(from.userType());
- if (d->interpolator == 0) //no interpolator found
- return QVariant();
- }
-
- return d->interpolator(from.constData(), to.constData(), progress);
+ return d_func()->interpolator(from.constData(), to.constData(), progress);
}
/*!
@@ -645,9 +661,8 @@ QVariant QVariantAnimation::interpolated(const QVariant &from, const QVariant &t
*/
void QVariantAnimation::updateCurrentTime(int msecs)
{
- Q_D(QVariantAnimation);
Q_UNUSED(msecs);
- d->recalculateCurrentInterval();
+ d_func()->recalculateCurrentInterval();
}
QT_END_NAMESPACE