1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtQuick module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QQUICKLISTVIEW_P_H
41 #define QQUICKLISTVIEW_P_H
42 
43 //
44 //  W A R N I N G
45 //  -------------
46 //
47 // This file is not part of the Qt API.  It exists purely as an
48 // implementation detail.  This header file may change from version to
49 // version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 
54 #include <private/qtquickglobal_p.h>
55 
56 QT_REQUIRE_CONFIG(quick_listview);
57 
58 #include "qquickitemview_p.h"
59 
60 #include <private/qtquickglobal_p.h>
61 
62 QT_BEGIN_NAMESPACE
63 
64 class QQuickListView;
65 class QQuickListViewPrivate;
66 class Q_QUICK_PRIVATE_EXPORT QQuickViewSection : public QObject
67 {
68     Q_OBJECT
69     Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY propertyChanged)
70     Q_PROPERTY(SectionCriteria criteria READ criteria WRITE setCriteria NOTIFY criteriaChanged)
71     Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
72     Q_PROPERTY(int labelPositioning READ labelPositioning WRITE setLabelPositioning NOTIFY labelPositioningChanged)
73     QML_NAMED_ELEMENT(ViewSection)
74 public:
75     QQuickViewSection(QQuickListView *parent=nullptr);
76 
property()77     QString property() const { return m_property; }
78     void setProperty(const QString &);
79 
80     enum SectionCriteria { FullString, FirstCharacter };
Q_ENUM(SectionCriteria)81     Q_ENUM(SectionCriteria)
82     SectionCriteria criteria() const { return m_criteria; }
83     void setCriteria(SectionCriteria);
84 
delegate()85     QQmlComponent *delegate() const { return m_delegate; }
86     void setDelegate(QQmlComponent *delegate);
87 
88     QString sectionString(const QString &value);
89 
90     enum LabelPositioning { InlineLabels = 0x01, CurrentLabelAtStart = 0x02, NextLabelAtEnd = 0x04 };
Q_ENUM(LabelPositioning)91     Q_ENUM(LabelPositioning)
92     int labelPositioning() const { return m_labelPositioning; }
93     void setLabelPositioning(int pos);
94 
95 Q_SIGNALS:
96     void sectionsChanged();
97     void propertyChanged();
98     void criteriaChanged();
99     void delegateChanged();
100     void labelPositioningChanged();
101 
102 private:
103     QString m_property;
104     SectionCriteria m_criteria;
105     QQmlComponent *m_delegate;
106     int m_labelPositioning;
107     QQuickListViewPrivate *m_view;
108 };
109 
110 
111 class QQmlInstanceModel;
112 class QQuickListViewAttached;
113 class Q_QUICK_PRIVATE_EXPORT QQuickListView : public QQuickItemView
114 {
115     Q_OBJECT
116     Q_DECLARE_PRIVATE(QQuickListView)
117 
118     Q_PROPERTY(qreal highlightMoveVelocity READ highlightMoveVelocity WRITE setHighlightMoveVelocity NOTIFY highlightMoveVelocityChanged)
119     Q_PROPERTY(qreal highlightResizeVelocity READ highlightResizeVelocity WRITE setHighlightResizeVelocity NOTIFY highlightResizeVelocityChanged)
120     Q_PROPERTY(int highlightResizeDuration READ highlightResizeDuration WRITE setHighlightResizeDuration NOTIFY highlightResizeDurationChanged)
121 
122     Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged)
123     Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
124 
125     Q_PROPERTY(QQuickViewSection *section READ sectionCriteria CONSTANT)
126     Q_PROPERTY(QString currentSection READ currentSection NOTIFY currentSectionChanged)
127 
128     Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged)
129 
130     Q_PROPERTY(HeaderPositioning headerPositioning READ headerPositioning WRITE setHeaderPositioning NOTIFY headerPositioningChanged REVISION 4)
131     Q_PROPERTY(FooterPositioning footerPositioning READ footerPositioning WRITE setFooterPositioning NOTIFY footerPositioningChanged REVISION 4)
132 
133     Q_CLASSINFO("DefaultProperty", "data")
134     QML_NAMED_ELEMENT(ListView)
135     QML_ATTACHED(QQuickListViewAttached)
136 
137 public:
138     QQuickListView(QQuickItem *parent=nullptr);
139     ~QQuickListView();
140 
141     qreal spacing() const;
142     void setSpacing(qreal spacing);
143 
144     enum Orientation { Horizontal = Qt::Horizontal, Vertical = Qt::Vertical };
145     Q_ENUM(Orientation)
146     Orientation orientation() const;
147     void setOrientation(Orientation);
148 
149     QQuickViewSection *sectionCriteria();
150     QString currentSection() const;
151 
152     void setHighlightFollowsCurrentItem(bool) override;
153 
154     qreal highlightMoveVelocity() const;
155     void setHighlightMoveVelocity(qreal);
156 
157     qreal highlightResizeVelocity() const;
158     void setHighlightResizeVelocity(qreal);
159 
160     int highlightResizeDuration() const;
161     void setHighlightResizeDuration(int);
162 
163     void setHighlightMoveDuration(int) override;
164 
165     enum SnapMode { NoSnap, SnapToItem, SnapOneItem };
166     Q_ENUM(SnapMode)
167     SnapMode snapMode() const;
168     void setSnapMode(SnapMode mode);
169 
170     enum HeaderPositioning { InlineHeader, OverlayHeader, PullBackHeader };
171     Q_ENUM(HeaderPositioning)
172     HeaderPositioning headerPositioning() const;
173     void setHeaderPositioning(HeaderPositioning positioning);
174 
175     enum FooterPositioning { InlineFooter, OverlayFooter, PullBackFooter };
176     Q_ENUM(FooterPositioning)
177     FooterPositioning footerPositioning() const;
178     void setFooterPositioning(FooterPositioning positioning);
179 
180     static QQuickListViewAttached *qmlAttachedProperties(QObject *);
181 
182 public Q_SLOTS:
183     void incrementCurrentIndex();
184     void decrementCurrentIndex();
185 
186 Q_SIGNALS:
187     void spacingChanged();
188     void orientationChanged();
189     void currentSectionChanged();
190     void highlightMoveVelocityChanged();
191     void highlightResizeVelocityChanged();
192     void highlightResizeDurationChanged();
193     void snapModeChanged();
194     Q_REVISION(4) void headerPositioningChanged();
195     Q_REVISION(4) void footerPositioningChanged();
196 
197 protected:
198     void viewportMoved(Qt::Orientations orient) override;
199     void keyPressEvent(QKeyEvent *) override;
200     void geometryChanged(const QRectF &newGeometry,const QRectF &oldGeometry) override;
201     void initItem(int index, QObject *item) override;
202     qreal maxYExtent() const override;
203     qreal maxXExtent() const override;
204 };
205 
206 class QQuickListViewAttached : public QQuickItemViewAttached
207 {
208     Q_OBJECT
209 
210 public:
QQuickListViewAttached(QObject * parent)211     QQuickListViewAttached(QObject *parent)
212         : QQuickItemViewAttached(parent), m_sectionItem(nullptr) {}
~QQuickListViewAttached()213     ~QQuickListViewAttached() {}
214 
215 public:
216     QPointer<QQuickItem> m_sectionItem;
217 };
218 
219 
220 QT_END_NAMESPACE
221 
222 QML_DECLARE_TYPE(QQuickListView)
223 QML_DECLARE_TYPE(QQuickViewSection)
224 
225 #endif // QQUICKLISTVIEW_P_H
226