changeset 1 | f7ac710697a9 |
parent 0 | 16d8024aca5e |
child 2 | 06ff229162e9 |
0:16d8024aca5e | 1:f7ac710697a9 |
---|---|
26 #include "hbabstractitemview_p.h" |
26 #include "hbabstractitemview_p.h" |
27 #include "hbabstractitemcontainer_p.h" |
27 #include "hbabstractitemcontainer_p.h" |
28 |
28 |
29 #include <hbabstractitemview.h> |
29 #include <hbabstractitemview.h> |
30 #include <hbabstractviewitem.h> |
30 #include <hbabstractviewitem.h> |
31 #include <hbgesturefilter.h> |
|
32 #include <hbevent.h> |
31 #include <hbevent.h> |
33 #include <hbabstractitemcontainer.h> |
32 #include <hbabstractitemcontainer.h> |
34 #include <hbwidgetfeedback.h> |
33 #include <hbwidgetfeedback.h> |
35 #include <hbinstance.h> |
34 #include <hbinstance.h> |
36 #include <hbscrollbar.h> |
35 #include <hbscrollbar.h> |
37 #include <hbmodeliterator.h> |
36 #include <hbmodeliterator.h> |
38 |
37 |
39 #include <QGraphicsSceneMouseEvent> |
38 #include <QGraphicsSceneMouseEvent> |
40 #include <QGraphicsScene> |
39 #include <QGraphicsScene> |
41 #include <QDebug> |
40 #include <QDebug> |
41 // For QMAP_INT__ITEM_STATE_DEPRECATED's sake. Removed when QMap<int,QVariant> based state item system is removed |
|
42 #include <hbabstractviewitem_p.h> |
|
43 |
|
44 #include <QGesture> |
|
45 #include <QGestureEvent> |
|
46 #include <QPanGesture> |
|
47 |
|
42 |
48 |
43 /*! |
49 /*! |
44 @alpha |
50 @alpha |
45 @hbwidgets |
51 @hbwidgets |
46 \class HbAbstractItemView |
52 \class HbAbstractItemView |
169 |
175 |
170 Animation related to item press and release. |
176 Animation related to item press and release. |
171 */ |
177 */ |
172 |
178 |
173 /*! |
179 /*! |
180 \var HbAbstractItemView::Expand |
|
181 |
|
182 Animation related to setting item expand. |
|
183 */ |
|
184 |
|
185 /*! |
|
186 \var HbAbstractItemView::Collapse |
|
187 |
|
188 Animation related to setting item collapsed. |
|
189 */ |
|
190 |
|
191 /*! |
|
174 Here are the main properties of the class: |
192 Here are the main properties of the class: |
175 |
193 |
176 \li HbAbstractItemView::itemRecycling: ItemRecycling. |
194 \li HbAbstractItemView::itemRecycling: ItemRecycling. |
177 \li HbAbstractItemView::SelectionMode: Different selection types supported by view. |
195 \li HbAbstractItemView::SelectionMode: Different selection types supported by view. |
178 \li HbAbstractItemView::bufferSize : Buffer Size used for item recycling. |
196 \li HbAbstractItemView::bufferSize : Buffer Size used for item recycling. |
497 */ |
515 */ |
498 bool HbAbstractItemView::event(QEvent *e) |
516 bool HbAbstractItemView::event(QEvent *e) |
499 { |
517 { |
500 Q_D(HbAbstractItemView); |
518 Q_D(HbAbstractItemView); |
501 |
519 |
502 bool result = false; |
520 bool result = HbScrollArea::event(e); |
503 |
|
504 if (e->type() == HbEvent::ChildFocusOut) { |
|
505 d->mWasScrolling = isScrolling(); |
|
506 result = true; |
|
507 } |
|
508 |
|
509 result |= HbScrollArea::event(e); |
|
510 |
521 |
511 // The two above statements have to be executed before these |
522 // The two above statements have to be executed before these |
512 if (e->type() == HbEvent::ChildFocusIn) { |
523 if (e->type() == HbEvent::ChildFocusIn) { |
513 HbAbstractViewItem *item = 0; |
524 HbAbstractViewItem *item = 0; |
514 QList<HbAbstractViewItem *> items = d->mContainer->items(); |
525 QList<HbAbstractViewItem *> items = d->mContainer->items(); |
538 return result; |
549 return result; |
539 } |
550 } |
540 |
551 |
541 /*! |
552 /*! |
542 \reimp |
553 \reimp |
543 */ |
554 |
544 void HbAbstractItemView::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
545 { |
|
546 Q_D(HbAbstractItemView); |
|
547 d->mPostponedScrollIndex = QPersistentModelIndex(); |
|
548 d->mPreviousSelectedIndex = QModelIndex(); |
|
549 d->mPreviousSelectedCommand = QItemSelectionModel::NoUpdate; |
|
550 d->mInstantClickedModifiers = 0; |
|
551 |
|
552 d->mHitItem = d->itemAt(event->scenePos()); |
|
553 |
|
554 if (d->mHitItem && d->mHitItem->modelIndex().isValid()) { |
|
555 QGraphicsItem::GraphicsItemFlags flags = d->mHitItem->flags(); |
|
556 if (!flags.testFlag(QGraphicsItem::ItemIsFocusable)){ |
|
557 d->mHitItem = 0; |
|
558 } |
|
559 } |
|
560 |
|
561 if (d->mHitItem) { |
|
562 if (d->mHitItem->modelIndex().isValid()) { |
|
563 Hb::InteractionModifiers modifiers = 0; |
|
564 if (d->mWasScrolling) { |
|
565 modifiers |= Hb::ModifierScrolling; |
|
566 } |
|
567 HbWidgetFeedback::triggered(d->mHitItem, Hb::InstantPressed, modifiers); |
|
568 |
|
569 if (!d->mWasScrolling) { |
|
570 d->mHitItem->setPressed(true); |
|
571 } |
|
572 } |
|
573 } |
|
574 |
|
575 if (isScrolling()) { |
|
576 // Needed when focus does not change. Otherwise mWasScrolling updating is done on |
|
577 // focusOutEvent or event function. |
|
578 d->mWasScrolling = true; |
|
579 } |
|
580 |
|
581 HbScrollArea::mousePressEvent(event); |
|
582 |
|
583 if (d->mHitItem) { |
|
584 emitPressed(d->mHitItem->modelIndex()); |
|
585 if (d->mSelectionModel) { |
|
586 QItemSelectionModel::SelectionFlags flags = selectionCommand(d->mHitItem, event); |
|
587 d->mSelectionModel->select(d->mHitItem->modelIndex(), flags); |
|
588 } |
|
589 } else if (d->mGestureFilter) { |
|
590 d->mGestureFilter->setLongpressAnimation(false); |
|
591 } |
|
592 |
|
593 event->accept(); |
|
594 } |
|
595 |
|
596 /*! |
|
597 \reimp |
|
598 */ |
|
599 void HbAbstractItemView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
600 { |
|
601 Q_D(HbAbstractItemView); |
|
602 |
|
603 HbScrollArea::mouseReleaseEvent(event); |
|
604 |
|
605 if (d->mGestureFilter) { |
|
606 d->mGestureFilter->setLongpressAnimation(true); |
|
607 } |
|
608 |
|
609 HbAbstractViewItem* hitItem = d->itemAt(event->scenePos()); |
|
610 if (hitItem) { |
|
611 QGraphicsItem::GraphicsItemFlags flags = hitItem->flags(); |
|
612 if (!flags.testFlag(QGraphicsItem::ItemIsFocusable)){ |
|
613 hitItem = 0; |
|
614 } |
|
615 } |
|
616 |
|
617 if (d->mHitItem) { |
|
618 d->mHitItem->setPressed(false); |
|
619 } |
|
620 |
|
621 if (hitItem) { |
|
622 if (hitItem->modelIndex().isValid()) { |
|
623 Hb::InteractionModifiers modifiers = 0; |
|
624 if (d->mWasScrolling) { |
|
625 modifiers |= Hb::ModifierScrolling; |
|
626 } |
|
627 HbWidgetFeedback::triggered(hitItem, Hb::InstantReleased, modifiers); |
|
628 } |
|
629 emitReleased(hitItem->modelIndex()); |
|
630 } |
|
631 |
|
632 if (d->mWasScrolling || d->mOptions.testFlag(HbAbstractItemViewPrivate::PanningActive)) { |
|
633 d->mOptions &= ~HbAbstractItemViewPrivate::PanningActive; |
|
634 if (d->mSelectionSettings.testFlag(HbAbstractItemViewPrivate::Selection)) { |
|
635 d->mSelectionSettings &= ~HbAbstractItemViewPrivate::Selection; |
|
636 d->mContSelectionAction = QItemSelectionModel::NoUpdate; |
|
637 } |
|
638 } else if (hitItem) { |
|
639 if (d->mSelectionModel) { |
|
640 d->mSelectionModel->setCurrentIndex(hitItem->modelIndex(), QItemSelectionModel::NoUpdate); |
|
641 |
|
642 QItemSelectionModel::SelectionFlags flags = selectionCommand(hitItem, event); |
|
643 d->mSelectionModel->select(hitItem->modelIndex(), flags); |
|
644 } |
|
645 |
|
646 if ( d->mHitItem == hitItem |
|
647 && hitItem->modelIndex().isValid()){ |
|
648 HbWidgetFeedback::triggered(hitItem, Hb::InstantClicked, d->mInstantClickedModifiers); |
|
649 emitActivated(hitItem->modelIndex()); |
|
650 } |
|
651 |
|
652 HbAbstractViewItem *item = d->currentItem(); |
|
653 if (item) { |
|
654 d->revealItem(item, EnsureVisible); |
|
655 } |
|
656 } |
|
657 d->mWasScrolling = false; |
|
658 event->accept(); |
|
659 } |
|
660 |
|
661 /*! |
|
662 \reimp |
|
663 */ |
|
664 void HbAbstractItemView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
665 { |
|
666 HbScrollArea::mouseMoveEvent( event ); |
|
667 |
|
668 Q_D(HbAbstractItemView); |
|
669 |
|
670 // contiguous selection handling. |
|
671 if (d->mSelectionSettings.testFlag(HbAbstractItemViewPrivate::Selection) |
|
672 && d->mSelectionModel |
|
673 && d->mSelectionMode == HbAbstractItemView::ContiguousSelection |
|
674 && geometry().contains(event->pos())) { |
|
675 |
|
676 QModelIndex firstIndex; |
|
677 QModelIndex lastIndex; |
|
678 d->mContainer->firstAndLastVisibleModelIndex(firstIndex, lastIndex); |
|
679 qreal scenePosY = event->scenePos().y(); |
|
680 qreal lastScenePosY = event->lastScenePos().y(); |
|
681 QPolygonF polygon; |
|
682 polygon << event->lastScenePos() << event->scenePos(); |
|
683 |
|
684 QList<QGraphicsItem *> items = scene()->items(polygon); |
|
685 int itemCount = items.count(); |
|
686 |
|
687 // loop through the items in the scene |
|
688 for (int current = 0; current < itemCount ; ++current) { |
|
689 HbAbstractViewItem *item = d->viewItem(items.at(current)); |
|
690 if (item) { |
|
691 if (d->mHitItem && item != d->mHitItem) { |
|
692 d->mHitItem->setPressed(false); |
|
693 } |
|
694 |
|
695 QModelIndex itemIndex(item->modelIndex()); |
|
696 QItemSelectionModel::SelectionFlags command = selectionCommand(item, event); |
|
697 if ( itemIndex != d->mPreviousSelectedIndex |
|
698 || command != d->mPreviousSelectedCommand) { |
|
699 d->mPreviousSelectedIndex = itemIndex; |
|
700 d->mPreviousSelectedCommand = command; |
|
701 d->mSelectionModel->select(itemIndex, command); |
|
702 |
|
703 // Scroll up/down when needed |
|
704 HbAbstractViewItem *scrollItem = 0; |
|
705 if (itemIndex == firstIndex |
|
706 && lastScenePosY > scenePosY) { |
|
707 scrollItem = d->mContainer->itemByIndex(d->mModelIterator->previousIndex(itemIndex)); |
|
708 } else if (itemIndex == lastIndex |
|
709 && lastScenePosY < scenePosY) { |
|
710 scrollItem = d->mContainer->itemByIndex(d->mModelIterator->nextIndex(itemIndex)); |
|
711 } |
|
712 |
|
713 if (scrollItem) { |
|
714 QPointF delta = d->pixelsToScroll(scrollItem, EnsureVisible); |
|
715 d->scrollByAmount(delta); |
|
716 } |
|
717 break; |
|
718 } |
|
719 } |
|
720 } |
|
721 } |
|
722 |
|
723 event->accept(); |
|
724 } |
|
725 |
|
726 /*! |
|
727 This slot is called when orientation is changed. |
555 This slot is called when orientation is changed. |
728 \a newOrientation has the currentOrientation mode. |
556 \a newOrientation has the currentOrientation mode. |
729 Note: Currently platform dependent orientation support is not available |
557 Note: Currently platform dependent orientation support is not available |
730 */ |
558 */ |
731 void HbAbstractItemView::orientationChanged(Qt::Orientation newOrientation) |
559 void HbAbstractItemView::orientationChanged(Qt::Orientation newOrientation) |
732 { |
560 { |
733 Q_UNUSED(newOrientation); |
561 Q_UNUSED(newOrientation); |
734 |
562 |
735 Q_D(HbAbstractItemView); |
563 Q_D(HbAbstractItemView); |
564 |
|
736 |
565 |
737 //Setting the uniform ites sizes to container again resets size caches. |
566 //Setting the uniform ites sizes to container again resets size caches. |
738 d->mContainer->setUniformItemSizes(d->mContainer->uniformItemSizes()); |
567 d->mContainer->setUniformItemSizes(d->mContainer->uniformItemSizes()); |
739 d->mContainer->setPos(0,0); |
568 d->mContainer->setPos(0,0); |
740 d->refreshContainerGeometry(); |
569 d->refreshContainerGeometry(); |
741 |
570 |
742 d->updateScrollMetrics(); |
571 d->updateScrollMetrics(); |
743 |
572 |
573 d->stopAnimating(); |
|
744 scrollTo(d->mVisibleIndex, HbAbstractItemView::PositionAtTop); |
574 scrollTo(d->mVisibleIndex, HbAbstractItemView::PositionAtTop); |
745 |
575 |
746 d->mVisibleIndex = QModelIndex(); |
576 d->mVisibleIndex = QModelIndex(); |
747 } |
577 } |
748 |
578 |
882 |
712 |
883 /*! |
713 /*! |
884 Returns SelectionFlags to be used when updating selection of a item. |
714 Returns SelectionFlags to be used when updating selection of a item. |
885 The event is a user input event, such as a mouse or keyboard event. |
715 The event is a user input event, such as a mouse or keyboard event. |
886 contiguousArea is true, if selectiontype is not single or no selection and |
716 contiguousArea is true, if selectiontype is not single or no selection and |
887 user has pressed on contiguousArea of viewItemi.e CheckBox. |
717 user has pressed on contiguousArea of viewItem i.e CheckBox. |
888 By default this is false. |
718 By default this is false. |
889 Subclasses should overide this function to define their own selection behavior. |
719 Subclasses should overide this function to define their own selection behavior. |
720 |
|
721 Note: The \a event parameter is not necessary a full event. For mouse events |
|
722 it is quaranteed to contain the event type and position. |
|
890 |
723 |
891 \sa HbAbstractViewItem::selectionAreaContains(const QPointF &scenePosition) const |
724 \sa HbAbstractViewItem::selectionAreaContains(const QPointF &scenePosition) const |
892 */ |
725 */ |
893 QItemSelectionModel::SelectionFlags HbAbstractItemView::selectionCommand(const HbAbstractViewItem *item, |
726 QItemSelectionModel::SelectionFlags HbAbstractItemView::selectionCommand(const HbAbstractViewItem *item, |
894 const QEvent *event) |
727 const QEvent *event) |
970 if (oldItem) { |
803 if (oldItem) { |
971 oldItem->lostFocus(); |
804 oldItem->lostFocus(); |
972 } |
805 } |
973 |
806 |
974 if (previous.isValid()) { |
807 if (previous.isValid()) { |
975 d->mContainer->setItemStateValue(previous, HbAbstractViewItem::FocusKey, false); |
808 #ifndef QMAP_INT__ITEM_STATE_DEPRECATED |
809 d->mContainer->setItemStateValue(previous, HbAbstractViewItem::FocusKey, false); |
|
810 #endif |
|
811 d->mContainer->setItemTransientStateValue(previous, "focused", false); |
|
976 } |
812 } |
977 |
813 |
978 if (newItem) { |
814 if (newItem) { |
979 newItem->receivedFocus(); |
815 newItem->receivedFocus(); |
980 } |
816 } |
981 |
817 |
982 if (d->mCurrentIndex.isValid()) { |
818 if (d->mCurrentIndex.isValid()) { |
819 #ifndef QMAP_INT__ITEM_STATE_DEPRECATED |
|
983 d->mContainer->setItemStateValue(d->mCurrentIndex, HbAbstractViewItem::FocusKey, true); |
820 d->mContainer->setItemStateValue(d->mCurrentIndex, HbAbstractViewItem::FocusKey, true); |
821 #endif |
|
822 d->mContainer->setItemTransientStateValue(d->mCurrentIndex, "focused", true); |
|
984 } |
823 } |
985 |
824 |
986 } |
825 } |
987 } |
826 } |
988 |
827 |
1000 for (int i = 0; i < count; ++i) { |
839 for (int i = 0; i < count; ++i) { |
1001 HbAbstractViewItem *item = d->mContainer->itemByIndex(selectedIndexes.at(i)); |
840 HbAbstractViewItem *item = d->mContainer->itemByIndex(selectedIndexes.at(i)); |
1002 if (item) { |
841 if (item) { |
1003 item->setCheckState(Qt::Checked); |
842 item->setCheckState(Qt::Checked); |
1004 if (!d->mClearingSelection) { |
843 if (!d->mClearingSelection) { |
1005 HbWidgetFeedback::triggered(item, Hb::InstantSelectionChanged); |
844 Hb::InteractionModifiers modifiers = 0; |
845 if (d->mIsScrolling) { |
|
846 modifiers |= Hb::ModifierScrolling; |
|
847 } |
|
848 HbWidgetFeedback::triggered(item, Hb::InstantSelectionChanged, modifiers); |
|
1006 } |
849 } |
1007 } |
850 } |
851 #ifndef QMAP_INT__ITEM_STATE_DEPRECATED |
|
1008 d->mContainer->setItemStateValue(selectedIndexes.at(i), |
852 d->mContainer->setItemStateValue(selectedIndexes.at(i), |
1009 HbAbstractViewItem::CheckStateKey, |
853 HbAbstractViewItem::CheckStateKey, |
854 Qt::Checked); |
|
855 #endif |
|
856 d->mContainer->setItemTransientStateValue(selectedIndexes.at(i), |
|
857 "checkState", |
|
1010 Qt::Checked); |
858 Qt::Checked); |
1011 } |
859 } |
1012 |
860 |
1013 QModelIndexList deselectedIndexes(deselected.indexes()); |
861 QModelIndexList deselectedIndexes(deselected.indexes()); |
1014 count = deselectedIndexes.count(); |
862 count = deselectedIndexes.count(); |
1018 item->setCheckState(Qt::Unchecked); |
866 item->setCheckState(Qt::Unchecked); |
1019 if (!d->mClearingSelection) { |
867 if (!d->mClearingSelection) { |
1020 HbWidgetFeedback::triggered(item, Hb::InstantSelectionChanged); |
868 HbWidgetFeedback::triggered(item, Hb::InstantSelectionChanged); |
1021 } |
869 } |
1022 } |
870 } |
871 #ifndef QMAP_INT__ITEM_STATE_DEPRECATED |
|
1023 d->mContainer->setItemStateValue(deselectedIndexes.at(i), |
872 d->mContainer->setItemStateValue(deselectedIndexes.at(i), |
1024 HbAbstractViewItem::CheckStateKey, |
873 HbAbstractViewItem::CheckStateKey, |
1025 Qt::Unchecked); |
874 Qt::Unchecked); |
875 #endif |
|
876 d->mContainer->setItemTransientStateValue(deselectedIndexes.at(i), |
|
877 "checkState", |
|
878 Qt::Unchecked); |
|
1026 } |
879 } |
1027 } |
880 } |
1028 |
881 |
1029 /*! |
882 /*! |
1030 This slot is called when rows are inserted. |
883 This slot is called when rows are inserted. |
1038 return; |
891 return; |
1039 } |
892 } |
1040 |
893 |
1041 for (int current = start; current <= end; current++) { |
894 for (int current = start; current <= end; current++) { |
1042 QModelIndex index = model()->index(current, 0, parent); |
895 QModelIndex index = model()->index(current, 0, parent); |
1043 bool animate = d->mEnabledAnimations & HbAbstractItemView::Appear ? d->mAnimateItems : false; |
896 d->mContainer->addItem(index, d->animationEnabled(true)); |
1044 d->mContainer->addItem(index, animate); |
|
1045 } |
897 } |
1046 |
898 |
1047 |
899 |
1048 if (!d->mCurrentIndex.isValid() && d->mSelectionModel) { |
900 if (!d->mCurrentIndex.isValid() && d->mSelectionModel) { |
1049 d->mSelectionModel->setCurrentIndex(d->mModelIterator->nextIndex(QModelIndex()), QItemSelectionModel::NoUpdate); |
901 d->mSelectionModel->setCurrentIndex(d->mModelIterator->nextIndex(QModelIndex()), QItemSelectionModel::NoUpdate); |
1145 Q_UNUSED(index); |
997 Q_UNUSED(index); |
1146 Q_UNUSED(start); |
998 Q_UNUSED(start); |
1147 Q_UNUSED(end); |
999 Q_UNUSED(end); |
1148 } |
1000 } |
1149 |
1001 |
1150 |
|
1151 /*! |
|
1152 \reimp |
|
1153 */ |
|
1154 void HbAbstractItemView::panGesture(const QPointF &point) |
|
1155 { |
|
1156 Q_D( HbAbstractItemView ); |
|
1157 d->mPostponedScrollIndex = QPersistentModelIndex(); |
|
1158 d->mOptions |= d->PanningActive; |
|
1159 |
|
1160 if (d->mHitItem) { |
|
1161 d->mHitItem->setPressed(false, false); |
|
1162 } |
|
1163 |
|
1164 HbScrollArea::panGesture(point); |
|
1165 |
|
1166 } |
|
1167 |
|
1168 /*! |
|
1169 \reimp |
|
1170 */ |
|
1171 void HbAbstractItemView::longPressGesture(const QPointF &point) |
|
1172 { |
|
1173 Q_D( HbAbstractItemView ); |
|
1174 d->mPostponedScrollIndex = QPersistentModelIndex(); |
|
1175 HbScrollArea::longPressGesture(point); |
|
1176 |
|
1177 if (d->mHitItem) { |
|
1178 if (d->mHitItem->modelIndex().isValid()) { |
|
1179 HbWidgetFeedback::triggered(d->mHitItem, Hb::InstantLongPressed); |
|
1180 } |
|
1181 if (d->mHitItem) { |
|
1182 d->mHitItem->setPressed(false); |
|
1183 } |
|
1184 emit longPressed(d->mHitItem, point); |
|
1185 } |
|
1186 } |
|
1187 |
|
1188 /*! |
|
1189 \reimp |
|
1190 */ |
|
1191 void HbAbstractItemView::focusOutEvent(QFocusEvent *event) |
|
1192 { |
|
1193 HbScrollArea::focusOutEvent(event); |
|
1194 |
|
1195 Q_D( HbAbstractItemView ); |
|
1196 |
|
1197 d->mWasScrolling = isScrolling(); |
|
1198 d->stopScrolling(); |
|
1199 } |
|
1200 |
|
1201 /*! |
1002 /*! |
1202 Emits the activated signal. |
1003 Emits the activated signal. |
1203 */ |
1004 */ |
1204 void HbAbstractItemView::emitActivated(const QModelIndex &modelIndex) |
1005 void HbAbstractItemView::emitActivated(const QModelIndex &modelIndex) |
1205 { |
1006 { |
1291 { |
1092 { |
1292 Q_D(HbAbstractItemView); |
1093 Q_D(HbAbstractItemView); |
1293 |
1094 |
1294 QPointF newDelta(delta); |
1095 QPointF newDelta(delta); |
1295 |
1096 |
1296 if (d->mContainer->itemRecycling()) { |
1097 if (d->mContainer->itemRecycling() |
1098 && !d->mContainer->items().isEmpty()) { |
|
1297 newDelta = d->mContainer->recycleItems(delta); |
1099 newDelta = d->mContainer->recycleItems(delta); |
1298 d->mAnimationInitialPosition = d->mAnimationInitialPosition + newDelta - delta; |
1100 d->mAnimationInitialPosition = d->mAnimationInitialPosition + newDelta - delta; |
1299 d->refreshContainerGeometry(); |
1101 d->refreshContainerGeometry(); |
1300 } |
1102 } |
1301 |
1103 |
1302 return HbScrollArea::scrollByAmount(newDelta); |
1104 return HbScrollArea::scrollByAmount(newDelta); |
1303 } |
1105 } |
1304 |
1106 |
1305 /*! |
1107 /*! |
1108 \deprecated HbAbstractItemView::container() const |
|
1109 is deprecated, because class HbAbstractItemContainer will be made private. |
|
1110 |
|
1306 Returns the container widget. |
1111 Returns the container widget. |
1307 */ |
1112 */ |
1308 HbAbstractItemContainer *HbAbstractItemView::container() const |
1113 HbAbstractItemContainer *HbAbstractItemView::container() const |
1309 { |
1114 { |
1115 qWarning("HbAbstractItemView::container() const is deprecated, because class HbAbstractItemContainer will be made private."); |
|
1310 Q_D(const HbAbstractItemView); |
1116 Q_D(const HbAbstractItemView); |
1311 return d->mContainer; |
1117 return d->mContainer; |
1312 } |
1118 } |
1313 |
1119 |
1314 /*! |
1120 /*! |
1448 return d->mEnabledAnimations; |
1254 return d->mEnabledAnimations; |
1449 } |
1255 } |
1450 |
1256 |
1451 /*! |
1257 /*! |
1452 \reimp |
1258 \reimp |
1453 |
1259 */ |
1454 Sets the pressed item non-pressed. |
1260 void HbAbstractItemView::gestureEvent(QGestureEvent *event) |
1455 */ |
1261 { |
1456 void HbAbstractItemView::upGesture(int value) |
1262 if (event->gesture(Qt::PanGesture)) { |
1263 Q_D(HbAbstractItemView); |
|
1264 if (d->panTriggered(event)) { |
|
1265 event->accept(); |
|
1266 } else { |
|
1267 HbScrollArea::gestureEvent(event); |
|
1268 } |
|
1269 } else { |
|
1270 HbScrollArea::gestureEvent(event); |
|
1271 } |
|
1272 } |
|
1273 |
|
1274 void HbAbstractItemView::itemPressed(const QPointF &pos) |
|
1457 { |
1275 { |
1458 Q_D(HbAbstractItemView); |
1276 Q_D(HbAbstractItemView); |
1459 |
1277 |
1460 d->mPostponedScrollIndex = QPersistentModelIndex(); |
1278 d->mPostponedScrollIndex = QPersistentModelIndex(); |
1461 |
1279 d->mPreviousSelectedIndex = QModelIndex(); |
1462 if (d->mHitItem) { |
1280 d->mPreviousSelectedCommand = QItemSelectionModel::NoUpdate; |
1463 d->mHitItem->setPressed(false, false); |
1281 d->mSelectionSettings &= ~HbAbstractItemViewPrivate::Selection; |
1464 } |
1282 d->mContSelectionAction = QItemSelectionModel::NoUpdate; |
1465 |
1283 |
1466 HbScrollArea::upGesture(value); |
1284 HbAbstractViewItem *item = qobject_cast<HbAbstractViewItem *>(sender()); |
1467 } |
1285 QModelIndex index = item->modelIndex(); |
1468 |
1286 |
1469 /*! |
1287 if (d->mSelectionMode != HbAbstractItemView::NoSelection) { |
1470 \reimp |
1288 QGraphicsSceneMouseEvent mousePressEvent(QEvent::GraphicsSceneMousePress); |
1471 |
1289 mousePressEvent.setPos(pos); |
1472 Sets the pressed item non-pressed. |
1290 d->mSelectionModel->select(index, selectionCommand(item, &mousePressEvent)); |
1473 */ |
1291 } |
1474 void HbAbstractItemView::downGesture(int value) |
1292 |
1475 { |
1293 emitPressed(item->modelIndex()); |
1476 Q_D(HbAbstractItemView); |
1294 } |
1477 |
1295 |
1478 d->mPostponedScrollIndex = QPersistentModelIndex(); |
1296 void HbAbstractItemView::itemReleased(const QPointF &pos) |
1479 |
1297 { |
1480 if (d->mHitItem) { |
1298 Q_UNUSED(pos); |
1481 d->mHitItem->setPressed(false, false); |
1299 |
1482 } |
1300 HbAbstractViewItem *item = qobject_cast<HbAbstractViewItem *>(sender()); |
1483 |
1301 emitReleased(item->modelIndex()); |
1484 HbScrollArea::downGesture(value); |
1302 } |
1485 } |
1303 |
1486 |
1304 void HbAbstractItemView::itemActivated(const QPointF &pos) |
1487 /*! |
1305 { |
1488 \reimp |
1306 Q_D(HbAbstractItemView); |
1489 |
1307 |
1490 Sets the pressed item non-pressed. |
1308 HbAbstractViewItem *item = qobject_cast<HbAbstractViewItem *>(sender()); |
1491 */ |
1309 QModelIndex index = item->modelIndex(); |
1492 void HbAbstractItemView::leftGesture(int value) |
1310 |
1493 { |
1311 d->mSelectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate); |
1494 Q_D(HbAbstractItemView); |
1312 |
1495 |
1313 if (d->mSelectionMode != HbAbstractItemView::NoSelection) { |
1496 d->mPostponedScrollIndex = QPersistentModelIndex(); |
1314 QGraphicsSceneMouseEvent mouseReleaseEvent(QEvent::GraphicsSceneMouseRelease); |
1497 |
1315 mouseReleaseEvent.setPos(pos); |
1498 if (d->mHitItem) { |
1316 d->mSelectionModel->select(index, selectionCommand(item, &mouseReleaseEvent)); |
1499 d->mHitItem->setPressed(false, false); |
1317 } |
1500 } |
1318 |
1501 |
1319 emitActivated(index); |
1502 HbScrollArea::leftGesture(value); |
1320 } |
1503 } |
1321 |
1504 |
1322 void HbAbstractItemView::itemLongPressed(const QPointF &pos) |
1505 /*! |
1323 { |
1506 \reimp |
1324 HbAbstractViewItem *item = qobject_cast<HbAbstractViewItem *>(sender()); |
1507 |
1325 emit longPressed(item, item->mapToScene(pos)); |
1508 Sets the pressed item non-pressed. |
1326 } |
1509 */ |
1327 |
1510 void HbAbstractItemView::rightGesture(int value) |
1328 void HbAbstractItemView::itemCreated(HbAbstractViewItem *item) |
1511 { |
1329 { |
1512 Q_D(HbAbstractItemView); |
1330 QObject::connect(item, SIGNAL(pressed(QPointF)), this, SLOT(itemPressed(QPointF))); |
1513 |
1331 QObject::connect(item, SIGNAL(released(QPointF)), this, SLOT(itemReleased(QPointF))); |
1514 d->mPostponedScrollIndex = QPersistentModelIndex(); |
1332 QObject::connect(item, SIGNAL(activated(QPointF)), this, SLOT(itemActivated(QPointF))); |
1515 |
1333 QObject::connect(item, SIGNAL(longPressed(QPointF)), this, SLOT(itemLongPressed(QPointF))); |
1516 if (d->mHitItem) { |
|
1517 d->mHitItem->setPressed(false, false); |
|
1518 } |
|
1519 |
|
1520 HbScrollArea::rightGesture(value); |
|
1521 } |
1334 } |
1522 |
1335 |
1523 /*! |
1336 /*! |
1524 \reimp |
1337 \reimp |
1525 */ |
1338 */ |
1533 d->mPostponedScrollIndex = QPersistentModelIndex(); |
1346 d->mPostponedScrollIndex = QPersistentModelIndex(); |
1534 } |
1347 } |
1535 return false; |
1348 return false; |
1536 } |
1349 } |
1537 |
1350 |
1351 /*! |
|
1352 * Sets the value of the longPressEnabled property. This value is set |
|
1353 * to true if the widget is to respond to long press gestures, false otherwise. |
|
1354 * |
|
1355 * The default value is true. |
|
1356 * |
|
1357 * \sa HbAbstractItemView::longPressEnabled() |
|
1358 */ |
|
1359 void HbAbstractItemView::setLongPressEnabled(bool enabled) |
|
1360 { |
|
1361 Q_D(HbAbstractItemView); |
|
1362 d->mLongPressEnabled = enabled; |
|
1363 } |
|
1364 |
|
1365 /*! |
|
1366 Returns true if the item view handles long press gestures, false otherwise |
|
1367 |
|
1368 \sa HbAbstractItemView::setLongPressEnabled() |
|
1369 */ |
|
1370 bool HbAbstractItemView::longPressEnabled() const |
|
1371 { |
|
1372 Q_D(const HbAbstractItemView); |
|
1373 return d->mLongPressEnabled; |
|
1374 } |
|
1375 |
|
1376 /*! |
|
1377 Slot handles QAbstractItemModel::layoutChanged() signal. |
|
1378 Default implementation sets first model item visible as first view item. |
|
1379 */ |
|
1380 void HbAbstractItemView::modelLayoutChanged() |
|
1381 { |
|
1382 Q_D(HbAbstractItemView); |
|
1383 d->mContainer->d_func()->updateItemBuffer(); |
|
1384 d->mContainer->setModelIndexes(d->mModelIterator->nextIndex(QModelIndex())); |
|
1385 if (d->mContainer->items().count() > 0) { |
|
1386 scrollTo(d->mContainer->items().at(0)->modelIndex(), PositionAtTop); |
|
1387 } |
|
1388 } |
|
1389 |
|
1538 #include "moc_hbabstractitemview.cpp" |
1390 #include "moc_hbabstractitemview.cpp" |
1539 |
1391 |
1540 |
1392 |