diff options
Diffstat (limited to 'tests/auto/qtquick1/qdeclarativeanchors')
11 files changed, 0 insertions, 1190 deletions
diff --git a/tests/auto/qtquick1/qdeclarativeanchors/data/anchors.qml b/tests/auto/qtquick1/qdeclarativeanchors/data/anchors.qml deleted file mode 100644 index 9b7c805336..0000000000 --- a/tests/auto/qtquick1/qdeclarativeanchors/data/anchors.qml +++ /dev/null @@ -1,162 +0,0 @@ -import QtQuick 1.0 - -Rectangle { - color: "white" - width: 240 - height: 320 - Rectangle { id: masterRect; objectName: "masterRect"; x: 26; width: 96; height: 20; color: "red" } - Rectangle { - id: rect1; objectName: "rect1" - y: 20; width: 10; height: 10 - anchors.left: masterRect.left - } - Rectangle { - id: rect2; objectName: "rect2" - y: 20; width: 10; height: 10 - anchors.left: masterRect.right - } - Rectangle { - id: rect3; objectName: "rect3" - y: 20; width: 10; height: 10 - anchors.left: masterRect.horizontalCenter - } - Rectangle { - id: rect4; objectName: "rect4" - y: 30; width: 10; height: 10 - anchors.right: masterRect.left - } - Rectangle { - id: rect5; objectName: "rect5" - y: 30; width: 10; height: 10 - anchors.right: masterRect.right - } - Rectangle { - id: rect6; objectName: "rect6" - y: 30; width: 10; height: 10 - anchors.right: masterRect.horizontalCenter - } - Rectangle { - id: rect7; objectName: "rect7" - y: 50; width: 10; height: 10 - anchors.left: parent.left - } - Rectangle { - id: rect8; objectName: "rect8" - y: 50; width: 10; height: 10 - anchors.left: parent.right - } - Rectangle { - id: rect9; objectName: "rect9" - y: 50; width: 10; height: 10 - anchors.left: parent.horizontalCenter - } - Rectangle { - id: rect10; objectName: "rect10" - y: 60; width: 10; height: 10 - anchors.right: parent.left - } - Rectangle { - id: rect11; objectName: "rect11" - y: 60; width: 10; height: 10 - anchors.right: parent.right - } - Rectangle { - id: rect12; objectName: "rect12" - y: 60; width: 10; height: 10 - anchors.right: parent.horizontalCenter - } - Rectangle { - id: rect13; objectName: "rect13" - x: 200; width: 10; height: 10 - anchors.top: masterRect.bottom - } - Rectangle { - id: rect14; objectName: "rect14" - width: 10; height: 10; color: "steelblue" - anchors.verticalCenter: parent.verticalCenter - } - Rectangle { - id: rect15; objectName: "rect15" - y: 200; height: 10 - anchors.left: masterRect.left - anchors.right: masterRect.right - } - Rectangle { - id: rect16; objectName: "rect16" - y: 220; height: 10 - anchors.left: masterRect.left - anchors.horizontalCenter: masterRect.right - } - Rectangle { - id: rect17; objectName: "rect17" - y: 240; height: 10 - anchors.right: masterRect.right - anchors.horizontalCenter: masterRect.left - } - Rectangle { - id: rect18; objectName: "rect18" - x: 180; width: 10 - anchors.top: masterRect.bottom - anchors.bottom: rect12.top - } - Rectangle { - id: rect19; objectName: "rect19" - y: 70; width: 10; height: 10 - anchors.horizontalCenter: parent.horizontalCenter - } - Rectangle { - id: rect20; objectName: "rect20" - y: 70; width: 10; height: 10 - anchors.horizontalCenter: parent.right - } - Rectangle { - id: rect21; objectName: "rect21" - y: 70; width: 10; height: 10 - anchors.horizontalCenter: parent.left - } - Rectangle { - id: rect22; objectName: "rect22" - width: 10; height: 10 - anchors.centerIn: masterRect - } - Rectangle { - id: rect23; objectName: "rect23" - anchors.left: masterRect.left - anchors.leftMargin: 5 - anchors.right: masterRect.right - anchors.rightMargin: 5 - anchors.top: masterRect.top - anchors.topMargin: 5 - anchors.bottom: masterRect.bottom - anchors.bottomMargin: 5 - } - Rectangle { - id: rect24; objectName: "rect24" - width: 10; height: 10 - anchors.horizontalCenter: masterRect.left - anchors.horizontalCenterOffset: width/2 - } - Rectangle { - id: rect25; objectName: "rect25" - width: 10; height: 10 - anchors.verticalCenter: rect12.top - anchors.verticalCenterOffset: height/2 - } - Rectangle { - id: rect26; objectName: "rect26" - width: 10; height: 10 - anchors.baseline: masterRect.top - anchors.baselineOffset: height/2 - } - Text { - id: text1; objectName: "text1" - y: 200; - text: "Hello" - } - Text { - id: text2; objectName: "text2" - anchors.baseline: text1.baseline - anchors.left: text1.right - text: "World" - } -} diff --git a/tests/auto/qtquick1/qdeclarativeanchors/data/anchorsqgraphicswidget.qml b/tests/auto/qtquick1/qdeclarativeanchors/data/anchorsqgraphicswidget.qml deleted file mode 100644 index 82d0315aad..0000000000 --- a/tests/auto/qtquick1/qdeclarativeanchors/data/anchorsqgraphicswidget.qml +++ /dev/null @@ -1,162 +0,0 @@ -import QtQuick 1.0 - -Rectangle { - color: "white" - width: 240 - height: 320 - Rectangle { id: masterRect; objectName: "masterRect"; x: 26; width: 96; height: 20; color: "red" } - QGraphicsWidget { - id: rect1; objectName: "rect1" - y: 20; width: 10; height: 10 - anchors.left: masterRect.left - } - QGraphicsWidget { - id: rect2; objectName: "rect2" - y: 20; width: 10; height: 10 - anchors.left: masterRect.right - } - QGraphicsWidget { - id: rect3; objectName: "rect3" - y: 20; width: 10; height: 10 - anchors.left: masterRect.horizontalCenter - } - QGraphicsWidget { - id: rect4; objectName: "rect4" - y: 30; width: 10; height: 10 - anchors.right: masterRect.left - } - QGraphicsWidget { - id: rect5; objectName: "rect5" - y: 30; width: 10; height: 10 - anchors.right: masterRect.right - } - QGraphicsWidget { - id: rect6; objectName: "rect6" - y: 30; width: 10; height: 10 - anchors.right: masterRect.horizontalCenter - } - QGraphicsWidget { - id: rect7; objectName: "rect7" - y: 50; width: 10; height: 10 - anchors.left: parent.left - } - QGraphicsWidget { - id: rect8; objectName: "rect8" - y: 50; width: 10; height: 10 - anchors.left: parent.right - } - QGraphicsWidget { - id: rect9; objectName: "rect9" - y: 50; width: 10; height: 10 - anchors.left: parent.horizontalCenter - } - QGraphicsWidget { - id: rect10; objectName: "rect10" - y: 60; width: 10; height: 10 - anchors.right: parent.left - } - QGraphicsWidget { - id: rect11; objectName: "rect11" - y: 60; width: 10; height: 10 - anchors.right: parent.right - } - QGraphicsWidget { - id: rect12; objectName: "rect12" - y: 60; width: 10; height: 10 - anchors.right: parent.horizontalCenter - } - QGraphicsWidget { - id: rect13; objectName: "rect13" - x: 200; width: 10; height: 10 - anchors.top: masterRect.bottom - } - QGraphicsWidget { - id: rect14; objectName: "rect14" - width: 10; height: 10; - anchors.verticalCenter: parent.verticalCenter - } - QGraphicsWidget { - id: rect15; objectName: "rect15" - y: 200; height: 10 - anchors.left: masterRect.left - anchors.right: masterRect.right - } - QGraphicsWidget { - id: rect16; objectName: "rect16" - y: 220; height: 10 - anchors.left: masterRect.left - anchors.horizontalCenter: masterRect.right - } - QGraphicsWidget { - id: rect17; objectName: "rect17" - y: 240; height: 10 - anchors.right: masterRect.right - anchors.horizontalCenter: masterRect.left - } - QGraphicsWidget { - id: rect18; objectName: "rect18" - x: 180; width: 10 - anchors.top: masterRect.bottom - anchors.bottom: rect12.top - } - QGraphicsWidget { - id: rect19; objectName: "rect19" - y: 70; width: 10; height: 10 - anchors.horizontalCenter: parent.horizontalCenter - } - QGraphicsWidget { - id: rect20; objectName: "rect20" - y: 70; width: 10; height: 10 - anchors.horizontalCenter: parent.right - } - QGraphicsWidget { - id: rect21; objectName: "rect21" - y: 70; width: 10; height: 10 - anchors.horizontalCenter: parent.left - } - QGraphicsWidget { - id: rect22; objectName: "rect22" - width: 10; height: 10 - anchors.centerIn: masterRect - } - QGraphicsWidget { - id: rect23; objectName: "rect23" - anchors.left: masterRect.left - anchors.leftMargin: 5 - anchors.right: masterRect.right - anchors.rightMargin: 5 - anchors.top: masterRect.top - anchors.topMargin: 5 - anchors.bottom: masterRect.bottom - anchors.bottomMargin: 5 - } - QGraphicsWidget { - id: rect24; objectName: "rect24" - width: 10; height: 10 - anchors.horizontalCenter: masterRect.left - anchors.horizontalCenterOffset: width/2 - } - QGraphicsWidget { - id: rect25; objectName: "rect25" - width: 10; height: 10 - anchors.verticalCenter: rect12.top - anchors.verticalCenterOffset: height/2 - } - Rectangle { - id: rect26; objectName: "rect26" - width: 10; height: 10 - anchors.baseline: masterRect.top - anchors.baselineOffset: height/2 - } - Text { - id: text1; objectName: "text1" - y: 200; - text: "Hello" - } - Text { - id: text2; objectName: "text2" - anchors.baseline: text1.baseline - anchors.left: text1.right - text: "World" - } -} diff --git a/tests/auto/qtquick1/qdeclarativeanchors/data/centerin.qml b/tests/auto/qtquick1/qdeclarativeanchors/data/centerin.qml deleted file mode 100644 index d3bc8cb2bc..0000000000 --- a/tests/auto/qtquick1/qdeclarativeanchors/data/centerin.qml +++ /dev/null @@ -1,12 +0,0 @@ -import QtQuick 1.0 - -Rectangle { - width: 200; height: 200 - Rectangle { - objectName: "centered" - width: 50; height: 50; color: "blue" - anchors.centerIn: parent; - anchors.verticalCenterOffset: 30 - anchors.horizontalCenterOffset: 10 - } -} diff --git a/tests/auto/qtquick1/qdeclarativeanchors/data/crash1.qml b/tests/auto/qtquick1/qdeclarativeanchors/data/crash1.qml deleted file mode 100644 index de66067ce6..0000000000 --- a/tests/auto/qtquick1/qdeclarativeanchors/data/crash1.qml +++ /dev/null @@ -1,11 +0,0 @@ -import QtQuick 1.0 - -Column { - Text { - text: "foo" - anchors.fill: parent - } - Text { - text: "bar" - } -} diff --git a/tests/auto/qtquick1/qdeclarativeanchors/data/fill.qml b/tests/auto/qtquick1/qdeclarativeanchors/data/fill.qml deleted file mode 100644 index ff19675ef1..0000000000 --- a/tests/auto/qtquick1/qdeclarativeanchors/data/fill.qml +++ /dev/null @@ -1,14 +0,0 @@ -import QtQuick 1.0 - -Rectangle { - width: 200; height: 200 - Rectangle { - objectName: "filler" - width: 50; height: 50; color: "blue" - anchors.fill: parent; - anchors.leftMargin: 10; - anchors.rightMargin: 20; - anchors.topMargin: 30; - anchors.bottomMargin: 40; - } -} diff --git a/tests/auto/qtquick1/qdeclarativeanchors/data/hvCenter.qml b/tests/auto/qtquick1/qdeclarativeanchors/data/hvCenter.qml deleted file mode 100644 index 11b31ffdc0..0000000000 --- a/tests/auto/qtquick1/qdeclarativeanchors/data/hvCenter.qml +++ /dev/null @@ -1,11 +0,0 @@ -import QtQuick 1.0 - -Rectangle { - width: 77; height: 95 - Rectangle { - objectName: "centered" - width: 57; height: 57; color: "blue" - anchors.verticalCenter: parent.verticalCenter - anchors.horizontalCenter: parent.horizontalCenter - } -} diff --git a/tests/auto/qtquick1/qdeclarativeanchors/data/loop1.qml b/tests/auto/qtquick1/qdeclarativeanchors/data/loop1.qml deleted file mode 100644 index def48fae52..0000000000 --- a/tests/auto/qtquick1/qdeclarativeanchors/data/loop1.qml +++ /dev/null @@ -1,8 +0,0 @@ -import QtQuick 1.0 - -Rectangle { - id: rect - width: 120; height: 200; color: "white" - Text { id: text1; anchors.right: text2.right; text: "Hello" } - Text { id: text2; anchors.right: text1.right; anchors.rightMargin: 10; text: "World" } -} diff --git a/tests/auto/qtquick1/qdeclarativeanchors/data/loop2.qml b/tests/auto/qtquick1/qdeclarativeanchors/data/loop2.qml deleted file mode 100644 index 93430efb15..0000000000 --- a/tests/auto/qtquick1/qdeclarativeanchors/data/loop2.qml +++ /dev/null @@ -1,20 +0,0 @@ -import QtQuick 1.0 - -Rectangle { - id: container; - width: 600; - height: 600; - - Image { - id: image1 - source: "http://labs.qt.nokia.com/blogs/wp-content/uploads/2009/03/3311388091_ac2a257feb.jpg" - anchors.right: image2.left - } - - Image { - id: image2 - source: "http://labs.qt.nokia.com/blogs/wp-content/uploads/2009/03/oslo_groupphoto.jpg" - anchors.left: image1.right - anchors.leftMargin: 20 - } -} diff --git a/tests/auto/qtquick1/qdeclarativeanchors/data/margins.qml b/tests/auto/qtquick1/qdeclarativeanchors/data/margins.qml deleted file mode 100644 index 685346a879..0000000000 --- a/tests/auto/qtquick1/qdeclarativeanchors/data/margins.qml +++ /dev/null @@ -1,13 +0,0 @@ -import QtQuick 1.0 - -Rectangle { - width: 200; height: 200 - Rectangle { - objectName: "filler" - width: 50; height: 50; color: "blue" - anchors.fill: parent; - anchors.margins: 10 - anchors.leftMargin: 5 - anchors.topMargin: 6 - } -} diff --git a/tests/auto/qtquick1/qdeclarativeanchors/qdeclarativeanchors.pro b/tests/auto/qtquick1/qdeclarativeanchors/qdeclarativeanchors.pro deleted file mode 100644 index 57a285b4f9..0000000000 --- a/tests/auto/qtquick1/qdeclarativeanchors/qdeclarativeanchors.pro +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdeclarativeanchors -SOURCES += tst_qdeclarativeanchors.cpp -macx:CONFIG -= app_bundle - -DEFINES += SRCDIR=\\\"$$PWD\\\" - -CONFIG += parallel_test - -QT += core-private gui-private widgets-private v8-private declarative-private qtquick1-private testlib diff --git a/tests/auto/qtquick1/qdeclarativeanchors/tst_qdeclarativeanchors.cpp b/tests/auto/qtquick1/qdeclarativeanchors/tst_qdeclarativeanchors.cpp deleted file mode 100644 index 1130cd7a14..0000000000 --- a/tests/auto/qtquick1/qdeclarativeanchors/tst_qdeclarativeanchors.cpp +++ /dev/null @@ -1,767 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include <qtest.h> -#include <QSignalSpy> -#include <QtWidgets/QGraphicsWidget> -#include <private/qgraphicsitem_p.h> -#include <QtDeclarative/qdeclarativeengine.h> -#include <QtDeclarative/qdeclarativecomponent.h> -#include <QtQuick1/qdeclarativeview.h> -#include <QtQuick1/private/qdeclarativerectangle_p.h> -#include <QtQuick1/private/qdeclarativetext_p.h> -#include <QtQuick1/private/qdeclarativeanchors_p_p.h> -#include <QtQuick1/private/qdeclarativeitem_p.h> - -Q_DECLARE_METATYPE(QDeclarative1Anchors::Anchor) -Q_DECLARE_METATYPE(QDeclarative1AnchorLine::AnchorLine) - -class tst_QDeclarative1Anchors : public QObject -{ - Q_OBJECT -public: - tst_QDeclarative1Anchors() {} - -private slots: - void basicAnchors(); - void basicAnchorsQGraphicsWidget(); - void basicAnchorsRTL(); - void loops(); - void illegalSets(); - void illegalSets_data(); - void reset(); - void reset_data(); - void resetConvenience(); - void nullItem(); - void nullItem_data(); - void crash1(); - void centerIn(); - void centerInRTL(); - void hvCenter(); - void hvCenterRTL(); - void fill(); - void fillRTL(); - void margins(); - void marginsRTL(); -}; - -/* - Find an item with the specified id. -*/ -template<typename T> -T *findItem(QGraphicsObject *parent, const QString &objectName) -{ - const QMetaObject &mo = T::staticMetaObject; - QList<QGraphicsItem *> children = parent->childItems(); - for (int i = 0; i < children.count(); ++i) { - QDeclarativeItem *item = qobject_cast<QDeclarativeItem *>(children.at(i)->toGraphicsObject()); - if (item) { - if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { - return static_cast<T*>(item); - } - item = findItem<T>(item, objectName); - if (item) - return static_cast<T*>(item); - } - } - - return 0; -} - -QGraphicsObject *findObject(QGraphicsObject *parent, const QString &objectName) -{ - QList<QGraphicsItem *> children = parent->childItems(); - for (int i = 0; i < children.count(); ++i) { - QGraphicsObject *item = children.at(i)->toGraphicsObject(); - if (item) { - if (objectName.isEmpty() || item->objectName() == objectName) { - return item; - } - item = findObject(item, objectName); - if (item) - return item; - } - } - - return 0; -} - - -void tst_QDeclarative1Anchors::basicAnchors() -{ - QDeclarativeView *view = new QDeclarativeView; - view->setSource(QUrl::fromLocalFile(SRCDIR "/data/anchors.qml")); - - qApp->processEvents(); - - //sibling horizontal - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect1"))->x(), 26.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect2"))->x(), 122.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect3"))->x(), 74.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect4"))->x(), 16.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect5"))->x(), 112.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect6"))->x(), 64.0); - - //parent horizontal - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect7"))->x(), 0.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect8"))->x(), 240.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect9"))->x(), 120.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect10"))->x(), -10.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect11"))->x(), 230.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect12"))->x(), 110.0); - - //vertical - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect13"))->y(), 20.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect14"))->y(), 155.0); - - //stretch - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect15"))->x(), 26.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect15"))->width(), 96.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect16"))->x(), 26.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect16"))->width(), 192.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect17"))->x(), -70.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect17"))->width(), 192.0); - - //vertical stretch - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect18"))->y(), 20.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect18"))->height(), 40.0); - - //more parent horizontal - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect19"))->x(), 115.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect20"))->x(), 235.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect21"))->x(), -5.0); - - //centerIn - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect22"))->x(), 69.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect22"))->y(), 5.0); - - //margins - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect23"))->x(), 31.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect23"))->y(), 5.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect23"))->width(), 86.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect23"))->height(), 10.0); - - // offsets - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect24"))->x(), 26.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect25"))->y(), 60.0); - QCOMPARE(findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("rect26"))->y(), 5.0); - - //baseline - QDeclarative1Text *text1 = findItem<QDeclarative1Text>(view->rootObject(), QLatin1String("text1")); - QDeclarative1Text *text2 = findItem<QDeclarative1Text>(view->rootObject(), QLatin1String("text2")); - QCOMPARE(text1->y(), text2->y()); - - delete view; -} - -void tst_QDeclarative1Anchors::basicAnchorsQGraphicsWidget() -{ - QDeclarativeView *view = new QDeclarativeView; - view->setSource(QUrl::fromLocalFile(SRCDIR "/data/anchorsqgraphicswidget.qml")); - - qApp->processEvents(); - - //sibling horizontal - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect1"))->x(), 26.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect2"))->x(), 122.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect3"))->x(), 74.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect4"))->x(), 16.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect5"))->x(), 112.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect6"))->x(), 64.0); - - //parent horizontal - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect7"))->x(), 0.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect8"))->x(), 240.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect9"))->x(), 120.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect10"))->x(), -10.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect11"))->x(), 230.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect12"))->x(), 110.0); - - //vertical - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect13"))->y(), 20.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect14"))->y(), 155.0); - - //stretch - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect15"))->x(), 26.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect15"))->property("width").toReal(), 96.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect16"))->x(), 26.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect16"))->property("width").toReal(), 192.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect17"))->x(), -70.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect17"))->property("width").toReal(), 192.0); - - //vertical stretch - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect18"))->y(), 20.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect18"))->property("height").toReal(), 40.0); - - //more parent horizontal - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect19"))->x(), 115.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect20"))->x(), 235.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect21"))->x(), -5.0); - - //centerIn - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect22"))->x(), 69.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect22"))->y(), 5.0); - - //margins - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect23"))->x(), 31.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect23"))->y(), 5.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect23"))->property("width").toReal(), 86.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect23"))->property("height").toReal(), 10.0); - - // offsets - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect24"))->x(), 26.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect25"))->y(), 60.0); - QCOMPARE(findObject(view->rootObject(), QLatin1String("rect26"))->y(), 5.0); - - //baseline - QDeclarative1Text *text1 = findItem<QDeclarative1Text>(view->rootObject(), QLatin1String("text1")); - QDeclarative1Text *text2 = findItem<QDeclarative1Text>(view->rootObject(), QLatin1String("text2")); - QCOMPARE(text1->y(), text2->y()); - - delete view; -} - -QDeclarativeItem* childItem(QDeclarativeItem *parentItem, const char * itemString) { - return findItem<QDeclarativeItem>(parentItem, QLatin1String(itemString)); -} - -qreal offsetMasterRTL(QDeclarativeItem *rootItem, const char * itemString) { - QDeclarativeItem* masterItem = findItem<QDeclarativeItem>(rootItem, QLatin1String("masterRect")); - return masterItem->width()+2*masterItem->x()-findItem<QDeclarativeItem>(rootItem, QLatin1String(itemString))->width(); -} - -qreal offsetParentRTL(QDeclarativeItem *rootItem, const char * itemString) { - return rootItem->width()+2*rootItem->x()-findItem<QDeclarativeItem>(rootItem, QLatin1String(itemString))->width(); -} - -void mirrorAnchors(QDeclarativeItem *item) { - QDeclarativeItemPrivate *itemPrivate = QDeclarativeItemPrivate::get(item); - itemPrivate->setLayoutMirror(true); -} - -void tst_QDeclarative1Anchors::basicAnchorsRTL() -{ - QDeclarativeView *view = new QDeclarativeView; - view->setSource(QUrl::fromLocalFile(SRCDIR "/data/anchors.qml")); - - qApp->processEvents(); - - QDeclarativeItem* rootItem = qobject_cast<QDeclarativeItem*>(view->rootObject()); - foreach(QObject *child, rootItem->children()) { - bool mirrored = QDeclarativeItemPrivate::get(qobject_cast<QDeclarativeItem*>(child))->anchors()->property("mirrored").toBool(); - QCOMPARE(mirrored, false); - } - - foreach(QObject *child, rootItem->children()) - mirrorAnchors(qobject_cast<QDeclarativeItem*>(child)); - - foreach(QObject *child, rootItem->children()) { - bool mirrored = QDeclarativeItemPrivate::get(qobject_cast<QDeclarativeItem*>(child))->anchors()->property("mirrored").toBool(); - QCOMPARE(mirrored, true); - } - - //sibling horizontal - QCOMPARE(childItem(rootItem, "rect1")->x(), offsetMasterRTL(rootItem, "rect1")-26.0); - QCOMPARE(childItem(rootItem, "rect2")->x(), offsetMasterRTL(rootItem, "rect2")-122.0); - QCOMPARE(childItem(rootItem, "rect3")->x(), offsetMasterRTL(rootItem, "rect3")-74.0); - QCOMPARE(childItem(rootItem, "rect4")->x(), offsetMasterRTL(rootItem, "rect4")-16.0); - QCOMPARE(childItem(rootItem, "rect5")->x(), offsetMasterRTL(rootItem, "rect5")-112.0); - QCOMPARE(childItem(rootItem, "rect6")->x(), offsetMasterRTL(rootItem, "rect6")-64.0); - - //parent horizontal - QCOMPARE(childItem(rootItem, "rect7")->x(), offsetParentRTL(rootItem, "rect7")-0.0); - QCOMPARE(childItem(rootItem, "rect8")->x(), offsetParentRTL(rootItem, "rect8")-240.0); - QCOMPARE(childItem(rootItem, "rect9")->x(), offsetParentRTL(rootItem, "rect9")-120.0); - QCOMPARE(childItem(rootItem, "rect10")->x(), offsetParentRTL(rootItem, "rect10")+10.0); - QCOMPARE(childItem(rootItem, "rect11")->x(), offsetParentRTL(rootItem, "rect11")-230.0); - QCOMPARE(childItem(rootItem, "rect12")->x(), offsetParentRTL(rootItem, "rect12")-110.0); - - //vertical - QCOMPARE(childItem(rootItem, "rect13")->y(), 20.0); - QCOMPARE(childItem(rootItem, "rect14")->y(), 155.0); - - //stretch - QCOMPARE(childItem(rootItem, "rect15")->x(), offsetMasterRTL(rootItem, "rect15")-26.0); - QCOMPARE(childItem(rootItem, "rect15")->width(), 96.0); - QCOMPARE(childItem(rootItem, "rect16")->x(), offsetMasterRTL(rootItem, "rect16")-26.0); - QCOMPARE(childItem(rootItem, "rect16")->width(), 192.0); - QCOMPARE(childItem(rootItem, "rect17")->x(), offsetMasterRTL(rootItem, "rect17")+70.0); - QCOMPARE(childItem(rootItem, "rect17")->width(), 192.0); - - //vertical stretch - QCOMPARE(childItem(rootItem, "rect18")->y(), 20.0); - QCOMPARE(childItem(rootItem, "rect18")->height(), 40.0); - - //more parent horizontal - QCOMPARE(childItem(rootItem, "rect19")->x(), offsetParentRTL(rootItem, "rect19")-115.0); - QCOMPARE(childItem(rootItem, "rect20")->x(), offsetParentRTL(rootItem, "rect20")-235.0); - QCOMPARE(childItem(rootItem, "rect21")->x(), offsetParentRTL(rootItem, "rect21")+5.0); - - //centerIn - QCOMPARE(childItem(rootItem, "rect22")->x(), offsetMasterRTL(rootItem, "rect22")-69.0); - QCOMPARE(childItem(rootItem, "rect22")->y(), 5.0); - - //margins - QCOMPARE(childItem(rootItem, "rect23")->x(), offsetMasterRTL(rootItem, "rect23")-31.0); - QCOMPARE(childItem(rootItem, "rect23")->y(), 5.0); - QCOMPARE(childItem(rootItem, "rect23")->width(), 86.0); - QCOMPARE(childItem(rootItem, "rect23")->height(), 10.0); - - // offsets - QCOMPARE(childItem(rootItem, "rect24")->x(), offsetMasterRTL(rootItem, "rect24")-26.0); - QCOMPARE(childItem(rootItem, "rect25")->y(), 60.0); - QCOMPARE(childItem(rootItem, "rect26")->y(), 5.0); - - //baseline - QDeclarative1Text *text1 = findItem<QDeclarative1Text>(rootItem, QLatin1String("text1")); - QDeclarative1Text *text2 = findItem<QDeclarative1Text>(rootItem, QLatin1String("text2")); - QCOMPARE(text1->y(), text2->y()); - - delete view; -} - -// mostly testing that we don't crash -void tst_QDeclarative1Anchors::loops() -{ - { - QUrl source(QUrl::fromLocalFile(SRCDIR "/data/loop1.qml")); - - QString expect = source.toString() + ":6:5: QML Text: Possible anchor loop detected on horizontal anchor."; - QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); - QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); - QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); - - QDeclarativeView *view = new QDeclarativeView; - view->setSource(source); - qApp->processEvents(); - - delete view; - } - - { - QSKIP("This causes a lockup due to Bearer management stuff"); - QUrl source(QUrl::fromLocalFile(SRCDIR "/data/loop2.qml")); - - QString expect = source.toString() + ":8:3: QML Image: Possible anchor loop detected on horizontal anchor."; - QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); - - QDeclarativeView *view = new QDeclarativeView; - view->setSource(source); - qApp->processEvents(); - - delete view; - } -} - -void tst_QDeclarative1Anchors::illegalSets() -{ - QFETCH(QString, qml); - QFETCH(QString, warning); - - QTest::ignoreMessage(QtWarningMsg, warning.toLatin1()); - - QDeclarativeEngine engine; - QDeclarativeComponent component(&engine); - component.setData(QByteArray("import QtQuick 1.0\n" + qml.toUtf8()), QUrl::fromLocalFile("")); - if (!component.isReady()) - qWarning() << "Test errors:" << component.errors(); - QVERIFY(component.isReady()); - QObject *o = component.create(); - delete o; -} - -void tst_QDeclarative1Anchors::illegalSets_data() -{ - QTest::addColumn<QString>("qml"); - QTest::addColumn<QString>("warning"); - - QTest::newRow("H - too many anchors") - << "Rectangle { id: rect; Rectangle { anchors.left: rect.left; anchors.right: rect.right; anchors.horizontalCenter: rect.horizontalCenter } }" - << "file::2:23: QML Rectangle: Cannot specify left, right, and hcenter anchors."; - - foreach (const QString &side, QStringList() << "left" << "right") { - QTest::newRow("H - anchor to V") - << QString("Rectangle { Rectangle { anchors.%1: parent.top } }").arg(side) - << "file::2:13: QML Rectangle: Cannot anchor a horizontal edge to a vertical edge."; - - QTest::newRow("H - anchor to non parent/sibling") - << QString("Rectangle { Item { Rectangle { id: rect } } Rectangle { anchors.%1: rect.%1 } }").arg(side) - << "file::2:45: QML Rectangle: Cannot anchor to an item that isn't a parent or sibling."; - - QTest::newRow("H - anchor to self") - << QString("Rectangle { id: rect; anchors.%1: rect.%1 }").arg(side) - << "file::2:1: QML Rectangle: Cannot anchor item to self."; - } - - - QTest::newRow("V - too many anchors") - << "Rectangle { id: rect; Rectangle { anchors.top: rect.top; anchors.bottom: rect.bottom; anchors.verticalCenter: rect.verticalCenter } }" - << "file::2:23: QML Rectangle: Cannot specify top, bottom, and vcenter anchors."; - - QTest::newRow("V - too many anchors with baseline") - << "Rectangle { Text { id: text1; text: \"Hello\" } Text { anchors.baseline: text1.baseline; anchors.top: text1.top; } }" - << "file::2:47: QML Text: Baseline anchor cannot be used in conjunction with top, bottom, or vcenter anchors."; - - foreach (const QString &side, QStringList() << "top" << "bottom" << "baseline") { - - QTest::newRow("V - anchor to H") - << QString("Rectangle { Rectangle { anchors.%1: parent.left } }").arg(side) - << "file::2:13: QML Rectangle: Cannot anchor a vertical edge to a horizontal edge."; - - QTest::newRow("V - anchor to non parent/sibling") - << QString("Rectangle { Item { Rectangle { id: rect } } Rectangle { anchors.%1: rect.%1 } }").arg(side) - << "file::2:45: QML Rectangle: Cannot anchor to an item that isn't a parent or sibling."; - - QTest::newRow("V - anchor to self") - << QString("Rectangle { id: rect; anchors.%1: rect.%1 }").arg(side) - << "file::2:1: QML Rectangle: Cannot anchor item to self."; - } - - - QTest::newRow("centerIn - anchor to non parent/sibling") - << "Rectangle { Item { Rectangle { id: rect } } Rectangle { anchors.centerIn: rect} }" - << "file::2:45: QML Rectangle: Cannot anchor to an item that isn't a parent or sibling."; - - - QTest::newRow("fill - anchor to non parent/sibling") - << "Rectangle { Item { Rectangle { id: rect } } Rectangle { anchors.fill: rect} }" - << "file::2:45: QML Rectangle: Cannot anchor to an item that isn't a parent or sibling."; -} - -void tst_QDeclarative1Anchors::reset() -{ - QFETCH(QString, side); - QFETCH(QDeclarative1AnchorLine::AnchorLine, anchorLine); - QFETCH(QDeclarative1Anchors::Anchor, usedAnchor); - - QDeclarativeItem *baseItem = new QDeclarativeItem; - - QDeclarative1AnchorLine anchor; - anchor.item = baseItem; - anchor.anchorLine = anchorLine; - - QDeclarativeItem *item = new QDeclarativeItem; - QDeclarativeItemPrivate *itemPrivate = QDeclarativeItemPrivate::get(item); - - const QMetaObject *meta = itemPrivate->anchors()->metaObject(); - QMetaProperty p = meta->property(meta->indexOfProperty(side.toUtf8().constData())); - - QVERIFY(p.write(itemPrivate->anchors(), qVariantFromValue(anchor))); - QCOMPARE(itemPrivate->anchors()->usedAnchors().testFlag(usedAnchor), true); - - QVERIFY(p.reset(itemPrivate->anchors())); - QCOMPARE(itemPrivate->anchors()->usedAnchors().testFlag(usedAnchor), false); - - delete item; - delete baseItem; -} - -void tst_QDeclarative1Anchors::reset_data() -{ - QTest::addColumn<QString>("side"); - QTest::addColumn<QDeclarative1AnchorLine::AnchorLine>("anchorLine"); - QTest::addColumn<QDeclarative1Anchors::Anchor>("usedAnchor"); - - QTest::newRow("left") << "left" << QDeclarative1AnchorLine::Left << QDeclarative1Anchors::LeftAnchor; - QTest::newRow("top") << "top" << QDeclarative1AnchorLine::Top << QDeclarative1Anchors::TopAnchor; - QTest::newRow("right") << "right" << QDeclarative1AnchorLine::Right << QDeclarative1Anchors::RightAnchor; - QTest::newRow("bottom") << "bottom" << QDeclarative1AnchorLine::Bottom << QDeclarative1Anchors::BottomAnchor; - - QTest::newRow("hcenter") << "horizontalCenter" << QDeclarative1AnchorLine::HCenter << QDeclarative1Anchors::HCenterAnchor; - QTest::newRow("vcenter") << "verticalCenter" << QDeclarative1AnchorLine::VCenter << QDeclarative1Anchors::VCenterAnchor; - QTest::newRow("baseline") << "baseline" << QDeclarative1AnchorLine::Baseline << QDeclarative1Anchors::BaselineAnchor; -} - -void tst_QDeclarative1Anchors::resetConvenience() -{ - QDeclarativeItem *baseItem = new QDeclarativeItem; - QDeclarativeItem *item = new QDeclarativeItem; - QDeclarativeItemPrivate *itemPrivate = QDeclarativeItemPrivate::get(item); - - //fill - itemPrivate->anchors()->setFill(baseItem); - QVERIFY(itemPrivate->anchors()->fill() == baseItem); - itemPrivate->anchors()->resetFill(); - QVERIFY(itemPrivate->anchors()->fill() == 0); - - //centerIn - itemPrivate->anchors()->setCenterIn(baseItem); - QVERIFY(itemPrivate->anchors()->centerIn() == baseItem); - itemPrivate->anchors()->resetCenterIn(); - QVERIFY(itemPrivate->anchors()->centerIn() == 0); - - delete item; - delete baseItem; -} - -void tst_QDeclarative1Anchors::nullItem() -{ - QFETCH(QString, side); - - QDeclarative1AnchorLine anchor; - QDeclarativeItem *item = new QDeclarativeItem; - QDeclarativeItemPrivate *itemPrivate = QDeclarativeItemPrivate::get(item); - - const QMetaObject *meta = itemPrivate->anchors()->metaObject(); - QMetaProperty p = meta->property(meta->indexOfProperty(side.toUtf8().constData())); - - QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML Item: Cannot anchor to a null item."); - QVERIFY(p.write(itemPrivate->anchors(), qVariantFromValue(anchor))); - - delete item; -} - -void tst_QDeclarative1Anchors::nullItem_data() -{ - QTest::addColumn<QString>("side"); - - QTest::newRow("left") << "left"; - QTest::newRow("top") << "top"; - QTest::newRow("right") << "right"; - QTest::newRow("bottom") << "bottom"; - - QTest::newRow("hcenter") << "horizontalCenter"; - QTest::newRow("vcenter") << "verticalCenter"; - QTest::newRow("baseline") << "baseline"; -} - -void tst_QDeclarative1Anchors::crash1() -{ - QUrl source(QUrl::fromLocalFile(SRCDIR "/data/crash1.qml")); - - QString expect = source.toString() + ":4:5: QML Text: Possible anchor loop detected on fill."; - - QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); - - // QT-3245 ... anchor loop detection needs improving. - QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); - QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); - QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); - QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); - QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); - QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); - QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); - - QDeclarativeView *view = new QDeclarativeView(source); - qApp->processEvents(); - - delete view; -} - -void tst_QDeclarative1Anchors::fill() -{ - QDeclarativeView *view = new QDeclarativeView(QUrl::fromLocalFile(SRCDIR "/data/fill.qml")); - - qApp->processEvents(); - QDeclarative1Rectangle* rect = findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("filler")); - QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); - QCOMPARE(rect->x(), 0.0 + 10.0); - QCOMPARE(rect->y(), 0.0 + 30.0); - QCOMPARE(rect->width(), 200.0 - 10.0 - 20.0); - QCOMPARE(rect->height(), 200.0 - 30.0 - 40.0); - //Alter Offsets (tests QTBUG-6631) - rectPrivate->anchors()->setLeftMargin(20.0); - rectPrivate->anchors()->setRightMargin(0.0); - rectPrivate->anchors()->setBottomMargin(0.0); - rectPrivate->anchors()->setTopMargin(10.0); - QCOMPARE(rect->x(), 0.0 + 20.0); - QCOMPARE(rect->y(), 0.0 + 10.0); - QCOMPARE(rect->width(), 200.0 - 20.0); - QCOMPARE(rect->height(), 200.0 - 10.0); - - delete view; -} - -void tst_QDeclarative1Anchors::fillRTL() -{ - QDeclarativeView *view = new QDeclarativeView(QUrl::fromLocalFile(SRCDIR "/data/fill.qml")); - - qApp->processEvents(); - QDeclarative1Rectangle* rect = findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("filler")); - QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); - mirrorAnchors(rect); - - QCOMPARE(rect->x(), 0.0 + 20.0); - QCOMPARE(rect->y(), 0.0 + 30.0); - QCOMPARE(rect->width(), 200.0 - 10.0 - 20.0); - QCOMPARE(rect->height(), 200.0 - 30.0 - 40.0); - //Alter Offsets (tests QTBUG-6631) - rectPrivate->anchors()->setLeftMargin(20.0); - rectPrivate->anchors()->setRightMargin(0.0); - rectPrivate->anchors()->setBottomMargin(0.0); - rectPrivate->anchors()->setTopMargin(10.0); - QCOMPARE(rect->x(), 0.0 + 0.0); - QCOMPARE(rect->y(), 0.0 + 10.0); - QCOMPARE(rect->width(), 200.0 - 20.0); - QCOMPARE(rect->height(), 200.0 - 10.0); - - delete view; -} -void tst_QDeclarative1Anchors::centerIn() -{ - QDeclarativeView *view = new QDeclarativeView(QUrl::fromLocalFile(SRCDIR "/data/centerin.qml")); - - qApp->processEvents(); - QDeclarative1Rectangle* rect = findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("centered")); - QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); - - QCOMPARE(rect->x(), 75.0 + 10); - QCOMPARE(rect->y(), 75.0 + 30); - //Alter Offsets (tests QTBUG-6631) - rectPrivate->anchors()->setHorizontalCenterOffset(-20.0); - rectPrivate->anchors()->setVerticalCenterOffset(-10.0); - QCOMPARE(rect->x(), 75.0 - 20.0); - QCOMPARE(rect->y(), 75.0 - 10.0); - - delete view; -} - - -void tst_QDeclarative1Anchors::centerInRTL() -{ - QDeclarativeView *view = new QDeclarativeView(QUrl::fromLocalFile(SRCDIR "/data/centerin.qml")); - - qApp->processEvents(); - QDeclarative1Rectangle* rect = findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("centered")); - QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); - mirrorAnchors(rect); - - QCOMPARE(rect->x(), 75.0 - 10); - QCOMPARE(rect->y(), 75.0 + 30); - //Alter Offsets (tests QTBUG-6631) - rectPrivate->anchors()->setHorizontalCenterOffset(-20.0); - rectPrivate->anchors()->setVerticalCenterOffset(-10.0); - QCOMPARE(rect->x(), 75.0 + 20.0); - QCOMPARE(rect->y(), 75.0 - 10.0); - - delete view; -} - -void tst_QDeclarative1Anchors::hvCenter() -{ - QDeclarativeView *view = new QDeclarativeView(QUrl::fromLocalFile(SRCDIR "/data/hvCenter.qml")); - - qApp->processEvents(); - QDeclarative1Rectangle* rect = findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("centered")); - QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); - - // test QTBUG-10999 - QCOMPARE(rect->x(), 10.0); - QCOMPARE(rect->y(), 19.0); - - rectPrivate->anchors()->setHorizontalCenterOffset(-5.0); - rectPrivate->anchors()->setVerticalCenterOffset(5.0); - QCOMPARE(rect->x(), 10.0 - 5.0); - QCOMPARE(rect->y(), 19.0 + 5.0); - - delete view; -} - -void tst_QDeclarative1Anchors::hvCenterRTL() -{ - QDeclarativeView *view = new QDeclarativeView(QUrl::fromLocalFile(SRCDIR "/data/hvCenter.qml")); - - qApp->processEvents(); - QDeclarative1Rectangle* rect = findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("centered")); - QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); - mirrorAnchors(rect); - - // test QTBUG-10999 - QCOMPARE(rect->x(), 10.0); - QCOMPARE(rect->y(), 19.0); - - rectPrivate->anchors()->setHorizontalCenterOffset(-5.0); - rectPrivate->anchors()->setVerticalCenterOffset(5.0); - QCOMPARE(rect->x(), 10.0 + 5.0); - QCOMPARE(rect->y(), 19.0 + 5.0); - - delete view; -} -void tst_QDeclarative1Anchors::margins() -{ - QDeclarativeView *view = new QDeclarativeView(QUrl::fromLocalFile(SRCDIR "/data/margins.qml")); - - qApp->processEvents(); - QDeclarative1Rectangle* rect = findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("filler")); - QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); - QCOMPARE(rect->x(), 5.0); - QCOMPARE(rect->y(), 6.0); - QCOMPARE(rect->width(), 200.0 - 5.0 - 10.0); - QCOMPARE(rect->height(), 200.0 - 6.0 - 10.0); - - rectPrivate->anchors()->setTopMargin(0.0); - rectPrivate->anchors()->setMargins(20.0); - - QCOMPARE(rect->x(), 5.0); - QCOMPARE(rect->y(), 20.0); - QCOMPARE(rect->width(), 200.0 - 5.0 - 20.0); - QCOMPARE(rect->height(), 200.0 - 20.0 - 20.0); - - delete view; -} - -void tst_QDeclarative1Anchors::marginsRTL() -{ - QDeclarativeView *view = new QDeclarativeView(QUrl::fromLocalFile(SRCDIR "/data/margins.qml")); - - QDeclarative1Rectangle* rect = findItem<QDeclarative1Rectangle>(view->rootObject(), QLatin1String("filler")); - QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); - mirrorAnchors(rect); - - QCOMPARE(rect->x(), 10.0); - QCOMPARE(rect->y(), 6.0); - QCOMPARE(rect->width(), 200.0 - 5.0 - 10.0); - QCOMPARE(rect->height(), 200.0 - 6.0 - 10.0); - - rectPrivate->anchors()->setTopMargin(0.0); - rectPrivate->anchors()->setMargins(20.0); - - QCOMPARE(rect->x(), 20.0); - QCOMPARE(rect->y(), 20.0); - QCOMPARE(rect->width(), 200.0 - 5.0 - 20.0); - QCOMPARE(rect->height(), 200.0 - 20.0 - 20.0); - - delete view; -} - - -QTEST_MAIN(tst_QDeclarative1Anchors) - -#include "tst_qdeclarativeanchors.moc" |