ganeswidgets/src/hgcoverflowcontainer.cpp
changeset 19 31a1a9e11046
parent 8 15f034b8a3b5
child 20 a60f8b6b1d32
equal deleted inserted replaced
18:1591614dbf89 19:31a1a9e11046
    16 */
    16 */
    17 
    17 
    18 #include <QGesture>
    18 #include <QGesture>
    19 #include <QGraphicsSceneResizeEvent>
    19 #include <QGraphicsSceneResizeEvent>
    20 #include <QPainter>
    20 #include <QPainter>
    21 #include <HbLabel>
       
    22 #include "hgcoverflowcontainer.h"
    21 #include "hgcoverflowcontainer.h"
    23 #include "hgmediawallrenderer.h"
    22 #include "hgmediawallrenderer.h"
    24 #include "hgwidgetitem.h"
    23 #include "hgwidgetitem.h"
    25 #include "hgcenteritemarea.h"
    24 #include "hgcenteritemarea.h"
    26 #include "trace.h"
    25 #include "trace.h"
    73 qreal HgCoverflowContainer::getCameraRotationY(qreal springVelocity)
    72 qreal HgCoverflowContainer::getCameraRotationY(qreal springVelocity)
    74 {
    73 {
    75     return qBound(-KCameraMaxYAngle, springVelocity * KSpringVelocityToCameraYAngleFactor, KCameraMaxYAngle);
    74     return qBound(-KCameraMaxYAngle, springVelocity * KSpringVelocityToCameraYAngleFactor, KCameraMaxYAngle);
    76 }
    75 }
    77 
    76 
    78 void HgCoverflowContainer::handleTapAction(const QPointF& pos, HgWidgetItem* hitItem, int hitItemIndex)
    77 bool HgCoverflowContainer::handleTapAction(const QPointF& pos, HgWidgetItem* hitItem, int hitItemIndex)
    79 {
    78 {
    80     Q_UNUSED(pos)
    79     Q_UNUSED(pos)
    81 
    80 
    82     if (qAbs(qreal(hitItemIndex) - mSpring.pos().x()) < 0.01f)
    81     INFO("Tap:" << hitItem->modelIndex().row());
    83     {
    82 
       
    83     if (mSelectionMode != HgWidget::NoSelection) {
       
    84         return handleItemSelection(hitItem);
       
    85     }
       
    86 
       
    87     if (qAbs(qreal(hitItemIndex) - mSpring.pos().x()) < 0.01f) {
       
    88         mSelectionModel->setCurrentIndex(hitItem->modelIndex(), QItemSelectionModel::Current);
    84         emit activated(hitItem->modelIndex());
    89         emit activated(hitItem->modelIndex());
    85     }
    90     } else {
    86     else
       
    87     {
       
    88         mSpring.animateToPos(QPointF(hitItemIndex, 0));
    91         mSpring.animateToPos(QPointF(hitItemIndex, 0));
    89     }
    92     }
    90 }
    93     
    91 
    94     return true;
    92 void HgCoverflowContainer::handleLongTapAction(const QPointF& pos, HgWidgetItem* hitItem, int hitItemIndex)
    95 }
       
    96 
       
    97 bool HgCoverflowContainer::handleLongTapAction(const QPointF& pos, HgWidgetItem* hitItem, int hitItemIndex)
    93 {
    98 {
    94     Q_UNUSED(hitItemIndex)
    99     Q_UNUSED(hitItemIndex)
    95 
   100     INFO("Long tap:" << hitItem->modelIndex().row());
    96     emit longPressed(hitItem->modelIndex(), pos);
   101     
       
   102     bool currentPressed = hitItem->modelIndex() == mSelectionModel->currentIndex();
       
   103     
       
   104     mSelectionModel->setCurrentIndex(hitItem->modelIndex(), QItemSelectionModel::Current);
       
   105     mSpring.animateToPos(QPointF(hitItemIndex, 0));
       
   106     
       
   107     if (mHandleLongPress && currentPressed && !mSpring.isActive()) {
       
   108         emit longPressed(hitItem->modelIndex(), pos);
       
   109     }
       
   110     return true;
    97 }
   111 }
    98 
   112 
    99 void HgCoverflowContainer::onScrollPositionChanged(qreal pos)
   113 void HgCoverflowContainer::onScrollPositionChanged(qreal pos)
   100 {
   114 {
   101     HgContainer::onScrollPositionChanged(pos);
   115     HgContainer::onScrollPositionChanged(pos);
   239 {
   253 {
   240     HgContainer::resizeEvent(event);
   254     HgContainer::resizeEvent(event);
   241     updateItemSize();
   255     updateItemSize();
   242 }
   256 }
   243 
   257 
       
   258 bool HgCoverflowContainer::handleTap(Qt::GestureState state, const QPointF &pos)
       
   259 {
       
   260     FUNC_LOG;
       
   261     
       
   262     bool handleGesture = false;
       
   263     
       
   264     if (hasItemAt(pos)) {
       
   265         int hitItemIndex = -1;
       
   266         // hititem will be valid since hasItemAt returned true.
       
   267         HgWidgetItem* hitItem = getItemAt(pos,hitItemIndex);
       
   268         switch (state) 
       
   269             {
       
   270             case Qt::GestureStarted:
       
   271                 {
       
   272                 mIgnoreGestureAction = false;
       
   273                 
       
   274                 if (mHandleLongPress && !mSpring.isActive()) {
       
   275                     // in coverflow mode we react to longtap only if animation is not on and
       
   276                     // center item is tapped.
       
   277                     if (hitItem->modelIndex() == mSelectionModel->currentIndex()) {
       
   278                         startLongPressWatcher(pos);
       
   279                     }
       
   280                 }
       
   281                 mSpring.cancel();
       
   282                 break;
       
   283                 }
       
   284             case Qt::GestureFinished:
       
   285                 handleGesture = handleTapAction(pos,hitItem,hitItemIndex);
       
   286             case Qt::GestureUpdated:
       
   287             case Qt::GestureCanceled:
       
   288             default:
       
   289                 stopLongPressWatcher();
       
   290                 break;
       
   291             }
       
   292         
       
   293         handleGesture = true;
       
   294     } else {
       
   295         // User has tapped outside any item.
       
   296         if (state == Qt::GestureStarted) {
       
   297             // Stop scrolling.
       
   298             mSpring.cancel();            
       
   299         } else if ( state == Qt::GestureFinished) {
       
   300             // Tap finished and outside any item is pressed.
       
   301             // Lets do focus animation to current item.
       
   302             scrollToPosition(mSpring.pos(), true);
       
   303         }
       
   304         
       
   305         mIgnoreGestureAction = true;
       
   306     }    
       
   307     return handleGesture;
       
   308 }
       
   309 
       
   310 bool HgCoverflowContainer::handleLongTap(Qt::GestureState state, const QPointF &pos)
       
   311 {
       
   312     // base class handles long tap if item is hitted.
       
   313     if (state == Qt::GestureUpdated && !HgContainer::handleLongTap(state, pos)) {
       
   314         // empty area pressed. Animate current item to front.
       
   315         scrollToPosition(mSpring.pos(), true);
       
   316     }
       
   317     
       
   318     return true;
       
   319 }
       
   320 
   244 // EOF
   321 // EOF