summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2009-05-19 06:13:17 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2009-05-19 06:13:17 (GMT)
commit38a978121bef0efd1f6fd573c4289e40352b63a6 (patch)
tree8323766cda9f181689098e62f36b9cb4ad089bae
parent2057092a86b049075e50eb3bc934982cec991f9b (diff)
parentda5cb2883e2b0e4a52a0aecba2c82808e64668f8 (diff)
downloadQt-38a978121bef0efd1f6fd573c4289e40352b63a6.zip
Qt-38a978121bef0efd1f6fd573c4289e40352b63a6.tar.gz
Qt-38a978121bef0efd1f6fd573c4289e40352b63a6.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-rw-r--r--doc/src/declarative/elements.qdoc1
-rw-r--r--examples/declarative/dial/DialLibrary/Dial.qml34
-rw-r--r--src/declarative/fx/qfxanchors.cpp4
-rw-r--r--src/declarative/fx/qfxtransform.cpp28
-rw-r--r--src/declarative/fx/qfxtransform.h5
-rw-r--r--tests/auto/declarative/anchors/data/anchors.qml115
-rw-r--r--tests/auto/declarative/anchors/tst_anchors.cpp75
7 files changed, 241 insertions, 21 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/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;
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:
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 <QtDeclarative/qmlengine.h>
#include <QtDeclarative/qmlcomponent.h>
#include <QtDeclarative/qfxview.h>
-#include <QtDeclarative/qfximage.h>
-#include <QtDeclarative/qfxtext.h>
+#include <QtDeclarative/qfxrect.h>
class tst_anchors : public QObject
{
@@ -11,10 +10,82 @@ class tst_anchors : public QObject
public:
tst_anchors() {}
+ template<typename T>
+ T *findItem(QFxItem *parent, const QString &id);
+
private slots:
+ void basicAnchors();
void loops();
};
+/*
+ Find an item with the specified id.
+*/
+template<typename T>
+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<QFxItem*>(parent->QSimpleCanvasItem::children().at(i));
+ if (mo.cast(item) && (id.isEmpty() || item->id() == id)) {
+ return static_cast<T*>(item);
+ }
+ item = findItem<T>(item, id);
+ if (item)
+ return static_cast<T*>(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<QFxRect>(view->root(), QLatin1String("Rect1"))->x(), 26.0);
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect2"))->x(), 122.0);
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect3"))->x(), 74.0);
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect4"))->x(), 16.0);
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect5"))->x(), 112.0);
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect6"))->x(), 64.0);
+
+ //parent horizontal
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect7"))->x(), 0.0);
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect8"))->x(), 240.0);
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect9"))->x(), 120.0);
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect10"))->x(), -10.0);
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect11"))->x(), 230.0);
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect12"))->x(), 110.0);
+
+ //vertical
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect13"))->y(), 20.0);
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect14"))->y(), 155.0);
+
+ //stretch
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect15"))->x(), 26.0);
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect15"))->width(), 96.0);
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect16"))->x(), 26.0);
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect16"))->width(), 192.0);
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect17"))->x(), -70.0);
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect17"))->width(), 192.0);
+
+ //vertical stretch
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect18"))->y(), 20.0);
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect18"))->height(), 40.0);
+
+ //more parent horizontal
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect19"))->x(), 115.0);
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect20"))->x(), 235.0);
+ QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect21"))->x(), -5.0);
+
+ delete view;
+}
+
// mostly testing that we don't crash
void tst_anchors::loops()
{