ganeswidgets/src/hggridcontainer.cpp
changeset 2 49c70dcc3f17
parent 1 e48454f237ca
child 3 c863538fcbb6
equal deleted inserted replaced
1:e48454f237ca 2:49c70dcc3f17
    60 }
    60 }
    61 
    61 
    62 HgMediaWallRenderer* HgGridContainer::createRenderer(Qt::Orientation scrollDirection)
    62 HgMediaWallRenderer* HgGridContainer::createRenderer(Qt::Orientation scrollDirection)
    63 {
    63 {
    64 
    64 
    65     HgMediaWallRenderer* renderer = new HgMediaWallRenderer(this, scrollDirection, false);
    65     HgMediaWallRenderer* renderer = new HgMediaWallRenderer(this, scrollDirection, scrollDirection, false);
    66     renderer->enableCoverflowMode(false);
    66     renderer->enableCoverflowMode(false);
    67     renderer->setImageSize(mUserItemSize);
    67     renderer->setImageSize(mUserItemSize);
    68     renderer->setRowCount(3, renderer->getImageSize(), false);    
    68     renderer->setRowCount(3, renderer->getImageSize(), false);    
    69     renderer->enableReflections(false);
    69     renderer->enableReflections(false);
    70     renderer->setSpacing(mUserItemSpacing);
    70     renderer->setSpacing(mUserItemSpacing);
    73     return renderer;
    73     return renderer;
    74 }
    74 }
    75 
    75 
    76 qreal HgGridContainer::getCameraDistance(qreal springVelocity)
    76 qreal HgGridContainer::getCameraDistance(qreal springVelocity)
    77 {
    77 {
    78     if (mRenderer->getOrientation() == Qt::Vertical)
    78     if (mRenderer->getScrollDirection() == Qt::Vertical)
    79         return 0;
    79         return 0;
    80     
    80     
    81     return qAbs(springVelocity * 0.01f);
    81     return qAbs(springVelocity * 0.01f);
    82 }
    82 }
    83 
    83 
    84 qreal HgGridContainer::getCameraRotationY(qreal springVelocity)
    84 qreal HgGridContainer::getCameraRotationY(qreal springVelocity)
    85 {
    85 {
    86     if (mRenderer->getOrientation() == Qt::Vertical)
    86     if (mRenderer->getScrollDirection() == Qt::Vertical)
    87         return 0;
    87         return 0;
    88 
    88 
    89     return qBound(-KCameraMaxYAngle, springVelocity * KSpringVelocityToCameraYAngleFactor, KCameraMaxYAngle);
    89     return qBound(-KCameraMaxYAngle, springVelocity * KSpringVelocityToCameraYAngleFactor, KCameraMaxYAngle);
    90 }
    90 }
    91 
    91 
    92 void HgGridContainer::handleTapAction(const QPointF& pos, HgWidgetItem* hitItem, int hitItemIndex)
    92 void HgGridContainer::handleTapAction(const QPointF& pos, HgWidgetItem* hitItem, int hitItemIndex)
    93 {
    93 {
    94     Q_UNUSED(pos)
    94     Q_UNUSED(pos)
    95     Q_UNUSED(hitItemIndex)
    95     Q_UNUSED(hitItemIndex)
    96         
    96         
    97     selectItem();                
    97     selectItem(hitItemIndex);                
    98     emit activated(hitItem->modelIndex());                        
    98     emit activated(hitItem->modelIndex());                        
    99 }
    99 }
   100 
   100 
   101 void HgGridContainer::handleLongTapAction(const QPointF& pos, HgWidgetItem* hitItem, int hitItemIndex)
   101 void HgGridContainer::handleLongTapAction(const QPointF& pos, HgWidgetItem* hitItem, int hitItemIndex)
   102 {
   102 {
   103     Q_UNUSED(hitItemIndex)
   103     Q_UNUSED(hitItemIndex)
   104     
   104     
   105     selectItem();
   105     selectItem(hitItemIndex);
   106     emit longPressed(hitItem->modelIndex(), pos);    
   106     emit longPressed(hitItem->modelIndex(), pos);    
   107 }
   107 }
   108 
   108 
   109 void HgGridContainer::onScrollPositionChanged(qreal pos)
   109 void HgGridContainer::onScrollPositionChanged(qreal pos)
   110 {
   110 {
   114     const int index = ((int)pos)*rowCount();
   114     const int index = ((int)pos)*rowCount();
   115     if (index > itemCount()) return;
   115     if (index > itemCount()) return;
   116     
   116     
   117     HgWidgetItem* item = itemByIndex(index);
   117     HgWidgetItem* item = itemByIndex(index);
   118     if (item && item->modelIndex() != mSelectionModel->currentIndex()) {
   118     if (item && item->modelIndex() != mSelectionModel->currentIndex()) {
   119         qDebug() << "CURRENT CHANGE" << QString::number(item->modelIndex().row());
       
   120         mSelectionModel->setCurrentIndex(item->modelIndex(), QItemSelectionModel::Current);
   119         mSelectionModel->setCurrentIndex(item->modelIndex(), QItemSelectionModel::Current);
   121     }    
   120     }    
   122 }
   121 }