aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2012-07-26 13:14:50 +1000
committerQt by Nokia <qt-info@nokia.com>2012-07-27 03:08:24 +0200
commit3a045419ba588107d7730978c14643d68340f24b (patch)
tree2d9d84b06b4ae762dfc46a5bfbea5ee31f560e8d /src/quick
parent4dcd5ae1e27252755a51dec139269bc4f998adb4 (diff)
Add SnapPosition mode to positionViewAtIndex() in List/GridView.
This allows the view to be positioned on a snap boundary, which is generally what is wanted when strict highlight mode s set or snapping is enabled. Task-number: QTBUG-26605 Change-Id: I6288dc8be4ff16c412b56ab449b6a9fb7b7ea889 Reviewed-by: Bea Lam <bea.lam@nokia.com>
Diffstat (limited to 'src/quick')
-rw-r--r--src/quick/items/qquickgridview.cpp3
-rw-r--r--src/quick/items/qquickitemview.cpp26
-rw-r--r--src/quick/items/qquickitemview_p.h2
-rw-r--r--src/quick/items/qquicklistview.cpp3
4 files changed, 32 insertions, 2 deletions
diff --git a/src/quick/items/qquickgridview.cpp b/src/quick/items/qquickgridview.cpp
index 8f330b9031..518692a813 100644
--- a/src/quick/items/qquickgridview.cpp
+++ b/src/quick/items/qquickgridview.cpp
@@ -2490,6 +2490,9 @@ bool QQuickGridViewPrivate::needsRefillForAddedOrRemovedIndex(int modelIndex) co
bring the item into view.
\li GridView.Contain - ensure the entire item is visible. If the item is larger than
the view the item is positioned at the top (or left for \c GridView.TopToBottom flow) of the view.
+ \li GridView.SnapPosition - position the item at \l preferredHighlightBegin. This mode
+ is only valid if \l highlightRangeMode is StrictlyEnforceRange or snapping is enabled
+ via \l snapMode.
\endlist
If positioning the view at the index would cause empty space to be displayed at
diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp
index 8f1687f4e6..240027e312 100644
--- a/src/quick/items/qquickitemview.cpp
+++ b/src/quick/items/qquickitemview.cpp
@@ -613,6 +613,10 @@ void QQuickItemView::setHighlightRangeMode(HighlightRangeMode mode)
return;
d->highlightRange = mode;
d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd;
+ if (isComponentComplete()) {
+ d->updateViewport();
+ d->fixupPosition();
+ }
emit highlightRangeModeChanged();
}
@@ -631,6 +635,10 @@ void QQuickItemView::setPreferredHighlightBegin(qreal start)
return;
d->highlightRangeStart = start;
d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd;
+ if (isComponentComplete()) {
+ d->updateViewport();
+ d->fixupPosition();
+ }
emit preferredHighlightBeginChanged();
}
@@ -641,6 +649,10 @@ void QQuickItemView::resetPreferredHighlightBegin()
if (d->highlightRangeStart == 0)
return;
d->highlightRangeStart = 0;
+ if (isComponentComplete()) {
+ d->updateViewport();
+ d->fixupPosition();
+ }
emit preferredHighlightBeginChanged();
}
@@ -658,6 +670,10 @@ void QQuickItemView::setPreferredHighlightEnd(qreal end)
return;
d->highlightRangeEnd = end;
d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd;
+ if (isComponentComplete()) {
+ d->updateViewport();
+ d->fixupPosition();
+ }
emit preferredHighlightEndChanged();
}
@@ -668,6 +684,10 @@ void QQuickItemView::resetPreferredHighlightEnd()
if (d->highlightRangeEnd == 0)
return;
d->highlightRangeEnd = 0;
+ if (isComponentComplete()) {
+ d->updateViewport();
+ d->fixupPosition();
+ }
emit preferredHighlightEndChanged();
}
@@ -819,7 +839,7 @@ void QQuickItemViewPrivate::positionViewAtIndex(int index, int mode)
Q_Q(QQuickItemView);
if (!isValid())
return;
- if (mode < QQuickItemView::Beginning || mode > QQuickItemView::Contain)
+ if (mode < QQuickItemView::Beginning || mode > QQuickItemView::SnapPosition)
return;
applyPendingChanges();
@@ -871,6 +891,10 @@ void QQuickItemViewPrivate::positionViewAtIndex(int index, int mode)
pos = itemPos - size() + item->size();
if (itemPos < pos)
pos = itemPos;
+ break;
+ case QQuickItemView::SnapPosition:
+ pos = itemPos - highlightRangeStart;
+ break;
}
pos = qMin(pos, maxExtent);
qreal minExtent;
diff --git a/src/quick/items/qquickitemview_p.h b/src/quick/items/qquickitemview_p.h
index e1cb02070d..75d573c930 100644
--- a/src/quick/items/qquickitemview_p.h
+++ b/src/quick/items/qquickitemview_p.h
@@ -199,7 +199,7 @@ public:
int highlightMoveDuration() const;
virtual void setHighlightMoveDuration(int);
- enum PositionMode { Beginning, Center, End, Visible, Contain };
+ enum PositionMode { Beginning, Center, End, Visible, Contain, SnapPosition };
Q_INVOKABLE void positionViewAtIndex(int index, int mode);
Q_INVOKABLE int indexAt(qreal x, qreal y) const;
diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp
index 18b994733e..61574ee1b1 100644
--- a/src/quick/items/qquicklistview.cpp
+++ b/src/quick/items/qquicklistview.cpp
@@ -3031,6 +3031,9 @@ void QQuickListViewPrivate::translateAndTransitionItemsAfter(int afterModelIndex
bring the item into view.
\li ListView.Contain - ensure the entire item is visible. If the item is larger than
the view the item is positioned at the top (or left for horizontal orientation) of the view.
+ \li ListView.SnapPosition - position the item at \l preferredHighlightBegin. This mode
+ is only valid if \l highlightRangeMode is StrictlyEnforceRange or snapping is enabled
+ via \l snapMode.
\endlist
If positioning the view at \a index would cause empty space to be displayed at