| 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 QQUICKGRIDVIEW_P_H |
| 5 | #define QQUICKGRIDVIEW_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 <QtQuick/private/qtquickglobal_p.h> |
| 19 | |
| 20 | QT_REQUIRE_CONFIG(quick_gridview); |
| 21 | |
| 22 | #include "qquickitemview_p.h" |
| 23 | |
| 24 | QT_BEGIN_NAMESPACE |
| 25 | |
| 26 | class QQuickGridViewAttached; |
| 27 | class QQuickGridViewPrivate; |
| 28 | class Q_QUICK_EXPORT QQuickGridView : public QQuickItemView |
| 29 | { |
| 30 | Q_OBJECT |
| 31 | Q_DECLARE_PRIVATE(QQuickGridView) |
| 32 | |
| 33 | Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged) |
| 34 | Q_PROPERTY(qreal cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellWidthChanged) |
| 35 | Q_PROPERTY(qreal cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellHeightChanged) |
| 36 | |
| 37 | Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged) |
| 38 | |
| 39 | Q_CLASSINFO("DefaultProperty" , "data" ) |
| 40 | QML_NAMED_ELEMENT(GridView) |
| 41 | QML_ADDED_IN_VERSION(2, 0) |
| 42 | QML_ATTACHED(QQuickGridViewAttached) |
| 43 | |
| 44 | public: |
| 45 | enum Flow { |
| 46 | FlowLeftToRight = LeftToRight, |
| 47 | FlowTopToBottom = TopToBottom |
| 48 | }; |
| 49 | Q_ENUM(Flow) |
| 50 | |
| 51 | QQuickGridView(QQuickItem *parent=nullptr); |
| 52 | |
| 53 | void setHighlightFollowsCurrentItem(bool) override; |
| 54 | void setHighlightMoveDuration(int) override; |
| 55 | |
| 56 | Flow flow() const; |
| 57 | void setFlow(Flow); |
| 58 | |
| 59 | qreal cellWidth() const; |
| 60 | void setCellWidth(qreal); |
| 61 | |
| 62 | qreal cellHeight() const; |
| 63 | void setCellHeight(qreal); |
| 64 | |
| 65 | enum SnapMode { NoSnap, SnapToRow, SnapOneRow }; |
| 66 | Q_ENUM(SnapMode) |
| 67 | SnapMode snapMode() const; |
| 68 | void setSnapMode(SnapMode mode); |
| 69 | |
| 70 | static QQuickGridViewAttached *qmlAttachedProperties(QObject *); |
| 71 | |
| 72 | public Q_SLOTS: |
| 73 | void moveCurrentIndexUp(); |
| 74 | void moveCurrentIndexDown(); |
| 75 | void moveCurrentIndexLeft(); |
| 76 | void moveCurrentIndexRight(); |
| 77 | |
| 78 | Q_SIGNALS: |
| 79 | void cellWidthChanged(); |
| 80 | void cellHeightChanged(); |
| 81 | void highlightMoveDurationChanged(); |
| 82 | void flowChanged(); |
| 83 | void snapModeChanged(); |
| 84 | |
| 85 | protected: |
| 86 | void viewportMoved(Qt::Orientations) override; |
| 87 | void keyPressEvent(QKeyEvent *) override; |
| 88 | void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; |
| 89 | void initItem(int index, QObject *item) override; |
| 90 | }; |
| 91 | |
| 92 | class QQuickGridViewAttached : public QQuickItemViewAttached |
| 93 | { |
| 94 | Q_OBJECT |
| 95 | Q_PROPERTY(QQuickGridView *view READ view NOTIFY viewChanged FINAL) |
| 96 | public: |
| 97 | QQuickGridViewAttached(QObject *parent) |
| 98 | : QQuickItemViewAttached(parent) {} |
| 99 | ~QQuickGridViewAttached() {} |
| 100 | QQuickGridView *view() const { return m_view; } |
| 101 | void setView(QQuickGridView *view) { |
| 102 | if (view != m_view) { |
| 103 | m_view = view; |
| 104 | Q_EMIT viewChanged(); |
| 105 | } |
| 106 | } |
| 107 | private: |
| 108 | QPointer<QQuickGridView> m_view; |
| 109 | }; |
| 110 | |
| 111 | |
| 112 | QT_END_NAMESPACE |
| 113 | |
| 114 | #endif // QQUICKGRIDVIEW_P_H |
| 115 | |