equal
deleted
inserted
replaced
31 #include <QString> |
31 #include <QString> |
32 #include <QModelIndex> |
32 #include <QModelIndex> |
33 #include <QStandardItemModel> |
33 #include <QStandardItemModel> |
34 #include <QStandardItem> |
34 #include <QStandardItem> |
35 #include <QTranslator> |
35 #include <QTranslator> |
|
36 #include <QSortFilterProxyModel> |
36 |
37 |
37 #include <hbmainwindow.h> |
38 #include <hbmainwindow.h> |
38 #include <hbinstance.h> |
39 #include <hbinstance.h> |
39 #include "cpthemechanger.h" |
40 #include "cpthemechanger.h" |
40 |
41 |
61 constructor. |
62 constructor. |
62 */ |
63 */ |
63 CpThemeControl::CpThemeControl(): mThemeListView(0), |
64 CpThemeControl::CpThemeControl(): mThemeListView(0), |
64 mThemePreview(0), |
65 mThemePreview(0), |
65 mThemeChanger(0), |
66 mThemeChanger(0), |
66 mListModel(0) |
67 mListModel(0), |
|
68 mSortModel(0) |
67 { |
69 { |
68 mThemeChanger = new CpThemeChanger(); |
70 mThemeChanger = new CpThemeChanger(); |
69 |
71 |
70 |
72 |
71 QTranslator *translator = new QTranslator(this); |
73 QTranslator *translator = new QTranslator(this); |
101 { |
103 { |
102 |
104 |
103 mThemeListView = new CpThemeListView(); |
105 mThemeListView = new CpThemeListView(); |
104 |
106 |
105 mListModel = &mThemeChanger->model(); |
107 mListModel = &mThemeChanger->model(); |
|
108 |
|
109 mSortModel = new QSortFilterProxyModel(this); |
|
110 mSortModel->setDynamicSortFilter(true); |
|
111 mSortModel->setSortCaseSensitivity(Qt::CaseInsensitive); |
|
112 mSortModel->sort(0); |
|
113 mSortModel->setSourceModel(mListModel); |
106 |
114 |
107 // Set the model for theme list. |
115 // Set the model for theme list. |
108 mThemeListView->setModel(mListModel); |
116 mThemeListView->setModel(mSortModel); |
|
117 mThemeListView->themeList()->setSelectionMode(HbAbstractItemView::SingleSelection); |
|
118 |
|
119 setActiveThemeIndex(); |
|
120 |
109 |
121 |
110 //connect to signal for selecting a list item. |
122 //connect to signal for selecting a list item. |
111 connect(mThemeListView,SIGNAL(newThemeSelected(const QModelIndex&)), |
123 connect(mThemeListView,SIGNAL(newThemeSelected(const QModelIndex&)), |
112 this,SLOT(newThemeSelected(const QModelIndex&))); |
124 this,SLOT(newThemeSelected(const QModelIndex&))); |
113 |
125 |
152 { |
164 { |
153 if(!index.isValid()) { |
165 if(!index.isValid()) { |
154 return; |
166 return; |
155 } |
167 } |
156 |
168 |
157 CpThemeChanger::ThemeInfo themeInfo = mThemeChanger->themes().at(index.row()); |
169 |
158 |
170 CpThemeChanger::ThemeInfo themeInfo; |
|
171 QVariant data; |
|
172 |
|
173 //reset the current index to active theme, so that the selection remains on current |
|
174 //theme even though another list item is selected. |
|
175 setActiveThemeIndex(); |
|
176 |
|
177 //get the theme name. |
|
178 data = index.data(Qt::DisplayRole); |
|
179 if(data.isValid()) { |
|
180 themeInfo.name = data.toString(); |
|
181 } |
|
182 //get theme icon. |
|
183 data = index.data(Qt::DecorationRole); |
|
184 if(data.isValid()) { |
|
185 themeInfo.icon = data.value<HbIcon>(); |
|
186 } |
|
187 |
|
188 data = index.data(CpThemeChanger::PortraitPreviewRole); |
|
189 if(data.isValid()) { |
|
190 themeInfo.portraitPreviewIcon = data.value<HbIcon>(); |
|
191 } |
|
192 |
|
193 data = index.data(CpThemeChanger::LandscapePreviewRole); |
|
194 if(data.isValid()) { |
|
195 themeInfo.landscapePreviewIcon = data.value<HbIcon>(); |
|
196 } |
|
197 |
|
198 |
159 //Set up the theme preview and set it to |
199 //Set up the theme preview and set it to |
160 //the current view of main window. |
200 //the current view of main window. |
161 HbMainWindow* mWindow = ::mainWindow(); |
201 HbMainWindow* mWindow = ::mainWindow(); |
162 |
202 |
163 if(!mThemePreview){ |
203 if(!mThemePreview){ |
209 //to theme list view. |
249 //to theme list view. |
210 HbMainWindow* mainWindow = ::mainWindow(); |
250 HbMainWindow* mainWindow = ::mainWindow(); |
211 mainWindow->removeView(mThemePreview); |
251 mainWindow->removeView(mThemePreview); |
212 mThemePreview->deleteLater(); |
252 mThemePreview->deleteLater(); |
213 mThemePreview = 0; |
253 mThemePreview = 0; |
214 |
254 |
|
255 //reset the current index to active theme, so that the selection remains on current |
|
256 //theme even though another list item is selected. |
|
257 setActiveThemeIndex(); |
215 mainWindow->setCurrentView(mThemeListView); |
258 mainWindow->setCurrentView(mThemeListView); |
216 } |
259 } |
217 |
260 |
218 /*! |
261 /*! |
219 Slot for when the theme list view is closed. Ownership of the theme list was given to |
262 Slot for when the theme list view is closed. Ownership of the theme list was given to |
234 void CpThemeControl::triggerThemeListClose() |
277 void CpThemeControl::triggerThemeListClose() |
235 { |
278 { |
236 mThemeListView->closeView(); |
279 mThemeListView->closeView(); |
237 } |
280 } |
238 |
281 |
239 |
282 /*! |
240 |
283 * Private function that sets the current index of theme list view to indicate |
241 |
284 * the active theme. |
|
285 */ |
|
286 void CpThemeControl::setActiveThemeIndex() |
|
287 { |
|
288 //Get the index of current theme. |
|
289 QModelIndex sourceIndex = mListModel->index(mThemeChanger->indexOf(mThemeChanger->currentTheme()),0); |
|
290 //Map it to the sort model index. |
|
291 QModelIndex sortedIndex = mSortModel->mapFromSource(sourceIndex); |
|
292 //set current index. |
|
293 mThemeListView->themeList()->setCurrentIndex(sortedIndex, QItemSelectionModel::SelectCurrent); |
|
294 } |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |