From b176adc2665ef4b94f30ba5fd8d85a5913b0bbbb Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 19 May 2009 11:36:49 +1000 Subject: Add missing clearItem() flag --- src/declarative/fx/qfxanchors.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/declarative/fx/qfxanchors.cpp b/src/declarative/fx/qfxanchors.cpp index 826d6c1..3eaf47a 100644 --- a/src/declarative/fx/qfxanchors.cpp +++ b/src/declarative/fx/qfxanchors.cpp @@ -186,8 +186,10 @@ void QFxAnchorsPrivate::clearItem(QFxItem *item) fill = 0; if (centeredIn == item) centeredIn = 0; - if (left.item == item) + if (left.item == item) { left.item = 0; + usedAnchors &= ~QFxAnchors::HasLeftAnchor; + } if (right.item == item) { right.item = 0; usedAnchors &= ~QFxAnchors::HasRightAnchor; -- cgit v0.12 From f9aa68b172ddcaa63e5a1bc4d91649d0734d3b15 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 19 May 2009 14:45:49 +1000 Subject: Add a basic anchoring autotest. --- tests/auto/declarative/anchors/data/anchors.qml | 115 ++++++++++++++++++++++++ tests/auto/declarative/anchors/tst_anchors.cpp | 75 +++++++++++++++- 2 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/anchors/data/anchors.qml diff --git a/tests/auto/declarative/anchors/data/anchors.qml b/tests/auto/declarative/anchors/data/anchors.qml new file mode 100644 index 0000000..6a87390 --- /dev/null +++ b/tests/auto/declarative/anchors/data/anchors.qml @@ -0,0 +1,115 @@ +Rect { + color: "white" + width: 240 + height: 320 + Rect { id: MasterRect; x: 26; width: 96; height: 20; color: "red" } + Rect { + id: Rect1 + y: 20; width: 10; height: 10 + anchors.left: MasterRect.left + } + Rect { + id: Rect2 + y: 20; width: 10; height: 10 + anchors.left: MasterRect.right + } + Rect { + id: Rect3 + y: 20; width: 10; height: 10 + anchors.left: MasterRect.horizontalCenter + } + Rect { + id: Rect4 + y: 30; width: 10; height: 10 + anchors.right: MasterRect.left + } + Rect { + id: Rect5 + y: 30; width: 10; height: 10 + anchors.right: MasterRect.right + } + Rect { + id: Rect6 + y: 30; width: 10; height: 10 + anchors.right: MasterRect.horizontalCenter + } + Rect { + id: Rect7 + y: 50; width: 10; height: 10 + anchors.left: parent.left + } + Rect { + id: Rect8 + y: 50; width: 10; height: 10 + anchors.left: parent.right + } + Rect { + id: Rect9 + y: 50; width: 10; height: 10 + anchors.left: parent.horizontalCenter + } + Rect { + id: Rect10 + y: 60; width: 10; height: 10 + anchors.right: parent.left + } + Rect { + id: Rect11 + y: 60; width: 10; height: 10 + anchors.right: parent.right + } + Rect { + id: Rect12 + y: 60; width: 10; height: 10 + anchors.right: parent.horizontalCenter + } + Rect { + id: Rect13 + x: 200; width: 10; height: 10 + anchors.top: MasterRect.bottom + } + Rect { + id: Rect14 + width: 10; height: 10; color: "steelblue" + anchors.verticalCenter: parent.verticalCenter + } + Rect { + id: Rect15 + y: 200; height: 10 + anchors.left: MasterRect.left + anchors.right: MasterRect.right + } + Rect { + id: Rect16 + y: 220; height: 10 + anchors.left: MasterRect.left + anchors.horizontalCenter: MasterRect.right + } + Rect { + id: Rect17 + y: 240; height: 10 + anchors.right: MasterRect.right + anchors.horizontalCenter: MasterRect.left + } + Rect { + id: Rect18 + x: 180; width: 10 + anchors.top: MasterRect.bottom + anchors.bottom: Rect12.top + } + Rect { + id: Rect19 + y: 70; width: 10; height: 10 + anchors.horizontalCenter: parent.horizontalCenter + } + Rect { + id: Rect20 + y: 70; width: 10; height: 10 + anchors.horizontalCenter: parent.right + } + Rect { + id: Rect21 + y: 70; width: 10; height: 10 + anchors.horizontalCenter: parent.left + } +} diff --git a/tests/auto/declarative/anchors/tst_anchors.cpp b/tests/auto/declarative/anchors/tst_anchors.cpp index 683a7b9..8087d6e 100644 --- a/tests/auto/declarative/anchors/tst_anchors.cpp +++ b/tests/auto/declarative/anchors/tst_anchors.cpp @@ -2,8 +2,7 @@ #include #include #include -#include -#include +#include class tst_anchors : public QObject { @@ -11,10 +10,82 @@ class tst_anchors : public QObject public: tst_anchors() {} + template + T *findItem(QFxItem *parent, const QString &id); + private slots: + void basicAnchors(); void loops(); }; +/* + Find an item with the specified id. +*/ +template +T *tst_anchors::findItem(QFxItem *parent, const QString &id) +{ + const QMetaObject &mo = T::staticMetaObject; + for (int i = 0; i < parent->QSimpleCanvasItem::children().count(); ++i) { + QFxItem *item = qobject_cast(parent->QSimpleCanvasItem::children().at(i)); + if (mo.cast(item) && (id.isEmpty() || item->id() == id)) { + return static_cast(item); + } + item = findItem(item, id); + if (item) + return static_cast(item); + } + + return 0; +} + +void tst_anchors::basicAnchors() +{ + QFxView *view = new QFxView; + view->setUrl(QUrl("file://" SRCDIR "/data/anchors.qml")); + + view->execute(); + qApp->processEvents(); + + //sibling horizontal + QCOMPARE(findItem(view->root(), QLatin1String("Rect1"))->x(), 26.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect2"))->x(), 122.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect3"))->x(), 74.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect4"))->x(), 16.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect5"))->x(), 112.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect6"))->x(), 64.0); + + //parent horizontal + QCOMPARE(findItem(view->root(), QLatin1String("Rect7"))->x(), 0.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect8"))->x(), 240.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect9"))->x(), 120.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect10"))->x(), -10.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect11"))->x(), 230.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect12"))->x(), 110.0); + + //vertical + QCOMPARE(findItem(view->root(), QLatin1String("Rect13"))->y(), 20.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect14"))->y(), 155.0); + + //stretch + QCOMPARE(findItem(view->root(), QLatin1String("Rect15"))->x(), 26.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect15"))->width(), 96.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect16"))->x(), 26.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect16"))->width(), 192.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect17"))->x(), -70.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect17"))->width(), 192.0); + + //vertical stretch + QCOMPARE(findItem(view->root(), QLatin1String("Rect18"))->y(), 20.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect18"))->height(), 40.0); + + //more parent horizontal + QCOMPARE(findItem(view->root(), QLatin1String("Rect19"))->x(), 115.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect20"))->x(), 235.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect21"))->x(), -5.0); + + delete view; +} + // mostly testing that we don't crash void tst_anchors::loops() { -- cgit v0.12 From da5cb2883e2b0e4a52a0aecba2c82808e64668f8 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 19 May 2009 15:27:44 +1000 Subject: Docs and minor fixes for the Rotation element. --- doc/src/declarative/elements.qdoc | 1 + examples/declarative/dial/DialLibrary/Dial.qml | 34 +++++++++++++------------- src/declarative/fx/qfxtransform.cpp | 28 +++++++++++++++++++++ src/declarative/fx/qfxtransform.h | 5 +++- 4 files changed, 50 insertions(+), 18 deletions(-) diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index 976e2f1..3298699 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -140,6 +140,7 @@ The following table lists the Qml elements provided by the Qt Declarative module \o \list +\o \l Rotation \o \l Squish \o \l Rotation3D \endlist diff --git a/examples/declarative/dial/DialLibrary/Dial.qml b/examples/declarative/dial/DialLibrary/Dial.qml index 2e214a8..e3fd382 100644 --- a/examples/declarative/dial/DialLibrary/Dial.qml +++ b/examples/declarative/dial/DialLibrary/Dial.qml @@ -4,26 +4,26 @@ Item { width: 210; height: 210 Image { id: Background; source: "background.svg" } - Item { - x: 104; y: 102 - rotation: Needle.rotation - Image { - source: "needle_shadow.svg" - x: -104; y: -102 + + Image { + source: "needle_shadow.svg" + transform: Rotation { + originX: 104; originY: 102 + angle: NeedleRotation.angle } } - Item { + Image { id: Needle - x: 102; y: 98 - rotation: -130 - rotation: Follow { - spring: 1.4 - damping: .15 - source: Math.min(Math.max(-130, value*2.2 - 130), 133) - } - Image { - source: "needle.svg" - x: -102; y: -98 + source: "needle.svg" + transform: Rotation { + id: NeedleRotation + originX: 102; originY: 98 + angle: -130 + angle: Follow { + spring: 1.4 + damping: .15 + source: Math.min(Math.max(-130, value*2.2 - 130), 133) + } } } Image { source: "overlay.svg" } diff --git a/src/declarative/fx/qfxtransform.cpp b/src/declarative/fx/qfxtransform.cpp index 7b76367..bc59e0a 100644 --- a/src/declarative/fx/qfxtransform.cpp +++ b/src/declarative/fx/qfxtransform.cpp @@ -179,6 +179,20 @@ void QFxAxis::setEndZ(qreal z) emit updated(); } +/*! + \qmlclass Rotation + \brief A Rotation object provides a way to rotate an Item around a point. + + The following example rotates a Rect around its interior point 25, 25: + \qml + Rect { + width: 100; height: 100 + color: "blue" + transform: Rotation { originX: 25; originY: 25; angle: 45} + } + \endqml +*/ + QFxRotation::QFxRotation(QObject *parent) : QFxTransform(parent), _originX(0), _originY(0), _angle(0), _dirty(true) { @@ -188,6 +202,12 @@ QFxRotation::~QFxRotation() { } +/*! + \qmlproperty real Rotation::originX + \qmlproperty real Rotation::originY + + The point to rotate around. +*/ qreal QFxRotation::originX() const { return _originX; @@ -210,6 +230,11 @@ void QFxRotation::setOriginY(qreal oy) update(); } +/*! + \qmlproperty real Rotation::angle + + The angle, in degrees, to rotate. +*/ qreal QFxRotation::angle() const { return _angle; @@ -217,8 +242,11 @@ qreal QFxRotation::angle() const void QFxRotation::setAngle(qreal angle) { + if (_angle == angle) + return; _angle = angle; update(); + emit angleChanged(); } bool QFxRotation::isIdentity() const diff --git a/src/declarative/fx/qfxtransform.h b/src/declarative/fx/qfxtransform.h index a3a1a83..2e17ed5 100644 --- a/src/declarative/fx/qfxtransform.h +++ b/src/declarative/fx/qfxtransform.h @@ -115,7 +115,7 @@ class Q_DECLARATIVE_EXPORT QFxRotation : public QFxTransform Q_PROPERTY(qreal originX READ originX WRITE setOriginX) Q_PROPERTY(qreal originY READ originY WRITE setOriginY) - Q_PROPERTY(qreal angle READ angle WRITE setAngle) + Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged()) public: QFxRotation(QObject *parent=0); ~QFxRotation(); @@ -132,6 +132,9 @@ public: virtual bool isIdentity() const; virtual QSimpleCanvas::Matrix transform() const; +Q_SIGNALS: + void angleChanged(); + private Q_SLOTS: void update(); private: -- cgit v0.12