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: Private implementatin for class CpSettingFormEntryItemData. |
|
15 * |
|
16 */ |
|
17 #include "cpsettingformentryitemdata_p.h" |
|
18 #include <QVariant> |
|
19 #include <hbdataformviewitem.h> |
|
20 #include <hbdataform.h> |
|
21 #include <hbdataformmodel.h> |
|
22 #include <hbdataformmodelitem.h> |
|
23 #include <cpitemdatahelper.h> |
|
24 #include <cpsettingformentryitemdata.h> |
|
25 |
|
26 CpSettingFormEntryItemDataPrivate::CpSettingFormEntryItemDataPrivate() |
|
27 : mDataForm(0), |
|
28 mItemDataHelper(0), |
|
29 mItemPressed(false) |
|
30 { |
|
31 |
|
32 } |
|
33 |
|
34 CpSettingFormEntryItemDataPrivate::CpSettingFormEntryItemDataPrivate(CpItemDataHelper *itemDataHelper) |
|
35 : mDataForm(0), |
|
36 mItemDataHelper(itemDataHelper), |
|
37 mItemPressed(false) |
|
38 { |
|
39 |
|
40 } |
|
41 |
|
42 CpSettingFormEntryItemDataPrivate::CpSettingFormEntryItemDataPrivate(HbDataForm *dataForm) |
|
43 : mDataForm(dataForm), |
|
44 mItemDataHelper(0), |
|
45 mItemPressed(false) |
|
46 { |
|
47 |
|
48 } |
|
49 |
|
50 void CpSettingFormEntryItemDataPrivate::init(CpSettingFormEntryItemData *parent) |
|
51 { |
|
52 mParent = parent; |
|
53 |
|
54 HbDataFormModelItem::DataItemType itemType = mParent->type(); |
|
55 switch (itemType) |
|
56 { |
|
57 default: break; |
|
58 case CpSettingFormEntryItemData::ListEntryItem: |
|
59 { |
|
60 if (mItemDataHelper) { |
|
61 mItemDataHelper->connectToForm(SIGNAL(pressed (QModelIndex)),mParent,SLOT(_q_itemPressed(QModelIndex))); |
|
62 mItemDataHelper->connectToForm(SIGNAL(activated(QModelIndex)),mParent,SLOT(_q_itemActivated(QModelIndex))); |
|
63 } |
|
64 else if (mDataForm) { |
|
65 QObject::connect( mDataForm,SIGNAL(pressed(QModelIndex)),mParent,SLOT(_q_itemPressed(QModelIndex)) ); |
|
66 QObject::connect( mDataForm,SIGNAL(activated(QModelIndex)),mParent,SLOT(_q_itemActivated(QModelIndex)) ); |
|
67 } |
|
68 } |
|
69 break; |
|
70 case CpSettingFormEntryItemData::ButtonEntryItem: |
|
71 { |
|
72 if (mItemDataHelper) { |
|
73 mItemDataHelper->addConnection(mParent,SIGNAL(clicked()),mParent,SLOT(onLaunchView())); |
|
74 } |
|
75 else if (mDataForm) { |
|
76 mDataForm->addConnection(mParent,SIGNAL(clicked()),mParent,SLOT(onLaunchView())); |
|
77 } |
|
78 } |
|
79 break; |
|
80 } |
|
81 } |
|
82 |
|
83 QString CpSettingFormEntryItemDataPrivate::text() const |
|
84 { |
|
85 HbDataFormModelItem::DataItemType itemType = mParent->type(); |
|
86 switch (itemType) |
|
87 { |
|
88 default: break; |
|
89 case CpSettingFormEntryItemData::ListEntryItem: |
|
90 return mParent->label(); |
|
91 case CpSettingFormEntryItemData::ButtonEntryItem: |
|
92 return mParent->contentWidgetData(QString("text")).toString(); |
|
93 } |
|
94 return QString(); |
|
95 } |
|
96 |
|
97 void CpSettingFormEntryItemDataPrivate::setText(const QString &text) |
|
98 { |
|
99 HbDataFormModelItem::DataItemType itemType = mParent->type(); |
|
100 switch (itemType) |
|
101 { |
|
102 default: break; |
|
103 case CpSettingFormEntryItemData::ListEntryItem: |
|
104 mParent->setLabel(text); |
|
105 break; |
|
106 case CpSettingFormEntryItemData::ButtonEntryItem: |
|
107 mParent->setContentWidgetData(QString("text"),QVariant(text)); |
|
108 break; |
|
109 } |
|
110 } |
|
111 |
|
112 QString CpSettingFormEntryItemDataPrivate::description() const |
|
113 { |
|
114 HbDataFormModelItem::DataItemType itemType = mParent->type(); |
|
115 switch (itemType) |
|
116 { |
|
117 default: break; |
|
118 case CpSettingFormEntryItemData::ListEntryItem: |
|
119 return mParent->data(HbDataFormModelItem::DescriptionRole).toString(); |
|
120 case CpSettingFormEntryItemData::ButtonEntryItem: |
|
121 return mParent->contentWidgetData(QString("additionalText")).toString(); |
|
122 } |
|
123 return QString(); |
|
124 } |
|
125 |
|
126 void CpSettingFormEntryItemDataPrivate::setDescription(const QString &description) |
|
127 { |
|
128 HbDataFormModelItem::DataItemType itemType = mParent->type(); |
|
129 switch (itemType) |
|
130 { |
|
131 default: break; |
|
132 case CpSettingFormEntryItemData::ListEntryItem: |
|
133 mParent->setData(HbDataFormModelItem::DescriptionRole , description); |
|
134 // set a useless property for model item to emit a datachanged signal |
|
135 // this is a workaround for informing the change event of description in list item |
|
136 mParent->setContentWidgetData("Useless", true); |
|
137 break; |
|
138 case CpSettingFormEntryItemData::ButtonEntryItem: |
|
139 mParent->setContentWidgetData(QString("additionalText"),QVariant(description)); |
|
140 break; |
|
141 } |
|
142 } |
|
143 |
|
144 QString CpSettingFormEntryItemDataPrivate::iconName() const |
|
145 { |
|
146 HbDataFormModelItem::DataItemType itemType = mParent->type(); |
|
147 switch (itemType) |
|
148 { |
|
149 default: break; |
|
150 case CpSettingFormEntryItemData::ListEntryItem: |
|
151 return mParent->icon(); |
|
152 case CpSettingFormEntryItemData::ButtonEntryItem: |
|
153 return qvariant_cast<HbIcon>(mParent->contentWidgetData(QString("icon"))).iconName(); |
|
154 } |
|
155 return QString(); |
|
156 } |
|
157 |
|
158 void CpSettingFormEntryItemDataPrivate::setIconName(const QString &icon) |
|
159 { |
|
160 HbDataFormModelItem::DataItemType itemType = mParent->type(); |
|
161 switch (itemType) |
|
162 { |
|
163 default: break; |
|
164 case CpSettingFormEntryItemData::ListEntryItem: |
|
165 mParent->setIcon(icon); |
|
166 break; |
|
167 case CpSettingFormEntryItemData::ButtonEntryItem: |
|
168 mParent->setContentWidgetData(QString("icon"),HbIcon(icon)); |
|
169 break; |
|
170 } |
|
171 } |
|
172 |
|
173 HbIcon CpSettingFormEntryItemDataPrivate::entryItemIcon() const |
|
174 { |
|
175 HbDataFormModelItem::DataItemType itemType = mParent->type(); |
|
176 switch (itemType) |
|
177 { |
|
178 default: break; |
|
179 case CpSettingFormEntryItemData::ListEntryItem: |
|
180 return HbIcon(mParent->icon()); |
|
181 case CpSettingFormEntryItemData::ButtonEntryItem: |
|
182 return qvariant_cast<HbIcon>(mParent->contentWidgetData(QString("icon"))); |
|
183 } |
|
184 return HbIcon(); |
|
185 } |
|
186 |
|
187 void CpSettingFormEntryItemDataPrivate::setEntryItemIcon(const HbIcon &icon) |
|
188 { |
|
189 HbDataFormModelItem::DataItemType itemType = mParent->type(); |
|
190 switch (itemType) |
|
191 { |
|
192 default: break; |
|
193 case CpSettingFormEntryItemData::ListEntryItem: |
|
194 mParent->setIcon(icon.iconName()); |
|
195 break; |
|
196 case CpSettingFormEntryItemData::ButtonEntryItem: |
|
197 mParent->setContentWidgetData(QString("icon"),icon); |
|
198 break; |
|
199 } |
|
200 } |
|
201 |
|
202 |
|
203 void CpSettingFormEntryItemDataPrivate::_q_itemPressed(const QModelIndex &index) |
|
204 { |
|
205 mItemPressed = ( modelItemFromModelIndex(index) == mParent ); |
|
206 } |
|
207 |
|
208 |
|
209 void CpSettingFormEntryItemDataPrivate::_q_itemActivated(const QModelIndex &index) |
|
210 { |
|
211 if (mItemPressed && modelItemFromModelIndex(index) == mParent) { |
|
212 mParent->onLaunchView(); |
|
213 } |
|
214 mItemPressed = false; |
|
215 } |
|
216 |
|
217 |
|
218 HbDataFormModelItem *CpSettingFormEntryItemDataPrivate::modelItemFromModelIndex(const QModelIndex &index) |
|
219 { |
|
220 if (mItemDataHelper) { |
|
221 return mItemDataHelper->modelItemFromModelIndex(index); |
|
222 } |
|
223 else if (mDataForm){ |
|
224 HbDataFormModel *dataFormModel = |
|
225 qobject_cast<HbDataFormModel*>(mDataForm->model()); |
|
226 if (dataFormModel) { |
|
227 return dataFormModel->itemFromIndex(index); |
|
228 } |
|
229 } |
|
230 |
|
231 return 0; |
|
232 } |
|
233 |
|
234 #include "moc_cpsettingformentryitemdata.cpp" |
|
235 |
|
236 //End of File |
|