src/hbwidgets/itemviews/hbgridview.cpp
changeset 23 e6ad4ef83b23
parent 6 c3690ec91ef8
child 28 b7da29130b0e
--- a/src/hbwidgets/itemviews/hbgridview.cpp	Wed Aug 18 10:05:37 2010 +0300
+++ b/src/hbwidgets/itemviews/hbgridview.cpp	Thu Sep 02 20:44:51 2010 +0300
@@ -120,11 +120,11 @@
 {
     Q_D(HbGridView);
 
-    d->mVisibleIndex = d->indexInTheCenter();
+    d->mVisibleIndex = d->firstFullyVisibleIndex();
 
     d->itemContainer()->setRowCount(rowCount);
 
-    scrollTo(d->mVisibleIndex, HbAbstractItemView::PositionAtCenter);
+    scrollTo(d->mVisibleIndex, HbAbstractItemView::PositionAtTop);
 }
 
 /*!
@@ -147,11 +147,11 @@
 {
     Q_D(HbGridView);
 
-    d->mVisibleIndex = d->indexInTheCenter();
+    d->mVisibleIndex = d->firstFullyVisibleIndex();
 
     d->itemContainer()->setColumnCount(columnCount);
 
-    scrollTo(d->mVisibleIndex, HbAbstractItemView::PositionAtCenter);
+    scrollTo(d->mVisibleIndex, HbAbstractItemView::PositionAtTop);
 }
 
 
@@ -279,7 +279,7 @@
 void HbGridView::orientationAboutToBeChanged()
 {
     Q_D(HbGridView);
-    d->mVisibleIndex = d->indexInTheCenter();
+    d->mVisibleIndex = d->firstFullyVisibleIndex();
 }
 
 /*!
@@ -291,10 +291,21 @@
     d->mContainer->setPos(0,0);
     if (d->mSwapDimensionsOnOrientationChange) {
         d->itemContainer()->orientationChanged(newOrientation);
+        int indexPosition = d->mModelIterator->indexPosition(d->mVisibleIndex);
+        int columnsCount = 0;
+        if (d->mScrollDirections == Qt::Vertical) {
+            columnsCount = columnCount();
+        } else {
+            columnsCount = rowCount();
+        }
+        int remainder = indexPosition % columnsCount;
+        if (remainder > columnsCount / 2) {
+            d->mVisibleIndex = d->mModelIterator->index(indexPosition + columnsCount - remainder);
+        }
     }
 
     // abstract part is enough - container update buffer
-    HbAbstractItemView::scrollTo(d->mVisibleIndex, HbAbstractItemView::PositionAtCenter);
+    HbAbstractItemView::scrollTo(d->mVisibleIndex, HbAbstractItemView::PositionAtTop);
 
     d->mVisibleIndex = QModelIndex();
 }
@@ -395,13 +406,12 @@
 {
     Q_D(HbGridView);
     // scroll direction changed, calculations need to be done on old value
-    d->mVisibleIndex = d->indexInTheCenter((d->mScrollDirections == Qt::Vertical) 
-        ? Qt::Horizontal : Qt::Vertical);
+    d->mVisibleIndex = d->firstFullyVisibleIndex();
     d->mContainer->setPos(0,0);
     d->itemContainer()->scrollDirectionChanged(scrollDirection);
 
     // abstract part is enough - container update buffer
-    HbAbstractItemView::scrollTo(d->mVisibleIndex, HbAbstractItemView::PositionAtCenter);
+    HbAbstractItemView::scrollTo(d->mVisibleIndex, HbAbstractItemView::PositionAtTop);
 
     d->mVisibleIndex = QModelIndex();
 }