bf0ac855423ecd1230fb1910396c1828ea2a00d0
[profile/ivi/qtdeclarative.git] / src / qtquick1 / graphicsitems / qdeclarativepathview_p_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
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.
17 **
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.
21 **
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.
29 **
30 ** Other Usage
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.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QDECLARATIVEPATHVIEW_P_H
43 #define QDECLARATIVEPATHVIEW_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
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.
52 //
53 // We mean it.
54 //
55
56 #include "private/qdeclarativepathview_p.h"
57
58 #include "QtQuick1/private/qdeclarativeitem_p.h"
59 #include "QtQuick1/private/qdeclarativevisualitemmodel_p.h"
60
61 #include <QtDeclarative/qdeclarative.h>
62 #include <QtQuick1/private/qdeclarativeanimation_p_p.h>
63 #include <QtDeclarative/private/qdeclarativeguard_p.h>
64
65 #include <qdatetime.h>
66
67 QT_BEGIN_NAMESPACE
68
69 class QDeclarative1OpenMetaObjectType;
70 class QDeclarative1PathViewAttached;
71 class QDeclarative1PathViewPrivate : public QDeclarativeItemPrivate, public QDeclarativeItemChangeListener
72 {
73     Q_DECLARE_PUBLIC(QDeclarative1PathView)
74
75 public:
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)
91     {
92     }
93
94     void init();
95
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))
100                 att->m_percent = -1;
101             scheduleLayout();
102         }
103     }
104
105     void scheduleLayout() {
106         Q_Q(QDeclarative1PathView);
107         if (!layoutScheduled) {
108             layoutScheduled = true;
109             QCoreApplication::postEvent(q, new QEvent(QEvent::User), Qt::HighEventPriority);
110         }
111     }
112
113     QDeclarativeItem *getItem(int modelIndex);
114     void releaseItem(QDeclarativeItem *item);
115     QDeclarative1PathViewAttached *attached(QDeclarativeItem *item);
116     void clear();
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;
124     }
125
126     void handleMousePressEvent(QGraphicsSceneMouseEvent *event);
127     void handleMouseMoveEvent(QGraphicsSceneMouseEvent *event);
128     void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *);
129
130     int calcCurrentIndex();
131     void updateCurrent();
132     static void fixOffsetCallback(void*);
133     void fixOffset();
134     void setOffset(qreal offset);
135     void setAdjustedOffset(qreal offset);
136     void regenerate();
137     void updateItem(QDeclarativeItem *, qreal);
138     void snapToCurrent();
139     QPointF pointNear(const QPointF &point, qreal *nearPercent=0) const;
140
141     QDeclarative1Path *path;
142     int currentIndex;
143     QDeclarativeGuard<QDeclarativeItem> currentItem;
144     qreal currentItemOffset;
145     qreal startPc;
146     QPointF startPoint;
147     qreal lastDist;
148     int lastElapsed;
149     qreal offset;
150     qreal offsetAdj;
151     qreal mappedRange;
152     bool stealMouse : 1;
153     bool ownModel : 1;
154     bool interactive : 1;
155     bool haveHighlightRange : 1;
156     bool autoHighlight : 1;
157     bool highlightUp : 1;
158     bool layoutScheduled : 1;
159     bool moving : 1;
160     bool flicking : 1;
161     QElapsedTimer lastPosTime;
162     QPointF lastPos;
163     qreal dragMargin;
164     qreal deceleration;
165     QDeclarative1TimeLine tl;
166     QDeclarative1TimeLineValueProxy<QDeclarative1PathViewPrivate> moveOffset;
167     int firstIndex;
168     int pathItems;
169     int requestedIndex;
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;
187     int modelCount;
188 };
189
190 QT_END_NAMESPACE
191
192 #endif