src/hbwidgets/itemviews/hbgridviewitem.cpp
changeset 34 ed14f46c0e55
parent 6 c3690ec91ef8
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    24 ****************************************************************************/
    24 ****************************************************************************/
    25 
    25 
    26 #include "hbgridviewitem_p.h"
    26 #include "hbgridviewitem_p.h"
    27 #include <hbgridviewitem.h>
    27 #include <hbgridviewitem.h>
    28 #include "hbgridview_p.h"
    28 #include "hbgridview_p.h"
    29 #include <hbstyleoptiongridviewitem_p.h>
    29 
       
    30 #include <hbstyletextprimitivedata.h>
       
    31 #include <hbstylerichtextprimitivedata.h>
       
    32 #include <hbstyleiconprimitivedata.h>
    30 #include <QDebug>
    33 #include <QDebug>
    31 
    34 
    32 /*!
    35 /*!
    33  @beta
    36  @beta
    34  @hbwidgets
    37  @hbwidgets
    35  \class HbGridViewItem
    38  \class HbGridViewItem
    36  \brief HbGridViewItem class represents a single item in a grid.    
    39  \brief HbGridViewItem class represents a single item in a grid.    
    37 
    40 
    38  The HbGridViewItem class provides a view item that is used by HbGridView class to visualize content within 
    41  The HbGridViewItem class provides a view item that is used by HbGridView class to visualize content within 
    39  a single model index. By default HbGridViewItem supports a QString that is stored into the Qt::DisplayRole role 
    42  a single model index. 
    40  and a QIcon or HbIcon that is stored into the Qt::DecoratorRole role within the index. QBrush, HbIcon or HbFrameBackground can be used
    43  
    41  as a background by storing them into the Qt::BackgroundRole role. If Qt::BackgroundRole is empty, the default item background
    44  HbGridViewItem supports Hb::StandardItem in Hb::ItemTypeRole role of data model.
    42  is used.
    45 
       
    46  Following item data roles are supported by HbGridViewItem
       
    47  \li QString in Qt::DisplayRole of the data model
       
    48  \li QIcon or HbIcon in Qt::DecoratorRole role. QIcon is supported only for compatibility reasons. 
       
    49  If QIcon is used the limitations described in the HbIcon::HbIcon(const QIcon &icon) apply.
       
    50 
       
    51  Handling Qt::BackgroundRole item data role takes place in base class HbAbstractViewItem.
    43 
    52 
    44  \b Subclassing
    53  \b Subclassing
    45 
    54 
    46  When subclassing HbGridViewItem, you must provide implementations of the createItem() and updateChildItems() functions.
    55  When subclassing HbGridViewItem, you must provide implementations of the createItem() and updateChildItems() functions.
    47 
    56 
    49 
    58 
    50  If the derived grid view item has transient state information that would have no meaning if stored within the model index (for example child item cursor
    59  If the derived grid view item has transient state information that would have no meaning if stored within the model index (for example child item cursor
    51  position selection areas etc.) the view item can use the grid view's internal state model to store this information.To use this feature 
    60  position selection areas etc.) the view item can use the grid view's internal state model to store this information.To use this feature 
    52  implement the state() and setState() functions in the derived class.
    61  implement the state() and setState() functions in the derived class.
    53  
    62  
    54  See also HbGridView, HbAbstractItemView, HbAbstractViewItem, HbStyleOptionAbstractViewItem
    63  See also HbGridView, HbAbstractItemView, HbAbstractViewItem
    55 
    64 
    56  \primitives
    65  \primitives
    57  \primitive{icon} HbIconItem representing the icon in the HbGridViewItem. 
    66  \primitive{icon} HbIconItem with item name "icon" representing the icon in the HbGridViewItem. 
    58  \primitive{text} HbTextItem representing the text in the HbGridViewItem. 
    67  \primitive{text} HbTextItem with item name "text" representing the text in the HbGridViewItem. 
       
    68 
       
    69  \sa HbAbstractViewItem
    59 
    70 
    60  */
    71  */
    61 
    72 
    62 /*!
    73 /*!
    63  Constructs a grid view item with the given parent.
    74  Constructs a grid view item with the given parent.
   146         d->updateIconItem(*viewPrivate);
   157         d->updateIconItem(*viewPrivate);
   147     }
   158     }
   148     HbAbstractViewItem::updateChildItems();
   159     HbAbstractViewItem::updateChildItems();
   149 }
   160 }
   150 
   161 
       
   162 
       
   163 /*!
       
   164   Initializes the HbGridViewItem primitive data. 
       
   165   
       
   166   This function calls HbWidgetBase::initPrimitiveData().
       
   167   \a primitiveData is data object, which is populated with data. \a primitive is the primitive.
       
   168 */
       
   169 void HbGridViewItem::initPrimitiveData(HbStylePrimitiveData     *primitiveData, 
       
   170                                        const QGraphicsObject    *primitive)
       
   171 {
       
   172     Q_ASSERT_X(primitive && primitiveData, "HbGridViewItem::initPrimitiveData" , "NULL data not permitted");
       
   173     Q_D(HbGridViewItem);
       
   174 
       
   175     HbWidgetBase::initPrimitiveData(primitiveData, primitive);
       
   176     if (primitiveData->type == HbStylePrimitiveData::SPD_Text) {
       
   177         HbStyleTextPrimitiveData *textPrimitiveData = hbstyleprimitivedata_cast<HbStyleTextPrimitiveData*>(primitiveData);
       
   178         textPrimitiveData->text = d->mText;
       
   179 
       
   180     } else if (primitiveData->type == HbStylePrimitiveData::SPD_Icon) {
       
   181         HbStyleIconPrimitiveData *iconPrimitiveData = hbstyleprimitivedata_cast<HbStyleIconPrimitiveData*>(primitiveData);
       
   182         iconPrimitiveData->icon = d->mIcon;
       
   183     }
       
   184 }
       
   185 
       
   186 
   151 /*!
   187 /*!
   152  \reimp
   188  \reimp
   153  */
   189  */
   154 void HbGridViewItem::updatePrimitives()
   190 void HbGridViewItem::updatePrimitives()
   155 {
   191 {
   156     Q_D( HbGridViewItem );
   192     Q_D( HbGridViewItem );
   157     if (d->mTextItem || d->mIconItem) {
   193     if (d->mTextItem || d->mIconItem) {
   158         HbStyleOptionGridViewItem styleOption;
       
   159         initStyleOption(&styleOption);
       
   160 
       
   161         if (d->mTextItem) {
   194         if (d->mTextItem) {
   162             style()->updatePrimitive(d->mTextItem, HbStyle::P_GridViewItem_text,
   195             HbStyleTextPrimitiveData textPrimitiveData;
   163                     &styleOption);
   196             initPrimitiveData(&textPrimitiveData, d->mTextItem);
       
   197             style()->updatePrimitive(d->mTextItem, &textPrimitiveData,this);
   164         }
   198         }
   165         if (d->mIconItem) {
   199         if (d->mIconItem) {
   166             style()->updatePrimitive(d->mIconItem, HbStyle::P_GridViewItem_icon,
   200             HbStyleIconPrimitiveData iconPrimitiveData;
   167                     &styleOption);
   201             initPrimitiveData(&iconPrimitiveData, d->mIconItem);
       
   202             style()->updatePrimitive(d->mIconItem, &iconPrimitiveData,this);
   168         }
   203         }
   169     }
   204     }
   170     HbAbstractViewItem::updatePrimitives();
   205     HbAbstractViewItem::updatePrimitives();
   171 }
       
   172 
       
   173 /*!
       
   174     Populates a style option object for this widget based on its current state, and stores the output in \a option.
       
   175 */
       
   176 void HbGridViewItem::initStyleOption(HbStyleOptionGridViewItem *option) const
       
   177 {
       
   178     Q_D( const HbGridViewItem );
       
   179 
       
   180     HbAbstractViewItem::initStyleOption(option);
       
   181     option->icon = d->mIcon;
       
   182     option->text = d->mText;
       
   183 }
   206 }
   184 
   207 
   185 /*!
   208 /*!
   186  \reimp
   209  \reimp
   187  */
   210  */