|
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 "cxutils.h" |
|
19 #include "cxeengine.h" |
|
20 #include "cxuisettingsinfo.h" |
|
21 #include "cxesettings.h" |
|
22 #include "cxuisettingradiobuttonlist.h" |
|
23 #include "cxuisettingradiobuttonlistmodel.h" |
|
24 |
|
25 CxuiSettingRadioButtonList::CxuiSettingRadioButtonList(QGraphicsItem *parent, CxeEngine *engine) |
|
26 : HbRadioButtonList(parent), |
|
27 mEngine(engine), |
|
28 mSettingId(), |
|
29 mSettingValues(), |
|
30 mOriginalIndex(0) |
|
31 { |
|
32 CX_ASSERT_ALWAYS(mEngine); |
|
33 |
|
34 mListModel = new CxuiSettingRadioButtonListModel(); |
|
35 setModel(mListModel); |
|
36 |
|
37 // connect the signals again |
|
38 connect(this, SIGNAL(itemSelected(int)), this, SLOT(handleItemSelected(int))); |
|
39 } |
|
40 |
|
41 |
|
42 void CxuiSettingRadioButtonList::init(CxUiSettings::RadioButtonListParams *data) |
|
43 { |
|
44 // first we reset the model and clear any previous data |
|
45 mSettingValues.clear(); |
|
46 mListModel->resetModel(); |
|
47 |
|
48 disconnect(SIGNAL(valueSelected(int))); |
|
49 |
|
50 if (data) { |
|
51 QStringList settingStrings; |
|
52 mSettingValues.clear(); |
|
53 |
|
54 CxUiSettings::SettingItem setting; |
|
55 foreach (setting, data->mSettingPairList) { |
|
56 settingStrings.append(setting.mItem); // setting string |
|
57 mSettingValues.append(setting.mValue); // engine value for setting |
|
58 } |
|
59 |
|
60 // Set the setting strings to the model. |
|
61 setItems(settingStrings); |
|
62 // Set the preview mode. |
|
63 // Note: We implement preview ourselves, not with HbRadioButtonList preview mode. |
|
64 setPreviewMode(HbRadioButtonList::NoPreview); |
|
65 mPreview = data->mPreview; |
|
66 |
|
67 setSettingId(data->mSettingId); |
|
68 setListBoxType(data->mListboxType); |
|
69 } |
|
70 |
|
71 } |
|
72 |
|
73 void CxuiSettingRadioButtonList::setItems(const QStringList &values) |
|
74 { |
|
75 mListModel->setItems(values); |
|
76 } |
|
77 |
|
78 void CxuiSettingRadioButtonList::setListBoxType(int type) |
|
79 { |
|
80 mListModel->setListBoxType(type); |
|
81 } |
|
82 |
|
83 |
|
84 void CxuiSettingRadioButtonList::setSettingId(const QString &id) |
|
85 { |
|
86 // Selected item is updated, when this list is shown. |
|
87 mSettingId = id; |
|
88 } |
|
89 |
|
90 |
|
91 |
|
92 void CxuiSettingRadioButtonList::handleItemSelected(int index) |
|
93 { |
|
94 CX_DEBUG_ENTER_FUNCTION(); |
|
95 |
|
96 if (mPreview) { |
|
97 commit(index); |
|
98 } else { |
|
99 // no action needed |
|
100 } |
|
101 CX_DEBUG_EXIT_FUNCTION(); |
|
102 } |
|
103 |
|
104 void CxuiSettingRadioButtonList::showEvent(QShowEvent *event) |
|
105 { |
|
106 CX_DEBUG_ENTER_FUNCTION(); |
|
107 |
|
108 initOriginalSelectedItem(); |
|
109 QGraphicsWidget::showEvent(event); |
|
110 |
|
111 CX_DEBUG_EXIT_FUNCTION(); |
|
112 } |
|
113 |
|
114 |
|
115 /*! |
|
116 * Get the value currently active in settings. |
|
117 */ |
|
118 void CxuiSettingRadioButtonList::initOriginalSelectedItem() |
|
119 { |
|
120 CX_DEBUG_ENTER_FUNCTION(); |
|
121 |
|
122 QString value; |
|
123 int err = mEngine->settings().get(mSettingId, value); |
|
124 |
|
125 int index = 0; |
|
126 |
|
127 if (err == CxeError::None) { |
|
128 index = mSettingValues.indexOf(QVariant(value)); |
|
129 } |
|
130 |
|
131 mOriginalIndex = index; |
|
132 setSelected(mOriginalIndex); |
|
133 |
|
134 CX_DEBUG_EXIT_FUNCTION(); |
|
135 } |
|
136 |
|
137 /*! |
|
138 This slot can be used to set the selection accepted. |
|
139 */ |
|
140 void CxuiSettingRadioButtonList::handleSelectionAccepted() |
|
141 { |
|
142 CX_DEBUG_ENTER_FUNCTION(); |
|
143 |
|
144 // Ok button pressed. Update originally selected item, |
|
145 // which is the one that always get's set when closing. |
|
146 mOriginalIndex = selected(); |
|
147 |
|
148 emit selectionCommitted(); |
|
149 |
|
150 CX_DEBUG_EXIT_FUNCTION(); |
|
151 } |
|
152 |
|
153 void CxuiSettingRadioButtonList::handleClose() |
|
154 { |
|
155 CX_DEBUG_ENTER_FUNCTION(); |
|
156 |
|
157 if (!mSettingId.isEmpty()) { |
|
158 // If handleSelectionAccepted was called, this now contains the new index, |
|
159 // otherwise the original one is selected. |
|
160 commit(mOriginalIndex); |
|
161 } |
|
162 |
|
163 // clear settings id so setting value doesn't get updated by |
|
164 // accident when updating ui appearance |
|
165 mSettingId.clear(); |
|
166 |
|
167 CX_DEBUG_EXIT_FUNCTION(); |
|
168 } |
|
169 |
|
170 |
|
171 |
|
172 /*! |
|
173 Commits value to the cenrep store. |
|
174 */ |
|
175 void CxuiSettingRadioButtonList::commit(int index) |
|
176 { |
|
177 CX_DEBUG_ENTER_FUNCTION(); |
|
178 |
|
179 CX_DEBUG(("id: %s", mSettingId.toAscii().data())); |
|
180 |
|
181 if (!mSettingId.isEmpty() && !mSettingValues.isEmpty()) { |
|
182 QVariant value = mSettingValues.at(index); |
|
183 if (value.canConvert<int>()) { |
|
184 CX_DEBUG(("index:%d value:%d", index, value.toInt())); |
|
185 |
|
186 // Don't set the value again, if it is the current value. |
|
187 // For e.g. video quality it would result in re-preparation etc. |
|
188 int current(0); |
|
189 CxeError::Id status(mEngine->settings().get(mSettingId, current)); |
|
190 |
|
191 if (status != CxeError::None || current != value.toInt()) { |
|
192 mEngine->settings().set(mSettingId, value.toInt()); |
|
193 } |
|
194 // inform interested clients about value changed event |
|
195 emit valueSelected(value.toInt()); |
|
196 } else if(value.canConvert<QString>()) { |
|
197 CX_DEBUG(("index:%d value:[%s]", index, value.toString().toAscii().constData())); |
|
198 mEngine->settings().set(mSettingId, value.toString()); |
|
199 } |
|
200 } |
|
201 |
|
202 CX_DEBUG_EXIT_FUNCTION(); |
|
203 } |
|
204 |
|
205 // end of file |