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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "cppersonalizationcustomviewitem.h" |
|
19 #include "cpmastervolumeslider.h" |
|
20 #include <hbdataformmodelitem.h> |
|
21 #include <hbdataformmodel.h> |
|
22 #include <hbabstractitemview.h> |
|
23 #include <QMetaProperty> |
|
24 |
|
25 CpPersonalizationCustomViewItem::CpPersonalizationCustomViewItem(QGraphicsItem *parent ) |
|
26 : HbDataFormViewItem(parent) |
|
27 { |
|
28 } |
|
29 CpPersonalizationCustomViewItem::~CpPersonalizationCustomViewItem() |
|
30 { |
|
31 } |
|
32 HbAbstractViewItem* CpPersonalizationCustomViewItem::createItem() |
|
33 { |
|
34 return new CpPersonalizationCustomViewItem(*this); |
|
35 } |
|
36 bool CpPersonalizationCustomViewItem::canSetModelIndex(const QModelIndex &index) const |
|
37 { |
|
38 int type = index.data(HbDataFormModelItem::ItemTypeRole).toInt(); |
|
39 if (type == MasterVolumeSliderItem) { |
|
40 return true; |
|
41 } |
|
42 else { |
|
43 return false; |
|
44 } |
|
45 } |
|
46 |
|
47 HbWidget *CpPersonalizationCustomViewItem::createCustomWidget() |
|
48 { |
|
49 int type = modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt(); |
|
50 if (type == MasterVolumeSliderItem) { |
|
51 CpMasterVolumeSlider *masterVolumeSlider = new CpMasterVolumeSlider(); |
|
52 connect(masterVolumeSlider, SIGNAL(valueChanged(int)), this, SLOT(store())); |
|
53 mWidget = masterVolumeSlider; |
|
54 return masterVolumeSlider; |
|
55 } |
|
56 else { |
|
57 return 0; |
|
58 } |
|
59 } |
|
60 |
|
61 void CpPersonalizationCustomViewItem::load() |
|
62 { |
|
63 HbDataFormViewItem::load(); |
|
64 if (mWidget) { |
|
65 HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>( |
|
66 modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt()); |
|
67 |
|
68 if(itemType == MasterVolumeSliderItem) { |
|
69 |
|
70 QModelIndex itemIndex = modelIndex(); |
|
71 HbDataFormModel *model = static_cast<HbDataFormModel*>(itemView()->model());; |
|
72 HbDataFormModelItem *modelItem = static_cast<HbDataFormModelItem*>( |
|
73 model->itemFromIndex(itemIndex)); |
|
74 |
|
75 const QMetaObject *metaObj = mWidget->metaObject(); |
|
76 int count = metaObj->propertyCount(); |
|
77 for (int i = 0; i < count; i++) { |
|
78 QMetaProperty metaProperty = metaObj->property(i); |
|
79 if (metaProperty.isValid() && metaProperty.isWritable()) { |
|
80 metaProperty.write(mWidget,modelItem->contentWidgetData(metaProperty.name())); |
|
81 } |
|
82 |
|
83 } |
|
84 } |
|
85 } |
|
86 } |
|
87 |
|
88 void CpPersonalizationCustomViewItem::store() |
|
89 { |
|
90 HbDataFormViewItem::store(); |
|
91 if (mWidget) { |
|
92 HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>( |
|
93 modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt()); |
|
94 |
|
95 if(itemType == MasterVolumeSliderItem) { |
|
96 |
|
97 QModelIndex itemIndex = modelIndex(); |
|
98 HbDataFormModel *model = static_cast<HbDataFormModel*>(itemView()->model());; |
|
99 HbDataFormModelItem *modelItem = static_cast<HbDataFormModelItem*>( |
|
100 model->itemFromIndex(itemIndex)); |
|
101 if (CpMasterVolumeSlider *slider = qobject_cast<CpMasterVolumeSlider *>(mWidget)) { |
|
102 modelItem->setContentWidgetData("value",slider->value()); |
|
103 } |
|
104 |
|
105 } |
|
106 } |
|
107 } |
|
108 |
|
109 void CpPersonalizationCustomViewItem::onValueChanged(int value) |
|
110 { |
|
111 HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>( |
|
112 modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt()); |
|
113 |
|
114 if(itemType == MasterVolumeSliderItem) { |
|
115 |
|
116 QModelIndex itemIndex = modelIndex(); |
|
117 HbDataFormModel *model = static_cast<HbDataFormModel*>(itemView()->model());; |
|
118 HbDataFormModelItem *modelItem = static_cast<HbDataFormModelItem*>( |
|
119 model->itemFromIndex(itemIndex)); |
|
120 modelItem->setContentWidgetData("value",value); |
|
121 } |
|
122 } |
|