on xenial help sign in
Rework the Base.qml clipping to work on the new ListViewWithPageHeader
commit52f8f32510bf1985c2bcfb83608d355d51702351 authorAlbert Astals <albert.astals@canonical.com> dateWed 12 Jun 2013, 12:25 (13 years ago) parent3234320
2 files changed+23−22
Components/ListItems/Base.qml+15−22 plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+8
Components/ListItems/Base.qml+15−22
@@ -54,35 +54,28 @@ AbstractButton {
5454 */
5555 function __showDivider() {
5656 // if we're not in ListView, always show a thin dividing line at the bottom
57− if (ListView.view !== null) {
58−
59− // if we're last item in ListView don't show divider
60− if (index === ListView.view.model.count - 1) return false;
57+ var model = null;
58+ if (typeof ListViewWithPageHeader !== 'undefined') {
59+ if (typeof ListViewWithPageHeader.model !== 'undefined') {
60+ model = ListViewWithPageHeader.model;
61+ }
62+ } else if (ListView.view !== null) {
63+ model = ListView.view.model;
6164 }
65+ // if we're last item in ListView don't show divider
66+ if (model && index === model.count - 1) return false;
67+
6268 return true;
6369 }
6470
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−
7071 property real __heightToClip: {
7172 // Check this is in position where clipping is needed
72− if (__clippingRequired && __yPositionRelativeToListView <= __sectionDelegateHeight
73− && __yPositionRelativeToListView > -height) {
74− return Math.min(__sectionDelegateHeight - __yPositionRelativeToListView, height);
75− } else {
76− return 0;
77− }
78− }
79−
80− property int __sectionDelegateHeight: {
81− if (__clippingRequired && ListView.view.hasOwnProperty("__sectionDelegateHeight")) {
82− return ListView.view.__sectionDelegateHeight;
83− } else {
84− return 0;
73+ if (typeof ListViewWithPageHeader !== 'undefined') {
74+ if (typeof heightToClip !== 'undefined') {
75+ return heightToClip;
76+ }
8577 }
78+ return 0;
8679 }
8780
8881 /*!
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+8
@@ -531,6 +531,8 @@ void ListViewWithPageHeader::itemCreated(int modelIndex, QQuickItem *item)
531531// qDebug() << "ListViewWithPageHeader::itemCreated" << modelIndex << item;
532532
533533 item->setParentItem(m_clipItem);
534+ QQmlContext *context = QQmlEngine::contextForObject(item)->parentContext();
535+ context->setContextProperty(QLatin1String("ListViewWithPageHeader"), this);
534536 if (m_asyncRequestedIndexes.remove(modelIndex)) {
535537 createItem(modelIndex, false);
536538 }
@@ -739,6 +741,12 @@ void ListViewWithPageHeader::updatePolish()
739741 }
740742 }
741743 }
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+ }
742750// qDebug() << "ListViewWithPageHeader::updatePolish" << /*index << */pos + m_clipItem->y() << /*QQuickItemPrivate::get(item)->culled <<*/ (pos + item->height() < visibleFrom) << (pos > visibleTo);
743751 pos += item->height();
744752 ++modelIndex;