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
int firstCreatedIndex()
const;
90 Q_INVOKABLE
int createdItemCount()
const;
91 Q_INVOKABLE QQuickItem *item(
int modelIndex)
const;
96 Q_INVOKABLE
bool maximizeVisibleArea(
int modelIndex);
97 Q_INVOKABLE
bool maximizeVisibleArea(
int modelIndex,
int itemHeight);
101 void delegateChanged();
102 void headerChanged();
103 void sectionDelegateChanged();
104 void sectionPropertyChanged();
105 void forceNoClipChanged();
106 void stickyHeaderHeightChanged();
107 void headerItemShownHeightChanged();
110 void componentComplete()
override;
111 void viewportMoved(Qt::Orientations orient)
override;
112 qreal minYExtent()
const override;
113 void itemGeometryChanged(QQuickItem *item,
const QRectF &newGeometry,
const QRectF &oldGeometry)
override;
114 void itemImplicitHeightChanged(QQuickItem *item)
override;
115 void updatePolish()
override;
118 void itemCreated(
int modelIndex, QObject *
object);
119 void onContentHeightChanged();
120 void onContentWidthChanged();
121 void onHeightChanged();
122 void onModelUpdated(
const QQmlChangeSet &changeSet,
bool reset);
123 void contentYAnimationRunningChanged(
bool running);
129 qreal height()
const;
132 void setY(qreal newY);
135 void setCulled(
bool culled);
137 QQuickItem *sectionItem()
const {
return m_sectionItem; }
138 void setSectionItem(QQuickItem *sectionItem);
142 QQuickItem *m_sectionItem;
145 bool maximizeVisibleArea(ListItem *listItem,
int listItemHeight);
147 void createDelegateModel();
151 bool addVisibleItems(qreal fillFrom, qreal fillTo,
bool asynchronous);
152 bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo);
153 ListItem *createItem(
int modelIndex,
bool asynchronous);
155 void adjustHeader(qreal diff);
156 void adjustMinYExtent();
157 void updateClipItem();
158 void headerHeightChanged(qreal newHeaderHeight, qreal oldHeaderHeight, qreal oldHeaderY);
159 ListItem *itemAtIndex(
int modelIndex)
const;
160 void releaseItem(ListItem *item);
161 void reallyReleaseItem(ListItem *item);
162 void updateWatchedRoles();
163 QQuickItem *getSectionItem(
int modelIndex,
bool alreadyInserted);
164 QQuickItem *getSectionItem(
const QString §ionText);
166 QQmlDelegateModel *m_delegateModel;
169 int m_asyncRequestedIndex;
172 bool m_delegateValidated;
175 QList<ListItem *> m_visibleItems;
176 int m_firstVisibleIndex;
180 QQuickItem *m_clipItem;
184 bool m_contentHeightDirty;
186 QQuickItem *m_headerItem;
187 qreal m_previousContentY;
188 qreal m_previousHeaderImplicitHeight;
189 qreal m_headerItemShownHeight;
191 enum ContentYAnimationType { ContentYAnimationShowHeader, ContentYAnimationMaximizeVisibleArea };
192 ContentYAnimationType contentYAnimationType;
193 QQuickNumberAnimation *m_contentYAnimation;
195 QQmlComponent *m_sectionDelegate;
196 QString m_sectionProperty;
197 QQuickItem *m_topSectionItem;
201 bool m_inContentHeightKeepHeaderShown;
205 QList<ListItem *> m_itemsToRelease;