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 QQUICKPATHVIEW_P_P_H
5#define QQUICKPATHVIEW_P_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_pathview);
21
22#include "qquickpathview_p.h"
23#include "qquickitem_p.h"
24
25#include <QtQml/qqml.h>
26#include <QtCore/qdatetime.h>
27#include <QtCore/qcoreapplication.h>
28
29#include <private/qquickanimation_p_p.h>
30#include <private/qqmldelegatemodel_p.h>
31#include <private/qquicktimeline_p_p.h>
32#include <private/qpodvector_p.h>
33
34#include <QtCore/qpointer.h>
35
36QT_BEGIN_NAMESPACE
37
38class QQmlOpenMetaObjectType;
39class QQuickPathViewAttached;
40class QQuickPathViewPrivate : public QQuickItemPrivate,
41 public QSafeQuickItemChangeListener<QQuickPathViewPrivate>
42{
43 Q_DECLARE_PUBLIC(QQuickPathView)
44
45public:
46 QQuickPathViewPrivate();
47
48 void init();
49
50 void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &) override {
51 if (change.sizeChange() && (!highlightItem || item != highlightItem)) {
52 if (QQuickPathViewAttached *att = attached(item))
53 att->m_percent = -1;
54 scheduleLayout();
55 }
56 }
57
58 void itemDestroyed(QQuickItem *item) override
59 {
60 if (!items.removeOne(t: item))
61 itemCache.removeOne(t: item);
62 }
63
64 void scheduleLayout() {
65 Q_Q(QQuickPathView);
66 if (!layoutScheduled) {
67 layoutScheduled = true;
68 q->polish();
69 }
70 }
71
72 QQuickItem *getItem(int modelIndex, qreal z = 0, bool async=false);
73 void releaseCurrentItem()
74 {
75 auto oldCurrentItem = std::exchange(obj&: currentItem, new_val: nullptr);
76 releaseItem(item: oldCurrentItem);
77 }
78 void releaseItem(QQuickItem *item);
79 QQuickPathViewAttached *attached(QQuickItem *item);
80 QQmlOpenMetaObjectType *attachedType();
81 void clear();
82 void updateMappedRange();
83 qreal positionOfIndex(qreal index) const;
84 bool isInBound(qreal position, qreal lower, qreal upper, bool emptyRangeCheck = true) const;
85 void createHighlight();
86 void updateHighlight();
87 void setHighlightPosition(qreal pos);
88 bool isValid() const {
89 return model && model->count() > 0 && model->isValid() && path;
90 }
91
92 void handleMousePressEvent(QMouseEvent *event);
93 void handleMouseMoveEvent(QMouseEvent *event);
94 void handleMouseReleaseEvent(QMouseEvent *);
95
96 int calcCurrentIndex();
97 void createCurrentItem();
98 void updateCurrent();
99 static void fixOffsetCallback(void*);
100 void fixOffset();
101 void setOffset(qreal offset);
102 void setAdjustedOffset(qreal offset);
103 void regenerate();
104 void updateItem(QQuickItem *, qreal);
105 enum MovementReason { Other, SetIndex, Mouse };
106 void snapToIndex(int index, MovementReason reason);
107 QPointF pointNear(const QPointF &point, qreal *nearPercent=0) const;
108 void addVelocitySample(qreal v);
109 qreal calcVelocity() const;
110 qint64 computeCurrentTime(QInputEvent *event) const;
111 void setDragging(bool d);
112
113 QQuickPath *path;
114 int currentIndex;
115 QPointer<QQuickItem> currentItem;
116 qreal currentItemOffset;
117 qreal startPc;
118 QPointF startPoint;
119 QPointF startPos;
120 qreal offset;
121 qreal offsetAdj;
122 qreal mappedRange;
123 qreal mappedCache;
124 bool stealMouse : 1;
125 bool ownModel : 1;
126 bool interactive : 1;
127 bool haveHighlightRange : 1;
128 bool autoHighlight : 1;
129 bool highlightUp : 1;
130 bool layoutScheduled : 1;
131 bool moving : 1;
132 bool flicking : 1;
133 bool dragging : 1;
134 bool inRequest : 1;
135 bool delegateValidated : 1;
136 bool inRefill : 1;
137 QElapsedTimer timer;
138 qint64 lastPosTime;
139 QPointF lastPos;
140 qreal dragMargin;
141 qreal deceleration;
142 qreal maximumFlickVelocity;
143 QQuickTimeLine tl;
144 QQuickTimeLineValueProxy<QQuickPathViewPrivate> moveOffset;
145 int flickDuration;
146 int pathItems;
147 int requestedIndex;
148 int cacheSize;
149 int requestedCacheSize;
150 qreal requestedZ;
151 QList<QQuickItem *> items;
152 QList<QQuickItem *> itemCache;
153 QPointer<QQmlInstanceModel> model;
154 QVariant modelVariant;
155 MovementReason moveReason;
156 QQuickPathView::MovementDirection movementDirection; // default
157 QQuickPathView::MovementDirection moveDirection; // next movement
158 QQmlOpenMetaObjectType *attType;
159 QQmlComponent *highlightComponent;
160 QQuickItem *highlightItem;
161 QQuickTimeLineValueProxy<QQuickPathViewPrivate> moveHighlight;
162 qreal highlightPosition;
163 qreal highlightRangeStart;
164 qreal highlightRangeEnd;
165 QQuickPathView::HighlightRangeMode highlightRangeMode;
166 int highlightMoveDuration;
167 int modelCount;
168 QPODVector<qreal,10> velocityBuffer;
169 QQuickPathView::SnapMode snapMode;
170};
171
172QT_END_NAMESPACE
173
174#endif
175

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