ganeswidgets/src/hgmediawallrenderer.cpp
changeset 13 8bf920201dea
parent 9 dde80bf4a8c7
child 19 31a1a9e11046
--- a/ganeswidgets/src/hgmediawallrenderer.cpp	Tue Jul 06 15:29:26 2010 +0300
+++ b/ganeswidgets/src/hgmediawallrenderer.cpp	Wed Aug 18 10:52:49 2010 +0300
@@ -436,7 +436,7 @@
         mNextScrollDirection = mScrollDirection;
         return;
     }
-    
+        
     if (mScrollDirection != scrollDirection)
     {
         mStateMachine->setAnimated(animate);
@@ -449,7 +449,7 @@
         {
             //emit renderingNeeded();            
         }
-    } else if (!animate) {
+    } else {
         // reset next scrolldirection just to be sure. In some cases
         // when orientation changes couple of times and container visibility changes
         // we might otherwise end up in wrong state.
@@ -661,23 +661,42 @@
 }
     
 qreal HgMediaWallRenderer::getWorldWidth() const
-{   
-    qreal width = ceil((qreal)mDataProvider->imageCount() / (qreal)mRowCount - 1.0f);
-    
+{
+    qreal worldWidth = ceil((qreal)mDataProvider->imageCount() / (qreal)mRowCount);
+    qreal worldWidthAsIndex = worldWidth - 1.0f;
+
     // if we are in vertical orientation we want last and first item
     // to place at the top and bottom of the screen instead of center
     if (mScrollDirection == Qt::Vertical)
     {
-        qreal step = mSpacing2D.height() + mImageSize2D.height(); 
-        width -= (mRect.height() / step - 1.0f);
+        qreal step = mSpacing2D.height() + mImageSize2D.height();
+        qreal screenWidth = mRect.height() / step;
+        if(worldWidth > screenWidth) //do the items take over one screenful?
+        {
+            worldWidthAsIndex -= (screenWidth - 1.0f);
+        }
+        else
+        {
+            // all items fit to one screenful
+            return 0;
+        }
     }
     else if (mScrollDirection == Qt::Horizontal && !mCoverflowMode)
     {
         qreal step = mSpacing2D.width() + mImageSize2D.width();
-        width -= (mRect.width() / step - 1.0f);
+        qreal screenWidth = mRect.width() / step;
+        if(worldWidth > screenWidth) //do the items take over one screenful?
+        {
+            worldWidthAsIndex -= (screenWidth - 1.0f);
+        }
+        else
+        {
+            // all items fit to one screenful
+            return 0;
+        }
     }
-       
-    return width;
+    
+    return worldWidthAsIndex;
 }