on xenial help sign in
Implement+test the maximizeVisibleArea function

Tries to show as much possible of an index that is already shown on screen Will be used for the dash category expansion. Approved by PS Jenkins bot, Gerry Boland.

commit2074cdae316ab89569f5acab51d0cd85a55a39de authorAlbert Astals <albert.astals@canonical.com> dateThu 8 Aug 2013, 14:44 (13 years ago) parentdbafbfa0690015
4 files changed+549−20
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+55−13 plugins/ListViewWithPageHeader/listviewwithpageheader.h+8−1 tests/plugins/ListViewWithPageHeader/listviewwithpageheadertest.cpp+206−3 tests/plugins/ListViewWithPageHeader/listviewwithpageheadertestsection.cpp+280−3
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+55−13
@@ -160,16 +160,16 @@ ListViewWithPageHeader::ListViewWithPageHeader()
160160// m_clipItem = new QQuickRectangle(contentItem());
161161// ((QQuickRectangle*)m_clipItem)->setColor(Qt::gray);
162162
163− m_headerShowAnimation = new QQuickNumberAnimation(this);
164− m_headerShowAnimation->setEasing(QEasingCurve::OutQuad);
165− m_headerShowAnimation->setProperty("contentY");
166− m_headerShowAnimation->setDuration(200);
167− m_headerShowAnimation->setTargetObject(this);
163+ m_contentYAnimation = new QQuickNumberAnimation(this);
164+ m_contentYAnimation->setEasing(QEasingCurve::OutQuad);
165+ m_contentYAnimation->setProperty("contentY");
166+ m_contentYAnimation->setDuration(200);
167+ m_contentYAnimation->setTargetObject(this);
168168
169169 connect(this, SIGNAL(contentWidthChanged()), this, SLOT(onContentWidthChanged()));
170170 connect(this, SIGNAL(contentHeightChanged()), this, SLOT(onContentHeightChanged()));
171171 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()));
173173}
174174
175175ListViewWithPageHeader::~ListViewWithPageHeader()
@@ -374,11 +374,48 @@ void ListViewWithPageHeader::showHeader()
374374 layout();
375375 }
376376 }
377− m_headerShowAnimation->setTo(to);
378− m_headerShowAnimation->start();
377+ m_contentYAnimation->setTo(to);
378+ contentYAnimationType = ContentYAnimationShowHeader;
379+ m_contentYAnimation->start();
379380 }
380381}
381382
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+
382419qreal ListViewWithPageHeader::minYExtent() const
383420{
384421// qDebug() << "ListViewWithPageHeader::minYExtent" << m_minYExtent;
@@ -400,6 +437,7 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
400437 QQuickFlickable::viewportMoved(orient);
401438// qDebug() << "ListViewWithPageHeader::viewportMoved" << contentY();
402439 qreal diff = m_previousContentY - contentY();
440+ const bool showHeaderAnimationRunning = m_contentYAnimation->isRunning() && contentYAnimationType == ContentYAnimationShowHeader;
403441 if (m_headerItem) {
404442 auto oldHeaderItemShownHeight = m_headerItemShownHeight;
405443 if (contentY() < -m_minYExtent) {
@@ -410,16 +448,20 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
410448 m_headerItem->setHeight(m_headerItem->implicitHeight());
411449 // We are going down (but it's not because of the rebound at the end)
412450 // (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
414452 const bool scrolledUp = m_previousContentY > contentY();
415453 const bool notRebounding = contentY() + height() < contentHeight();
416454 const bool notShownByItsOwn = contentY() + diff > m_headerItem->y() + m_headerItem->height();
455+ const bool maximizeVisibleAreaRunning = m_contentYAnimation->isRunning() && contentYAnimationType == ContentYAnimationMaximizeVisibleArea;
417456
418457 if (!scrolledUp && contentY() == -m_minYExtent) {
419458 m_headerItemShownHeight = 0;
420459 m_headerItem->setY(contentY());
421− } else if ((scrolledUp && notRebounding && notShownByItsOwn) || (m_headerItemShownHeight > 0)) {
422− m_headerItemShownHeight += diff;
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
464+ m_headerItemShownHeight += diff;
423465 if (contentY() == -m_minYExtent) {
424466 m_headerItemShownHeight = 0;
425467 } else {
@@ -435,7 +477,7 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
435477 // We will be changing the clip item, need to accomadate for it
436478 // otherwise we move the firstItem down/up twice (unless the
437479 // show header animation is running, where we want to keep the viewport stable)
438− if (!m_headerShowAnimation->isRunning()) {
480+ if (!showHeaderAnimationRunning) {
439481 diff += oldHeaderItemShownHeight - m_headerItemShownHeight;
440482 } else {
441483 diff = -diff;
@@ -445,7 +487,7 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
445487 updateClipItem();
446488 ListItem *firstItem = m_visibleItems.first();
447489 firstItem->setY(firstItem->y() + diff);
448− if (m_headerShowAnimation->isRunning()) {
490+ if (showHeaderAnimationRunning) {
449491 adjustMinYExtent();
450492 }
451493 }
plugins/ListViewWithPageHeader/listviewwithpageheader.h+8−1
@@ -89,6 +89,11 @@ public:
8989 Q_INVOKABLE void positionAtBeginning();
9090 Q_INVOKABLE void showHeader();
9191
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+
9297Q_SIGNALS:
9398 void modelChanged();
9499 void delegateChanged();
@@ -182,7 +187,9 @@ private:
182187 qreal m_previousContentY;
183188 qreal m_headerItemShownHeight; // The height of header shown when the header is shown outside its topmost position
184189 // i.e. it's being shown after dragging down in the middle of the list
185− QQuickNumberAnimation *m_headerShowAnimation;
190+ enum ContentYAnimationType { ContentYAnimationShowHeader, ContentYAnimationMaximizeVisibleArea };
191+ ContentYAnimationType contentYAnimationType;
192+ QQuickNumberAnimation *m_contentYAnimation;
186193
187194 QQmlComponent *m_sectionDelegate;
188195 QString m_sectionProperty;
tests/plugins/ListViewWithPageHeader/listviewwithpageheadertest.cpp+206−3
@@ -1245,7 +1245,7 @@ private Q_SLOTS:
12451245
12461246 lvwph->showHeader();
12471247
1248− QTRY_VERIFY(!lvwph->m_headerShowAnimation->isRunning());
1248+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
12491249 QTRY_COMPARE(lvwph->m_visibleItems.count(), 5);
12501250 QCOMPARE(lvwph->m_firstVisibleIndex, 0);
12511251 verifyItem(0, -375., 150., true);
@@ -1301,7 +1301,7 @@ private Q_SLOTS:
13011301
13021302 lvwph->showHeader();
13031303
1304− QTRY_VERIFY(!lvwph->m_headerShowAnimation->isRunning());
1304+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
13051305 QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
13061306 QCOMPARE(lvwph->m_firstVisibleIndex, 0);
13071307 verifyItem(0, -20., 150., false);
@@ -1339,7 +1339,7 @@ private Q_SLOTS:
13391339
13401340 lvwph->showHeader();
13411341
1342− QTRY_VERIFY(!lvwph->m_headerShowAnimation->isRunning());
1342+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
13431343 QTRY_VERIFY (lvwph->isAtYEnd());
13441344 }
13451345
@@ -1409,6 +1409,209 @@ private Q_SLOTS:
14091409 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
14101410 }
14111411
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+
14121615private:
14131616 QQuickView *view;
14141617 ListViewWithPageHeader *lvwph;
tests/plugins/ListViewWithPageHeader/listviewwithpageheadertestsection.cpp+280−3
@@ -1506,7 +1506,7 @@ private Q_SLOTS:
15061506
15071507 lvwph->showHeader();
15081508
1509− QTRY_VERIFY(!lvwph->m_headerShowAnimation->isRunning());
1509+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
15101510 QTRY_COMPARE(lvwph->m_visibleItems.count(), 3);
15111511 QCOMPARE(lvwph->m_firstVisibleIndex, 0);
15121512 verifyItem(0, -20., 190., false, "Agressive", true);
@@ -1565,7 +1565,7 @@ private Q_SLOTS:
15651565
15661566 lvwph->showHeader();
15671567
1568− QTRY_VERIFY(!lvwph->m_headerShowAnimation->isRunning());
1568+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
15691569 QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
15701570 QCOMPARE(lvwph->m_firstVisibleIndex, 0);
15711571 verifyItem(0, -375., 190., true, "Agressive", true);
@@ -1607,7 +1607,7 @@ private Q_SLOTS:
16071607
16081608 lvwph->showHeader();
16091609
1610− QTRY_VERIFY(!lvwph->m_headerShowAnimation->isRunning());
1610+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
16111611 QTRY_VERIFY (lvwph->isAtYEnd());
16121612 }
16131613
@@ -1755,6 +1755,283 @@ private Q_SLOTS:
17551755 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
17561756 }
17571757
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+ }
17582035
17592036private:
17602037 QQuickView *view;