1 // Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350
2 /****************************************************************************
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** No Commercial Usage
12 ** This file contains pre-release code and may not be distributed.
13 ** You may use this file in accordance with the terms and conditions
14 ** contained in the Technology Preview License Agreement accompanying
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
41 ****************************************************************************/
43 #ifndef QDECLARATIVEPATHVIEW_P_H
44 #define QDECLARATIVEPATHVIEW_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 "qsgpathview_p.h"
58 #include "qsgitem_p.h"
59 #include "qsgvisualitemmodel_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>
70 class QDeclarativeOpenMetaObjectType;
71 class QSGPathViewAttached;
72 class QSGPathViewPrivate : public QSGItemPrivate, public QSGItemChangeListener
74 Q_DECLARE_PUBLIC(QSGPathView)
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)
83 , dragMargin(0), deceleration(100)
84 , moveOffset(this, &QSGPathViewPrivate::setAdjustedOffset)
85 , firstIndex(-1), pathItems(-1), requestedIndex(-1)
86 , moveReason(Other), moveDirection(Shortest), attType(0), highlightComponent(0), highlightItem(0)
87 , moveHighlight(this, &QSGPathViewPrivate::setHighlightPosition)
88 , highlightPosition(0)
89 , highlightRangeStart(0), highlightRangeEnd(0)
90 , highlightRangeMode(QSGPathView::StrictlyEnforceRange)
91 , highlightMoveDuration(300), modelCount(0)
97 void itemGeometryChanged(QSGItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) {
98 if ((newGeometry.size() != oldGeometry.size())
99 && (!highlightItem || item != highlightItem)) {
100 if (QSGPathViewAttached *att = attached(item))
106 void scheduleLayout() {
108 if (!layoutScheduled) {
109 layoutScheduled = true;
114 QSGItem *getItem(int modelIndex);
115 void releaseItem(QSGItem *item);
116 QSGPathViewAttached *attached(QSGItem *item);
118 void updateMappedRange();
119 qreal positionOfIndex(qreal index) const;
120 void createHighlight();
121 void updateHighlight();
122 void setHighlightPosition(qreal pos);
123 bool isValid() const {
124 return model && model->count() > 0 && model->isValid() && path;
127 void handleMousePressEvent(QGraphicsSceneMouseEvent *event);
128 void handleMouseMoveEvent(QGraphicsSceneMouseEvent *event);
129 void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *);
131 int calcCurrentIndex();
132 void updateCurrent();
133 static void fixOffsetCallback(void*);
135 void setOffset(qreal offset);
136 void setAdjustedOffset(qreal offset);
138 void updateItem(QSGItem *, qreal);
139 void snapToCurrent();
140 QPointF pointNear(const QPointF &point, qreal *nearPercent=0) const;
142 QDeclarativePath *path;
144 QDeclarativeGuard<QSGItem> currentItem;
145 qreal currentItemOffset;
155 bool interactive : 1;
156 bool haveHighlightRange : 1;
157 bool autoHighlight : 1;
158 bool highlightUp : 1;
159 bool layoutScheduled : 1;
162 QElapsedTimer lastPosTime;
166 QDeclarativeTimeLine tl;
167 QDeclarativeTimeLineValueProxy<QSGPathViewPrivate> moveOffset;
171 QList<QSGItem *> items;
172 QList<QSGItem *> itemCache;
173 QDeclarativeGuard<QSGVisualModel> model;
174 QVariant modelVariant;
175 enum MovementReason { Other, SetIndex, Mouse };
176 MovementReason moveReason;
177 enum MovementDirection { Shortest, Negative, Positive };
178 MovementDirection moveDirection;
179 QDeclarativeOpenMetaObjectType *attType;
180 QDeclarativeComponent *highlightComponent;
181 QSGItem *highlightItem;
182 QDeclarativeTimeLineValueProxy<QSGPathViewPrivate> moveHighlight;
183 qreal highlightPosition;
184 qreal highlightRangeStart;
185 qreal highlightRangeEnd;
186 QSGPathView::HighlightRangeMode highlightRangeMode;
187 int highlightMoveDuration;