diff options
author | Adriano Rezende <adriano.rezende@openbossa.org> | 2009-11-16 14:14:42 -0300 |
---|---|---|
committer | Adriano Rezende <adriano.rezende@openbossa.org> | 2009-11-16 14:56:05 -0300 |
commit | 522f9d72ff67d6c34aad68010fec6bd6d10712f7 (patch) | |
tree | f3f091f67fdc7a6014517ed0b229a3b9bcc34a5c | |
parent | cbd5d281e051fff81d9e3fa3acf4a4f7725dccb4 (diff) |
Shared: Added maximum offset changed signal
Signed-off-by: Adriano Rezende <adriano.rezende@openbossa.org>
-rw-r--r-- | shared/listview.cpp | 35 | ||||
-rw-r--r-- | shared/listview.h | 1 |
2 files changed, 28 insertions, 8 deletions
diff --git a/shared/listview.cpp b/shared/listview.cpp index feac60d..ae109ac 100644 --- a/shared/listview.cpp +++ b/shared/listview.cpp @@ -172,6 +172,8 @@ public: void repositionRenderers(); bool setPixelPosition(int value); int visibleItemCount(); + void setMaximumOffset(int value); + void updateMaximumOffset(); int totalCount() const { return !model ? 0 : model->count(); } @@ -179,6 +181,7 @@ public: int currentItem; int offset; + int maximumOffset; int spareRenderers; AbstractModel *model; @@ -193,6 +196,7 @@ private: ListViewPrivate::ListViewPrivate(ListView *qptr) : itemSpace(50), currentItem(0), + maximumOffset(0), spareRenderers(2), model(0), creator(0), @@ -349,6 +353,23 @@ int ListViewPrivate::visibleItemCount() return qMax(r - spareRenderers, 0); } +void ListViewPrivate::setMaximumOffset(int value) +{ + value = qMax(value, 0); + if (maximumOffset != value) { + maximumOffset = value; + emit q->maximumOffsetChanged(); + } +} + +void ListViewPrivate::updateMaximumOffset() +{ + if (totalCount() == 0) + setMaximumOffset(0); + else + setMaximumOffset(qRound(totalCount() * itemSpace - q->size().height())); +} + ListView::ListView(QGraphicsItem *parent) @@ -424,6 +445,7 @@ void ListView::setCreator(AbstractListViewCreator *creator) if (item) { d->itemSpace = item->preferredSize().height(); delete item; + d->updateMaximumOffset(); } } } @@ -438,25 +460,19 @@ void ListView::setOffset(int position) int oldOffset = offset(); d->setPixelPosition(qBound(0, position, maximumOffset())); - // XXX: must emit also when maximum offset has changed if (oldOffset != offset()) emit offsetChanged(); } int ListView::maximumOffset() const { - if (d->totalCount() == 0) - return 0; - - const int total = d->totalCount() * d->itemSpace; - const int space = size().height(); - - return qMax(qRound(total - space), 0); + return d->maximumOffset; } void ListView::resizeEvent(QGraphicsSceneResizeEvent *event) { QGraphicsWidget::resizeEvent(event); + d->updateMaximumOffset(); d->reconfigureRenderers(); } @@ -492,6 +508,7 @@ ListViewItem *ListView::itemFromIndex(int index) void ListView::modelChanged() { d->currentItem = 0; + d->updateMaximumOffset(); setOffset(0); reconfigureRenderers(); } @@ -508,6 +525,7 @@ void ListView::itemAdded(int index) { Q_UNUSED(index); // XXX: optimize (check if it's in visible area) + d->updateMaximumOffset(); reconfigureRenderers(); } @@ -515,6 +533,7 @@ void ListView::itemRemoved(int index) { Q_UNUSED(index); // XXX: optimize (check if it's in visible area) + d->updateMaximumOffset(); reconfigureRenderers(); } diff --git a/shared/listview.h b/shared/listview.h index 594f866..374fda6 100644 --- a/shared/listview.h +++ b/shared/listview.h @@ -111,6 +111,7 @@ public: signals: void offsetChanged(); + void maximumOffsetChanged(); void itemClicked(int index); public slots: |