26 #include "hbabstractitemview_p.h" |
26 #include "hbabstractitemview_p.h" |
27 #include "hbabstractitemcontainer_p.h" |
27 #include "hbabstractitemcontainer_p.h" |
28 #include "hbabstractitemcontainer_p_p.h" |
28 #include "hbabstractitemcontainer_p_p.h" |
29 #include "hblistlayout_p.h" |
29 #include "hblistlayout_p.h" |
30 #include "hbstyleoption_p.h" |
30 #include "hbstyleoption_p.h" |
|
31 #include "hbframeitem.h" |
|
32 #include "hbstyleprimitivedata.h" |
31 |
33 |
32 #include <hbmodeliterator.h> |
34 #include <hbmodeliterator.h> |
33 #include <hbdatepickerviewitem_p.h> |
35 #include <hbdatepickerviewitem_p.h> |
34 #include <hbtapgesture.h> |
36 #include <hbtapgesture.h> |
|
37 #include <hbstyleframeprimitivedata.h> |
35 |
38 |
36 #include <qmath.h> |
39 #include <qmath.h> |
37 #include <QTimeLine> |
40 #include <QTimeLine> |
38 #include <QGraphicsItemAnimation> |
41 #include <QGraphicsItemAnimation> |
39 #include <QGestureEvent> |
42 #include <QGestureEvent> |
59 qreal topBoundary(); |
62 qreal topBoundary(); |
60 qreal bottomBoundary(); |
63 qreal bottomBoundary(); |
61 |
64 |
62 HbAbstractViewItem* getCenterItem(); |
65 HbAbstractViewItem* getCenterItem(); |
63 void slectItemAt(const QPointF& point,QGraphicsItem* itemToMap); |
66 void slectItemAt(const QPointF& point,QGraphicsItem* itemToMap); |
64 |
67 void setItemState(HbAbstractViewItem* item = 0); |
65 |
68 |
66 QTimeLine *animationtimer; |
69 QTimeLine *animationtimer; |
67 QGraphicsItemAnimation *animation; |
70 QGraphicsItemAnimation *animation; |
68 Q_DECLARE_PUBLIC(HbDatePickerView); |
71 Q_DECLARE_PUBLIC(HbDatePickerView); |
69 QGraphicsItem *mBackground; |
72 QGraphicsObject *mBackground; |
70 QGraphicsItem *mFrame;//overlay |
73 QGraphicsObject *mFrame;//overlay |
71 QGraphicsItem *mHighlight; |
74 QGraphicsObject *mHighlight; |
72 QGraphicsItem *mDivider; |
75 QGraphicsObject *mDivider; |
73 // bool tapActive; |
76 // bool tapActive; |
|
77 QPointer<HbAbstractViewItem> mPreviousItem; |
74 |
78 |
75 enum ViewState |
79 enum ViewState |
76 { |
80 { |
77 NoState = 0, |
81 NoState = 0, |
78 TapStarted = 1, |
82 TapStarted = 1, |
79 ScrollStarted = 2 |
83 ScrollStarted = 2 |
80 }; |
84 }; |
81 Q_DECLARE_FLAGS(ViewStates, ViewState); |
85 Q_DECLARE_FLAGS(ViewStates, ViewState) |
82 ViewStates viewStates; |
86 ViewStates viewStates; |
83 |
87 |
84 }; |
88 }; |
85 class HbDatePickerContainerPrivate; |
89 class HbDatePickerContainerPrivate; |
86 |
90 |
104 int maxItemCount() const; |
108 int maxItemCount() const; |
105 HbAbstractViewItem *createDefaultPrototype() const; |
109 HbAbstractViewItem *createDefaultPrototype() const; |
106 void viewResized(const QSizeF &size); |
110 void viewResized(const QSizeF &size); |
107 |
111 |
108 private: |
112 private: |
109 Q_DECLARE_PRIVATE(HbDatePickerContainer); |
113 Q_DECLARE_PRIVATE(HbDatePickerContainer) |
110 friend class HbDatePickerView; |
114 friend class HbDatePickerView; |
111 friend class HbDatePickerViewPrivate; |
115 friend class HbDatePickerViewPrivate; |
112 }; |
116 }; |
113 |
117 |
114 class HbDatePickerContainerPrivate:public HbAbstractItemContainerPrivate |
118 class HbDatePickerContainerPrivate:public HbAbstractItemContainerPrivate |
566 } |
570 } |
567 } |
571 } |
568 d->mContainer->setModelIndexes(d->mModelIterator->index(newIndex)); |
572 d->mContainer->setModelIndexes(d->mModelIterator->index(newIndex)); |
569 } |
573 } |
570 } |
574 } |
|
575 |
|
576 |
|
577 |
571 //HbAbstractItemView::scrollTo(index, hint); |
578 //HbAbstractItemView::scrollTo(index, hint); |
572 if ( index.isValid() |
579 if ( index.isValid() |
573 && d->mModelIterator->model() == index.model()) { |
580 && d->mModelIterator->model() == index.model()) { |
574 d->mPostponedScrollIndex = QPersistentModelIndex(); |
581 d->mPostponedScrollIndex = QPersistentModelIndex(); |
575 d->scrollTo(index, hint); |
582 d->scrollTo(index, hint); |
594 { |
601 { |
595 Q_Q(HbDatePickerView); |
602 Q_Q(HbDatePickerView); |
596 QPointF mappedPoint = itemTomap->mapToScene(point); |
603 QPointF mappedPoint = itemTomap->mapToScene(point); |
597 HbDatePickerContainer* container = static_cast<HbDatePickerContainer*>(mContainer); |
604 HbDatePickerContainer* container = static_cast<HbDatePickerContainer*>(mContainer); |
598 HbDatePickerContainerPrivate* containerPriv = container->d_func(); |
605 HbDatePickerContainerPrivate* containerPriv = container->d_func(); |
599 |
606 |
600 HbAbstractViewItem* item = qobject_cast<HbAbstractViewItem*>(itemAt(mappedPoint)); //(q->sender()); |
607 |
|
608 |
|
609 HbAbstractViewItem* item = qobject_cast<HbAbstractViewItem*>(itemAt(mappedPoint)); //(q->sender()); |
|
610 |
601 if(item){ |
611 if(item){ |
602 QPointF centerPt = q->mapToScene(q->boundingRect().center()); |
612 QPointF centerPt = q->mapToScene(q->boundingRect().center()); |
603 qreal itemHeight = containerPriv->getSmallestItemHeight(); |
613 qreal itemHeight = containerPriv->getSmallestItemHeight(); |
604 centerPt.setY(centerPt.y()- itemHeight/2); |
614 centerPt.setY(centerPt.y()- itemHeight/2); |
605 QPointF itemPos = q->mapToScene(containerPriv->itemBoundingRect(item).topLeft()); |
615 QPointF itemPos = q->mapToScene(containerPriv->itemBoundingRect(item).topLeft()); |
608 if(qCeil(delta.y())!=0){ |
618 if(qCeil(delta.y())!=0){ |
609 QPointF contPos = container->pos(); |
619 QPointF contPos = container->pos(); |
610 QPointF newPos = contPos-QPointF(0,qCeil(delta.y())); |
620 QPointF newPos = contPos-QPointF(0,qCeil(delta.y())); |
611 //need to remove already posted request to avoid multiple scrolling |
621 //need to remove already posted request to avoid multiple scrolling |
612 QCoreApplication::removePostedEvents(q,QEvent::LayoutRequest); |
622 QCoreApplication::removePostedEvents(q,QEvent::LayoutRequest); |
613 q->scrollContentsTo(-newPos,200); |
623 q->scrollContentsTo(-newPos,200); |
614 } |
624 } |
615 else { |
625 else { |
616 q->setCurrentIndex(item->modelIndex()); |
626 q->setCurrentIndex(item->modelIndex()); |
617 emit q->itemSelected(item->modelIndex().row()); |
627 emit q->itemSelected(item->modelIndex().row()); |
618 } |
628 setItemState(item); |
619 |
629 } |
620 } |
630 |
621 |
631 |
|
632 } |
|
633 |
|
634 } |
|
635 |
|
636 void HbDatePickerViewPrivate::setItemState(HbAbstractViewItem* item) |
|
637 { |
|
638 if(!item){ |
|
639 Q_Q(HbDatePickerView); |
|
640 QPointF mappedPoint = q->mapToScene(q->boundingRect().center()); |
|
641 item = qobject_cast<HbAbstractViewItem*>(itemAt(mappedPoint)); |
|
642 } |
|
643 if(item){ |
|
644 //change the items states for the current selection |
|
645 if(mPreviousItem && mPreviousItem->property("state").toString().compare("normal")){ |
|
646 mPreviousItem->setProperty("state", "normal"); |
|
647 } |
|
648 if(item && item->property("state").toString().compare("selected")){ |
|
649 item->setProperty("state", "selected"); |
|
650 } |
|
651 mPreviousItem = item; |
|
652 } |
622 } |
653 } |
623 |
654 |
624 void HbDatePickerViewPrivate::_q_scrollingEnded() |
655 void HbDatePickerViewPrivate::_q_scrollingEnded() |
625 { |
656 { |
626 if(mOptions & PanningActive){ |
657 if(mOptions & PanningActive){ |
701 scrollTo(model()->index(row,0),PositionAtCenter); |
733 scrollTo(model()->index(row,0),PositionAtCenter); |
702 //scrolling will not be started all the time so we need to emit signal |
734 //scrolling will not be started all the time so we need to emit signal |
703 //here in those cases. |
735 //here in those cases. |
704 if(!d->viewStates.testFlag(HbDatePickerViewPrivate::ScrollStarted)){ |
736 if(!d->viewStates.testFlag(HbDatePickerViewPrivate::ScrollStarted)){ |
705 emit itemSelected(row); |
737 emit itemSelected(row); |
|
738 if(scene()){ |
|
739 d->setItemState(); |
|
740 } |
706 } |
741 } |
707 } |
742 } |
708 } |
743 } |
709 |
744 |
710 int HbDatePickerView::selected() const |
745 int HbDatePickerView::selected() const |
723 void HbDatePickerViewPrivate::createPrimitives() |
758 void HbDatePickerViewPrivate::createPrimitives() |
724 { |
759 { |
725 Q_Q(HbDatePickerView); |
760 Q_Q(HbDatePickerView); |
726 |
761 |
727 //this is the highlight which is placed at center |
762 //this is the highlight which is placed at center |
|
763 |
728 if(!mHighlight) { |
764 if(!mHighlight) { |
729 mHighlight = HbStylePrivate::createPrimitive(HbStylePrivate::P_TumbleView_highlight,q); |
765 mHighlight = q->style()->createPrimitive(HbStyle::PT_FrameItem,"highlight",q); |
730 HbStyle::setItemName(mHighlight,"highlight"); |
766 } |
731 } |
767 |
732 if(!mDivider){ |
768 if(!mDivider) { |
733 mDivider = HbStylePrivate::createPrimitive(HbStylePrivate::P_DateTimePicker_separator,q); |
769 mDivider = q->style()->createPrimitive(HbStyle::PT_FrameItem,"separator",q); |
734 HbStyle::setItemName(mDivider,"separator"); |
770 } |
735 mDivider->hide(); |
|
736 } |
|
737 |
|
738 } |
771 } |
739 void HbDatePickerView::updatePrimitives() |
772 void HbDatePickerView::updatePrimitives() |
740 { |
773 { |
741 Q_D(HbDatePickerView); |
774 Q_D(HbDatePickerView); |
742 |
775 HbAbstractItemView::updatePrimitives(); |
743 HbStyleOption opt; |
776 |
744 initStyleOption(&opt); |
|
745 |
|
746 if(d->mBackground) { |
|
747 HbStylePrivate::updatePrimitive(d->mBackground,HbStylePrivate::P_TumbleView_background,&opt); |
|
748 } |
|
749 if(d->mFrame) { |
|
750 HbStylePrivate::updatePrimitive(d->mFrame,HbStylePrivate::P_TumbleView_frame,&opt); |
|
751 } |
|
752 if(d->mHighlight) { |
777 if(d->mHighlight) { |
753 HbStylePrivate::updatePrimitive(d->mHighlight,HbStylePrivate::P_TumbleView_highlight,&opt); |
778 HbStyleFramePrimitiveData data; |
754 } |
779 initPrimitiveData(&data,d->mHighlight); |
755 if(d->mDivider){ |
780 style()->updatePrimitive(d->mHighlight,&data,this); |
756 HbStylePrivate::updatePrimitive(d->mDivider, HbStylePrivate::P_DateTimePicker_separator, &opt); |
781 } |
757 } |
782 |
758 HbAbstractItemView::updatePrimitives(); |
783 if(d->mDivider) { |
|
784 HbStyleFramePrimitiveData data; |
|
785 initPrimitiveData(&data,d->mDivider); |
|
786 style()->updatePrimitive(d->mDivider,&data,this); |
|
787 } |
|
788 } |
|
789 void HbDatePickerView::initPrimitiveData(HbStylePrimitiveData *primitiveData, const QGraphicsObject *primitive) |
|
790 { |
|
791 HbWidget::initPrimitiveData(primitiveData, primitive); |
|
792 QString itemName = HbStyle::itemName(primitive); |
|
793 |
|
794 if(itemName == QLatin1String("highlight")) { |
|
795 HbStyleFramePrimitiveData *frameItem = hbstyleprimitivedata_cast<HbStyleFramePrimitiveData*>(primitiveData); |
|
796 frameItem->frameGraphicsName= QLatin1String("qtg_fr_tumbler_highlight_pri"); |
|
797 frameItem->frameType = HbFrameDrawer::ThreePiecesHorizontal; |
|
798 (const_cast<QGraphicsObject *> (primitive))->setZValue(-1); |
|
799 } |
|
800 |
|
801 if(itemName == QLatin1String("separator")) { |
|
802 HbStyleFramePrimitiveData *frameItem = hbstyleprimitivedata_cast<HbStyleFramePrimitiveData*>(primitiveData); |
|
803 frameItem->frameGraphicsName= QLatin1String("qtg_graf_tumbler_divider"); |
|
804 frameItem->frameType = HbFrameDrawer::OnePiece; |
|
805 (const_cast<QGraphicsObject *> (primitive))->setZValue(2); |
|
806 } |
759 |
807 |
760 } |
808 } |
761 |
809 |
762 |
810 |
763 void HbDatePickerView::gestureEvent(QGestureEvent *event) |
811 void HbDatePickerView::gestureEvent(QGestureEvent *event) |