ganeswidgets/src/hgcontainer.cpp
changeset 11 42505cd701c6
parent 6 1cdcc61142d2
child 12 6c0ec0ccd2d4
equal deleted inserted replaced
7:5ebec3429918 11:42505cd701c6
    94         HgWidgetItem* item = new HgWidgetItem(mQuadRenderer);
    94         HgWidgetItem* item = new HgWidgetItem(mQuadRenderer);
    95         mItems.append(item);
    95         mItems.append(item);
    96     }
    96     }
    97 }
    97 }
    98 
    98 
       
    99 // TODO: This does exactly the same as HgContainer::imageCount(), should this be thus removed?
    99 int HgContainer::itemCount() const
   100 int HgContainer::itemCount() const
   100 {
   101 {
   101     return mItems.count();
   102     return mItems.count();
   102 }
   103 }
   103 
   104 
   391     }
   392     }
   392     // else do nothing
   393     // else do nothing
   393     scrollTo(mSelectionModel->currentIndex());
   394     scrollTo(mSelectionModel->currentIndex());
   394 }
   395 }
   395 
   396 
       
   397 // TODO: This does exactly the same as HgContainer::itemCount(), should this be thus removed?
   396 int HgContainer::imageCount() const
   398 int HgContainer::imageCount() const
   397 {
   399 {
   398     return mItems.count();
   400     return mItems.count();
   399 }
   401 }
   400 
   402 
   609 void HgContainer::boundSpring()
   611 void HgContainer::boundSpring()
   610 {
   612 {
   611     FUNC_LOG;
   613     FUNC_LOG;
   612 
   614 
   613     qreal x = mSpring.endPos().x();
   615     qreal x = mSpring.endPos().x();
   614     x = qBound(qreal(0), x, worldWidth());
       
   615     if (mRenderer->coverflowModeEnabled()) {
   616     if (mRenderer->coverflowModeEnabled()) {
   616         qreal i = floorf(x);
   617         qreal i = floorf(x);
   617         x = (x - i > 0.5f) ? ceilf(x) : i;
   618         x = (x - i > 0.5f) ? ceilf(x) : i;
   618         mSpring.animateToPos(QPointF(x, 0));
   619     }
   619     }
   620 
   620 
   621     mSpring.animateToPosAfterPanning(QPointF(x, 0), worldWidth());
   621     mSpring.animateToPos(QPointF(x, 0));
       
   622 
   622 
   623 }
   623 }
   624 
   624 
   625 bool HgContainer::handlePanning(QPanGesture *gesture)
   625 bool HgContainer::handlePanning(QPanGesture *gesture)
   626 {
   626 {
   677     else if (mDragged && gesture->state() == Qt::GestureFinished) {
   677     else if (mDragged && gesture->state() == Qt::GestureFinished) {
   678         mDrag.update(delta, pos, itemSide);
   678         mDrag.update(delta, pos, itemSide);
   679         mDragged = false;
   679         mDragged = false;
   680         qreal newPos(0);
   680         qreal newPos(0);
   681         if (mDrag.finish(pos, mRenderer->coverflowModeEnabled(), newPos)) {
   681         if (mDrag.finish(pos, mRenderer->coverflowModeEnabled(), newPos)) {
   682             mSpring.animateToPos(QPointF(qBound(qreal(0), newPos, worldWidth()), 0));
   682             
       
   683             mSpring.animateToPosAfterPanning(QPointF(newPos, 0), worldWidth());
       
   684             
   683             HgWidgetItem* item = itemByIndex(newPos);
   685             HgWidgetItem* item = itemByIndex(newPos);
   684             if (item && item->modelIndex() != mSelectionModel->currentIndex()) {
   686             if (item && item->modelIndex() != mSelectionModel->currentIndex()) {
   685             //    mSelectionModel->setCurrentIndex(item->modelIndex(), QItemSelectionModel::Current);
   687             //    mSelectionModel->setCurrentIndex(item->modelIndex(), QItemSelectionModel::Current);
   686             }
   688             }
   687         }
   689         }
   705 bool HgContainer::handleTap(Qt::GestureState state, const QPointF &pos)
   707 bool HgContainer::handleTap(Qt::GestureState state, const QPointF &pos)
   706 {
   708 {
   707     FUNC_LOG;
   709     FUNC_LOG;
   708     
   710     
   709     bool handleGesture = false;
   711     bool handleGesture = false;
   710 
   712     
   711     if (hasItemAt(pos)) {
   713     if (hasItemAt(pos)) {
   712         switch (state) 
   714         switch (state) 
   713             {
   715             {
   714             case Qt::GestureStarted:
   716             case Qt::GestureStarted:
   715                 {
   717                 {
   716                 if (mRenderer->coverflowModeEnabled() || !mSpring.isActive()) {
   718                 if (mRenderer->coverflowModeEnabled() || !mSpring.isActive()) {
   717                     mIgnoreGestureAction = false;
   719                     mIgnoreGestureAction = false;
   718                     startLongPressWatcher(pos);
   720                     startLongPressWatcher(pos);
   719                 } else if(mSpring.isActive()) {
   721                 } else if(mSpring.isActive()) {
   720                     mSpring.cancel();
   722                     
       
   723                     int rowCount = mRenderer->getRowCount();
       
   724                     if(rowCount != 0)   //just in case, should not be zero 
       
   725                     {
       
   726                         qreal springPos = mSpring.pos().x();
       
   727                         int gridTotalHeightInImages = ceilf( mItems.count() / rowCount );
       
   728                         qreal currentViewHeightInImages;
       
   729                         if (scrollDirection() == Qt::Horizontal ) {
       
   730                             int rowHeight = mRenderer->getImageSize().width() + mRenderer->getSpacing().width();
       
   731                             currentViewHeightInImages = rect().width() / rowHeight;
       
   732                         } else {
       
   733                             int rowHeight = mRenderer->getImageSize().height() + mRenderer->getSpacing().height();
       
   734                             currentViewHeightInImages = rect().height() / rowHeight;
       
   735                         }
       
   736                         
       
   737                         // If list does not currently fill the whole screen (some theme background behind the list
       
   738                         // is visible), and list is moving, then do not react to tapping.
       
   739                         if( springPos >= 0 
       
   740                             && springPos <= (gridTotalHeightInImages - currentViewHeightInImages) )
       
   741                         {
       
   742                             mSpring.cancel();
       
   743                         }
       
   744                     }
   721                     mIgnoreGestureAction = true;
   745                     mIgnoreGestureAction = true;
   722                 }
   746                 }
   723                 break;
   747                 break;
   724                 }
   748                 }
   725             case Qt::GestureFinished:
   749             case Qt::GestureFinished:
   731                 break;
   755                 break;
   732             }
   756             }
   733         
   757         
   734         handleGesture = true;
   758         handleGesture = true;
   735     } else {
   759     } else {
   736        mIgnoreGestureAction = true;
   760         mIgnoreGestureAction = true;
   737     }    
   761     }    
   738     return handleGesture;
   762     return handleGesture;
   739 }
   763 }
   740 
   764 
   741 bool HgContainer::handleLongTap(Qt::GestureState state, const QPointF &pos)
   765 bool HgContainer::handleLongTap(Qt::GestureState state, const QPointF &pos)