42 #include "private/qdeclarativelistview_p.h" 44 #include "private/qdeclarativeflickable_p_p.h" 45 #include "private/qdeclarativevisualitemmodel_p.h" 47 #include "private/qdeclarativesmoothedanimation_p_p.h" 56 #include "qplatformdefs.h" 60 #ifndef QML_FLICK_SNAPONETHRESHOLD 61 #define QML_FLICK_SNAPONETHRESHOLD 30 112 return (view->effectiveLayoutDirection() ==
Qt::RightToLeft ? -section->width()-section->x() : section->x());
114 return itemPosition();
122 return (view->effectiveLayoutDirection() ==
Qt::RightToLeft ? -item->width()-item->x() : item->x());
140 return item->y() + (item->height() >= 1.0 ? item->height() : 1) - 1;
143 ? -item->width()-item->x() + (item->width() >= 1.0 ? item->width() : 1)
144 : item->x() + (item->width() >= 1.0 ? item->width() : 1)) - 1;
151 pos += section->height();
157 section->setX(-section->width()-pos);
158 pos += section->width();
160 item->setX(-item->width()-pos);
164 pos += section->width();
172 item->setHeight(size);
174 item->setWidth(size);
177 return (x >= item->x() && x < item->x() + item->width() &&
178 y >= item->y() && y < item->y() + item->height());
197 , visiblePos(0), visibleIndex(0)
198 , averageSize(100.0), currentIndex(-1), requestedIndex(-1)
199 , itemCount(0), highlightRangeStart(0), highlightRangeEnd(0)
200 , highlightRangeStartValid(false), highlightRangeEndValid(false)
201 , highlightComponent(0), highlight(0), trackedItem(0)
202 , moveReason(Other), buffer(0), highlightPosAnimator(0), highlightSizeAnimator(0)
203 , sectionCriteria(0), spacing(0.0)
204 , highlightMoveSpeed(400), highlightMoveDuration(-1)
205 , highlightResizeSpeed(400), highlightResizeDuration(-1), highlightRange(
QDeclarativeListView::NoHighlightRange)
207 , footerComponent(0), footer(0), headerComponent(0), header(0)
208 , bufferMode(BufferBefore | BufferAfter)
209 , ownModel(false), wrap(false), autoHighlight(true), haveHighlightRange(false)
210 , correctFlick(false), inFlickCorrection(false), lazyRelease(false)
211 , deferredRelease(false), layoutScheduled(false), currentIndexCleared(false)
212 , inViewportMoved(false)
213 , minExtentDirty(true), maxExtentDirty(true)
223 if (modelIndex >= visibleIndex && modelIndex < visibleIndex + visibleItems.count()) {
224 for (
int i = modelIndex - visibleIndex; i < visibleItems.count(); ++i) {
226 if (item->
index == modelIndex)
235 for (
int i = 0; i < visibleItems.count(); ++i) {
240 return visibleItems.count() ? visibleItems.first() : 0;
246 if (modelIndex < visibleIndex)
250 while (idx < visibleItems.count()) {
252 if (item->
index != -1)
253 lastIndex = item->
index;
254 if (item->
index == modelIndex)
255 return visibleItems.at(idx-1);
258 if (lastIndex == modelIndex-1)
259 return visibleItems.last();
265 if (q->isComponentComplete()) {
268 q->scene()->removeItem(header->item);
269 header->item->deleteLater();
275 q->scene()->removeItem(footer->item);
276 footer->item->deleteLater();
285 updateCurrent(currentIndex);
306 q->QDeclarativeFlickable::setContentY(pos);
309 q->QDeclarativeFlickable::setContentX(-pos-size());
311 q->QDeclarativeFlickable::setContentX(pos);
321 if (!visibleItems.isEmpty()) {
322 pos = (*visibleItems.constBegin())->
position();
323 if (visibleIndex > 0)
324 pos -= visibleIndex * (averageSize + spacing);
331 if (!visibleItems.isEmpty()) {
332 int invisibleCount = visibleItems.count() - visibleIndex;
333 for (
int i = visibleItems.count()-1; i >= 0; --i) {
334 if (visibleItems.at(i)->index != -1) {
335 invisibleCount = model->count() - visibleItems.at(i)->index - 1;
339 pos = (*(--visibleItems.constEnd()))->endPosition() + invisibleCount * (averageSize + spacing);
340 }
else if (model && model->count()) {
341 pos = model->count() * averageSize + (model->count()-1) * spacing;
347 return isRightToLeft() ? -lastPosition()-1 : originPosition();
351 return isRightToLeft() ? -originPosition()-1 : lastPosition();
355 if (
FxListItem *item = visibleItem(modelIndex))
357 if (!visibleItems.isEmpty()) {
358 if (modelIndex < visibleIndex) {
359 int count = visibleIndex - modelIndex;
361 if (modelIndex == currentIndex && currentItem) {
362 cs = currentItem->size() + spacing;
365 return (*visibleItems.constBegin())->
position() - count * (averageSize + spacing) - cs;
367 int idx = visibleItems.count() - 1;
368 while (idx >= 0 && visibleItems.at(idx)->index == -1)
373 idx = visibleItems.at(idx)->index;
374 int count = modelIndex - idx - 1;
376 return (*(--visibleItems.constEnd()))->endPosition() + spacing + count * (averageSize + spacing) + 1;
383 if (
FxListItem *item = visibleItem(modelIndex))
385 if (!visibleItems.isEmpty()) {
386 if (modelIndex < visibleIndex) {
387 int count = visibleIndex - modelIndex;
388 return (*visibleItems.constBegin())->
position() - (count - 1) * (averageSize + spacing) - spacing - 1;
390 int idx = visibleItems.count() - 1;
391 while (idx >= 0 && visibleItems.at(idx)->index == -1)
396 idx = visibleItems.at(idx)->index;
397 int count = modelIndex - idx - 1;
398 return (*(--visibleItems.constEnd()))->endPosition() + count * (averageSize + spacing);
405 if (
FxListItem *item = visibleItem(modelIndex))
409 if (sectionCriteria) {
410 QString propValue = model->stringValue(modelIndex, sectionCriteria->property());
411 section = sectionCriteria->sectionString(propValue);
418 return model && model->count() && model->isValid();
423 return snapItem->position();
424 if (visibleItems.count()) {
425 qreal firstPos = visibleItems.first()->position();
426 qreal endPos = visibleItems.last()->position();
427 if (pos < firstPos) {
428 return firstPos -
qRound((firstPos - pos) / averageSize) * averageSize;
429 }
else if (pos > endPos)
430 return endPos +
qRound((pos - endPos) / averageSize) * averageSize;
432 return qRound((pos - originPosition()) / averageSize) * averageSize + originPosition();
437 for (
int i = 0; i < visibleItems.count(); ++i) {
439 if (item->
index == -1)
442 if (highlight && itemTop >= pos && item->
endPosition() <= pos + highlight->size() - 1)
444 if (itemTop+item->
size()/2 >= pos && itemTop-item->
size()/2 < pos)
452 for (
int i = visibleItems.count()-1; i >= 0; --i) {
454 if (listItem->
index != -1) {
455 lastIndex = listItem->
index;
464 if (modelIndex < visibleIndex || modelIndex >= visibleIndex + visibleItems.count())
466 for (
int i = 0; i < visibleItems.count(); ++i) {
468 if (listItem->
index == modelIndex)
470 if (listItem->
index > modelIndex)
479 q->setContentHeight(endPosition() - startPosition() + 1);
481 q->setContentWidth(endPosition() - startPosition() + 1);
488 if (!q->isComponentComplete())
490 if (item != contentItem && (!highlight || item != highlight->item)) {
496 if ((header && header->item == item) || (footer && footer->item == item)) {
502 if (currentItem && currentItem->item == item)
504 if (trackedItem && trackedItem->item == item)
505 q->trackedPositionChanged();
511 for (
int i = 0; i < visibleItems.count(); ++i) {
513 if (listItem->
index == -1) {
515 }
else if (listItem->
index != visibleIndex + i - skip) {
516 qFatal(
"index %d %d %d", visibleIndex, i, listItem->
index);
521 void refill(
qreal from,
qreal to,
bool doBuffer =
false);
522 void scheduleLayout();
524 void updateUnrequestedIndexes();
525 void updateUnrequestedPositions();
526 void updateTrackedItem();
527 void createHighlight();
528 void updateHighlight();
530 void updateSections();
531 void updateCurrentSection();
532 void updateCurrent(
int);
533 void updateAverage();
536 void fixupPosition();
537 void positionViewAtIndex(
int index,
int mode);
569 static const int sectionCacheSize = 4;
583 enum BufferMode { NoBuffer = 0x00, BufferBefore = 0x01, BufferAfter = 0x02 };
607 addItemChangeListener(
this, Geometry);
616 for (
int i = 0; i < visibleItems.count(); ++i)
617 releaseItem(visibleItems.at(i));
618 visibleItems.clear();
619 for (
int i = 0; i < sectionCacheSize; ++i) {
620 delete sectionCache[i];
623 visiblePos = header ? header->size() : 0;
625 releaseItem(currentItem);
629 minExtentDirty =
true;
630 maxExtentDirty =
true;
638 requestedIndex = modelIndex;
642 listItem->
index = modelIndex;
644 if (sectionCriteria) {
645 QString propValue = model->stringValue(modelIndex, sectionCriteria->property());
647 if (modelIndex > 0) {
648 if (
FxListItem *item = itemBefore(modelIndex))
653 if (modelIndex < model->count()-1) {
654 if (
FxListItem *item = visibleItem(modelIndex+1))
660 if (model->completePending()) {
664 model->completeItem();
670 if (sectionCriteria && sectionCriteria->delegate()) {
672 createSection(listItem);
674 unrequestedItems.remove(listItem->
item);
687 creationContext ? creationContext :
qmlContext(q));
706 if (trackedItem == item)
710 if (model->release(item->
item) == 0) {
712 unrequestedItems.insert(item->
item, model->indexOf(item->
item, q));
717 if (!sectionCache[i]) {
718 sectionCache[i] = item->
section;
724 }
while (i < sectionCacheSize);
733 if (!isValid() || !q->isComponentComplete())
735 itemCount = model->count();
736 qreal bufferFrom = from - buffer;
737 qreal bufferTo = to + buffer;
738 qreal fillFrom = from;
740 if (doBuffer && (bufferMode & BufferAfter))
742 if (doBuffer && (bufferMode & BufferBefore))
743 fillFrom = bufferFrom;
745 bool haveValidItems =
false;
746 int modelIndex = visibleIndex;
747 qreal itemEnd = visiblePos-1;
748 if (!visibleItems.isEmpty()) {
749 visiblePos = (*visibleItems.constBegin())->
position();
750 itemEnd = (*(--visibleItems.constEnd()))->endPosition() + spacing;
751 int i = visibleItems.count() - 1;
752 while (i > 0 && visibleItems.at(i)->index == -1)
754 if (visibleItems.at(i)->index != -1) {
755 haveValidItems =
true;
756 modelIndex = visibleItems.at(i)->index + 1;
760 if (haveValidItems && (fillFrom > itemEnd+averageSize+spacing
761 || fillTo < visiblePos - averageSize - spacing)) {
764 int count = (fillFrom - itemEnd) / (averageSize + spacing);
765 for (
int i = 0; i < visibleItems.count(); ++i)
766 releaseItem(visibleItems.at(i));
767 visibleItems.clear();
769 if (modelIndex >= model->count()) {
770 count -= modelIndex - model->count() + 1;
771 modelIndex = model->count() - 1;
772 }
else if (modelIndex < 0) {
776 visibleIndex = modelIndex;
777 visiblePos = itemEnd + count * (averageSize + spacing) + 1;
778 itemEnd = visiblePos-1;
781 bool changed =
false;
783 qreal pos = itemEnd + 1;
784 while (modelIndex < model->count() && pos <= fillTo) {
786 if (!(item = createItem(modelIndex)))
789 pos += item->
size() + spacing;
790 visibleItems.append(item);
796 while (visibleIndex > 0 && visibleIndex <= model->count() && visiblePos-1 >= fillFrom) {
798 if (!(item = createItem(visibleIndex-1)))
801 visiblePos -= item->
size() + spacing;
803 visibleItems.prepend(item);
809 if (!lazyRelease || !changed || deferredRelease) {
810 while (visibleItems.count() > 1 && (item = visibleItems.first()) && item->
endPosition() < bufferFrom) {
814 if (item->
index != -1)
816 visibleItems.removeFirst();
820 while (visibleItems.count() > 1 && (item = visibleItems.last()) && item->
position() > bufferTo) {
824 visibleItems.removeLast();
828 deferredRelease =
false;
830 deferredRelease =
true;
833 minExtentDirty =
true;
834 maxExtentDirty =
true;
835 if (visibleItems.count())
836 visiblePos = (*visibleItems.constBegin())->
position();
838 if (currentIndex >= 0 && currentItem && !visibleItem(currentIndex)) {
839 currentItem->setPosition(positionAt(currentIndex));
844 updateCurrentSection();
850 updateUnrequestedPositions();
851 }
else if (!doBuffer && buffer && bufferMode != NoBuffer) {
852 refill(from, to,
true);
860 if (!layoutScheduled) {
861 layoutScheduled =
true;
869 layoutScheduled =
false;
870 if (!isValid() && !visibleItems.count()) {
875 if (!visibleItems.isEmpty()) {
876 bool fixedCurrent = currentItem && visibleItems.first()->item == currentItem->item;
877 qreal sum = visibleItems.first()->size();
878 qreal pos = visibleItems.first()->position() + visibleItems.first()->size() + spacing;
879 for (
int i=1; i < visibleItems.count(); ++i) {
882 pos += item->
size() + spacing;
884 fixedCurrent = fixedCurrent || (currentItem && item->
item == currentItem->item);
886 averageSize =
qRound(sum / visibleItems.count());
888 if (currentIndex >= 0 && currentItem && !fixedCurrent)
889 currentItem->setPosition(positionAt(currentIndex));
892 minExtentDirty =
true;
893 maxExtentDirty =
true;
895 if (!q->isMoving() && !q->isFlicking()) {
900 updateCurrentSection();
912 for (it = unrequestedItems.
begin(); it != unrequestedItems.
end(); ++
it)
913 *it = model->indexOf(it.
key(), q);
919 if (unrequestedItems.count()) {
922 for (it = unrequestedItems.
begin(); it != unrequestedItems.
end(); ++
it) {
925 if (item->
y() + item->
height() > pos && item->
y() < pos + q->height())
926 item->
setY(positionAt(*it));
928 if (item->
x() + item->
width() > pos && item->
x() < pos + q->width()) {
930 item->
setX(-positionAt(*it)-item->
width());
932 item->
setX(positionAt(*it));
947 q->trackedPositionChanged();
953 bool changed =
false;
955 if (trackedItem == highlight)
957 if (highlight->item->scene())
958 highlight->item->scene()->removeItem(highlight->item);
959 highlight->item->deleteLater();
962 delete highlightPosAnimator;
963 delete highlightSizeAnimator;
964 highlightPosAnimator = 0;
965 highlightSizeAnimator = 0;
971 if (highlightComponent) {
972 item = createComponentItem(highlightComponent);
980 if (currentItem && autoHighlight) {
982 highlight->item->setHeight(currentItem->item->height());
984 highlight->item->setWidth(currentItem->item->width());
986 highlight->setPosition(currentItem->itemPosition());
993 highlightPosAnimator->velocity = highlightMoveSpeed;
994 highlightPosAnimator->userDuration = highlightMoveDuration;
997 highlightSizeAnimator->velocity = highlightResizeSpeed;
998 highlightSizeAnimator->userDuration = highlightResizeDuration;
1000 if (autoHighlight) {
1001 highlightPosAnimator->restart();
1002 highlightSizeAnimator->restart();
1008 emit q->highlightItemChanged();
1013 if ((!currentItem && highlight) || (currentItem && !highlight))
1015 if (currentItem && autoHighlight && highlight && !hData.moving && !vData.moving) {
1017 highlightPosAnimator->to = isRightToLeft()
1018 ? -currentItem->itemPosition()-currentItem->itemSize()
1019 : currentItem->itemPosition();
1020 highlightSizeAnimator->to = currentItem->itemSize();
1022 if (highlight->item->width() == 0)
1023 highlight->item->setWidth(currentItem->item->width());
1025 if (highlight->item->height() == 0)
1026 highlight->item->setHeight(currentItem->item->height());
1028 highlightPosAnimator->restart();
1029 highlightSizeAnimator->restart();
1031 updateTrackedItem();
1037 if (!sectionCriteria || !sectionCriteria->delegate())
1042 int i = sectionCacheSize-1;
1043 while (i >= 0 && !sectionCache[i])
1046 listItem->
section = sectionCache[i];
1047 sectionCache[i] = 0;
1054 QObject *nobj = sectionCriteria->delegate()->beginCreate(context);
1068 sectionCriteria->delegate()->completeCreate();
1075 }
else if (listItem->
section) {
1079 if (!sectionCache[i]) {
1080 sectionCache[i] = listItem->
section;
1086 }
while (i < sectionCacheSize);
1095 if (sectionCriteria && !visibleItems.isEmpty()) {
1097 if (visibleIndex > 0)
1098 prevSection = sectionAt(visibleIndex-1);
1101 for (
int i = 0; i < visibleItems.count(); ++i) {
1104 if (visibleItems.at(i)->index != -1) {
1105 QString propValue = model->stringValue(visibleItems.at(i)->index, sectionCriteria->property());
1106 attached->
setSection(sectionCriteria->sectionString(propValue));
1107 idx = visibleItems.at(i)->index;
1109 createSection(visibleItems.at(i));
1112 prevSection = attached->
section();
1116 if (idx > 0 && idx < model->count()-1)
1127 if (!sectionCriteria || visibleItems.isEmpty()) {
1128 if (!currentSection.isEmpty()) {
1129 currentSection.clear();
1130 emit q->currentSectionChanged();
1135 while (index < visibleItems.count() && visibleItems.at(index)->endPosition() <
position())
1138 QString newSection = currentSection;
1139 if (index < visibleItems.count())
1140 newSection = visibleItems.
at(index)->attached->section();
1142 newSection = visibleItems.first()->attached->
section();
1143 if (newSection != currentSection) {
1144 currentSection = newSection;
1145 emit q->currentSectionChanged();
1152 if (!q->isComponentComplete() || !isValid() || modelIndex < 0 || modelIndex >= model->count()) {
1154 currentItem->attached->setIsCurrentItem(
false);
1155 releaseItem(currentItem);
1157 currentIndex = modelIndex;
1158 emit q->currentIndexChanged();
1160 }
else if (currentIndex != modelIndex) {
1161 currentIndex = modelIndex;
1162 emit q->currentIndexChanged();
1167 if (currentItem && currentIndex == modelIndex) {
1172 currentIndex = modelIndex;
1173 currentItem = createItem(modelIndex);
1174 if (oldCurrentItem && (!currentItem || oldCurrentItem->
item != currentItem->item))
1177 if (modelIndex == visibleIndex - 1 && visibleItems.count()) {
1179 currentItem->setPosition(visibleItems.first()->position() - currentItem->size() - spacing);
1183 currentItem->setPosition(positionAt(modelIndex));
1185 currentItem->item->setFocus(
true);
1186 currentItem->attached->setIsCurrentItem(
true);
1190 if (currentItem->section)
1191 currentItem->section->setVisible(
false);
1192 if (visibleItems.isEmpty())
1193 averageSize = currentItem->size();
1196 emit q->currentIndexChanged();
1198 releaseItem(oldCurrentItem);
1203 if (!visibleItems.count())
1206 for (
int i = 0; i < visibleItems.count(); ++i)
1207 sum += visibleItems.at(i)->size();
1208 averageSize =
qRound(sum / visibleItems.count());
1214 if (!footer && footerComponent) {
1226 if (visibleItems.count()) {
1227 qreal endPos = lastPosition() + 1;
1228 if (lastVisibleIndex() == model->count()-1) {
1229 footer->setPosition(endPos);
1232 if (endPos <= visiblePos || footer->
position() < endPos)
1233 footer->setPosition(endPos);
1236 footer->setPosition(visiblePos);
1244 if (!header && headerComponent) {
1256 if (visibleItems.count()) {
1257 qreal startPos = originPosition();
1258 if (visibleIndex == 0) {
1259 header->setPosition(startPos - header->size());
1261 if (
position() <= startPos || header->position() > startPos - header->size())
1262 header->setPosition(startPos - header->size());
1266 visiblePos = header->size();
1267 header->setPosition(0);
1289 correctFlick =
false;
1290 fixupMode = moveReason ==
Mouse ? fixupMode : Immediate;
1293 qreal highlightStart;
1296 if (isRightToLeft()) {
1299 highlightStart = highlightRangeStartValid ? size() - highlightRangeEnd : highlightRangeStart;
1300 highlightEnd = highlightRangeEndValid ? size() - highlightRangeStart : highlightRangeEnd;
1303 highlightStart = highlightRangeStart;
1304 highlightEnd = highlightRangeEnd;
1314 bias = averageSize/2;
1315 else if (data.
velocity < 0 && dist < -QML_FLICK_SNAPONETHRESHOLD && dist > -averageSize/2)
1316 bias = -averageSize/2;
1317 if (isRightToLeft())
1319 tempPosition -= bias;
1321 FxListItem *topItem = snapItemAt(tempPosition+highlightStart);
1322 if (!topItem && strictHighlightRange && currentItem) {
1325 topItem = currentItem;
1327 FxListItem *bottomItem = snapItemAt(tempPosition+highlightEnd);
1328 if (!bottomItem && strictHighlightRange && currentItem) {
1331 bottomItem = currentItem;
1335 if (topItem && (isInBounds || strictHighlightRange)) {
1336 if (topItem->
index == 0 && header && tempPosition+highlightStart < header->
position()+header->size()/2 && !strictHighlightRange) {
1337 pos = isRightToLeft() ? - header->position() + highlightStart - size() : header->position() - highlightStart;
1339 if (isRightToLeft())
1340 pos =
qMax(
qMin(-topItem->
position() + highlightStart - size(), -maxExtent), -minExtent);
1342 pos =
qMax(
qMin(topItem->
position() - highlightStart, -maxExtent), -minExtent);
1344 }
else if (bottomItem && isInBounds) {
1345 if (isRightToLeft())
1346 pos =
qMax(
qMin(-bottomItem->
position() + highlightEnd - size(), -maxExtent), -minExtent);
1348 pos =
qMax(
qMin(bottomItem->
position() - highlightEnd, -maxExtent), -minExtent);
1356 timeline.reset(data.
move);
1357 if (fixupMode != Immediate) {
1361 timeline.set(data.
move, -pos);
1363 vTime = timeline.time();
1365 }
else if (currentItem && strictHighlightRange
1368 qreal pos = currentItem->itemPosition();
1369 if (viewPos < pos + currentItem->itemSize() - highlightEnd)
1370 viewPos = pos + currentItem->itemSize() - highlightEnd;
1371 if (viewPos > pos - highlightStart)
1372 viewPos = pos - highlightStart;
1373 if (isRightToLeft())
1374 viewPos = -viewPos-size();
1376 timeline.reset(data.
move);
1378 if (fixupMode != Immediate) {
1382 timeline.set(data.
move, -viewPos);
1385 vTime = timeline.time();
1401 correctFlick =
true;
1405 qreal maxDistance = 0;
1407 qreal highlightStart = isRightToLeft() && highlightRangeStartValid ? size()-highlightRangeEnd : highlightRangeStart;
1414 qreal bias = dist < averageSize/2 ? averageSize/2 : 0;
1415 if (isRightToLeft())
1417 data.
flickTarget = -snapPosAt(-(dataValue - highlightStart) - bias) + highlightStart;
1419 velocity = maxVelocity;
1431 qreal bias = -dist < averageSize/2 ? averageSize/2 : 0;
1432 if (isRightToLeft())
1434 data.
flickTarget = -snapPosAt(-(dataValue - highlightStart) + bias) + highlightStart;
1436 velocity = -maxVelocity;
1447 if (maxDistance > 0 || overShoot) {
1453 if (maxVelocity != -1 && maxVelocity <
qAbs(v)) {
1459 if (!hData.flicking && !vData.flicking) {
1461 qreal accel = deceleration;
1463 overshootDist =
qreal(0.0);
1465 qreal dist = v2 / (accel *
qreal(2.0)) + averageSize/4;
1466 if (maxDistance > 0)
1467 dist =
qMin(dist, maxDistance);
1472 qreal distTemp = isRightToLeft() ? -dist : dist;
1473 data.
flickTarget = -snapPosAt(-(dataValue - highlightStart) + distTemp) + highlightStart;
1478 overshootDist = overShootDistance(vSize);
1481 overshootDist = overShootDistance(vSize);
1488 qreal adjv2 = accel * 2.0f *
qAbs(adjDist);
1497 accel = v2 / (2.0f *
qAbs(dist));
1498 }
else if (overShoot) {
1501 overshootDist = overShootDistance(vSize);
1504 overshootDist = overShootDistance(vSize);
1509 timeline.reset(data.
move);
1510 timeline.accel(data.
move, v, accel, maxDistance + overshootDist);
1512 if (!hData.flicking && q->xflick()) {
1513 hData.flicking =
true;
1514 emit q->flickingChanged();
1515 emit q->flickingHorizontallyChanged();
1516 emit q->flickStarted();
1518 if (!vData.flicking && q->yflick()) {
1519 vData.flicking =
true;
1520 emit q->flickingChanged();
1521 emit q->flickingVerticallyChanged();
1522 emit q->flickStarted();
1524 correctFlick =
true;
1530 newtarget = -snapPosAt(-(tempFlickTarget - highlightStart)) + highlightStart;
1531 newtarget = isRightToLeft() ? -newtarget+size() : newtarget;
1533 if (velocity < 0 && newtarget <= maxExtent)
1534 newtarget = maxExtent - overshootDist;
1535 else if (velocity > 0 && newtarget >= minExtent)
1536 newtarget = minExtent + overshootDist;
1539 correctFlick =
false;
1544 if ((v < 0 && dist < 0) || (v > 0 && dist > 0)) {
1545 correctFlick =
false;
1546 timeline.reset(data.
move);
1547 fixup(data, minExtent, maxExtent);
1551 timeline.reset(data.
move);
1552 timeline.accelDistance(data.
move, v, -dist);
1556 correctFlick =
false;
1557 timeline.reset(data.
move);
1558 fixup(data, minExtent, maxExtent);
1758 return d->modelVariant;
1764 if (
d->modelVariant == model)
1782 if (
object && (vim = qobject_cast<QDeclarativeVisualModel *>(
object))) {
1785 d->ownModel =
false;
1793 d->model = oldModel;
1796 dataModel->setModel(model);
1803 if ((
d->currentIndex >=
d->model->count() ||
d->currentIndex < 0) && !
d->currentIndexCleared) {
1807 d->updateCurrent(
d->currentIndex);
1808 if (
d->highlight &&
d->currentItem) {
1809 if (
d->autoHighlight)
1810 d->highlight->setPosition(
d->currentItem->position());
1811 d->updateTrackedItem();
1814 d->updateViewport();
1857 return dataModel->delegate();
1873 int oldCount = dataModel->count();
1874 dataModel->setDelegate(delegate);
1876 for (
int i = 0; i <
d->visibleItems.count(); ++i)
1877 d->releaseItem(
d->visibleItems.at(i));
1878 d->visibleItems.clear();
1879 d->releaseItem(
d->currentItem);
1884 d->updateCurrent(
d->currentIndex);
1885 if (
d->highlight &&
d->currentItem) {
1886 if (
d->autoHighlight)
1887 d->highlight->setPosition(
d->currentItem->position());
1888 d->updateTrackedItem();
1890 d->updateViewport();
1892 if (oldCount != dataModel->count())
1919 return d->currentIndex;
1925 if (
d->requestedIndex >= 0)
1927 d->currentIndexCleared = (index == -1);
1928 if (index ==
d->currentIndex)
1931 if (
d->layoutScheduled)
1934 d->updateCurrent(index);
1935 }
else if (
d->currentIndex != index) {
1944 if (!
d->currentItem)
1946 return d->currentItem->item;
1967 return d->highlight->item;
1981 return d->model->count();
2002 return d->highlightComponent;
2008 if (highlight !=
d->highlightComponent) {
2010 d->createHighlight();
2012 d->updateHighlight();
2042 return d->autoHighlight;
2048 if (
d->autoHighlight != autoHighlight) {
2049 d->autoHighlight = autoHighlight;
2050 if (autoHighlight) {
2051 d->updateHighlight();
2053 if (
d->highlightPosAnimator)
2054 d->highlightPosAnimator->stop();
2055 if (
d->highlightSizeAnimator)
2056 d->highlightSizeAnimator->stop();
2099 return d->highlightRangeStart;
2105 d->highlightRangeStartValid =
true;
2106 if (
d->highlightRangeStart == start)
2108 d->highlightRangeStart = start;
2109 d->haveHighlightRange =
d->highlightRange !=
NoHighlightRange &&
d->highlightRangeStart <=
d->highlightRangeEnd;
2116 d->highlightRangeStartValid =
false;
2117 if (
d->highlightRangeStart == 0)
2119 d->highlightRangeStart = 0;
2126 return d->highlightRangeEnd;
2132 d->highlightRangeEndValid =
true;
2133 if (
d->highlightRangeEnd == end)
2135 d->highlightRangeEnd =
end;
2136 d->haveHighlightRange =
d->highlightRange !=
NoHighlightRange &&
d->highlightRangeStart <=
d->highlightRangeEnd;
2143 d->highlightRangeEndValid =
false;
2144 if (
d->highlightRangeEnd == 0)
2146 d->highlightRangeEnd = 0;
2153 return d->highlightRange;
2159 if (
d->highlightRange == mode)
2161 d->highlightRange = mode;
2162 d->haveHighlightRange =
d->highlightRange !=
NoHighlightRange &&
d->highlightRangeStart <=
d->highlightRangeEnd;
2185 if (spacing !=
d->spacing) {
2225 if (
d->orient != orientation) {
2266 return d->layoutDirection;
2272 if (
d->layoutDirection != layoutDirection) {
2282 if (
d->effectiveLayoutMirror)
2285 return d->layoutDirection;
2310 if (
d->wrap == wrap)
2347 if (
d->buffer != b) {
2414 if (!
d->sectionCriteria) {
2418 return d->sectionCriteria;
2431 return d->currentSection;
2459 return
d->highlightMoveSpeed;
2465 if (
d->highlightMoveSpeed != speed) {
2466 d->highlightMoveSpeed = speed;
2467 if (
d->highlightPosAnimator)
2468 d->highlightPosAnimator->velocity =
d->highlightMoveSpeed;
2476 return d->highlightMoveDuration;
2482 if (
d->highlightMoveDuration != duration) {
2483 d->highlightMoveDuration = duration;
2484 if (
d->highlightPosAnimator)
2485 d->highlightPosAnimator->userDuration =
d->highlightMoveDuration;
2493 return
d->highlightResizeSpeed;
2499 if (
d->highlightResizeSpeed != speed) {
2500 d->highlightResizeSpeed = speed;
2501 if (
d->highlightSizeAnimator)
2502 d->highlightSizeAnimator->velocity =
d->highlightResizeSpeed;
2510 return d->highlightResizeDuration;
2516 if (
d->highlightResizeDuration != duration) {
2517 d->highlightResizeDuration = duration;
2518 if (
d->highlightSizeAnimator)
2519 d->highlightSizeAnimator->userDuration =
d->highlightResizeDuration;
2557 if (
d->snapMode != mode) {
2578 return d->footerComponent;
2584 if (
d->footerComponent != footer) {
2588 d->footer->item->deleteLater();
2593 d->minExtentDirty =
true;
2594 d->maxExtentDirty =
true;
2597 d->updateViewport();
2619 return d->headerComponent;
2625 if (
d->headerComponent != header) {
2629 d->header->item->deleteLater();
2634 d->minExtentDirty =
true;
2635 d->maxExtentDirty =
true;
2639 d->updateViewport();
2666 if (
d->layoutScheduled)
2681 if (
d->inViewportMoved)
2683 d->inViewportMoved =
true;
2684 d->lazyRelease =
true;
2686 if (
d->hData.flicking ||
d->vData.flicking ||
d->hData.moving ||
d->vData.moving)
2693 qreal highlightStart;
2695 if (
d->isRightToLeft()) {
2697 viewPos = -
d->position()-
d->size();
2698 highlightStart =
d->highlightRangeStartValid ?
d->size()-
d->highlightRangeEnd :
d->highlightRangeStart;
2699 highlightEnd =
d->highlightRangeEndValid ?
d->size()-
d->highlightRangeStart :
d->highlightRangeEnd;
2701 viewPos =
d->position();
2702 highlightStart =
d->highlightRangeStart;
2703 highlightEnd =
d->highlightRangeEnd;
2705 if (pos > viewPos + highlightEnd -
d->highlight->size())
2706 pos = viewPos + highlightEnd -
d->highlight->size();
2707 if (pos < viewPos + highlightStart)
2708 pos = viewPos + highlightStart;
2709 d->highlightPosAnimator->stop();
2710 d->highlight->setPosition(
qRound(pos));
2713 if (
FxListItem *snapItem =
d->snapItemAt(
d->highlight->position())) {
2714 if (snapItem->index >= 0 && snapItem->index !=
d->currentIndex)
2715 d->updateCurrent(snapItem->index);
2720 if ((
d->hData.flicking ||
d->vData.flicking) &&
d->correctFlick && !
d->inFlickCorrection) {
2721 d->inFlickCorrection =
true;
2724 if (
yflick() && !
d->vData.inOvershoot) {
2725 if (
d->vData.velocity > 0) {
2727 if ((minY -
d->vData.move.value() <
height()/2 ||
d->vData.flickTarget -
d->vData.move.value() <
height()/2)
2728 && minY !=
d->vData.flickTarget)
2729 d->flickY(-
d->vData.smoothVelocity.value());
2731 }
else if (
d->vData.velocity < 0) {
2733 if ((
d->vData.move.value() - maxY <
height()/2 ||
d->vData.move.value() -
d->vData.flickTarget <
height()/2)
2734 && maxY !=
d->vData.flickTarget)
2735 d->flickY(-
d->vData.smoothVelocity.value());
2740 if (
xflick() && !
d->hData.inOvershoot) {
2741 if (
d->hData.velocity > 0) {
2743 if ((minX -
d->hData.move.value() <
width()/2 ||
d->hData.flickTarget -
d->hData.move.value() <
width()/2)
2744 && minX !=
d->hData.flickTarget)
2745 d->flickX(-
d->hData.smoothVelocity.value());
2746 d->bufferMode =
d->isRightToLeft()
2748 }
else if (
d->hData.velocity < 0) {
2750 if ((
d->hData.move.value() - maxX <
width()/2 ||
d->hData.move.value() -
d->hData.flickTarget <
width()/2)
2751 && maxX !=
d->hData.flickTarget)
2752 d->flickX(-
d->hData.smoothVelocity.value());
2753 d->bufferMode =
d->isRightToLeft()
2757 d->inFlickCorrection =
false;
2759 d->inViewportMoved =
false;
2767 if (
d->minExtentDirty) {
2768 d->minExtent = -
d->startPosition();
2769 if (
d->header &&
d->visibleItems.count())
2770 d->minExtent +=
d->header->size();
2772 d->minExtent +=
d->highlightRangeStart;
2773 if (
d->sectionCriteria) {
2774 if (
d->visibleItem(0))
2775 d->minExtent -=
d->visibleItem(0)->sectionSize();
2777 d->minExtent =
qMax(
d->minExtent, -(
d->endPositionAt(0) -
d->highlightRangeEnd + 1));
2779 d->minExtentDirty =
false;
2782 return d->minExtent;
2790 if (
d->maxExtentDirty) {
2791 if (!
d->model || !
d->model->count()) {
2792 d->maxExtent =
d->header ? -
d->header->size() : 0;
2795 d->maxExtent = -(
d->positionAt(
d->model->count()-1) -
d->highlightRangeStart);
2796 if (
d->highlightRangeEnd !=
d->highlightRangeStart)
2797 d->maxExtent =
qMin(
d->maxExtent, -(
d->endPosition() -
d->highlightRangeEnd + 1));
2799 d->maxExtent = -(
d->endPosition() -
height() + 1);
2802 d->maxExtent -=
d->footer->size();
2804 if (
d->maxExtent > minY)
2805 d->maxExtent = minY;
2806 d->maxExtentDirty =
false;
2808 return d->maxExtent;
2816 if (
d->minExtentDirty) {
2817 d->minExtent = -
d->startPosition();
2819 qreal highlightStart;
2821 qreal endPositionFirstItem = 0;
2822 if (
d->isRightToLeft()) {
2823 if (
d->model &&
d->model->count())
2824 endPositionFirstItem =
d->positionAt(
d->model->count()-1);
2826 d->minExtent +=
d->header->size();
2827 highlightStart =
d->highlightRangeStartValid
2828 ?
d->highlightRangeStart - (
d->lastPosition()-endPositionFirstItem)
2829 :
d->size() - (
d->lastPosition()-endPositionFirstItem);
2830 highlightEnd =
d->highlightRangeEndValid ?
d->highlightRangeEnd :
d->size();
2832 d->minExtent +=
d->footer->size();
2834 if (
d->minExtent < maxX)
2835 d->minExtent = maxX;
2837 endPositionFirstItem =
d->endPositionAt(0);
2838 highlightStart =
d->highlightRangeStart;
2839 highlightEnd =
d->highlightRangeEnd;
2840 if (
d->header &&
d->visibleItems.count())
2841 d->minExtent +=
d->header->size();
2844 d->minExtent +=
d->isRightToLeft() ? -highlightStart : highlightStart;
2845 d->minExtent =
qMax(
d->minExtent, -(endPositionFirstItem - highlightEnd + 1));
2847 d->minExtentDirty =
false;
2850 return d->minExtent;
2858 if (
d->maxExtentDirty) {
2859 qreal highlightStart;
2861 qreal lastItemPosition = 0;
2863 if (
d->isRightToLeft()) {
2864 highlightStart =
d->highlightRangeStartValid ?
d->highlightRangeEnd :
d->size();
2865 highlightEnd =
d->highlightRangeEndValid ?
d->highlightRangeStart :
d->size();
2866 lastItemPosition =
d->endPosition();
2868 highlightStart =
d->highlightRangeStart;
2869 highlightEnd =
d->highlightRangeEnd;
2870 if (
d->model &&
d->model->count())
2871 lastItemPosition =
d->positionAt(
d->model->count()-1);
2873 if (!
d->model || !
d->model->count()) {
2874 if (!
d->isRightToLeft())
2875 d->maxExtent =
d->header ? -
d->header->size() : 0;
2878 d->maxExtent = -(lastItemPosition - highlightStart);
2879 if (highlightEnd != highlightStart) {
2880 d->maxExtent =
d->isRightToLeft()
2881 ?
qMax(
d->maxExtent, -(
d->endPosition() - highlightEnd + 1))
2882 :
qMin(
d->maxExtent, -(
d->endPosition() - highlightEnd + 1));
2885 d->maxExtent = -(
d->endPosition() -
width() + 1);
2887 if (
d->isRightToLeft()) {
2888 if (
d->header &&
d->visibleItems.count())
2889 d->maxExtent -=
d->header->size();
2892 d->maxExtent -=
d->footer->size();
2894 if (
d->maxExtent > minX)
2895 d->maxExtent = minX;
2897 d->maxExtentDirty =
false;
2899 return d->maxExtent;
2909 if (
d->model &&
d->model->count() &&
d->interactive) {
2913 if (
currentIndex() > 0 || (
d->wrap && !
event->isAutoRepeat())) {
2917 }
else if (
d->wrap) {
2924 if (
currentIndex() <
d->model->count() - 1 || (
d->wrap && !
event->isAutoRepeat())) {
2928 }
else if (
d->wrap) {
2939 const QRectF &oldGeometry)
2942 d->maxExtentDirty =
true;
2943 d->minExtentDirty =
true;
2946 int dx = newGeometry.
width() - oldGeometry.
width();
2968 int count =
d->model ?
d->model->count() : 0;
2991 int count =
d->model ?
d->model->count() : 0;
3008 if (layoutScheduled)
3014 maxExtent = -q->maxYExtent();
3016 maxExtent = isRightToLeft() ? q->minXExtent()-size(): -q->maxXExtent();
3019 int itemPos = positionAt(idx);
3022 visibleItems.
clear();
3023 visiblePos = itemPos;
3025 setPosition(
qMin(
qreal(itemPos), maxExtent));
3027 for (
int i = 0; i < oldVisible.
count(); ++i)
3028 releaseItem(oldVisible.
at(i));
3029 item = visibleItem(idx);
3040 pos = itemPos - (size() - item->
size())/2;
3043 pos = itemPos - size() + item->
size();
3048 if (itemPos > pos + size())
3049 pos = itemPos - size() + item->
size();
3055 pos = itemPos - size() + item->
size();
3059 pos =
qMin(pos, maxExtent);
3062 minExtent = -q->minYExtent();
3064 minExtent = isRightToLeft() ? q->maxXExtent()-size(): -q->minXExtent();
3066 pos =
qMax(pos, minExtent);
3071 if (autoHighlight) {
3120 if (!
d->isValid() || index < 0 || index >=
d->model->count())
3122 d->positionViewAtIndex(index, mode);
3161 d->positionViewAtIndex(
d->model->count(),
End);
3182 for (
int i = 0; i <
d->visibleItems.count(); ++i) {
3183 const FxListItem *listItem =
d->visibleItems.at(i);
3185 return listItem->
index;
3201 if (
d->currentIndex < 0 && !
d->currentIndexCleared)
3202 d->updateCurrent(0);
3204 d->updateCurrent(
d->currentIndex);
3205 if (
d->highlight &&
d->currentItem) {
3206 if (
d->autoHighlight)
3207 d->highlight->setPosition(
d->currentItem->position());
3208 d->updateTrackedItem();
3220 if (
d->sectionCriteria && !
d->sectionCriteria->property().isEmpty())
3221 roles <<
d->sectionCriteria->property().toUtf8();
3222 d->model->setWatchedRoles(roles);
3223 d->updateSections();
3232 if (
d->isRightToLeft())
3233 d->refill(-
d->position()-
d->size()+1, -
d->position());
3235 d->refill(
d->position(),
d->position()+
d->size()-1);
3241 if (!
d->trackedItem || !
d->currentItem)
3244 qreal trackedPos =
qCeil(
d->trackedItem->position());
3245 qreal trackedSize =
d->trackedItem->size();
3246 if (
d->trackedItem !=
d->currentItem) {
3247 trackedPos -=
d->currentItem->sectionSize();
3248 trackedSize +=
d->currentItem->sectionSize();
3251 qreal highlightStart;
3253 if (
d->isRightToLeft()) {
3254 viewPos = -
d->position()-
d->size();
3255 highlightStart =
d->highlightRangeStartValid ?
d->size()-
d->highlightRangeEnd :
d->highlightRangeStart;
3256 highlightEnd =
d->highlightRangeEndValid ?
d->size()-
d->highlightRangeStart :
d->highlightRangeEnd;
3258 viewPos =
d->position();
3259 highlightStart =
d->highlightRangeStart;
3260 highlightEnd =
d->highlightRangeEnd;
3263 if (
d->haveHighlightRange) {
3265 if (trackedPos > pos + highlightEnd -
d->trackedItem->size())
3266 pos = trackedPos - highlightEnd +
d->trackedItem->size();
3267 if (trackedPos < pos + highlightStart)
3268 pos = trackedPos - highlightStart;
3270 if (trackedPos < d->startPosition() + highlightStart) {
3271 pos =
d->startPosition();
3272 }
else if (
d->trackedItem->endPosition() >
d->endPosition() -
d->size() + highlightEnd) {
3273 pos =
d->endPosition() -
d->size() + 1;
3274 if (pos < d->startPosition())
3275 pos =
d->startPosition();
3277 if (trackedPos < viewPos + highlightStart) {
3278 pos = trackedPos - highlightStart;
3279 }
else if (trackedPos > viewPos + highlightEnd - trackedSize) {
3280 pos = trackedPos - highlightEnd + trackedSize;
3285 if (trackedPos < viewPos && d->
currentItem->position() < viewPos) {
3286 pos =
d->currentItem->position() < trackedPos ? trackedPos :
d->currentItem->position();
3287 }
else if (
d->trackedItem->endPosition() >= viewPos +
d->size()
3288 &&
d->currentItem->endPosition() >= viewPos +
d->size()) {
3289 if (
d->trackedItem->endPosition() <=
d->currentItem->endPosition()) {
3290 pos =
d->trackedItem->endPosition() -
d->size() + 1;
3291 if (trackedSize >
d->size())
3294 pos =
d->currentItem->endPosition() -
d->size() + 1;
3295 if (
d->currentItem->size() >
d->size())
3296 pos =
d->currentItem->position();
3300 if (viewPos != pos) {
3302 d->calcVelocity =
true;
3303 d->setPosition(pos);
3304 d->calcVelocity =
false;
3314 d->updateUnrequestedIndexes();
3317 qreal tempPos =
d->isRightToLeft() ? -
d->position()-
d->size() :
d->position();
3318 int index =
d->visibleItems.count() ?
d->mapFromModel(modelIndex) : 0;
3321 int i =
d->visibleItems.count() - 1;
3322 while (i > 0 &&
d->visibleItems.at(i)->index == -1)
3324 if (i == 0 &&
d->visibleItems.first()->index == -1) {
3326 index =
d->visibleItems.count();
3327 }
else if (
d->visibleItems.at(i)->index + 1 == modelIndex
3328 &&
d->visibleItems.at(i)->endPosition() <
d->buffer+tempPos+
d->size()-1) {
3330 index =
d->visibleItems.count();
3332 if (modelIndex < d->visibleIndex) {
3334 d->visibleIndex +=
count;
3335 for (
int i = 0; i <
d->visibleItems.count(); ++i) {
3337 if (listItem->
index != -1 && listItem->
index >= modelIndex)
3341 if (
d->currentIndex >= modelIndex) {
3343 d->currentIndex +=
count;
3345 d->currentItem->index =
d->currentIndex;
3348 d->scheduleLayout();
3357 if (
d->visibleItems.count()) {
3358 pos = index <
d->visibleItems.count() ?
d->visibleItems.at(index)->position()
3359 :
d->visibleItems.last()->endPosition()+
d->spacing+1;
3360 }
else if (
d->itemCount == 0 &&
d->header) {
3361 pos =
d->header->size();
3364 int initialPos =
pos;
3367 bool addedVisible =
false;
3369 if (firstVisible && pos < firstVisible->
position()) {
3371 int insertionIdx =
index;
3373 int from = tempPos -
d->buffer;
3374 for (i = count-1; i >= 0 && pos > from; --i) {
3375 if (!addedVisible) {
3376 d->scheduleLayout();
3377 addedVisible =
true;
3385 d->visibleItems.insert(insertionIdx, item);
3386 pos -= item->
size() +
d->spacing;
3393 while (insertionIdx--) {
3395 if (item->
index != -1)
3397 d->releaseItem(item);
3401 for (
int i = insertionIdx-1; i >= 0; i--) {
3408 int to =
d->buffer+tempPos+
d->size()-1;
3409 for (i = 0; i < count && pos <= to; ++i) {
3410 if (!addedVisible) {
3411 d->scheduleLayout();
3412 addedVisible =
true;
3420 d->visibleItems.insert(index, item);
3423 pos += item->
size() +
d->spacing;
3429 while (
d->visibleItems.count() >
index)
3430 d->releaseItem(
d->visibleItems.takeLast());
3432 diff = pos - initialPos;
3434 if (
d->itemCount &&
d->currentIndex >= modelIndex) {
3436 d->currentIndex +=
count;
3437 if (
d->currentItem) {
3438 d->currentItem->index =
d->currentIndex;
3439 d->currentItem->setPosition(
d->currentItem->position() +
diff);
3442 }
else if (!
d->itemCount && (!
d->currentIndex || (
d->currentIndex < 0 && !
d->currentIndexCleared))) {
3443 d->updateCurrent(0);
3446 for (; index <
d->visibleItems.count(); ++
index) {
3448 if (
d->currentItem && listItem->
item !=
d->currentItem->item)
3450 if (listItem->
index != -1)
3454 for (
int j = 0; j < added.
count(); ++j)
3457 d->updateSections();
3468 d->updateUnrequestedIndexes();
3472 int preRemovedSize = 0;
3473 bool removedVisible =
false;
3476 while (it !=
d->visibleItems.end()) {
3478 if (item->
index == -1 || item->
index < modelIndex) {
3481 }
else if (item->
index >= modelIndex + count) {
3487 if (!removedVisible) {
3488 d->scheduleLayout();
3489 removedVisible =
true;
3497 if (item == firstVisible)
3500 preRemovedSize += item->
size();
3501 it =
d->visibleItems.erase(it);
3502 d->releaseItem(item);
3507 if (firstVisible &&
d->visibleItems.first() != firstVisible)
3508 d->visibleItems.first()->setPosition(
d->visibleItems.first()->position() + preRemovedSize);
3511 if (
d->currentIndex >= modelIndex + count) {
3512 d->currentIndex -=
count;
3514 d->currentItem->index -=
count;
3516 }
else if (
d->currentIndex >= modelIndex &&
d->currentIndex < modelIndex + count) {
3518 d->currentItem->attached->setIsCurrentItem(
false);
3519 d->releaseItem(
d->currentItem);
3521 d->currentIndex = -1;
3523 d->updateCurrent(
qMin(modelIndex,
d->itemCount-1));
3529 bool haveVisibleIndex =
false;
3530 for (it =
d->visibleItems.begin(); it !=
d->visibleItems.end(); ++
it) {
3531 if ((*it)->index != -1) {
3532 d->visibleIndex = (*it)->index;
3533 haveVisibleIndex =
true;
3538 if (!haveVisibleIndex) {
3539 d->timeline.clear();
3540 if (removedVisible &&
d->itemCount == 0) {
3541 d->visibleIndex = 0;
3542 d->visiblePos =
d->header ?
d->header->size() : 0;
3548 if (modelIndex < d->visibleIndex)
3549 d->visibleIndex = modelIndex+1;
3550 d->visibleIndex =
qMax(
qMin(
d->visibleIndex,
d->itemCount-1), 0);
3554 d->updateSections();
3562 it !=
d->visibleItems.end();) {
3565 d->releaseItem(listItem);
3566 it =
d->visibleItems.erase(
it);
3573 d->updateSections();
3582 d->updateUnrequestedIndexes();
3584 if (
d->visibleItems.isEmpty()) {
3596 while (it !=
d->visibleItems.end()) {
3598 if (item->
index >= from && item->
index < from + count) {
3600 item->
index += (to-from);
3602 if (item->
position() < firstItemPos)
3603 moveBy += item->
size();
3604 it =
d->visibleItems.erase(it);
3613 int remaining =
count;
3614 int endIndex =
d->visibleIndex;
3615 it =
d->visibleItems.begin();
3616 while (it !=
d->visibleItems.end()) {
3618 if (remaining && item->
index >= to && item->
index < to + count) {
3622 movedItem =
d->createItem(item->
index);
3629 moveBy -= movedItem->
size();
3630 it =
d->visibleItems.insert(it, movedItem);
3634 if (item->
index != -1) {
3635 if (item->
index >= to) {
3639 endIndex = item->
index;
3648 d->visibleItems.append(item);
3653 for (it =
d->visibleItems.begin(); it !=
d->visibleItems.end(); ++
it) {
3654 if ((*it)->index != -1) {
3655 d->visibleIndex = (*it)->index;
3661 if (
d->currentIndex >= 0 &&
d->currentItem) {
3662 int oldCurrent =
d->currentIndex;
3663 d->currentIndex =
d->model->indexOf(
d->currentItem->item,
this);
3664 if (oldCurrent !=
d->currentIndex) {
3665 d->currentItem->index =
d->currentIndex;
3671 while (moved.
count()) {
3672 int idx = moved.
begin().key();
3674 if (
d->currentItem && item->
item ==
d->currentItem->item)
3676 d->releaseItem(item);
3680 if (!
d->visibleItems.isEmpty())
3681 d->visibleItems.first()->setPosition(
d->visibleItems.first()->position() +
moveBy);
3683 d->updateSections();
3690 d->updateSections();
3699 if (
d->highlight &&
d->currentItem) {
3700 if (
d->autoHighlight)
3701 d->highlight->setPosition(
d->currentItem->position());
3702 d->updateTrackedItem();
3711 if (
d->requestedIndex != index) {
3713 d->unrequestedItems.insert(item, index);
3715 item->
setY(
d->positionAt(index));
3717 if (
d->isRightToLeft())
3718 item->
setX(-
d->positionAt(index)-item->
width());
3720 item->
setX(
d->positionAt(index));
3728 d->unrequestedItems.remove(item);
3736 d->updateHighlight();
The QVariant class acts like a union for the most common Qt data types.
void setFlickableDirection(FlickableDirection)
QDeclarativeItem * createComponentItem(QDeclarativeComponent *component)
virtual qreal minYExtent() const
void cacheBufferChanged()
QString section(QChar sep, int start, int end=-1, SectionFlags flags=SectionDefault) const
This function returns a section of the string.
QDeclarativeComponent * headerComponent
Q_INVOKABLE void positionViewAtBeginning()
The QKeyEvent class describes a key event.
FxListItem * snapItemAt(qreal pos)
virtual void componentComplete()
void setCriteria(SectionCriteria)
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
int highlightMoveDuration
QDeclarativeItem * highlightItem()
#define QT_END_NAMESPACE
This macro expands to.
qreal endPositionAt(int modelIndex) const
QDeclarativeListView::SnapMode snapMode
HighlightRangeMode highlightRangeMode() const
QDeclarativeParserStatus ** d
The QEasingCurve class provides easing curves for controlling animation.
const QChar at(int i) const
Returns the character at the given index position in the string.
QList< FxListItem * > visibleItems
void createSection(FxListItem *)
#define it(className, varName)
void destroyingItem(QDeclarativeItem *item)
virtual qreal maxYExtent() const
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
void itemsRemoved(int index, int count)
void setOrientation(Orientation)
void setHighlightFollowsCurrentItem(bool)
virtual bool event(QEvent *)
QDeclarativeComponent * footerComponent
void highlightResizeSpeedChanged()
void highlightMoveDurationChanged()
void setPreferredHighlightEnd(qreal)
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
QDeclarativeItem * contentItem()
static void clear(QVariant::Private *d)
void setFooter(QDeclarativeComponent *)
QDeclarativeComponent * delegate() const
void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry)
QDeclarativeComponent * highlightComponent
virtual void keyPressEvent(QKeyEvent *event)
QDeclarativeContext * parentContext() const
Return the context's parent QDeclarativeContext, or 0 if this context has no parent or if the parent ...
void setPreferredHighlightBegin(qreal)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
virtual void flick(QDeclarativeFlickablePrivate::AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize, QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity)
QPointF pos() const
Returns the position of the item in parent coordinates.
FxListItem * itemBefore(int modelIndex) const
int count(const T &t) const
Returns the number of occurrences of value in the list.
qreal highlightRangeStart
void setDelegate(QDeclarativeComponent *)
QDeclarativeListView::Orientation orient
virtual bool event(QEvent *event)
#define QML_FLICK_SNAPONETHRESHOLD
The QString class provides a Unicode character string.
T * qobject_cast(QObject *object)
T take(const Key &key)
Removes the item with the key from the hash and returns the value associated with it...
QDeclarativeComponent * footer() const
void setView(QDeclarativeListView *view)
void update(const QRectF &rect=QRectF())
Schedules a redraw of the area covered by rect in this item.
Q_DECL_CONSTEXPR T qAbs(const T &t)
The QObject class is the base class of all Qt objects.
Q_DECLARATIVE_EXPORT QDeclarativeContext * qmlContext(const QObject *)
virtual void viewportMoved()
QDeclarativeComponent * highlight() const
void itemsMoved(int from, int to, int count)
bool highlightRangeEndValid
virtual QObject * create(QDeclarativeContext *context=0)
Create an object instance from this component.
void itemGeometryChanged(QDeclarativeItem *, const QRectF &, const QRectF &)
void setVisible(bool visible)
If visible is true, the item is made visible.
virtual qreal maxXExtent() const
Qt::LayoutDirection effectiveLayoutDirection() const
virtual qreal minYExtent() const
int lastVisibleIndex() const
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
void setHighlightMoveDuration(int)
void preferredHighlightBeginChanged()
qreal highlightResizeSpeed
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
int highlightResizeDuration() const
qreal itemPosition() const
void setParentItem(QDeclarativeItem *parent)
int key() const
Returns the code of the key that was pressed or released.
qreal positionAt(int modelIndex) const
void setNextSection(const QString §)
void currentIndexChanged()
qreal snapPosAt(qreal pos)
void append(const T &t)
Inserts value at the end of the list.
void layoutDirectionChanged()
virtual void setContentY(qreal pos)
void positionViewAtIndex(int index, int mode)
void setProperty(const QString &)
SectionCriteria criteria() const
#define QT_BEGIN_NAMESPACE
This macro expands to.
void setZValue(qreal z)
Sets the Z-value of the item to z.
void highlightRangeModeChanged()
The QRectF class defines a rectangle in the plane using floating point precision. ...
Qt::LayoutDirection layoutDirection
The QDeclarativeComponent class encapsulates a QML component definition.
Qt::LayoutDirection layoutDirection() const
const qreal MinimumFlickVelocity
bool highlightRangeStartValid
QDeclarativeComponent * m_delegate
The QDeclarativeItem class provides the most basic of all visual items in QML.
Orientation orientation() const
qreal highlightResizeSpeed() const
bool contains(qreal x, qreal y) const
QDeclarativeListViewAttached * attached
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
void addItemChangeListener(QDeclarativeItemChangeListener *listener, ChangeTypes types)
void removeItem(QGraphicsItem *item)
Removes the item item and all its children from the scene.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
void orientationChanged()
qreal preferredHighlightEnd() const
virtual void setContentX(qreal pos)
void setHighlightMoveSpeed(qreal)
void decrementCurrentIndex()
void setLayoutDirection(Qt::LayoutDirection)
qreal height() const
Returns the height of the rectangle.
virtual qreal value() const
Return the current value.
virtual void viewportMoved()
const T & at(int i) const
Returns the item at index position i in the list.
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
This function is called to handle this item's changes in geometry from oldGeometry to newGeometry...
virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent)
static const char * data(const QByteArray &arr)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
MovementReason moveReason
void setPrevSection(const QString §)
QDeclarativeGuard< QDeclarativeVisualModel > model
qreal width() const
Returns the width of the rectangle.
QDeclarativeViewSection * sectionCriteria
void moveBy(qreal dx, qreal dy)
Moves the item by dx points horizontally, and dy point vertically.
bool isRightToLeft() const
void incrementCurrentIndex()
void clear()
Removes all items from the list.
FxListItem * visibleItem(int modelIndex) const
QDeclarativeComponent * header() const
void updateUnrequestedIndexes()
static qreal component(const QPointF &point, unsigned int i)
QDeclarativeListView(QDeclarativeItem *parent=0)
void setX(qreal x)
Set's the x coordinate of the item's position.
bool highlightFollowsCurrentItem() const
void setContentHeight(qreal)
void setHeader(QDeclarativeComponent *)
virtual qreal minXExtent() const
bool isWrapEnabled() const
virtual qreal minXExtent() const
QHash< QDeclarativeItem *, int > unrequestedItems
qreal endPosition() const
void updateUnrequestedPositions()
void keyNavigationWrapsChanged()
The QList::iterator class provides an STL-style non-const iterator for QList and QQueue.
virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent)
qreal preferredHighlightBegin() const
void setSpacing(qreal spacing)
void setHighlight(QDeclarativeComponent *highlight)
void setContextProperty(const QString &, QObject *)
Set the value of the name property on this context.
QDeclarativeViewSection * sectionCriteria()
int mapFromModel(int modelIndex) const
void highlightResizeDurationChanged()
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
QDeclarativeItem * currentItem()
void setContentWidth(qreal)
FxListItem * createItem(int modelIndex)
void itemsInserted(int index, int count)
void removeItemChangeListener(QDeclarativeItemChangeListener *, ChangeTypes types)
QSmoothedAnimation * highlightSizeAnimator
qreal startPosition() const
Q_CORE_EXPORT void qFatal(const char *,...)
QString currentSection() const
QDeclarativeComponent * delegate() const
void setDelegate(QDeclarativeComponent *delegate)
#define Q_DECLARE_PUBLIC(Class)
QDeclarativeTimeLineValueProxy< QDeclarativeFlickablePrivate > move
qreal y() const
This convenience function is equivalent to calling pos().
SectionCriteria m_criteria
FxListItem * firstVisibleItem() const
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
void QDeclarative_setParent_noEvent(QObject *object, QObject *parent)
Makes the object a child of parent.
void setPosition(qreal pos)
virtual void keyPressEvent(QKeyEvent *)
const Key key(const T &value) const
Returns the first key mapped to value.
QObject * parent() const
Returns a pointer to the parent object.
qreal x() const
This convenience function is equivalent to calling pos().
static QDeclarativeListViewAttached * qmlAttachedProperties(QObject *)
void setY(qreal y)
Set's the y coordinate of the item's position.
virtual void componentComplete()
void trackedPositionChanged()
void highlightMoveSpeedChanged()
Q_INVOKABLE int indexAt(qreal x, qreal y) const
void resetPreferredHighlightBegin()
qreal sectionSize() const
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
void setIsCurrentItem(bool c)
void releaseItem(FxListItem *item)
QDeclarativeListView::HighlightRangeMode highlightRange
void highlightFollowsCurrentItemChanged()
T qvariant_cast(const QVariant &)
virtual void flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize, QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity)
The QDeclarativeContext class defines a context within a QML engine.
static const QGraphicsItemPrivate * get(const QGraphicsItem *item)
void setHighlightResizeDuration(int)
void setCurrentIndex(int idx)
QSmoothedAnimation * highlightPosAnimator
int highlightResizeDuration
void setHighlightResizeSpeed(qreal)
The QDeclarativeProperty class abstracts accessing properties on objects created from QML...
QDeclarativeListView * view
int count(const Key &key) const
Returns the number of items associated with the key.
qreal highlightMoveSpeed() const
void setSnapMode(SnapMode mode)
QDeclarativeListViewPrivate()
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
Q_INVOKABLE void positionViewAtEnd()
static QDeclarativeContext * contextForObject(const QObject *)
Returns the QDeclarativeContext for the object, or 0 if no context has been set.
void refill(qreal from, qreal to, bool doBuffer=false)
void updateCurrentSection()
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
This function is called to handle this item's changes in geometry from oldGeometry to newGeometry...
virtual void setContentX(qreal pos)
qreal lastPosition() const
qreal endPosition() const
static const KeyPair *const end
void resetPreferredHighlightEnd()
int highlightMoveDuration() const
QString sectionString(const QString &value)
The QEvent class is the base class of all event classes.
Type type() const
Returns the event type.
SnapMode snapMode() const
QDeclarativeItem * section
void setSection(const QString §)
virtual void setContentY(qreal pos)
void setModel(const QVariant &)
void setHighlightRangeMode(HighlightRangeMode mode)
Q_INVOKABLE void positionViewAtIndex(int index, int mode)
FxListItem(QDeclarativeItem *i, QDeclarativeListView *v)
Q_DECL_CONSTEXPR int qRound(qreal d)
void preferredHighlightEndChanged()
QString sectionAt(int modelIndex)
void setPosition(qreal pos)
void setWrapEnabled(bool)
qreal originPosition() const
QDeclarativeContext * creationContext() const
Returns the QDeclarativeContext the component was created in.
void checkVisible() const
The QList class is a template class that provides lists.
void keyPressPreHandler(QKeyEvent *)
void itemsChanged(int index, int count)
void createdItem(int index, QDeclarativeItem *item)