1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
6 | **
|
---|
7 | ** This file is part of the QtDeclarative module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at qt-info@nokia.com.
|
---|
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 "private/qdeclarativeitem_p.h"
|
---|
59 | #include "private/qdeclarativevisualitemmodel_p.h"
|
---|
60 |
|
---|
61 | #include <qdeclarative.h>
|
---|
62 | #include <qdeclarativeanimation_p_p.h>
|
---|
63 | #include <qdeclarativeguard_p.h>
|
---|
64 |
|
---|
65 | #include <qdatetime.h>
|
---|
66 |
|
---|
67 | QT_BEGIN_NAMESPACE
|
---|
68 |
|
---|
69 | class QDeclarativeOpenMetaObjectType;
|
---|
70 | class QDeclarativePathViewAttached;
|
---|
71 | class QDeclarativePathViewPrivate : public QDeclarativeItemPrivate, public QDeclarativeItemChangeListener
|
---|
72 | {
|
---|
73 | Q_DECLARE_PUBLIC(QDeclarativePathView)
|
---|
74 |
|
---|
75 | public:
|
---|
76 | QDeclarativePathViewPrivate()
|
---|
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, &QDeclarativePathViewPrivate::setAdjustedOffset)
|
---|
84 | , firstIndex(-1), pathItems(-1), requestedIndex(-1)
|
---|
85 | , moveReason(Other), moveDirection(Shortest), attType(0), highlightComponent(0), highlightItem(0)
|
---|
86 | , moveHighlight(this, &QDeclarativePathViewPrivate::setHighlightPosition)
|
---|
87 | , highlightPosition(0)
|
---|
88 | , highlightRangeStart(0), highlightRangeEnd(0)
|
---|
89 | , highlightRangeMode(QDeclarativePathView::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 (QDeclarativePathViewAttached *att = attached(item))
|
---|
100 | att->m_percent = -1;
|
---|
101 | scheduleLayout();
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | void scheduleLayout() {
|
---|
106 | Q_Q(QDeclarativePathView);
|
---|
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 | QDeclarativePathViewAttached *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 | QDeclarativePath *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 | QDeclarativeTimeLine tl;
|
---|
166 | QDeclarativeTimeLineValueProxy<QDeclarativePathViewPrivate> moveOffset;
|
---|
167 | int firstIndex;
|
---|
168 | int pathItems;
|
---|
169 | int requestedIndex;
|
---|
170 | QList<QDeclarativeItem *> items;
|
---|
171 | QList<QDeclarativeItem *> itemCache;
|
---|
172 | QDeclarativeGuard<QDeclarativeVisualModel> model;
|
---|
173 | QVariant modelVariant;
|
---|
174 | enum MovementReason { Other, SetIndex, Mouse };
|
---|
175 | MovementReason moveReason;
|
---|
176 | enum MovementDirection { Shortest, Negative, Positive };
|
---|
177 | MovementDirection moveDirection;
|
---|
178 | QDeclarativeOpenMetaObjectType *attType;
|
---|
179 | QDeclarativeComponent *highlightComponent;
|
---|
180 | QDeclarativeItem *highlightItem;
|
---|
181 | QDeclarativeTimeLineValueProxy<QDeclarativePathViewPrivate> moveHighlight;
|
---|
182 | qreal highlightPosition;
|
---|
183 | qreal highlightRangeStart;
|
---|
184 | qreal highlightRangeEnd;
|
---|
185 | QDeclarativePathView::HighlightRangeMode highlightRangeMode;
|
---|
186 | int highlightMoveDuration;
|
---|
187 | int modelCount;
|
---|
188 | };
|
---|
189 |
|
---|
190 | QT_END_NAMESPACE
|
---|
191 |
|
---|
192 | #endif
|
---|