controlpanel/src/cpframework/src/cpdataformlistentryviewitem.cpp
branchRCL_3
changeset 25 7e0eff37aedb
parent 24 8ee96d21d9bf
child 26 e78c61e77b1a
equal deleted inserted replaced
24:8ee96d21d9bf 25:7e0eff37aedb
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0""
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  View item implementation for list entry item.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cpdataformlistentryviewitem.h"
       
    19 
       
    20 #ifdef HB_EFFECTS
       
    21     #include "hbeffect.h"
       
    22 #endif
       
    23 
       
    24 #ifdef HB_GESTURE_FW
       
    25     #include <hbtapgesture.h>
       
    26     #include <hbframeitem.h>
       
    27 #endif
       
    28 
       
    29 #include <hbdataformmodel.h>
       
    30 #include <hbdataformmodelitem.h>
       
    31 #include <hbabstractitemview.h>
       
    32 #include <cpsettingformentryitemdata.h>
       
    33 
       
    34 #define CP_DATAFORMLISTENTRYVIEWITEM QLatin1String("cpdataformlistentryviewitem")
       
    35 
       
    36 /**
       
    37  * Constructor
       
    38  */
       
    39 CpDataFormListEntryViewItem::CpDataFormListEntryViewItem(QGraphicsItem *parent) : 
       
    40     HbDataFormViewItem(parent)
       
    41 {
       
    42     // Add effeect just like item in HbListView
       
    43 #ifdef HB_EFFECTS       
       
    44     HbEffect::add(CP_DATAFORMLISTENTRYVIEWITEM + "-focus", "listviewitem_press", "pressed");
       
    45     HbEffect::add(CP_DATAFORMLISTENTRYVIEWITEM + "-focus", "listviewitem_release", "released");
       
    46 #endif
       
    47 }
       
    48 
       
    49 /**
       
    50  * Destructor
       
    51  */
       
    52 CpDataFormListEntryViewItem::~CpDataFormListEntryViewItem()
       
    53 {
       
    54 }
       
    55 
       
    56 /**
       
    57  * Reimplement by CpDataFormListEntryViewItem, this function return a instance copy.
       
    58  */
       
    59 HbAbstractViewItem* CpDataFormListEntryViewItem::createItem()
       
    60 {
       
    61     return new CpDataFormListEntryViewItem(*this);
       
    62 }
       
    63 
       
    64 /**
       
    65  * Reimplement by CpDataFormListEntryViewItem, return true when the model item type is 
       
    66  * ListEntryItem
       
    67  */
       
    68 bool CpDataFormListEntryViewItem::canSetModelIndex(const QModelIndex &index) const
       
    69 {
       
    70     HbDataFormModelItem::DataItemType itemType = 
       
    71         static_cast<HbDataFormModelItem::DataItemType>( 
       
    72                 index.data(HbDataFormModelItem::ItemTypeRole).toInt());
       
    73 
       
    74     return ( itemType == CpSettingFormEntryItemData::ListEntryItem );
       
    75 }
       
    76 
       
    77 /**
       
    78  * Reimplement by CpDataFormListEntryViewItem
       
    79  * No content widget in custom list item. So return a null pointer directly
       
    80  */
       
    81 HbWidget* CpDataFormListEntryViewItem::createCustomWidget()
       
    82 {
       
    83     // Don't need to create any widget
       
    84     return 0;
       
    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());
       
    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  */
       
   115 void CpDataFormListEntryViewItem::pressStateChanged(bool pressed, bool animate)
       
   116 {
       
   117 #ifdef HB_EFFECTS
       
   118     QGraphicsItem *focusItem =  primitive("dataItem_Background");
       
   119     bool doAnimate = animate;
       
   120 
       
   121     if (pressed) {
       
   122         if (doAnimate) {
       
   123             HbEffect::cancel(this, "released");
       
   124             HbEffect::cancel(focusItem, "released");
       
   125 
       
   126             HbEffect::start(this, CP_DATAFORMLISTENTRYVIEWITEM, "pressed");
       
   127             HbEffect::start(focusItem, CP_DATAFORMLISTENTRYVIEWITEM + QString("-focus"), "pressed");
       
   128         }
       
   129     } else {
       
   130         if (doAnimate) {
       
   131             HbEffect::cancel(this, "pressed");
       
   132             HbEffect::cancel(focusItem, "pressed");
       
   133 
       
   134             HbEffect::start(this, CP_DATAFORMLISTENTRYVIEWITEM, "released");
       
   135             HbEffect::start(focusItem, CP_DATAFORMLISTENTRYVIEWITEM + QString("-focus"), "released");
       
   136         } else {
       
   137             HbEffect::cancel(this, "pressed");
       
   138             HbEffect::start(this, CP_DATAFORMLISTENTRYVIEWITEM, "released");
       
   139             if (focusItem) {
       
   140                 HbEffect::cancel(focusItem, "pressed");
       
   141                 HbEffect::start(focusItem, CP_DATAFORMLISTENTRYVIEWITEM + QString("-focus"), "released", this);
       
   142             }
       
   143         }
       
   144     }
       
   145 #endif
       
   146 }
       
   147 
       
   148 #ifdef HB_GESTURE_FW
       
   149 
       
   150 /**
       
   151  * Reimplement by CpDataFormListEntryViewItem, set different graphics for list item's gesture
       
   152  */
       
   153 void CpDataFormListEntryViewItem::gestureEvent(QGestureEvent *event)
       
   154 {
       
   155     HbFrameItem *backgroundItem = static_cast<HbFrameItem*> ( primitive("dataItem_Background") );
       
   156     HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture));
       
   157     
       
   158     if(backgroundItem && tap) {
       
   159         switch(tap->state()) {
       
   160         case Qt::GestureStarted: {
       
   161                 // Set the pressed state
       
   162                 backgroundItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_list_pressed"));
       
   163             }
       
   164             break;
       
   165         case Qt::GestureUpdated: {
       
   166             
       
   167             }
       
   168             break;
       
   169         case Qt::GestureCanceled: {
       
   170                 // Set the normal state
       
   171                 backgroundItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_list_normal"));
       
   172             }
       
   173             break;
       
   174         case Qt::GestureFinished: {
       
   175                 // Set the normal state
       
   176                 backgroundItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_list_normal"));
       
   177             }
       
   178             break;
       
   179         default:
       
   180             break;
       
   181         }
       
   182     }
       
   183 
       
   184     HbDataFormViewItem::gestureEvent( event );
       
   185 }
       
   186 #endif
       
   187 
       
   188 
       
   189 //End of File