src/hbwidgets/itemviews/hblistviewitem.cpp
changeset 30 80e4d18b72f5
parent 23 e6ad4ef83b23
equal deleted inserted replaced
28:b7da29130b0e 30:80e4d18b72f5
    31 #include <hbicon.h>
    31 #include <hbicon.h>
    32 #include <hbiconitem.h>
    32 #include <hbiconitem.h>
    33 #include <hbtextitem.h>
    33 #include <hbtextitem.h>
    34 #include <hbrichtextitem.h>
    34 #include <hbrichtextitem.h>
    35 #include <hbstyle.h>
    35 #include <hbstyle.h>
    36 #include <hbstyleoptionlistviewitem_p.h>
    36 #include <hbstyleprimitivedata.h>
       
    37 #include <hbstyletextprimitivedata.h>
       
    38 #include <hbstylerichtextprimitivedata.h>
       
    39 #include <hbstyleiconprimitivedata.h>
    37 
    40 
    38 #include <QPersistentModelIndex>
    41 #include <QPersistentModelIndex>
    39 #include <QVariant>
    42 #include <QVariant>
    40 #include <QItemSelectionModel>
    43 #include <QItemSelectionModel>
    41 #include <QStyleOption>
       
    42 #include <QSizePolicy>
    44 #include <QSizePolicy>
    43 
    45 
    44 /*!
    46 /*!
    45     @beta
    47     @beta
    46     @hbwidgets
    48     @hbwidgets
   100     Below is an example how the layout properties can be configured.
   102     Below is an example how the layout properties can be configured.
   101 
   103 
   102     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,45}
   104     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,45}
   103 
   105 
   104     \primitives
   106     \primitives
   105     \primitive{icon-1} HbIconItem representing the icon-1 as described in the table above. 
   107     \primitive{icon-1} HbIconItem with item name "icon-1" representing icon-1 as described in the table above. 
   106     \primitive{icon-2} HbIconItem representing the icon-2 as described in the table above. 
   108     \primitive{icon-2} HbIconItem with item name "icon-2" representing the icon-2 as described in the table above. 
   107     \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.
   109     \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.
   108     \primitive{text-2} HbTextItem or HbRichTextItem representing the text-2 as described in the table above.
   110     \primitive{text-2} HbTextItem or HbRichTextItem with item name "text-2" representing the text-2 as described in the table above.
   109     \primitive{text-3} HbTextItem or HbRichTextItem representing the text-3 as described in the table above.
   111     \primitive{text-3} HbTextItem or HbRichTextItem with item name "text-3" representing the text-3 as described in the table above.
   110 
   112 
   111 */
   113 */
   112 
   114 
   113 /*!
   115 /*!
   114     \enum HbListViewItem::StretchingStyle
   116     \enum HbListViewItem::StretchingStyle
   217                                        const int index)
   219                                        const int index)
   218 {
   220 {
   219     Q_Q( HbListViewItem );
   221     Q_Q( HbListViewItem );
   220 
   222 
   221     // create icon item and set it to layout
   223     // create icon item and set it to layout
   222     HbStylePrivate::Primitive primitive = decorationPrimitive(value);
   224      HbStyle::PrimitiveType primitive = decorationPrimitive(value);
   223 
   225 
   224     if (primitive != HbStylePrivate::P_None) {
   226      if (primitive != HbStyle::PT_None) {
   225         QGraphicsItem *item = mDecorationRoleItems.value(index);
   227         QGraphicsObject *item = mDecorationRoleItems.value(index);
   226         if (!item) {
   228         if (!item) {
   227             mItemsChanged = true;
   229             mItemsChanged = true;
   228             themingPending = true;
   230             themingPending = true;
   229             item = HbStylePrivate::createPrimitive(primitive, q);
   231 
       
   232             QString name;
       
   233             if (index == 0) {
       
   234                 name = QLatin1String("icon-1");
       
   235             } else if (index == 1) {
       
   236                 name = QLatin1String("icon-2");
       
   237             } else {
       
   238                 name = QLatin1String("icon-") + QString::number(index + 1);
       
   239             }
       
   240 
       
   241             item = q->style()->createPrimitive(primitive, name, 0);
       
   242             item->setParentItem(q); // To enable asynchronous icon loading.
       
   243             item->setZValue(index + 1);
   230 
   244 
   231             if (index < mDecorationRoleItems.count()) {
   245             if (index < mDecorationRoleItems.count()) {
   232                 mDecorationRoleItems.replace(index, item);
   246                 mDecorationRoleItems.replace(index, item);
   233             } else {
   247             } else {
   234                 mDecorationRoleItems.append(item);
   248                 mDecorationRoleItems.append(item);
   250 {
   264 {
   251     Q_Q( HbListViewItem );
   265     Q_Q( HbListViewItem );
   252 
   266 
   253     // create text item  and set it to layout
   267     // create text item  and set it to layout
   254     if (!value.isNull()) {
   268     if (!value.isNull()) {
   255         QGraphicsItem *textItem = mDisplayRoleTextItems.value(index);
   269         QGraphicsObject *textItem = mDisplayRoleTextItems.value(index);
   256 
   270 
   257         HbStylePrivate::Primitive primitive = displayPrimitive();
   271         HbStyle::PrimitiveType primitive = displayPrimitive();
   258         if (!textItem) {
   272         if (!textItem) {
   259             mItemsChanged = true;
   273             mItemsChanged = true;
   260             themingPending = true;
   274             themingPending = true;
   261             textItem = HbStylePrivate::createPrimitive(primitive, q);
   275 
       
   276             QString name;
       
   277             if (index == 0) {
       
   278                 name = QLatin1String("text-1");
       
   279             } else if (index == 1) {
       
   280                 name = QLatin1String("text-2");
       
   281             } else if (index == 2) {
       
   282                 name = QLatin1String("text-3");
       
   283             } else {
       
   284                 name = QLatin1String("text-") + QString::number(index + 1);
       
   285             }
       
   286 
       
   287             textItem = q->style()->createPrimitive(primitive, name, q);
       
   288             HbTextItem *realTextItem = qobject_cast<HbTextItem*>(textItem);
       
   289             if (realTextItem) {
       
   290                 realTextItem->setTextWrapping(Hb::TextNoWrap);
       
   291             }
   262             if (index < mDisplayRoleTextItems.count()) {
   292             if (index < mDisplayRoleTextItems.count()) {
   263                 mDisplayRoleTextItems.replace(index, textItem);
   293                 mDisplayRoleTextItems.replace(index, textItem);
   264             } else {
   294             } else {
   265                 mDisplayRoleTextItems.append(textItem);
   295                 mDisplayRoleTextItems.append(textItem);
   266             }
   296             }
   417 
   447 
   418     HbAbstractViewItem::updateChildItems();
   448     HbAbstractViewItem::updateChildItems();
   419 }
   449 }
   420 
   450 
   421 /*!
   451 /*!
       
   452   Initializes the HbListViewItem primitive data. 
       
   453   
       
   454   This function calls HbWidgetBase::initPrimitiveData().
       
   455   \a primitiveData is data object, which is populated with data. \a primitive is the primitive.
       
   456   \a index is used to index data item in the internal store.
       
   457 */
       
   458 void HbListViewItem::initPrimitiveData(HbStylePrimitiveData     *primitiveData, 
       
   459                                        const QGraphicsObject    *primitive,
       
   460                                        int                      index)
       
   461 {
       
   462     Q_ASSERT_X(primitive && primitiveData, "HbListViewItem::initPrimitiveData" , "NULL data not permitted");
       
   463     HB_SDD(HbListViewItem);
       
   464 
       
   465     HbWidgetBase::initPrimitiveData(primitiveData, primitive);
       
   466     if (primitiveData->type == HbStylePrimitiveData::SPD_Text) {
       
   467         HbStyleTextPrimitiveData *textPrimitiveData = hbstyleprimitivedata_cast<HbStyleTextPrimitiveData*>(primitiveData);
       
   468 
       
   469          textPrimitiveData->text = d->mStringList.at(index);
       
   470 
       
   471         if (index == 1) {
       
   472             textPrimitiveData->textWrapping = Hb::TextNoWrap;
       
   473             textPrimitiveData->elideMode = Qt::ElideNone;
       
   474             if (d->isMultilineSupported()) {
       
   475                 if (sd->mMinimumSecondaryTextRowCount != -1) {
       
   476                     // min & max secondary text row counts set by app
       
   477                     if (sd->mMaximumSecondaryTextRowCount != 1) {
       
   478                         textPrimitiveData->textWrapping = Hb::TextWordWrap;
       
   479                         textPrimitiveData->elideMode = Qt::ElideRight;
       
   480                     }
       
   481                     textPrimitiveData->minimumLines = sd->mMinimumSecondaryTextRowCount;
       
   482                     textPrimitiveData->maximumLines = sd->mMaximumSecondaryTextRowCount;
       
   483                 }
       
   484                 else {
       
   485                     // min & max secondary text row counts not set by app. Allow setting those from .css
       
   486                     // Needed when multilineSecondaryTextSupported changed from FALSE to TRUE and
       
   487                     // min & max secondary text row counts has not been set by app
       
   488                     HbWidgetBasePrivate *widgetBaseP = HbStylePrivate::widgetBasePrivate(
       
   489                         qobject_cast<HbWidgetBase*>(const_cast<QGraphicsObject*>(primitive)));
       
   490                     if (widgetBaseP) {
       
   491                         widgetBaseP->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextWrapMode, false);
       
   492                         widgetBaseP->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextLinesMin, false);
       
   493                         widgetBaseP->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextLinesMax, false);
       
   494                     }
       
   495                 }
       
   496             } else {
       
   497                 // min & max secondary text row counts must always be 1. They cannot be overridden by .css
       
   498                 textPrimitiveData->minimumLines = 1;
       
   499                 textPrimitiveData->maximumLines = 1;
       
   500             }
       
   501         } 
       
   502     } else if (primitiveData->type == HbStylePrimitiveData::SPD_RichText) {
       
   503         hbstyleprimitivedata_cast<HbStyleRichTextPrimitiveData*>(primitiveData)->text = d->mStringList.at(index);
       
   504     } else if (primitiveData->type == HbStylePrimitiveData::SPD_Icon) {
       
   505         if (d->mDecorationList.at(index).canConvert<HbIcon>()){
       
   506             hbstyleprimitivedata_cast<HbStyleIconPrimitiveData*>(primitiveData)->icon = d->mDecorationList.at(index).value<HbIcon>();
       
   507         } else if (d->mDecorationList.at(index).canConvert<QIcon>()){
       
   508             hbstyleprimitivedata_cast<HbStyleIconPrimitiveData*>(primitiveData)->icon = HbIcon(d->mDecorationList.at(index).value<QIcon>());
       
   509         }
       
   510     }
       
   511 }
       
   512 
       
   513 
       
   514 /*!
   422     \reimp
   515     \reimp
   423 */
   516 */
   424 void HbListViewItem::updatePrimitives()
   517 void HbListViewItem::updatePrimitives()
   425 {
   518 {
   426     HB_SDD(HbListViewItem);
   519     Q_D( HbListViewItem );
   427 
       
   428     HbStyleOptionListViewItem *styleOption = sd->mListStyleOption;
       
   429     initStyleOption(styleOption);
       
   430 
   520 
   431     int count = d->mStringList.count();
   521     int count = d->mStringList.count();
   432     for (int i = 0; i < count; ++i) {
   522     for (int i = 0; i < count; ++i) {
   433         QGraphicsItem *item = d->mDisplayRoleTextItems.value(i);
   523         QGraphicsObject *item = d->mDisplayRoleTextItems.value(i);
   434         if (item) {
   524         if (item) {
   435             styleOption->index = i;
   525             if (d->displayPrimitive() == HbStyle::PT_TextItem) {
   436             styleOption->content = d->mStringList.at(i);
   526                 HbStyleTextPrimitiveData textPrimitiveData;
   437             styleOption->multilineSecondaryTextSupported = d->isMultilineSupported();
   527                 initPrimitiveData(&textPrimitiveData, item, i);
   438 
   528                 style()->updatePrimitive(item,&textPrimitiveData,this);
   439             if (i == 1) {
   529             } else {
   440                 // criteria of secondary text in middle column is fulfilled
   530                 HbStyleRichTextPrimitiveData richTextPrimitiveData;
   441                 styleOption->minimumLines = sd->mMinimumSecondaryTextRowCount;
   531                 initPrimitiveData(&richTextPrimitiveData, item, i);
   442                 styleOption->maximumLines = sd->mMaximumSecondaryTextRowCount;
   532                 style()->updatePrimitive(item,&richTextPrimitiveData,this);
   443             } 
   533             }
   444             HbStylePrivate::updatePrimitive(item, d->displayPrimitive(), styleOption);
   534         }
   445         }
   535     }
   446     }
       
   447 
       
   448     styleOption->role = Qt::DecorationRole;
       
   449 
   536 
   450     count = d->mDecorationList.count();
   537     count = d->mDecorationList.count();
   451     for (int i = 0; i < count; ++i) {
   538     for (int i = 0; i < count; ++i) {
   452         QGraphicsItem *item = d->mDecorationRoleItems.value(i);
   539         QGraphicsObject *item = d->mDecorationRoleItems.value(i);
   453         if (item) {
   540         if (item) {
   454             styleOption->index = i;
   541             HbStyleIconPrimitiveData iconPrimitiveData;
   455             styleOption->content = d->mDecorationList.at(i);
   542             initPrimitiveData(&iconPrimitiveData, item, i);
   456             HbStylePrivate::updatePrimitive(   
   543             style()->updatePrimitive(item,&iconPrimitiveData,this);
   457                         item, 
       
   458                         d->decorationPrimitive(d->mDecorationList.at(i)), 
       
   459                         styleOption);
       
   460         }
   544         }
   461     }
   545     }
   462     HbAbstractViewItem::updatePrimitives();
   546     HbAbstractViewItem::updatePrimitives();
   463 }
   547 }
   464 
   548