@@ -91,6 +91,7 @@
92#include "listviewwithpageheader.h"
92#include "listviewwithpageheader.h"
94+#include <QCoreApplication>
94#include <QDebug>
95#include <QDebug>
95#include <qqmlinfo.h>
96#include <qqmlinfo.h>
96#include <qqmlengine.h>
97#include <qqmlengine.h>
@@ -477,6 +478,11 @@ void ListViewWithPageHeader::componentComplete()
477 polish();
478 polish();
481+static inline bool uFuzzyCompare(qreal r1, qreal r2)
483+ return qFuzzyCompare(r1, r2) || (qFuzzyIsNull(r1) && qFuzzyIsNull(r2));
480void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
486void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
482 // Check we are not being taken down and don't paint anything
488 // Check we are not being taken down and don't paint anything
@@ -491,11 +497,7 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
491 const bool showHeaderAnimationRunning = m_contentYAnimation->isRunning() && contentYAnimationType == ContentYAnimationShowHeader;
497 const bool showHeaderAnimationRunning = m_contentYAnimation->isRunning() && contentYAnimationType == ContentYAnimationShowHeader;
492 if (m_headerItem) {
498 if (m_headerItem) {
493 const auto oldHeaderItemShownHeight = m_headerItemShownHeight;
499 const auto oldHeaderItemShownHeight = m_headerItemShownHeight;
494− if (contentY() < -m_minYExtent) {
500+ if (uFuzzyCompare(contentY(), -m_minYExtent) || contentY() > -m_minYExtent) {
495− // Stick the header item to the top when dragging down
496− m_headerItem->setY(contentY());
497− m_headerItem->setHeight(m_headerItem->implicitHeight() + (-m_minYExtent - contentY()));
499 m_headerItem->setHeight(m_headerItem->implicitHeight());
501 m_headerItem->setHeight(m_headerItem->implicitHeight());
500 // We are going down (but it's not because of the rebound at the end)
502 // We are going down (but it's not because of the rebound at the end)
501 // (but the header was not shown by it's own position)
503 // (but the header was not shown by it's own position)
@@ -509,21 +511,32 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
509 m_headerItemShownHeight = 0;
511 m_headerItemShownHeight = 0;
510 m_headerItem->setY(-m_minYExtent);
512 m_headerItem->setY(-m_minYExtent);
511 } else if ((scrolledUp && notRebounding && notShownByItsOwn && !maximizeVisibleAreaRunning) || (m_headerItemShownHeight > 0) || m_inContentHeightKeepHeaderShown) {
513 } else if ((scrolledUp && notRebounding && notShownByItsOwn && !maximizeVisibleAreaRunning) || (m_headerItemShownHeight > 0) || m_inContentHeightKeepHeaderShown) {
514+ if (maximizeVisibleAreaRunning && diff > 0) {
512− if (maximizeVisibleAreaRunning && diff > 0) // If we are maximizing and the header was shown, make sure we hide it
515+ // If we are maximizing and the header was shown, make sure we hide it
513 m_headerItemShownHeight -= diff;
516 m_headerItemShownHeight -= diff;
515 m_headerItemShownHeight += diff;
518 m_headerItemShownHeight += diff;
516− if (contentY() == -m_minYExtent) {
520+ if (uFuzzyCompare(contentY(), -m_minYExtent)) {
517 m_headerItemShownHeight = 0;
521 m_headerItemShownHeight = 0;
519 m_headerItemShownHeight = qBound(static_cast<qreal>(0.), m_headerItemShownHeight, m_headerItem->height());
523 m_headerItemShownHeight = qBound(static_cast<qreal>(0.), m_headerItemShownHeight, m_headerItem->height());
521 if (m_headerItemShownHeight > 0) {
525 if (m_headerItemShownHeight > 0) {
526+ if (uFuzzyCompare(m_headerItem->height(), m_headerItemShownHeight)) {
527+ m_headerItem->setY(contentY());
528+ m_headerItemShownHeight = m_headerItem->height();
522− m_headerItem->setY(contentY() - m_headerItem->height() + m_headerItemShownHeight);
530+ m_headerItem->setY(contentY() - m_headerItem->height() + m_headerItemShownHeight);
524 m_headerItem->setY(-m_minYExtent);
533 m_headerItem->setY(-m_minYExtent);
537+ // Stick the header item to the top when dragging down
538+ m_headerItem->setY(contentY());
539+ m_headerItem->setHeight(m_headerItem->implicitHeight() + (-m_minYExtent - contentY()));
528 // We will be changing the clip item, need to accomadate for it
541 // We will be changing the clip item, need to accomadate for it
529 // otherwise we move the firstItem down/up twice (unless the
542 // otherwise we move the firstItem down/up twice (unless the
@@ -1128,7 +1141,12 @@ void ListViewWithPageHeader::adjustMinYExtent()
1128 nonCreatedHeight = m_firstVisibleIndex * visibleItemsHeight / visibleItems;
1141 nonCreatedHeight = m_firstVisibleIndex * visibleItemsHeight / visibleItems;
1129// qDebug() << m_firstVisibleIndex << visibleItemsHeight << visibleItems << nonCreatedHeight;
1142// qDebug() << m_firstVisibleIndex << visibleItemsHeight << visibleItems << nonCreatedHeight;
1131− m_minYExtent = nonCreatedHeight - m_visibleItems.first()->y() - m_clipItem->y() + (m_headerItem ? m_headerItem->implicitHeight() : 0);
1144+ const qreal headerHeight = (m_headerItem ? m_headerItem->implicitHeight() : 0);
1145+ m_minYExtent = nonCreatedHeight - m_visibleItems.first()->y() - m_clipItem->y() + headerHeight;
1146+ if (m_minYExtent != 0 && qFuzzyIsNull(m_minYExtent)) {
1148+ m_visibleItems.first()->setY(nonCreatedHeight - m_clipItem->y() + headerHeight);
@@ -1264,6 +1282,11 @@ void ListViewWithPageHeader::updatePolish()
1264 refill();
1282 refill();
1266 if (m_contentHeightDirty) {
1284 if (m_contentHeightDirty) {
1285+ // We need to make sure all bindings have updated otherwise
1286+ // we may end up with bindings updating when we call setContentHeight
1287+ // and then everything gets out of sync, i.e. testHeaderPositionBug1240118
1288+ QCoreApplication::instance()->processEvents();
1267 qreal contentHeight;
1290 qreal contentHeight;
1268 if (m_visibleItems.isEmpty()) {
1291 if (m_visibleItems.isEmpty()) {
1269 contentHeight = m_headerItem ? m_headerItem->height() : 0;
1292 contentHeight = m_headerItem ? m_headerItem->height() : 0;