From ca30cacd614b7de8a855a3b4a1dc254c5f9289c9 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 10 Nov 2009 13:35:05 +1000 Subject: More highlight testing. --- .../graphicsitems/qmlgraphicsgridview.cpp | 26 ++++++++++++++++++- .../graphicsitems/qmlgraphicsgridview_p.h | 5 ++++ .../graphicsitems/qmlgraphicslistview.cpp | 30 +++++++++++++++++++--- .../graphicsitems/qmlgraphicslistview_p.h | 3 +++ .../tst_qmlgraphicsgridview.cpp | 17 ++++++++++++ .../tst_qmlgraphicslistview.cpp | 15 +++++++++++ 6 files changed, 92 insertions(+), 4 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp index 10050f2..1b94426 100644 --- a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp @@ -565,6 +565,7 @@ void QmlGraphicsGridViewPrivate::updateTrackedItem() void QmlGraphicsGridViewPrivate::createHighlight() { Q_Q(QmlGraphicsGridView); + bool changed = false; if (highlight) { if (trackedItem == highlight) trackedItem = 0; @@ -575,6 +576,7 @@ void QmlGraphicsGridViewPrivate::createHighlight() delete highlightYAnimator; highlightXAnimator = 0; highlightYAnimator = 0; + changed = true; } if (currentItem) { @@ -606,8 +608,11 @@ void QmlGraphicsGridViewPrivate::createHighlight() highlightYAnimator->setTarget(QmlMetaProperty(highlight->item, QLatin1String("y"))); highlightYAnimator->setDuration(150); highlightYAnimator->setEnabled(autoHighlight); + changed = true; } } + if (changed) + emit q->highlightChanged(); } void QmlGraphicsGridViewPrivate::updateHighlight() @@ -887,6 +892,25 @@ QmlGraphicsItem *QmlGraphicsGridView::currentItem() } /*! + \qmlproperty Item GridView::highlightItem + + \c highlightItem holds the highlight item, which was created + from the \l highlight component. + + The highlightItem is managed by the view unless + \l highlightFollowsCurrentItem is set to false. + + \sa highlight, highlightFollowsCurrentItem +*/ +QmlGraphicsItem *QmlGraphicsGridView::highlightItem() +{ + Q_D(QmlGraphicsGridView); + if (!d->highlight) + return 0; + return d->highlight->item; +} + +/*! \qmlproperty int GridView::count This property holds the number of items in the view. */ @@ -909,7 +933,7 @@ int QmlGraphicsGridView::count() const The below example demonstrates how to make a simple highlight: \snippet doc/src/snippets/declarative/gridview/gridview.qml 1 - \sa highlightFollowsCurrentItem + \sa highlightItem, highlightFollowsCurrentItem */ QmlComponent *QmlGraphicsGridView::highlight() const { diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview_p.h b/src/declarative/graphicsitems/qmlgraphicsgridview_p.h index 3fd36bd..3e09cf3 100644 --- a/src/declarative/graphicsitems/qmlgraphicsgridview_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsgridview_p.h @@ -62,8 +62,11 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsGridView : public QmlGraphicsFlickable Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) Q_PROPERTY(QmlGraphicsItem *currentItem READ currentItem NOTIFY currentIndexChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) + Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) + Q_PROPERTY(QmlGraphicsItem *highlightItem READ highlightItem NOTIFY highlightChanged) Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) + Q_PROPERTY(Flow flow READ flow WRITE setFlow) Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) @@ -85,6 +88,7 @@ public: void setCurrentIndex(int idx); QmlGraphicsItem *currentItem(); + QmlGraphicsItem *highlightItem(); int count() const; QmlComponent *highlight() const; @@ -123,6 +127,7 @@ Q_SIGNALS: void currentIndexChanged(); void cellWidthChanged(); void cellHeightChanged(); + void highlightChanged(); protected: virtual void viewportMoved(); diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index 53287a6..12bf0d8 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -641,6 +641,7 @@ void QmlGraphicsListViewPrivate::updateTrackedItem() void QmlGraphicsListViewPrivate::createHighlight() { Q_Q(QmlGraphicsListView); + bool changed = false; if (highlight) { if (trackedItem == highlight) trackedItem = 0; @@ -651,6 +652,7 @@ void QmlGraphicsListViewPrivate::createHighlight() delete highlightSizeAnimator; highlightPosAnimator = 0; highlightSizeAnimator = 0; + changed = true; } if (currentItem) { @@ -687,8 +689,11 @@ void QmlGraphicsListViewPrivate::createHighlight() highlightSizeAnimator->setVelocity(highlightResizeSpeed); highlightSizeAnimator->setTarget(QmlMetaProperty(highlight->item, sizeProp)); highlightSizeAnimator->setEnabled(autoHighlight); + changed = true; } } + if (changed) + emit q->highlightChanged(); } void QmlGraphicsListViewPrivate::updateHighlight() @@ -871,7 +876,7 @@ void QmlGraphicsListViewPrivate::flickX(qreal velocity) if (v > 0) dist = -dist; dist = -_moveX.value() - snapPosAt(-(_moveX.value() - highlightRangeStart) + dist) + highlightRangeStart; - if (v < 0 && dist >= 0 || v > 0 && dist <= 0) { + if ((v < 0 && dist >= 0) || (v > 0 && dist <= 0)) { timeline.reset(_moveX); fixupX(); return; @@ -929,7 +934,7 @@ void QmlGraphicsListViewPrivate::flickY(qreal velocity) if (v > 0) dist = -dist; dist = -_moveY.value() - snapPosAt(-(_moveY.value() - highlightRangeStart) + dist) + highlightRangeStart; - if (v < 0 && dist >= 0 || v > 0 && dist <= 0) { + if ((v < 0 && dist >= 0) || (v > 0 && dist <= 0)) { timeline.reset(_moveY); fixupY(); return; @@ -1202,6 +1207,25 @@ QmlGraphicsItem *QmlGraphicsListView::currentItem() } /*! + \qmlproperty Item ListView::highlightItem + + \c highlightItem holds the highlight item, which was created + from the \l highlight component. + + The highlightItem is managed by the view unless + \l highlightFollowsCurrentItem is set to false. + + \sa highlight, highlightFollowsCurrentItem +*/ +QmlGraphicsItem *QmlGraphicsListView::highlightItem() +{ + Q_D(QmlGraphicsListView); + if (!d->highlight) + return 0; + return d->highlight->item; +} + +/*! \qmlproperty int ListView::count This property holds the number of items in the view. */ @@ -1228,7 +1252,7 @@ int QmlGraphicsListView::count() const \snippet doc/src/snippets/declarative/listview/listview.qml 1 \image trivialListView.png - \sa highlightFollowsCurrentItem + \sa highlightItem, highlightFollowsCurrentItem */ QmlComponent *QmlGraphicsListView::highlight() const { diff --git a/src/declarative/graphicsitems/qmlgraphicslistview_p.h b/src/declarative/graphicsitems/qmlgraphicslistview_p.h index 3f46434..b8a6e1f 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview_p.h +++ b/src/declarative/graphicsitems/qmlgraphicslistview_p.h @@ -66,6 +66,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsListView : public QmlGraphicsFlickable Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) + Q_PROPERTY(QmlGraphicsItem *highlightItem READ highlightItem NOTIFY highlightChanged) Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) Q_PROPERTY(qreal highlightMoveSpeed READ highlightMoveSpeed WRITE setHighlightMoveSpeed NOTIFY highlightMoveSpeedChanged) Q_PROPERTY(qreal highlightResizeSpeed READ highlightResizeSpeed WRITE setHighlightResizeSpeed NOTIFY highlightResizeSpeedChanged) @@ -99,6 +100,7 @@ public: void setCurrentIndex(int idx); QmlGraphicsItem *currentItem(); + QmlGraphicsItem *highlightItem(); int count() const; QmlComponent *highlight() const; @@ -155,6 +157,7 @@ Q_SIGNALS: void sectionExpressionChanged(); void highlightMoveSpeedChanged(); void highlightResizeSpeedChanged(); + void highlightChanged(); protected: virtual void viewportMoved(); diff --git a/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp b/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp index 7c32d14..f89e02f 100644 --- a/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp +++ b/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp @@ -534,9 +534,12 @@ void tst_QmlGraphicsGridView::currentIndex() QmlGraphicsItem *viewport = gridview->viewport(); QVERIFY(viewport != 0); + QTest::qWait(500); + // current item should be third item QCOMPARE(gridview->currentIndex(), 5); QCOMPARE(gridview->currentItem(), findItem(viewport, "wrapper", 5)); + QCOMPARE(gridview->currentItem()->y(), gridview->highlightItem()->y()); gridview->moveCurrentIndexRight(); QCOMPARE(gridview->currentIndex(), 6); @@ -605,6 +608,20 @@ void tst_QmlGraphicsGridView::currentIndex() QVERIFY(key.isAccepted()); QCOMPARE(gridview->currentIndex(), 0); + // turn off auto highlight + gridview->setHighlightFollowsCurrentItem(false); + QVERIFY(gridview->highlightFollowsCurrentItem() == false); + + QTest::qWait(500); + QVERIFY(gridview->highlightItem()); + qreal hlPosX = gridview->highlightItem()->x(); + qreal hlPosY = gridview->highlightItem()->y(); + + gridview->setCurrentIndex(5); + QTest::qWait(500); + QCOMPARE(gridview->highlightItem()->x(), hlPosX); + QCOMPARE(gridview->highlightItem()->y(), hlPosY); + delete canvas; } diff --git a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp index 2e797d8..a4949eb 100644 --- a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp +++ b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp @@ -800,9 +800,12 @@ void tst_QmlGraphicsListView::currentIndex() QmlGraphicsItem *viewport = listview->viewport(); QVERIFY(viewport != 0); + QTest::qWait(500); + // current item should be third item QCOMPARE(listview->currentIndex(), 3); QCOMPARE(listview->currentItem(), findItem(viewport, "wrapper", 3)); + QCOMPARE(listview->highlightItem()->y(), listview->currentItem()->y()); // no wrap listview->setCurrentIndex(0); @@ -851,6 +854,18 @@ void tst_QmlGraphicsListView::currentIndex() QVERIFY(key.isAccepted()); QCOMPARE(listview->currentIndex(), 0); + // turn off auto highlight + listview->setHighlightFollowsCurrentItem(false); + QVERIFY(listview->highlightFollowsCurrentItem() == false); + + QTest::qWait(500); + QVERIFY(listview->highlightItem()); + qreal hlPos = listview->highlightItem()->y(); + + listview->setCurrentIndex(4); + QTest::qWait(500); + QCOMPARE(listview->highlightItem()->y(), hlPos); + delete canvas; } -- cgit v0.12