diff options
author | Martin Jones <martin.jones@nokia.com> | 2011-09-23 16:13:51 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-09-26 03:24:42 +0200 |
commit | 14228a41471a327f6e600220a795a1c6cb23c2b2 (patch) | |
tree | c7c9f127b8dfc9f9e608ab421a692be7896d0c18 /tests/auto/declarative/qsglistview | |
parent | 2790f9b1d5488f7f29903408eaa5d2a6118f55ee (diff) |
Support margins in Flickable.
It is sometimes desireable to leave a margin/add decoration around the
content of a Flickable. This adds topMargin, leftMargin, bottomMargin
rightMargin, xOrigin and yOrigin properties to Flickable.
Task-number: QTBUG-21362
Change-Id: Ia24ea4c63e7a8de683b68100baac782c6f3a66bb
Reviewed-on: http://codereview.qt-project.org/5445
Reviewed-by: Bea Lam <bea.lam@nokia.com>
Diffstat (limited to 'tests/auto/declarative/qsglistview')
-rw-r--r-- | tests/auto/declarative/qsglistview/data/margins.qml | 47 | ||||
-rw-r--r-- | tests/auto/declarative/qsglistview/tst_qsglistview.cpp | 63 |
2 files changed, 110 insertions, 0 deletions
diff --git a/tests/auto/declarative/qsglistview/data/margins.qml b/tests/auto/declarative/qsglistview/data/margins.qml new file mode 100644 index 0000000000..19bbef500f --- /dev/null +++ b/tests/auto/declarative/qsglistview/data/margins.qml @@ -0,0 +1,47 @@ +import QtQuick 2.0 + +Rectangle { + id: root + width: 240 + height: 320 + color: "#ffffff" + + Component { + id: myDelegate + Rectangle { + id: wrapper + objectName: "wrapper" + height: 20 + width: 240 + Text { + text: index + } + Text { + x: 30 + id: textName + objectName: "textName" + text: name + } + Text { + x: 120 + id: textNumber + objectName: "textNumber" + text: number + } + Text { + x: 200 + text: wrapper.y + } + color: ListView.isCurrentItem ? "lightsteelblue" : "white" + } + } + ListView { + id: list + objectName: "list" + anchors.fill: parent + topMargin: 30 + bottomMargin: 50 + model: testModel + delegate: myDelegate + } +} diff --git a/tests/auto/declarative/qsglistview/tst_qsglistview.cpp b/tests/auto/declarative/qsglistview/tst_qsglistview.cpp index ce1587db88..291877cba6 100644 --- a/tests/auto/declarative/qsglistview/tst_qsglistview.cpp +++ b/tests/auto/declarative/qsglistview/tst_qsglistview.cpp @@ -136,6 +136,7 @@ private slots: void onRemove_data(); void rightToLeft(); void test_mirroring(); + void margins(); private: template <class T> void items(); @@ -3542,6 +3543,68 @@ void tst_QSGListView::test_mirroring() delete canvasB; } +void tst_QSGListView::margins() +{ + QSGView *canvas = createView(); + + TestModel2 model; + for (int i = 0; i < 50; i++) + model.addItem("Item" + QString::number(i), ""); + + QDeclarativeContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/margins.qml")); + canvas->show(); + qApp->processEvents(); + + QSGListView *listview = findItem<QSGListView>(canvas->rootObject(), "list"); + QTRY_VERIFY(listview != 0); + + QSGItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); + + QCOMPARE(listview->contentY(), -30.); + QCOMPARE(listview->yOrigin(), 0.); + + // check end bound + listview->positionViewAtEnd(); + qreal pos = listview->contentY(); + listview->setContentY(pos + 80); + listview->returnToBounds(); + QTRY_COMPARE(listview->contentY(), pos + 50); + + // remove item before visible and check that top margin is maintained + // and yOrigin is updated + listview->setContentY(100); + model.removeItem(1); + QTest::qWait(100); + listview->setContentY(-50); + listview->returnToBounds(); + QCOMPARE(listview->yOrigin(), 20.); + QTRY_COMPARE(listview->contentY(), -10.); + + // reduce top margin + listview->setTopMargin(20); + QCOMPARE(listview->yOrigin(), 20.); + QTRY_COMPARE(listview->contentY(), 0.); + + // check end bound + listview->positionViewAtEnd(); + pos = listview->contentY(); + listview->setContentY(pos + 80); + listview->returnToBounds(); + QTRY_COMPARE(listview->contentY(), pos + 50); + + // reduce bottom margin + pos = listview->contentY(); + listview->setBottomMargin(40); + QCOMPARE(listview->yOrigin(), 20.); + QTRY_COMPARE(listview->contentY(), pos-10); + + delete canvas; +} + void tst_QSGListView::qListModelInterface_items() { items<TestModel>(); |