diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-12-01 07:27:49 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-12-01 07:27:49 (GMT) |
commit | 88ee1fa39e2f1aff0eac5503ca34274481125b8f (patch) | |
tree | 2b2b77fa49f5a01ce29977b41f860761fa7e1ff8 /src | |
parent | f36455bc3b559261c73b4f6269591a2eda8d0baa (diff) | |
download | Qt-88ee1fa39e2f1aff0eac5503ca34274481125b8f.zip Qt-88ee1fa39e2f1aff0eac5503ca34274481125b8f.tar.gz Qt-88ee1fa39e2f1aff0eac5503ca34274481125b8f.tar.bz2 |
Add header and footer to ListView.
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/graphicsitems/qmlgraphicslistview.cpp | 133 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qmlgraphicslistview_p.h | 9 |
2 files changed, 137 insertions, 5 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index 9dd2ab4..144eed7 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -178,6 +178,7 @@ public: , moveReason(Other), buffer(0), highlightPosAnimator(0), highlightSizeAnimator(0), spacing(0.0) , highlightMoveSpeed(400), highlightResizeSpeed(400), highlightRange(QmlGraphicsListView::NoHighlightRange) , snapMode(QmlGraphicsListView::NoSnap), overshootDist(0.0) + , footerComponent(0), footer(0), headerComponent(0), header(0) , ownModel(false), wrap(false), autoHighlight(true), haveHighlightRange(false) , correctFlick(true) {} @@ -209,7 +210,6 @@ public: } FxListItem *nextVisibleItem() const { - qDebug() << "last vis"; const qreal pos = position(); bool foundFirst = false; for (int i = 0; i < visibleItems.count(); ++i) { @@ -404,9 +404,9 @@ public: void updateViewport() { Q_Q(QmlGraphicsListView); if (orient == QmlGraphicsListView::Vertical) - q->setViewportHeight(endPosition() - startPosition()); + q->setViewportHeight(q->minYExtent() - q->maxYExtent()); else - q->setViewportWidth(endPosition() - startPosition()); + q->setViewportWidth(q->minXExtent() - q->maxXExtent()); } @@ -434,6 +434,8 @@ public: void updateCurrentSection(); void updateCurrent(int); void updateAverage(); + void updateHeader(); + void updateFooter(); void fixupPosition(); virtual void fixupY(); virtual void fixupX(); @@ -469,6 +471,10 @@ public: QmlGraphicsListView::HighlightRangeMode highlightRange; QmlGraphicsListView::SnapMode snapMode; qreal overshootDist; + QmlComponent *footerComponent; + FxListItem *footer; + QmlComponent *headerComponent; + FxListItem *header; bool ownModel : 1; bool wrap : 1; @@ -491,7 +497,7 @@ void QmlGraphicsListViewPrivate::clear() for (int i = 0; i < visibleItems.count(); ++i) releaseItem(visibleItems.at(i)); visibleItems.clear(); - visiblePos = 0; + visiblePos = header ? header->size() : 0; visibleIndex = 0; releaseItem(currentItem); currentItem = 0; @@ -623,6 +629,10 @@ void QmlGraphicsListViewPrivate::refill(qreal from, qreal to) updateAverage(); if (!sectionExpression.isEmpty()) updateCurrentSection(); + if (header) + updateHeader(); + if (footer) + updateFooter(); updateViewport(); } } @@ -647,6 +657,10 @@ void QmlGraphicsListViewPrivate::layout() q->refill(); updateHighlight(); fixupPosition(); + if (header) + updateHeader(); + if (footer) + updateFooter(); updateUnrequestedPositions(); updateViewport(); } @@ -860,6 +874,66 @@ void QmlGraphicsListViewPrivate::updateAverage() averageSize = sum / visibleItems.count(); } +void QmlGraphicsListViewPrivate::updateFooter() +{ + Q_Q(QmlGraphicsListView); + if (!footer && footerComponent) { + QmlGraphicsItem *item = 0; + QmlContext *context = new QmlContext(qmlContext(q)); + QObject *nobj = footerComponent->create(context); + if (nobj) { + context->setParent(nobj); + item = qobject_cast<QmlGraphicsItem *>(nobj); + if (!item) + delete nobj; + } else { + delete context; + } + if (item) { + item->setParent(q->viewport()); + item->setZValue(1); + footer = new FxListItem(item, q); + } + } + if (footer) { + if (visibleItems.count()) + footer->setPosition(endPosition()); + else + footer->setPosition(visiblePos); + } +} + +void QmlGraphicsListViewPrivate::updateHeader() +{ + Q_Q(QmlGraphicsListView); + if (!header && headerComponent) { + QmlGraphicsItem *item = 0; + QmlContext *context = new QmlContext(qmlContext(q)); + QObject *nobj = headerComponent->create(context); + if (nobj) { + context->setParent(nobj); + item = qobject_cast<QmlGraphicsItem *>(nobj); + if (!item) + delete nobj; + } else { + delete context; + } + if (item) { + item->setParent(q->viewport()); + item->setZValue(1); + header = new FxListItem(item, q); + if (visibleItems.isEmpty()) + visiblePos = header->size(); + } + } + if (header) { + if (visibleItems.count()) + header->setPosition(startPosition() - header->size()); + else + header->setPosition(0); + } +} + void QmlGraphicsListViewPrivate::fixupPosition() { if (orient == QmlGraphicsListView::Vertical) @@ -1759,6 +1833,47 @@ void QmlGraphicsListView::setSnapMode(SnapMode mode) } } +QmlComponent *QmlGraphicsListView::footer() const +{ + Q_D(const QmlGraphicsListView); + return d->footerComponent; +} + +void QmlGraphicsListView::setFooter(QmlComponent *footer) +{ + Q_D(QmlGraphicsListView); + if (d->footerComponent != footer) { + if (d->footer) { + delete d->footer; + d->footer = 0; + } + d->footerComponent = footer; + d->updateFooter(); + d->updateViewport(); + } +} + +QmlComponent *QmlGraphicsListView::header() const +{ + Q_D(const QmlGraphicsListView); + return d->headerComponent; +} + +void QmlGraphicsListView::setHeader(QmlComponent *header) +{ + Q_D(QmlGraphicsListView); + if (d->headerComponent != header) { + if (d->header) { + delete d->header; + d->header = 0; + } + d->headerComponent = header; + d->updateHeader(); + d->updateFooter(); + d->updateViewport(); + } +} + void QmlGraphicsListView::viewportMoved() { Q_D(QmlGraphicsListView); @@ -1813,6 +1928,8 @@ qreal QmlGraphicsListView::minYExtent() const if (d->orient == QmlGraphicsListView::Horizontal) return QmlGraphicsFlickable::minYExtent(); qreal extent = -d->startPosition(); + if (d->header && d->visibleItems.count()) + extent += d->header->size(); if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) extent += d->highlightRangeStart; @@ -1829,6 +1946,8 @@ qreal QmlGraphicsListView::maxYExtent() const extent = -(d->positionAt(count()-1) - d->highlightRangeEnd); else extent = -(d->endPosition() - height() + 1); + if (d->footer) + extent -= d->footer->size(); qreal minY = minYExtent(); if (extent > minY) extent = minY; @@ -1841,6 +1960,8 @@ qreal QmlGraphicsListView::minXExtent() const if (d->orient == QmlGraphicsListView::Vertical) return QmlGraphicsFlickable::minXExtent(); qreal extent = -d->startPosition(); + if (d->header) + extent += d->header->size(); if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) extent += d->highlightRangeStart; @@ -1857,6 +1978,8 @@ qreal QmlGraphicsListView::maxXExtent() const extent = -(d->positionAt(count()-1) - d->highlightRangeEnd); else extent = -(d->endPosition() - width() + 1); + if (d->footer) + extent -= d->footer->size(); qreal minX = minXExtent(); if (extent > minX) extent = minX; @@ -2221,7 +2344,7 @@ void QmlGraphicsListView::itemsRemoved(int modelIndex, int count) if (d->visibleItems.isEmpty()) { d->visibleIndex = 0; - d->visiblePos = 0; + d->visiblePos = d->header ? d->header->size() : 0; d->timeline.clear(); d->setPosition(0); if (d->model->count() == 0) diff --git a/src/declarative/graphicsitems/qmlgraphicslistview_p.h b/src/declarative/graphicsitems/qmlgraphicslistview_p.h index cc74056..241fb05 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview_p.h +++ b/src/declarative/graphicsitems/qmlgraphicslistview_p.h @@ -84,6 +84,9 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsListView : public QmlGraphicsFlickable Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode) + Q_PROPERTY(QmlComponent *header READ header WRITE setHeader) + Q_PROPERTY(QmlComponent *footer READ footer WRITE setFooter) + Q_ENUMS(HighlightRangeMode) Q_ENUMS(Orientation) Q_ENUMS(SnapMode) @@ -149,6 +152,12 @@ public: SnapMode snapMode() const; void setSnapMode(SnapMode mode); + QmlComponent *footer() const; + void setFooter(QmlComponent *); + + QmlComponent *header() const; + void setHeader(QmlComponent *); + static QmlGraphicsListViewAttached *qmlAttachedProperties(QObject *); public Q_SLOTS: |