ganeswidgets/src/hgcontainer.cpp
changeset 11 42505cd701c6
parent 6 1cdcc61142d2
child 12 6c0ec0ccd2d4
--- a/ganeswidgets/src/hgcontainer.cpp	Thu Jul 08 15:37:35 2010 +0300
+++ b/ganeswidgets/src/hgcontainer.cpp	Fri Jul 23 10:05:37 2010 +0300
@@ -96,6 +96,7 @@
     }
 }
 
+// TODO: This does exactly the same as HgContainer::imageCount(), should this be thus removed?
 int HgContainer::itemCount() const
 {
     return mItems.count();
@@ -393,6 +394,7 @@
     scrollTo(mSelectionModel->currentIndex());
 }
 
+// TODO: This does exactly the same as HgContainer::itemCount(), should this be thus removed?
 int HgContainer::imageCount() const
 {
     return mItems.count();
@@ -611,14 +613,12 @@
     FUNC_LOG;
 
     qreal x = mSpring.endPos().x();
-    x = qBound(qreal(0), x, worldWidth());
     if (mRenderer->coverflowModeEnabled()) {
         qreal i = floorf(x);
         x = (x - i > 0.5f) ? ceilf(x) : i;
-        mSpring.animateToPos(QPointF(x, 0));
     }
 
-    mSpring.animateToPos(QPointF(x, 0));
+    mSpring.animateToPosAfterPanning(QPointF(x, 0), worldWidth());
 
 }
 
@@ -679,7 +679,9 @@
         mDragged = false;
         qreal newPos(0);
         if (mDrag.finish(pos, mRenderer->coverflowModeEnabled(), newPos)) {
-            mSpring.animateToPos(QPointF(qBound(qreal(0), newPos, worldWidth()), 0));
+            
+            mSpring.animateToPosAfterPanning(QPointF(newPos, 0), worldWidth());
+            
             HgWidgetItem* item = itemByIndex(newPos);
             if (item && item->modelIndex() != mSelectionModel->currentIndex()) {
             //    mSelectionModel->setCurrentIndex(item->modelIndex(), QItemSelectionModel::Current);
@@ -707,7 +709,7 @@
     FUNC_LOG;
     
     bool handleGesture = false;
-
+    
     if (hasItemAt(pos)) {
         switch (state) 
             {
@@ -717,7 +719,29 @@
                     mIgnoreGestureAction = false;
                     startLongPressWatcher(pos);
                 } else if(mSpring.isActive()) {
-                    mSpring.cancel();
+                    
+                    int rowCount = mRenderer->getRowCount();
+                    if(rowCount != 0)   //just in case, should not be zero 
+                    {
+                        qreal springPos = mSpring.pos().x();
+                        int gridTotalHeightInImages = ceilf( mItems.count() / rowCount );
+                        qreal currentViewHeightInImages;
+                        if (scrollDirection() == Qt::Horizontal ) {
+                            int rowHeight = mRenderer->getImageSize().width() + mRenderer->getSpacing().width();
+                            currentViewHeightInImages = rect().width() / rowHeight;
+                        } else {
+                            int rowHeight = mRenderer->getImageSize().height() + mRenderer->getSpacing().height();
+                            currentViewHeightInImages = rect().height() / rowHeight;
+                        }
+                        
+                        // If list does not currently fill the whole screen (some theme background behind the list
+                        // is visible), and list is moving, then do not react to tapping.
+                        if( springPos >= 0 
+                            && springPos <= (gridTotalHeightInImages - currentViewHeightInImages) )
+                        {
+                            mSpring.cancel();
+                        }
+                    }
                     mIgnoreGestureAction = true;
                 }
                 break;
@@ -733,7 +757,7 @@
         
         handleGesture = true;
     } else {
-       mIgnoreGestureAction = true;
+        mIgnoreGestureAction = true;
     }    
     return handleGesture;
 }