Show header/footer if current index is set to first/last item or row
[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 ** 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 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     qreal contentStartPosition() const;
91     int findLastVisibleIndex(int defaultValue = -1) const;
92     FxViewItem *visibleItem(int modelIndex) const;
93     FxViewItem *firstVisibleItem() const;
94     int mapFromModel(int modelIndex) const;
95     void adjustMoveParameters(int *from, int *to, int *count) const;
96
97     virtual void init();
98     virtual void clear();
99     virtual void updateViewport();
100
101     void regenerate();
102     void layout();
103     void refill();
104     void refill(qreal from, qreal to, bool doBuffer = false);
105     void scheduleLayout();
106     void mirrorChange();
107
108     FxViewItem *createItem(int modelIndex);
109     virtual void releaseItem(FxViewItem *item);
110
111     QSGItem *createHighlightItem();
112     QSGItem *createComponentItem(QDeclarativeComponent *component, bool receiveItemGeometryChanges, bool createDefault = false);
113
114     void updateCurrent(int modelIndex);
115     void updateTrackedItem();
116     void updateUnrequestedIndexes();
117     void updateUnrequestedPositions();
118     void positionViewAtIndex(int index, int mode);
119
120     void checkVisible() const;
121
122     QDeclarativeGuard<QSGVisualModel> model;
123     QVariant modelVariant;
124     int itemCount;
125     int buffer;
126     int bufferMode;
127     Qt::LayoutDirection layoutDirection;
128
129     MovementReason moveReason;
130
131     QList<FxViewItem *> visibleItems;
132     int visibleIndex;
133     int currentIndex;
134     FxViewItem *currentItem;
135     FxViewItem *trackedItem;
136     QHash<QSGItem*,int> unrequestedItems;
137     int requestedIndex;
138
139     // XXX split into struct
140     QDeclarativeComponent *highlightComponent;
141     FxViewItem *highlight;
142     int highlightRange;     // enum value
143     qreal highlightRangeStart;
144     qreal highlightRangeEnd;
145     int highlightMoveDuration;
146
147     QDeclarativeComponent *headerComponent;
148     FxViewItem *header;
149     QDeclarativeComponent *footerComponent;
150     FxViewItem *footer;
151
152     mutable qreal minExtent;
153     mutable qreal maxExtent;
154
155     bool ownModel : 1;
156     bool wrap : 1;
157     bool lazyRelease : 1;
158     bool deferredRelease : 1;
159     bool layoutScheduled : 1;
160     bool inViewportMoved : 1;
161     bool currentIndexCleared : 1;
162     bool haveHighlightRange : 1;
163     bool autoHighlight : 1;
164     bool highlightRangeStartValid : 1;
165     bool highlightRangeEndValid : 1;
166     mutable bool minExtentDirty : 1;
167     mutable bool maxExtentDirty : 1;
168
169 protected:
170     virtual Qt::Orientation layoutOrientation() const = 0;
171     virtual bool isContentFlowReversed() const = 0;
172
173     virtual qreal positionAt(int index) const = 0;
174     virtual qreal endPositionAt(int index) const = 0;
175     virtual qreal originPosition() const = 0;
176     virtual qreal lastPosition() const = 0;
177
178     virtual qreal headerSize() const = 0;
179     virtual qreal footerSize() const = 0;
180     virtual bool showHeaderForIndex(int index) const = 0;
181     virtual bool showFooterForIndex(int index) const = 0;
182     virtual void updateHeader() = 0;
183     virtual void updateFooter() = 0;
184
185     virtual void createHighlight() = 0;
186     virtual void updateHighlight() = 0;
187     virtual void resetHighlightPosition() = 0;
188
189     virtual void setPosition(qreal pos) = 0;
190     virtual void fixupPosition() = 0;
191
192     virtual bool addVisibleItems(int fillFrom, int fillTo, bool doBuffer) = 0;
193     virtual bool removeNonVisibleItems(int bufferFrom, int bufferTo) = 0;
194     virtual void visibleItemsChanged() = 0;
195
196     virtual FxViewItem *newViewItem(int index, QSGItem *item) = 0;
197     virtual void repositionPackageItemAt(QSGItem *item, int index) = 0;
198
199     virtual void layoutVisibleItems() = 0;
200     virtual void changedVisibleIndex(int newIndex) = 0;
201
202     virtual void initializeViewItem(FxViewItem *) {}
203     virtual void initializeCurrentItem() {}
204     virtual void updateSections() {}
205
206     virtual void itemGeometryChanged(QSGItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
207 };
208
209
210 QT_END_NAMESPACE
211
212 QT_END_HEADER
213
214 #endif // QSGITEMVIEW_P_P_H