|
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 HbPushButton *button = new HbPushButton(); |
|
53 |
|
54 return button; |
|
55 } |
|
56 default: |
|
57 return 0; |
|
58 } |
|
59 } |
|
60 |
|
61 bool MsgSettingsDataFormCustomItem::canSetModelIndex(const QModelIndex &index) const |
|
62 { |
|
63 HbDataFormModelItem::DataItemType itemType = |
|
64 static_cast<HbDataFormModelItem::DataItemType> (index.data( |
|
65 HbDataFormModelItem::ItemTypeRole).toInt()); |
|
66 |
|
67 if (itemType >= HbDataFormModelItem::CustomItemBase && itemType |
|
68 <= HbDataFormModelItem::CustomItemBase + 10) |
|
69 { |
|
70 return true; |
|
71 } |
|
72 return false; |
|
73 } |
|
74 |
|
75 void MsgSettingsDataFormCustomItem::restore() |
|
76 { |
|
77 HbDataFormModelItem |
|
78 * mItem = |
|
79 static_cast<HbDataFormModel*> (itemView()->model())->itemFromIndex( |
|
80 modelIndex()); |
|
81 |
|
82 if (mItem) |
|
83 { |
|
84 QString str = mItem->contentWidgetData("text").toString(); |
|
85 HbPushButton *button = static_cast<HbPushButton*>(dataItemContentWidget()); |
|
86 if (button) |
|
87 { |
|
88 button->setText(str); |
|
89 } |
|
90 } |
|
91 } |