| 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 | |
| 20 | QT_REQUIRE_CONFIG(quick_listview); |
| 21 | |
| 22 | #include "qquickitemview_p.h" |
| 23 | |
| 24 | #include <private/qtquickglobal_p.h> |
| 25 | |
| 26 | #include <QtCore/qpointer.h> |
| 27 | |
| 28 | QT_BEGIN_NAMESPACE |
| 29 | |
| 30 | class QQuickListView; |
| 31 | class QQuickListViewPrivate; |
| 32 | class Q_QUICK_EXPORT QQuickViewSection : public QObject |
| 33 | { |
| 34 | Q_OBJECT |
| 35 | Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY propertyChanged) |
| 36 | Q_PROPERTY(SectionCriteria criteria READ criteria WRITE setCriteria NOTIFY criteriaChanged) |
| 37 | Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) |
| 38 | Q_PROPERTY(int labelPositioning READ labelPositioning WRITE setLabelPositioning NOTIFY labelPositioningChanged) |
| 39 | QML_NAMED_ELEMENT(ViewSection) |
| 40 | QML_ADDED_IN_VERSION(2, 0) |
| 41 | public: |
| 42 | QQuickViewSection(QQuickListView *parent=nullptr); |
| 43 | |
| 44 | QString property() const { return m_property; } |
| 45 | void setProperty(const QString &); |
| 46 | |
| 47 | enum SectionCriteria { FullString, FirstCharacter }; |
| 48 | Q_ENUM(SectionCriteria) |
| 49 | SectionCriteria criteria() const { return m_criteria; } |
| 50 | void setCriteria(SectionCriteria); |
| 51 | |
| 52 | QQmlComponent *delegate() const { return m_delegate; } |
| 53 | void setDelegate(QQmlComponent *delegate); |
| 54 | |
| 55 | QString sectionString(const QString &value); |
| 56 | |
| 57 | enum LabelPositioning { InlineLabels = 0x01, CurrentLabelAtStart = 0x02, NextLabelAtEnd = 0x04 }; |
| 58 | Q_ENUM(LabelPositioning) |
| 59 | int labelPositioning() const { return m_labelPositioning; } |
| 60 | void setLabelPositioning(int pos); |
| 61 | |
| 62 | Q_SIGNALS: |
| 63 | void sectionsChanged(); |
| 64 | void propertyChanged(); |
| 65 | void criteriaChanged(); |
| 66 | void delegateChanged(); |
| 67 | void labelPositioningChanged(); |
| 68 | |
| 69 | private: |
| 70 | QString m_property; |
| 71 | SectionCriteria m_criteria; |
| 72 | QQmlComponent *m_delegate; |
| 73 | int m_labelPositioning; |
| 74 | QQuickListViewPrivate *m_view; |
| 75 | }; |
| 76 | |
| 77 | |
| 78 | class QQmlInstanceModel; |
| 79 | class QQuickListViewAttached; |
| 80 | class Q_QUICK_EXPORT QQuickListView : public QQuickItemView |
| 81 | { |
| 82 | Q_OBJECT |
| 83 | Q_DECLARE_PRIVATE(QQuickListView) |
| 84 | |
| 85 | Q_PROPERTY(qreal highlightMoveVelocity READ highlightMoveVelocity WRITE setHighlightMoveVelocity NOTIFY highlightMoveVelocityChanged) |
| 86 | Q_PROPERTY(qreal highlightResizeVelocity READ highlightResizeVelocity WRITE setHighlightResizeVelocity NOTIFY highlightResizeVelocityChanged) |
| 87 | Q_PROPERTY(int highlightResizeDuration READ highlightResizeDuration WRITE setHighlightResizeDuration NOTIFY highlightResizeDurationChanged) |
| 88 | |
| 89 | Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) |
| 90 | Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged) |
| 91 | |
| 92 | Q_PROPERTY(QQuickViewSection *section READ sectionCriteria CONSTANT) |
| 93 | Q_PROPERTY(QString currentSection READ currentSection NOTIFY currentSectionChanged) |
| 94 | |
| 95 | Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged) |
| 96 | |
| 97 | Q_PROPERTY(HeaderPositioning headerPositioning READ headerPositioning WRITE setHeaderPositioning NOTIFY headerPositioningChanged REVISION(2, 4)) |
| 98 | Q_PROPERTY(FooterPositioning footerPositioning READ footerPositioning WRITE setFooterPositioning NOTIFY footerPositioningChanged REVISION(2, 4)) |
| 99 | |
| 100 | Q_CLASSINFO("DefaultProperty" , "data" ) |
| 101 | QML_NAMED_ELEMENT(ListView) |
| 102 | QML_ADDED_IN_VERSION(2, 0) |
| 103 | QML_ATTACHED(QQuickListViewAttached) |
| 104 | |
| 105 | public: |
| 106 | QQuickListView(QQuickItem *parent=nullptr); |
| 107 | ~QQuickListView(); |
| 108 | |
| 109 | qreal spacing() const; |
| 110 | void setSpacing(qreal spacing); |
| 111 | |
| 112 | enum Orientation { Horizontal = Qt::Horizontal, Vertical = Qt::Vertical }; |
| 113 | Q_ENUM(Orientation) |
| 114 | Orientation orientation() const; |
| 115 | void setOrientation(Orientation); |
| 116 | |
| 117 | QQuickViewSection *sectionCriteria(); |
| 118 | QString currentSection() const; |
| 119 | |
| 120 | void setHighlightFollowsCurrentItem(bool) override; |
| 121 | |
| 122 | qreal highlightMoveVelocity() const; |
| 123 | void setHighlightMoveVelocity(qreal); |
| 124 | |
| 125 | qreal highlightResizeVelocity() const; |
| 126 | void setHighlightResizeVelocity(qreal); |
| 127 | |
| 128 | int highlightResizeDuration() const; |
| 129 | void setHighlightResizeDuration(int); |
| 130 | |
| 131 | void setHighlightMoveDuration(int) override; |
| 132 | |
| 133 | enum SnapMode { NoSnap, SnapToItem, SnapOneItem }; |
| 134 | Q_ENUM(SnapMode) |
| 135 | SnapMode snapMode() const; |
| 136 | void setSnapMode(SnapMode mode); |
| 137 | |
| 138 | enum { , , }; |
| 139 | Q_ENUM(HeaderPositioning) |
| 140 | HeaderPositioning () const; |
| 141 | void (HeaderPositioning positioning); |
| 142 | |
| 143 | enum { , , }; |
| 144 | Q_ENUM(FooterPositioning) |
| 145 | FooterPositioning () const; |
| 146 | void (FooterPositioning positioning); |
| 147 | |
| 148 | static QQuickListViewAttached *qmlAttachedProperties(QObject *); |
| 149 | |
| 150 | public Q_SLOTS: |
| 151 | void incrementCurrentIndex(); |
| 152 | void decrementCurrentIndex(); |
| 153 | |
| 154 | Q_SIGNALS: |
| 155 | void spacingChanged(); |
| 156 | void orientationChanged(); |
| 157 | void currentSectionChanged(); |
| 158 | void highlightMoveVelocityChanged(); |
| 159 | void highlightResizeVelocityChanged(); |
| 160 | void highlightResizeDurationChanged(); |
| 161 | void snapModeChanged(); |
| 162 | Q_REVISION(2, 4) void (); |
| 163 | Q_REVISION(2, 4) void (); |
| 164 | |
| 165 | protected: |
| 166 | void viewportMoved(Qt::Orientations orient) override; |
| 167 | void keyPressEvent(QKeyEvent *) override; |
| 168 | void geometryChange(const QRectF &newGeometry,const QRectF &oldGeometry) override; |
| 169 | void initItem(int index, QObject *item) override; |
| 170 | qreal maxYExtent() const override; |
| 171 | qreal maxXExtent() const override; |
| 172 | }; |
| 173 | |
| 174 | class Q_QUICK_EXPORT QQuickListViewAttached : public QQuickItemViewAttached |
| 175 | { |
| 176 | Q_OBJECT |
| 177 | Q_PROPERTY(QQuickListView *view READ view NOTIFY viewChanged FINAL) |
| 178 | public: |
| 179 | QQuickListViewAttached(QObject *parent) |
| 180 | : QQuickItemViewAttached(parent), m_sectionItem(nullptr) {} |
| 181 | ~QQuickListViewAttached() {} |
| 182 | QQuickListView *view() const { return m_view; } |
| 183 | void setView(QQuickListView *view) { |
| 184 | if (view != m_view) { |
| 185 | m_view = view; |
| 186 | Q_EMIT viewChanged(); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | public: |
| 191 | QPointer<QQuickItem> m_sectionItem; |
| 192 | private: |
| 193 | QPointer<QQuickListView> m_view; |
| 194 | }; |
| 195 | |
| 196 | |
| 197 | QT_END_NAMESPACE |
| 198 | |
| 199 | #endif // QQUICKLISTVIEW_P_H |
| 200 | |