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

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