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 "qsgvisualitemmodel_p.h"
54 QT_MODULE(Declarative)
59 FxViewItem(QSGItem *, bool own);
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;
68 virtual bool contains(qreal x, qreal y) const = 0;
73 QSGItemViewAttached *attached;
76 class QSGItemViewPrivate : public QSGFlickablePrivate
78 Q_DECLARE_PUBLIC(QSGItemView)
82 enum BufferMode { NoBuffer = 0x00, BufferBefore = 0x01, BufferAfter = 0x02 };
83 enum MovementReason { Other, SetIndex, Mouse };
86 qreal position() 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;
99 virtual void updateViewport();
104 void refill(qreal from, qreal to, bool doBuffer = false);
105 void scheduleLayout();
108 FxViewItem *createItem(int modelIndex);
109 virtual void releaseItem(FxViewItem *item);
111 QSGItem *createHighlightItem();
112 QSGItem *createComponentItem(QDeclarativeComponent *component, bool receiveItemGeometryChanges, bool createDefault = false);
114 void updateCurrent(int modelIndex);
115 void updateTrackedItem();
116 void updateUnrequestedIndexes();
117 void updateUnrequestedPositions();
118 void positionViewAtIndex(int index, int mode);
120 void checkVisible() const;
122 QDeclarativeGuard<QSGVisualModel> model;
123 QVariant modelVariant;
127 Qt::LayoutDirection layoutDirection;
129 MovementReason moveReason;
131 QList<FxViewItem *> visibleItems;
134 FxViewItem *currentItem;
135 FxViewItem *trackedItem;
136 QHash<QSGItem*,int> unrequestedItems;
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;
147 QDeclarativeComponent *headerComponent;
149 QDeclarativeComponent *footerComponent;
152 mutable qreal minExtent;
153 mutable qreal maxExtent;
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;
170 virtual Qt::Orientation layoutOrientation() const = 0;
171 virtual bool isContentFlowReversed() const = 0;
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;
178 virtual qreal headerSize() const = 0;
179 virtual qreal footerSize() const = 0;
180 virtual void updateHeader() = 0;
181 virtual void updateFooter() = 0;
183 virtual void createHighlight() = 0;
184 virtual void updateHighlight() = 0;
185 virtual void resetHighlightPosition() = 0;
187 virtual void setPosition(qreal pos) = 0;
188 virtual void fixupPosition() = 0;
190 virtual bool addVisibleItems(int fillFrom, int fillTo, bool doBuffer) = 0;
191 virtual bool removeNonVisibleItems(int bufferFrom, int bufferTo) = 0;
192 virtual void visibleItemsChanged() = 0;
194 virtual FxViewItem *newViewItem(int index, QSGItem *item) = 0;
195 virtual void repositionPackageItemAt(QSGItem *item, int index) = 0;
197 virtual void layoutVisibleItems() = 0;
198 virtual void changedVisibleIndex(int newIndex) = 0;
200 virtual void initializeViewItem(FxViewItem *) {}
201 virtual void initializeCurrentItem() {}
202 virtual void updateSections() {}
204 virtual void itemGeometryChanged(QSGItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
212 #endif // QSGITEMVIEW_P_P_H