src/hbwidgets/itemviews/hblistviewitem.cpp
changeset 30 80e4d18b72f5
parent 23 e6ad4ef83b23
--- a/src/hbwidgets/itemviews/hblistviewitem.cpp	Fri Sep 17 08:32:10 2010 +0300
+++ b/src/hbwidgets/itemviews/hblistviewitem.cpp	Mon Oct 04 00:38:12 2010 +0300
@@ -33,12 +33,14 @@
 #include <hbtextitem.h>
 #include <hbrichtextitem.h>
 #include <hbstyle.h>
-#include <hbstyleoptionlistviewitem_p.h>
+#include <hbstyleprimitivedata.h>
+#include <hbstyletextprimitivedata.h>
+#include <hbstylerichtextprimitivedata.h>
+#include <hbstyleiconprimitivedata.h>
 
 #include <QPersistentModelIndex>
 #include <QVariant>
 #include <QItemSelectionModel>
-#include <QStyleOption>
 #include <QSizePolicy>
 
 /*!
@@ -102,11 +104,11 @@
     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,45}
 
     \primitives
-    \primitive{icon-1} HbIconItem representing the icon-1 as described in the table above. 
-    \primitive{icon-2} HbIconItem representing the icon-2 as described in the table above. 
-    \primitive{text-1} HbTextItem or HbRichTextItem representing the text-1 as described in the table above. The type of the return value depends on the textFormat() of the item.
-    \primitive{text-2} HbTextItem or HbRichTextItem representing the text-2 as described in the table above.
-    \primitive{text-3} HbTextItem or HbRichTextItem representing the text-3 as described in the table above.
+    \primitive{icon-1} HbIconItem with item name "icon-1" representing icon-1 as described in the table above. 
+    \primitive{icon-2} HbIconItem with item name "icon-2" representing the icon-2 as described in the table above. 
+    \primitive{text-1} HbTextItem or HbRichTextItem with item name "text-1" representing the text-1 as described in the table above. The type of the return value depends on the textFormat() of the item.
+    \primitive{text-2} HbTextItem or HbRichTextItem with item name "text-2" representing the text-2 as described in the table above.
+    \primitive{text-3} HbTextItem or HbRichTextItem with item name "text-3" representing the text-3 as described in the table above.
 
 */
 
@@ -219,14 +221,26 @@
     Q_Q( HbListViewItem );
 
     // create icon item and set it to layout
-    HbStylePrivate::Primitive primitive = decorationPrimitive(value);
+     HbStyle::PrimitiveType primitive = decorationPrimitive(value);
 
