1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QQUICKPATHVIEW_P_P_H
43 #define QQUICKPATHVIEW_P_P_H
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
56 #include "qquickpathview_p.h"
57 #include "qquickitem_p.h"
58 #include "qquickvisualdatamodel_p.h"
60 #include <QtQml/qqml.h>
61 #include <QtCore/qdatetime.h>
62 #include <QtCore/qcoreapplication.h>
64 #include <private/qquickanimation_p_p.h>
65 #include <private/qqmlguard_p.h>
66 #include <private/qquicktimeline_p_p.h>
70 class QQmlOpenMetaObjectType;
71 class QQuickPathViewAttached;
72 class QQuickPathViewPrivate : public QQuickItemPrivate, public QQuickItemChangeListener
74 Q_DECLARE_PUBLIC(QQuickPathView)
77 QQuickPathViewPrivate()
78 : path(0), currentIndex(0), currentItemOffset(0.0), startPc(0), lastDist(0)
79 , lastElapsed(0), offset(0.0), offsetAdj(0.0), mappedRange(1.0)
80 , stealMouse(false), ownModel(false), interactive(true), haveHighlightRange(true)
81 , autoHighlight(true), highlightUp(false), layoutScheduled(false)
82 , moving(false), flicking(false), requestedOnPath(false), inRequest(false)
83 , dragMargin(0), deceleration(100)
84 , moveOffset(this, &QQuickPathViewPrivate::setAdjustedOffset), flickDuration(0)
85 , firstIndex(-1), pathItems(-1), requestedIndex(-1), requestedZ(0)
86 , moveReason(Other), moveDirection(Shortest), attType(0), highlightComponent(0), highlightItem(0)
87 , moveHighlight(this, &QQuickPathViewPrivate::setHighlightPosition)
88 , highlightPosition(0)
89 , highlightRangeStart(0), highlightRangeEnd(0)
90 , highlightRangeMode(QQuickPathView::StrictlyEnforceRange)
91 , highlightMoveDuration(300), modelCount(0)
97 void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) {
98 if ((newGeometry.size() != oldGeometry.size())
99 && (!highlightItem || item != highlightItem)) {
100 if (QQuickPathViewAttached *att = attached(item))
106 void scheduleLayout() {
108 if (!layoutScheduled) {
109 layoutScheduled = true;
114 QQuickItem *getItem(int modelIndex, qreal z = 0, bool onPath=true);
115 void releaseItem(QQuickItem *item);
116 QQuickPathViewAttached *attached(QQuickItem *item);
117 QQmlOpenMetaObjectType *attachedType();
119 void updateMappedRange();
120 qreal positionOfIndex(qreal index) const;
121 void createHighlight();
122 void updateHighlight();
123 void setHighlightPosition(qreal pos);
124 bool isValid() const {
125 return model && model->count() > 0 && model->isValid() && path;
128 void handleMousePressEvent(QMouseEvent *event);
129 void handleMouseMoveEvent(QMouseEvent *event);
130 void handleMouseReleaseEvent(QMouseEvent *);
132 int calcCurrentIndex();
133 void createCurrentItem();
134 void updateCurrent();
135 static void fixOffsetCallback(void*);
137 void setOffset(qreal offset);
138 void setAdjustedOffset(qreal offset);
140 void updateItem(QQuickItem *, qreal);
141 void snapToCurrent();
142 QPointF pointNear(const QPointF &point, qreal *nearPercent=0) const;
143 void addVelocitySample(qreal v);
144 qreal calcVelocity() const;
148 QQmlGuard<QQuickItem> currentItem;
149 qreal currentItemOffset;
159 bool interactive : 1;
160 bool haveHighlightRange : 1;
161 bool autoHighlight : 1;
162 bool highlightUp : 1;
163 bool layoutScheduled : 1;
166 bool requestedOnPath : 1;
168 QElapsedTimer lastPosTime;
173 QQuickTimeLineValueProxy<QQuickPathViewPrivate> moveOffset;
179 QList<QQuickItem *> items;
180 QList<QQuickItem *> itemCache;
181 QQmlGuard<QQuickVisualModel> model;
182 QVariant modelVariant;
183 enum MovementReason { Other, SetIndex, Mouse };
184 MovementReason moveReason;
185 enum MovementDirection { Shortest, Negative, Positive };
186 MovementDirection moveDirection;
187 QQmlOpenMetaObjectType *attType;
188 QQmlComponent *highlightComponent;
189 QQuickItem *highlightItem;
190 QQuickTimeLineValueProxy<QQuickPathViewPrivate> moveHighlight;
191 qreal highlightPosition;
192 qreal highlightRangeStart;
193 qreal highlightRangeEnd;
194 QQuickPathView::HighlightRangeMode highlightRangeMode;
195 int highlightMoveDuration;
197 QPODVector<qreal,10> velocityBuffer;