1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QDECLARATIVEPATHVIEW_P_H
43 #define QDECLARATIVEPATHVIEW_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 "private/qdeclarativepathview_p.h"
58 #include "QtQuick1/private/qdeclarativeitem_p.h"
59 #include "QtQuick1/private/qdeclarativevisualitemmodel_p.h"
61 #include <QtDeclarative/qdeclarative.h>
62 #include <QtQuick1/private/qdeclarativeanimation_p_p.h>
63 #include <QtDeclarative/private/qdeclarativeguard_p.h>
65 #include <qdatetime.h>
69 class QDeclarative1OpenMetaObjectType;
70 class QDeclarative1PathViewAttached;
71 class QDeclarative1PathViewPrivate : public QDeclarativeItemPrivate, public QDeclarativeItemChangeListener
73 Q_DECLARE_PUBLIC(QDeclarative1PathView)
76 QDeclarative1PathViewPrivate()
77 : path(0), currentIndex(0), currentItemOffset(0.0), startPc(0), lastDist(0)
78 , lastElapsed(0), offset(0.0), offsetAdj(0.0), mappedRange(1.0)
79 , stealMouse(false), ownModel(false), interactive(true), haveHighlightRange(true)
80 , autoHighlight(true), highlightUp(false), layoutScheduled(false)
81 , moving(false), flicking(false)
82 , dragMargin(0), deceleration(100)
83 , moveOffset(this, &QDeclarative1PathViewPrivate::setAdjustedOffset)
84 , firstIndex(-1), pathItems(-1), requestedIndex(-1)
85 , moveReason(Other), moveDirection(Shortest), attType(0), highlightComponent(0), highlightItem(0)
86 , moveHighlight(this, &QDeclarative1PathViewPrivate::setHighlightPosition)
87 , highlightPosition(0)
88 , highlightRangeStart(0), highlightRangeEnd(0)
89 , highlightRangeMode(QDeclarative1PathView::StrictlyEnforceRange)
90 , highlightMoveDuration(300), modelCount(0)
96 void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) {
97 if ((newGeometry.size() != oldGeometry.size())
98 && (!highlightItem || item != highlightItem)) {
99 if (QDeclarative1PathViewAttached *att = attached(item))
105 void scheduleLayout() {
106 Q_Q(QDeclarative1PathView);
107 if (!layoutScheduled) {
108 layoutScheduled = true;
109 QCoreApplication::postEvent(q, new QEvent(QEvent::User), Qt::HighEventPriority);
113 QDeclarativeItem *getItem(int modelIndex);
114 void releaseItem(QDeclarativeItem *item);
115 QDeclarative1PathViewAttached *attached(QDeclarativeItem *item);
117 void updateMappedRange();
118 qreal positionOfIndex(qreal index) const;
119 void createHighlight();
120 void updateHighlight();
121 void setHighlightPosition(qreal pos);
122 bool isValid() const {
123 return model && model->count() > 0 && model->isValid() && path;
126 void handleMousePressEvent(QGraphicsSceneMouseEvent *event);
127 void handleMouseMoveEvent(QGraphicsSceneMouseEvent *event);
128 void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *);
130 int calcCurrentIndex();
131 void updateCurrent();
132 static void fixOffsetCallback(void*);
134 void setOffset(qreal offset);
135 void setAdjustedOffset(qreal offset);
137 void updateItem(QDeclarativeItem *, qreal);
138 void snapToCurrent();
139 QPointF pointNear(const QPointF &point, qreal *nearPercent=0) const;
141 QDeclarative1Path *path;
143 QDeclarativeGuard<QDeclarativeItem> currentItem;
144 qreal currentItemOffset;
154 bool interactive : 1;
155 bool haveHighlightRange : 1;
156 bool autoHighlight : 1;
157 bool highlightUp : 1;
158 bool layoutScheduled : 1;
161 QElapsedTimer lastPosTime;
165 QDeclarative1TimeLine tl;
166 QDeclarative1TimeLineValueProxy<QDeclarative1PathViewPrivate> moveOffset;
170 QList<QDeclarativeItem *> items;
171 QList<QDeclarativeItem *> itemCache;
172 QDeclarativeGuard<QDeclarative1VisualModel> model;
173 QVariant modelVariant;
174 enum MovementReason { Other, SetIndex, Mouse };
175 MovementReason moveReason;
176 enum MovementDirection { Shortest, Negative, Positive };
177 MovementDirection moveDirection;
178 QDeclarative1OpenMetaObjectType *attType;
179 QDeclarativeComponent *highlightComponent;
180 QDeclarativeItem *highlightItem;
181 QDeclarative1TimeLineValueProxy<QDeclarative1PathViewPrivate> moveHighlight;
182 qreal highlightPosition;
183 qreal highlightRangeStart;
184 qreal highlightRangeEnd;
185 QDeclarative1PathView::HighlightRangeMode highlightRangeMode;
186 int highlightMoveDuration;