From e4648700e7e3c84c61d6b012f7d480394b889c31 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 11 Sep 2009 15:48:20 +1000 Subject: Fix moving an item to the first visible position. Also fix the type of some properties/variables. --- src/declarative/fx/qfxlistview.cpp | 32 ++++++++++++++++---------------- src/declarative/fx/qfxlistview.h | 6 +++--- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 6596735..ac9b6ca 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -172,11 +172,11 @@ public: QFxListViewPrivate() : model(0), currentItem(0), tmpCurrent(0), orient(Qt::Vertical) , visiblePos(0), visibleIndex(0) - , averageSize(100), currentIndex(-1), requestedIndex(-1) + , averageSize(100.0), currentIndex(-1), requestedIndex(-1) , currItemMode(QFxListView::Free), snapPos(0), highlightComponent(0), highlight(0), trackedItem(0) - , moveReason(Other), buffer(0), highlightPosAnimator(0), highlightSizeAnimator(0), spacing(0) + , moveReason(Other), buffer(0), highlightPosAnimator(0), highlightSizeAnimator(0), spacing(0.0) , ownModel(false), wrap(false), autoHighlight(true) - , fixCurrentVisibility(false) {} + {} void init(); void clear(); @@ -205,7 +205,7 @@ public: else q->setViewportX(pos); } - int size() const { + qreal size() const { Q_Q(const QFxListView); return orient == Qt::Vertical ? q->height() : q->width(); } @@ -384,12 +384,11 @@ public: QmlEaseFollow *highlightSizeAnimator; QString sectionExpression; QString currentSection; - int spacing; + qreal spacing; - int ownModel : 1; - int wrap : 1; - int autoHighlight : 1; - int fixCurrentVisibility : 1; + bool ownModel : 1; + bool wrap : 1; + bool autoHighlight : 1; }; void QFxListViewPrivate::init() @@ -755,7 +754,6 @@ void QFxListViewPrivate::updateCurrent(int modelIndex) FxListItem *oldCurrentItem = currentItem; currentIndex = modelIndex; currentItem = createItem(modelIndex); - fixCurrentVisibility = true; if (oldCurrentItem && (!currentItem || oldCurrentItem->item != currentItem->item)) oldCurrentItem->attached->setIsCurrentItem(false); if (currentItem) { @@ -1149,13 +1147,13 @@ void QFxListView::setSnapPosition(int pos) This property holds the spacing to leave between items. */ -int QFxListView::spacing() const +qreal QFxListView::spacing() const { Q_D(const QFxListView); return d->spacing; } -void QFxListView::setSpacing(int spacing) +void QFxListView::setSpacing(qreal spacing) { Q_D(QFxListView); if (spacing != d->spacing) { @@ -1640,6 +1638,7 @@ void QFxListView::destroyRemoved() void QFxListView::itemsMoved(int from, int to, int count) { Q_D(QFxListView); + qreal firstItemPos = d->visibleItems.first()->position(); QHash moved; int moveBy = 0; @@ -1653,11 +1652,9 @@ void QFxListView::itemsMoved(int from, int to, int count) moveBy += item->size(); it = d->visibleItems.erase(it); } else { - if (item->index > from && item->index != -1) { - // move everything after the moved items. + // move everything after the moved items. + if (item->index > from && item->index != -1) item->index -= count; - item->setPosition(item->position()-moveBy); - } ++it; } } @@ -1698,6 +1695,9 @@ void QFxListView::itemsMoved(int from, int to, int count) while (moved.count()) d->releaseItem(moved.take(moved.begin().key())); + // Ensure we don't cause an ugly list scroll. + d->visibleItems.first()->setPosition(firstItemPos); + d->layout(); } diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h index 4a124cb..095c27b 100644 --- a/src/declarative/fx/qfxlistview.h +++ b/src/declarative/fx/qfxlistview.h @@ -73,7 +73,7 @@ class Q_DECLARATIVE_EXPORT QFxListView : public QFxFlickable Q_PROPERTY(bool autoHighlight READ autoHighlight WRITE setAutoHighlight) //### highlightFollowsCurrentItem Q_PROPERTY(CurrentItemPositioning currentItemPositioning READ currentItemPositioning WRITE setCurrentItemPositioning) //### mode Q_PROPERTY(int snapPosition READ snapPosition WRITE setSnapPosition) - Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) //### qreal + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) Q_PROPERTY(bool wrap READ isWrapEnabled WRITE setWrapEnabled) //### keyNavigationWraps, stops at end when held Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) @@ -115,8 +115,8 @@ public: int snapPosition() const; void setSnapPosition(int pos); - int spacing() const; - void setSpacing(int spacing); + qreal spacing() const; + void setSpacing(qreal spacing); Qt::Orientation orientation() const; void setOrientation(Qt::Orientation); -- cgit v0.12