31 #include "hbabstractitemcontainer_p.h" |
31 #include "hbabstractitemcontainer_p.h" |
32 |
32 |
33 #include <hbnamespace.h> |
33 #include <hbnamespace.h> |
34 #include <hbnamespace_p.h> |
34 #include <hbnamespace_p.h> |
35 #include <hbstyle.h> |
35 #include <hbstyle.h> |
36 #include <hbstyleoptiontreeviewitem_p.h> |
|
37 #include <hbwidgetfeedback.h> |
36 #include <hbwidgetfeedback.h> |
38 #include <hbtapgesture.h> |
37 #include <hbtapgesture.h> |
39 #include <hbeffect.h> |
38 #include <hbeffect.h> |
|
39 |
|
40 #include <hbstyleiconprimitivedata.h> |
40 |
41 |
41 #include <QPersistentModelIndex> |
42 #include <QPersistentModelIndex> |
42 #include <QVariant> |
43 #include <QVariant> |
43 #include <QDebug> |
44 #include <QDebug> |
44 |
45 |
57 \b Subclassing |
58 \b Subclassing |
58 |
59 |
59 See HbListViewItem for commmon view item subclassing reference. |
60 See HbListViewItem for commmon view item subclassing reference. |
60 |
61 |
61 \primitives |
62 \primitives |
62 \primitive{subitem-indicator} HbIconItem representing the expand/collapse icon in an HbTreeViewItem that has child items. |
63 \primitive{subitem-indicator} HbIconItem with item name "subitem-indicator" representing the expand/collapse icon in an HbTreeViewItem that has child items. |
63 */ |
64 */ |
64 |
65 |
65 |
66 |
66 HbTreeViewItemPrivate::HbTreeViewItemPrivate(HbTreeViewItem *prototype) : |
67 HbTreeViewItemPrivate::HbTreeViewItemPrivate(HbTreeViewItem *prototype) : |
67 HbListViewItemPrivate(prototype, new HbTreeViewItemShared), |
68 HbListViewItemPrivate(prototype, new HbTreeViewItemShared), |
111 |
112 |
112 void HbTreeViewItemPrivate::updateExpandItem() |
113 void HbTreeViewItemPrivate::updateExpandItem() |
113 { |
114 { |
114 Q_Q(HbTreeViewItem); |
115 Q_Q(HbTreeViewItem); |
115 |
116 |
116 HbStyleOptionTreeViewItem styleOption; |
117 HbStyleIconPrimitiveData iconPrimitiveData; |
117 q->initStyleOption(&styleOption); |
118 q->initPrimitiveData(&iconPrimitiveData, mExpandItem); |
118 |
119 |
119 HbStylePrivate::updatePrimitive(mExpandItem, HbStylePrivate::P_TreeViewItem_expandicon, &styleOption); |
120 q->style()->updatePrimitive(mExpandItem, &iconPrimitiveData, q); |
120 } |
121 } |
121 |
122 |
122 void HbTreeViewItemPrivate::tapTriggered(QGestureEvent *event) |
123 void HbTreeViewItemPrivate::tapTriggered(QGestureEvent *event) |
123 { |
124 { |
124 Q_Q(HbTreeViewItem); |
125 Q_Q(HbTreeViewItem); |
238 |
239 |
239 const QAbstractItemModel *model = d->mIndex.model(); |
240 const QAbstractItemModel *model = d->mIndex.model(); |
240 |
241 |
241 if (model && model->hasChildren(d->mIndex) && sd->mUserExpandable) { |
242 if (model && model->hasChildren(d->mIndex) && sd->mUserExpandable) { |
242 if (!d->mExpandItem) { |
243 if (!d->mExpandItem) { |
243 d->mExpandItem = HbStylePrivate::createPrimitive(HbStylePrivate::P_TreeViewItem_expandicon, this); |
244 d->mExpandItem = style()->createPrimitive(HbStyle::PT_IconItem, QLatin1String("subitem-indicator"), 0); |
|
245 d->mExpandItem->setParentItem(this); // To enable asynchronous icon loading. |
244 d->mItemsChanged = true; |
246 d->mItemsChanged = true; |
245 } |
247 } |
246 } else { |
248 } else { |
247 if (d->mExpandItem) { |
249 if (d->mExpandItem) { |
248 d->mItemsChanged = true; |
250 d->mItemsChanged = true; |
336 HbListViewItem::setTransientState(state); |
338 HbListViewItem::setTransientState(state); |
337 d->mExpanded = state.value("expanded").toBool(); |
339 d->mExpanded = state.value("expanded").toBool(); |
338 } |
340 } |
339 |
341 |
340 /*! |
342 /*! |
341 Initialize option with the values from this HbTreeViewItem. |
343 Initializes the HbTreeViewItem primitive data. |
342 |
344 |
343 This method is useful for subclasses when they need a HbStyleOptionTreeViewItem, |
345 This function calls HbWidgetBase::initPrimitiveData(). |
344 but don't want to fill in all the information themselves. |
346 \a primitiveData is data object, which is populated with data. \a primitive is the primitive. |
345 */ |
347 */ |
346 void HbTreeViewItem::initStyleOption(HbStyleOptionTreeViewItem *option) const |
348 void HbTreeViewItem::initPrimitiveData(HbStylePrimitiveData *primitiveData, |
347 { |
349 const QGraphicsObject *primitive) |
348 Q_D(const HbTreeViewItem); |
350 { |
349 |
351 Q_ASSERT_X(primitive && primitiveData, "HbTreeViewItem::initPrimitiveData" , "NULL data not permitted"); |
350 HbListViewItem::initStyleOption(option); |
352 Q_D(HbTreeViewItem); |
351 |
353 |
352 option->expanded = d->mExpanded; |
354 HbWidgetBase::initPrimitiveData(primitiveData, primitive); |
|
355 if ( primitiveData->type == HbStylePrimitiveData::SPD_Icon |
|
356 && primitive == d->mExpandItem) { |
|
357 QString iconName; |
|
358 if (d->mExpanded) { |
|
359 if (testAttribute(Hb::InsidePopup)) { |
|
360 iconName = QLatin1String("qtg_mono_collapse"); |
|
361 } else { |
|
362 iconName = QLatin1String("qtg_small_collapse"); |
|
363 } |
|
364 } else { |
|
365 if (testAttribute(Hb::InsidePopup)) { |
|
366 iconName = QLatin1String("qtg_mono_expand"); |
|
367 } else { |
|
368 iconName = QLatin1String("qtg_small_expand"); |
|
369 } |
|
370 } |
|
371 hbstyleprimitivedata_cast<HbStyleIconPrimitiveData*>(primitiveData)->iconName = iconName; |
|
372 } |
353 } |
373 } |
354 |
374 |
355 /*! |
375 /*! |
356 Sets items either expandable or non-expandable by the user, depending on the value of \a expandable. |
376 Sets items either expandable or non-expandable by the user, depending on the value of \a expandable. |
357 |
377 |
381 |
401 |
382 /*! |
402 /*! |
383 \reimp |
403 \reimp |
384 |
404 |
385 In the base class the multiselection mode selection area is the whole item. In HbTreeView this is not |
405 In the base class the multiselection mode selection area is the whole item. In HbTreeView this is not |
386 possible because of the expansion icon. For the HbTreeView the selection area in multiselection mode is |
406 possible because of the expansion icon. For the HbTreeView the selection is area of |
387 defined by the primitive HbStylePrivate::P_ItemViewItem_touchmultiselection |
407 primitive with item name "multiselection-toucharea". |
388 */ |
408 */ |
389 bool HbTreeViewItem::selectionAreaContains(const QPointF &position, SelectionAreaType selectionAreaType) const |
409 bool HbTreeViewItem::selectionAreaContains(const QPointF &position, SelectionAreaType selectionAreaType) const |
390 { |
410 { |
391 Q_D(const HbTreeViewItem); |
411 Q_D(const HbTreeViewItem); |
392 if ( selectionAreaType == HbAbstractViewItem::MultiSelection |
412 if ( selectionAreaType == HbAbstractViewItem::MultiSelection |