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 QtDeclarative 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 <QtDeclarative/qdeclarative.h>
61 #include <QtCore/qdatetime.h>
62 #include <QtCore/qcoreapplication.h>
64 #include <private/qdeclarativeanimation_p_p.h>
65 #include <private/qdeclarativeguard_p.h>
66 #include <private/qdeclarativetimeline_p_p.h>
70 class QDeclarativeOpenMetaObjectType;
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)
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 QDeclarativeOpenMetaObjectType *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;
144 QDeclarativePath *path;
146 QDeclarativeGuard<QQuickItem> currentItem;
147 qreal currentItemOffset;
157 bool interactive : 1;
158 bool haveHighlightRange : 1;
159 bool autoHighlight : 1;
160 bool highlightUp : 1;
161 bool layoutScheduled : 1;
164 bool requestedOnPath : 1;
166 QElapsedTimer lastPosTime;
170 QDeclarativeTimeLine tl;
171 QDeclarativeTimeLineValueProxy<QQuickPathViewPrivate> moveOffset;
176 QList<QQuickItem *> items;
177 QList<QQuickItem *> itemCache;
178 QDeclarativeGuard<QQuickVisualModel> model;
179 QVariant modelVariant;
180 enum MovementReason { Other, SetIndex, Mouse };
181 MovementReason moveReason;
182 enum MovementDirection { Shortest, Negative, Positive };
183 MovementDirection moveDirection;
184 QDeclarativeOpenMetaObjectType *attType;
185 QDeclarativeComponent *highlightComponent;
186 QQuickItem *highlightItem;
187 QDeclarativeTimeLineValueProxy<QQuickPathViewPrivate> moveHighlight;
188 qreal highlightPosition;
189 qreal highlightRangeStart;
190 qreal highlightRangeEnd;
191 QQuickPathView::HighlightRangeMode highlightRangeMode;
192 int highlightMoveDuration;