Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickitemview_p_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQUICKITEMVIEW_P_P_H
43 #define QQUICKITEMVIEW_P_P_H
44
45 #include "qquickitemview_p.h"
46 #include "qquickflickable_p_p.h"
47 #include "qquickvisualdatamodel_p.h"
48 #include <private/qdeclarativechangeset_p.h>
49
50
51 QT_BEGIN_HEADER
52
53 QT_BEGIN_NAMESPACE
54
55 class FxViewItem
56 {
57 public:
58     FxViewItem(QQuickItem *, bool own);
59     ~FxViewItem();
60
61     // these are positions and sizes along the current direction of scrolling/flicking
62     virtual qreal position() const = 0;
63     virtual qreal endPosition() const = 0;
64     virtual qreal size() const = 0;
65     virtual qreal sectionSize() const = 0;
66
67     virtual bool contains(qreal x, qreal y) const = 0;
68
69     QQuickItem *item;
70     bool ownItem;
71     int index;
72     QQuickItemViewAttached *attached;
73 };
74
75 class QQuickItemViewChangeSet
76 {
77 public:
78     QQuickItemViewChangeSet();
79
80     bool hasPendingChanges() const;
81     void prepare(int currentIndex, int count);
82     void reset();
83
84     void applyChanges(const QDeclarativeChangeSet &changeSet);
85
86     int itemCount;
87     int newCurrentIndex;
88     QDeclarativeChangeSet pendingChanges;
89     QHash<QDeclarativeChangeSet::MoveKey, FxViewItem *> removedItems;
90
91     bool active : 1;
92     bool currentChanged : 1;
93     bool currentRemoved : 1;
94 };
95
96 class QQuickItemViewPrivate : public QQuickFlickablePrivate
97 {
98     Q_DECLARE_PUBLIC(QQuickItemView)
99 public:
100     QQuickItemViewPrivate();
101
102     struct ChangeResult {
103         QDeclarativeNullableValue<qreal> visiblePos;
104         qreal sizeChangesBeforeVisiblePos;
105         qreal sizeChangesAfterVisiblePos;
106         bool changedFirstItem;
107         int changeBeforeVisible;
108
109         ChangeResult(const QDeclarativeNullableValue<qreal> &p)
110             : visiblePos(p), sizeChangesBeforeVisiblePos(0), sizeChangesAfterVisiblePos(0),
111             changedFirstItem(false), changeBeforeVisible(0) {}
112
113         void reset() {
114             sizeChangesBeforeVisiblePos = 0.0;
115             sizeChangesAfterVisiblePos = 0.0;
116             changedFirstItem = false;
117             changeBeforeVisible = 0;
118         }
119     };
120
121     enum BufferMode { NoBuffer = 0x00, BufferBefore = 0x01, BufferAfter = 0x02 };
122     enum MovementReason { Other, SetIndex, Mouse };
123
124     bool isValid() const;
125     qreal position() const;
126     qreal size() const;
127     qreal startPosition() const;
128     qreal endPosition() const;
129     qreal contentStartPosition() const;
130     int findLastVisibleIndex(int defaultValue = -1) const;
131     FxViewItem *visibleItem(int modelIndex) const;
132     FxViewItem *firstVisibleItem() const;
133     int mapFromModel(int modelIndex) const;
134
135     virtual void init();
136     virtual void clear();
137     virtual void updateViewport();
138
139     void regenerate();
140     void layout();
141     void refill();
142     void refill(qreal from, qreal to);
143     void mirrorChange();
144
145     FxViewItem *createItem(int modelIndex, bool asynchronous = false);
146     virtual void releaseItem(FxViewItem *item);
147
148     QQuickItem *createHighlightItem();
149     QQuickItem *createComponentItem(QDeclarativeComponent *component, bool receiveItemGeometryChanges, bool createDefault = false);
150
151     void updateCurrent(int modelIndex);
152     void updateTrackedItem();
153     void updateUnrequestedIndexes();
154     void updateUnrequestedPositions();
155     void updateVisibleIndex();
156     void positionViewAtIndex(int index, int mode);
157     void applyPendingChanges();
158     bool applyModelChanges();
159     bool applyRemovalChange(const QDeclarativeChangeSet::Remove &removal, ChangeResult *changeResult, int *removedCount);
160     void repositionFirstItem(FxViewItem *prevVisibleItemsFirst, qreal prevVisibleItemsFirstPos,
161             FxViewItem *prevFirstVisible, ChangeResult *insertionResult, ChangeResult *removalResult);
162
163     void checkVisible() const;
164
165     void markExtentsDirty() {
166         if (layoutOrientation() == Qt::Vertical)
167             vData.markExtentsDirty();
168         else
169             hData.markExtentsDirty();
170     }
171
172     QDeclarativeGuard<QQuickVisualModel> model;
173     QVariant modelVariant;
174     int itemCount;
175     int buffer;
176     int bufferMode;
177     Qt::LayoutDirection layoutDirection;
178
179     MovementReason moveReason;
180
181     QList<FxViewItem *> visibleItems;
182     int visibleIndex;
183     int currentIndex;
184     FxViewItem *currentItem;
185     FxViewItem *trackedItem;
186     QHash<QQuickItem*,int> unrequestedItems;
187     int requestedIndex;
188     FxViewItem *requestedItem;
189     QQuickItemViewChangeSet currentChanges;
190
191     // XXX split into struct
192     QDeclarativeComponent *highlightComponent;
193     FxViewItem *highlight;
194     int highlightRange;     // enum value
195     qreal highlightRangeStart;
196     qreal highlightRangeEnd;
197     int highlightMoveDuration;
198
199     QDeclarativeComponent *headerComponent;
200     FxViewItem *header;
201     QDeclarativeComponent *footerComponent;
202     FxViewItem *footer;
203
204     mutable qreal minExtent;
205     mutable qreal maxExtent;
206
207     bool ownModel : 1;
208     bool wrap : 1;
209     bool inApplyModelChanges : 1;
210     bool inViewportMoved : 1;
211     bool forceLayout : 1;
212     bool currentIndexCleared : 1;
213     bool haveHighlightRange : 1;
214     bool autoHighlight : 1;
215     bool highlightRangeStartValid : 1;
216     bool highlightRangeEndValid : 1;
217     bool fillCacheBuffer : 1;
218     bool inRequest : 1;
219     bool requestedAsync : 1;
220
221 protected:
222     virtual Qt::Orientation layoutOrientation() const = 0;
223     virtual bool isContentFlowReversed() const = 0;
224
225     virtual qreal positionAt(int index) const = 0;
226     virtual qreal endPositionAt(int index) const = 0;
227     virtual qreal originPosition() const = 0;
228     virtual qreal lastPosition() const = 0;
229
230     virtual qreal headerSize() const = 0;
231     virtual qreal footerSize() const = 0;
232     virtual bool showHeaderForIndex(int index) const = 0;
233     virtual bool showFooterForIndex(int index) const = 0;
234     virtual void updateHeader() = 0;
235     virtual void updateFooter() = 0;
236
237     virtual void createHighlight() = 0;
238     virtual void updateHighlight() = 0;
239     virtual void resetHighlightPosition() = 0;
240
241     virtual void setPosition(qreal pos) = 0;
242     virtual void fixupPosition() = 0;
243
244     virtual bool addVisibleItems(qreal fillFrom, qreal fillTo, bool doBuffer) = 0;
245     virtual bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo) = 0;
246     virtual void visibleItemsChanged() = 0;
247
248     virtual FxViewItem *newViewItem(int index, QQuickItem *item) = 0;
249     virtual void repositionPackageItemAt(QQuickItem *item, int index) = 0;
250     virtual void resetFirstItemPosition(qreal pos = 0.0) = 0;
251     virtual void adjustFirstItem(qreal forwards, qreal backwards, int changeBeforeVisible) = 0;
252
253     virtual void layoutVisibleItems(int fromModelIndex = 0) = 0;
254     virtual void changedVisibleIndex(int newIndex) = 0;
255     virtual bool applyInsertionChange(const QDeclarativeChangeSet::Insert &insert, ChangeResult *changeResult, QList<FxViewItem *> *newItems) = 0;
256
257     virtual bool needsRefillForAddedOrRemovedIndex(int) const { return false; }
258
259     virtual void initializeViewItem(FxViewItem *) {}
260     virtual void initializeCurrentItem() {}
261     virtual void updateSections() {}
262
263     virtual void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
264 };
265
266
267 QT_END_NAMESPACE
268
269 QT_END_HEADER
270
271 #endif // QQUICKITEMVIEW_P_P_H