24 ****************************************************************************/ |
24 ****************************************************************************/ |
25 #include "hbtreeviewitem_p.h" |
25 #include "hbtreeviewitem_p.h" |
26 |
26 |
27 #include "hbtreeviewitem.h" |
27 #include "hbtreeviewitem.h" |
28 #include "hbtreeview.h" |
28 #include "hbtreeview.h" |
29 #include "hbnamespace.h" |
|
30 #include "hbabstractitemview.h" |
29 #include "hbabstractitemview.h" |
31 #include "hbstyle.h" |
|
32 #include "hbstyleoptiontreeviewitem.h" |
|
33 #include "hbabstractitemcontainer.h" |
30 #include "hbabstractitemcontainer.h" |
|
31 |
|
32 #include <hbnamespace.h> |
|
33 #include <hbstyle.h> |
|
34 #include <hbstyleoptiontreeviewitem.h> |
|
35 #include <hbwidgetfeedback.h> |
|
36 #include <hbtapgesture.h> |
|
37 #include <hbeffect.h> |
34 |
38 |
35 #include <QPersistentModelIndex> |
39 #include <QPersistentModelIndex> |
36 #include <QVariant> |
40 #include <QVariant> |
37 #include <QDebug> |
41 #include <QDebug> |
38 |
42 |
52 |
56 |
53 See HbListViewItem for commmon view item subclassing reference. |
57 See HbListViewItem for commmon view item subclassing reference. |
54 |
58 |
55 */ |
59 */ |
56 |
60 |
|
61 /*! |
|
62 \deprecated HbTreeViewItem::StateKey |
|
63 is deprecated. Please use string based state keys. |
|
64 |
|
65 \enum HbTreeViewItem::StateKey |
|
66 |
|
67 HbTreeViewItem's user defined state keys. |
|
68 |
|
69 \sa HbAbstractViewItem::transientState() |
|
70 */ |
|
71 |
|
72 /*! |
|
73 \deprecated HbTreeViewItem::ExpansionKey |
|
74 is deprecated. Please use string based state keys. This key is replaced by "expanded". |
|
75 |
|
76 \var HbTreeViewItem::ExpansionKey |
|
77 Predefined key for expansion/collapsion state of a view item. Default state is collapsed. |
|
78 */ |
|
79 |
|
80 |
|
81 |
57 HbTreeViewItemPrivate::HbTreeViewItemPrivate(HbTreeViewItem *prototype) : |
82 HbTreeViewItemPrivate::HbTreeViewItemPrivate(HbTreeViewItem *prototype) : |
58 HbListViewItemPrivate(prototype), |
83 HbListViewItemPrivate(prototype, new HbTreeViewItemShared), |
59 mExpandItem(0), |
84 mExpandItem(0), |
60 mExpanded(false) |
85 mExpanded(false) |
61 { |
86 { |
|
87 |
62 } |
88 } |
63 |
89 |
64 HbTreeViewItemPrivate::HbTreeViewItemPrivate(const HbTreeViewItemPrivate &source) : |
90 HbTreeViewItemPrivate::HbTreeViewItemPrivate(const HbTreeViewItemPrivate &source) : |
65 HbListViewItemPrivate(source), |
91 HbListViewItemPrivate(source), |
66 mExpandItem(0), |
92 mExpandItem(0), |
89 } else { |
123 } else { |
90 return HbListViewItemPrivate::modelItemType(); |
124 return HbListViewItemPrivate::modelItemType(); |
91 } |
125 } |
92 } |
126 } |
93 |
127 |
94 QGraphicsItem *HbTreeViewItemPrivate::updateExpandItem() |
128 void HbTreeViewItemPrivate::updateExpandItem() |
95 { |
129 { |
96 Q_Q(HbTreeViewItem); |
130 Q_Q(HbTreeViewItem); |
97 QGraphicsItem *item = mExpandItem; |
|
98 |
|
99 if (!item) { |
|
100 mItemsChanged = true; |
|
101 item = q->style()->createPrimitive(HbStyle::P_TreeViewItem_expandicon, q); |
|
102 } |
|
103 |
131 |
104 HbStyleOptionTreeViewItem styleOption; |
132 HbStyleOptionTreeViewItem styleOption; |
105 q->initStyleOption(&styleOption); |
133 q->initStyleOption(&styleOption); |
106 |
134 |
107 q->style()->updatePrimitive(item, HbStyle::P_TreeViewItem_expandicon, &styleOption); |
135 q->style()->updatePrimitive(mExpandItem, HbStyle::P_TreeViewItem_expandicon, &styleOption); |
108 |
136 } |
109 return item; |
137 |
110 } |
138 void HbTreeViewItemPrivate::tapTriggered(QGestureEvent *event) |
111 |
139 { |
|
140 Q_Q(HbTreeViewItem); |
|
141 |
|
142 HbTapGesture *gesture = static_cast<HbTapGesture *>(event->gesture(Qt::TapGesture)); |
|
143 |
|
144 if (gesture->state() == Qt::GestureFinished |
|
145 && gesture->tapStyleHint() == HbTapGesture::Tap) { |
|
146 |
|
147 QPointF position = event->mapToGraphicsScene(gesture->hotSpot()); |
|
148 position = q->mapFromScene(position); |
|
149 |
|
150 bool inSelectionArea = false; |
|
151 if (mSharedData->mItemView->selectionMode() == HbAbstractItemView::SingleSelection) { |
|
152 inSelectionArea = q->selectionAreaContains(position, HbAbstractViewItem::SingleSelection); |
|
153 } else if ( mSharedData->mItemView->selectionMode() == HbAbstractItemView::MultiSelection |
|
154 || mSharedData->mItemView->selectionMode() == HbAbstractItemView::ContiguousSelection) { |
|
155 inSelectionArea = q->selectionAreaContains(position, HbAbstractViewItem::MultiSelection); |
|
156 } |
|
157 |
|
158 Hb::InteractionModifiers modifiers = 0; |
|
159 if (mExpandItem |
|
160 && mSharedData->mItemView |
|
161 && (mSharedData->mItemView->selectionMode() == HbAbstractItemView::SingleSelection |
|
162 || !inSelectionArea)) { |
|
163 if (q->isExpanded()) { |
|
164 modifiers |= Hb::ModifierExpandedItem; |
|
165 q->setExpanded(false); |
|
166 } else { |
|
167 modifiers |= Hb::ModifierCollapsedItem; |
|
168 q->setExpanded(true); |
|
169 } |
|
170 } |
|
171 |
|
172 HbWidgetFeedback::triggered(q, Hb::InstantReleased, modifiers); |
|
173 q->setPressed(false); |
|
174 |
|
175 emit q->activated(position); |
|
176 emit q->released(position); |
|
177 revealItem(); |
|
178 |
|
179 event->accept(); |
|
180 } else { |
|
181 HbListViewItemPrivate::tapTriggered(event); |
|
182 } |
|
183 |
|
184 } |
112 |
185 |
113 /*! |
186 /*! |
114 Constructs an tree view item with the given parent. |
187 Constructs an tree view item with the given parent. |
115 */ |
188 */ |
116 HbTreeViewItem::HbTreeViewItem(QGraphicsItem *parent) : |
189 HbTreeViewItem::HbTreeViewItem(QGraphicsItem *parent) : |
117 HbListViewItem(*new HbTreeViewItemPrivate(this), parent) |
190 HbListViewItem(*new HbTreeViewItemPrivate(this), parent) |
118 { |
191 { |
119 Q_D( HbTreeViewItem ); |
192 Q_D( HbTreeViewItem ); |
120 d->q_ptr = this; |
193 d->q_ptr = this; |
|
194 |
|
195 d->init(); |
121 } |
196 } |
122 |
197 |
123 /*! |
198 /*! |
124 Creates a separate graphics widget with same tree view item state as \a source. |
199 Creates a separate graphics widget with same tree view item state as \a source. |
125 */ |
200 */ |
126 HbTreeViewItem::HbTreeViewItem(const HbTreeViewItem &source) : |
201 HbTreeViewItem::HbTreeViewItem(const HbTreeViewItem &source) : |
127 HbListViewItem(*new HbTreeViewItemPrivate(*source.d_func()), 0) |
202 HbListViewItem(*new HbTreeViewItemPrivate(*source.d_func()), 0) |
128 { |
203 { |
129 Q_D( HbTreeViewItem ); |
204 Q_D( HbTreeViewItem ); |
130 d->q_ptr = this; |
205 d->q_ptr = this; |
|
206 |
|
207 d->init(); |
131 } |
208 } |
132 |
209 |
133 /*! |
210 /*! |
134 \internal |
211 \internal |
135 */ |
212 */ |
136 HbTreeViewItem::HbTreeViewItem(HbTreeViewItemPrivate &dd, QGraphicsItem * parent) : |
213 HbTreeViewItem::HbTreeViewItem(HbTreeViewItemPrivate &dd, QGraphicsItem * parent) : |
137 HbListViewItem(dd, parent) |
214 HbListViewItem(dd, parent) |
138 { |
215 { |
139 Q_D( HbTreeViewItem ); |
216 Q_D( HbTreeViewItem ); |
140 d->q_ptr = this; |
217 d->q_ptr = this; |
|
218 |
|
219 d->init(); |
141 } |
220 } |
142 |
221 |
143 /*! |
222 /*! |
144 Destroys the tree view item. |
223 Destroys the tree view item. |
145 */ |
224 */ |
169 /*! |
248 /*! |
170 \reimp |
249 \reimp |
171 */ |
250 */ |
172 void HbTreeViewItem::updateChildItems() |
251 void HbTreeViewItem::updateChildItems() |
173 { |
252 { |
|
253 HB_SDD(HbTreeViewItem); |
|
254 |
|
255 const QAbstractItemModel *model = d->mIndex.model(); |
|
256 |
|
257 if (model && model->hasChildren(d->mIndex) && sd->mUserExpandable) { |
|
258 if (!d->mExpandItem) { |
|
259 d->mExpandItem = style()->createPrimitive(HbStyle::P_TreeViewItem_expandicon, this); |
|
260 d->mItemsChanged = true; |
|
261 } |
|
262 } else { |
|
263 if (d->mExpandItem) { |
|
264 d->mItemsChanged = true; |
|
265 delete d->mExpandItem; |
|
266 d->mExpandItem = 0; |
|
267 } |
|
268 } |
|
269 |
|
270 HbListViewItem::updateChildItems(); |
|
271 } |
|
272 |
|
273 /*! |
|
274 \reimp |
|
275 */ |
|
276 void HbTreeViewItem::updatePrimitives() |
|
277 { |
174 Q_D(HbTreeViewItem); |
278 Q_D(HbTreeViewItem); |
175 |
279 if (d->mExpandItem) { |
176 const QAbstractItemModel *model = d->mIndex.model(); |
|
177 |
|
178 if (model && model->hasChildren(d->mIndex)) { |
|
179 d->mExpandItem = d->updateExpandItem(); |
|
180 } else if (d->mExpandItem) { |
|
181 d->mItemsChanged = true; |
|
182 delete d->mExpandItem; |
|
183 d->mExpandItem = 0; |
|
184 } |
|
185 |
|
186 HbListViewItem::updateChildItems(); |
|
187 } |
|
188 |
|
189 /*! |
|
190 \reimp |
|
191 */ |
|
192 void HbTreeViewItem::updatePrimitives() |
|
193 { |
|
194 Q_D(HbTreeViewItem); |
|
195 if(d->mExpandItem) { |
|
196 d->updateExpandItem(); |
280 d->updateExpandItem(); |
197 } |
281 } |
198 HbListViewItem::updatePrimitives(); |
282 HbListViewItem::updatePrimitives(); |
199 } |
283 } |
200 |
284 |
256 |
343 |
257 return state; |
344 return state; |
258 } |
345 } |
259 |
346 |
260 /*! |
347 /*! |
|
348 \reimp |
|
349 */ |
|
350 QHash<QString, QVariant> HbTreeViewItem::transientState() const |
|
351 { |
|
352 Q_D(const HbTreeViewItem); |
|
353 QHash<QString, QVariant> state = HbListViewItem::transientState(); |
|
354 if (d->mExpanded) { |
|
355 state.insert("expanded", d->mExpanded); |
|
356 } |
|
357 return state; |
|
358 } |
|
359 |
|
360 |
|
361 /*! |
|
362 \reimp |
|
363 */ |
|
364 void HbTreeViewItem::setTransientState(const QHash<QString, QVariant> &state) |
|
365 { |
|
366 Q_D(HbTreeViewItem); |
|
367 |
|
368 HbListViewItem::setTransientState(state); |
|
369 d->mExpanded = state.value("expanded").toBool(); |
|
370 } |
|
371 |
|
372 /*! |
|
373 \deprecated HbTreeViewItem::setState(const QMap<int,QVariant> &) |
|
374 is deprecated. Please use HbTreeViewItem::setState(const QHash<QString, QVariant> &state) instead. |
|
375 |
261 \reimp |
376 \reimp |
262 */ |
377 */ |
263 void HbTreeViewItem::setState(const QMap<int,QVariant> &state) |
378 void HbTreeViewItem::setState(const QMap<int,QVariant> &state) |
264 { |
379 { |
265 Q_D(HbTreeViewItem); |
380 Q_D(HbTreeViewItem); |
287 |
402 |
288 option->expanded = d->mExpanded; |
403 option->expanded = d->mExpanded; |
289 } |
404 } |
290 |
405 |
291 /*! |
406 /*! |
292 Provides access to primitives of HbTreeViewItem. |
407 |
293 \param primitive is the type of the requested primitive. The available primitives are |
408 \deprecated HbTreeViewItem::primitive(HbStyle::Primitive) |
294 \c P_TreeViewItem_expandicon |
409 is deprecated. |
|
410 |
|
411 Provides access to primitives of HbTreeViewItem. |
|
412 \param primitive is the type of the requested primitive. The available primitives are |
|
413 \c P_TreeViewItem_expandicon |
295 */ |
414 */ |
296 QGraphicsItem *HbTreeViewItem::primitive(HbStyle::Primitive primitive) const |
415 QGraphicsItem *HbTreeViewItem::primitive(HbStyle::Primitive primitive) const |
297 { |
416 { |
298 Q_D(const HbTreeViewItem); |
417 Q_D(const HbTreeViewItem); |
299 if (primitive == HbStyle::P_TreeViewItem_expandicon) { |
418 if (primitive == HbStyle::P_TreeViewItem_expandicon) { |
301 } else { |
420 } else { |
302 return HbListViewItem::primitive(primitive); |
421 return HbListViewItem::primitive(primitive); |
303 } |
422 } |
304 } |
423 } |
305 |
424 |
|
425 /*! |
|
426 Sets items either expandable or non-expandable by the user, depending on the value of \a expandable. |
|
427 |
|
428 This method will change the user expandable value for all view items. |
|
429 |
|
430 \sa isUserExpandable |
|
431 */ |
|
432 void HbTreeViewItem::setUserExpandable(bool expandable) |
|
433 { |
|
434 HB_SDD(HbTreeViewItem); |
|
435 if (sd->mUserExpandable != expandable) { |
|
436 sd->mUserExpandable = expandable; |
|
437 d->updateCloneItems(true); |
|
438 } |
|
439 } |
|
440 |
|
441 /*! |
|
442 Returns true if the items are expandable by the user; otherwise returns false. |
|
443 |
|
444 \sa setUserExpandable |
|
445 */ |
|
446 bool HbTreeViewItem::isUserExpandable() const |
|
447 { |
|
448 HB_SDD(const HbTreeViewItem); |
|
449 return sd->mUserExpandable; |
|
450 } |
|
451 |
|
452 /*! |
|
453 \reimp |
|
454 |
|
455 In the base class the multiselection mode selection area is the whole item. In HbTreeView this is not |
|
456 possible because of the expansion icon. For the HbTreeView the selection area in multiselection mode is |
|
457 defined by the primitive HbStyle::P_ItemViewItem_touchmultiselection |
|
458 */ |
|
459 bool HbTreeViewItem::selectionAreaContains(const QPointF &position, SelectionAreaType selectionAreaType) const |
|
460 { |
|
461 Q_D(const HbTreeViewItem); |
|
462 if ( selectionAreaType == HbAbstractViewItem::MultiSelection |
|
463 || selectionAreaType == HbAbstractViewItem::ContiguousSelection) { |
|
464 |
|
465 if( d->mMultiSelectionTouchArea |
|
466 && !d->mMultiSelectionTouchArea->boundingRect().isEmpty()) { |
|
467 return d->mMultiSelectionTouchArea->boundingRect().contains(mapToItem(d->mMultiSelectionTouchArea,position)); |
|
468 } else if (d->mSelectionItem) { |
|
469 return d->mSelectionItem->boundingRect().contains(mapToItem(d->mSelectionItem, position)); |
|
470 } else { |
|
471 return false; |
|
472 } |
|
473 } |
|
474 return HbAbstractViewItem::selectionAreaContains(position, selectionAreaType); |
|
475 } |
|
476 |
306 #include "moc_hbtreeviewitem.cpp" |
477 #include "moc_hbtreeviewitem.cpp" |
307 |
478 |