1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKLISTVIEW_P_H
5#define QQUICKLISTVIEW_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <private/qtquickglobal_p.h>
19
20QT_REQUIRE_CONFIG(quick_listview);
21
22#include "qquickitemview_p.h"
23
24#include <private/qtquickglobal_p.h>
25
26QT_BEGIN_NAMESPACE
27
28class QQuickListView;
29class QQuickListViewPrivate;
30class Q_QUICK_PRIVATE_EXPORT QQuickViewSection : public QObject
31{
32 Q_OBJECT
33 Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY propertyChanged FINAL)
34 Q_PROPERTY(SectionCriteria criteria READ criteria WRITE setCriteria NOTIFY criteriaChanged FINAL)
35 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL)
36 Q_PROPERTY(int labelPositioning READ labelPositioning WRITE setLabelPositioning NOTIFY labelPositioningChanged FINAL)
37 QML_NAMED_ELEMENT(ViewSection)
38 QML_ADDED_IN_VERSION(2, 0)
39public:
40 QQuickViewSection(QQuickListView *parent=nullptr);
41
42 QString property() const { return m_property; }
43 void setProperty(const QString &);
44
45 enum SectionCriteria { FullString, FirstCharacter };
46 Q_ENUM(SectionCriteria)
47 SectionCriteria criteria() const { return m_criteria; }
48 void setCriteria(SectionCriteria);
49
50 QQmlComponent *delegate() const { return m_delegate; }
51 void setDelegate(QQmlComponent *delegate);
52
53 QString sectionString(const QString &value);
54
55 enum LabelPositioning { InlineLabels = 0x01, CurrentLabelAtStart = 0x02, NextLabelAtEnd = 0x04 };
56 Q_ENUM(LabelPositioning)
57 int labelPositioning() const { return m_labelPositioning; }
58 void setLabelPositioning(int pos);
59
60Q_SIGNALS:
61 void sectionsChanged();
62 void propertyChanged();
63 void criteriaChanged();
64 void delegateChanged();
65 void labelPositioningChanged();
66
67private:
68 QString m_property;
69 SectionCriteria m_criteria;
70 QQmlComponent *m_delegate;
71 int m_labelPositioning;
72 QQuickListViewPrivate *m_view;
73};
74
75
76class QQmlInstanceModel;
77class QQuickListViewAttached;
78class Q_QUICK_PRIVATE_EXPORT QQuickListView : public QQuickItemView
79{
80 Q_OBJECT
81 Q_DECLARE_PRIVATE(QQuickListView)
82
83 Q_PROPERTY(qreal highlightMoveVelocity READ highlightMoveVelocity WRITE setHighlightMoveVelocity NOTIFY highlightMoveVelocityChanged FINAL)
84 Q_PROPERTY(qreal highlightResizeVelocity READ highlightResizeVelocity WRITE setHighlightResizeVelocity NOTIFY highlightResizeVelocityChanged FINAL)
85 Q_PROPERTY(int highlightResizeDuration READ highlightResizeDuration WRITE setHighlightResizeDuration NOTIFY highlightResizeDurationChanged FINAL)
86
87 Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged FINAL)
88 Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL)
89
90 Q_PROPERTY(QQuickViewSection *section READ sectionCriteria CONSTANT FINAL)
91 Q_PROPERTY(QString currentSection READ currentSection NOTIFY currentSectionChanged FINAL)
92
93 Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged FINAL)
94
95 Q_PROPERTY(HeaderPositioning headerPositioning READ headerPositioning WRITE setHeaderPositioning NOTIFY headerPositioningChanged REVISION(2, 4) FINAL)
96 Q_PROPERTY(FooterPositioning footerPositioning READ footerPositioning WRITE setFooterPositioning NOTIFY footerPositioningChanged REVISION(2, 4) FINAL)
97
98 Q_CLASSINFO("DefaultProperty", "data")
99 QML_NAMED_ELEMENT(ListView)
100 QML_ADDED_IN_VERSION(2, 0)
101 QML_ATTACHED(QQuickListViewAttached)
102
103public:
104 QQuickListView(QQuickItem *parent=nullptr);
105 ~QQuickListView();
106
107 qreal spacing() const;
108 void setSpacing(qreal spacing);
109
110 enum Orientation { Horizontal = Qt::Horizontal, Vertical = Qt::Vertical };
111 Q_ENUM(Orientation)
112 Orientation orientation() const;
113 void setOrientation(Orientation);
114
115 QQuickViewSection *sectionCriteria();
116 QString currentSection() const;
117
118 void setHighlightFollowsCurrentItem(bool) override;
119
120 qreal highlightMoveVelocity() const;
121 void setHighlightMoveVelocity(qreal);
122
123 qreal highlightResizeVelocity() const;
124 void setHighlightResizeVelocity(qreal);
125
126 int highlightResizeDuration() const;
127 void setHighlightResizeDuration(int);
128
129 void setHighlightMoveDuration(int) override;
130
131 enum SnapMode { NoSnap, SnapToItem, SnapOneItem };
132 Q_ENUM(SnapMode)
133 SnapMode snapMode() const;
134 void setSnapMode(SnapMode mode);
135
136 enum HeaderPositioning { InlineHeader, OverlayHeader, PullBackHeader };
137 Q_ENUM(HeaderPositioning)
138 HeaderPositioning headerPositioning() const;
139 void setHeaderPositioning(HeaderPositioning positioning);
140
141 enum FooterPositioning { InlineFooter, OverlayFooter, PullBackFooter };
142 Q_ENUM(FooterPositioning)
143 FooterPositioning footerPositioning() const;
144 void setFooterPositioning(FooterPositioning positioning);
145
146 static QQuickListViewAttached *qmlAttachedProperties(QObject *);
147
148public Q_SLOTS:
149 void incrementCurrentIndex();
150 void decrementCurrentIndex();
151
152Q_SIGNALS:
153 void spacingChanged();
154 void orientationChanged();
155 void currentSectionChanged();
156 void highlightMoveVelocityChanged();
157 void highlightResizeVelocityChanged();
158 void highlightResizeDurationChanged();
159 void snapModeChanged();
160 Q_REVISION(2, 4) void headerPositioningChanged();
161 Q_REVISION(2, 4) void footerPositioningChanged();
162
163protected:
164 void viewportMoved(Qt::Orientations orient) override;
165 void keyPressEvent(QKeyEvent *) override;
166 void geometryChange(const QRectF &newGeometry,const QRectF &oldGeometry) override;
167 void initItem(int index, QObject *item) override;
168 qreal maxYExtent() const override;
169 qreal maxXExtent() const override;
170};
171
172class Q_QUICK_PRIVATE_EXPORT QQuickListViewAttached : public QQuickItemViewAttached
173{
174 Q_OBJECT
175
176public:
177 QQuickListViewAttached(QObject *parent)
178 : QQuickItemViewAttached(parent), m_sectionItem(nullptr) {}
179 ~QQuickListViewAttached() {}
180
181public:
182 QPointer<QQuickItem> m_sectionItem;
183};
184
185
186QT_END_NAMESPACE
187
188QML_DECLARE_TYPE(QQuickListView)
189QML_DECLARE_TYPE(QQuickViewSection)
190
191#endif // QQUICKLISTVIEW_P_H
192

source code of qtdeclarative/src/quick/items/qquicklistview_p.h