messagingapp/msgsettings/settingsview/src/msgsettingsdataformcustomitem.cpp
changeset 23 238255e8b033
child 27 e4592d119491
equal deleted inserted replaced
5:4697dfb2d7ad 23:238255e8b033
       
     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:  This class provides custom list item for the
       
    15  * DataForm
       
    16  *
       
    17  */
       
    18 
       
    19 #include <msgsettingsdataformcustomitem.h>
       
    20 #include <hbdataformmodelitem.h>
       
    21 #include <hbpushbutton.h>
       
    22 #include <hbdataformmodel.h>
       
    23 #include <hbdataform.h>
       
    24 
       
    25 MsgSettingsDataFormCustomItem::MsgSettingsDataFormCustomItem(
       
    26         QGraphicsItem *parent) :
       
    27     HbDataFormViewItem(parent)
       
    28     {
       
    29     }
       
    30 
       
    31 MsgSettingsDataFormCustomItem::~MsgSettingsDataFormCustomItem()
       
    32     {
       
    33     }
       
    34 
       
    35 HbAbstractViewItem* MsgSettingsDataFormCustomItem::createItem()
       
    36     {
       
    37     return new MsgSettingsDataFormCustomItem(*this);
       
    38     }
       
    39 
       
    40 HbWidget* MsgSettingsDataFormCustomItem::createCustomWidget()
       
    41     {
       
    42     HbDataFormModelItem::DataItemType
       
    43             itemType =
       
    44                     static_cast<HbDataFormModelItem::DataItemType> (modelIndex().data(
       
    45                             HbDataFormModelItem::ItemTypeRole).toInt());
       
    46 
       
    47     switch (itemType)
       
    48         {
       
    49         case HbDataFormModelItem::CustomItemBase + 1:
       
    50             {
       
    51             //custom button
       
    52             QString
       
    53                     str =
       
    54                             modelIndex().data(HbDataFormModelItem::KeyRole).toString();
       
    55             HbPushButton *button = new HbPushButton(str);
       
    56 
       
    57             return button;
       
    58             }
       
    59         default:
       
    60             return 0;
       
    61         }
       
    62     }
       
    63 
       
    64 bool MsgSettingsDataFormCustomItem::canSetModelIndex(const QModelIndex &index) const
       
    65     {
       
    66     HbDataFormModelItem::DataItemType itemType =
       
    67             static_cast<HbDataFormModelItem::DataItemType> (index.data(
       
    68                     HbDataFormModelItem::ItemTypeRole).toInt());
       
    69 
       
    70     if (itemType >= HbDataFormModelItem::CustomItemBase && itemType
       
    71             <= HbDataFormModelItem::CustomItemBase + 10)
       
    72         {
       
    73         return true;
       
    74         }
       
    75     return false;
       
    76     }
       
    77 
       
    78 void MsgSettingsDataFormCustomItem::restore()
       
    79     {
       
    80     HbDataFormModelItem
       
    81             * mItem =
       
    82                     static_cast<HbDataFormModel*> (itemView()->model())->itemFromIndex(
       
    83                             modelIndex());
       
    84 
       
    85     if (mItem)
       
    86         {
       
    87         QString str = mItem->contentWidgetData("text").toString();
       
    88         HbPushButton *button = static_cast<HbPushButton*>(dataItemContentWidget());
       
    89         if (button)
       
    90             {
       
    91             button->setText(str);
       
    92             }
       
    93         }
       
    94     }