58 mClearingSelection(false), |
58 mClearingSelection(false), |
59 mAnimateItems(false), |
59 mAnimateItems(false), |
60 mPostponedScrollHint(HbAbstractItemView::PositionAtTop), |
60 mPostponedScrollHint(HbAbstractItemView::PositionAtTop), |
61 mPreviousSelectedCommand(QItemSelectionModel::NoUpdate), |
61 mPreviousSelectedCommand(QItemSelectionModel::NoUpdate), |
62 mAnimationTimer(0), |
62 mAnimationTimer(0), |
63 mModelIterator(0), |
63 mModelIterator(0), |
64 mEnabledAnimations(HbAbstractItemView::All), |
64 mEnabledAnimations(HbAbstractItemView::All), |
65 mLongPressEnabled(true), |
65 mLongPressEnabled(true), |
66 mDoingContiguousSelection(false) |
66 mDoingContiguousSelection(false) |
67 { |
67 { |
68 } |
68 } |
69 |
69 |
70 HbAbstractItemViewPrivate::~HbAbstractItemViewPrivate() |
70 HbAbstractItemViewPrivate::~HbAbstractItemViewPrivate() |
71 { |
71 { |
347 } |
347 } |
348 |
348 |
349 bool HbAbstractItemViewPrivate::panTriggered(QGestureEvent *event) |
349 bool HbAbstractItemViewPrivate::panTriggered(QGestureEvent *event) |
350 { |
350 { |
351 Q_Q(HbAbstractItemView); |
351 Q_Q(HbAbstractItemView); |
352 |
352 int retVal = false; |
353 HbPanGesture *gesture = static_cast<HbPanGesture *>(event->gesture(Qt::PanGesture)); |
353 HbPanGesture *gesture = static_cast<HbPanGesture *>(event->gesture(Qt::PanGesture)); |
354 |
354 |
355 switch (gesture->state()) { |
355 switch (gesture->state()) { |
356 case Qt::GestureStarted: |
356 case Qt::GestureStarted: |
357 mOptions |= PanningActive; |
357 mOptions |= PanningActive; |
358 // Fallthrough |
358 // Fallthrough |
359 case Qt::GestureUpdated: { |
359 case Qt::GestureUpdated: { |
360 QPointF scenePos = event->mapToGraphicsScene(gesture->hotSpot()); |
360 QPointF scenePos = event->mapToGraphicsScene(gesture->hotSpot()); |
361 if (mDoingContiguousSelection) { |
361 if (mDoingContiguousSelection) { |
362 int retVal = false; |
|
363 |
362 |
364 // loop through the items in the scene |
363 // loop through the items in the scene |
365 qreal scenePosY = scenePos.y(); |
364 qreal scenePosY = scenePos.y(); |
366 QPointF lastScenePos = scenePos + gesture->lastOffset() - gesture->offset(); |
365 QPointF lastScenePos = scenePos + gesture->lastOffset() - gesture->offset(); |
367 qreal lastScenePosY = lastScenePos.y(); |
366 qreal lastScenePosY = lastScenePos.y(); |
378 QPointF position(qBound((qreal)0.0, scenePosInItemCoordinates.x(), item->size().width()), |
377 QPointF position(qBound((qreal)0.0, scenePosInItemCoordinates.x(), item->size().width()), |
379 qBound((qreal)0.0, scenePosInItemCoordinates.y(), item->size().height())); |
378 qBound((qreal)0.0, scenePosInItemCoordinates.y(), item->size().height())); |
380 mouseMoveEvent.setPos(position); |
379 mouseMoveEvent.setPos(position); |
381 QItemSelectionModel::SelectionFlags command = q->selectionCommand(item, &mouseMoveEvent); |
380 QItemSelectionModel::SelectionFlags command = q->selectionCommand(item, &mouseMoveEvent); |
382 |
381 |
383 // in contiguousselectionarea there shall be no panning from HbScrollArea, thus return true |
382 // in contiguousselectionarea there shall be no panning from HbScrollArea, thus return true |
384 if (command != QItemSelectionModel::NoUpdate) { |
383 if (command != QItemSelectionModel::NoUpdate) { |
385 retVal = true; |
384 retVal = true; |
386 } |
385 } |
387 |
386 |
388 if ( itemIndex != mPreviousSelectedIndex |
387 if ( itemIndex != mPreviousSelectedIndex |
389 || command != mPreviousSelectedCommand) { |
388 || command != mPreviousSelectedCommand) { |
390 mPreviousSelectedIndex = itemIndex; |
389 mPreviousSelectedIndex = itemIndex; |
391 mPreviousSelectedCommand = command; |
390 mPreviousSelectedCommand = command; |
392 mSelectionModel->select(itemIndex, command); |
391 mSelectionModel->select(itemIndex, command); |
|
392 HbWidgetFeedback::triggered(q, Hb::InstantSelectionChanged, Hb::ModifierScrolling); |
393 } |
393 } |
394 |
394 |
395 // check if we need to start or keep on scrolling |
395 // check if we need to start or keep on scrolling |
396 int scrollDirection = 0; |
396 int scrollDirection = 0; |
397 QPointF pos = q->mapFromScene(scenePos); |
397 QPointF pos = q->mapFromScene(scenePos); |
424 retVal = true; |
424 retVal = true; |
425 } |
425 } |
426 break; |
426 break; |
427 } |
427 } |
428 } |
428 } |
429 return retVal; |
429 } |
430 } |
430 else { |
431 else if (!mDoingContiguousSelection){ |
|
432 HbWidgetFeedback::continuousTriggered(q, Hb::ContinuousScrolled); |
431 HbWidgetFeedback::continuousTriggered(q, Hb::ContinuousScrolled); |
433 } |
432 } |
434 break; |
433 break; |
435 } |
434 } |
436 case Qt::GestureFinished: |
435 case Qt::GestureFinished: |
437 case Qt::GestureCanceled: { |
436 case Qt::GestureCanceled: { |
438 mOptions &= ~PanningActive; |
437 mOptions &= ~PanningActive; |
439 if (mDoingContiguousSelection) { |
438 if (mDoingContiguousSelection) { |
440 stopAnimating(); |
439 stopAnimating(); |
441 mDoingContiguousSelection = false; |
440 mDoingContiguousSelection = false; |
442 return true; |
441 retVal = true; |
443 } |
442 } |
444 else { |
443 else { |
445 HbWidgetFeedback::continuousStopped(q, Hb::ContinuousScrolled); |
444 HbWidgetFeedback::continuousStopped(q, Hb::ContinuousScrolled); |
446 } |
445 } |
447 break; |
446 break; |
448 } |
447 } |
449 default: |
448 default: |
450 break; |
449 break; |
451 } |
450 } |
452 |
451 return retVal; |
453 return false; |
|
454 } |
452 } |
455 |
453 |
456 /*! |
454 /*! |
457 This slot is called when the view is scrolling doing countinuousselection. It does the item |
455 This slot is called when the view is scrolling doing countinuousselection. It does the item |
458 selection/deselection |
456 selection/deselection |
478 { |
476 { |
479 Q_Q(HbAbstractItemView); |
477 Q_Q(HbAbstractItemView); |
480 |
478 |
481 mFrictionEnabled = mOrigFriction; |
479 mFrictionEnabled = mOrigFriction; |
482 |
480 |
483 QObject::disconnect(q, SIGNAL(scrollPositionChanged(QPointF)), q, SLOT(_q_scrollingI(QPointF))); |
481 QObject::disconnect(q, SIGNAL(scrollPositionChanged(QPointF)), q, SLOT(_q_scrolling(QPointF))); |
484 QObject::disconnect(q, SIGNAL(scrollingEnded()), q, SLOT(_q_scrollingEnded())); |
482 QObject::disconnect(q, SIGNAL(scrollingEnded()), q, SLOT(_q_scrollingEnded())); |
485 QObject::disconnect(q, SIGNAL(scrollingStarted()), q, SLOT(_q_scrollingStarted())); |
483 QObject::disconnect(q, SIGNAL(scrollingStarted()), q, SLOT(_q_scrollingStarted())); |
486 } |
484 } |
487 |
485 |
488 /*! |
486 /*! |
506 { |
504 { |
507 QModelIndex firstVisibleModelIndex; |
505 QModelIndex firstVisibleModelIndex; |
508 QModelIndex lastVisibleModelIndex; |
506 QModelIndex lastVisibleModelIndex; |
509 mContainer->firstAndLastVisibleModelIndex(firstVisibleModelIndex, lastVisibleModelIndex); |
507 mContainer->firstAndLastVisibleModelIndex(firstVisibleModelIndex, lastVisibleModelIndex); |
510 |
508 |
511 if (mModelIterator->model()) { |
509 mVisibleIndex = firstVisibleModelIndex; |
512 if (lastVisibleModelIndex == mModelIterator->index(mModelIterator->indexCount() - 1)) { |
|
513 mVisibleIndex = lastVisibleModelIndex; |
|
514 } else { |
|
515 mVisibleIndex = firstVisibleModelIndex; |
|
516 } |
|
517 } |
|
518 } |
510 } |
519 |
511 |
520 /*! |
512 /*! |
521 \private |
513 \private |
522 |
514 |
661 switch (event->type()) { |
653 switch (event->type()) { |
662 case QEvent::GraphicsSceneMousePress: |
654 case QEvent::GraphicsSceneMousePress: |
663 case QEvent::GraphicsSceneMouseDoubleClick: { |
655 case QEvent::GraphicsSceneMouseDoubleClick: { |
664 |
656 |
665 // check if the mouse click is in the multiselectionarea |
657 // check if the mouse click is in the multiselectionarea |
666 if (item->selectionAreaContains(static_cast<const QGraphicsSceneMouseEvent *>(event)->pos(), HbAbstractViewItem::MultiSelection)) { |
658 if (item->selectionAreaContains(static_cast<const QGraphicsSceneMouseEvent *>(event)->pos(), HbAbstractViewItem::MultiSelection)) { |
667 mSelectionSettings |= Selection; |
659 mSelectionSettings |= Selection; |
668 if (mSelectionModel && mSelectionModel->isSelected(item->modelIndex())) { |
660 if (mSelectionModel && mSelectionModel->isSelected(item->modelIndex())) { |
669 mContSelectionAction = QItemSelectionModel::Deselect; |
661 mContSelectionAction = QItemSelectionModel::Deselect; |
670 } else { |
662 } else { |
671 mContSelectionAction = QItemSelectionModel::Select; |
663 mContSelectionAction = QItemSelectionModel::Select; |
672 } |
664 } |