controlpanel/src/cpframework/src/cpdataformlistentryviewitem.cpp
changeset 55 4c15d9aa2384
parent 40 6465d5bb863a
equal deleted inserted replaced
47:dbe66a66f6a9 55:4c15d9aa2384
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  
    14 * Description:  View item implementation for list entry item.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include "cpdataformlistentryviewitem.h"
    18 #include "cpdataformlistentryviewitem.h"
    19 
    19 
    31 #include <hbabstractitemview.h>
    31 #include <hbabstractitemview.h>
    32 #include <cpsettingformentryitemdata.h>
    32 #include <cpsettingformentryitemdata.h>
    33 
    33 
    34 #define CP_DATAFORMLISTENTRYVIEWITEM QLatin1String("cpdataformlistentryviewitem")
    34 #define CP_DATAFORMLISTENTRYVIEWITEM QLatin1String("cpdataformlistentryviewitem")
    35 
    35 
       
    36 /**
       
    37  * Constructor
       
    38  */
    36 CpDataFormListEntryViewItem::CpDataFormListEntryViewItem(QGraphicsItem *parent) : 
    39 CpDataFormListEntryViewItem::CpDataFormListEntryViewItem(QGraphicsItem *parent) : 
    37     HbDataFormViewItem(parent)
    40     HbDataFormViewItem(parent)
    38 {
    41 {
       
    42     // Add effeect just like item in HbListView
    39 #ifdef HB_EFFECTS       
    43 #ifdef HB_EFFECTS       
    40     HbEffect::add(CP_DATAFORMLISTENTRYVIEWITEM + "-focus", "listviewitem_press", "pressed");
    44     HbEffect::add(CP_DATAFORMLISTENTRYVIEWITEM + "-focus", "listviewitem_press", "pressed");
    41     HbEffect::add(CP_DATAFORMLISTENTRYVIEWITEM + "-focus", "listviewitem_release", "released");
    45     HbEffect::add(CP_DATAFORMLISTENTRYVIEWITEM + "-focus", "listviewitem_release", "released");
    42 #endif
    46 #endif
    43 }
    47 }
    44 
    48 
       
    49 /**
       
    50  * Destructor
       
    51  */
    45 CpDataFormListEntryViewItem::~CpDataFormListEntryViewItem()
    52 CpDataFormListEntryViewItem::~CpDataFormListEntryViewItem()
    46 {
    53 {
    47 }
    54 }
    48 
    55 
       
    56 /**
       
    57  * Reimplement by CpDataFormListEntryViewItem, this function return a instance copy.
       
    58  */
    49 HbAbstractViewItem* CpDataFormListEntryViewItem::createItem()
    59 HbAbstractViewItem* CpDataFormListEntryViewItem::createItem()
    50 {
    60 {
    51     return new CpDataFormListEntryViewItem(*this);
    61     return new CpDataFormListEntryViewItem(*this);
    52 }
    62 }
    53 
    63 
       
    64 /**
       
    65  * Reimplement by CpDataFormListEntryViewItem, return true when the model item type is 
       
    66  * ListEntryItem
       
    67  */
    54 bool CpDataFormListEntryViewItem::canSetModelIndex(const QModelIndex &index) const
    68 bool CpDataFormListEntryViewItem::canSetModelIndex(const QModelIndex &index) const
    55 {
    69 {
    56     HbDataFormModelItem::DataItemType itemType = 
    70     HbDataFormModelItem::DataItemType itemType = 
    57         static_cast<HbDataFormModelItem::DataItemType>( 
    71         static_cast<HbDataFormModelItem::DataItemType>( 
    58                 index.data(HbDataFormModelItem::ItemTypeRole).toInt());
    72                 index.data(HbDataFormModelItem::ItemTypeRole).toInt());
    59 
    73 
    60     return ( itemType == CpSettingFormEntryItemData::ListEntryItem );
    74     return ( itemType == CpSettingFormEntryItemData::ListEntryItem );
    61 }
    75 }
    62 
    76 
       
    77 /**
       
    78  * Reimplement by CpDataFormListEntryViewItem
       
    79  * No content widget in custom list item. So return a null pointer directly
       
    80  */
    63 HbWidget* CpDataFormListEntryViewItem::createCustomWidget()
    81 HbWidget* CpDataFormListEntryViewItem::createCustomWidget()
    64 {
    82 {
    65     HbDataFormModelItem::DataItemType itemType =
    83     // Don't need to create any widget
    66             static_cast<HbDataFormModelItem::DataItemType> (modelIndex().data(
       
    67                     HbDataFormModelItem::ItemTypeRole).toInt());
       
    68     switch (itemType)
       
    69     {
       
    70         case CpSettingFormEntryItemData::ListEntryItem: {
       
    71             break;
       
    72         }
       
    73         default: {
       
    74             break;
       
    75         }
       
    76     }
       
    77     
       
    78     return 0;
    84     return 0;
    79 }
    85 }
       
    86 /**
       
    87  * Reimplement by CpDataFormListEntryViewItem. Change the description property for 
       
    88  * custom list item.
       
    89  */
       
    90 void CpDataFormListEntryViewItem::restore()
       
    91 {
       
    92     HbDataFormModelItem::DataItemType itemType =
       
    93         static_cast<HbDataFormModelItem::DataItemType> (modelIndex().data(
       
    94             HbDataFormModelItem::ItemTypeRole).toInt());
    80 
    95 
       
    96     if (itemType == CpSettingFormEntryItemData::ListEntryItem) {
       
    97         QModelIndex itemIndex = modelIndex();
       
    98         HbDataFormModel *model = qobject_cast<HbDataFormModel*> (itemView()->model());
       
    99         if (model) {
       
   100             HbDataFormModelItem *modelItem = model->itemFromIndex(itemIndex);
       
   101             if (modelItem->data(HbDataFormModelItem::DescriptionRole).toString().isEmpty()) {
       
   102                 this->setProperty("hasDescription", false);
       
   103             }
       
   104             else {
       
   105                 this->setProperty("hasDescription", true);
       
   106             }    
       
   107         }        
       
   108     }
       
   109     HbDataFormViewItem::restore();
       
   110 }
       
   111 
       
   112 /**
       
   113  * Reimplement by CpDataFormListEntryViewItem, provide the effect when pressing list item
       
   114  */
    81 void CpDataFormListEntryViewItem::pressStateChanged(bool pressed, bool animate)
   115 void CpDataFormListEntryViewItem::pressStateChanged(bool pressed, bool animate)
    82 {
   116 {
    83 #ifdef HB_EFFECTS
   117 #ifdef HB_EFFECTS
    84     QGraphicsItem *focusItem =  primitive("dataItem_Background");
   118     QGraphicsItem *focusItem =  primitive("dataItem_Background");
    85     bool doAnimate = animate;
   119     bool doAnimate = animate;
   110     }
   144     }
   111 #endif
   145 #endif
   112 }
   146 }
   113 
   147 
   114 #ifdef HB_GESTURE_FW
   148 #ifdef HB_GESTURE_FW
       
   149 
       
   150 /**
       
   151  * Reimplement by CpDataFormListEntryViewItem, set different graphics for list item's gesture
       
   152  */
   115 void CpDataFormListEntryViewItem::gestureEvent(QGestureEvent *event)
   153 void CpDataFormListEntryViewItem::gestureEvent(QGestureEvent *event)
   116 {
   154 {
   117     HbFrameItem *backgroundItem = static_cast<HbFrameItem*> ( primitive("dataItem_Background") );
   155     HbFrameItem *backgroundItem = static_cast<HbFrameItem*> ( primitive("dataItem_Background") );
   118     HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture));
   156     HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture));
   119     
   157     
   120     if(backgroundItem && tap) {
   158     if(backgroundItem && tap) {
   121         switch(tap->state()) {
   159         switch(tap->state()) {
   122         case Qt::GestureStarted: {
   160         case Qt::GestureStarted: {
       
   161                 // Set the pressed state
   123                 backgroundItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_list_pressed"));
   162                 backgroundItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_list_pressed"));
   124             }
   163             }
   125             break;
   164             break;
   126         case Qt::GestureUpdated: {
   165         case Qt::GestureUpdated: {
   127             
   166             
   128             }
   167             }
   129             break;
   168             break;
   130         case Qt::GestureCanceled: {
   169         case Qt::GestureCanceled: {
       
   170                 // Set the normal state
   131                 backgroundItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_list_normal"));
   171                 backgroundItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_list_normal"));
   132             }
   172             }
   133             break;
   173             break;
   134         case Qt::GestureFinished: {
   174         case Qt::GestureFinished: {
       
   175                 // Set the normal state
   135                 backgroundItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_list_normal"));
   176                 backgroundItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_list_normal"));
   136             }
   177             }
   137             break;
   178             break;
   138         default:
   179         default:
   139             break;
   180             break;