summaryrefslogtreecommitdiffstats
path: root/src/corelib/animation
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
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')
-rw-r--r--src/corelib/animation/qpropertyanimation.cpp11
-rw-r--r--src/corelib/animation/qpropertyanimation_p.h2
-rw-r--r--src/corelib/animation/qvariantanimation.cpp43
-rw-r--r--src/corelib/animation/qvariantanimation_p.h18
4 files changed, 40 insertions, 34 deletions
diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp
index 9a17049..47361a5 100644
--- a/src/corelib/animation/qpropertyanimation.cpp
+++ b/src/corelib/animation/qpropertyanimation.cpp
@@ -110,17 +110,16 @@ void QPropertyAnimationPrivate::updateMetaProperty()
if (!target || propertyName.isEmpty())
return;
- if (hasMetaProperty == 0 && !property.isValid()) {
+ if (!hasMetaProperty && !property.isValid()) {
const QMetaObject *mo = target->metaObject();
propertyIndex = mo->indexOfProperty(propertyName);
if (propertyIndex != -1) {
- hasMetaProperty = 1;
+ hasMetaProperty = true;
property = mo->property(propertyIndex);
propertyType = property.userType();
} else {
if (!target->dynamicPropertyNames().contains(propertyName))
qWarning("QPropertyAnimation: you're trying to animate a non-existing property %s of your QObject", propertyName.constData());
- hasMetaProperty = 2;
}
}
@@ -133,7 +132,7 @@ void QPropertyAnimationPrivate::updateProperty(const QVariant &newValue)
if (!target || state == QAbstractAnimation::Stopped)
return;
- if (hasMetaProperty == 1) {
+ if (hasMetaProperty) {
if (newValue.userType() == propertyType) {
//no conversion is needed, we directly call the QObject::qt_metacall
void *data = const_cast<void*>(newValue.constData());
@@ -216,7 +215,7 @@ void QPropertyAnimation::setTargetObject(QObject *target)
connect(target, SIGNAL(destroyed()), SLOT(_q_targetDestroyed()));
d->target = target;
- d->hasMetaProperty = 0;
+ d->hasMetaProperty = false;
d->updateMetaProperty();
}
@@ -242,7 +241,7 @@ void QPropertyAnimation::setPropertyName(const QByteArray &propertyName)
}
d->propertyName = propertyName;
- d->hasMetaProperty = 0;
+ d->hasMetaProperty = false;
d->updateMetaProperty();
}
diff --git a/src/corelib/animation/qpropertyanimation_p.h b/src/corelib/animation/qpropertyanimation_p.h
index b51d039..a4387dd 100644
--- a/src/corelib/animation/qpropertyanimation_p.h
+++ b/src/corelib/animation/qpropertyanimation_p.h
@@ -78,7 +78,7 @@ public:
int propertyType;
int propertyIndex;
- int hasMetaProperty;
+ bool hasMetaProperty;
QByteArray propertyName;
void updateProperty(const QVariant &);
void updateMetaProperty();
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
diff --git a/src/corelib/animation/qvariantanimation_p.h b/src/corelib/animation/qvariantanimation_p.h
index 0d296db..2c559cf 100644
--- a/src/corelib/animation/qvariantanimation_p.h
+++ b/src/corelib/animation/qvariantanimation_p.h
@@ -67,17 +67,7 @@ class QVariantAnimationPrivate : public QAbstractAnimationPrivate
Q_DECLARE_PUBLIC(QVariantAnimation)
public:
- QVariantAnimationPrivate() : duration(250), hasStartValue(false)
- {
- }
-
- void init()
- {
- //we keep the mask so that we emit valueChanged only when needed (for performance reasons)
- changedSignalMask = (1 << q_func()->metaObject()->indexOfSignal("valueChanged(QVariant)"));
- currentInterval.start.first = currentInterval.end.first = 2; //will force the initial refresh
- interpolator = 0;
- }
+ QVariantAnimationPrivate();
static QVariantAnimationPrivate *get(QVariantAnimation *q)
{
@@ -100,9 +90,9 @@ public:
QVariantAnimation::KeyValue start, end;
} currentInterval;
- mutable QVariantAnimation::Interpolator interpolator;
+ QVariantAnimation::Interpolator interpolator;
- quint32 changedSignalMask;
+ const quint32 changedSignalMask;
void setCurrentValueForProgress(const qreal progress);
void recalculateCurrentInterval(bool force=false);
@@ -110,6 +100,8 @@ public:
QVariant valueAt(qreal step) const;
void convertValues(int t);
+ void updateInterpolator();
+
static QVariantAnimation::Interpolator getInterpolator(int interpolationType);
};