src/hbwidgets/itemviews/hbtreeviewitem.cpp
changeset 30 80e4d18b72f5
parent 23 e6ad4ef83b23
--- a/src/hbwidgets/itemviews/hbtreeviewitem.cpp	Fri Sep 17 08:32:10 2010 +0300
+++ b/src/hbwidgets/itemviews/hbtreeviewitem.cpp	Mon Oct 04 00:38:12 2010 +0300
@@ -33,11 +33,12 @@
 #include <hbnamespace.h>
 #include <hbnamespace_p.h>
 #include <hbstyle.h>
-#include <hbstyleoptiontreeviewitem_p.h>
 #include <hbwidgetfeedback.h>
 #include <hbtapgesture.h>
 #include <hbeffect.h>
 
+#include <hbstyleiconprimitivedata.h>
+
 #include <QPersistentModelIndex>
 #include <QVariant>
 #include <QDebug>
@@ -59,7 +60,7 @@
     See HbListViewItem for commmon view item subclassing reference. 
 
     \primitives
-    \primitive{subitem-indicator} HbIconItem representing the expand/collapse icon in an HbTreeViewItem that has child items.
+    \primitive{subitem-indicator} HbIconItem with item name "subitem-indicator" representing the expand/collapse icon in an HbTreeViewItem that has child items.
 */
 
 
@@ -113,10 +114,10 @@
 {
     Q_Q(HbTreeViewItem);
 
-    HbStyleOptionTreeViewItem styleOption;
-    q->initStyleOption(&styleOption);
+    HbStyleIconPrimitiveData iconPrimitiveData;
+    q->initPrimitiveData(&iconPrimitiveData, mExpandItem);
 
-    HbStylePrivate::updatePrimitive(mExpandItem, HbStylePrivate::P_TreeViewItem_expandicon, &styleOption);
+    q->style()->updatePrimitive(mExpandItem, &iconPrimitiveData, q);
 }
 
 void HbTreeViewItemPrivate::tapTriggered(QGestureEvent *event)
@@ -240,7 +241,8 @@
 
     if (model && model->hasChildren(d->mIndex) && sd->mUserExpandable) {
         if (!d->mExpandItem) {
-            d->mExpandItem = HbStylePrivate::createPrimitive(HbStylePrivate::P_TreeViewItem_expandicon, this);
+            d->mExpandItem = style()->createPrimitive(HbStyle::PT_IconItem, QLatin1String("subitem-indicator"), 0);
+            d->mExpandItem->setParentItem(this); // To enable asynchronous icon loading.
             d->mItemsChanged = true;
         }
     } else {
@@ -338,18 +340,36 @@
 }
 
 /*!
-    Initialize option with the values from this HbTreeViewItem. 
-
-    This method is useful for subclasses when they need a HbStyleOptionTreeViewItem, 
-    but don't want to fill in all the information themselves.
+  Initializes the HbTreeViewItem primitive data. 
+  
+  This function calls HbWidgetBase::initPrimitiveData().
+  \a primitiveData is data object, which is populated with data. \a primitive is the primitive.
 */
-void HbTreeViewItem::initStyleOption(HbStyleOptionTreeViewItem *option) const
+void HbTreeViewItem::initPrimitiveData(HbStylePrimitiveData     *primitiveData, 
+                                       const QGraphicsObject    *primitive)
 {
-    Q_D(const HbTreeViewItem);
+    Q_ASSERT_X(primitive && primitiveData, "HbTreeViewItem::initPrimitiveData" , "NULL data not permitted");
+    Q_D(HbTreeViewItem);
 
-    HbListViewItem::initStyleOption(option);
-
-    option->expanded = d->mExpanded;
+    HbWidgetBase::initPrimitiveData(primitiveData, primitive);
+    if (    primitiveData->type == HbStylePrimitiveData::SPD_Icon
+        &&  primitive == d->mExpandItem) {
+        QString iconName;
+        if (d->mExpanded) {
+            if (testAttribute(Hb::InsidePopup)) {
+                iconName = QLatin1String("qtg_mono_collapse");
+            } else {
+                iconName = QLatin1String("qtg_small_collapse");
+            }
+        } else {
+            if (testAttribute(Hb::InsidePopup)) {
+                iconName = QLatin1String("qtg_mono_expand");
+            } else {
+                iconName = QLatin1String("qtg_small_expand");
+            }
+        }
+        hbstyleprimitivedata_cast<HbStyleIconPrimitiveData*>(primitiveData)->iconName = iconName;
+    }
 }
 
 /*!
@@ -383,8 +403,8 @@
     \reimp
     
     In the base class the multiselection mode selection area is the whole item. In HbTreeView this is not
-    possible because of the expansion icon. For the HbTreeView the selection area in multiselection mode is 
-    defined by the primitive HbStylePrivate::P_ItemViewItem_touchmultiselection
+    possible because of the expansion icon. For the HbTreeView the selection is area of
+    primitive with item name "multiselection-toucharea".
 */
 bool HbTreeViewItem::selectionAreaContains(const QPointF &position, SelectionAreaType selectionAreaType) const
 {