Initial import from qtquick2.
[profile/ivi/qtdeclarative.git] / src / declarative / items / qsgpathview_p_p.h
1 // Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350
2 /****************************************************************************
3 **
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 **
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 **
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
15 ** this package.
16 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QDECLARATIVEPATHVIEW_P_H
44 #define QDECLARATIVEPATHVIEW_P_H
45
46 //
47 //  W A R N I N G
48 //  -------------
49 //
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.
53 //
54 // We mean it.
55 //
56
57 #include "qsgpathview_p.h"
58 #include "qsgitem_p.h"
59 #include "qsgvisualitemmodel_p.h"
60
61 #include <QtDeclarative/qdeclarative.h>
62 #include <QtCore/qdatetime.h>
63 #include <QtCore/qcoreapplication.h>
64
65 #include <private/qdeclarativeanimation_p_p.h>
66 #include <private/qdeclarativeguard_p.h>
67
68 QT_BEGIN_NAMESPACE
69
70 class QDeclarativeOpenMetaObjectType;
71 class QSGPathViewAttached;
72 class QSGPathViewPrivate : public QSGItemPrivate, public QSGItemChangeListener
73 {
74     Q_DECLARE_PUBLIC(QSGPathView)
75
76 public:
77     QSGPathViewPrivate()
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)
92     {
93     }
94
95     void init();
96
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))
101                 att->m_percent = -1;
102             scheduleLayout();
103         }
104     }
105
106     void scheduleLayout() {
107         Q_Q(QSGPathView);
108         if (!layoutScheduled) {
109             layoutScheduled = true;
110             q->polish();
111         }
112     }
113
114     QSGItem *getItem(int modelIndex);
115     void releaseItem(QSGItem *item);
116     QSGPathViewAttached *attached(QSGItem *item);
117     void clear();
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;
125     }
126
127     void handleMousePressEvent(QGraphicsSceneMouseEvent *event);
128     void handleMouseMoveEvent(QGraphicsSceneMouseEvent *event);
129     void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *);
130
131     int calcCurrentIndex();
132     void updateCurrent();
133     static void fixOffsetCallback(void*);
134     void fixOffset();
135     void setOffset(qreal offset);
136     void setAdjustedOffset(qreal offset);
137     void regenerate();
138     void updateItem(QSGItem *, qreal);
139     void snapToCurrent();
140     QPointF pointNear(const QPointF &point, qreal *nearPercent=0) const;
141
142     QDeclarativePath *path;
143     int currentIndex;
144     QDeclarativeGuard<QSGItem> currentItem;
145     qreal currentItemOffset;
146     qreal startPc;
147     QPointF startPoint;
148     qreal lastDist;
149     int lastElapsed;
150     qreal offset;
151     qreal offsetAdj;
152     qreal mappedRange;
153     bool stealMouse : 1;
154     bool ownModel : 1;
155     bool interactive : 1;
156     bool haveHighlightRange : 1;
157     bool autoHighlight : 1;
158     bool highlightUp : 1;
159     bool layoutScheduled : 1;
160     bool moving : 1;
161     bool flicking : 1;
162     QElapsedTimer lastPosTime;
163     QPointF lastPos;
164     qreal dragMargin;
165     qreal deceleration;
166     QDeclarativeTimeLine tl;
167     QDeclarativeTimeLineValueProxy<QSGPathViewPrivate> moveOffset;
168     int firstIndex;
169     int pathItems;
170     int requestedIndex;
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;
188     int modelCount;
189 };
190
191 QT_END_NAMESPACE
192
193 #endif