17 #ifndef LISTVIEWWITHPAGEHEADER_H
18 #define LISTVIEWWITHPAGEHEADER_H
20 #include <private/qquickitemchangelistener_p.h>
21 #include <private/qquickflickable_p.h>
23 class QAbstractItemModel;
24 class QQuickNumberAnimation;
26 class QQmlDelegateModel;
49 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelChanged)
50 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
51 Q_PROPERTY(QQuickItem *pageHeader READ header WRITE setHeader NOTIFY headerChanged)
52 Q_PROPERTY(QQmlComponent *sectionDelegate READ sectionDelegate WRITE setSectionDelegate NOTIFY sectionDelegateChanged)
53 Q_PROPERTY(QString sectionProperty READ sectionProperty WRITE setSectionProperty NOTIFY sectionPropertyChanged)
54 Q_PROPERTY(
bool forceNoClip READ forceNoClip WRITE setForceNoClip NOTIFY forceNoClipChanged)
55 Q_PROPERTY(
int stickyHeaderHeight READ stickyHeaderHeight NOTIFY stickyHeaderHeightChanged)
56 Q_PROPERTY(qreal headerItemShownHeight READ headerItemShownHeight NOTIFY headerItemShownHeightChanged)
58 friend class ListViewWithPageHeaderTest;
59 friend class ListViewWithPageHeaderTestSection;
60 friend class ListViewWithPageHeaderTestExternalModel;
66 QAbstractItemModel *model()
const;
67 void setModel(QAbstractItemModel *model);
69 QQmlComponent *delegate()
const;
70 void setDelegate(QQmlComponent *delegate);
72 QQuickItem *header()
const;
73 void setHeader(QQuickItem *header);
75 QQmlComponent *sectionDelegate()
const;
76 void setSectionDelegate(QQmlComponent *delegate);
78 QString sectionProperty()
const;
79 void setSectionProperty(
const QString &property);
81 bool forceNoClip()
const;
82 void setForceNoClip(
bool noClip);
84 int stickyHeaderHeight()
const;
85 qreal headerItemShownHeight()
const;
87 Q_INVOKABLE
void positionAtBeginning();
88 Q_INVOKABLE
void showHeader();
89 Q_INVOKABLE QQuickItem *item(
int modelIndex)
const;
94 Q_INVOKABLE
bool maximizeVisibleArea(
int modelIndex);
95 Q_INVOKABLE
bool maximizeVisibleArea(
int modelIndex,
int itemHeight);
99 void delegateChanged();
100 void headerChanged();
101 void sectionDelegateChanged();
102 void sectionPropertyChanged();
103 void forceNoClipChanged();
104 void stickyHeaderHeightChanged();
105 void headerItemShownHeightChanged();
108 void componentComplete()
override;
109 void viewportMoved(Qt::Orientations orient)
override;
110 qreal minYExtent()
const override;
111 void itemGeometryChanged(QQuickItem *item,
const QRectF &newGeometry,
const QRectF &oldGeometry)
override;
112 void itemImplicitHeightChanged(QQuickItem *item)
override;
113 void updatePolish()
override;
116 void itemCreated(
int modelIndex, QObject *
object);
117 void onContentHeightChanged();
118 void onContentWidthChanged();
119 void onHeightChanged();
120 void onModelUpdated(
const QQmlChangeSet &changeSet,
bool reset);
121 void contentYAnimationRunningChanged(
bool running);
127 qreal height()
const;
130 void setY(qreal newY);
133 void setCulled(
bool culled);
135 QQuickItem *sectionItem()
const {
return m_sectionItem; }
136 void setSectionItem(QQuickItem *sectionItem);
140 QQuickItem *m_sectionItem;
143 bool maximizeVisibleArea(ListItem *listItem,
int listItemHeight);
145 void createDelegateModel();
149 bool addVisibleItems(qreal fillFrom, qreal fillTo,
bool asynchronous);
150 bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo);
151 ListItem *createItem(
int modelIndex,
bool asynchronous);
153 void adjustHeader(qreal diff);
154 void adjustMinYExtent();
155 void updateClipItem();
156 void headerHeightChanged(qreal newHeaderHeight, qreal oldHeaderHeight, qreal oldHeaderY);
157 ListItem *itemAtIndex(
int modelIndex)
const;
158 void releaseItem(ListItem *item);
159 void reallyReleaseItem(ListItem *item);
160 void updateWatchedRoles();
161 QQuickItem *getSectionItem(
int modelIndex,
bool alreadyInserted);
162 QQuickItem *getSectionItem(
const QString §ionText);
164 QQmlDelegateModel *m_delegateModel;
167 int m_asyncRequestedIndex;
170 bool m_delegateValidated;
173 QList<ListItem *> m_visibleItems;
174 int m_firstVisibleIndex;
178 QQuickItem *m_clipItem;
182 bool m_contentHeightDirty;
184 QQuickItem *m_headerItem;
185 qreal m_previousContentY;
186 qreal m_previousHeaderImplicitHeight;
187 qreal m_headerItemShownHeight;
189 enum ContentYAnimationType { ContentYAnimationShowHeader, ContentYAnimationMaximizeVisibleArea };
190 ContentYAnimationType contentYAnimationType;
191 QQuickNumberAnimation *m_contentYAnimation;
193 QQmlComponent *m_sectionDelegate;
194 QString m_sectionProperty;
195 QQuickItem *m_topSectionItem;
199 bool m_inContentHeightKeepHeaderShown;
203 QList<ListItem *> m_itemsToRelease;