on xenial help sign in
Implement+test the maximizeVisibleArea function
2074cdaAlbert Astals
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+55−13
@@ -160,16 +160,16 @@ ListViewWithPageHeader::ListViewWithPageHeader()
160// m_clipItem = new QQuickRectangle(contentItem());
160// m_clipItem = new QQuickRectangle(contentItem());
161// ((QQuickRectangle*)m_clipItem)->setColor(Qt::gray);
161// ((QQuickRectangle*)m_clipItem)->setColor(Qt::gray);
162
162
163− m_headerShowAnimation = new QQuickNumberAnimation(this);
163+ m_contentYAnimation = new QQuickNumberAnimation(this);
164− m_headerShowAnimation->setEasing(QEasingCurve::OutQuad);
164+ m_contentYAnimation->setEasing(QEasingCurve::OutQuad);
165− m_headerShowAnimation->setProperty("contentY");
165+ m_contentYAnimation->setProperty("contentY");
166− m_headerShowAnimation->setDuration(200);
166+ m_contentYAnimation->setDuration(200);
167− m_headerShowAnimation->setTargetObject(this);
167+ m_contentYAnimation->setTargetObject(this);
168
168
169 connect(this, SIGNAL(contentWidthChanged()), this, SLOT(onContentWidthChanged()));
169 connect(this, SIGNAL(contentWidthChanged()), this, SLOT(onContentWidthChanged()));
170 connect(this, SIGNAL(contentHeightChanged()), this, SLOT(onContentHeightChanged()));
170 connect(this, SIGNAL(contentHeightChanged()), this, SLOT(onContentHeightChanged()));
171 connect(this, SIGNAL(heightChanged()), this, SLOT(onHeightChanged()));
171 connect(this, SIGNAL(heightChanged()), this, SLOT(onHeightChanged()));
172− connect(m_headerShowAnimation, SIGNAL(stopped()), this, SLOT(onShowHeaderAnimationFinished()));
172+ connect(m_contentYAnimation, SIGNAL(stopped()), this, SLOT(onShowHeaderAnimationFinished()));
173}
173}
174
174
175ListViewWithPageHeader::~ListViewWithPageHeader()
175ListViewWithPageHeader::~ListViewWithPageHeader()
@@ -374,11 +374,48 @@ void ListViewWithPageHeader::showHeader()
374 layout();
374 layout();
375 }
375 }
376 }
376 }
377− m_headerShowAnimation->setTo(to);
377+ m_contentYAnimation->setTo(to);
378− m_headerShowAnimation->start();
378+ contentYAnimationType = ContentYAnimationShowHeader;
379+ m_contentYAnimation->start();
379 }
380 }
380}
381}
381
382
383+bool ListViewWithPageHeader::maximizeVisibleArea(int modelIndex)
384+{
385+ ListItem *listItem = itemAtIndex(modelIndex);
386+ if (listItem)
387+ {
388+ const auto listItemY = m_clipItem->y() + listItem->y();
389+ if (listItemY > contentY() && listItemY + listItem->height() > contentY() + height()) {
390+ // we can scroll the list up to show more stuff
391+ const auto to = qMin(listItemY, listItemY + listItem->height() - height());
392+ m_contentYAnimation->setTo(to);
393+ contentYAnimationType = ContentYAnimationMaximizeVisibleArea;
394+ m_contentYAnimation->start();
395+ } else if ((listItemY < contentY() && listItemY + listItem->height() < contentY() + height()) ||
396+ (m_topSectionItem && !listItem->m_sectionItem && listItemY - m_topSectionItem->height() < contentY() && listItemY + listItem->height() < contentY() + height()))
397+ {
398+ // we can scroll the list down to show more stuff
399+ auto realVisibleListItemY = listItemY;
400+ if (m_topSectionItem) {
401+ // If we are showing the top section sticky item and this item doesn't have a section
402+ // item we have to make sure to scroll it a bit more so that it is not underlapping
403+ // the top section sticky item
404+ bool topSectionShown = !QQuickItemPrivate::get(m_topSectionItem)->culled;
405+ if (topSectionShown && !listItem->m_sectionItem) {
406+ realVisibleListItemY -= m_topSectionItem->height();
407+ }
408+ }
409+ const auto to = qMax(realVisibleListItemY, listItemY + listItem->height() - height());
410+ m_contentYAnimation->setTo(to);
411+ contentYAnimationType = ContentYAnimationMaximizeVisibleArea;
412+ m_contentYAnimation->start();
413+ }
414+ return true;
415+ }
416+ return false;
417+}
418+
382qreal ListViewWithPageHeader::minYExtent() const
419qreal ListViewWithPageHeader::minYExtent() const
383{
420{
384// qDebug() << "ListViewWithPageHeader::minYExtent" << m_minYExtent;
421// qDebug() << "ListViewWithPageHeader::minYExtent" << m_minYExtent;
@@ -400,6 +437,7 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
400 QQuickFlickable::viewportMoved(orient);
437 QQuickFlickable::viewportMoved(orient);
401// qDebug() << "ListViewWithPageHeader::viewportMoved" << contentY();
438// qDebug() << "ListViewWithPageHeader::viewportMoved" << contentY();
402 qreal diff = m_previousContentY - contentY();
439 qreal diff = m_previousContentY - contentY();
440+ const bool showHeaderAnimationRunning = m_contentYAnimation->isRunning() && contentYAnimationType == ContentYAnimationShowHeader;
403 if (m_headerItem) {
441 if (m_headerItem) {
404 auto oldHeaderItemShownHeight = m_headerItemShownHeight;
442 auto oldHeaderItemShownHeight = m_headerItemShownHeight;
405 if (contentY() < -m_minYExtent) {
443 if (contentY() < -m_minYExtent) {
@@ -410,16 +448,20 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
410 m_headerItem->setHeight(m_headerItem->implicitHeight());
448 m_headerItem->setHeight(m_headerItem->implicitHeight());
411 // We are going down (but it's not because of the rebound at the end)
449 // We are going down (but it's not because of the rebound at the end)
412 // (but the header was not shown by it's own position)
450 // (but the header was not shown by it's own position)
413− // or the header is partially shown
451+ // or the header is partially shown and we are not doing a maximizeVisibleArea either
414 const bool scrolledUp = m_previousContentY > contentY();
452 const bool scrolledUp = m_previousContentY > contentY();
415 const bool notRebounding = contentY() + height() < contentHeight();
453 const bool notRebounding = contentY() + height() < contentHeight();
416 const bool notShownByItsOwn = contentY() + diff > m_headerItem->y() + m_headerItem->height();
454 const bool notShownByItsOwn = contentY() + diff > m_headerItem->y() + m_headerItem->height();
455+ const bool maximizeVisibleAreaRunning = m_contentYAnimation->isRunning() && contentYAnimationType == ContentYAnimationMaximizeVisibleArea;
417
456
418 if (!scrolledUp && contentY() == -m_minYExtent) {
457 if (!scrolledUp && contentY() == -m_minYExtent) {
419 m_headerItemShownHeight = 0;
458 m_headerItemShownHeight = 0;
420 m_headerItem->setY(contentY());
459 m_headerItem->setY(contentY());
421− } else if ((scrolledUp && notRebounding && notShownByItsOwn) || (m_headerItemShownHeight > 0)) {
460+ } else if ((scrolledUp && notRebounding && notShownByItsOwn && !maximizeVisibleAreaRunning) || (m_headerItemShownHeight > 0)) {
461+ if (maximizeVisibleAreaRunning && diff > 0) // If we are maximizing and the header was shown, make sure we hide it
462+ m_headerItemShownHeight -= diff;
463+ else
422− m_headerItemShownHeight += diff;
464+ m_headerItemShownHeight += diff;
423 if (contentY() == -m_minYExtent) {
465 if (contentY() == -m_minYExtent) {
424 m_headerItemShownHeight = 0;
466 m_headerItemShownHeight = 0;
425 } else {
467 } else {
@@ -435,7 +477,7 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
435 // We will be changing the clip item, need to accomadate for it
477 // We will be changing the clip item, need to accomadate for it
436 // otherwise we move the firstItem down/up twice (unless the
478 // otherwise we move the firstItem down/up twice (unless the
437 // show header animation is running, where we want to keep the viewport stable)
479 // show header animation is running, where we want to keep the viewport stable)
438− if (!m_headerShowAnimation->isRunning()) {
480+ if (!showHeaderAnimationRunning) {
439 diff += oldHeaderItemShownHeight - m_headerItemShownHeight;
481 diff += oldHeaderItemShownHeight - m_headerItemShownHeight;
440 } else {
482 } else {
441 diff = -diff;
483 diff = -diff;
@@ -445,7 +487,7 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
445 updateClipItem();
487 updateClipItem();
446 ListItem *firstItem = m_visibleItems.first();
488 ListItem *firstItem = m_visibleItems.first();
447 firstItem->setY(firstItem->y() + diff);
489 firstItem->setY(firstItem->y() + diff);
448− if (m_headerShowAnimation->isRunning()) {
490+ if (showHeaderAnimationRunning) {
449 adjustMinYExtent();
491 adjustMinYExtent();
450 }
492 }
451 }
493 }
plugins/ListViewWithPageHeader/listviewwithpageheader.h+8−1
@@ -89,6 +89,11 @@ public:
89 Q_INVOKABLE void positionAtBeginning();
89 Q_INVOKABLE void positionAtBeginning();
90 Q_INVOKABLE void showHeader();
90 Q_INVOKABLE void showHeader();
91
91
92+ // The index has to be created for this to try to do something
93+ // Created items are those visible and the precached ones
94+ // Returns if the item existed or not
95+ Q_INVOKABLE bool maximizeVisibleArea(int modelIndex);
96+
92Q_SIGNALS:
97Q_SIGNALS:
93 void modelChanged();
98 void modelChanged();
94 void delegateChanged();
99 void delegateChanged();
@@ -182,7 +187,9 @@ private:
182 qreal m_previousContentY;
187 qreal m_previousContentY;
183 qreal m_headerItemShownHeight; // The height of header shown when the header is shown outside its topmost position
188 qreal m_headerItemShownHeight; // The height of header shown when the header is shown outside its topmost position
184 // i.e. it's being shown after dragging down in the middle of the list
189 // i.e. it's being shown after dragging down in the middle of the list
190+ enum ContentYAnimationType { ContentYAnimationShowHeader, ContentYAnimationMaximizeVisibleArea };
191+ ContentYAnimationType contentYAnimationType;
185− QQuickNumberAnimation *m_headerShowAnimation;
192+ QQuickNumberAnimation *m_contentYAnimation;
186
193
187 QQmlComponent *m_sectionDelegate;
194 QQmlComponent *m_sectionDelegate;
188 QString m_sectionProperty;
195 QString m_sectionProperty;
tests/plugins/ListViewWithPageHeader/listviewwithpageheadertest.cpp+206−3
@@ -1245,7 +1245,7 @@ private Q_SLOTS:
1245
1245
1246 lvwph->showHeader();
1246 lvwph->showHeader();
1247
1247
1248− QTRY_VERIFY(!lvwph->m_headerShowAnimation->isRunning());
1248+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1249 QTRY_COMPARE(lvwph->m_visibleItems.count(), 5);
1249 QTRY_COMPARE(lvwph->m_visibleItems.count(), 5);
1250 QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1250 QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1251 verifyItem(0, -375., 150., true);
1251 verifyItem(0, -375., 150., true);
@@ -1301,7 +1301,7 @@ private Q_SLOTS:
1301
1301
1302 lvwph->showHeader();
1302 lvwph->showHeader();
1303
1303
1304− QTRY_VERIFY(!lvwph->m_headerShowAnimation->isRunning());
1304+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1305 QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
1305 QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
1306 QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1306 QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1307 verifyItem(0, -20., 150., false);
1307 verifyItem(0, -20., 150., false);
@@ -1339,7 +1339,7 @@ private Q_SLOTS:
1339
1339
1340 lvwph->showHeader();
1340 lvwph->showHeader();
1341
1341
1342− QTRY_VERIFY(!lvwph->m_headerShowAnimation->isRunning());
1342+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1343 QTRY_VERIFY (lvwph->isAtYEnd());
1343 QTRY_VERIFY (lvwph->isAtYEnd());
1344 }
1344 }
1345
1345
@@ -1409,6 +1409,209 @@ private Q_SLOTS:
1409 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1409 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1410 }
1410 }
1411
1411
1412+ void testMaximizeVisibleArea()
1413+ {
1414+ bool res = lvwph->maximizeVisibleArea(2);
1415+ QVERIFY(res);
1416+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1417+
1418+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
1419+ QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1420+ verifyItem(0, -158., 150., true);
1421+ verifyItem(1, -8., 200., false);
1422+ verifyItem(2, 192, 350., false);
1423+ verifyItem(3, 542, 350., true);
1424+ QCOMPARE(lvwph->m_minYExtent, 0.);
1425+ QCOMPARE(lvwph->m_clipItem->y(), 208.);
1426+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1427+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1428+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1429+ QCOMPARE(lvwph->contentY(), 208.);
1430+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1431+ }
1432+
1433+ void testMaximizeVisibleAreaVisibleItems()
1434+ {
1435+ bool res = lvwph->maximizeVisibleArea(0);
1436+ QVERIFY(res);
1437+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1438+
1439+ verifyInitialTopPosition();
1440+
1441+ res = lvwph->maximizeVisibleArea(1);
1442+ QVERIFY(res);
1443+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1444+
1445+ verifyInitialTopPosition();
1446+ }
1447+
1448+ void testMaximizeVisibleAreaInvalidIndexes()
1449+ {
1450+ bool res = lvwph->maximizeVisibleArea(-1);
1451+ QVERIFY(!res);
1452+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1453+
1454+ verifyInitialTopPosition();
1455+
1456+ res = lvwph->maximizeVisibleArea(1000);
1457+ QVERIFY(!res);
1458+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1459+
1460+ verifyInitialTopPosition();
1461+
1462+ res = lvwph->maximizeVisibleArea(4);
1463+ QVERIFY(!res);
1464+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1465+
1466+ verifyInitialTopPosition();
1467+ }
1468+
1469+ void testMaximizeVisibleAreaBigElement()
1470+ {
1471+ model->setProperty(2, "size", 4000);
1472+ bool res = lvwph->maximizeVisibleArea(2);
1473+ QVERIFY(res);
1474+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1475+
1476+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 3);
1477+ QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1478+ verifyItem(0, -350., 150., true);
1479+ verifyItem(1, -200., 200., true);
1480+ verifyItem(2, 0, 4000., false);
1481+ QCOMPARE(lvwph->m_minYExtent, 0.);
1482+ QCOMPARE(lvwph->m_clipItem->y(), 400.);
1483+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1484+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1485+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1486+ QCOMPARE(lvwph->contentY(), 400.);
1487+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1488+ }
1489+
1490+ void testMaximizeVisibleAreaScrollDown()
1491+ {
1492+ changeContentY(250);
1493+ bool res = lvwph->maximizeVisibleArea(1);
1494+ QVERIFY(res);
1495+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1496+
1497+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
1498+ QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1499+ verifyItem(0, -150., 150., true);
1500+ verifyItem(1, 0., 200., false);
1501+ verifyItem(2, 200, 350., false);
1502+ verifyItem(3, 550, 350., true);
1503+ QCOMPARE(lvwph->m_minYExtent, 0.);
1504+ QCOMPARE(lvwph->m_clipItem->y(), 200.);
1505+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1506+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1507+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1508+ QCOMPARE(lvwph->contentY(), 200.);
1509+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1510+ }
1511+
1512+ void testMaximizeVisibleAreaScrollDownBigElement()
1513+ {
1514+ model->setProperty(1, "size", 1000);
1515+ changeContentY(1150);
1516+ bool res = lvwph->maximizeVisibleArea(1);
1517+ QVERIFY(res);
1518+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1519+
1520+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 2);
1521+ QCOMPARE(lvwph->m_firstVisibleIndex, 1);
1522+ verifyItem(0, -458., 1000., false);
1523+ verifyItem(1, 542., 350., true);
1524+ QCOMPARE(lvwph->m_minYExtent, 362.5);
1525+ QCOMPARE(lvwph->m_clipItem->y(), 658.);
1526+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1527+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1528+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1529+ QCOMPARE(lvwph->contentY(), 658.);
1530+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1531+ }
1532+
1533+ void testMaximizeVisibleAreaBigElementInTheMiddle()
1534+ {
1535+ model->setProperty(1, "size", 1000);
1536+ changeContentY(650);
1537+
1538+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 2);
1539+ QCOMPARE(lvwph->m_firstVisibleIndex, 1);
1540+ verifyItem(0, -450., 1000., false);
1541+ verifyItem(1, 550., 350., true);
1542+ QCOMPARE(lvwph->m_minYExtent, 525.);
1543+ QCOMPARE(lvwph->m_clipItem->y(), 650.);
1544+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1545+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1546+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1547+ QCOMPARE(lvwph->contentY(), 650.);
1548+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1549+
1550+ bool res = lvwph->maximizeVisibleArea(1);
1551+ QVERIFY(res);
1552+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1553+
1554+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 2);
1555+ QCOMPARE(lvwph->m_firstVisibleIndex, 1);
1556+ verifyItem(0, -450., 1000., false);
1557+ verifyItem(1, 550., 350., true);
1558+ QCOMPARE(lvwph->m_minYExtent, 525.);
1559+ QCOMPARE(lvwph->m_clipItem->y(), 650.);
1560+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1561+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1562+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1563+ QCOMPARE(lvwph->contentY(), 650.);
1564+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1565+ }
1566+
1567+ void testMaximizeVisibleAreaTopWithHalfPageHeader()
1568+ {
1569+ changeContentY(430);
1570+ changeContentY(-30);
1571+
1572+ bool res = lvwph->maximizeVisibleArea(1);
1573+ QVERIFY(res);
1574+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1575+
1576+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
1577+ QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1578+ verifyItem(0, -150., 150., true);
1579+ verifyItem(1, 0., 200., false);
1580+ verifyItem(2, 200, 350., false);
1581+ verifyItem(3, 550, 350., true);
1582+ QCOMPARE(lvwph->m_minYExtent, 0.);
1583+ QCOMPARE(lvwph->m_clipItem->y(), 200.);
1584+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1585+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1586+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1587+ QCOMPARE(lvwph->contentY(), 200.);
1588+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1589+ }
1590+
1591+ void testMaximizeVisibleAreaBottomWithHalfPageHeader()
1592+ {
1593+ changeContentY(430);
1594+ changeContentY(-30);
1595+
1596+ bool res = lvwph->maximizeVisibleArea(3);
1597+ QVERIFY(res);
1598+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1599+
1600+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
1601+ QCOMPARE(lvwph->m_firstVisibleIndex, 1);
1602+ verifyItem(0, -358., 200., true);
1603+ verifyItem(1, -158., 350., false);
1604+ verifyItem(2, 192, 350., false);
1605+ verifyItem(3, 542, 350., true);
1606+ QCOMPARE(lvwph->m_minYExtent, 162.5);
1607+ QCOMPARE(lvwph->m_clipItem->y(), 558.);
1608+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1609+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1610+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1611+ QCOMPARE(lvwph->contentY(), 558.);
1612+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1613+ }
1614+
1412private:
1615private:
1413 QQuickView *view;
1616 QQuickView *view;
1414 ListViewWithPageHeader *lvwph;
1617 ListViewWithPageHeader *lvwph;
tests/plugins/ListViewWithPageHeader/listviewwithpageheadertestsection.cpp+280−3
@@ -1506,7 +1506,7 @@ private Q_SLOTS:
1506
1506
1507 lvwph->showHeader();
1507 lvwph->showHeader();
1508
1508
1509− QTRY_VERIFY(!lvwph->m_headerShowAnimation->isRunning());
1509+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1510 QTRY_COMPARE(lvwph->m_visibleItems.count(), 3);
1510 QTRY_COMPARE(lvwph->m_visibleItems.count(), 3);
1511 QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1511 QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1512 verifyItem(0, -20., 190., false, "Agressive", true);
1512 verifyItem(0, -20., 190., false, "Agressive", true);
@@ -1565,7 +1565,7 @@ private Q_SLOTS:
1565
1565
1566 lvwph->showHeader();
1566 lvwph->showHeader();
1567
1567
1568− QTRY_VERIFY(!lvwph->m_headerShowAnimation->isRunning());
1568+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1569 QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
1569 QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
1570 QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1570 QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1571 verifyItem(0, -375., 190., true, "Agressive", true);
1571 verifyItem(0, -375., 190., true, "Agressive", true);
@@ -1607,7 +1607,7 @@ private Q_SLOTS:
1607
1607
1608 lvwph->showHeader();
1608 lvwph->showHeader();
1609
1609
1610− QTRY_VERIFY(!lvwph->m_headerShowAnimation->isRunning());
1610+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1611 QTRY_VERIFY (lvwph->isAtYEnd());
1611 QTRY_VERIFY (lvwph->isAtYEnd());
1612 }
1612 }
1613
1613
@@ -1755,6 +1755,283 @@ private Q_SLOTS:
1755 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1755 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1756 }
1756 }
1757
1757
1758+ void testMaximizeVisibleArea()
1759+ {
1760+ bool res = lvwph->maximizeVisibleArea(2);
1761+ QVERIFY(res);
1762+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1763+
1764+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
1765+ QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1766+ verifyItem(0, -278., 190., true, "Agressive", true);
1767+ verifyItem(1, -88., 240., false, "Regular", true);
1768+ verifyItem(2, 152, 390., false, "Mild", false);
1769+ verifyItem(3, 542, 390., true, "Bold", true);
1770+ QCOMPARE(lvwph->m_minYExtent, 0.);
1771+ QCOMPARE(lvwph->m_clipItem->y(), 328.);
1772+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1773+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1774+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1775+ QCOMPARE(lvwph->contentY(), 328.);
1776+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1777+ QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1778+ QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
1779+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
1780+ QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1781+ }
1782+
1783+ void testMaximizeVisibleAreaVisibleItems()
1784+ {
1785+ bool res = lvwph->maximizeVisibleArea(0);
1786+ QVERIFY(res);
1787+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1788+
1789+ verifyInitialTopPosition();
1790+
1791+ res = lvwph->maximizeVisibleArea(1);
1792+ QVERIFY(res);
1793+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1794+
1795+ verifyInitialTopPosition();
1796+ }
1797+
1798+ void testMaximizeVisibleAreaInvalidIndexes()
1799+ {
1800+ bool res = lvwph->maximizeVisibleArea(-1);
1801+ QVERIFY(!res);
1802+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1803+
1804+ verifyInitialTopPosition();
1805+
1806+ res = lvwph->maximizeVisibleArea(1000);
1807+ QVERIFY(!res);
1808+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1809+
1810+ verifyInitialTopPosition();
1811+
1812+ res = lvwph->maximizeVisibleArea(3);
1813+ QVERIFY(!res);
1814+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1815+
1816+ verifyInitialTopPosition();
1817+ }
1818+
1819+ void testMaximizeVisibleAreaBigElement()
1820+ {
1821+ model->setProperty(2, "size", 4000);
1822+ verifyItem(2, 480, 4040., false, "Mild", false);
1823+
1824+ bool res = lvwph->maximizeVisibleArea(2);
1825+ QVERIFY(res);
1826+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1827+
1828+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 3);
1829+ QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1830+ verifyItem(0, -430., 190., true, "Agressive", true);
1831+ verifyItem(1, -240., 240., true, "Regular", true);
1832+ verifyItem(2, 0, 4040., false, "Mild", false);
1833+ QCOMPARE(lvwph->m_minYExtent, 0.);
1834+ QCOMPARE(lvwph->m_clipItem->y(), 480.);
1835+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1836+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1837+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1838+ QCOMPARE(lvwph->contentY(), 480.);
1839+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1840+ QVERIFY(QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1841+ }
1842+
1843+ void testMaximizeVisibleAreaScrollDown()
1844+ {
1845+ changeContentY(350);
1846+ bool res = lvwph->maximizeVisibleArea(1);
1847+ QVERIFY(res);
1848+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1849+
1850+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
1851+ QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1852+ verifyItem(0, -190., 190., true, "Agressive", true);
1853+ verifyItem(1, 0., 240., false, "Regular", false);
1854+ verifyItem(2, 240, 390., false, "Mild", false);
1855+ verifyItem(3, 630, 390., true, "Bold", true);
1856+ QCOMPARE(lvwph->m_minYExtent, 0.);
1857+ QCOMPARE(lvwph->m_clipItem->y(), 240.);
1858+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1859+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1860+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1861+ QCOMPARE(lvwph->contentY(), 240.);
1862+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1863+ QVERIFY(QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1864+ }
1865+
1866+ void testMaximizeVisibleAreaScrollDownBigElement()
1867+ {
1868+ model->setProperty(1, "size", 1000);
1869+ changeContentY(1150);
1870+ bool res = lvwph->maximizeVisibleArea(1);
1871+ QVERIFY(res);
1872+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1873+
1874+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 2);
1875+ QCOMPARE(lvwph->m_firstVisibleIndex, 1);
1876+ verifyItem(0, -498., 1040., false, "Regular", true);
1877+ verifyItem(1, 542., 390., true, "Mild", true);
1878+ QCOMPARE(lvwph->m_minYExtent, 1250/3.);
1879+ QCOMPARE(lvwph->m_clipItem->y(), 738.);
1880+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1881+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1882+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1883+ QCOMPARE(lvwph->contentY(), 738.);
1884+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1885+ QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1886+ QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
1887+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
1888+ QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1889+ }
1890+
1891+ void testMaximizeVisibleAreaBigElementInTheMiddle()
1892+ {
1893+ model->setProperty(1, "size", 1000);
1894+ changeContentY(650);
1895+
1896+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 2);
1897+ QCOMPARE(lvwph->m_firstVisibleIndex, 1);
1898+ verifyItem(0, -410., 1040., false, "Regular", true);
1899+ verifyItem(1, 630., 390., true, "Mild", true);
1900+ QCOMPARE(lvwph->m_minYExtent, 525.);
1901+ QCOMPARE(lvwph->m_clipItem->y(), 650.);
1902+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1903+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1904+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1905+ QCOMPARE(lvwph->contentY(), 650.);
1906+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1907+ QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1908+ QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
1909+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
1910+ QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1911+
1912+ bool res = lvwph->maximizeVisibleArea(1);
1913+ QVERIFY(res);
1914+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1915+
1916+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 2);
1917+ QCOMPARE(lvwph->m_firstVisibleIndex, 1);
1918+ verifyItem(0, -410., 1040., false, "Regular", true);
1919+ verifyItem(1, 630., 390., true, "Mild", true);
1920+ QCOMPARE(lvwph->m_minYExtent, 525.);
1921+ QCOMPARE(lvwph->m_clipItem->y(), 650.);
1922+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1923+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1924+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1925+ QCOMPARE(lvwph->contentY(), 650.);
1926+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1927+ QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1928+ QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
1929+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
1930+ QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1931+ }
1932+
1933+ void testMaximizeVisibleAreaTopWithHalfPageHeader()
1934+ {
1935+ changeContentY(430);
1936+ changeContentY(-30);
1937+
1938+ bool res = lvwph->maximizeVisibleArea(1);
1939+ QVERIFY(res);
1940+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1941+
1942+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
1943+ QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1944+ verifyItem(0, -190., 190., true, "Agressive", true);
1945+ verifyItem(1, 0., 240., false, "Regular", false);
1946+ verifyItem(2, 240, 390., false, "Mild", false);
1947+ verifyItem(3, 630, 390., true, "Bold", true);
1948+ QCOMPARE(lvwph->m_minYExtent, 0.);
1949+ QCOMPARE(lvwph->m_clipItem->y(), 240.);
1950+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1951+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1952+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1953+ QCOMPARE(lvwph->contentY(), 240.);
1954+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1955+ QVERIFY(QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1956+ }
1957+
1958+ void testMaximizeVisibleAreaBottomWithHalfPageHeader()
1959+ {
1960+ changeContentY(430);
1961+ changeContentY(-30);
1962+
1963+ bool res = lvwph->maximizeVisibleArea(3);
1964+ QVERIFY(res);
1965+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1966+
1967+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
1968+ QCOMPARE(lvwph->m_firstVisibleIndex, 1);
1969+ verifyItem(0, -478., 240., true, "Regular", true);
1970+ verifyItem(1, -238., 390., false, "Mild", true);
1971+ verifyItem(2, 152, 390., false, "Bold", false);
1972+ verifyItem(3, 542, 350., true, QString(), true);
1973+ QCOMPARE(lvwph->m_minYExtent, 152.5);
1974+ QCOMPARE(lvwph->m_clipItem->y(), 718.);
1975+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1976+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1977+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1978+ QCOMPARE(lvwph->contentY(), 718.);
1979+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1980+ QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1981+ QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1982+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
1983+ QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1984+ }
1985+
1986+ void testMaximizeVisibleAreaTopSecondSectionItemStickySection()
1987+ {
1988+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 0), Q_ARG(QVariant, 100), Q_ARG(QVariant, "Agressive"));
1989+ changeContentY(250);
1990+ bool res = lvwph->maximizeVisibleArea(1);
1991+ QVERIFY(res);
1992+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1993+
1994+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
1995+ QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1996+ verifyItem(0, -100., 140., false, "Agressive", true);
1997+ verifyItem(1, 40., 150., false, QString(), true);
1998+ verifyItem(2, 190, 240., false, "Regular", false);
1999+ verifyItem(3, 430, 390., false, "Mild", false);
2000+ QCOMPARE(lvwph->m_minYExtent, 0.);
2001+ QCOMPARE(lvwph->m_clipItem->y(), 150.);
2002+ QCOMPARE(lvwph->m_clipItem->clip(), false);
2003+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
2004+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
2005+ QCOMPARE(lvwph->contentY(), 150.);
2006+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
2007+ QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
2008+ QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
2009+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 0);
2010+ QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
2011+
2012+ changeContentY(20);
2013+ res = lvwph->maximizeVisibleArea(1);
2014+ QVERIFY(res);
2015+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
2016+
2017+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
2018+ QCOMPARE(lvwph->m_firstVisibleIndex, 0);
2019+ verifyItem(0, -100., 140., false, "Agressive", true);
2020+ verifyItem(1, 40., 150., false, QString(), true);
2021+ verifyItem(2, 190, 240., false, "Regular", false);
2022+ verifyItem(3, 430, 390., false, "Mild", false);
2023+ QCOMPARE(lvwph->m_minYExtent, 0.);
2024+ QCOMPARE(lvwph->m_clipItem->y(), 150.);
2025+ QCOMPARE(lvwph->m_clipItem->clip(), false);
2026+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
2027+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
2028+ QCOMPARE(lvwph->contentY(), 150.);
2029+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
2030+ QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
2031+ QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
2032+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 0);
2033+ QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
2034+ }
1758
2035
1759private:
2036private:
1760 QQuickView *view;
2037 QQuickView *view;