| 1 | // Copyright (C) 2017 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 QQUICKTUMBLER_P_H |
| 5 | #define QQUICKTUMBLER_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 <QtCore/qvariant.h> |
| 19 | #include <QtQml/qqmlcomponent.h> |
| 20 | #include <QtQuickTemplates2/private/qquickcontrol_p.h> |
| 21 | |
| 22 | QT_BEGIN_NAMESPACE |
| 23 | |
| 24 | class QQuickTumblerAttached; |
| 25 | class QQuickTumblerPrivate; |
| 26 | |
| 27 | class Q_QUICKTEMPLATES2_EXPORT QQuickTumbler : public QQuickControl |
| 28 | { |
| 29 | Q_OBJECT |
| 30 | Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged FINAL) |
| 31 | Q_PROPERTY(int count READ count NOTIFY countChanged FINAL) |
| 32 | Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL) |
| 33 | Q_PROPERTY(QQuickItem *currentItem READ currentItem NOTIFY currentItemChanged FINAL) |
| 34 | Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL) |
| 35 | Q_PROPERTY(int visibleItemCount READ visibleItemCount WRITE setVisibleItemCount NOTIFY visibleItemCountChanged FINAL) |
| 36 | // 2.1 (Qt 5.8) |
| 37 | Q_PROPERTY(bool wrap READ wrap WRITE setWrap RESET resetWrap NOTIFY wrapChanged FINAL REVISION(2, 1)) |
| 38 | // 2.2 (Qt 5.9) |
| 39 | Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged FINAL REVISION(2, 2)) |
| 40 | QML_NAMED_ELEMENT(Tumbler) |
| 41 | QML_ATTACHED(QQuickTumblerAttached) |
| 42 | QML_ADDED_IN_VERSION(2, 0) |
| 43 | |
| 44 | public: |
| 45 | explicit QQuickTumbler(QQuickItem *parent = nullptr); |
| 46 | ~QQuickTumbler(); |
| 47 | |
| 48 | QVariant model() const; |
| 49 | void setModel(const QVariant &model); |
| 50 | |
| 51 | int count() const; |
| 52 | |
| 53 | int currentIndex() const; |
| 54 | void setCurrentIndex(int currentIndex); |
| 55 | QQuickItem *currentItem() const; |
| 56 | |
| 57 | QQmlComponent *delegate() const; |
| 58 | void setDelegate(QQmlComponent *delegate); |
| 59 | |
| 60 | int visibleItemCount() const; |
| 61 | void setVisibleItemCount(int visibleItemCount); |
| 62 | |
| 63 | static QQuickTumblerAttached *qmlAttachedProperties(QObject *object); |
| 64 | |
| 65 | // 2.1 (Qt 5.8) |
| 66 | bool wrap() const; |
| 67 | void setWrap(bool wrap); |
| 68 | void resetWrap(); |
| 69 | |
| 70 | // 2.2 (Qt 5.9) |
| 71 | bool isMoving() const; |
| 72 | |
| 73 | enum PositionMode { |
| 74 | Beginning, |
| 75 | Center, |
| 76 | End, |
| 77 | Visible, // ListView-only |
| 78 | Contain, |
| 79 | SnapPosition |
| 80 | }; |
| 81 | Q_ENUM(PositionMode) |
| 82 | |
| 83 | // 2.5 (Qt 5.12) |
| 84 | Q_REVISION(2, 5) Q_INVOKABLE void positionViewAtIndex(int index, PositionMode mode); |
| 85 | |
| 86 | Q_SIGNALS: |
| 87 | void modelChanged(); |
| 88 | void countChanged(); |
| 89 | void currentIndexChanged(); |
| 90 | void currentItemChanged(); |
| 91 | void delegateChanged(); |
| 92 | void visibleItemCountChanged(); |
| 93 | // 2.1 (Qt 5.8) |
| 94 | Q_REVISION(2, 1) void wrapChanged(); |
| 95 | // 2.2 (Qt 5.9) |
| 96 | Q_REVISION(2, 2) void movingChanged(); |
| 97 | |
| 98 | protected: |
| 99 | void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; |
| 100 | void componentComplete() override; |
| 101 | void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) override; |
| 102 | void keyPressEvent(QKeyEvent *event) override; |
| 103 | void updatePolish() override; |
| 104 | |
| 105 | QFont defaultFont() const override; |
| 106 | |
| 107 | private: |
| 108 | Q_DISABLE_COPY(QQuickTumbler) |
| 109 | Q_DECLARE_PRIVATE(QQuickTumbler) |
| 110 | |
| 111 | Q_PRIVATE_SLOT(d_func(), void _q_updateItemWidths()) |
| 112 | Q_PRIVATE_SLOT(d_func(), void _q_updateItemHeights()) |
| 113 | Q_PRIVATE_SLOT(d_func(), void _q_onViewCurrentIndexChanged()) |
| 114 | Q_PRIVATE_SLOT(d_func(), void _q_onViewCountChanged()) |
| 115 | Q_PRIVATE_SLOT(d_func(), void _q_onViewOffsetChanged()) |
| 116 | Q_PRIVATE_SLOT(d_func(), void _q_onViewContentYChanged()) |
| 117 | }; |
| 118 | |
| 119 | class QQuickTumblerAttachedPrivate; |
| 120 | |
| 121 | class Q_QUICKTEMPLATES2_EXPORT QQuickTumblerAttached : public QObject |
| 122 | { |
| 123 | Q_OBJECT |
| 124 | Q_PROPERTY(QQuickTumbler *tumbler READ tumbler CONSTANT FINAL) |
| 125 | Q_PROPERTY(qreal displacement READ displacement NOTIFY displacementChanged FINAL) |
| 126 | |
| 127 | public: |
| 128 | explicit QQuickTumblerAttached(QObject *parent = nullptr); |
| 129 | |
| 130 | QQuickTumbler *tumbler() const; |
| 131 | qreal displacement() const; |
| 132 | |
| 133 | Q_SIGNALS: |
| 134 | void displacementChanged(); |
| 135 | |
| 136 | private: |
| 137 | Q_DISABLE_COPY(QQuickTumblerAttached) |
| 138 | Q_DECLARE_PRIVATE(QQuickTumblerAttached) |
| 139 | }; |
| 140 | |
| 141 | QT_END_NAMESPACE |
| 142 | |
| 143 | #endif // QQUICKTUMBLER_P_H |
| 144 | |