summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems
diff options
context:
space:
mode:
authorA-Team <ateam@pad.test.qt.nokia.com>2010-09-07 12:31:14 (GMT)
committerA-Team <ateam@pad.test.qt.nokia.com>2010-09-07 12:31:14 (GMT)
commit30cf45cf53e030158fef4dfb262e7444332d3138 (patch)
tree3bfe9133feb8d1505b6e394e791a348cdf4d475f /src/declarative/graphicsitems
parentd52f0887a740d147a74c3e38ae587f688fbf896a (diff)
parent3505c6cdcdfac5a6d0f4b94dbdbcc8ad72f8048a (diff)
downloadQt-30cf45cf53e030158fef4dfb262e7444332d3138.zip
Qt-30cf45cf53e030158fef4dfb262e7444332d3138.tar.gz
Qt-30cf45cf53e030158fef4dfb262e7444332d3138.tar.bz2
Merge branch '4.7-oslo1' into 4.7-doc
Diffstat (limited to 'src/declarative/graphicsitems')
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimagebase.cpp12
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview.cpp81
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview.cpp285
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview_p.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview_p_p.h12
-rw-r--r--src/declarative/graphicsitems/qdeclarativepositioners.cpp48
6 files changed, 261 insertions, 178 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 ef28ab2..2eae0af 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;
@@ -2916,14 +2957,18 @@ void QDeclarativeListView::itemsRemoved(int modelIndex, int count)
}
if (removedVisible && d->visibleItems.isEmpty()) {
- d->visibleIndex = 0;
- d->visiblePos = d->header ? d->header->size() : 0;
d->timeline.clear();
- d->setPosition(0);
if (d->itemCount == 0) {
+ d->visibleIndex = 0;
+ d->visiblePos = d->header ? d->header->size() : 0;
+ d->setPosition(0);
d->updateHeader();
d->updateFooter();
update();
+ } else {
+ if (modelIndex < d->visibleIndex)
+ d->visibleIndex = modelIndex+1;
+ d->visibleIndex = qMax(qMin(d->visibleIndex, d->itemCount-1), 0);
}
}
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/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp
index b776b8e..77b26b9 100644
--- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp
@@ -247,13 +247,13 @@ void QDeclarativeBasePositioner::prePositioning()
positionedItems.append(posItem);
item = &positionedItems[positionedItems.count()-1];
item->isNew = true;
- if (child->opacity() <= 0.0 || childPrivate->explicitlyHidden)
+ if (child->opacity() <= 0.0 || childPrivate->explicitlyHidden || !childPrivate->width() || !childPrivate->height())
item->isVisible = false;
} else {
item = &oldItems[wIdx];
// Items are only omitted from positioning if they are explicitly hidden
// i.e. their positioning is not affected if an ancestor is hidden.
- if (child->opacity() <= 0.0 || childPrivate->explicitlyHidden) {
+ if (child->opacity() <= 0.0 || childPrivate->explicitlyHidden || !childPrivate->width() || !childPrivate->height()) {
item->isVisible = false;
} else if (!item->isVisible) {
item->isVisible = true;
@@ -321,12 +321,6 @@ void QDeclarativeBasePositioner::finishApplyTransitions()
d->moveActions.clear();
}
-static inline bool isInvisible(QGraphicsObject *child)
-{
- QGraphicsItemPrivate *childPrivate = static_cast<QGraphicsItemPrivate*>(QGraphicsItemPrivate::get(child));
- return child->opacity() == 0.0 || childPrivate->explicitlyHidden || !childPrivate->width() || !childPrivate->height();
-}
-
/*!
\qmlclass Column QDeclarativeColumn
\ingroup qml-positioning-elements
@@ -449,7 +443,7 @@ void QDeclarativeColumn::doPositioning(QSizeF *contentSize)
for (int ii = 0; ii < positionedItems.count(); ++ii) {
const PositionedItem &child = positionedItems.at(ii);
- if (!child.item || isInvisible(child.item))
+ if (!child.item || !child.isVisible)
continue;
if(child.item->y() != voffset)
@@ -584,7 +578,7 @@ void QDeclarativeRow::doPositioning(QSizeF *contentSize)
for (int ii = 0; ii < positionedItems.count(); ++ii) {
const PositionedItem &child = positionedItems.at(ii);
- if (!child.item || isInvisible(child.item))
+ if (!child.item || !child.isVisible)
continue;
if(child.item->x() != hoffset)
@@ -793,9 +787,17 @@ void QDeclarativeGrid::setFlow(Flow flow)
void QDeclarativeGrid::doPositioning(QSizeF *contentSize)
{
+
int c = m_columns;
int r = m_rows;
- int numVisible = positionedItems.count();
+ //Is allocating the extra QPODVector too much overhead?
+ QPODVector<PositionedItem, 8> visibleItems;//we aren't concerned with invisible items
+ visibleItems.reserve(positionedItems.count());
+ for(int i=0; i<positionedItems.count(); i++)
+ if(positionedItems[i].item && positionedItems[i].isVisible)
+ visibleItems.append(positionedItems[i]);
+
+ int numVisible = visibleItems.count();
if (m_columns <= 0 && m_rows <= 0){
c = 4;
r = (numVisible+3)/4;
@@ -816,11 +818,10 @@ void QDeclarativeGrid::doPositioning(QSizeF *contentSize)
if (i==0)
maxColWidth << 0;
- if (childIndex == positionedItems.count())
- continue;
- const PositionedItem &child = positionedItems.at(childIndex++);
- if (!child.item || isInvisible(child.item))
- continue;
+ if (childIndex == visibleItems.count())
+ break;
+
+ const PositionedItem &child = visibleItems.at(childIndex++);
QGraphicsItemPrivate *childPrivate = QGraphicsItemPrivate::get(child.item);
if (childPrivate->width() > maxColWidth[j])
maxColWidth[j] = childPrivate->width();
@@ -837,10 +838,9 @@ void QDeclarativeGrid::doPositioning(QSizeF *contentSize)
maxColWidth << 0;
if (childIndex == positionedItems.count())
- continue;
- const PositionedItem &child = positionedItems.at(childIndex++);
- if (!child.item || isInvisible(child.item))
- continue;
+ break;
+
+ const PositionedItem &child = visibleItems.at(childIndex++);
QGraphicsItemPrivate *childPrivate = QGraphicsItemPrivate::get(child.item);
if (childPrivate->width() > maxColWidth[j])
maxColWidth[j] = childPrivate->width();
@@ -854,10 +854,8 @@ void QDeclarativeGrid::doPositioning(QSizeF *contentSize)
int yoffset=0;
int curRow =0;
int curCol =0;
- for (int i = 0; i < positionedItems.count(); ++i) {
- const PositionedItem &child = positionedItems.at(i);
- if (!child.item || isInvisible(child.item))
- continue;
+ for (int i = 0; i < visibleItems.count(); ++i) {
+ const PositionedItem &child = visibleItems.at(i);
if((child.item->x()!=xoffset)||(child.item->y()!=yoffset)){
positionX(xoffset, child);
positionY(yoffset, child);
@@ -1033,7 +1031,7 @@ void QDeclarativeFlow::doPositioning(QSizeF *contentSize)
for (int i = 0; i < positionedItems.count(); ++i) {
const PositionedItem &child = positionedItems.at(i);
- if (!child.item || isInvisible(child.item))
+ if (!child.item || !child.isVisible)
continue;
QGraphicsItemPrivate *childPrivate = QGraphicsItemPrivate::get(child.item);