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

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

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