1 // Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350
2 /****************************************************************************
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: http://www.qt-project.org/
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this
15 ** file. Please review the following information to ensure the GNU Lesser
16 ** General Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
23 ** GNU General Public License Usage
24 ** Alternatively, this file may be used under the terms of the GNU General
25 ** Public License version 3.0 as published by the Free Software Foundation
26 ** and appearing in the file LICENSE.GPL included in the packaging of this
27 ** file. Please review the following information to ensure the GNU General
28 ** Public License version 3.0 requirements will be met:
29 ** http://www.gnu.org/copyleft/gpl.html.
32 ** Alternatively, this file may be used in accordance with the terms and
33 ** conditions contained in a signed written agreement between you and Nokia.
41 ****************************************************************************/
43 #ifndef QQUICKPATHVIEW_P_P_H
44 #define QQUICKPATHVIEW_P_P_H
50 // This file is not part of the Qt API. It exists purely as an
51 // implementation detail. This header file may change from version to
52 // version without notice, or even be removed.
57 #include "qquickpathview_p.h"
58 #include "qquickitem_p.h"
59 #include "qquickvisualdatamodel_p.h"
61 #include <QtDeclarative/qdeclarative.h>
62 #include <QtCore/qdatetime.h>
63 #include <QtCore/qcoreapplication.h>
65 #include <private/qdeclarativeanimation_p_p.h>
66 #include <private/qdeclarativeguard_p.h>
67 #include <private/qdeclarativetimeline_p_p.h>
71 class QDeclarativeOpenMetaObjectType;
72 class QQuickPathViewAttached;
73 class QQuickPathViewPrivate : public QQuickItemPrivate, public QQuickItemChangeListener
75 Q_DECLARE_PUBLIC(QQuickPathView)
78 QQuickPathViewPrivate()
79 : path(0), currentIndex(0), currentItemOffset(0.0), startPc(0), lastDist(0)
80 , lastElapsed(0), offset(0.0), offsetAdj(0.0), mappedRange(1.0)
81 , stealMouse(false), ownModel(false), interactive(true), haveHighlightRange(true)
82 , autoHighlight(true), highlightUp(false), layoutScheduled(false)
83 , moving(false), flicking(false), requestedOnPath(false), inRequest(false)
84 , dragMargin(0), deceleration(100)
85 , moveOffset(this, &QQuickPathViewPrivate::setAdjustedOffset)
86 , firstIndex(-1), pathItems(-1), requestedIndex(-1), requestedZ(0)
87 , moveReason(Other), moveDirection(Shortest), attType(0), highlightComponent(0), highlightItem(0)
88 , moveHighlight(this, &QQuickPathViewPrivate::setHighlightPosition)
89 , highlightPosition(0)
90 , highlightRangeStart(0), highlightRangeEnd(0)
91 , highlightRangeMode(QQuickPathView::StrictlyEnforceRange)
92 , highlightMoveDuration(300), modelCount(0)
98 void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) {
99 if ((newGeometry.size() != oldGeometry.size())
100 && (!highlightItem || item != highlightItem)) {
101 if (QQuickPathViewAttached *att = attached(item))
107 void scheduleLayout() {
109 if (!layoutScheduled) {
110 layoutScheduled = true;
115 QQuickItem *getItem(int modelIndex, qreal z = 0, bool onPath=true);
116 void releaseItem(QQuickItem *item);
117 QQuickPathViewAttached *attached(QQuickItem *item);
118 QDeclarativeOpenMetaObjectType *attachedType();
120 void updateMappedRange();
121 qreal positionOfIndex(qreal index) const;
122 void createHighlight();
123 void updateHighlight();
124 void setHighlightPosition(qreal pos);
125 bool isValid() const {
126 return model && model->count() > 0 && model->isValid() && path;
129 void handleMousePressEvent(QMouseEvent *event);
130 void handleMouseMoveEvent(QMouseEvent *event);
131 void handleMouseReleaseEvent(QMouseEvent *);
133 int calcCurrentIndex();
134 void createCurrentItem();
135 void updateCurrent();
136 static void fixOffsetCallback(void*);
138 void setOffset(qreal offset);
139 void setAdjustedOffset(qreal offset);
141 void updateItem(QQuickItem *, qreal);
142 void snapToCurrent();
143 QPointF pointNear(const QPointF &point, qreal *nearPercent=0) const;
145 QDeclarativePath *path;
147 QDeclarativeGuard<QQuickItem> currentItem;
148 qreal currentItemOffset;
158 bool interactive : 1;
159 bool haveHighlightRange : 1;
160 bool autoHighlight : 1;
161 bool highlightUp : 1;
162 bool layoutScheduled : 1;
165 bool requestedOnPath : 1;
167 QElapsedTimer lastPosTime;
171 QDeclarativeTimeLine tl;
172 QDeclarativeTimeLineValueProxy<QQuickPathViewPrivate> moveOffset;
177 QList<QQuickItem *> items;
178 QList<QQuickItem *> itemCache;
179 QDeclarativeGuard<QQuickVisualModel> model;
180 QVariant modelVariant;
181 enum MovementReason { Other, SetIndex, Mouse };
182 MovementReason moveReason;
183 enum MovementDirection { Shortest, Negative, Positive };
184 MovementDirection moveDirection;
185 QDeclarativeOpenMetaObjectType *attType;
186 QDeclarativeComponent *highlightComponent;
187 QQuickItem *highlightItem;
188 QDeclarativeTimeLineValueProxy<QQuickPathViewPrivate> moveHighlight;
189 qreal highlightPosition;
190 qreal highlightRangeStart;
191 qreal highlightRangeEnd;
192 QQuickPathView::HighlightRangeMode highlightRangeMode;
193 int highlightMoveDuration;