|
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 "infowidgetlayoutmanager.h" |
|
19 #include <QtGlobal> |
|
20 #include <QObject> |
|
21 #include <QGraphicsWidget> |
|
22 #include <hbdocumentloader.h> |
|
23 #include <hblabel.h> |
|
24 #include <hbmarqueeitem.h> |
|
25 #include <hbiconitem.h> |
|
26 #include <hbpushbutton.h> |
|
27 #include "infowidgetlogging.h" |
|
28 |
|
29 |
|
30 const char INFOWIDGET_DOCML_FILE[] = ":/resource/infowidget.docml"; |
|
31 |
|
32 // Docml widget name mappings |
|
33 const char LAYOUT_PREFIX_INFO_DISPLAY[] = "id:"; |
|
34 const char LAYOUT_PREFIX_SETTINGS_DISPLAY[] = "sd:"; |
|
35 const char LAYOUT_NAME_CONTENT[] = "content"; |
|
36 const char LAYOUT_NAME_MCNMARQUEEITEM[] = "mcnMarqueeItem"; |
|
37 const char LAYOUT_NAME_MCNLABEL[] = "mcnLabel"; |
|
38 const char LAYOUT_NAME_HOMEZONELABEL[] = "homeZoneLabel"; |
|
39 const char LAYOUT_NAME_ACTIVELINELABEL[] = "activeLineLabel"; |
|
40 const char LAYOUT_NAME_SATTEXTLABEL[] = "satTextLabel"; |
|
41 const char LAYOUT_NAME_HOMEZONEICON[] = "homeZoneIcon"; |
|
42 const char LAYOUT_NAME_MCNICON[] = "mcnIcon"; |
|
43 const char LAYOUT_NAME_ACTIVELINEICON[] = "activeLineIcon"; |
|
44 const char LAYOUT_NAME_SATTEXTICON[] = "satTextIcon"; |
|
45 const char LAYOUT_NAME_HOMEZONECHECKBOX[] = "homeZoneCheckBox"; |
|
46 const char LAYOUT_NAME_MCNCHECKBOX[] = "mcnCheckBox"; |
|
47 const char LAYOUT_NAME_ACTIVELINECHECKBOX[] = "activeLineCheckBox"; |
|
48 const char LAYOUT_NAME_SATTEXTCHECKBOX[] = "satTextCheckBox"; |
|
49 const char LAYOUT_NAME_OKBUTTON[] = "okButton"; |
|
50 const char LAYOUT_NAME_CONTAINER[] = "container"; |
|
51 const char LAYOUT_NAME_SETTINGSCONTAINER[] = "settingsContainer"; |
|
52 |
|
53 |
|
54 /*! |
|
55 InfoWidgetDocumentLoader::InfoWidgetDocumentLoader() |
|
56 */ |
|
57 InfoWidgetDocumentLoader::InfoWidgetDocumentLoader() |
|
58 { |
|
59 } |
|
60 |
|
61 /*! |
|
62 InfoWidgetDocumentLoader::createObject() |
|
63 */ |
|
64 QObject *InfoWidgetDocumentLoader::createObject( |
|
65 const QString &type, |
|
66 const QString &name) |
|
67 { |
|
68 DPRINT << ": IN"; |
|
69 |
|
70 DPRINT << ": type: "<< type; |
|
71 DPRINT << ": name: "<< name; |
|
72 |
|
73 if ( type == HbMarqueeItem::staticMetaObject.className() ) { |
|
74 DPRINT << ": HbMarqueeItem"; |
|
75 QObject *object = new HbMarqueeItem; |
|
76 object->setObjectName(name); |
|
77 DPRINT << ": HbMarqueeitem found, OUT"; |
|
78 return object; |
|
79 } |
|
80 |
|
81 DPRINT << ": OUT"; |
|
82 |
|
83 return HbDocumentLoader::createObject(type, name); |
|
84 } |
|
85 |
|
86 /*! |
|
87 */ |
|
88 InfoWidgetLayoutManager::InfoWidgetLayoutManager(QObject *parent) |
|
89 : QObject(parent), |
|
90 m_documentLoader(NULL), |
|
91 m_displayRole(InfoDisplay), |
|
92 m_layoutRows(0) |
|
93 { |
|
94 DPRINT << ": IN"; |
|
95 |
|
96 // Fill supported layout item roles for info display |
|
97 QList<LayoutItemRole> displayWidgetRoles = widgetRoles(InfoDisplay); |
|
98 |
|
99 // Try to load all widgets in list by widget role |
|
100 bool loadResult = loadWidgets(InfoDisplay, |
|
101 displayWidgetRoles, |
|
102 m_infoDisplayWidgets); |
|
103 DPRINT << ": info display widget load result: " << loadResult; |
|
104 |
|
105 // Fill supported layout item roles for settings display |
|
106 displayWidgetRoles = widgetRoles(SettingsDisplay); |
|
107 |
|
108 // Try to load all widgets in list by widget role |
|
109 loadResult = loadWidgets(SettingsDisplay, |
|
110 displayWidgetRoles, |
|
111 m_settingsDisplayWidgets); |
|
112 DPRINT << ": settings display widget load result: " << loadResult; |
|
113 |
|
114 DPRINT << ": OUT"; |
|
115 } |
|
116 |
|
117 /*! |
|
118 */ |
|
119 InfoWidgetLayoutManager::~InfoWidgetLayoutManager() |
|
120 { |
|
121 DPRINT << ": IN"; |
|
122 |
|
123 if (m_documentLoader) { |
|
124 delete m_documentLoader; |
|
125 } |
|
126 |
|
127 DPRINT << ": OUT"; |
|
128 } |
|
129 |
|
130 /*! |
|
131 */ |
|
132 InfoWidgetLayoutManager::DisplayRole InfoWidgetLayoutManager::currentDisplayRole() |
|
133 { |
|
134 DPRINT; |
|
135 return m_displayRole; |
|
136 } |
|
137 |
|
138 /*! |
|
139 */ |
|
140 QList<InfoWidgetLayoutManager::LayoutItemRole> InfoWidgetLayoutManager::currentWidgetRoles() |
|
141 { |
|
142 DPRINT; |
|
143 return m_widgets.keys(); |
|
144 } |
|
145 |
|
146 int InfoWidgetLayoutManager::layoutRows() const |
|
147 { |
|
148 DPRINT; |
|
149 return m_layoutRows; |
|
150 } |
|
151 |
|
152 void InfoWidgetLayoutManager::setLayoutRows(int rows) |
|
153 { |
|
154 DPRINT; |
|
155 m_layoutRows = rows; |
|
156 } |
|
157 |
|
158 /*! |
|
159 InfoWidgetLayoutManager::contentWidget() |
|
160 */ |
|
161 QGraphicsWidget* InfoWidgetLayoutManager::contentWidget() |
|
162 { |
|
163 DPRINT; |
|
164 return getWidget(RoleContent); |
|
165 } |
|
166 |
|
167 /*! |
|
168 InfoWidgetLayoutManager::getWidget(); |
|
169 */ |
|
170 QGraphicsWidget* InfoWidgetLayoutManager::getWidget(LayoutItemRole itemRole) |
|
171 { |
|
172 DPRINT << ": item role: " << itemRole; |
|
173 |
|
174 QGraphicsWidget *widget = m_widgets.value(itemRole); |
|
175 if (widget) { |
|
176 DPRINT << ": widget: " << widget; |
|
177 } |
|
178 |
|
179 return widget; |
|
180 } |
|
181 |
|
182 /*! |
|
183 InfoWidgetLayoutManager::hideWidget(); |
|
184 */ |
|
185 void InfoWidgetLayoutManager::hideWidget(LayoutItemRole itemRole) |
|
186 { |
|
187 DPRINT << ": item role: " << itemRole; |
|
188 |
|
189 QGraphicsWidget *widget = m_widgets.value(itemRole); |
|
190 if (widget) { |
|
191 DPRINT << ": hiding widget: " << widget; |
|
192 widget->hide(); |
|
193 } |
|
194 } |
|
195 |
|
196 /*! |
|
197 InfoWidgetLayoutManager::hideAll(); |
|
198 */ |
|
199 void InfoWidgetLayoutManager::hideAll() |
|
200 { |
|
201 DPRINT << ": IN"; |
|
202 |
|
203 QMapIterator<LayoutItemRole, QGraphicsWidget *> iterator(m_widgets); |
|
204 while (iterator.hasNext()) { |
|
205 iterator.next(); |
|
206 QGraphicsWidget *widget = iterator.value(); |
|
207 if (widget) { |
|
208 widget->hide(); |
|
209 } |
|
210 } |
|
211 |
|
212 DPRINT << ": OUT"; |
|
213 } |
|
214 |
|
215 |
|
216 /*! |
|
217 InfoWidgetLayoutManager::showAll(); |
|
218 */ |
|
219 void InfoWidgetLayoutManager::showAll() |
|
220 { |
|
221 DPRINT << ": IN"; |
|
222 |
|
223 QMapIterator<LayoutItemRole, QGraphicsWidget *> iterator(m_widgets); |
|
224 while (iterator.hasNext()) { |
|
225 iterator.next(); |
|
226 QGraphicsWidget *widget = iterator.value(); |
|
227 if (widget) { |
|
228 widget->show(); |
|
229 } |
|
230 } |
|
231 |
|
232 DPRINT << ": OUT"; |
|
233 } |
|
234 |
|
235 /*! |
|
236 InfoWidgetLayoutManager::layoutInfoDisplay() |
|
237 */ |
|
238 QGraphicsLayout* InfoWidgetLayoutManager::layoutInfoDisplay() |
|
239 { |
|
240 DPRINT << ": IN"; |
|
241 |
|
242 hideAll(); |
|
243 |
|
244 m_displayRole = InfoDisplay; |
|
245 m_widgets = m_infoDisplayWidgets; |
|
246 |
|
247 QGraphicsLayout *activeLayout(NULL); |
|
248 DPRINT << ": getting content item and using its layout for activeLayout"; |
|
249 QGraphicsWidget *content = getWidget(RoleContent); |
|
250 if (content) { |
|
251 DPRINT << ": content found, getting layout"; |
|
252 activeLayout = content->layout(); |
|
253 } |
|
254 |
|
255 DPRINT << ": OUT"; |
|
256 return activeLayout; |
|
257 } |
|
258 |
|
259 /*! |
|
260 InfoWidgetLayoutManager::layoutSettingsDisplay() |
|
261 */ |
|
262 QGraphicsLayout* InfoWidgetLayoutManager::layoutSettingsDisplay() |
|
263 { |
|
264 DPRINT << ": IN"; |
|
265 |
|
266 hideAll(); |
|
267 |
|
268 m_displayRole = SettingsDisplay; |
|
269 m_widgets = m_settingsDisplayWidgets; |
|
270 |
|
271 QGraphicsLayout *activeLayout(NULL); |
|
272 DPRINT << ": getting content item and using its layout for activeLayout"; |
|
273 QGraphicsWidget *content = getWidget(RoleContent); |
|
274 if (content) { |
|
275 DPRINT << ": content found, getting layout"; |
|
276 activeLayout = content->layout(); |
|
277 } |
|
278 |
|
279 DPRINT << ": OUT"; |
|
280 return activeLayout; |
|
281 } |
|
282 |
|
283 /*! |
|
284 InfoWidgetLayoutManager::loadWidgets() |
|
285 */ |
|
286 bool InfoWidgetLayoutManager::loadWidgets(const DisplayRole displayRole, |
|
287 const QList<LayoutItemRole> &displayWidgets, |
|
288 QMap<LayoutItemRole, QGraphicsWidget *> &widgetMap) |
|
289 { |
|
290 DPRINT << ": IN"; |
|
291 bool loadResult(true); |
|
292 |
|
293 // Cleanup previously loaded content in case of any data |
|
294 widgetMap.clear(); |
|
295 |
|
296 if (!m_documentLoader) { |
|
297 m_documentLoader = new InfoWidgetDocumentLoader; |
|
298 } |
|
299 |
|
300 Q_ASSERT(m_documentLoader); |
|
301 |
|
302 bool loaded = false; |
|
303 m_documentLoader->load(INFOWIDGET_DOCML_FILE, &loaded); |
|
304 |
|
305 if (!loaded) { |
|
306 qWarning() << "Unable to load .docml: " << INFOWIDGET_DOCML_FILE; |
|
307 } |
|
308 else { |
|
309 DPRINT << ": document " << INFOWIDGET_DOCML_FILE << " loaded successfully"; |
|
310 |
|
311 QGraphicsWidget *widget(NULL); |
|
312 LayoutItemRole currentWidgetRole; |
|
313 bool allWidgetsLoaded(true); |
|
314 |
|
315 foreach (currentWidgetRole, displayWidgets) { |
|
316 DPRINT << ": iterating displayWidgets, current role: " << static_cast<int>(currentWidgetRole); |
|
317 |
|
318 widget = loadWidget(*m_documentLoader, displayRole, currentWidgetRole); |
|
319 if (widget) { |
|
320 DPRINT << ": widget found, inserting to widget map"; |
|
321 widgetMap.insert(currentWidgetRole, widget); |
|
322 widget = NULL; |
|
323 } else { |
|
324 allWidgetsLoaded = false; |
|
325 DPRINT << ": ERROR, widget not found!"; |
|
326 } |
|
327 } |
|
328 |
|
329 DPRINT << ": allWidgetsLoaded: " << allWidgetsLoaded; |
|
330 |
|
331 int widgetCount = widgetMap.count(); |
|
332 DPRINT << ": loaded widgets count: " << widgetCount; |
|
333 if (widgetCount == displayWidgets.count()) { |
|
334 DPRINT << ": all widgets loaded"; |
|
335 loadResult = true; |
|
336 } else { |
|
337 DPRINT << ": error, all widgets were not loaded"; |
|
338 loadResult = false; |
|
339 } |
|
340 } |
|
341 |
|
342 DPRINT << ": OUT"; |
|
343 return loadResult; |
|
344 } |
|
345 |
|
346 /*! |
|
347 InfoWidgetLayoutManager::loadWidget() |
|
348 |
|
349 Initialize loader with corresponding document file before calling this single widget loader utility |
|
350 */ |
|
351 QGraphicsWidget* InfoWidgetLayoutManager::loadWidget(InfoWidgetDocumentLoader &loader, |
|
352 DisplayRole displayRole, |
|
353 LayoutItemRole widgetRole) |
|
354 { |
|
355 DPRINT << ": IN"; |
|
356 |
|
357 QString widgetPrefix; |
|
358 if (displayRole == InfoDisplay) { |
|
359 widgetPrefix = LAYOUT_PREFIX_INFO_DISPLAY; |
|
360 } else if (displayRole == SettingsDisplay) { |
|
361 widgetPrefix = LAYOUT_PREFIX_SETTINGS_DISPLAY; |
|
362 } |
|
363 |
|
364 QGraphicsWidget *widget(NULL); |
|
365 QString widgetName = widgetPrefix; |
|
366 |
|
367 switch (widgetRole) |
|
368 { |
|
369 case RoleContent: |
|
370 widgetName.append(LAYOUT_NAME_CONTENT); |
|
371 break; |
|
372 case RoleMcnMarqueeItem: |
|
373 widgetName.append(LAYOUT_NAME_MCNMARQUEEITEM); |
|
374 break; |
|
375 case RoleHomeZoneLabel: |
|
376 widgetName.append(LAYOUT_NAME_HOMEZONELABEL); |
|
377 break; |
|
378 case RoleMcnLabel: |
|
379 widgetName.append(LAYOUT_NAME_MCNLABEL); |
|
380 break; |
|
381 case RoleActiveLineLabel: |
|
382 widgetName.append(LAYOUT_NAME_ACTIVELINELABEL); |
|
383 break; |
|
384 case RoleSatTextLabel: |
|
385 widgetName.append(LAYOUT_NAME_SATTEXTLABEL); |
|
386 break; |
|
387 case RoleHomeZoneIcon: |
|
388 widgetName.append(LAYOUT_NAME_HOMEZONEICON); |
|
389 break; |
|
390 case RoleMcnIcon: |
|
391 widgetName.append(LAYOUT_NAME_MCNICON); |
|
392 break; |
|
393 case RoleActiveLineIcon: |
|
394 widgetName.append(LAYOUT_NAME_ACTIVELINEICON); |
|
395 break; |
|
396 case RoleSatTextIcon: |
|
397 widgetName.append(LAYOUT_NAME_SATTEXTICON); |
|
398 break; |
|
399 case RoleHomeZoneCheckBox: |
|
400 widgetName.append(LAYOUT_NAME_HOMEZONECHECKBOX); |
|
401 break; |
|
402 case RoleMcnCheckBox: |
|
403 widgetName.append(LAYOUT_NAME_MCNCHECKBOX); |
|
404 break; |
|
405 case RoleActiveLineCheckBox: |
|
406 widgetName.append(LAYOUT_NAME_ACTIVELINECHECKBOX); |
|
407 break; |
|
408 case RoleSatTextCheckBox: |
|
409 widgetName.append(LAYOUT_NAME_SATTEXTCHECKBOX); |
|
410 break; |
|
411 case RoleOkButton: |
|
412 widgetName.append(LAYOUT_NAME_OKBUTTON); |
|
413 break; |
|
414 case RoleContainer: |
|
415 widgetName.append(LAYOUT_NAME_CONTAINER); |
|
416 break; |
|
417 case RoleSettingsContainer: |
|
418 widgetName.append(LAYOUT_NAME_SETTINGSCONTAINER); |
|
419 break; |
|
420 |
|
421 case RoleUndefined: // Fall through |
|
422 default: |
|
423 break; |
|
424 } |
|
425 |
|
426 widget = qobject_cast<QGraphicsWidget *>(loader.findWidget(widgetName)); |
|
427 |
|
428 if (widget) { |
|
429 DPRINT << ": widget found: " << widgetName; |
|
430 } else { |
|
431 DPRINT << ": ERROR, widget not found!"; |
|
432 } |
|
433 |
|
434 DPRINT << ": OUT"; |
|
435 return widget; |
|
436 } |
|
437 |
|
438 /*! |
|
439 InfoWidgetLayoutManager::widgetRoles() |
|
440 |
|
441 Returns supported widget roles for specific display |
|
442 */ |
|
443 const QList<InfoWidgetLayoutManager::LayoutItemRole> InfoWidgetLayoutManager::widgetRoles( |
|
444 DisplayRole displayRole) const |
|
445 { |
|
446 DPRINT << ": IN"; |
|
447 |
|
448 QList<LayoutItemRole> widgetRoles; |
|
449 |
|
450 switch (displayRole) { |
|
451 case SettingsDisplay: |
|
452 // Fill supported layout item roles for settings display |
|
453 widgetRoles.append(RoleContent); |
|
454 widgetRoles.append(RoleHomeZoneLabel); |
|
455 widgetRoles.append(RoleMcnLabel); |
|
456 widgetRoles.append(RoleActiveLineLabel); |
|
457 widgetRoles.append(RoleSatTextLabel); |
|
458 widgetRoles.append(RoleHomeZoneIcon); |
|
459 widgetRoles.append(RoleMcnIcon); |
|
460 widgetRoles.append(RoleActiveLineIcon); |
|
461 widgetRoles.append(RoleSatTextIcon); |
|
462 widgetRoles.append(RoleHomeZoneCheckBox); |
|
463 widgetRoles.append(RoleMcnCheckBox); |
|
464 widgetRoles.append(RoleActiveLineCheckBox); |
|
465 widgetRoles.append(RoleSatTextCheckBox); |
|
466 widgetRoles.append(RoleOkButton); |
|
467 widgetRoles.append(RoleSettingsContainer); |
|
468 break; |
|
469 case InfoDisplay: |
|
470 // Fill supported layout item roles for info display |
|
471 widgetRoles.append(RoleContent); |
|
472 widgetRoles.append(RoleHomeZoneLabel); |
|
473 widgetRoles.append(RoleMcnMarqueeItem); |
|
474 widgetRoles.append(RoleActiveLineLabel); |
|
475 widgetRoles.append(RoleSatTextLabel); |
|
476 widgetRoles.append(RoleHomeZoneIcon); |
|
477 widgetRoles.append(RoleMcnIcon); |
|
478 widgetRoles.append(RoleActiveLineIcon); |
|
479 widgetRoles.append(RoleSatTextIcon); |
|
480 widgetRoles.append(RoleSettingsContainer); |
|
481 break; |
|
482 |
|
483 default: |
|
484 break; |
|
485 } |
|
486 |
|
487 DPRINT << ": widgetRoles.count() : " << widgetRoles.count(); |
|
488 DPRINT << ": OUT"; |
|
489 return widgetRoles; |
|
490 } |
|
491 |
|
492 // End of File. |
|
493 |
|
494 |