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 ** 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
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
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 int findLastVisibleIndex(int defaultValue = -1) const;
91 FxViewItem *visibleItem(int modelIndex) const;
92 FxViewItem *firstVisibleItem() const;
93 int mapFromModel(int modelIndex) const;
96 virtual void updateCurrent(int modelIndex);
98 virtual void regenerate();
99 virtual void updateViewport();
102 void refill(qreal from, qreal to, bool doBuffer = false);
103 void scheduleLayout();
106 FxViewItem *createItem(int modelIndex);
107 virtual void releaseItem(FxViewItem *item);
109 QSGItem *createHighlightItem();
110 QSGItem *createComponentItem(QDeclarativeComponent *component, bool receiveItemGeometryChanges, bool createDefault = false);
112 void updateTrackedItem();
113 void updateUnrequestedIndexes();
114 void updateUnrequestedPositions();
115 void positionViewAtIndex(int index, int mode);
117 void checkVisible() const;
119 QDeclarativeGuard<QSGVisualModel> model;
120 QVariant modelVariant;
124 Qt::LayoutDirection layoutDirection;
126 MovementReason moveReason;
128 QList<FxViewItem *> visibleItems;
131 FxViewItem *currentItem;
132 FxViewItem *trackedItem;
133 QHash<QSGItem*,int> unrequestedItems;
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;
144 QDeclarativeComponent *headerComponent;
146 QDeclarativeComponent *footerComponent;
149 mutable qreal minExtent;
150 mutable qreal maxExtent;
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;
167 virtual Qt::Orientation layoutOrientation() const = 0;
168 virtual bool isContentFlowReversed() const = 0;
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;
175 virtual qreal headerSize() const = 0;
176 virtual qreal footerSize() const = 0;
177 virtual void updateHeader() = 0;
178 virtual void updateFooter() = 0;
180 virtual void createHighlight() = 0;
181 virtual void updateHighlight() = 0;
182 virtual void resetHighlightPosition() = 0;
184 virtual void setPosition(qreal pos) = 0;
185 virtual void fixupPosition() = 0;
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;
191 virtual FxViewItem *newViewItem(int index, QSGItem *item) = 0;
192 virtual void initializeViewItem(FxViewItem *) {}
193 virtual void repositionPackageItemAt(QSGItem *item, int index) = 0;
195 virtual void layoutVisibleItems() = 0;
197 virtual void updateSections() {}
198 virtual void changedVisibleIndex(int newIndex) = 0;
199 virtual void initializeCurrentItem() {}
201 virtual void itemGeometryChanged(QSGItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
209 #endif // QSGITEMVIEW_P_P_H