summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2009-11-27 02:41:18 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2009-11-27 02:41:18 (GMT)
commita432859f0494b127495932b7365b62a4e579dc2e (patch)
treeed93cb2d1765e52c625a4296cb7d4feb4fc44e9d
parent1efae63bf7cba55526c91dcff3139d0a10885efc (diff)
parent16202b23b29b5e84df9b3d7423c6a1e583230b78 (diff)
downloadQt-a432859f0494b127495932b7365b62a4e579dc2e.zip
Qt-a432859f0494b127495932b7365b62a4e579dc2e.tar.gz
Qt-a432859f0494b127495932b7365b62a4e579dc2e.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsflipable.cpp3
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsitem.cpp8
-rw-r--r--src/declarative/graphicsitems/qmlgraphicslistview.cpp41
-rw-r--r--src/declarative/graphicsitems/qmlgraphicslistview_p.h1
-rw-r--r--tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp88
5 files changed, 134 insertions, 7 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsflipable.cpp b/src/declarative/graphicsitems/qmlgraphicsflipable.cpp
index 7719469..b964e22 100644
--- a/src/declarative/graphicsitems/qmlgraphicsflipable.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicsflipable.cpp
@@ -97,8 +97,9 @@ public:
}
MouseRegion {
- anchors.fill: parent
+ // change between default and 'back' states
onClicked: flipable.state = (flipable.state == 'back' ? '' : 'back')
+ anchors.fill: parent
}
}
\endqml
diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.cpp b/src/declarative/graphicsitems/qmlgraphicsitem.cpp
index 5b4f1f1..db59cf2 100644
--- a/src/declarative/graphicsitems/qmlgraphicsitem.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicsitem.cpp
@@ -1307,20 +1307,20 @@ QmlGraphicsKeysAttached *QmlGraphicsKeysAttached::qmlAttachedProperties(QObject
\qml
Item {
Image {
- file: "tile.png"
+ source: "tile.png"
}
Image {
x: 80
width: 100
height: 100
- file: "tile.png"
+ source: "tile.png"
}
Image {
x: 190
width: 100
height: 100
- tile: true
- file: "tile.png"
+ fillMode: Image.Tile
+ source: "tile.png"
}
}
\endqml
diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp
index e05ae66..0224465 100644
--- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp
@@ -1603,7 +1603,7 @@ qreal QmlGraphicsListView::maxYExtent() const
if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange)
extent = -(d->positionAt(count()-1) - d->highlightRangeEnd);
else
- extent = -(d->endPosition() - height());
+ extent = -(d->endPosition() - height() + 1);
qreal minY = minYExtent();
if (extent > minY)
extent = minY;
@@ -1631,7 +1631,7 @@ qreal QmlGraphicsListView::maxXExtent() const
if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange)
extent = -(d->positionAt(count()-1) - d->highlightRangeEnd);
else
- extent = -(d->endPosition() - width());
+ extent = -(d->endPosition() - width() + 1);
qreal minX = minXExtent();
if (extent > minX)
extent = minX;
@@ -1706,6 +1706,43 @@ void QmlGraphicsListView::decrementCurrentIndex()
}
}
+/*!
+ \qmlmethod ListView::positionViewAtIndex(int index)
+
+ Positions the view such that the \a index is at the top (or left for horizontal orientation) of the view.
+ If positioning the view at the index would cause empty space to be displayed at
+ the end of the view, the view will be positioned at the end.
+*/
+void QmlGraphicsListView::positionViewAtIndex(int index)
+{
+ Q_D(QmlGraphicsListView);
+ if (index < 0 || index >= d->model->count())
+ return;
+
+ FxListItem *item = d->visibleItem(index);
+ if (item) {
+ // Already created - just move to top of view
+ int pos = item->position();
+ if (item->position() > -maxYExtent())
+ pos = -maxYExtent();
+ d->setPosition(pos);
+ } else {
+ int pos = d->positionAt(index);
+ // save the currently visible items in case any of them end up visible again
+ QList<FxListItem*> oldVisible = d->visibleItems;
+ d->visibleItems.clear();
+ d->visiblePos = pos;
+ d->visibleIndex = index;
+ d->setPosition(pos);
+ if (d->position() > -maxYExtent())
+ d->setPosition(-maxYExtent());
+ // now release the reference to all the old visible items.
+ for (int i = 0; i < oldVisible.count(); ++i)
+ d->releaseItem(oldVisible.at(i));
+ }
+}
+
+
void QmlGraphicsListView::componentComplete()
{
Q_D(QmlGraphicsListView);
diff --git a/src/declarative/graphicsitems/qmlgraphicslistview_p.h b/src/declarative/graphicsitems/qmlgraphicslistview_p.h
index b8a6e1f..795c766 100644
--- a/src/declarative/graphicsitems/qmlgraphicslistview_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicslistview_p.h
@@ -147,6 +147,7 @@ public:
public Q_SLOTS:
void incrementCurrentIndex();
void decrementCurrentIndex();
+ void positionViewAtIndex(int index);
Q_SIGNALS:
void countChanged();
diff --git a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp
index 08043f3..0a86ecc 100644
--- a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp
+++ b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp
@@ -79,6 +79,7 @@ private slots:
void spacing();
void sections();
void cacheBuffer();
+ void positionViewAtIndex();
private:
template <class T> void items();
@@ -1135,6 +1136,93 @@ void tst_QmlGraphicsListView::cacheBuffer()
delete canvas;
}
+void tst_QmlGraphicsListView::positionViewAtIndex()
+{
+ QmlView *canvas = createView(SRCDIR "/data/listview.qml");
+
+ TestModel model;
+ for (int i = 0; i < 40; i++)
+ model.addItem("Item" + QString::number(i), "");
+
+ QmlContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+
+ TestObject *testObject = new TestObject;
+ ctxt->setContextProperty("testObject", testObject);
+
+ canvas->execute();
+ qApp->processEvents();
+
+ QmlGraphicsListView *listview = findItem<QmlGraphicsListView>(canvas->root(), "list");
+ QVERIFY(listview != 0);
+
+ QmlGraphicsItem *viewport = listview->viewport();
+ QVERIFY(viewport != 0);
+
+ // Confirm items positioned correctly
+ int itemCount = findItems<QmlGraphicsItem>(viewport, "wrapper").count();
+ for (int i = 0; i < model.count() && i < itemCount; ++i) {
+ QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i);
+ if (!item) qWarning() << "Item" << i << "not found";
+ QVERIFY(item);
+ QCOMPARE(item->y(), i*20.);
+ }
+
+ // Position on a currently visible item
+ listview->positionViewAtIndex(3);
+ QCOMPARE(listview->viewportY(), 60.);
+
+ // Confirm items positioned correctly
+ itemCount = findItems<QmlGraphicsItem>(viewport, "wrapper").count();
+ for (int i = 3; i < model.count() && i < itemCount-3-1; ++i) {
+ QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i);
+ if (!item) qWarning() << "Item" << i << "not found";
+ QVERIFY(item);
+ QCOMPARE(item->y(), i*20.);
+ }
+
+ // Position on an item beyond the visible items
+ listview->positionViewAtIndex(22);
+ QCOMPARE(listview->viewportY(), 440.);
+
+ // Confirm items positioned correctly
+ itemCount = findItems<QmlGraphicsItem>(viewport, "wrapper").count();
+ for (int i = 22; i < model.count() && i < itemCount-22-1; ++i) {
+ QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i);
+ if (!item) qWarning() << "Item" << i << "not found";
+ QVERIFY(item);
+ QCOMPARE(item->y(), i*20.);
+ }
+
+ // Position on an item that would leave empty space if positioned at the top
+ listview->positionViewAtIndex(28);
+ QCOMPARE(listview->viewportY(), 480.);
+
+ // Confirm items positioned correctly
+ itemCount = findItems<QmlGraphicsItem>(viewport, "wrapper").count();
+ for (int i = 24; i < model.count() && i < itemCount-24-1; ++i) {
+ QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i);
+ if (!item) qWarning() << "Item" << i << "not found";
+ QVERIFY(item);
+ QCOMPARE(item->y(), i*20.);
+ }
+
+ // Position at the beginning again
+ listview->positionViewAtIndex(0);
+ QCOMPARE(listview->viewportY(), 0.);
+
+ // Confirm items positioned correctly
+ itemCount = findItems<QmlGraphicsItem>(viewport, "wrapper").count();
+ for (int i = 0; i < model.count() && i < itemCount-1; ++i) {
+ QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i);
+ if (!item) qWarning() << "Item" << i << "not found";
+ QVERIFY(item);
+ QCOMPARE(item->y(), i*20.);
+ }
+
+ delete canvas;
+}
+
void tst_QmlGraphicsListView::qListModelInterface_items()
{
items<TestModel>();