diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2009-07-24 00:06:42 (GMT) |
---|---|---|
committer | Alan Alpert <alan.alpert@nokia.com> | 2009-07-24 00:06:42 (GMT) |
commit | 8ba5e3b86984fce9fd3999d643cad6a732653940 (patch) | |
tree | d6cd1e14f0e5121d82f6d4202616f197913147a4 /src/declarative | |
parent | 8a67aa7d4397bf0fb2d24724c0d3588136f3c93e (diff) | |
parent | f2a0676485522b58e38b74b76d039611d6baa965 (diff) | |
download | Qt-8ba5e3b86984fce9fd3999d643cad6a732653940.zip Qt-8ba5e3b86984fce9fd3999d643cad6a732653940.tar.gz Qt-8ba5e3b86984fce9fd3999d643cad6a732653940.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/fx/qfxanchors.h | 27 | ||||
-rw-r--r-- | src/declarative/fx/qfxitem.h | 28 | ||||
-rw-r--r-- | src/declarative/fx/qfxitem_p.h | 1 | ||||
-rw-r--r-- | src/declarative/util/qmlstate.cpp | 28 | ||||
-rw-r--r-- | src/declarative/util/qmlstate.h | 9 | ||||
-rw-r--r-- | src/declarative/util/qmlstateoperations.cpp | 241 | ||||
-rw-r--r-- | src/declarative/util/qmlstateoperations.h | 49 | ||||
-rw-r--r-- | src/declarative/util/qmltransitionmanager.cpp | 46 |
8 files changed, 392 insertions, 37 deletions
diff --git a/src/declarative/fx/qfxanchors.h b/src/declarative/fx/qfxanchors.h index dcd5d79..c11080c 100644 --- a/src/declarative/fx/qfxanchors.h +++ b/src/declarative/fx/qfxanchors.h @@ -45,6 +45,7 @@ #include <QtCore/QObject> #include <QtDeclarative/qfxglobal.h> #include <QtDeclarative/qml.h> +#include <QtDeclarative/qfxitem.h> QT_BEGIN_HEADER @@ -52,31 +53,6 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QFxItem; -class QFxAnchorLine -{ -public: - QFxAnchorLine() : item(0), anchorLine(Invalid) - { - } - - enum AnchorLine { - Invalid = 0x0, - Left = 0x01, - Right = 0x02, - Top = 0x04, - Bottom = 0x08, - HCenter = 0x10, - VCenter = 0x20, - Baseline = 0x40, - Horizontal_Mask = Left | Right | HCenter, - Vertical_Mask = Top | Bottom | VCenter | Baseline - }; - - QFxItem *item; - AnchorLine anchorLine; -}; - class QFxAnchorsPrivate; class Q_DECLARATIVE_EXPORT QFxAnchors : public QObject { @@ -184,6 +160,7 @@ private: Q_DISABLE_COPY(QFxAnchors) Q_DECLARE_PRIVATE(QFxAnchors) }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QFxAnchors::UsedAnchors) QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h index e3f371e..a75bdcd 100644 --- a/src/declarative/fx/qfxitem.h +++ b/src/declarative/fx/qfxitem.h @@ -45,7 +45,6 @@ #include <QtCore/QObject> #include <QtScript/qscriptvalue.h> #include <QtCore/QList> -#include <QtDeclarative/qfxanchors.h> #include <QtDeclarative/qfxglobal.h> #include <QtDeclarative/qml.h> #include <QtDeclarative/qmlcomponent.h> @@ -58,6 +57,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) +class QFxItem; class Q_DECLARATIVE_EXPORT QFxContents : public QObject { Q_OBJECT @@ -85,12 +85,36 @@ private: qreal m_height; qreal m_width; }; -Q_DECLARE_OPERATORS_FOR_FLAGS(QFxAnchors::UsedAnchors) + +class QFxAnchorLine +{ +public: + QFxAnchorLine() : item(0), anchorLine(Invalid) + { + } + + enum AnchorLine { + Invalid = 0x0, + Left = 0x01, + Right = 0x02, + Top = 0x04, + Bottom = 0x08, + HCenter = 0x10, + VCenter = 0x20, + Baseline = 0x40, + Horizontal_Mask = Left | Right | HCenter, + Vertical_Mask = Top | Bottom | VCenter | Baseline + }; + + QFxItem *item; + AnchorLine anchorLine; +}; class QmlState; class QmlTransition; class QFxTransform; class QFxKeyEvent; +class QFxAnchors; class QFxItemPrivate; class Q_DECLARATIVE_EXPORT QFxItem : public QGraphicsObject, public QmlParserStatus { diff --git a/src/declarative/fx/qfxitem_p.h b/src/declarative/fx/qfxitem_p.h index 029b8b0..bb3a97a 100644 --- a/src/declarative/fx/qfxitem_p.h +++ b/src/declarative/fx/qfxitem_p.h @@ -55,6 +55,7 @@ #include <QtDeclarative/qfxitem.h> #include <QtDeclarative/qmlstate.h> +#include <QtDeclarative/qfxanchors.h> #include <private/qmlnullablevalue_p.h> #include <QtDeclarative/qml.h> #include <QtDeclarative/qmlcontext.h> diff --git a/src/declarative/util/qmlstate.cpp b/src/declarative/util/qmlstate.cpp index a5fe8a7..c41c31a 100644 --- a/src/declarative/util/qmlstate.cpp +++ b/src/declarative/util/qmlstate.cpp @@ -92,6 +92,24 @@ void ActionEvent::reverse() { } +QList<Action> ActionEvent::extraActions() +{ + return QList<Action>(); +} + +bool ActionEvent::changesBindings() +{ + return false; +} + +void ActionEvent::clearForwardBindings() +{ +} + +void ActionEvent::clearReverseBindings() +{ +} + /*! \internal */ @@ -399,10 +417,12 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever // 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) { - const Action &action = applyList.at(jj); - if (action.property == d->revertList.at(ii).property) - found = true; + if (!d->revertList.at(ii).event) { //### corresponding test for events? + for (int jj = 0; !found && jj < applyList.count(); ++jj) { + const Action &action = applyList.at(jj); + if (action.property == d->revertList.at(ii).property) + found = true; + } } if (!found) { QVariant cur = d->revertList.at(ii).property.read(); diff --git a/src/declarative/util/qmlstate.h b/src/declarative/util/qmlstate.h index e453446..7b3021b 100644 --- a/src/declarative/util/qmlstate.h +++ b/src/declarative/util/qmlstate.h @@ -73,6 +73,7 @@ public: QmlBinding *toBinding; ActionEvent *event; + //strictly for matching QObject *specifiedObject; QString specifiedProperty; @@ -84,9 +85,17 @@ class ActionEvent public: virtual ~ActionEvent(); virtual QString typeName() const; + virtual void execute(); virtual bool isReversable(); virtual void reverse(); + + //virtual bool hasExtraActions(); + virtual QList<Action> extraActions(); + + virtual bool changesBindings(); + virtual void clearForwardBindings(); + virtual void clearReverseBindings(); }; class QmlStateGroup; diff --git a/src/declarative/util/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp index 791628c..e2cbae4 100644 --- a/src/declarative/util/qmlstateoperations.cpp +++ b/src/declarative/util/qmlstateoperations.cpp @@ -272,4 +272,245 @@ QmlRunScript::ActionList QmlRunScript::actions() return rv; } +/*! + \qmlclass SetAnchors + \brief The SetAnchors element allows you to change anchors in a state. +*/ + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,SetAnchors,QmlSetAnchors) + +class QmlSetAnchorsPrivate : public QObjectPrivate +{ +public: + QmlSetAnchorsPrivate() : target(0) {} + + QString name; + QFxItem *target; + QString resetString; + QStringList resetList; + QFxAnchorLine left; + QFxAnchorLine right; + QFxAnchorLine top; + QFxAnchorLine bottom; + QFxAnchorLine origLeft; + QFxAnchorLine origRight; + QFxAnchorLine origTop; + QFxAnchorLine origBottom; + qreal origX; + qreal origY; + qreal origWidth; + qreal origHeight; +}; + +QmlSetAnchors::QmlSetAnchors(QObject *parent) + : QmlStateOperation(*(new QmlSetAnchorsPrivate), parent) +{ +} + +QmlSetAnchors::~QmlSetAnchors() +{ +} + +QmlSetAnchors::ActionList QmlSetAnchors::actions() +{ + Action a; + a.event = this; + return ActionList() << a; +} + +QFxItem *QmlSetAnchors::object() const +{ + Q_D(const QmlSetAnchors); + return d->target; +} + +void QmlSetAnchors::setObject(QFxItem *target) +{ + Q_D(QmlSetAnchors); + d->target = target; +} + +QString QmlSetAnchors::reset() const +{ + Q_D(const QmlSetAnchors); + return d->resetString; +} + +void QmlSetAnchors::setReset(const QString &reset) +{ + Q_D(QmlSetAnchors); + d->resetString = reset; + d->resetList = d->resetString.split(QLatin1Char(',')); +} + +QFxAnchorLine QmlSetAnchors::left() const +{ + Q_D(const QmlSetAnchors); + return d->left; +} + +void QmlSetAnchors::setLeft(const QFxAnchorLine &edge) +{ + Q_D(QmlSetAnchors); + d->left = edge; +} + +QFxAnchorLine QmlSetAnchors::right() const +{ + Q_D(const QmlSetAnchors); + return d->right; +} + +void QmlSetAnchors::setRight(const QFxAnchorLine &edge) +{ + Q_D(QmlSetAnchors); + d->right = edge; +} + +QFxAnchorLine QmlSetAnchors::top() const +{ + Q_D(const QmlSetAnchors); + return d->top; +} + +void QmlSetAnchors::setTop(const QFxAnchorLine &edge) +{ + Q_D(QmlSetAnchors); + d->top = edge; +} + +QFxAnchorLine QmlSetAnchors::bottom() const +{ + Q_D(const QmlSetAnchors); + return d->bottom; +} + +void QmlSetAnchors::setBottom(const QFxAnchorLine &edge) +{ + Q_D(QmlSetAnchors); + d->bottom = edge; +} + +void QmlSetAnchors::execute() +{ + Q_D(QmlSetAnchors); + if (!d->target) + return; + + //set any anchors that have been specified + if (d->left.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->setLeft(d->left); + if (d->right.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->setRight(d->right); + if (d->top.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->setTop(d->top); + if (d->bottom.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->setBottom(d->bottom); +} + +bool QmlSetAnchors::isReversable() +{ + return true; +} + +void QmlSetAnchors::reverse() +{ + Q_D(QmlSetAnchors); + if (!d->target) + return; + + //restore previous anchors + if (d->origLeft.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->setLeft(d->origLeft); + if (d->origRight.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->setRight(d->origRight); + if (d->origTop.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->setTop(d->origTop); + if (d->origBottom.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->setBottom(d->origBottom); + +} + +QString QmlSetAnchors::typeName() const +{ + return QLatin1String("SetAnchors"); +} + +QList<Action> QmlSetAnchors::extraActions() +{ + Q_D(QmlSetAnchors); + QList<Action> extra; + + //### try to be smarter about which ones we add. + // or short-circuit later on if they haven't actually changed. + // we shouldn't set explicit width if there wasn't one before. + if (d->target) { + Action a; + a.fromValue = d->origX; + a.property = QmlMetaProperty(d->target, "x"); + extra << a; + + a.fromValue = d->origY; + a.property = QmlMetaProperty(d->target, "y"); + extra << a; + + a.fromValue = d->origWidth; + a.property = QmlMetaProperty(d->target, "width"); + extra << a; + + a.fromValue = d->origHeight; + a.property = QmlMetaProperty(d->target, "height"); + extra << a; + } + + return extra; +} + +bool QmlSetAnchors::changesBindings() +{ + return true; +} + +void QmlSetAnchors::clearForwardBindings() +{ + Q_D(QmlSetAnchors); + d->origLeft = d->target->anchors()->left(); + d->origRight = d->target->anchors()->right(); + d->origTop = d->target->anchors()->top(); + d->origBottom = d->target->anchors()->bottom(); + d->origX = d->target->x(); + d->origY = d->target->y(); + d->origWidth = d->target->width(); + d->origHeight = d->target->height(); + + //reset any anchors that have been specified + if (d->resetList.contains(QLatin1String("left"))) + d->target->anchors()->resetLeft(); + if (d->resetList.contains(QLatin1String("right"))) + d->target->anchors()->resetRight(); + if (d->resetList.contains(QLatin1String("top"))) + d->target->anchors()->resetTop(); + if (d->resetList.contains(QLatin1String("bottom"))) + d->target->anchors()->resetBottom(); +} + +void QmlSetAnchors::clearReverseBindings() +{ + Q_D(QmlSetAnchors); + d->origX = d->target->x(); + d->origY = d->target->y(); + d->origWidth = d->target->width(); + d->origHeight = d->target->height(); + + //reset any anchors that were set in the state + if (d->left.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->resetLeft(); + if (d->right.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->resetRight(); + if (d->top.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->resetTop(); + if (d->bottom.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->resetBottom(); +} + QT_END_NAMESPACE diff --git a/src/declarative/util/qmlstateoperations.h b/src/declarative/util/qmlstateoperations.h index 67cd1cf..f595e16 100644 --- a/src/declarative/util/qmlstateoperations.h +++ b/src/declarative/util/qmlstateoperations.h @@ -44,6 +44,7 @@ #include <QtDeclarative/qmlstate.h> #include <QtDeclarative/qfxitem.h> +#include <QtDeclarative/qfxanchors.h> QT_BEGIN_HEADER @@ -101,10 +102,58 @@ public: virtual void execute(); }; +class QmlSetAnchorsPrivate; +class Q_DECLARATIVE_EXPORT QmlSetAnchors : public QmlStateOperation, public ActionEvent +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlSetAnchors) + + Q_PROPERTY(QFxItem *target READ object WRITE setObject) + Q_PROPERTY(QString reset READ reset WRITE setReset) + Q_PROPERTY(QFxAnchorLine left READ left WRITE setLeft) + Q_PROPERTY(QFxAnchorLine right READ right WRITE setRight) + Q_PROPERTY(QFxAnchorLine top READ top WRITE setTop) + Q_PROPERTY(QFxAnchorLine bottom READ bottom WRITE setBottom) + +public: + QmlSetAnchors(QObject *parent=0); + ~QmlSetAnchors(); + + virtual ActionList actions(); + + QFxItem *object() const; + void setObject(QFxItem *); + + QString reset() const; + void setReset(const QString &); + + QFxAnchorLine left() const; + void setLeft(const QFxAnchorLine &edge); + + QFxAnchorLine right() const; + void setRight(const QFxAnchorLine &edge); + + QFxAnchorLine top() const; + void setTop(const QFxAnchorLine &edge); + + QFxAnchorLine bottom() const; + void setBottom(const QFxAnchorLine &edge); + + virtual void execute(); + virtual bool isReversable(); + virtual void reverse(); + virtual QString typeName() const; + virtual QList<Action> extraActions(); + virtual bool changesBindings(); + virtual void clearForwardBindings(); + virtual void clearReverseBindings(); +}; + QT_END_NAMESPACE QML_DECLARE_TYPE(QmlParentChange) QML_DECLARE_TYPE(QmlRunScript) +QML_DECLARE_TYPE(QmlSetAnchors) QT_END_HEADER diff --git a/src/declarative/util/qmltransitionmanager.cpp b/src/declarative/util/qmltransitionmanager.cpp index 4609de8..b2d9414 100644 --- a/src/declarative/util/qmltransitionmanager.cpp +++ b/src/declarative/util/qmltransitionmanager.cpp @@ -95,7 +95,13 @@ void QmlTransitionManagerPrivate::applyBindings() if (action.toBinding) { action.property.setBinding(action.toBinding); action.toBinding->forceUpdate(); + } else if (action.event) { + if (action.reverseEvent) + action.event->reverse(); + else + action.event->execute(); } + } bindingsList.clear(); @@ -113,6 +119,13 @@ void QmlTransitionManager::transition(const QList<Action> &list, d->bindingsList << action; if (action.fromBinding) action.property.setBinding(0); // Disable current binding + if (action.event && action.event->changesBindings()) { //### assume isReversable()? + d->bindingsList << action; + if (action.reverseEvent) + action.event->clearReverseBindings(); + else + action.event->clearForwardBindings(); + } } // Animated transitions need both the start and the end value for @@ -126,13 +139,22 @@ void QmlTransitionManager::transition(const QList<Action> &list, if (!d->bindingsList.isEmpty()) { + //### do extra actions here? + // Apply all the property and binding changes - foreach(const Action &action, applyList) { + for (int ii = 0; ii < applyList.size(); ++ii) { + const Action &action = applyList.at(ii); if (action.toBinding) { action.property.setBinding(action.toBinding); action.toBinding->forceUpdate(); } else if (!action.event) { action.property.write(action.toValue); + } else if (action.event->isReversable()) { + if (action.reverseEvent) + action.event->reverse(); + else + action.event->execute(); + applyList << action.event->extraActions(); } } @@ -141,16 +163,28 @@ void QmlTransitionManager::transition(const QList<Action> &list, Action *action = &applyList[ii]; if (action->event) continue; - const QmlMetaProperty &prop = action->property; - if (action->toBinding) + if (action->toBinding || !action->toValue.isValid()) { //### is this always right (used for exta actions) action->toValue = prop.read(); + } } // Revert back to the original values foreach(const Action &action, applyList) { - if (action.event) + if (action.event) { + if (action.event->isReversable()) { + if (action.reverseEvent) { //reverse the reverse + action.event->clearForwardBindings(); + action.event->execute(); + action.event->clearReverseBindings(); + } else { + action.event->clearReverseBindings(); + action.event->reverse(); + action.event->clearForwardBindings(); + } + } continue; + } if (action.toBinding) action.property.setBinding(0); // Make sure this is disabled during the transition @@ -195,12 +229,12 @@ void QmlTransitionManager::transition(const QList<Action> &list, // applied at the end in applyBindings() to avoid any nastiness mid // transition foreach(const Action &action, applyList) { - if (action.event) { + if (action.event && !action.event->changesBindings()) { if (action.event->isReversable() && action.reverseEvent) action.event->reverse(); else action.event->execute(); - } else { + } else if (!action.event) { action.property.write(action.toValue); } } |