2 * Copyright (C) 2013 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include "listviewwithpageheader.h"
21#include <qqmlengine.h>
22#include <private/qquickvisualdatamodel_p.h>
23#include <private/qqmlglobal_p.h>
24#include <private/qquickitem_p.h>
25#include <private/qquickanimation_p.h>
26// #include <private/qquickrectangle_p.h>
28qreal ListViewWithPageHeader::ListItem::height() const
30 return m_item->height() + (m_sectionItem ? m_sectionItem->height() : 0);
33qreal ListViewWithPageHeader::ListItem::y() const
35 return m_item->y() - (m_sectionItem ? m_sectionItem->height() : 0);
38void ListViewWithPageHeader::ListItem::setY(qreal newY)
41 m_sectionItem->setY(newY);
42 m_item->setY(newY + m_sectionItem->height());
48bool ListViewWithPageHeader::ListItem::culled() const
50 return QQuickItemPrivate::get(m_item)->culled;
53void ListViewWithPageHeader::ListItem::setCulled(bool culled)
55 QQuickItemPrivate::get(m_item)->setCulled(culled);
57 QQuickItemPrivate::get(m_sectionItem)->setCulled(culled);
60ListViewWithPageHeader::ListViewWithPageHeader()
61 : m_delegateModel(nullptr)
62 , m_delegateValidated(false)
63 , m_firstVisibleIndex(-1)
65 , m_contentHeightDirty(false)
66 , m_headerItem(nullptr)
67 , m_previousContentY(0)
68 , m_headerItemShownHeight(0)
69 , m_sectionDelegate(nullptr)
70 , m_topSectionItem(nullptr)
72 m_clipItem = new QQuickItem(contentItem());
73// m_clipItem = new QQuickRectangle(contentItem());
74// ((QQuickRectangle*)m_clipItem)->setColor(Qt::gray);
76 m_headerShowAnimation = new QQuickNumberAnimation(this);
77 m_headerShowAnimation->setEasing(QEasingCurve::OutQuad);
78 m_headerShowAnimation->setProperty("contentY");
79 m_headerShowAnimation->setDuration(200);
80 m_headerShowAnimation->setTargetObject(this);
82 connect(this, SIGNAL(contentWidthChanged()), this, SLOT(onContentWidthChanged()));
83 connect(this, SIGNAL(contentHeightChanged()), this, SLOT(onContentHeightChanged()));
86ListViewWithPageHeader::~ListViewWithPageHeader()
90QAbstractItemModel *ListViewWithPageHeader::model() const
92 return m_delegateModel ? m_delegateModel->model().value<QAbstractItemModel *>() : nullptr;
95void ListViewWithPageHeader::setModel(QAbstractItemModel *model)
97 if (model != this->model()) {
98 if (!m_delegateModel) {
99 createDelegateModel();
101 disconnect(m_delegateModel, SIGNAL(modelUpdated(QQuickChangeSet,bool)), this, SLOT(onModelUpdated(QQuickChangeSet,bool)));
103 m_delegateModel->setModel(QVariant::fromValue<QAbstractItemModel *>(model));
104 connect(m_delegateModel, SIGNAL(modelUpdated(QQuickChangeSet,bool)), this, SLOT(onModelUpdated(QQuickChangeSet,bool)));
105 Q_EMIT modelChanged();
107// Q_EMIT contentHeightChanged();
108// Q_EMIT contentYChanged();
112QQmlComponent *ListViewWithPageHeader::delegate() const
114 return m_delegateModel ? m_delegateModel->delegate() : nullptr;
117void ListViewWithPageHeader::setDelegate(QQmlComponent *delegate)
119 if (delegate != this->delegate()) {
120 if (!m_delegateModel) {
121 createDelegateModel();
124 // Cleanup the existing items
125 foreach(ListItem *item, m_visibleItems)
127 m_visibleItems.clear();
128 m_firstVisibleIndex = -1;
132 m_delegateModel->setDelegate(delegate);
134 Q_EMIT delegateChanged();
135 m_delegateValidated = false;
136 m_contentHeightDirty = true;
141QQuickItem *ListViewWithPageHeader::header() const
146void ListViewWithPageHeader::setHeader(QQuickItem *headerItem)
148 if (m_headerItem != headerItem) {
149 qreal oldHeaderHeight = 0;
150 qreal oldHeaderY = 0;
152 oldHeaderHeight = m_headerItem->height();
153 oldHeaderY = m_headerItem->y();
154 QQuickItemPrivate::get(m_headerItem)->removeItemChangeListener(this, QQuickItemPrivate::Geometry);
155 m_headerItem->setParentItem(nullptr);
157 m_headerItem = headerItem;
159 m_headerItem->setParentItem(contentItem());
160 m_headerItem->setZ(1);
161 QQuickItemPrivate::get(m_headerItem)->addItemChangeListener(this, QQuickItemPrivate::Geometry);
163 qreal newHeaderHeight = m_headerItem ? m_headerItem->height() : 0;
164 if (!m_visibleItems.isEmpty() && newHeaderHeight != oldHeaderHeight) {
165 headerHeightChanged(newHeaderHeight, oldHeaderHeight, oldHeaderY);
167 m_contentHeightDirty = true;
169 Q_EMIT headerChanged();
173QQmlComponent *ListViewWithPageHeader::sectionDelegate() const
175 return m_sectionDelegate;
178void ListViewWithPageHeader::setSectionDelegate(QQmlComponent *delegate)
180 if (delegate != m_sectionDelegate) {
181 // TODO clean existing sections
183 m_sectionDelegate = delegate;
185 m_topSectionItem = getSectionItem(QString());
186 m_topSectionItem->setZ(3);
187 QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
189 // TODO create sections for existing items
191 Q_EMIT sectionDelegateChanged();
195QString ListViewWithPageHeader::sectionProperty() const
197 return m_sectionProperty;
200void ListViewWithPageHeader::setSectionProperty(const QString &property)
202 if (property != m_sectionProperty) {
203 m_sectionProperty = property;
205 updateWatchedRoles();
207 // TODO recreate sections
209 Q_EMIT sectionPropertyChanged();
213void ListViewWithPageHeader::positionAtBeginning()
215 qreal headerHeight = (m_headerItem ? m_headerItem->height() : 0);
216 if (m_firstVisibleIndex != 0) {
217 // This could be optimized by trying to reuse the interesection
218 // of items that may end up intersecting between the existing
219 // m_visibleItems and the items we are creating in the next loop
220 foreach(ListItem *item, m_visibleItems)
222 m_visibleItems.clear();
223 m_firstVisibleIndex = -1;
225 // Create the item 0, it will be already correctly positioned at createItem()
227 ListItem *item = createItem(0, false);
228 // Create the subsequent items
230 qreal pos = item->y() + item->height();
231 const qreal buffer = height() / 2;
232 const qreal bufferTo = height() + buffer;
233 while (modelIndex < m_delegateModel->count() && pos <= bufferTo) {
234 if (!(item = createItem(modelIndex, false)))
236 pos += item->height();
240 m_previousContentY = m_visibleItems.first()->y() - headerHeight;
242 setContentY(m_visibleItems.first()->y() + m_clipItem->y() - headerHeight);
245void ListViewWithPageHeader::showHeader()
247 auto to = qMax(-minYExtent(), contentY() - m_headerItem->height() + m_headerItemShownHeight);
248 if (to != contentY()) {
249 m_headerShowAnimation->setTo(to);
250 m_headerShowAnimation->start();
254qreal ListViewWithPageHeader::minYExtent() const
256// qDebug() << "ListViewWithPageHeader::minYExtent" << m_minYExtent;
260void ListViewWithPageHeader::componentComplete()
263 m_delegateModel->componentComplete();
265 QQuickFlickable::componentComplete();
270void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
272 QQuickFlickable::viewportMoved(orient);
273// qDebug() << "ListViewWithPageHeader::viewportMoved" << contentY();
274 qreal diff = m_previousContentY - contentY();
276 auto oldHeaderItemShownHeight = m_headerItemShownHeight;
277 if (contentY() < -m_minYExtent) {
278 // Stick the header item to the top when dragging down
279 m_headerItem->setY(contentY());
281 // We are going down (but it's not because of the rebound at the end)
282 // (but the header was not shown by it's own position)
283 // or the header is partially shown
284 const bool scrolledUp = m_previousContentY > contentY();
285 const bool notRebounding = contentY() + height() < contentHeight();
286 const bool notShownByItsOwn = contentY() + diff > m_headerItem->y() + m_headerItem->height();
288 if (!scrolledUp && contentY() == -m_minYExtent) {
289 m_headerItemShownHeight = 0;
290 m_headerItem->setY(contentY());
291 } else if ((scrolledUp && notRebounding && notShownByItsOwn) || (m_headerItemShownHeight > 0)) {
292 m_headerItemShownHeight += diff;
293 if (contentY() == -m_minYExtent) {
294 m_headerItemShownHeight = 0;
296 m_headerItemShownHeight = qBound(static_cast<qreal>(0.), m_headerItemShownHeight, m_headerItem->height());
298 if (m_headerItemShownHeight > 0) {
299 m_headerItem->setY(contentY() - m_headerItem->height() + m_headerItemShownHeight);
301 m_headerItem->setY(-m_minYExtent);
305 // We will be changing the clip item, need to accomadate for it
306 // otherwise we move the firstItem down/up twice
307 diff += oldHeaderItemShownHeight - m_headerItemShownHeight;
309 if (!m_visibleItems.isEmpty()) {
311 ListItem *firstItem = m_visibleItems.first();
312 firstItem->setY(firstItem->y() + diff);
315 m_previousContentY = contentY();
319void ListViewWithPageHeader::createDelegateModel()
321 m_delegateModel = new QQuickVisualDataModel(qmlContext(this), this);
322 connect(m_delegateModel, SIGNAL(createdItem(int,QQuickItem*)), this, SLOT(itemCreated(int,QQuickItem*)));
323 if (isComponentComplete())
324 m_delegateModel->componentComplete();
325 updateWatchedRoles();
328void ListViewWithPageHeader::refill()
330 if (!isComponentComplete()) {
331 qWarning() << "Incomplete ListViewWithPageHeader::refill";
335 const qreal buffer = height() / 2;
336 const qreal from = contentY();
337 const qreal to = from + height();
338 const qreal bufferFrom = from - buffer;
339 const qreal bufferTo = to + buffer;
341 bool added = addVisibleItems(from, to, false);
342 bool removed = removeNonVisibleItems(bufferFrom, bufferTo);
343 added |= addVisibleItems(bufferFrom, bufferTo, true);
345 if (added || removed) {
346 m_contentHeightDirty = true;
350bool ListViewWithPageHeader::addVisibleItems(qreal fillFrom, qreal fillTo, bool asynchronous)
355 if (m_delegateModel->count() == 0)
359// qDebug() << "ListViewWithPageHeader::addVisibleItems" << fillFrom << fillTo << asynchronous;
363 if (!m_visibleItems.isEmpty()) {
364 modelIndex = m_firstVisibleIndex + m_visibleItems.count();
365 item = m_visibleItems.last();
366 pos = item->y() + item->height() + m_clipItem->y();
368 bool changed = false;
369// qDebug() << (modelIndex < m_delegateModel->count()) << pos << fillTo;
370 while (modelIndex < m_delegateModel->count() && pos <= fillTo) {
371// qDebug() << "refill: append item" << modelIndex << "pos" << pos << "asynchronous" << asynchronous;
372 if (!(item = createItem(modelIndex, asynchronous)))
374 pos += item->height();
381 if (!m_visibleItems.isEmpty()) {
382 modelIndex = m_firstVisibleIndex - 1;
383 item = m_visibleItems.first();
384 pos = item->y() + m_clipItem->y();
386 while (modelIndex >= 0 && pos > fillFrom) {
387// qDebug() << "refill: prepend item" << modelIndex << "pos" << pos << "fillFrom" << fillFrom << "asynchronous" << asynchronous;
388 if (!(item = createItem(modelIndex, asynchronous)))
390 pos -= item->height();
398void ListViewWithPageHeader::releaseItem(ListItem *listItem)
400 QQuickItem *item = listItem->m_item;
401 QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
402 itemPrivate->removeItemChangeListener(this, QQuickItemPrivate::Geometry);
403 QQuickVisualModel::ReleaseFlags flags = m_delegateModel->release(item);
404 if (flags & QQuickVisualModel::Destroyed) {
405 item->setParentItem(nullptr);
407 delete listItem->m_sectionItem;
411void ListViewWithPageHeader::updateWatchedRoles()
413 if (m_delegateModel) {
414 QList<QByteArray> roles;
415 if (!m_sectionProperty.isEmpty())
416 roles << m_sectionProperty.toUtf8();
417 m_delegateModel->setWatchedRoles(roles);
421QQuickItem *ListViewWithPageHeader::getSectionItem(int modelIndex)
423 if (!m_sectionDelegate)
426 const QString section = m_delegateModel->stringValue(modelIndex, m_sectionProperty);
427 if (modelIndex > 0) {
428 const QString prevSection = m_delegateModel->stringValue(modelIndex - 1, m_sectionProperty);
429 if (section == prevSection)
433 return getSectionItem(section);
436QQuickItem *ListViewWithPageHeader::getSectionItem(const QString §ionText)
438 QQuickItem *sectionItem = nullptr;
440 QQmlContext *creationContext = m_sectionDelegate->creationContext();
441 QQmlContext *context = new QQmlContext(creationContext ? creationContext : qmlContext(this));
442 context->setContextProperty(QLatin1String("section"), sectionText);
443 QObject *nobj = m_sectionDelegate->beginCreate(context);
445 QQml_setParent_noEvent(context, nobj);
446 sectionItem = qobject_cast<QQuickItem *>(nobj);
450 sectionItem->setZ(2);
451 QQml_setParent_noEvent(sectionItem, m_clipItem);
452 sectionItem->setParentItem(m_clipItem);
457 m_sectionDelegate->completeCreate();
459 // TODO attach to sectionItem so we can accomodate to it changing its height
464bool ListViewWithPageHeader::removeNonVisibleItems(qreal bufferFrom, qreal bufferTo)
466// qDebug() << "ListViewWithPageHeader::removeNonVisibleItems" << bufferFrom << bufferTo;
467 bool changed = false;
469 bool foundVisible = false;
471 int removedItems = 0;
472 while (i < m_visibleItems.count()) {
473 ListItem *item = m_visibleItems[i];
474 const qreal pos = item->y() + m_clipItem->y();
475// qDebug() << i << pos << (pos + item->height()) << bufferFrom << bufferTo;
476 if (pos + item->height() < bufferFrom || pos > bufferTo) {
477// qDebug() << "Releasing" << i << (pos + item->height() < bufferFrom) << pos + item->height() << bufferFrom << (pos > bufferTo) << pos << bufferTo;
479 m_visibleItems.removeAt(i);
485 const int itemIndex = m_firstVisibleIndex + removedItems + i;
486 m_firstVisibleIndex = itemIndex;
495ListViewWithPageHeader::ListItem *ListViewWithPageHeader::createItem(int modelIndex, bool asynchronous)
497// qDebug() << "CREATE ITEM" << modelIndex;
498 if (asynchronous && m_asyncRequestedIndexes.contains(modelIndex))
501 m_asyncRequestedIndexes.remove(modelIndex);
502 QQuickItem *item = m_delegateModel->item(modelIndex, asynchronous);
504 m_asyncRequestedIndexes << modelIndex;
507// qDebug() << "ListViewWithPageHeader::createItem::We have the item" << modelIndex << item;
508 ListItem *listItem = new ListItem;
509 listItem->m_item = item;
510 listItem->m_sectionItem = getSectionItem(modelIndex);
511 QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Geometry);
512 ListItem *prevItem = itemAtIndex(modelIndex - 1);
514 listItem->setY(prevItem->y() + prevItem->height());
516 ListItem *nextItem = itemAtIndex(modelIndex + 1);
518 listItem->setY(nextItem->y() - listItem ->height());
519 } else if (modelIndex == 0 && m_headerItem) {
520 listItem->setY(m_headerItem->height());
523 listItem->setCulled(listItem->y() + listItem->height() + m_clipItem->y() < contentY() || listItem->y() + m_clipItem->y() >= contentY() + height());
524 if (m_visibleItems.isEmpty()) {
525 m_visibleItems << listItem;
527 m_visibleItems.insert(modelIndex - m_firstVisibleIndex, listItem);
529 if (m_firstVisibleIndex < 0 || modelIndex < m_firstVisibleIndex) {
530 m_firstVisibleIndex = modelIndex;
537void ListViewWithPageHeader::itemCreated(int modelIndex, QQuickItem *item)
539// qDebug() << "ListViewWithPageHeader::itemCreated" << modelIndex << item;
541 item->setParentItem(m_clipItem);
542 QQmlContext *context = QQmlEngine::contextForObject(item)->parentContext();
543 context->setContextProperty(QLatin1String("ListViewWithPageHeader"), this);
544 if (m_asyncRequestedIndexes.remove(modelIndex)) {
545 createItem(modelIndex, false);
549void ListViewWithPageHeader::updateClipItem()
551 m_clipItem->setHeight(height() - m_headerItemShownHeight);
552 m_clipItem->setY(contentY() + m_headerItemShownHeight);
553 m_clipItem->setClip(m_headerItemShownHeight > 0);
556void ListViewWithPageHeader::onContentHeightChanged()
561void ListViewWithPageHeader::onContentWidthChanged()
563 m_clipItem->setWidth(contentItem()->width());
566void ListViewWithPageHeader::onModelUpdated(const QQuickChangeSet &changeSet, bool /*reset*/)
568 // TODO Do something with reset
569// qDebug() << "ListViewWithPageHeader::onModelUpdated" << changeSet << reset;
570 foreach(const QQuickChangeSet::Remove &remove, changeSet.removes()) {
571// qDebug() << "ListViewWithPageHeader::onModelUpdated Remove" << remove;
572 if (remove.index + remove.count > m_firstVisibleIndex && remove.index < m_firstVisibleIndex + m_visibleItems.count()) {
573 const qreal oldFirstValidIndexPos = m_visibleItems.first()->y();
574 // If all the items we are removing are either not created or culled
575 // we have to grow down to avoid viewport changing
576 bool growDown = true;
577 for (int i = 0; growDown && i < remove.count; ++i) {
578 const int modelIndex = remove.index + i;
579 ListItem *item = itemAtIndex(modelIndex);
580 if (item && !item->culled()) {
584 for (int i = remove.count - 1; i >= 0; --i) {
585 const int visibleIndex = remove.index + i - m_firstVisibleIndex;
586 if (visibleIndex >= 0 && visibleIndex < m_visibleItems.count()) {
587 ListItem *item = m_visibleItems[visibleIndex];
589 m_visibleItems.removeAt(visibleIndex);
594 } else if (remove.index <= m_firstVisibleIndex && !m_visibleItems.isEmpty()) {
595 // We removed the first item that is the one that positions the rest
596 // position the new first item correctly
597 m_visibleItems.first()->setY(oldFirstValidIndexPos);
599 } else if (remove.index + remove.count <= m_firstVisibleIndex) {
600 m_firstVisibleIndex -= remove.count;
604 foreach(const QQuickChangeSet::Insert &insert, changeSet.inserts()) {
605// qDebug() << "ListViewWithPageHeader::onModelUpdated Insert" << insert;
606 const bool insertingInValidIndexes = insert.index > m_firstVisibleIndex && insert.index < m_firstVisibleIndex + m_visibleItems.count();
607 const bool firstItemWithViewOnTop = insert.index == 0 && m_firstVisibleIndex == 0 && m_visibleItems.first()->y() + m_clipItem->y() > contentY();
608 if (insertingInValidIndexes || firstItemWithViewOnTop)
610 // If the items we are adding won't be really visible
611 // we grow up instead of down to not change the viewport
613 if (!firstItemWithViewOnTop) {
614 for (int i = 0; i < m_visibleItems.count(); ++i) {
615 if (!m_visibleItems[i]->culled()) {
616 if (insert.index <= m_firstVisibleIndex + i) {
624 const qreal oldFirstValidIndexPos = m_visibleItems.first()->y();
625 for (int i = insert.count - 1; i >= 0; --i) {
626 const int modelIndex = insert.index + i;
627 ListItem *item = createItem(modelIndex, false);
629 ListItem *firstItem = m_visibleItems.first();
630 firstItem->setY(firstItem->y() - item->height());
634 if (firstItemWithViewOnTop) {
635 ListItem *firstItem = m_visibleItems.first();
636 firstItem->setY(oldFirstValidIndexPos);
638 } else if (insert.index <= m_firstVisibleIndex) {
639 m_firstVisibleIndex += insert.count;
644 m_contentHeightDirty = true;
647void ListViewWithPageHeader::itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry)
649 const qreal heightDiff = newGeometry.height() - oldGeometry.height();
650 if (heightDiff != 0) {
651 if (item == m_headerItem) {
652 headerHeightChanged(newGeometry.height(), oldGeometry.height(), oldGeometry.y());
654 if (oldGeometry.y() + oldGeometry.height() + m_clipItem->y() < contentY() && !m_visibleItems.isEmpty()) {
655 ListItem *firstItem = m_visibleItems.first();
656 firstItem->setY(firstItem->y() - heightDiff);
661 m_contentHeightDirty = true;
665void ListViewWithPageHeader::headerHeightChanged(qreal newHeaderHeight, qreal oldHeaderHeight, qreal oldHeaderY)
667 const qreal heightDiff = newHeaderHeight - oldHeaderHeight;
668 if (m_headerItemShownHeight > 0) {
669 // If the header is shown because of the clip
671 m_headerItemShownHeight += heightDiff;
672 m_headerItemShownHeight = qBound(static_cast<qreal>(0.), m_headerItemShownHeight, newHeaderHeight);
676 if (oldHeaderY + oldHeaderHeight > contentY()) {
677 // If the header is shown because its position
679 ListItem *firstItem = m_visibleItems.first();
680 firstItem->setY(firstItem->y() + heightDiff);
682 // If the header is not on screen, just change the start of the list
683 // so the viewport is not changed
690void ListViewWithPageHeader::adjustMinYExtent()
692 if (m_visibleItems.isEmpty()) {
695 m_minYExtent = -m_visibleItems.first()->y() - m_clipItem->y() + (m_headerItem ? m_headerItem->height() : 0);
699ListViewWithPageHeader::ListItem *ListViewWithPageHeader::itemAtIndex(int modelIndex) const
701 const int visibleIndexedModelIndex = modelIndex - m_firstVisibleIndex;
702 if (visibleIndexedModelIndex >= 0 && visibleIndexedModelIndex < m_visibleItems.count())
703 return m_visibleItems[visibleIndexedModelIndex];
708void ListViewWithPageHeader::updatePolish()
713 if (!m_visibleItems.isEmpty()) {
714 const qreal visibleFrom = contentY() - m_clipItem->y() + m_headerItemShownHeight;
715 const qreal visibleTo = contentY() + height() - m_clipItem->y();
717 qreal pos = m_visibleItems.first()->y();
719// qDebug() << "ListViewWithPageHeader::updatePolish Updating positions and heights. contentY" << contentY() << "minYExtent" << minYExtent();
720 int firstReallyVisibleItem = -1;
721 int modelIndex = m_firstVisibleIndex;
722 foreach(ListItem *item, m_visibleItems) {
723 const bool cull = pos + item->height() < visibleFrom || pos >= visibleTo;
724 item->setCulled(cull);
726 if (!cull && firstReallyVisibleItem == -1) {
727 firstReallyVisibleItem = modelIndex;
728 if (m_topSectionItem) {
729 // Update the top sticky section header
730 const QString section = m_delegateModel->stringValue(modelIndex, m_sectionProperty);
731 QQmlContext *context = QQmlEngine::contextForObject(m_topSectionItem)->parentContext();
732 context->setContextProperty(QLatin1String("section"), section);
734 // Positing the top section sticky item is a two step process
735 // First we set it either we cull it (because it doesn't need to be sticked to the top)
736 // or stick it to the top
737 // Then after the loop we'll make sure that if there's another section just below it
738 // pushed the sticky section up to make it disappear
739 const qreal topSectionStickPos = m_headerItemShownHeight + contentY() - m_clipItem->y();
740 if (topSectionStickPos <= pos) {
741 QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
742 QQuickItemPrivate::get(item->m_sectionItem)->setCulled(false);
744 QQuickItemPrivate::get(m_topSectionItem)->setCulled(false);
745 m_topSectionItem->setY(topSectionStickPos);
746 if (item->m_sectionItem) {
747 QQuickItemPrivate::get(item->m_sectionItem)->setCulled(true);
752 QQmlContext *context = QQmlEngine::contextForObject(item->m_item)->parentContext();
753 if (!cull && pos < visibleFrom) {
754 context->setContextProperty(QLatin1String("heightToClip"), visibleFrom - pos);
756 context->setContextProperty(QLatin1String("heightToClip"), QVariant::fromValue<int>(0));
758// qDebug() << "ListViewWithPageHeader::updatePolish" << /*index << */pos + m_clipItem->y() << /*QQuickItemPrivate::get(item)->culled <<*/ (pos + item->height() < visibleFrom) << (pos > visibleTo);
759 pos += item->height();
763 // Second step of section sticky item positioning
764 // Look at the next section header, check if it's pushing up the sticky one
765 if (m_topSectionItem) {
766 for (int i = firstReallyVisibleItem - m_firstVisibleIndex + 1; i < m_visibleItems.count(); ++i) {
767 ListItem *item = m_visibleItems[i];
768 if (item->m_sectionItem) {
769 if (m_topSectionItem->y() + m_topSectionItem->height() > item->y()) {
770 m_topSectionItem->setY(item->y() - m_topSectionItem->height());
780 if (m_contentHeightDirty) {
782 const int modelCount = model()->rowCount();
783 const int visibleItems = m_visibleItems.count();
784 const int lastValidIndex = m_firstVisibleIndex + visibleItems - 1;
785 if (lastValidIndex == modelCount - 1) {
786 ListItem *item = m_visibleItems.last();
787 contentHeight = item->y() + item->height() + m_clipItem->y();
788 if (m_firstVisibleIndex != 0) {
789 // Make sure that if we are shrinking we tell the view we still fit
790 m_minYExtent = qMax(m_minYExtent, -(contentHeight - height()));
793 contentHeight = m_headerItem ? m_headerItem->height() : 0;
794 if (!m_visibleItems.isEmpty()) {
795 foreach(ListItem *item, m_visibleItems) {
796 contentHeight += item->height();
798 const int unknownSizes = modelCount - visibleItems;
799 contentHeight += unknownSizes * contentHeight / visibleItems;
803 m_contentHeightDirty = false;
804 setContentHeight(contentHeight);
809#include "moc_listviewwithpageheader.cpp"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list