diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-10-02 03:13:27 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-10-02 03:13:27 (GMT) |
commit | 6d06a9d19b4e0fc3ec2b7e32a014103c58e93ae0 (patch) | |
tree | 1e66dbe507d235b8e95538881b1ce16a14ffa06c /src/declarative | |
parent | a4fc9805bd1dd8798ccb2918e4dbd3ed8b0ca2f9 (diff) | |
download | Qt-6d06a9d19b4e0fc3ec2b7e32a014103c58e93ae0.zip Qt-6d06a9d19b4e0fc3ec2b7e32a014103c58e93ae0.tar.gz Qt-6d06a9d19b4e0fc3ec2b7e32a014103c58e93ae0.tar.bz2 |
Try to restore stacking order when restoring from a ParentChange.
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/fx/qfxitem.h | 7 | ||||
-rw-r--r-- | src/declarative/util/qmlstateoperations.cpp | 58 | ||||
-rw-r--r-- | src/declarative/util/qmlstateoperations.h | 1 |
3 files changed, 59 insertions, 7 deletions
diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h index b309cb3..30c522f 100644 --- a/src/declarative/fx/qfxitem.h +++ b/src/declarative/fx/qfxitem.h @@ -210,6 +210,13 @@ private: Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxItem) }; +template<typename T> + T qobject_cast(QGraphicsObject *o) +{ + QObject *obj = o; + return qobject_cast<T>(obj); +} + // ### move to QGO template<typename T> T qobject_cast(QGraphicsItem *item) diff --git a/src/declarative/util/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp index 8673bb2..a9a5bd5 100644 --- a/src/declarative/util/qmlstateoperations.cpp +++ b/src/declarative/util/qmlstateoperations.cpp @@ -47,22 +47,24 @@ #include <QtCore/qdebug.h> #include <QtDeclarative/qmlinfo.h> #include <private/qfxanchors_p.h> +#include <private/qfxitem_p.h> QT_BEGIN_NAMESPACE class QmlParentChangePrivate : public QObjectPrivate { public: - QmlParentChangePrivate() : target(0), parent(0), origParent(0) {} + QmlParentChangePrivate() : target(0), parent(0), origParent(0), origStackBefore(0) {} QFxItem *target; QFxItem *parent; - QFxItem *origParent; + QGuard<QFxItem> origParent; + QGuard<QFxItem> origStackBefore; - void doChange(QFxItem *targetParent); + void doChange(QFxItem *targetParent, QFxItem *stackBefore = 0); }; -void QmlParentChangePrivate::doChange(QFxItem *targetParent) +void QmlParentChangePrivate::doChange(QFxItem *targetParent, QFxItem *stackBefore) { if (targetParent && target && target->parentItem()) { QPointF me = target->parentItem()->mapToScene(QPointF(0,0)); @@ -115,6 +117,11 @@ void QmlParentChangePrivate::doChange(QFxItem *targetParent) } else if (target) { target->setParentItem(targetParent); } + + //restore the original stack position. + //### if stackBefore has also been reparented this won't work + if (stackBefore) + target->stackBefore(stackBefore); } /*! @@ -179,11 +186,47 @@ QmlStateOperation::ActionList QmlParentChange::actions() return ActionList() << a; } +class AccessibleFxItem : public QFxItem +{ + Q_OBJECT + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxItem); +public: + int siblingIndex() { + Q_D(QFxItem); + return d->siblingIndex; + } +}; + +void QmlParentChange::saveOriginals() +{ + Q_D(QmlParentChange); + if (!d->target) { + d->origParent = 0; + d->origStackBefore = 0; + return; + } + + d->origParent = d->target->parentItem(); + + //try to determine the items original stack position so we can restore it + if (!d->origParent) + d->origStackBefore = 0; + int siblingIndex = ((AccessibleFxItem*)d->target)->siblingIndex() + 1; + QList<QGraphicsItem*> children = d->origParent->childItems(); + for (int i = 0; i < children.count(); ++i) { + QFxItem *child = qobject_cast<QFxItem*>(children.at(i)); + if (!child) + continue; + if (((AccessibleFxItem*)child)->siblingIndex() == siblingIndex) { + d->origStackBefore = child; + break; + } + } +} + void QmlParentChange::execute() { Q_D(QmlParentChange); - if (d->target) - d->origParent = d->target->parentItem(); d->doChange(d->parent); } @@ -195,7 +238,7 @@ bool QmlParentChange::isReversable() void QmlParentChange::reverse() { Q_D(QmlParentChange); - d->doChange(d->origParent); + d->doChange(d->origParent, d->origStackBefore); } QString QmlParentChange::typeName() const @@ -664,5 +707,6 @@ bool QmlAnchorChanges::override(ActionEvent*other) QT_END_NAMESPACE +#include "qmlstateoperations.moc" #include "moc_qmlstateoperations.cpp" diff --git a/src/declarative/util/qmlstateoperations.h b/src/declarative/util/qmlstateoperations.h index 34aec93..d8132fd 100644 --- a/src/declarative/util/qmlstateoperations.h +++ b/src/declarative/util/qmlstateoperations.h @@ -72,6 +72,7 @@ public: virtual ActionList actions(); + virtual void saveOriginals(); virtual void execute(); virtual bool isReversable(); virtual void reverse(); |