9caea984991237fe21c2ad060077b8adf40c0f1b
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickpathview_p_p.h
1 // Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350
2 /****************************************************************************
3 **
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: http://www.qt-project.org/
7 **
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 **
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.
18 **
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.
22 **
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.
30 **
31 ** Other Usage
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.
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QQUICKPATHVIEW_P_P_H
44 #define QQUICKPATHVIEW_P_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 "qquickpathview_p.h"
58 #include "qquickitem_p.h"
59 #include "qquickvisualdatamodel_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 #include <private/qdeclarativetimeline_p_p.h>
68
69 QT_BEGIN_NAMESPACE
70
71 class QDeclarativeOpenMetaObjectType;
72 class QQuickPathViewAttached;
73 class QQuickPathViewPrivate : public QQuickItemPrivate, public QQuickItemChangeListener
74 {
75     Q_DECLARE_PUBLIC(QQuickPathView)
76
77 public:
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)
93     {
94     }
95
96     void init();
97
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))
102                 att->m_percent = -1;
103             scheduleLayout();
104         }
105     }
106
107     void scheduleLayout() {
108         Q_Q(QQuickPathView);
109         if (!layoutScheduled) {
110             layoutScheduled = true;
111             q->polish();
112         }
113     }
114
115     QQuickItem *getItem(int modelIndex, qreal z = 0, bool onPath=true);
116     void releaseItem(QQuickItem *item);
117     QQuickPathViewAttached *attached(QQuickItem *item);
118     QDeclarativeOpenMetaObjectType *attachedType();
119     void clear();
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;
127     }
128
129     void handleMousePressEvent(QMouseEvent *event);
130     void handleMouseMoveEvent(QMouseEvent *event);
131     void handleMouseReleaseEvent(QMouseEvent *);
132
133     int calcCurrentIndex();
134     void createCurrentItem();
135     void updateCurrent();
136     static void fixOffsetCallback(void*);
137     void fixOffset();
138     void setOffset(qreal offset);
139     void setAdjustedOffset(qreal offset);
140     void regenerate();
141     void updateItem(QQuickItem *, qreal);
142     void snapToCurrent();
143     QPointF pointNear(const QPointF &point, qreal *nearPercent=0) const;
144
145     QDeclarativePath *path;
146     int currentIndex;
147     QDeclarativeGuard<QQuickItem> currentItem;
148     qreal currentItemOffset;
149     qreal startPc;
150     QPointF startPoint;
151     qreal lastDist;
152     int lastElapsed;
153     qreal offset;
154     qreal offsetAdj;
155     qreal mappedRange;
156     bool stealMouse : 1;
157     bool ownModel : 1;
158     bool interactive : 1;
159     bool haveHighlightRange : 1;
160     bool autoHighlight : 1;
161     bool highlightUp : 1;
162     bool layoutScheduled : 1;
163     bool moving : 1;
164     bool flicking : 1;
165     bool requestedOnPath : 1;
166     bool inRequest : 1;
167     QElapsedTimer lastPosTime;
168     QPointF lastPos;
169     qreal dragMargin;
170     qreal deceleration;
171     QDeclarativeTimeLine tl;
172     QDeclarativeTimeLineValueProxy<QQuickPathViewPrivate> moveOffset;
173     int firstIndex;
174     int pathItems;
175     int requestedIndex;
176     qreal requestedZ;
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;
194     int modelCount;
195 };
196
197 QT_END_NAMESPACE
198
199 #endif