Make lastPosition() result consistent among GridView and ListView
[profile/ivi/qtdeclarative.git] / src / declarative / items / qsgitemview_p_p.h
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 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
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 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QSGITEMVIEW_P_P_H
43 #define QSGITEMVIEW_P_P_H
44
45 #include "qsgitemview_p.h"
46 #include "qsgflickable_p_p.h"
47 #include "qsgvisualitemmodel_p.h"
48
49
50 QT_BEGIN_HEADER
51
52 QT_BEGIN_NAMESPACE
53
54 QT_MODULE(Declarative)
55
56 class FxViewItem
57 {
58 public:
59     FxViewItem(QSGItem *, bool own);
60     ~FxViewItem();
61
62     // these are positions and sizes along the current direction of scrolling/flicking
63     virtual qreal position() const = 0;
64     virtual qreal endPosition() const = 0;
65     virtual qreal size() const = 0;
66     virtual qreal sectionSize() const = 0;
67
68     virtual bool contains(qreal x, qreal y) const = 0;
69
70     QSGItem *item;
71     bool ownItem;
72     int index;
73     QSGItemViewAttached *attached;
74 };
75
76 class QSGItemViewPrivate : public QSGFlickablePrivate
77 {
78     Q_DECLARE_PUBLIC(QSGItemView)
79 public:
80     QSGItemViewPrivate();
81
82     enum BufferMode { NoBuffer = 0x00, BufferBefore = 0x01, BufferAfter = 0x02 };
83     enum MovementReason { Other, SetIndex, Mouse };
84
85     bool isValid() const;
86     qreal position() const;
87     qreal size() const;
88     qreal startPosition() const;
89     qreal endPosition() const;
90     int findLastVisibleIndex(int defaultValue = -1) const;
91     FxViewItem *visibleItem(int modelIndex) const;
92     FxViewItem *firstVisibleItem() const;
93     int mapFromModel(int modelIndex) const;
94
95     virtual void init();
96     virtual void updateCurrent(int modelIndex);
97     virtual void clear();
98     virtual void regenerate();
99     virtual void updateViewport();
100     void layout();
101     void refill();
102     void refill(qreal from, qreal to, bool doBuffer = false);
103     void scheduleLayout();
104     void mirrorChange();
105
106     FxViewItem *createItem(int modelIndex);
107     virtual void releaseItem(FxViewItem *item);
108
109     QSGItem *createHighlightItem();
110     QSGItem *createComponentItem(QDeclarativeComponent *component, bool receiveItemGeometryChanges, bool createDefault = false);
111
112     void updateTrackedItem();
113     void updateUnrequestedIndexes();
114     void updateUnrequestedPositions();
115     void positionViewAtIndex(int index, int mode);
116
117     void checkVisible() const;
118
119     QDeclarativeGuard<QSGVisualModel> model;
120     QVariant modelVariant;
121     int itemCount;
122     int buffer;
123     int bufferMode;
124     Qt::LayoutDirection layoutDirection;
125
126     MovementReason moveReason;
127
128     QList<FxViewItem *> visibleItems;
129     int visibleIndex;
130     int currentIndex;
131     FxViewItem *currentItem;
132     FxViewItem *trackedItem;
133     QHash<QSGItem*,int> unrequestedItems;
134     int requestedIndex;
135
136     // XXX split into struct
137     QDeclarativeComponent *highlightComponent;
138     FxViewItem *highlight;
139     int highlightRange;     // enum value
140     qreal highlightRangeStart;
141     qreal highlightRangeEnd;
142     int highlightMoveDuration;
143
144     QDeclarativeComponent *headerComponent;
145     FxViewItem *header;
146     QDeclarativeComponent *footerComponent;
147     FxViewItem *footer;
148
149     mutable qreal minExtent;
150     mutable qreal maxExtent;
151
152     bool ownModel : 1;
153     bool wrap : 1;
154     bool lazyRelease : 1;
155     bool deferredRelease : 1;
156     bool layoutScheduled : 1;
157     bool inViewportMoved : 1;
158     bool currentIndexCleared : 1;
159     bool haveHighlightRange : 1;
160     bool autoHighlight : 1;
161     bool highlightRangeStartValid : 1;
162     bool highlightRangeEndValid : 1;
163     mutable bool minExtentDirty : 1;
164     mutable bool maxExtentDirty : 1;
165
166 protected:
167     virtual Qt::Orientation layoutOrientation() const = 0;
168     virtual bool isContentFlowReversed() const = 0;
169
170     virtual qreal positionAt(int index) const = 0;
171     virtual qreal endPositionAt(int index) const = 0;
172     virtual qreal originPosition() const = 0;
173     virtual qreal lastPosition() const = 0;
174
175     virtual qreal headerSize() const = 0;
176     virtual qreal footerSize() const = 0;
177     virtual void updateHeader() = 0;
178     virtual void updateFooter() = 0;
179
180     virtual void createHighlight() = 0;
181     virtual void updateHighlight() = 0;
182     virtual void resetHighlightPosition() = 0;
183
184     virtual void setPosition(qreal pos) = 0;
185     virtual void fixupPosition() = 0;
186
187     virtual bool addVisibleItems(int fillFrom, int fillTo, bool doBuffer) = 0;
188     virtual bool removeNonVisibleItems(int bufferFrom, int bufferTo) = 0;
189     virtual void visibleItemsChanged() = 0;
190
191     virtual FxViewItem *newViewItem(int index, QSGItem *item) = 0;
192     virtual void initializeViewItem(FxViewItem *) {}
193     virtual void repositionPackageItemAt(QSGItem *item, int index) = 0;
194
195     virtual void layoutVisibleItems() = 0;
196
197     virtual void updateSections() {}
198     virtual void changedVisibleIndex(int newIndex) = 0;
199     virtual void initializeCurrentItem() {}
200
201     virtual void itemGeometryChanged(QSGItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
202 };
203
204
205 QT_END_NAMESPACE
206
207 QT_END_HEADER
208
209 #endif // QSGITEMVIEW_P_P_H