summaryrefslogtreecommitdiffstats
path: root/src/declarative/util
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-07-02 00:55:49 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-07-02 00:55:49 (GMT)
commitba13a6003d95f9d07f94bdb0e210e0c0453d8b80 (patch)
treed13bf7a0ed2723194a773a3836cf43139471bfa8 /src/declarative/util
parentecd07750a74111ed9ef65a7439ddccc065c5dadc (diff)
parent4e9336d1f60089bffda7fca93a63d18ffce0a6fa (diff)
downloadQt-ba13a6003d95f9d07f94bdb0e210e0c0453d8b80.zip
Qt-ba13a6003d95f9d07f94bdb0e210e0c0453d8b80.tar.gz
Qt-ba13a6003d95f9d07f94bdb0e210e0c0453d8b80.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative/util')
-rw-r--r--src/declarative/util/qmlanimation.cpp39
-rw-r--r--src/declarative/util/qmlanimation.h1
-rw-r--r--src/declarative/util/qmlanimation_p.h4
-rw-r--r--src/declarative/util/qmllistmodel.cpp70
-rw-r--r--src/declarative/util/qmllistmodel.h28
-rw-r--r--src/declarative/util/qmltransition.cpp1
6 files changed, 70 insertions, 73 deletions
diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp
index c4eabfe..6ad47f5 100644
--- a/src/declarative/util/qmlanimation.cpp
+++ b/src/declarative/util/qmlanimation.cpp
@@ -97,13 +97,11 @@ QEasingCurve stringToCurve(const QString &curve)
if (normalizedCurve.startsWith(QLatin1String("ease")))
normalizedCurve = normalizedCurve.mid(4);
- //XXX optimize?
- int index = QEasingCurve::staticMetaObject.indexOfEnumerator("Type");
- QMetaEnum me = QEasingCurve::staticMetaObject.enumerator(index);
+ static int index = QEasingCurve::staticMetaObject.indexOfEnumerator("Type");
+ static QMetaEnum me = QEasingCurve::staticMetaObject.enumerator(index);
int value = me.keyToValue(normalizedCurve.toLatin1().constData());
if (value < 0) {
- //XXX print line number
qWarning("QEasingCurve: Unknown easing curve '%s'",
curve.toLatin1().constData());
value = 0;
@@ -130,7 +128,6 @@ QEasingCurve stringToCurve(const QString &curve)
return easingCurve;
}
- //XXX optimize
if (propName == QLatin1String("amplitude")) {
easingCurve.setAmplitude(propValue);
} else if (propName == QLatin1String("period")) {
@@ -698,15 +695,6 @@ void QmlPauseAnimation::setDuration(int duration)
emit durationChanged(duration);
}
-void QmlPauseAnimation::prepare(QmlMetaProperty &p)
-{
- Q_D(QmlPauseAnimation);
- if (d->userProperty.isNull)
- d->property = p;
- else
- d->property = d->userProperty;
-}
-
QAbstractAnimation *QmlPauseAnimation::qtAnimation()
{
Q_D(QmlPauseAnimation);
@@ -721,6 +709,10 @@ QAbstractAnimation *QmlPauseAnimation::qtAnimation()
\code
ColorAnimation { from: "white"; to: "#c0c0c0"; duration: 100 }
\endcode
+
+ When used in a transition, ColorAnimation will by default animate
+ all properties of type color that are changing. If a property or properties
+ are explicity set for the animation, then those will be used instead.
*/
/*!
\internal
@@ -740,6 +732,7 @@ QmlColorAnimation::QmlColorAnimation(QObject *parent)
d->init();
d->interpolatorType = QMetaType::QColor;
d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
+ d->defaultToInterpolatorType = true;
}
QmlColorAnimation::~QmlColorAnimation()
@@ -1359,17 +1352,9 @@ void QmlSequentialAnimation::transition(QmlStateActions &actions,
d->animations.at(i)->setTarget(d->userProperty);
}
- //XXX removing and readding isn't ideal; we do it to get around the problem mentioned below.
- for (int i = d->ag->animationCount()-1; i >= 0; --i)
- d->ag->takeAnimationAt(i);
-
for (int ii = from; ii < d->animations.count() && ii >= 0; ii += inc) {
d->animations.at(ii)->transition(actions, modified, direction);
- d->ag->addAnimation(d->animations.at(ii)->qtAnimation());
}
-
- //XXX changing direction means all the animations play in reverse, while we only want the ordering reversed.
- //d->ag->setDirection(direction == Backward ? QAbstractAnimation::Backward : QAbstractAnimation::Forward);
}
QML_DEFINE_TYPE(QmlSequentialAnimation,SequentialAnimation)
@@ -1809,8 +1794,11 @@ void QmlPropertyAnimation::transition(QmlStateActions &actions,
int interpolatorType; //for Number/ColorAnimation
int prevInterpolatorType; //for generic
QVariantAnimation::Interpolator interpolator;
+ bool reverse;
void setValue(qreal v)
{
+ if (reverse) //QVariantAnimation sends us 1->0 when reversed, but we are expecting 0->1
+ v = 1 - v;
QmlTimeLineValue::setValue(v);
for (int ii = 0; ii < actions.count(); ++ii) {
Action &action = actions[ii];
@@ -1845,8 +1833,7 @@ void QmlPropertyAnimation::transition(QmlStateActions &actions,
if (!d->propertyName.isEmpty() && !props.contains(d->propertyName))
props.append(d->propertyName);
- /* ### we used to select properties of name 'color' by default for color animations
- props << QLatin1String("color");*/
+ bool useType = (props.isEmpty() && d->defaultToInterpolatorType) ? true : false;
if (d->userProperty.isValid() && props.isEmpty() && !target()) {
props.append(d->userProperty.value.name());
@@ -1856,6 +1843,7 @@ void QmlPropertyAnimation::transition(QmlStateActions &actions,
PropertyUpdater *data = new PropertyUpdater;
data->interpolatorType = d->interpolatorType;
data->interpolator = d->interpolator;
+ data->reverse = direction == Backward ? true : false;
QSet<QObject *> objs;
for (int ii = 0; ii < actions.count(); ++ii) {
@@ -1869,7 +1857,8 @@ void QmlPropertyAnimation::transition(QmlStateActions &actions,
if ((d->filter.isEmpty() || d->filter.contains(obj) || (!same && d->filter.contains(sObj))) &&
(!d->exclude.contains(obj)) && (same || (!d->exclude.contains(sObj))) &&
- (props.contains(propertyName) || (!same && props.contains(sPropertyName))) &&
+ (props.contains(propertyName) || (!same && props.contains(sPropertyName))
+ || (useType && action.property.propertyType() == d->interpolatorType)) &&
(!target() || target() == obj || (!same && target() == sObj))) {
objs.insert(obj);
Action myAction = action;
diff --git a/src/declarative/util/qmlanimation.h b/src/declarative/util/qmlanimation.h
index 12212df..91c1898 100644
--- a/src/declarative/util/qmlanimation.h
+++ b/src/declarative/util/qmlanimation.h
@@ -154,7 +154,6 @@ Q_SIGNALS:
protected:
virtual QAbstractAnimation *qtAnimation();
- virtual void prepare(QmlMetaProperty &);
};
class QmlRunScriptActionPrivate;
diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h
index 051516d..fce5eca 100644
--- a/src/declarative/util/qmlanimation_p.h
+++ b/src/declarative/util/qmlanimation_p.h
@@ -319,7 +319,8 @@ class QmlPropertyAnimationPrivate : public QmlAbstractAnimationPrivate
public:
QmlPropertyAnimationPrivate()
: QmlAbstractAnimationPrivate(), fromSourced(false), fromIsDefined(false), toIsDefined(false),
- interpolatorType(0), interpolator(0), va(0), value(this, &QmlPropertyAnimationPrivate::valueChanged) {}
+ defaultToInterpolatorType(0), interpolatorType(0), interpolator(0), va(0),
+ value(this, &QmlPropertyAnimationPrivate::valueChanged) {}
void init();
@@ -335,6 +336,7 @@ public:
bool fromSourced;
bool fromIsDefined;
bool toIsDefined;
+ bool defaultToInterpolatorType;
int interpolatorType;
QVariantAnimation::Interpolator interpolator;
diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp
index c202a9f..f5f76b0 100644
--- a/src/declarative/util/qmllistmodel.cpp
+++ b/src/declarative/util/qmllistmodel.cpp
@@ -169,31 +169,6 @@ struct ListModelData
*/
-struct ModelNode;
-class ListModel : public QListModelInterface
-{
- Q_OBJECT
-public:
- ListModel(QObject *parent=0);
-
- virtual QList<int> roles() const;
- virtual QString toString(int role) const;
- Q_PROPERTY(int count READ count)
- virtual int count() const;
- virtual QHash<int,QVariant> data(int index, const QList<int> &roles = (QList<int>())) const;
-
-private:
- QVariant valueForNode(ModelNode *) const;
- mutable QStringList roleStrings;
- friend class ListModelParser;
- friend struct ModelNode;
-
- void checkRoles() const;
- void addRole(const QString &) const;
- mutable bool _rolesOk;
- ModelNode *_root;
-};
-
class ModelObject : public QObject
{
Q_OBJECT
@@ -220,9 +195,9 @@ struct ModelNode
QList<QVariant> values;
QHash<QString, ModelNode *> properties;
- ListModel *model() {
+ QmlListModel *model() {
if (!modelCache) {
- modelCache = new ListModel;
+ modelCache = new QmlListModel;
modelCache->_root = this;
}
return modelCache;
@@ -240,7 +215,7 @@ struct ModelNode
return objectCache;
}
- ListModel *modelCache;
+ QmlListModel *modelCache;
ModelObject *objectCache;
};
@@ -249,12 +224,16 @@ ModelObject::ModelObject(ModelNode *node)
{
}
-ListModel::ListModel(QObject *parent)
+QmlListModel::QmlListModel(QObject *parent)
: QListModelInterface(parent), _rolesOk(false), _root(0)
{
}
-void ListModel::checkRoles() const
+QmlListModel::~QmlListModel()
+{
+}
+
+void QmlListModel::checkRoles() const
{
if (_rolesOk)
return;
@@ -270,13 +249,13 @@ void ListModel::checkRoles() const
_rolesOk = true;
}
-void ListModel::addRole(const QString &role) const
+void QmlListModel::addRole(const QString &role) const
{
if (!roleStrings.contains(role))
roleStrings << role;
}
-QList<int> ListModel::roles() const
+QList<int> QmlListModel::roles() const
{
checkRoles();
QList<int> rv;
@@ -285,7 +264,7 @@ QList<int> ListModel::roles() const
return rv;
}
-QString ListModel::toString(int role) const
+QString QmlListModel::toString(int role) const
{
checkRoles();
if (role < roleStrings.count())
@@ -294,7 +273,7 @@ QString ListModel::toString(int role) const
return QString();
}
-QVariant ListModel::valueForNode(ModelNode *node) const
+QVariant QmlListModel::valueForNode(ModelNode *node) const
{
QObject *rv = 0;
@@ -327,7 +306,7 @@ QVariant ListModel::valueForNode(ModelNode *node) const
return QVariant();
}
-QHash<int,QVariant> ListModel::data(int index, const QList<int> &roles) const
+QHash<int,QVariant> QmlListModel::data(int index, const QList<int> &roles) const
{
checkRoles();
QHash<int, QVariant> rv;
@@ -352,13 +331,13 @@ QHash<int,QVariant> ListModel::data(int index, const QList<int> &roles) const
return rv;
}
-int ListModel::count() const
+int QmlListModel::count() const
{
if (!_root) return 0;
return _root->values.count();
}
-class ListModelParser : public QmlCustomParser
+class QmlListModelParser : public QmlCustomParser
{
public:
QByteArray compile(const QList<QmlCustomParserProperty> &, bool *ok);
@@ -366,7 +345,7 @@ public:
void setCustomData(QObject *, const QByteArray &);
};
-bool ListModelParser::compileProperty(const QmlCustomParserProperty &prop, QList<ListInstruction> &instr, QByteArray &data)
+bool QmlListModelParser::compileProperty(const QmlCustomParserProperty &prop, QList<ListInstruction> &instr, QByteArray &data)
{
QList<QVariant> values = prop.assignedValues();
for(int ii = 0; ii < values.count(); ++ii) {
@@ -433,7 +412,7 @@ bool ListModelParser::compileProperty(const QmlCustomParserProperty &prop, QList
return true;
}
-QByteArray ListModelParser::compile(const QList<QmlCustomParserProperty> &customProps, bool *ok)
+QByteArray QmlListModelParser::compile(const QList<QmlCustomParserProperty> &customProps, bool *ok)
{
*ok = true;
QList<ListInstruction> instr;
@@ -470,9 +449,9 @@ QByteArray ListModelParser::compile(const QList<QmlCustomParserProperty> &custom
return rv;
}
-void ListModelParser::setCustomData(QObject *obj, const QByteArray &d)
+void QmlListModelParser::setCustomData(QObject *obj, const QByteArray &d)
{
- ListModel *rv = static_cast<ListModel *>(obj);
+ QmlListModel *rv = static_cast<QmlListModel *>(obj);
ModelNode *root = new ModelNode;
rv->_root = root;
@@ -518,14 +497,14 @@ void ListModelParser::setCustomData(QObject *obj, const QByteArray &d)
}
}
-QML_DEFINE_CUSTOM_TYPE(ListModel, ListModel, ListModelParser)
+QML_DEFINE_CUSTOM_TYPE(QmlListModel, ListModel, QmlListModelParser)
// ### FIXME
-class ListElement : public QObject
+class QmlListElement : public QObject
{
Q_OBJECT
};
-QML_DEFINE_TYPE(ListElement,ListElement)
+QML_DEFINE_TYPE(QmlListElement,ListElement)
static void dump(ModelNode *node, int ind)
{
@@ -566,7 +545,6 @@ ModelNode::~ModelNode()
QT_END_NAMESPACE
Q_DECLARE_METATYPE(ModelNode *)
-QML_DECLARE_TYPE(ListModel)
-QML_DECLARE_TYPE(ListElement)
+QML_DECLARE_TYPE(QmlListElement)
#include "qmllistmodel.moc"
diff --git a/src/declarative/util/qmllistmodel.h b/src/declarative/util/qmllistmodel.h
index 56ed8fb..39edbe4 100644
--- a/src/declarative/util/qmllistmodel.h
+++ b/src/declarative/util/qmllistmodel.h
@@ -57,9 +57,37 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
+struct ModelNode;
+class QmlListModel : public QListModelInterface
+{
+ Q_OBJECT
+ Q_PROPERTY(int count READ count)
+
+public:
+ QmlListModel(QObject *parent=0);
+ ~QmlListModel();
+
+ virtual QList<int> roles() const;
+ virtual QString toString(int role) const;
+ virtual int count() const;
+ virtual QHash<int,QVariant> data(int index, const QList<int> &roles = (QList<int>())) const;
+
+private:
+ QVariant valueForNode(ModelNode *) const;
+ mutable QStringList roleStrings;
+ friend class QmlListModelParser;
+ friend struct ModelNode;
+
+ void checkRoles() const;
+ void addRole(const QString &) const;
+ mutable bool _rolesOk;
+ ModelNode *_root;
+};
QT_END_NAMESPACE
+QML_DECLARE_TYPE(QmlListModel)
+
QT_END_HEADER
#endif // QMLLISTMODEL_H
diff --git a/src/declarative/util/qmltransition.cpp b/src/declarative/util/qmltransition.cpp
index ccd0293..d793c7d 100644
--- a/src/declarative/util/qmltransition.cpp
+++ b/src/declarative/util/qmltransition.cpp
@@ -177,6 +177,7 @@ void QmlTransition::prepare(QmlStateOperation::ActionList &actions,
}
d->endState = endState;
+ d->group->setDirection(d->reversed ? QAbstractAnimation::Backward : QAbstractAnimation::Forward);
d->group->start();
}