diff options
-rw-r--r-- | examples/declarative/border-image/MyBorderImage.qml | 13 | ||||
-rw-r--r-- | examples/declarative/border-image/animated.qml | 12 | ||||
-rw-r--r-- | examples/declarative/border-image/example.qml | 8 | ||||
-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 |
6 files changed, 76 insertions, 23 deletions
diff --git a/examples/declarative/border-image/MyBorderImage.qml b/examples/declarative/border-image/MyBorderImage.qml index f9531df..395b648 100644 --- a/examples/declarative/border-image/MyBorderImage.qml +++ b/examples/declarative/border-image/MyBorderImage.qml @@ -1,9 +1,9 @@ import Qt 4.6 Item { - property var horizontalMode : "Stretch" - property var verticalMode : "Stretch" - property string source + property var horizontalMode : BorderImage.Stretch + property var verticalMode : BorderImage.Stretch + property alias source: MyImage.source property int minWidth property int minHeight property int maxWidth @@ -13,19 +13,20 @@ Item { id: Container width: 240; height: 240 BorderImage { - x: Container.width / 2 - width / 2 - y: Container.height / 2 - height / 2 + id: MyImage; x: Container.width / 2 - width / 2; y: Container.height / 2 - height / 2 + width: SequentialAnimation { running: true; repeat: true NumberAnimation { from: Container.minWidth; to: Container.maxWidth; duration: 2000; easing: "easeInOutQuad"} NumberAnimation { from: Container.maxWidth; to: Container.minWidth; duration: 2000; easing: "easeInOutQuad" } } + height: SequentialAnimation { running: true; repeat: true NumberAnimation { from: Container.minHeight; to: Container.maxHeight; duration: 2000; easing: "easeInOutQuad"} NumberAnimation { from: Container.maxHeight; to: Container.minHeight; duration: 2000; easing: "easeInOutQuad" } } - source: Container.source + horizontalTileMode: Container.horizontalMode verticalTileMode: Container.verticalMode border.top: Container.margin diff --git a/examples/declarative/border-image/animated.qml b/examples/declarative/border-image/animated.qml index 2fe2ea9..b34753f 100644 --- a/examples/declarative/border-image/animated.qml +++ b/examples/declarative/border-image/animated.qml @@ -14,19 +14,19 @@ Rectangle { x: 270; y: 20; minWidth: 120; maxWidth: 240 minHeight: 120; maxHeight: 240 source: "colors.png"; margin: 30 - horizontalMode: "Repeat"; verticalMode: "Repeat" + horizontalMode: BorderImage.Repeat; verticalMode: BorderImage.Repeat } MyBorderImage { x: 520; y: 20; minWidth: 120; maxWidth: 240 minHeight: 120; maxHeight: 240 source: "colors.png"; margin: 30 - horizontalMode: "Stretch"; verticalMode: "Repeat" + horizontalMode: BorderImage.Stretch; verticalMode: BorderImage.Repeat } MyBorderImage { x: 770; y: 20; minWidth: 120; maxWidth: 240 minHeight: 120; maxHeight: 240 source: "colors.png"; margin: 30 - horizontalMode: "Round"; verticalMode: "Round" + horizontalMode: BorderImage.Round; verticalMode: BorderImage.Round } MyBorderImage { x: 20; y: 280; minWidth: 60; maxWidth: 200 @@ -37,18 +37,18 @@ Rectangle { x: 270; y: 280; minWidth: 60; maxWidth: 200 minHeight: 40; maxHeight: 200 source: "bw.png"; margin: 10 - horizontalMode: "Repeat"; verticalMode: "Repeat" + horizontalMode: BorderImage.Repeat; verticalMode: BorderImage.Repeat } MyBorderImage { x: 520; y: 280; minWidth: 60; maxWidth: 200 minHeight: 40; maxHeight: 200 source: "bw.png"; margin: 10 - horizontalMode: "Stretch"; verticalMode: "Repeat" + horizontalMode: BorderImage.Stretch; verticalMode: BorderImage.Repeat } MyBorderImage { x: 770; y: 280; minWidth: 60; maxWidth: 200 minHeight: 40; maxHeight: 200 source: "bw.png"; margin: 10 - horizontalMode: "Round"; verticalMode: "Round" + horizontalMode: BorderImage.Round; verticalMode: BorderImage.Round } } diff --git a/examples/declarative/border-image/example.qml b/examples/declarative/border-image/example.qml index 87d3f37..a0b02b7 100644 --- a/examples/declarative/border-image/example.qml +++ b/examples/declarative/border-image/example.qml @@ -13,8 +13,8 @@ Rectangle { width: 180; height: 180 border.left: 30; border.top: 30 border.right: 30; border.bottom: 30 - horizontalTileMode: "Stretch" - verticalTileMode: "Stretch" + horizontalTileMode: BorderImage.Stretch + verticalTileMode: BorderImage.Stretch source: "colors.png" } @@ -22,8 +22,8 @@ Rectangle { width: 180; height: 180 border.left: 30; border.top: 30 border.right: 30; border.bottom: 30 - horizontalTileMode: "Round" - verticalTileMode: "Round" + horizontalTileMode: BorderImage.Round + verticalTileMode: BorderImage.Round source: "colors.png" } //! [0] 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(); |