21 ** If you have questions regarding the use of this file, please contact |
21 ** If you have questions regarding the use of this file, please contact |
22 ** Nokia at developer.feedback@nokia.com. |
22 ** Nokia at developer.feedback@nokia.com. |
23 ** |
23 ** |
24 ****************************************************************************/ |
24 ****************************************************************************/ |
25 #include "hbtumbleviewitem.h" |
25 #include "hbtumbleviewitem.h" |
|
26 #include "hbtapgesture_p.h" |
26 |
27 |
27 #include "hblistviewitem_p.h" |
28 #include "hblistviewitem_p.h" |
|
29 #include "hbnamespace_p.h" |
28 #include <hbstyleoptionlistviewitem_p.h> |
30 #include <hbstyleoptionlistviewitem_p.h> |
|
31 |
|
32 #include <QGestureEvent> |
|
33 #include <QCoreApplication> |
29 |
34 |
30 HbTumbleViewItem::HbTumbleViewItem(QGraphicsItem *parent) : |
35 HbTumbleViewItem::HbTumbleViewItem(QGraphicsItem *parent) : |
31 HbListViewItem(parent) |
36 HbListViewItem(parent) |
32 { |
37 { |
33 HB_SDD(HbAbstractViewItem); |
38 HB_SDD(HbAbstractViewItem); |
49 |
54 |
50 |
55 |
51 /*! |
56 /*! |
52 \reimp |
57 \reimp |
53 */ |
58 */ |
54 HbAbstractViewItem *HbTumbleViewItem::createItem() |
59 HbAbstractViewItem *HbTumbleViewItem::createItem() |
55 { |
60 { |
56 HbTumbleViewItem* item = new HbTumbleViewItem(*this); |
61 HbTumbleViewItem* item = new HbTumbleViewItem(*this); |
57 item->setFocusPolicy(Qt::NoFocus); |
62 item->setFocusPolicy(Qt::NoFocus); |
58 |
63 connect(item,SIGNAL(released(QPointF)),item->itemView(),SLOT(_q_itemSelected(QPointF))); |
59 return item; |
64 return item; |
60 } |
65 } |
61 |
|
62 /*! |
66 /*! |
63 \reimp |
67 \reimp |
64 */ |
68 */ |
65 void HbTumbleViewItem::updateChildItems() |
69 void HbTumbleViewItem::updateChildItems() |
66 { |
70 { |
67 Q_D(HbListViewItem); |
71 Q_D(HbListViewItem); |
|
72 if (d->mIndex.data(Qt::DisplayRole).isNull()) |
|
73 return; |
68 HbListViewItem::updateChildItems(); |
74 HbListViewItem::updateChildItems(); |
69 if(d->mSelectionItem){ |
75 if(d->mSelectionItem){ |
70 d->mSelectionItem->hide(); |
76 d->mSelectionItem->hide(); |
71 } |
77 } |
72 } |
78 } |
73 |
79 |
|
80 void HbTumbleViewItem::gestureEvent(QGestureEvent *event) |
|
81 { |
|
82 HbTapGesture *gesture = static_cast<HbTapGesture *>(event->gesture(Qt::TapGesture)); |
|
83 if (gesture) { |
|
84 Q_D(HbAbstractViewItem); |
|
85 if(itemView()->isScrolling()){ |
|
86 event->ignore(); |
|
87 event->ignore(Qt::TapGesture); |
|
88 return; |
|
89 } |
|
90 if(gesture->state() == Qt::GestureCanceled){ |
|
91 d->setPressed(false, false); |
|
92 event->accept(); |
|
93 scene()->setProperty(HbPrivate::OverridingGesture.latin1(),QVariant()); |
|
94 return; |
|
95 } |
|
96 d->tapTriggered(event); |
|
97 } else { |
|
98 HbWidget::gestureEvent(event); |
|
99 |
|
100 } |
|
101 } |
|
102 |
|
103 |
|
104 QSizeF HbTumbleViewItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
105 { |
|
106 HB_SDD(const HbAbstractViewItem); |
|
107 static qreal height=0; |
|
108 |
|
109 QSizeF sh=HbListViewItem::sizeHint(which,constraint); |
|
110 if(which == Qt::PreferredSize && sh.height()<=0) { |
|
111 //TODO:remove this check once refresh issue in DTP is solved on removeRows/insertRows |
|
112 if(height<=0) { |
|
113 //Let's create a temporary item and take the height for the size hint |
|
114 HbAbstractViewItem *tempitem = sd->mPrototype->createItem(); |
|
115 if(sd->mItemView) { |
|
116 QAbstractItemModel *model = sd->mItemView->model(); |
|
117 if(model) { |
|
118 int rowCount=model->rowCount(); |
|
119 QModelIndex ind=model->index(rowCount,0); |
|
120 if(ind.isValid()) { |
|
121 tempitem->setModelIndex(ind); |
|
122 } |
|
123 } |
|
124 } |
|
125 |
|
126 |
|
127 //call polish |
|
128 QEvent polishEvent(QEvent::Polish); |
|
129 QCoreApplication::sendEvent(const_cast<HbAbstractViewItem *>(tempitem), &polishEvent); |
|
130 height=tempitem->effectiveSizeHint(which,constraint).height(); |
|
131 delete tempitem; |
|
132 } |
|
133 return QSizeF(sh.width(),height); |
|
134 } |
|
135 return sh; |
|
136 } |
|
137 |
|
138 |
74 #include "moc_hbtumbleviewitem.cpp" |
139 #include "moc_hbtumbleviewitem.cpp" |
75 |
140 |