diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-06-26 02:28:34 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-06-26 02:28:34 (GMT) |
commit | afa4e61b10187102d3ea49d1c11bae1ef919d94d (patch) | |
tree | 7890eb2f3194de2b9a2ca7ed6fd0227f7b92fa36 | |
parent | ffc9e62cbf7e24cd04a1202de1b3e618f9e12642 (diff) | |
parent | 5b52c348243e6459cc7faa4ee76a23c7fadcd299 (diff) | |
download | Qt-afa4e61b10187102d3ea49d1c11bae1ef919d94d.zip Qt-afa4e61b10187102d3ea49d1c11bae1ef919d94d.tar.gz Qt-afa4e61b10187102d3ea49d1c11bae1ef919d94d.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-rw-r--r-- | examples/declarative/states/states.qml | 12 | ||||
-rw-r--r-- | examples/declarative/states/transitions.qml | 12 | ||||
-rw-r--r-- | examples/declarative/tutorials/helloworld/t3/tutorial3.qml | 11 | ||||
-rw-r--r-- | src/declarative/extra/qmltimer.cpp | 22 | ||||
-rw-r--r-- | src/declarative/extra/qmltimer.h | 7 | ||||
-rw-r--r-- | src/declarative/fx/qfxgridview.cpp | 4 | ||||
-rw-r--r-- | src/declarative/qml/qmlcompiler.cpp | 5 | ||||
-rw-r--r-- | src/declarative/qml/qmlcomponent.cpp | 1 | ||||
-rw-r--r-- | src/declarative/qml/qmldom.cpp | 10 | ||||
-rw-r--r-- | src/declarative/qml/qmldom.h | 1 | ||||
-rw-r--r-- | src/declarative/qml/qmlparser_p.h | 2 | ||||
-rw-r--r-- | src/declarative/util/qmlfollow.cpp | 8 | ||||
-rw-r--r-- | src/declarative/util/qmlstate.cpp | 102 | ||||
-rw-r--r-- | src/declarative/util/qmlstate.h | 23 | ||||
-rw-r--r-- | src/declarative/util/qmlstate_p.h | 29 |
15 files changed, 154 insertions, 95 deletions
diff --git a/examples/declarative/states/states.qml b/examples/declarative/states/states.qml index bcde20c..c7ee172 100644 --- a/examples/declarative/states/states.qml +++ b/examples/declarative/states/states.qml @@ -26,15 +26,21 @@ Rect { // In state 'Position1', change the 'myrect' item x, y to 150, 50. State { name: "Position1" - SetProperty { target: myrect; property: "x"; value: 150 } - SetProperty { target: myrect; property: "y"; value: 50 } + SetProperties { + target: myrect + x: 150 + y: 50 + } }, // In state 'Position2', change y to 100. We do not specify 'x' here - // it will therefore be restored to its default value of 0, if it // had been changed. State { name: "Position2" - SetProperty { target: myrect; property: "y"; value: 200 } + SetProperties { + target: myrect + y: 200 + } } ] } diff --git a/examples/declarative/states/transitions.qml b/examples/declarative/states/transitions.qml index 214f6e2..1a719ed 100644 --- a/examples/declarative/states/transitions.qml +++ b/examples/declarative/states/transitions.qml @@ -26,15 +26,21 @@ Rect { // In state 'Position1', change the 'myrect' item x, y to 150, 50. State { name: "Position1" - SetProperty { target: myrect; property: "x"; value: 150 } - SetProperty { target: myrect; property: "y"; value: 50 } + SetProperties { + target: myrect + x: 150 + y: 50 + } }, // In state 'Position2', change y to 100. We do not specify 'x' here - // it will therefore be restored to its default value of 0, if it // had been changed. State { name: "Position2" - SetProperty { target: myrect; property: "y"; value: 200 } + SetProperties { + target: myrect + y: 200 + } } ] diff --git a/examples/declarative/tutorials/helloworld/t3/tutorial3.qml b/examples/declarative/tutorials/helloworld/t3/tutorial3.qml index 5ea0dd6..f4bce32 100644 --- a/examples/declarative/tutorials/helloworld/t3/tutorial3.qml +++ b/examples/declarative/tutorials/helloworld/t3/tutorial3.qml @@ -14,15 +14,10 @@ Rect { State { name: "down" when: MouseRegion.pressed == true - SetProperty { + SetProperties { target: HelloText - property: "y" - value: 160 - } - SetProperty { - target: HelloText - property: "color" - value: "red" + y: 160 + color: "red" } } ] diff --git a/src/declarative/extra/qmltimer.cpp b/src/declarative/extra/qmltimer.cpp index 0c13c4a..4af83d3 100644 --- a/src/declarative/extra/qmltimer.cpp +++ b/src/declarative/extra/qmltimer.cpp @@ -54,12 +54,12 @@ class QmlTimerPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QmlTimer) public: QmlTimerPrivate() - : interval(1000), running(false), repeating(false), firesOnStart(false) + : interval(1000), running(false), repeating(false), triggeredOnStart(false) , componentComplete(false) {} int interval; bool running; bool repeating; - bool firesOnStart; + bool triggeredOnStart; QPauseAnimation pause; bool componentComplete; }; @@ -98,7 +98,7 @@ QmlTimer::QmlTimer(QObject *parent) /*! \qmlproperty int Timer::interval - Sets the \a interval between triggering. + Sets the \a interval in milliseconds between triggering. */ void QmlTimer::setInterval(int interval) { @@ -165,24 +165,24 @@ void QmlTimer::setRepeating(bool repeating) } /*! - \qmlproperty bool Timer::firesOnStart + \qmlproperty bool Timer::triggeredOnStart - If \a firesOnStart is true, the timer will be triggered immediately + If \a triggeredOnStart is true, the timer will be triggered immediately when started, and subsequently at the specified interval. \sa running */ -bool QmlTimer::firesOnStart() const +bool QmlTimer::triggeredOnStart() const { Q_D(const QmlTimer); - return d->firesOnStart; + return d->triggeredOnStart; } -void QmlTimer::setFiresOnStart(bool firesOnStart) +void QmlTimer::setTriggeredOnStart(bool triggeredOnStart) { Q_D(QmlTimer); - if (d->firesOnStart != firesOnStart) { - d->firesOnStart = firesOnStart; + if (d->triggeredOnStart != triggeredOnStart) { + d->triggeredOnStart = triggeredOnStart; update(); } } @@ -197,7 +197,7 @@ void QmlTimer::update() d->pause.setLoopCount(d->repeating ? -1 : 1); d->pause.setDuration(d->interval); d->pause.start(); - if (d->firesOnStart) { + if (d->triggeredOnStart) { QCoreApplication::removePostedEvents(this, QEvent::MetaCall); QMetaObject::invokeMethod(this, "ticked", Qt::QueuedConnection); } diff --git a/src/declarative/extra/qmltimer.h b/src/declarative/extra/qmltimer.h index 8a94395..8171385 100644 --- a/src/declarative/extra/qmltimer.h +++ b/src/declarative/extra/qmltimer.h @@ -57,10 +57,11 @@ class Q_DECLARATIVE_EXPORT QmlTimer : public QObject, public QmlParserStatus { Q_OBJECT Q_DECLARE_PRIVATE(QmlTimer) + Q_INTERFACES(QmlParserStatus) Q_PROPERTY(int interval READ interval WRITE setInterval) Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged) Q_PROPERTY(bool repeat READ isRepeating WRITE setRepeating) - Q_PROPERTY(bool firesOnStart READ firesOnStart WRITE setFiresOnStart) + Q_PROPERTY(bool triggeredOnStart READ triggeredOnStart WRITE setTriggeredOnStart) public: QmlTimer(QObject *parent=0); @@ -74,8 +75,8 @@ public: bool isRepeating() const; void setRepeating(bool repeating); - bool firesOnStart() const; - void setFiresOnStart(bool firesOnStart); + bool triggeredOnStart() const; + void setTriggeredOnStart(bool triggeredOnStart); protected: void componentComplete(); diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index 0ca9393..a6ffbb9 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -234,6 +234,8 @@ public: int count = columns - 1 - (modelIndex - visibleItems.last()->index - 1) % columns; return visibleItems.last()->colPos() - count * colSize(); } + } else { + return (modelIndex % columns) * colSize(); } return 0; } @@ -252,6 +254,8 @@ public: int rows = col / (columns * colSize()); return visibleItems.last()->rowPos() + rows * rowSize(); } + } else { + return (modelIndex / columns) * rowSize(); } return 0; } diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 8297ac4..cb0c571 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -570,7 +570,10 @@ void QmlCompiler::compileTree(Object *tree) bool QmlCompiler::compileObject(Object *obj, const BindingContext &ctxt) { Q_ASSERT (obj->type != -1); - obj->metatype = output->types.at(obj->type).metaObject(); + const QmlCompiledData::TypeReference &tr = output->types.at(obj->type); + obj->metatype = tr.metaObject(); + if (tr.component) + obj->url = tr.component->url(); if (output->types.at(obj->type).className == "Component") { COMPILE_CHECK(compileComponent(obj, ctxt)); diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index f90af4a..3429813 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -296,6 +296,7 @@ QmlComponent::QmlComponent(QmlEngine *engine, QmlCompiledComponent *cc, int star cc->addref(); d->start = start; d->count = count; + d->url = cc->url; } /*! diff --git a/src/declarative/qml/qmldom.cpp b/src/declarative/qml/qmldom.cpp index be58071..5271dc5 100644 --- a/src/declarative/qml/qmldom.cpp +++ b/src/declarative/qml/qmldom.cpp @@ -791,6 +791,16 @@ int QmlDomObject::length() const return 0; } +// Returns the URL of the type, if it is an external type, or an empty URL if +// not +QUrl QmlDomObject::url() const +{ + if (d && d->object) + return d->object->url; + else + return QUrl(); +} + QmlDomBasicValuePrivate::QmlDomBasicValuePrivate() : value(0) { diff --git a/src/declarative/qml/qmldom.h b/src/declarative/qml/qmldom.h index fde35a8..ab3e39f 100644 --- a/src/declarative/qml/qmldom.h +++ b/src/declarative/qml/qmldom.h @@ -143,6 +143,7 @@ public: int position() const; int length() const; + QUrl url() const; private: friend class QmlDomDocument; friend class QmlDomComponent; diff --git a/src/declarative/qml/qmlparser_p.h b/src/declarative/qml/qmlparser_p.h index a38ce69..78040da 100644 --- a/src/declarative/qml/qmlparser_p.h +++ b/src/declarative/qml/qmlparser_p.h @@ -102,6 +102,8 @@ namespace QmlParser // QmlCompiledData::types array, or -1 if the object is a fetched // object. int type; + // The url of this object if it is an external type. Used by the DOM + QUrl url; // The name of this type QByteArray typeName; // The id assigned to the object (if any). diff --git a/src/declarative/util/qmlfollow.cpp b/src/declarative/util/qmlfollow.cpp index 95e7792..d3b3617 100644 --- a/src/declarative/util/qmlfollow.cpp +++ b/src/declarative/util/qmlfollow.cpp @@ -93,11 +93,11 @@ void QmlFollowPrivate::tick(int time) if (!elapsed) return; if (mode == Spring) { - if (elapsed < 10) // capped at 100fps. + if (elapsed < 16) // capped at 62fps. return; // Real men solve the spring DEs using RK4. // We'll do something much simpler which gives a result that looks fine. - int count = (elapsed+5) / 10; + int count = (elapsed+8) / 16; for (int i = 0; i < count; ++i) { qreal diff = sourceValue - currentValue; velocity = velocity + spring * diff - damping * velocity; @@ -110,14 +110,14 @@ void QmlFollowPrivate::tick(int time) else if (velocity < -maxVelocity) velocity = -maxVelocity; } - currentValue += velocity * 10.0 / 1000.0; + currentValue += velocity * 16.0 / 1000.0; } if (qAbs(velocity) < epsilon && qAbs(sourceValue - currentValue) < epsilon) { velocity = 0.0; currentValue = sourceValue; clock.stop(); } - lastTime = time - (elapsed - count * 10); + lastTime = time - (elapsed - count * 16); } else { qreal moveBy = elapsed * velocityms; qreal diff = sourceValue - currentValue; diff --git a/src/declarative/util/qmlstate.cpp b/src/declarative/util/qmlstate.cpp index abe8301..0574224 100644 --- a/src/declarative/util/qmlstate.cpp +++ b/src/declarative/util/qmlstate.cpp @@ -234,19 +234,6 @@ QmlState &QmlState::operator<<(QmlStateOperation *op) return *this; } -#if 0 -static void dump(const QmlStateOperation::ActionList &list) -{ - if (!QString(getenv("STATE_DEBUG")).isEmpty()) - return; - - for (int ii = 0; ii < list.count(); ++ii) { - const Action &action = list.at(ii); - qWarning() << action.property.object << action.property.name << action.toValue; - } -} -#endif - void QmlStatePrivate::applyBindings() { foreach(const Action &action, bindingsList) { @@ -282,12 +269,16 @@ void QmlStatePrivate::complete() emit q->completed(); } -QmlStateOperation::ActionList QmlStatePrivate::generateActionList(QmlStateGroup *group) const +// Generate a list of actions for this state. This includes coelescing state +// actions that this state "extends" +QmlStateOperation::ActionList +QmlStatePrivate::generateActionList(QmlStateGroup *group) const { QmlStateOperation::ActionList applyList; if (inState) return applyList; + // Prevent "extends" recursion inState = true; if (!extends.isEmpty()) { @@ -336,12 +327,19 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever d->reverting.clear(); d->bindingsList.clear(); - if (revert) - d->revertList = static_cast<QmlStatePrivate*>(revert->d_ptr)->revertList; - QmlStateOperation::RevertActionList additionalReverts; + if (revert) { + QmlStatePrivate *revertPrivate = + static_cast<QmlStatePrivate*>(revert->d_ptr); + d->revertList = revertPrivate->revertList; + revertPrivate->revertList.clear(); + } + // List of actions caused by this state QmlStateOperation::ActionList applyList = d->generateActionList(group); + // List of actions that need to be reverted to roll back (just) this state + QmlStatePrivate::SimpleActionList additionalReverts; + // First add the reverse of all the applyList actions for (int ii = 0; ii < applyList.count(); ++ii) { const Action &action = applyList.at(ii); if (action.event || !action.restore) @@ -353,10 +351,15 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever found = true; } if (!found) { - RevertAction r(action); + // Only need to revert the applyList action if the previous + // state doesn't have a higher priority revert already + SimpleAction r(action); additionalReverts << r; } } + + // Any reverts from a previous state that aren't carried forth + // into this state need to be translated into apply actions for (int ii = 0; ii < d->revertList.count(); ++ii) { bool found = false; for (int jj = 0; !found && jj < applyList.count(); ++jj) { @@ -376,26 +379,41 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever a.bv = d->revertList.at(ii).bv; } applyList << a; + // Store these special reverts in the reverting list d->reverting << d->revertList.at(ii).property; } } + // All the local reverts now become part of the ongoing revertList d->revertList << additionalReverts; - //apply all changes, and work out any ending positions for bindings - //then rewind all changes and proceed as normal - //### 4 foreach loops! - //////////////////////////////////////////////////////////////////// - foreach(const Action &action, applyList) { - if (stateChangeDebug()) - qWarning() << " Action:" << action.property.object() << action.property.name() << action.toValue; + // Output for debugging + if (stateChangeDebug()) { + foreach(const Action &action, applyList) { + qWarning() << " Action:" << action.property.object() + << action.property.name() << action.toValue; + } + } + // Determine which actions are binding changes. + foreach(const Action &action, applyList) { if (action.bv && !action.toBinding.isEmpty()) { d->bindingsList << action; action.bv->clearExpression(); } } + // Animated transitions need both the start and the end value for + // each property change. In the presence of bindings, the end values + // are non-trivial to calculate. As a "best effort" attempt, we first + // apply all the property and binding changes, then read all the actual + // final values, then roll back the changes and proceed as normal. + // + // This doesn't catch everything, and it might be a little fragile in + // some cases - but whatcha going to do? + if (!d->bindingsList.isEmpty()) { + + // Apply all the property and binding changes foreach(const Action &action, applyList) { if (action.bv && !action.toBinding.isEmpty()) { action.bv->setExpression(action.toBinding); @@ -404,6 +422,7 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever } } + // Read all the end values for binding changes for (int ii = 0; ii < applyList.size(); ++ii) { Action *action = &applyList[ii]; if (action->event) @@ -415,6 +434,7 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever } } + // Revert back to the original values foreach(const Action &action, applyList) { if (action.event) continue; @@ -424,36 +444,44 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever action.property.write(action.fromValue); } } - //////////////////////////////////////////////////////////////////// - QmlStateOperation::ActionList modList = applyList; - QList<QmlMetaProperty> touched; + d->completeList.clear(); + if (trans) { + QList<QmlMetaProperty> touched; d->transition = trans; - trans->prepare(modList, touched, this); - for (int ii = 0; ii < modList.count(); ++ii) { - const Action &action = modList.at(ii); + trans->prepare(applyList, touched, this); + + // Modify the action list to remove actions handled in the transition + for (int ii = 0; ii < applyList.count(); ++ii) { + const Action &action = applyList.at(ii); if (action.event) { + if (action.actionDone) { - modList.removeAt(ii); + applyList.removeAt(ii); --ii; } + } else { - if (action.toValue != action.fromValue) { - d->completeList << RevertAction(action, false); - } if (touched.contains(action.property)) { - modList.removeAt(ii); + if (action.toValue != action.fromValue) + d->completeList << SimpleAction(action, + SimpleAction::EndState); + + applyList.removeAt(ii); --ii; } + } } } - foreach(const Action &action, modList) { + // Any actions remaining have not been handled by the transition and should + // be applied immediately + foreach(const Action &action, applyList) { if (action.event) action.event->execute(); else diff --git a/src/declarative/util/qmlstate.h b/src/declarative/util/qmlstate.h index 0b8d82a..59ef812 100644 --- a/src/declarative/util/qmlstate.h +++ b/src/declarative/util/qmlstate.h @@ -79,28 +79,6 @@ public: virtual void execute(); }; -class RevertAction -{ -public: - RevertAction(const Action &a, bool from = true) : bv(0) - { - property = a.property; - if (from) { - value = a.fromValue; - binding = a.fromBinding; - } else { - value = a.toValue; - binding = a.toBinding; - } - bv = a.bv; - } - - QmlMetaProperty property; - QVariant value; - QString binding; - QmlBindableValue *bv; -}; - class QmlStateGroup; class Q_DECLARATIVE_EXPORT QmlStateOperation : public QObject { @@ -109,7 +87,6 @@ public: QmlStateOperation(QObject *parent = 0) : QObject(parent) {} typedef QList<Action> ActionList; - typedef QList<RevertAction> RevertActionList; virtual ActionList actions(); diff --git a/src/declarative/util/qmlstate_p.h b/src/declarative/util/qmlstate_p.h index da8fdcd..7fcbcd7 100644 --- a/src/declarative/util/qmlstate_p.h +++ b/src/declarative/util/qmlstate_p.h @@ -48,6 +48,29 @@ QT_BEGIN_NAMESPACE +class SimpleAction +{ +public: + enum State { StartState, EndState }; + SimpleAction(const Action &a, State state = StartState) : bv(0) + { + property = a.property; + if (state == StartState) { + value = a.fromValue; + binding = a.fromBinding; + } else { + value = a.toValue; + binding = a.toBinding; + } + bv = a.bv; + } + + QmlMetaProperty property; + QVariant value; + QString binding; + QmlBindableValue *bv; +}; + class QmlStatePrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QmlState) @@ -56,13 +79,15 @@ public: QmlStatePrivate() : when(0), transition(0), inState(false), group(0) {} + typedef QList<SimpleAction> SimpleActionList; + QString name; QmlBindableValue *when; QmlConcreteList<QmlStateOperation *> operations; QmlTransition *transition; - QmlStateOperation::RevertActionList revertList; + SimpleActionList revertList; QList<QmlMetaProperty> reverting; - QmlStateOperation::RevertActionList completeList; + SimpleActionList completeList; QmlStateOperation::ActionList bindingsList; QString extends; mutable bool inState; |