-    if (primitive != HbStylePrivate::P_None) {
-        QGraphicsItem *item = mDecorationRoleItems.value(index);
+     if (primitive != HbStyle::PT_None) {
+        QGraphicsObject *item = mDecorationRoleItems.value(index);
         if (!item) {
             mItemsChanged = true;
             themingPending = true;
-            item = HbStylePrivate::createPrimitive(primitive, q);
+
+            QString name;
+            if (index == 0) {
+                name = QLatin1String("icon-1");
+            } else if (index == 1) {
+                name = QLatin1String("icon-2");
+            } else {
+                name = QLatin1String("icon-") + QString::number(index + 1);
+            }
+
+            item = q->style()->createPrimitive(primitive, name, 0);
+            item->setParentItem(q); // To enable asynchronous icon loading.
+            item->setZValue(index + 1);
 
             if (index < mDecorationRoleItems.count()) {
                 mDecorationRoleItems.replace(index, item);
@@ -252,13 +266,29 @@
 
     // create text item  and set it to layout
     if (!value.isNull()) {
-        QGraphicsItem *textItem = mDisplayRoleTextItems.value(index);
+        QGraphicsObject *textItem = mDisplayRoleTextItems.value(index);
 
-        HbStylePrivate::Primitive primitive = displayPrimitive();
+        HbStyle::PrimitiveType primitive = displayPrimitive();
         if (!textItem) {
             mItemsChanged = true;
             themingPending = true;
-            textItem = HbStylePrivate::createPrimitive(primitive, q);
+
+            QString name;
+            if (index == 0) {
+                name = QLatin1String("text-1");
+            } else if (index == 1) {
+                name = QLatin1String("text-2");
+            } else if (index == 2) {
+                name = QLatin1String("text-3");
+            } else {
+                name = QLatin1String("text-") + QString::number(index + 1);
+            }
+
+            textItem = q->style()->createPrimitive(primitive, name, q);
+            HbTextItem *realTextItem = qobject_cast<HbTextItem*>(textItem);
+            if (realTextItem) {
+                realTextItem->setTextWrapping(Hb::TextNoWrap);
+            }
             if (index < mDisplayRoleTextItems.count()) {
                 mDisplayRoleTextItems.replace(index, textItem);
             } else {
@@ -419,44 +449,98 @@
 }
 
 /*!
+  Initializes the HbListViewItem primitive data. 
+  
+  This function calls HbWidgetBase::initPrimitiveData().
+  \a primitiveData is data object, which is populated with data. \a primitive is the primitive.
+  \a index is used to index data item in the internal store.
+*/
+void HbListViewItem::initPrimitiveData(HbStylePrimitiveData     *primitiveData, 
+                                       const QGraphicsObject    *primitive,
+                                       int                      index)
+{
+    Q_ASSERT_X(primitive && primitiveData, "HbListViewItem::initPrimitiveData" , "NULL data not permitted");
+    HB_SDD(HbListViewItem);
+
+    HbWidgetBase::initPrimitiveData(primitiveData, primitive);
+    if (primitiveData->type == HbStylePrimitiveData::SPD_Text) {
+        HbStyleTextPrimitiveData *textPrimitiveData = hbstyleprimitivedata_cast<HbStyleTextPrimitiveData*>(primitiveData);
+
+         textPrimitiveData->text = d->mStringList.at(index);
+
+        if (index == 1) {
+            textPrimitiveData->textWrapping = Hb::TextNoWrap;
+            textPrimitiveData->elideMode = Qt::ElideNone;
+            if (d->isMultilineSupported()) {
+                if (sd->mMinimumSecondaryTextRowCount != -1) {
+                    // min & max secondary text row counts set by app
+                    if (sd->mMaximumSecondaryTextRowCount != 1) {
+                        textPrimitiveData->textWrapping = Hb::TextWordWrap;
+                        textPrimitiveData->elideMode = Qt::ElideRight;
+                    }
+                    textPrimitiveData->minimumLines = sd->mMinimumSecondaryTextRowCount;
+                    textPrimitiveData->maximumLines = sd->mMaximumSecondaryTextRowCount;
+                }
+                else {
+                    // min & max secondary text row counts not set by app. Allow setting those from .css
+                    // Needed when multilineSecondaryTextSupported changed from FALSE to TRUE and
+                    // min & max secondary text row counts has not been set by app
+                    HbWidgetBasePrivate *widgetBaseP = HbStylePrivate::widgetBasePrivate(
+                        qobject_cast<HbWidgetBase*>(const_cast<QGraphicsObject*>(primitive)));
+                    if (widgetBaseP) {
+                        widgetBaseP->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextWrapMode, false);
+                        widgetBaseP->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextLinesMin, false);
+                        widgetBaseP->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextLinesMax, false);
+                    }
+                }
+            } else {
+                // min & max secondary text row counts must always be 1. They cannot be overridden by .css
+                textPrimitiveData->minimumLines = 1;
+                textPrimitiveData->maximumLines = 1;
+            }
+        } 
+    } else if (primitiveData->type == HbStylePrimitiveData::SPD_RichText) {
+        hbstyleprimitivedata_cast<HbStyleRichTextPrimitiveData*>(primitiveData)->text = d->mStringList.at(index);
+    } else if (primitiveData->type == HbStylePrimitiveData::SPD_Icon) {
+        if (d->mDecorationList.at(index).canConvert<HbIcon>()){
+            hbstyleprimitivedata_cast<HbStyleIconPrimitiveData*>(primitiveData)->icon = d->mDecorationList.at(index).value<HbIcon>();
+        } else if (d->mDecorationList.at(index).canConvert<QIcon>()){
+            hbstyleprimitivedata_cast<HbStyleIconPrimitiveData*>(primitiveData)->icon = HbIcon(d->mDecorationList.at(index).value<QIcon>());
+        }
+    }
+}
+
+
+/*!
     \reimp
 */
 void HbListViewItem::updatePrimitives()
 {
-    HB_SDD(HbListViewItem);
-
-    HbStyleOptionListViewItem *styleOption = sd->mListStyleOption;
-    initStyleOption(styleOption);
+    Q_D( HbListViewItem );
 
     int count = d->mStringList.count();
     for (int i = 0; i < count; ++i) {
-        QGraphicsItem *item = d->mDisplayRoleTextItems.value(i);
+        QGraphicsObject *item = d->mDisplayRoleTextItems.value(i);
         if (item) {
-            styleOption->index = i;
-            styleOption->content = d->mStringList.at(i);
-            styleOption->multilineSecondaryTextSupported = d->isMultilineSupported();
-
-            if (i == 1) {
-                // criteria of secondary text in middle column is fulfilled
-                styleOption->minimumLines = sd->mMinimumSecondaryTextRowCount;
-                styleOption->maximumLines = sd->mMaximumSecondaryTextRowCount;
-            } 
-            HbStylePrivate::updatePrimitive(item, d->displayPrimitive(), styleOption);
+            if (d->displayPrimitive() == HbStyle::PT_TextItem) {
+                HbStyleTextPrimitiveData textPrimitiveData;
+                initPrimitiveData(&textPrimitiveData, item, i);
+                style()->updatePrimitive(item,&textPrimitiveData,this);
+            } else {
+                HbStyleRichTextPrimitiveData richTextPrimitiveData;
+                initPrimitiveData(&richTextPrimitiveData, item, i);
+                style()->updatePrimitive(item,&richTextPrimitiveData,this);
+            }
         }
     }
 
-    styleOption->role = Qt::DecorationRole;
-
     count = d->mDecorationList.count();
     for (int i = 0; i < count; ++i) {
-        QGraphicsItem *item = d->mDecorationRoleItems.value(i);
+        QGraphicsObject *item = d->mDecorationRoleItems.value(i);
         if (item) {
-            styleOption->index = i;
-            styleOption->content = d->mDecorationList.at(i);
-            HbStylePrivate::updatePrimitive(   
-                        item, 
-                        d->decorationPrimitive(d->mDecorationList.at(i)), 
-                        styleOption);
+            HbStyleIconPrimitiveData iconPrimitiveData;
+            initPrimitiveData(&iconPrimitiveData, item, i);
+            style()->updatePrimitive(item,&iconPrimitiveData,this);
         }
     }
     HbAbstractViewItem::updatePrimitives();