diff options
author | David Boddie <david.boddie@nokia.com> | 2010-09-07 16:36:49 (GMT) |
---|---|---|
committer | David Boddie <david.boddie@nokia.com> | 2010-09-07 16:36:49 (GMT) |
commit | 415ad7b69d364c41156d35b98790b02667a6671b (patch) | |
tree | 759b02134da808773a1d68eecf2eb5c0ff12167c /src/declarative | |
parent | 3c18c2a43260a271f8a13e89053eede15d399005 (diff) | |
parent | 703d85e8991e2061062f6d7c695cdeb45d9661fd (diff) | |
download | Qt-415ad7b69d364c41156d35b98790b02667a6671b.zip Qt-415ad7b69d364c41156d35b98790b02667a6671b.tar.gz Qt-415ad7b69d364c41156d35b98790b02667a6671b.tar.bz2 |
Merge branch '4.7' into qmldocs
Diffstat (limited to 'src/declarative')
8 files changed, 239 insertions, 173 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp index 416604b..f0293d6 100644 --- a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp @@ -140,9 +140,6 @@ void QDeclarativeImageBase::load() setImplicitWidth(0); setImplicitHeight(0); emit statusChanged(d->status); - d->sourcesize.setWidth(0); - d->sourcesize.setHeight(0); - emit sourceSizeChanged(); pixmapChange(); update(); } else { @@ -182,19 +179,20 @@ void QDeclarativeImageBase::requestFinished() } else { d->status = Ready; } - emit statusChanged(d->status); + + d->progress = 1.0; setImplicitWidth(d->pix.width()); setImplicitHeight(d->pix.height()); - d->progress = 1.0; - emit progressChanged(d->progress); - if (d->sourcesize.width() != d->pix.width() || d->sourcesize.height() != d->pix.height()) { d->sourcesize.setWidth(d->pix.width()); d->sourcesize.setHeight(d->pix.height()); emit sourceSizeChanged(); } + + emit statusChanged(d->status); + emit progressChanged(d->progress); pixmapChange(); update(); } diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 72c05bf..177c5b3 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -105,12 +105,23 @@ public: else return (view->orientation() == QDeclarativeListView::Vertical ? item->y() : item->x()); } + qreal itemPosition() const { + return (view->orientation() == QDeclarativeListView::Vertical ? item->y() : item->x()); + } qreal size() const { if (section) - return (view->orientation() == QDeclarativeListView::Vertical ? item->height()+section->height() : item->width()+section->height()); + return (view->orientation() == QDeclarativeListView::Vertical ? item->height()+section->height() : item->width()+section->width()); else return (view->orientation() == QDeclarativeListView::Vertical ? item->height() : item->width()); } + qreal itemSize() const { + return (view->orientation() == QDeclarativeListView::Vertical ? item->height() : item->width()); + } + qreal sectionSize() const { + if (section) + return (view->orientation() == QDeclarativeListView::Vertical ? section->height() : section->width()); + return 0.0; + } qreal endPosition() const { return (view->orientation() == QDeclarativeListView::Vertical ? item->y() + (item->height() > 0 ? item->height() : 1) @@ -131,6 +142,12 @@ public: item->setX(pos); } } + void setSize(qreal size) { + if (view->orientation() == QDeclarativeListView::Vertical) + item->setHeight(size); + else + item->setWidth(size); + } bool contains(int x, int y) const { return (x >= item->x() && x < item->x() + item->width() && y >= item->y() && y < item->y() + item->height()); @@ -256,7 +273,12 @@ public: if (!visibleItems.isEmpty()) { if (modelIndex < visibleIndex) { int count = visibleIndex - modelIndex; - return (*visibleItems.constBegin())->position() - count * (averageSize + spacing); + qreal cs = 0; + if (modelIndex == currentIndex && currentItem) { + cs = currentItem->size() + spacing; + --count; + } + return (*visibleItems.constBegin())->position() - count * (averageSize + spacing) - cs; } else { int idx = visibleItems.count() - 1; while (idx >= 0 && visibleItems.at(idx)->index == -1) @@ -716,6 +738,11 @@ void QDeclarativeListViewPrivate::refill(qreal from, qreal to, bool doBuffer) if (visibleItems.count()) visiblePos = (*visibleItems.constBegin())->position(); updateAverage(); + if (currentIndex >= 0 && currentItem && !visibleItem(currentIndex)) { + currentItem->setPosition(positionAt(currentIndex)); + updateHighlight(); + } + if (sectionCriteria) updateCurrentSection(); if (header) @@ -885,8 +912,8 @@ void QDeclarativeListViewPrivate::updateHighlight() createHighlight(); if (currentItem && autoHighlight && highlight && !movingHorizontally && !movingVertically) { // auto-update highlight - highlightPosAnimator->to = currentItem->position(); - highlightSizeAnimator->to = currentItem->size(); + highlightPosAnimator->to = currentItem->itemPosition(); + highlightSizeAnimator->to = currentItem->itemSize(); if (orient == QDeclarativeListView::Vertical) { if (highlight->item->width() == 0) highlight->item->setWidth(currentItem->item->width()); @@ -987,7 +1014,7 @@ void QDeclarativeListViewPrivate::updateCurrentSection() return; } int index = 0; - while (visibleItems.at(index)->endPosition() < position() && index < visibleItems.count()) + while (index < visibleItems.count() && visibleItems.at(index)->endPosition() < position()) ++index; if (index < visibleItems.count()) @@ -1172,9 +1199,9 @@ void QDeclarativeListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m } if (currentItem && haveHighlightRange && highlightRange == QDeclarativeListView::StrictlyEnforceRange) { updateHighlight(); - qreal currPos = currentItem->position(); - if (pos < currPos + currentItem->size() - highlightRangeEnd) - pos = currPos + currentItem->size() - highlightRangeEnd; + qreal currPos = currentItem->itemPosition(); + if (pos < currPos + currentItem->itemSize() - highlightRangeEnd) + pos = currPos + currentItem->itemSize() - highlightRangeEnd; if (pos > currPos - highlightRangeStart) pos = currPos - highlightRangeStart; } @@ -1191,10 +1218,10 @@ void QDeclarativeListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m } else if (haveHighlightRange && highlightRange == QDeclarativeListView::StrictlyEnforceRange) { if (currentItem) { updateHighlight(); - qreal pos = currentItem->position(); + qreal pos = currentItem->itemPosition(); qreal viewPos = position(); - if (viewPos < pos + currentItem->size() - highlightRangeEnd) - viewPos = pos + currentItem->size() - highlightRangeEnd; + if (viewPos < pos + currentItem->itemSize() - highlightRangeEnd) + viewPos = pos + currentItem->itemSize() - highlightRangeEnd; if (viewPos > pos - highlightRangeStart) viewPos = pos - highlightRangeStart; @@ -2342,6 +2369,10 @@ qreal QDeclarativeListView::minYExtent() const d->minExtent += d->header->size(); if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) { d->minExtent += d->highlightRangeStart; + if (d->sectionCriteria) { + if (d->visibleItem(0)) + d->minExtent -= d->visibleItem(0)->sectionSize(); + } d->minExtent = qMax(d->minExtent, -(d->endPositionAt(0) - d->highlightRangeEnd + 1)); } d->minExtentDirty = false; @@ -2589,6 +2620,11 @@ void QDeclarativeListView::positionViewAtIndex(int index, int mode) d->moveReason = QDeclarativeListViewPrivate::Other; cancelFlick(); d->setPosition(pos); + if (d->highlight) { + d->highlight->setPosition(d->currentItem->itemPosition()); + d->highlight->setSize(d->currentItem->itemSize()); + d->updateHighlight(); + } } d->fixupPosition(); } @@ -2649,7 +2685,12 @@ void QDeclarativeListView::trackedPositionChanged() if (!d->trackedItem || !d->currentItem) return; if (d->moveReason == QDeclarativeListViewPrivate::SetIndex) { - const qreal trackedPos = qCeil(d->trackedItem->position()); + qreal trackedPos = qCeil(d->trackedItem->position()); + qreal trackedSize = d->trackedItem->size(); + if (d->trackedItem != d->currentItem) { + trackedPos -= d->currentItem->sectionSize(); + trackedSize += d->currentItem->sectionSize(); + } const qreal viewPos = d->position(); qreal pos = viewPos; if (d->haveHighlightRange) { @@ -2668,8 +2709,8 @@ void QDeclarativeListView::trackedPositionChanged() } else { if (trackedPos < viewPos + d->highlightRangeStart) { pos = trackedPos - d->highlightRangeStart; - } else if (trackedPos > viewPos + d->highlightRangeEnd - d->trackedItem->size()) { - pos = trackedPos - d->highlightRangeEnd + d->trackedItem->size(); + } else if (trackedPos > viewPos + d->highlightRangeEnd - trackedSize) { + pos = trackedPos - d->highlightRangeEnd + trackedSize; } } } @@ -2680,7 +2721,7 @@ void QDeclarativeListView::trackedPositionChanged() && d->currentItem->endPosition() >= viewPos + d->size()) { if (d->trackedItem->endPosition() <= d->currentItem->endPosition()) { pos = d->trackedItem->endPosition() - d->size() + 1; - if (d->trackedItem->size() > d->size()) + if (trackedSize > d->size()) pos = trackedPos; } else { pos = d->currentItem->endPosition() - d->size() + 1; diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index 4b97505..de3f9fa 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -67,7 +67,7 @@ inline qreal qmlMod(qreal x, qreal y) static QDeclarativeOpenMetaObjectType *qPathViewAttachedType = 0; QDeclarativePathViewAttached::QDeclarativePathViewAttached(QObject *parent) -: QObject(parent), m_view(0), m_onPath(false), m_isCurrent(false) +: QObject(parent), m_percent(-1), m_view(0), m_onPath(false), m_isCurrent(false) { if (qPathViewAttachedType) { m_metaobject = new QDeclarativeOpenMetaObject(this, qPathViewAttachedType); @@ -164,8 +164,8 @@ void QDeclarativePathViewPrivate::clear() void QDeclarativePathViewPrivate::updateMappedRange() { - if (model && pathItems != -1 && pathItems < model->count()) - mappedRange = qreal(pathItems)/model->count(); + if (model && pathItems != -1 && pathItems < modelCount) + mappedRange = qreal(pathItems)/modelCount; else mappedRange = 1.0; } @@ -174,13 +174,13 @@ qreal QDeclarativePathViewPrivate::positionOfIndex(qreal index) const { qreal pos = -1.0; - if (model && index >= 0 && index < model->count()) { + if (model && index >= 0 && index < modelCount) { qreal start = 0.0; if (haveHighlightRange && highlightRangeMode != QDeclarativePathView::NoHighlightRange) start = highlightRangeStart; qreal globalPos = index + offset; - globalPos = qmlMod(globalPos, qreal(model->count())) / model->count(); - if (pathItems != -1 && pathItems < model->count()) { + globalPos = qmlMod(globalPos, qreal(modelCount)) / modelCount; + if (pathItems != -1 && pathItems < modelCount) { globalPos += start * mappedRange; globalPos = qmlMod(globalPos, 1.0); if (globalPos < mappedRange) @@ -242,21 +242,22 @@ void QDeclarativePathViewPrivate::updateHighlight() } else { qreal target = currentIndex; + offsetAdj = 0.0; tl.reset(moveHighlight); moveHighlight.setValue(highlightPosition); const int duration = highlightMoveDuration; - if (target - highlightPosition > model->count()/2) { + if (target - highlightPosition > modelCount/2) { highlightUp = false; - qreal distance = model->count() - target + highlightPosition; + qreal distance = modelCount - target + highlightPosition; tl.move(moveHighlight, 0.0, QEasingCurve(QEasingCurve::InQuad), int(duration * highlightPosition / distance)); - tl.set(moveHighlight, model->count()-0.01); - tl.move(moveHighlight, target, QEasingCurve(QEasingCurve::OutQuad), int(duration * (model->count()-target) / distance)); - } else if (target - highlightPosition <= -model->count()/2) { + tl.set(moveHighlight, modelCount-0.01); + tl.move(moveHighlight, target, QEasingCurve(QEasingCurve::OutQuad), int(duration * (modelCount-target) / distance)); + } else if (target - highlightPosition <= -modelCount/2) { highlightUp = true; - qreal distance = model->count() - highlightPosition + target; - tl.move(moveHighlight, model->count()-0.01, QEasingCurve(QEasingCurve::InQuad), int(duration * (model->count()-highlightPosition) / distance)); + qreal distance = modelCount - highlightPosition + target; + tl.move(moveHighlight, modelCount-0.01, QEasingCurve(QEasingCurve::InQuad), int(duration * (modelCount-highlightPosition) / distance)); tl.set(moveHighlight, 0.0); tl.move(moveHighlight, target, QEasingCurve(QEasingCurve::OutQuad), int(duration * target / distance)); } else { @@ -277,7 +278,7 @@ void QDeclarativePathViewPrivate::setHighlightPosition(qreal pos) end = highlightRangeEnd; } - qreal range = qreal(model->count()); + qreal range = qreal(modelCount); // calc normalized position of highlight relative to offset qreal relativeHighlight = qmlMod(pos + offset, range) / range; @@ -300,6 +301,9 @@ void QDeclarativePathViewPrivate::setHighlightPosition(qreal pos) void QDeclarativePathViewPrivate::updateItem(QDeclarativeItem *item, qreal percent) { if (QDeclarativePathViewAttached *att = attached(item)) { + if (qFuzzyCompare(att->m_percent, percent)) + return; + att->m_percent = percent; foreach(const QString &attr, path->attributes()) att->setValue(attr.toUtf8(), path->attributeAt(attr, percent)); } @@ -473,17 +477,19 @@ void QDeclarativePathView::setModel(const QVariant &model) if (QDeclarativeVisualDataModel *dataModel = qobject_cast<QDeclarativeVisualDataModel*>(d->model)) dataModel->setModel(model); } + d->modelCount = 0; if (d->model) { connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); connect(d->model, SIGNAL(modelReset()), this, SLOT(modelReset())); connect(d->model, SIGNAL(createdItem(int, QDeclarativeItem*)), this, SLOT(createdItem(int,QDeclarativeItem*))); - } - if (d->model->count()) - d->offset = qmlMod(d->offset, qreal(d->model->count())); - if (d->offset < 0) - d->offset = d->model->count() + d->offset; + d->modelCount = d->model->count(); + if (d->model->count()) + d->offset = qmlMod(d->offset, qreal(d->model->count())); + if (d->offset < 0) + d->offset = d->model->count() + d->offset; +} d->regenerate(); d->fixOffset(); emit countChanged(); @@ -497,7 +503,7 @@ void QDeclarativePathView::setModel(const QVariant &model) int QDeclarativePathView::count() const { Q_D(const QDeclarativePathView); - return d->model ? d->model->count() : 0; + return d->model ? d->modelCount : 0; } /*! @@ -545,11 +551,11 @@ int QDeclarativePathView::currentIndex() const void QDeclarativePathView::setCurrentIndex(int idx) { Q_D(QDeclarativePathView); - if (d->model && d->model->count()) - idx = qAbs(idx % d->model->count()); + if (d->model && d->modelCount) + idx = qAbs(idx % d->modelCount); if (d->model && idx != d->currentIndex) { - if (d->model->count()) { - int itemIndex = (d->currentIndex - d->firstIndex + d->model->count()) % d->model->count(); + if (d->modelCount) { + int itemIndex = (d->currentIndex - d->firstIndex + d->modelCount) % d->modelCount; if (itemIndex < d->items.count()) { if (QDeclarativeItem *item = d->items.at(itemIndex)) { if (QDeclarativePathViewAttached *att = d->attached(item)) @@ -560,10 +566,10 @@ void QDeclarativePathView::setCurrentIndex(int idx) d->currentItem = 0; d->moveReason = QDeclarativePathViewPrivate::SetIndex; d->currentIndex = idx; - if (d->model->count()) { + if (d->modelCount) { if (d->haveHighlightRange && d->highlightRangeMode == QDeclarativePathView::StrictlyEnforceRange) d->snapToCurrent(); - int itemIndex = (idx - d->firstIndex + d->model->count()) % d->model->count(); + int itemIndex = (idx - d->firstIndex + d->modelCount) % d->modelCount; if (itemIndex < d->items.count()) { d->currentItem = d->items.at(itemIndex); d->currentItem->setFocus(true); @@ -600,10 +606,10 @@ void QDeclarativePathView::incrementCurrentIndex() void QDeclarativePathView::decrementCurrentIndex() { Q_D(QDeclarativePathView); - if (d->model && d->model->count()) { + if (d->model && d->modelCount) { int idx = currentIndex()-1; if (idx < 0) - idx = d->model->count() - 1; + idx = d->modelCount - 1; setCurrentIndex(idx); } } @@ -632,9 +638,9 @@ void QDeclarativePathViewPrivate::setOffset(qreal o) Q_Q(QDeclarativePathView); if (offset != o) { if (isValid() && q->isComponentComplete()) { - offset = qmlMod(o, qreal(model->count())); + offset = qmlMod(o, qreal(modelCount)); if (offset < 0) - offset += qreal(model->count()); + offset += qreal(modelCount); q->refill(); } else { offset = o; @@ -643,6 +649,11 @@ void QDeclarativePathViewPrivate::setOffset(qreal o) } } +void QDeclarativePathViewPrivate::setAdjustedOffset(qreal o) +{ + setOffset(o+offsetAdj); +} + /*! \qmlproperty Component PathView::highlight This property holds the component to use as the highlight. @@ -705,6 +716,8 @@ QDeclarativeItem *QDeclarativePathView::highlightItem() These properties set the preferred range of the highlight (current item) within the view. The preferred values must be in the range 0.0-1.0. + If highlightRangeMode is set to \e PathView.NoHighlightRange + If highlightRangeMode is set to \e PathView.ApplyRange the view will attempt to maintain the highlight within the range, however the highlight can move outside of the range at the ends of the path @@ -1071,14 +1084,14 @@ void QDeclarativePathView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) d->moveReason = QDeclarativePathViewPrivate::Mouse; qreal newPc; d->pointNear(event->pos(), &newPc); - qreal diff = (newPc - d->startPc)*d->model->count()*d->mappedRange; + qreal diff = (newPc - d->startPc)*d->modelCount*d->mappedRange; if (diff) { setOffset(d->offset + diff); - if (diff > d->model->count()/2) - diff -= d->model->count(); - else if (diff < -d->model->count()/2) - diff += d->model->count(); + if (diff > d->modelCount/2) + diff -= d->modelCount; + else if (diff < -d->modelCount/2) + diff += d->modelCount; d->lastElapsed = QDeclarativeItemPrivate::restart(d->lastPosTime); d->lastDist = diff; @@ -1102,15 +1115,15 @@ void QDeclarativePathView::mouseReleaseEvent(QGraphicsSceneMouseEvent *) qreal elapsed = qreal(d->lastElapsed + QDeclarativeItemPrivate::elapsed(d->lastPosTime)) / 1000.; qreal velocity = elapsed > 0. ? d->lastDist / elapsed : 0; - if (d->model && d->model->count() && qAbs(velocity) > 1.) { - qreal count = d->pathItems == -1 ? d->model->count() : d->pathItems; + if (d->model && d->modelCount && qAbs(velocity) > 1.) { + qreal count = d->pathItems == -1 ? d->modelCount : d->pathItems; if (qAbs(velocity) > count * 2) // limit velocity velocity = (velocity > 0 ? count : -count) * 2; // Calculate the distance to be travelled qreal v2 = velocity*velocity; qreal accel = d->deceleration/10; // + 0.25 to encourage moving at least one item in the flick direction - qreal dist = qMin(qreal(d->model->count()-1), qreal(v2 / (accel * 2.0) + 0.25)); + qreal dist = qMin(qreal(d->modelCount-1), qreal(v2 / (accel * 2.0) + 0.25)); if (d->haveHighlightRange && d->highlightRangeMode == QDeclarativePathView::StrictlyEnforceRange) { // round to nearest item. if (velocity > 0.) @@ -1125,6 +1138,7 @@ void QDeclarativePathView::mouseReleaseEvent(QGraphicsSceneMouseEvent *) accel = v2 / (2.0f * qAbs(dist)); } } + d->offsetAdj = 0.0; d->moveOffset.setValue(d->offset); d->tl.accel(d->moveOffset, velocity, accel, dist); d->tl.callback(QDeclarativeTimeLineCallback(&d->moveOffset, d->fixOffsetCallback, d)); @@ -1260,79 +1274,81 @@ void QDeclarativePathView::refill() d->updateItem(item, 1.0); d->releaseItem(item); if (it == d->items.begin()) { - if (++d->firstIndex >= d->model->count()) + if (++d->firstIndex >= d->modelCount) d->firstIndex = 0; } it = d->items.erase(it); } ++idx; - if (idx >= d->model->count()) + if (idx >= d->modelCount) idx = 0; } - // add items to beginning and end - int count = d->pathItems == -1 ? d->model->count() : qMin(d->pathItems, d->model->count()); - if (d->items.count() < count) { - int idx = qRound(d->model->count() - d->offset) % d->model->count(); - qreal startPos = 0.0; - if (d->haveHighlightRange && d->highlightRangeMode != QDeclarativePathView::NoHighlightRange) - startPos = d->highlightRangeStart; - if (d->firstIndex >= 0) { - startPos = d->positionOfIndex(d->firstIndex); - idx = (d->firstIndex + d->items.count()) % d->model->count(); - } - qreal pos = d->positionOfIndex(idx); - while ((pos > startPos || !d->items.count()) && d->items.count() < count) { -// qDebug() << "append" << idx; - QDeclarativeItem *item = d->getItem(idx); - if (d->model->completePending()) - item->setZValue(idx+1); - if (d->currentIndex == idx) { - item->setFocus(true); - if (QDeclarativePathViewAttached *att = d->attached(item)) - att->setIsCurrentItem(true); - currentVisible = true; - d->currentItemOffset = pos; - d->currentItem = item; + if (d->modelCount) { + // add items to beginning and end + int count = d->pathItems == -1 ? d->modelCount : qMin(d->pathItems, d->modelCount); + if (d->items.count() < count) { + int idx = qRound(d->modelCount - d->offset) % d->modelCount; + qreal startPos = 0.0; + if (d->haveHighlightRange && d->highlightRangeMode != QDeclarativePathView::NoHighlightRange) + startPos = d->highlightRangeStart; + if (d->firstIndex >= 0) { + startPos = d->positionOfIndex(d->firstIndex); + idx = (d->firstIndex + d->items.count()) % d->modelCount; } - if (d->items.count() == 0) - d->firstIndex = idx; - d->items.append(item); - d->updateItem(item, pos); - if (d->model->completePending()) - d->model->completeItem(); - ++idx; - if (idx >= d->model->count()) - idx = 0; - pos = d->positionOfIndex(idx); - } - - idx = d->firstIndex - 1; - if (idx < 0) - idx = d->model->count() - 1; - pos = d->positionOfIndex(idx); - while (pos >= 0.0 && pos < startPos) { -// qDebug() << "prepend" << idx; - QDeclarativeItem *item = d->getItem(idx); - if (d->model->completePending()) - item->setZValue(idx+1); - if (d->currentIndex == idx) { - item->setFocus(true); - if (QDeclarativePathViewAttached *att = d->attached(item)) - att->setIsCurrentItem(true); - currentVisible = true; - d->currentItemOffset = pos; - d->currentItem = item; + qreal pos = d->positionOfIndex(idx); + while ((pos > startPos || !d->items.count()) && d->items.count() < count) { + // qDebug() << "append" << idx; + QDeclarativeItem *item = d->getItem(idx); + if (d->model->completePending()) + item->setZValue(idx+1); + if (d->currentIndex == idx) { + item->setFocus(true); + if (QDeclarativePathViewAttached *att = d->attached(item)) + att->setIsCurrentItem(true); + currentVisible = true; + d->currentItemOffset = pos; + d->currentItem = item; + } + if (d->items.count() == 0) + d->firstIndex = idx; + d->items.append(item); + d->updateItem(item, pos); + if (d->model->completePending()) + d->model->completeItem(); + ++idx; + if (idx >= d->modelCount) + idx = 0; + pos = d->positionOfIndex(idx); } - d->items.prepend(item); - d->updateItem(item, pos); - if (d->model->completePending()) - d->model->completeItem(); - d->firstIndex = idx; + idx = d->firstIndex - 1; if (idx < 0) - idx = d->model->count() - 1; + idx = d->modelCount - 1; pos = d->positionOfIndex(idx); + while (pos >= 0.0 && pos < startPos) { + // qDebug() << "prepend" << idx; + QDeclarativeItem *item = d->getItem(idx); + if (d->model->completePending()) + item->setZValue(idx+1); + if (d->currentIndex == idx) { + item->setFocus(true); + if (QDeclarativePathViewAttached *att = d->attached(item)) + att->setIsCurrentItem(true); + currentVisible = true; + d->currentItemOffset = pos; + d->currentItem = item; + } + d->items.prepend(item); + d->updateItem(item, pos); + if (d->model->completePending()) + d->model->completeItem(); + d->firstIndex = idx; + idx = d->firstIndex - 1; + if (idx < 0) + idx = d->modelCount - 1; + pos = d->positionOfIndex(idx); + } } } @@ -1348,6 +1364,8 @@ void QDeclarativePathView::refill() if (QDeclarativePathViewAttached *att = d->attached(d->highlightItem)) att->setOnPath(currentVisible); } + while (d->itemCache.count()) + d->releaseItem(d->itemCache.takeLast()); } void QDeclarativePathView::itemsInserted(int modelIndex, int count) @@ -1357,16 +1375,25 @@ void QDeclarativePathView::itemsInserted(int modelIndex, int count) if (!d->isValid() || !isComponentComplete()) return; - QList<QDeclarativeItem *> removedItems = d->items; + d->itemCache += d->items; d->items.clear(); if (modelIndex <= d->currentIndex) { d->currentIndex += count; emit currentIndexChanged(); + } else if (d->offset != 0) { + d->offset += count; + d->offsetAdj += count; + } + + d->modelCount = d->model->count(); + if (d->flicking || d->moving) { + d->regenerate(); + d->updateCurrent(); + } else { + d->firstIndex = -1; + d->updateMappedRange(); + d->scheduleLayout(); } - d->regenerate(); - while (removedItems.count()) - d->releaseItem(removedItems.takeLast()); - d->updateCurrent(); emit countChanged(); } @@ -1374,7 +1401,7 @@ void QDeclarativePathView::itemsRemoved(int modelIndex, int count) { //XXX support animated removal Q_D(QDeclarativePathView); - if (!d->isValid() || !isComponentComplete()) + if (!d->model || !d->modelCount || !d->model->isValid() || !d->path || !isComponentComplete()) return; // fix current @@ -1384,7 +1411,7 @@ void QDeclarativePathView::itemsRemoved(int modelIndex, int count) currentChanged = true; } else if (d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count) { // current item has been removed. - d->currentIndex = qMin(modelIndex, d->model->count()-1); + d->currentIndex = qMin(modelIndex, d->modelCount-1); if (d->currentItem) { if (QDeclarativePathViewAttached *att = d->attached(d->currentItem)) att->setIsCurrentItem(true); @@ -1392,15 +1419,21 @@ void QDeclarativePathView::itemsRemoved(int modelIndex, int count) currentChanged = true; } - QList<QDeclarativeItem *> removedItems = d->items; + d->itemCache += d->items; d->items.clear(); - if (d->offset >= d->model->count()) - d->offset = d->model->count() - 1; + if (modelIndex > d->currentIndex) { + if (d->offset >= count) { + d->offset -= count; + d->offsetAdj -= count; + } + } + + d->modelCount = d->model->count(); d->regenerate(); - while (removedItems.count()) - d->releaseItem(removedItems.takeLast()); d->updateCurrent(); + if (!d->modelCount) + update(); if (currentChanged) emit currentIndexChanged(); emit countChanged(); @@ -1431,6 +1464,7 @@ void QDeclarativePathView::itemsMoved(int /*from*/, int /*to*/, int /*count*/) void QDeclarativePathView::modelReset() { Q_D(QDeclarativePathView); + d->modelCount = d->model->count(); d->regenerate(); emit countChanged(); } @@ -1488,11 +1522,11 @@ int QDeclarativePathViewPrivate::calcCurrentIndex() { int current = -1; if (model && items.count()) { - offset = qmlMod(offset, model->count()); + offset = qmlMod(offset, modelCount); if (offset < 0) - offset += model->count(); - current = qRound(qAbs(qmlMod(model->count() - offset, model->count()))); - current = current % model->count(); + offset += modelCount; + current = qRound(qAbs(qmlMod(modelCount - offset, modelCount))); + current = current % modelCount; } return current; @@ -1508,7 +1542,7 @@ void QDeclarativePathViewPrivate::updateCurrent() int idx = calcCurrentIndex(); if (model && idx != currentIndex) { - int itemIndex = (currentIndex - firstIndex + model->count()) % model->count(); + int itemIndex = (currentIndex - firstIndex + modelCount) % modelCount; if (itemIndex < items.count()) { if (QDeclarativeItem *item = items.at(itemIndex)) { if (QDeclarativePathViewAttached *att = attached(item)) @@ -1517,7 +1551,7 @@ void QDeclarativePathViewPrivate::updateCurrent() } currentIndex = idx; currentItem = 0; - itemIndex = (idx - firstIndex + model->count()) % model->count(); + itemIndex = (idx - firstIndex + modelCount) % modelCount; if (itemIndex < items.count()) { currentItem = items.at(itemIndex); currentItem->setFocus(true); @@ -1549,25 +1583,26 @@ void QDeclarativePathViewPrivate::fixOffset() void QDeclarativePathViewPrivate::snapToCurrent() { - if (!model || model->count() <= 0) + if (!model || modelCount <= 0) return; - qreal targetOffset = model->count() - currentIndex; + qreal targetOffset = modelCount - currentIndex; moveReason = Other; + offsetAdj = 0.0; tl.reset(moveOffset); moveOffset.setValue(offset); const int duration = highlightMoveDuration; - if (targetOffset - offset > model->count()/2) { - qreal distance = model->count() - targetOffset + offset; + if (targetOffset - offset > modelCount/2) { + qreal distance = modelCount - targetOffset + offset; tl.move(moveOffset, 0.0, QEasingCurve(QEasingCurve::InQuad), int(duration * offset / distance)); - tl.set(moveOffset, model->count()); - tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::OutQuad), int(duration * (model->count()-targetOffset) / distance)); - } else if (targetOffset - offset <= -model->count()/2) { - qreal distance = model->count() - offset + targetOffset; - tl.move(moveOffset, model->count(), QEasingCurve(QEasingCurve::InQuad), int(duration * (model->count()-offset) / distance)); + tl.set(moveOffset, modelCount); + tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::OutQuad), int(duration * (modelCount-targetOffset) / distance)); + } else if (targetOffset - offset <= -modelCount/2) { + qreal distance = modelCount - offset + targetOffset; + tl.move(moveOffset, modelCount, QEasingCurve(QEasingCurve::InQuad), int(duration * (modelCount-offset) / distance)); tl.set(moveOffset, 0.0); tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::OutQuad), int(duration * targetOffset / distance)); } else { diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p.h index 035a64b..62a8c44 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview_p.h +++ b/src/declarative/graphicsitems/qdeclarativepathview_p.h @@ -226,6 +226,7 @@ public: emit pathChanged(); } } + qreal m_percent; Q_SIGNALS: void currentItemChanged(); diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h index 9abec2e..dfebe35 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h @@ -75,19 +75,19 @@ class QDeclarativePathViewPrivate : public QDeclarativeItemPrivate, public QDecl public: QDeclarativePathViewPrivate() : path(0), currentIndex(0), currentItemOffset(0.0), startPc(0), lastDist(0) - , lastElapsed(0), mappedRange(1.0) + , lastElapsed(0), offset(0.0), offsetAdj(0.0), mappedRange(1.0) , stealMouse(false), ownModel(false), interactive(true), haveHighlightRange(true) , autoHighlight(true), highlightUp(false), layoutScheduled(false) , moving(false), flicking(false) , dragMargin(0), deceleration(100) - , moveOffset(this, &QDeclarativePathViewPrivate::setOffset) + , moveOffset(this, &QDeclarativePathViewPrivate::setAdjustedOffset) , firstIndex(-1), pathItems(-1), requestedIndex(-1) , moveReason(Other), attType(0), highlightComponent(0), highlightItem(0) , moveHighlight(this, &QDeclarativePathViewPrivate::setHighlightPosition) , highlightPosition(0) , highlightRangeStart(0), highlightRangeEnd(0) , highlightRangeMode(QDeclarativePathView::StrictlyEnforceRange) - , highlightMoveDuration(300) + , highlightMoveDuration(300), modelCount(0) { } @@ -96,6 +96,8 @@ public: void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) { if ((newGeometry.size() != oldGeometry.size()) && (!highlightItem || item != highlightItem)) { + if (QDeclarativePathViewAttached *att = attached(item)) + att->m_percent = -1; scheduleLayout(); } } @@ -126,6 +128,7 @@ public: static void fixOffsetCallback(void*); void fixOffset(); void setOffset(qreal offset); + void setAdjustedOffset(qreal offset); void regenerate(); void updateItem(QDeclarativeItem *, qreal); void snapToCurrent(); @@ -140,6 +143,7 @@ public: qreal lastDist; int lastElapsed; qreal offset; + qreal offsetAdj; qreal mappedRange; bool stealMouse : 1; bool ownModel : 1; @@ -160,6 +164,7 @@ public: int pathItems; int requestedIndex; QList<QDeclarativeItem *> items; + QList<QDeclarativeItem *> itemCache; QDeclarativeGuard<QDeclarativeVisualModel> model; QVariant modelVariant; enum MovementReason { Other, SetIndex, Mouse }; @@ -173,6 +178,7 @@ public: qreal highlightRangeEnd; QDeclarativePathView::HighlightRangeMode highlightRangeMode; int highlightMoveDuration; + int modelCount; }; QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 61ea9c8..e55dc92 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -1764,9 +1764,7 @@ bool QDeclarativeCompiler::buildGroupedProperty(QDeclarativeParser::Property *pr Q_ASSERT(prop->index != -1); if (QDeclarativeValueTypeFactory::isValueType(prop->type)) { - QDeclarativeEnginePrivate *ep = - static_cast<QDeclarativeEnginePrivate *>(QObjectPrivate::get(engine)); - if (prop->type >= 0 /* QVariant == -1 */ && ep->valueTypes[prop->type]) { + if (prop->type >= 0 /* QVariant == -1 */ && enginePrivate->valueTypes[prop->type]) { if (prop->values.count()) { if (prop->values.at(0)->location < prop->value->location) { @@ -1780,7 +1778,7 @@ bool QDeclarativeCompiler::buildGroupedProperty(QDeclarativeParser::Property *pr COMPILE_EXCEPTION(prop, tr( "Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop->name))); } - COMPILE_CHECK(buildValueTypeProperty(ep->valueTypes[prop->type], + COMPILE_CHECK(buildValueTypeProperty(enginePrivate->valueTypes[prop->type], prop->value, obj, ctxt.incr())); obj->addValueTypeProperty(prop); } else { @@ -2211,7 +2209,7 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj) if (propName.at(0).isUpper()) COMPILE_EXCEPTION(&prop, tr("Property names cannot begin with an upper case letter")); - if (QDeclarativeEnginePrivate::get(engine)->globalClass->illegalNames().contains(propName)) + if (enginePrivate->globalClass->illegalNames().contains(propName)) COMPILE_EXCEPTION(&prop, tr("Illegal property name")); propNames.insert(prop.name); @@ -2224,7 +2222,7 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj) QString nameStr = QString::fromUtf8(name); if (nameStr.at(0).isUpper()) COMPILE_EXCEPTION(obj, tr("Signal names cannot begin with an upper case letter")); - if (QDeclarativeEnginePrivate::get(engine)->globalClass->illegalNames().contains(nameStr)) + if (enginePrivate->globalClass->illegalNames().contains(nameStr)) COMPILE_EXCEPTION(obj, tr("Illegal signal name")); methodNames.insert(name); } @@ -2235,7 +2233,7 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj) QString nameStr = QString::fromUtf8(name); if (nameStr.at(0).isUpper()) COMPILE_EXCEPTION(obj, tr("Method names cannot begin with an upper case letter")); - if (QDeclarativeEnginePrivate::get(engine)->globalClass->illegalNames().contains(nameStr)) + if (enginePrivate->globalClass->illegalNames().contains(nameStr)) COMPILE_EXCEPTION(obj, tr("Illegal method name")); methodNames.insert(name); } diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp index 6e6f0cb..845b3da 100644 --- a/src/declarative/util/qdeclarativestateoperations.cpp +++ b/src/declarative/util/qdeclarativestateoperations.cpp @@ -1427,6 +1427,7 @@ void QDeclarativeAnchorChanges::clearBindings() if (!d->target) return; + //### should this (saving "from" values) be moved to saveCurrentValues()? d->fromX = d->target->x(); d->fromY = d->target->y(); d->fromWidth = d->target->width(); @@ -1486,22 +1487,8 @@ void QDeclarativeAnchorChanges::rewind() return; QDeclarativeItemPrivate *targetPrivate = QDeclarativeItemPrivate::get(d->target); - //restore previous anchors - if (d->rewindLeft.anchorLine != QDeclarativeAnchorLine::Invalid) - targetPrivate->anchors()->setLeft(d->rewindLeft); - if (d->rewindRight.anchorLine != QDeclarativeAnchorLine::Invalid) - targetPrivate->anchors()->setRight(d->rewindRight); - if (d->rewindHCenter.anchorLine != QDeclarativeAnchorLine::Invalid) - targetPrivate->anchors()->setHorizontalCenter(d->rewindHCenter); - if (d->rewindTop.anchorLine != QDeclarativeAnchorLine::Invalid) - targetPrivate->anchors()->setTop(d->rewindTop); - if (d->rewindBottom.anchorLine != QDeclarativeAnchorLine::Invalid) - targetPrivate->anchors()->setBottom(d->rewindBottom); - if (d->rewindVCenter.anchorLine != QDeclarativeAnchorLine::Invalid) - targetPrivate->anchors()->setVerticalCenter(d->rewindVCenter); - if (d->rewindBaseline.anchorLine != QDeclarativeAnchorLine::Invalid) - targetPrivate->anchors()->setBaseline(d->rewindBaseline); + //restore previous values (but not previous bindings, i.e. anchors) d->target->setX(d->rewindX); d->target->setY(d->rewindY); if (targetPrivate->widthValid) { diff --git a/src/declarative/util/qdeclarativetransitionmanager.cpp b/src/declarative/util/qdeclarativetransitionmanager.cpp index 9f198e4..d82c4bb 100644 --- a/src/declarative/util/qdeclarativetransitionmanager.cpp +++ b/src/declarative/util/qdeclarativetransitionmanager.cpp @@ -176,7 +176,7 @@ void QDeclarativeTransitionManager::transition(const QList<QDeclarativeAction> & if (action.event->isReversable()) { action.event->clearBindings(); action.event->rewind(); - action.event->clearBindings(); + action.event->clearBindings(); //### shouldn't be needed } continue; } |