1 /* |
1 /* |
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
36 |
36 |
37 // connect the signals again |
37 // connect the signals again |
38 connect(this, SIGNAL(itemSelected(int)), this, SLOT(handleItemSelected(int))); |
38 connect(this, SIGNAL(itemSelected(int)), this, SLOT(handleItemSelected(int))); |
39 } |
39 } |
40 |
40 |
41 |
41 /*! |
|
42 * Init contents of the listbox and select current setting value. |
|
43 */ |
42 void CxuiSettingRadioButtonList::init(CxUiSettings::RadioButtonListParams *data) |
44 void CxuiSettingRadioButtonList::init(CxUiSettings::RadioButtonListParams *data) |
43 { |
45 { |
44 // first we reset the model and clear any previous data |
46 // first we reset the model and clear any previous data |
45 mSettingValues.clear(); |
47 mSettingValues.clear(); |
46 mListModel->resetModel(); |
48 mListModel->resetModel(); |
66 mPreview = data->mPreview; |
68 mPreview = data->mPreview; |
67 |
69 |
68 setSettingId(data->mSettingId); |
70 setSettingId(data->mSettingId); |
69 setListBoxType(data->mListboxType); |
71 setListBoxType(data->mListboxType); |
70 |
72 |
71 initOriginalSelectedItem(); |
73 // Store the original setting value and focus matching item. |
72 // ensure that currently selected item is visible |
74 QString value; |
73 scrollTo(currentIndex()); |
75 mEngine->settings().get(mSettingId, value); |
74 } |
76 CX_DEBUG(("CxuiSettingRadioButtonList - original value: [%s]", value.toAscii().data())); |
75 |
77 setOriginalSelectedItemByValue(QVariant(value)); |
|
78 } |
76 } |
79 } |
77 |
80 |
78 /*! |
81 /*! |
79 * Sets the original selection of list by value. Can be used to override value read from |
82 * Sets the original selection of list by value. Can be used to override value read from |
80 * CxeSettings or used to remember previously selected value in case of setting that is |
83 * CxeSettings or used to remember previously selected value in case of setting that is |
89 mOriginalIndex = index; |
92 mOriginalIndex = index; |
90 setSelected(index); |
93 setSelected(index); |
91 // ensure that currently selected item is visible |
94 // ensure that currently selected item is visible |
92 scrollTo(currentIndex()); |
95 scrollTo(currentIndex()); |
93 } else { |
96 } else { |
94 CX_DEBUG(("Value %s not found", value.toString().toAscii().data())); |
97 CX_DEBUG(("[WARNING] Value %s not found, defaulting to first item", value.toString().toAscii().data())); |
95 } |
98 } |
96 CX_DEBUG_EXIT_FUNCTION(); |
99 CX_DEBUG_EXIT_FUNCTION(); |
97 } |
100 } |
98 |
101 |
|
102 /*! |
|
103 * Set list texts. |
|
104 * @param values List of the texts. |
|
105 */ |
99 void CxuiSettingRadioButtonList::setItems(const QStringList &values) |
106 void CxuiSettingRadioButtonList::setItems(const QStringList &values) |
100 { |
107 { |
101 mListModel->setItems(values); |
108 mListModel->setItems(values); |
102 } |
109 } |
103 |
110 |
|
111 /*! |
|
112 * Set the type of this list. |
|
113 * @param type Type identifier, SingleLine or TwoLine. |
|
114 */ |
104 void CxuiSettingRadioButtonList::setListBoxType(int type) |
115 void CxuiSettingRadioButtonList::setListBoxType(int type) |
105 { |
116 { |
106 mListModel->setListBoxType(type); |
117 mListModel->setListBoxType(type); |
107 } |
118 } |
108 |
119 |
109 |
120 /*! |
|
121 * Set id of the setting this list represents. |
|
122 * @param id Id of the setting. |
|
123 */ |
110 void CxuiSettingRadioButtonList::setSettingId(const QString &id) |
124 void CxuiSettingRadioButtonList::setSettingId(const QString &id) |
111 { |
125 { |
112 // Selected item is updated, when this list is shown. |
126 // Selected item is updated, when this list is shown. |
113 mSettingId = id; |
127 mSettingId = id; |
114 } |
128 } |
115 |
129 |
116 |
130 /*! |
117 |
131 * Handle selecting an item. |
|
132 * @param index Index of the selected item in list. |
|
133 */ |
118 void CxuiSettingRadioButtonList::handleItemSelected(int index) |
134 void CxuiSettingRadioButtonList::handleItemSelected(int index) |
119 { |
135 { |
120 CX_DEBUG_ENTER_FUNCTION(); |
136 CX_DEBUG_ENTER_FUNCTION(); |
121 |
137 |
122 if (mPreview) { |
138 if (mPreview) { |
126 } |
142 } |
127 CX_DEBUG_EXIT_FUNCTION(); |
143 CX_DEBUG_EXIT_FUNCTION(); |
128 } |
144 } |
129 |
145 |
130 /*! |
146 /*! |
131 * Get the value currently active in settings. |
|
132 */ |
|
133 void CxuiSettingRadioButtonList::initOriginalSelectedItem() |
|
134 { |
|
135 CX_DEBUG_ENTER_FUNCTION(); |
|
136 |
|
137 QString value; |
|
138 int err = mEngine->settings().get(mSettingId, value); |
|
139 CX_DEBUG(("CxuiSettingRadioButtonList - original value: [%s]", value.toAscii().data())); |
|
140 |
|
141 int index = 0; |
|
142 |
|
143 if (err == CxeError::None) { |
|
144 index = mSettingValues.indexOf(QVariant(value)); |
|
145 CX_DEBUG(("CxuiSettingRadioButtonList - got original index of: %d", index)); |
|
146 } |
|
147 |
|
148 mOriginalIndex = index; |
|
149 setSelected(mOriginalIndex); |
|
150 |
|
151 CX_DEBUG_EXIT_FUNCTION(); |
|
152 } |
|
153 |
|
154 /*! |
|
155 This slot can be used to set the selection accepted. |
147 This slot can be used to set the selection accepted. |
156 */ |
148 */ |
157 void CxuiSettingRadioButtonList::handleSelectionAccepted() |
149 void CxuiSettingRadioButtonList::handleSelectionAccepted() |
158 { |
150 { |
159 CX_DEBUG_ENTER_FUNCTION(); |
151 CX_DEBUG_ENTER_FUNCTION(); |
165 emit selectionCommitted(); |
157 emit selectionCommitted(); |
166 |
158 |
167 CX_DEBUG_EXIT_FUNCTION(); |
159 CX_DEBUG_EXIT_FUNCTION(); |
168 } |
160 } |
169 |
161 |
|
162 /*! |
|
163 * Handle closing the listbox. If the current selection was accepted, |
|
164 * we commit the new value here. If current selection has been cancelled, |
|
165 * we commit the original value. |
|
166 */ |
170 void CxuiSettingRadioButtonList::handleClose() |
167 void CxuiSettingRadioButtonList::handleClose() |
171 { |
168 { |
172 CX_DEBUG_ENTER_FUNCTION(); |
169 CX_DEBUG_ENTER_FUNCTION(); |
173 |
170 |
174 if (!mSettingId.isEmpty()) { |
171 if (!mSettingId.isEmpty()) { |