on xenial help sign in
LVWPH: Fix header going bad when setContentHeight ends up moving the viewport
d465399Albert Astals
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+4−1
@@ -155,6 +155,7 @@ ListViewWithPageHeader::ListViewWithPageHeader()
155 , m_topSectionItem(nullptr)
155 , m_topSectionItem(nullptr)
156 , m_forceNoClip(false)
156 , m_forceNoClip(false)
157 , m_inLayout(false)
157 , m_inLayout(false)
158+ , m_inContentHeightKeepHeaderShown(false)
158{
159{
159 m_clipItem = new QQuickItem(contentItem());
160 m_clipItem = new QQuickItem(contentItem());
160// m_clipItem = new QQuickRectangle(contentItem());
161// m_clipItem = new QQuickRectangle(contentItem());
@@ -494,7 +495,7 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
494 if (!scrolledUp && contentY() == -m_minYExtent) {
495 if (!scrolledUp && contentY() == -m_minYExtent) {
495 m_headerItemShownHeight = 0;
496 m_headerItemShownHeight = 0;
496 m_headerItem->setY(contentY());
497 m_headerItem->setY(contentY());
497− } else if ((scrolledUp && notRebounding && notShownByItsOwn && !maximizeVisibleAreaRunning) || (m_headerItemShownHeight > 0)) {
498+ } else if ((scrolledUp && notRebounding && notShownByItsOwn && !maximizeVisibleAreaRunning) || (m_headerItemShownHeight > 0) || m_inContentHeightKeepHeaderShown) {
498 if (maximizeVisibleAreaRunning && diff > 0) // If we are maximizing and the header was shown, make sure we hide it
499 if (maximizeVisibleAreaRunning && diff > 0) // If we are maximizing and the header was shown, make sure we hide it
499 m_headerItemShownHeight -= diff;
500 m_headerItemShownHeight -= diff;
500 else
501 else
@@ -1267,7 +1268,9 @@ void ListViewWithPageHeader::updatePolish()
1267
1268
1268 m_contentHeightDirty = false;
1269 m_contentHeightDirty = false;
1269 adjustMinYExtent();
1270 adjustMinYExtent();
1271+ m_inContentHeightKeepHeaderShown = m_headerItem && m_headerItem->y() == contentY();
1270 setContentHeight(contentHeight);
1272 setContentHeight(contentHeight);
1273+ m_inContentHeightKeepHeaderShown = false;
1271 }
1274 }
1272}
1275}
1273
1276
plugins/ListViewWithPageHeader/listviewwithpageheader.h+1
@@ -202,6 +202,7 @@ private:
202
202
203 bool m_forceNoClip;
203 bool m_forceNoClip;
204 bool m_inLayout;
204 bool m_inLayout;
205+ bool m_inContentHeightKeepHeaderShown;
205
206
206 // Qt 5.0 doesn't like releasing the items just after itemCreated
207 // Qt 5.0 doesn't like releasing the items just after itemCreated
207 // so we delay the releasing until the next updatePolish
208 // so we delay the releasing until the next updatePolish
tests/plugins/ListViewWithPageHeader/listviewwithpageheadertest.cpp+17
@@ -1827,6 +1827,23 @@ private Q_SLOTS:
1827 lvwph->positionAtBeginning();
1827 lvwph->positionAtBeginning();
1828 }
1828 }
1829
1829
1830+ void testHeaderPositionBug1240118()
1831+ {
1832+ scrollToBottom();
1833+ lvwph->showHeader();
1834+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1835+ QTest::qWait(100); // Make sure stuff is stable
1836+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 0), Q_ARG(QVariant, 100));
1837+ model->setProperty(3, "size", 10);
1838+ model->setProperty(4, "size", 10);
1839+ model->setProperty(5, "size", 10);
1840+ model->setProperty(6, "size", 10);
1841+#if (QT_VERSION > QT_VERSION_CHECK(5, 0, 3))
1842+ QTRY_COMPARE(lvwph->m_minYExtent, 210.);
1843+#endif
1844+ QTRY_COMPARE(lvwph->m_headerItem->y(), -lvwph->m_minYExtent);
1845+ }
1846+
1830private:
1847private:
1831 QQuickView *view;
1848 QQuickView *view;
1832 ListViewWithPageHeader *lvwph;
1849 ListViewWithPageHeader *lvwph;