1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QSGITEMVIEW_P_P_H
43 #define QSGITEMVIEW_P_P_H
45 #include "qsgitemview_p.h"
46 #include "qsgflickable_p_p.h"
47 #include "qsgvisualdatamodel_p.h"
48 #include <private/qdeclarativechangeset_p.h>
55 QT_MODULE(Declarative)
60 FxViewItem(QSGItem *, bool own);
63 // these are positions and sizes along the current direction of scrolling/flicking
64 virtual qreal position() const = 0;
65 virtual qreal endPosition() const = 0;
66 virtual qreal size() const = 0;
67 virtual qreal sectionSize() const = 0;
69 virtual bool contains(qreal x, qreal y) const = 0;
74 QSGItemViewAttached *attached;
77 class QSGItemViewChangeSet
80 QSGItemViewChangeSet();
82 bool hasPendingChanges() const;
83 void prepare(int currentIndex, int count);
86 void applyChanges(const QDeclarativeChangeSet &changeSet);
90 QDeclarativeChangeSet pendingChanges;
91 QHash<QDeclarativeChangeSet::MoveKey, FxViewItem *> removedItems;
94 bool currentChanged : 1;
95 bool currentRemoved : 1;
98 class QSGItemViewPrivate : public QSGFlickablePrivate
100 Q_DECLARE_PUBLIC(QSGItemView)
102 QSGItemViewPrivate();
104 struct InsertionsResult {
105 QList<FxViewItem *> addedItems;
106 QList<FxViewItem *> movedBackwards;
107 qreal sizeAddedBeforeVisible;
109 InsertionsResult() : sizeAddedBeforeVisible(0) {}
112 enum BufferMode { NoBuffer = 0x00, BufferBefore = 0x01, BufferAfter = 0x02 };
113 enum MovementReason { Other, SetIndex, Mouse };
115 bool isValid() const;
116 qreal position() const;
118 qreal startPosition() const;
119 qreal endPosition() const;
120 qreal contentStartPosition() const;
121 int findLastVisibleIndex(int defaultValue = -1) const;
122 FxViewItem *visibleItem(int modelIndex) const;
123 FxViewItem *firstVisibleItem() const;
124 int mapFromModel(int modelIndex) const;
127 virtual void clear();
128 virtual void updateViewport();
133 void refill(qreal from, qreal to, bool doBuffer = false);
136 FxViewItem *createItem(int modelIndex);
137 virtual void releaseItem(FxViewItem *item);
139 QSGItem *createHighlightItem();
140 QSGItem *createComponentItem(QDeclarativeComponent *component, bool receiveItemGeometryChanges, bool createDefault = false);
142 void updateCurrent(int modelIndex);
143 void updateTrackedItem();
144 void updateUnrequestedIndexes();
145 void updateUnrequestedPositions();
146 void updateVisibleIndex();
147 void positionViewAtIndex(int index, int mode);
148 void applyPendingChanges();
149 bool applyModelChanges();
151 void checkVisible() const;
153 void markExtentsDirty() {
154 if (layoutOrientation() == Qt::Vertical)
155 vData.markExtentsDirty();
157 hData.markExtentsDirty();
160 QDeclarativeGuard<QSGVisualModel> model;
161 QVariant modelVariant;
165 Qt::LayoutDirection layoutDirection;
167 MovementReason moveReason;
169 QList<FxViewItem *> visibleItems;
172 FxViewItem *currentItem;
173 FxViewItem *trackedItem;
174 QHash<QSGItem*,int> unrequestedItems;
176 QSGItemViewChangeSet currentChanges;
178 // XXX split into struct
179 QDeclarativeComponent *highlightComponent;
180 FxViewItem *highlight;
181 int highlightRange; // enum value
182 qreal highlightRangeStart;
183 qreal highlightRangeEnd;
184 int highlightMoveDuration;
186 QDeclarativeComponent *headerComponent;
188 QDeclarativeComponent *footerComponent;
191 mutable qreal minExtent;
192 mutable qreal maxExtent;
196 bool lazyRelease : 1;
197 bool deferredRelease : 1;
198 bool inApplyModelChanges : 1;
199 bool inViewportMoved : 1;
200 bool forceLayout : 1;
201 bool currentIndexCleared : 1;
202 bool haveHighlightRange : 1;
203 bool autoHighlight : 1;
204 bool highlightRangeStartValid : 1;
205 bool highlightRangeEndValid : 1;
208 virtual Qt::Orientation layoutOrientation() const = 0;
209 virtual bool isContentFlowReversed() const = 0;
211 virtual qreal positionAt(int index) const = 0;
212 virtual qreal endPositionAt(int index) const = 0;
213 virtual qreal originPosition() const = 0;
214 virtual qreal lastPosition() const = 0;
216 virtual qreal headerSize() const = 0;
217 virtual qreal footerSize() const = 0;
218 virtual bool showHeaderForIndex(int index) const = 0;
219 virtual bool showFooterForIndex(int index) const = 0;
220 virtual void updateHeader() = 0;
221 virtual void updateFooter() = 0;
223 virtual void createHighlight() = 0;
224 virtual void updateHighlight() = 0;
225 virtual void resetHighlightPosition() = 0;
227 virtual void setPosition(qreal pos) = 0;
228 virtual void fixupPosition() = 0;
230 virtual bool addVisibleItems(qreal fillFrom, qreal fillTo, bool doBuffer) = 0;
231 virtual bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo) = 0;
232 virtual void visibleItemsChanged() = 0;
234 virtual FxViewItem *newViewItem(int index, QSGItem *item) = 0;
235 virtual void repositionPackageItemAt(QSGItem *item, int index) = 0;
236 virtual void resetItemPosition(FxViewItem *item, FxViewItem *toItem) = 0;
237 virtual void resetFirstItemPosition() = 0;
238 virtual void moveItemBy(FxViewItem *item, qreal forwards, qreal backwards) = 0;
240 virtual void layoutVisibleItems() = 0;
241 virtual void changedVisibleIndex(int newIndex) = 0;
242 virtual bool applyInsertionChange(const QDeclarativeChangeSet::Insert &, FxViewItem *, InsertionsResult *) = 0;
244 virtual void initializeViewItem(FxViewItem *) {}
245 virtual void initializeCurrentItem() {}
246 virtual void updateSections() {}
248 virtual void itemGeometryChanged(QSGItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
256 #endif // QSGITEMVIEW_P_P_H