diff options
author | Justin McPherson <justin.mcpherson@nokia.com> | 2010-02-25 07:28:27 (GMT) |
---|---|---|
committer | Justin McPherson <justin.mcpherson@nokia.com> | 2010-02-25 07:28:27 (GMT) |
commit | 75d61cbd7d2c72abb1fcf486c97bbb7429aea81b (patch) | |
tree | 53554843152f28dea7834e5f3f40f854f51af591 | |
parent | bd7ef8002b008816f5233fdd40742a12e0861b82 (diff) | |
parent | b469289a6ed067be92eb24239c59f5cd1f5f7956 (diff) | |
download | Qt-75d61cbd7d2c72abb1fcf486c97bbb7429aea81b.zip Qt-75d61cbd7d2c72abb1fcf486c97bbb7429aea81b.tar.gz Qt-75d61cbd7d2c72abb1fcf486c97bbb7429aea81b.tar.bz2 |
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt-qml
4 files changed, 81 insertions, 12 deletions
diff --git a/src/declarative/util/qdeclarativepropertychanges.cpp b/src/declarative/util/qdeclarativepropertychanges.cpp index 6c2e256..454fb06 100644 --- a/src/declarative/util/qdeclarativepropertychanges.cpp +++ b/src/declarative/util/qdeclarativepropertychanges.cpp @@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE /*! \qmlclass PropertyChanges QDeclarativePropertyChanges - \since 4.7 + \since 4.7 \brief The PropertyChanges element describes new property values for a state. PropertyChanges provides a state change that modifies the properties of an item. @@ -98,6 +98,33 @@ QT_BEGIN_NAMESPACE } \endqml + You can reset a property in a state change by assigning \c undefined. In the following + example we reset \c theText's width when we enter state1. This will give the text its + natural width (which is the whole string on one line). + + \qml + import Qt 4.6 + + Rectangle { + width: 640 + height: 480 + Text { + id: theText + width: 50 + wrap: true + text: "a text string that is longer than 50 pixels" + } + + states: State { + name: "state1" + PropertyChanges { + target: theText + width: undefined + } + } + } + \endqml + Changes to an Item's parent or anchors should be done using the associated change elements (ParentChange and AnchorChanges, respectively) rather than PropertyChanges. diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp index 6001a84..98edf85 100644 --- a/src/declarative/util/qdeclarativestateoperations.cpp +++ b/src/declarative/util/qdeclarativestateoperations.cpp @@ -80,7 +80,7 @@ void QDeclarativeParentChangePrivate::doChange(QDeclarativeItem *targetParent, Q //### for backwards direction, can we just restore original x, y, scale, rotation Q_Q(QDeclarativeParentChange); bool ok; - const QTransform &transform = target->itemTransform(targetParent, &ok); + const QTransform &transform = target->parentItem()->itemTransform(targetParent, &ok); if (transform.type() >= QTransform::TxShear || !ok) { qmlInfo(q) << QDeclarativeParentChange::tr("Unable to preserve appearance under complex transform"); ok = false; @@ -111,8 +111,9 @@ void QDeclarativeParentChangePrivate::doChange(QDeclarativeItem *targetParent, Q } } - qreal xt = transform.dx(); - qreal yt = transform.dy(); + const QPointF &point = transform.map(QPointF(target->x(),target->y())); + qreal x = point.x(); + qreal y = point.y(); if (ok && target->transformOrigin() != QDeclarativeItem::TopLeft) { qreal tempxt = target->transformOriginPoint().x(); qreal tempyt = target->transformOriginPoint().y(); @@ -121,18 +122,18 @@ void QDeclarativeParentChangePrivate::doChange(QDeclarativeItem *targetParent, Q t.rotate(rotation); t.scale(scale, scale); t.translate(tempxt, tempyt); - QPointF offset = t.map(QPointF(0,0)); - xt += offset.x(); - yt += offset.y(); + const QPointF &offset = t.map(QPointF(0,0)); + x += offset.x(); + y += offset.y(); } target->setParentItem(targetParent); if (ok) { - //qDebug() << xt << yt << rotation << scale; - target->setX(xt); - target->setY(yt); - target->setRotation(rotation); - target->setScale(scale); + //qDebug() << x << y << rotation << scale; + target->setX(x); + target->setY(y); + target->setRotation(target->rotation() + rotation); + target->setScale(target->scale() * scale); } } else if (target) { target->setParentItem(targetParent); diff --git a/tests/auto/declarative/qdeclarativestates/data/reset.qml b/tests/auto/declarative/qdeclarativestates/data/reset.qml new file mode 100644 index 0000000..a0a2b8c --- /dev/null +++ b/tests/auto/declarative/qdeclarativestates/data/reset.qml @@ -0,0 +1,20 @@ +import Qt 4.6 + +Rectangle { + width: 640 + height: 480 + Text { + id: theText + width: 50 + wrap: true + text: "a text string that is longer than 50 pixels" + } + + states: State { + name: "state1" + PropertyChanges { + target: theText + width: undefined + } + } +} diff --git a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp index 44fb51f..5ffce11 100644 --- a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp +++ b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp @@ -43,6 +43,7 @@ #include <QtDeclarative/qdeclarativecomponent.h> #include <private/qdeclarativeanchors_p_p.h> #include <private/qdeclarativerectangle_p.h> +#include <private/qdeclarativetext_p.h> #include <private/qdeclarativepropertychanges_p.h> #include <private/qdeclarativestategroup_p.h> @@ -81,6 +82,7 @@ private slots: void tempState(); void illegalTempState(); void nonExistantProperty(); + void reset(); }; QByteArray tst_qdeclarativestates::fullDataPath(const QString &path) @@ -912,6 +914,25 @@ void tst_qdeclarativestates::nonExistantProperty() QCOMPARE(rect->state(), QLatin1String("blue")); } +void tst_qdeclarativestates::reset() +{ + QDeclarativeEngine engine; + + QDeclarativeComponent c(&engine, SRCDIR "/data/reset.qml"); + QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); + QVERIFY(rect != 0); + + QDeclarativeText *text = rect->findChild<QDeclarativeText*>(); + QVERIFY(text != 0); + QCOMPARE(text->width(), qreal(50.)); + QVERIFY(text->width() < text->height()); + + rect->setState("state1"); + + QVERIFY(text->width() > 51); + QVERIFY(text->width() > text->height()); +} + QTEST_MAIN(tst_qdeclarativestates) #include "tst_qdeclarativestates.moc" |