on xenial help sign in
Rework the Base.qml clipping to work on the new ListViewWithPageHeader
52f8f32Albert Astals
Components/ListItems/Base.qml+15−22
@@ -54,35 +54,28 @@ AbstractButton {
54 */
54 */
55 function __showDivider() {
55 function __showDivider() {
56 // if we're not in ListView, always show a thin dividing line at the bottom
56 // if we're not in ListView, always show a thin dividing line at the bottom
57− if (ListView.view !== null) {
57+ var model = null;
58−
58+ if (typeof ListViewWithPageHeader !== 'undefined') {
59− // if we're last item in ListView don't show divider
59+ if (typeof ListViewWithPageHeader.model !== 'undefined') {
60− if (index === ListView.view.model.count - 1) return false;
60+ model = ListViewWithPageHeader.model;
61+ }
62+ } else if (ListView.view !== null) {
63+ model = ListView.view.model;
61 }
64 }
65+ // if we're last item in ListView don't show divider
66+ if (model && index === model.count - 1) return false;
67+
62 return true;
68 return true;
63 }
69 }
64
70
65− property bool __clippingRequired: ListView.view !== null
66− && ListView.view.section.labelPositioning & ViewSection.CurrentLabelAtStart
67−
68− property real __yPositionRelativeToListView: ListView.view ? y - ListView.view.contentY : y
69−
70 property real __heightToClip: {
71 property real __heightToClip: {
71 // Check this is in position where clipping is needed
72 // Check this is in position where clipping is needed
72− if (__clippingRequired && __yPositionRelativeToListView <= __sectionDelegateHeight
73+ if (typeof ListViewWithPageHeader !== 'undefined') {
73− && __yPositionRelativeToListView > -height) {
74+ if (typeof heightToClip !== 'undefined') {
74− return Math.min(__sectionDelegateHeight - __yPositionRelativeToListView, height);
75+ return heightToClip;
75− } else {
76− return 0;
77− }
78− }
76+ }
79−
80− property int __sectionDelegateHeight: {
81− if (__clippingRequired && ListView.view.hasOwnProperty("__sectionDelegateHeight")) {
82− return ListView.view.__sectionDelegateHeight;
83− } else {
84− return 0;
85 }
77 }
78+ return 0;
86 }
79 }
87
80
88 /*!
81 /*!
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+8
@@ -531,6 +531,8 @@ void ListViewWithPageHeader::itemCreated(int modelIndex, QQuickItem *item)
531// qDebug() << "ListViewWithPageHeader::itemCreated" << modelIndex << item;
531// qDebug() << "ListViewWithPageHeader::itemCreated" << modelIndex << item;
532
532
533 item->setParentItem(m_clipItem);
533 item->setParentItem(m_clipItem);
534+ QQmlContext *context = QQmlEngine::contextForObject(item)->parentContext();
535+ context->setContextProperty(QLatin1String("ListViewWithPageHeader"), this);
534 if (m_asyncRequestedIndexes.remove(modelIndex)) {
536 if (m_asyncRequestedIndexes.remove(modelIndex)) {
535 createItem(modelIndex, false);
537 createItem(modelIndex, false);
536 }
538 }
@@ -739,6 +741,12 @@ void ListViewWithPageHeader::updatePolish()
739 }
741 }
740 }
742 }
741 }
743 }
744+ QQmlContext *context = QQmlEngine::contextForObject(item->m_item)->parentContext();
745+ if (!cull && pos < visibleFrom) {
746+ context->setContextProperty(QLatin1String("heightToClip"), visibleFrom - pos);
747+ } else {
748+ context->setContextProperty(QLatin1String("heightToClip"), QVariant::fromValue<int>(0));
749+ }
742// qDebug() << "ListViewWithPageHeader::updatePolish" << /*index << */pos + m_clipItem->y() << /*QQuickItemPrivate::get(item)->culled <<*/ (pos + item->height() < visibleFrom) << (pos > visibleTo);
750// qDebug() << "ListViewWithPageHeader::updatePolish" << /*index << */pos + m_clipItem->y() << /*QQuickItemPrivate::get(item)->culled <<*/ (pos + item->height() < visibleFrom) << (pos > visibleTo);
743 pos += item->height();
751 pos += item->height();
744 ++modelIndex;
752 ++modelIndex;