|
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_SPNLABEL[] = "spnLabel"; |
|
38 const char LAYOUT_NAME_SATMARQUEEITEM[] = "satMarqueeItem"; |
|
39 const char LAYOUT_NAME_SPNICON[] = "spnIcon"; |
|
40 const char LAYOUT_NAME_MCNICON[] = "mcnIcon"; |
|
41 const char LAYOUT_NAME_SATTEXTICON[] = "satTextIcon"; |
|
42 const char LAYOUT_NAME_SPNCHECKBOX[] = "spnCheckBox"; |
|
43 const char LAYOUT_NAME_MCNCHECKBOX[] = "mcnCheckBox"; |
|
44 const char LAYOUT_NAME_SATTEXTCHECKBOX[] = "satTextCheckBox"; |
|
45 const char LAYOUT_NAME_OKBUTTON[] = "okButton"; |
|
46 const char LAYOUT_NAME_CONTAINER[] = "container"; |
|
47 const char LAYOUT_NAME_SETTINGSCONTAINER[] = "settingsContainer"; |
|
48 |
|
49 |
|
50 /*! |
|
51 \class InfoWidgetDocumentLoader |
|
52 \brief Custom document loader for Operator info widget |
|
53 |
|
54 Derived from HbDocumentLoader. |
|
55 |
|
56 */ |
|
57 |
|
58 /*! |
|
59 InfoWidgetDocumentLoader::InfoWidgetDocumentLoader() |
|
60 */ |
|
61 InfoWidgetDocumentLoader::InfoWidgetDocumentLoader() |
|
62 { |
|
63 } |
|
64 |
|
65 /*! |
|
66 InfoWidgetDocumentLoader::createObject() |
|
67 */ |
|
68 QObject *InfoWidgetDocumentLoader::createObject( |
|
69 const QString &type, |
|
70 const QString &name) |
|
71 { |
|
72 DPRINT << ": IN"; |
|
73 |
|
74 DPRINT << ": type: "<< type; |
|
75 DPRINT << ": name: "<< name; |
|
76 |
|
77 if ( type == HbMarqueeItem::staticMetaObject.className() ) { |
|
78 DPRINT << ": HbMarqueeItem"; |
|
79 QObject *object = new HbMarqueeItem; |
|
80 object->setObjectName(name); |
|
81 DPRINT << ": HbMarqueeitem found, OUT"; |
|
82 return object; |
|
83 } |
|
84 |
|
85 DPRINT << ": OUT"; |
|
86 return HbDocumentLoader::createObject(type, name); |
|
87 } |
|
88 |
|
89 |
|
90 /*! |
|
91 \class InfoWidgetLayoutManager |
|
92 \brief Layout manager class for Operator info widget. |
|
93 |
|
94 Handles layout document loading and accessing the loaded |
|
95 widgets. |
|
96 |
|
97 */ |
|
98 |
|
99 /*! |
|
100 InfoWidgetLayoutManager::InfoWidgetLayoutManager() |
|
101 */ |
|
102 InfoWidgetLayoutManager::InfoWidgetLayoutManager(QObject *parent) |
|
103 : QObject(parent), |
|
104 m_documentLoader(NULL), |
|
105 m_displayRole(InfoDisplay), |
|
106 m_layoutRows(0) |
|
107 { |
|
108 DPRINT << ": IN"; |
|
109 |
|
110 // Fill supported layout item roles for info display |
|
111 QList<LayoutItemRole> displayWidgetRoles = widgetRoles(InfoDisplay); |
|
112 |
|
113 // Try to load all widgets in list by widget role |
|
114 bool loadResult = loadWidgets(InfoDisplay, |
|
115 displayWidgetRoles, |
|
116 m_infoDisplayWidgets); |
|
117 DPRINT << ": info display widget load result: " << loadResult; |
|
118 |
|
119 // Fill supported layout item roles for settings display |
|
120 displayWidgetRoles = widgetRoles(SettingsDisplay); |
|
121 |
|
122 // Try to load all widgets in list by widget role |
|
123 loadResult = loadWidgets(SettingsDisplay, |
|
124 displayWidgetRoles, |
|
125 m_settingsDisplayWidgets); |
|
126 DPRINT << ": settings display widget load result: " << loadResult; |
|
127 |
|
128 DPRINT << ": OUT"; |
|
129 } |
|
130 |
|
131 /*! |
|
132 InfoWidgetLayoutManager::~InfoWidgetLayoutManager() |
|
133 */ |
|
134 InfoWidgetLayoutManager::~InfoWidgetLayoutManager() |
|
135 { |
|
136 DPRINT << ": IN"; |
|
137 |
|
138 if (m_documentLoader) { |
|
139 delete m_documentLoader; |
|
140 } |
|
141 |
|
142 DPRINT << ": OUT"; |
|
143 } |
|
144 |
|
145 /*! |
|
146 InfoWidgetLayoutManager::destroyObjects() |
|
147 |
|
148 Call on destruction for freeing |
|
149 loaded objects. Parent items are deleted |
|
150 causing deletion of corresponding object tree |
|
151 */ |
|
152 void InfoWidgetLayoutManager::destroyObjects() |
|
153 { |
|
154 DPRINT << ": IN"; |
|
155 |
|
156 // Destroy parent items |
|
157 QGraphicsWidget *contentInfoDisplay = |
|
158 m_infoDisplayWidgets.value(RoleContent); |
|
159 if (contentInfoDisplay) { |
|
160 delete contentInfoDisplay; |
|
161 m_infoDisplayWidgets.clear(); |
|
162 } |
|
163 |
|
164 QGraphicsWidget *contentSettingsDisplay= |
|
165 m_settingsDisplayWidgets.value(RoleContent); |
|
166 if (contentSettingsDisplay) { |
|
167 delete contentSettingsDisplay; |
|
168 m_settingsDisplayWidgets.clear(); |
|
169 } |
|
170 |
|
171 DPRINT << ": OUT"; |
|
172 } |
|
173 |
|
174 |
|
175 /*! |
|
176 InfoWidgetLayoutManager::currentDisplayRole() |
|
177 */ |
|
178 InfoWidgetLayoutManager::DisplayRole InfoWidgetLayoutManager::currentDisplayRole() |
|
179 { |
|
180 DPRINT; |
|
181 return m_displayRole; |
|
182 } |
|
183 |
|
184 /*! |
|
185 InfoWidgetLayoutManager::currentWidgetRoles() |
|
186 */ |
|
187 QList<InfoWidgetLayoutManager::LayoutItemRole> InfoWidgetLayoutManager::currentWidgetRoles() |
|
188 { |
|
189 DPRINT; |
|
190 return m_widgets.keys(); |
|
191 } |
|
192 |
|
193 /*! |
|
194 InfoWidgetLayoutManager::layoutRows() |
|
195 */ |
|
196 int InfoWidgetLayoutManager::layoutRows() const |
|
197 { |
|
198 DPRINT; |
|
199 return m_layoutRows; |
|
200 } |
|
201 |
|
202 /*! |
|
203 InfoWidgetLayoutManager::setLayoutRows() |
|
204 */ |
|
205 void InfoWidgetLayoutManager::setLayoutRows(int rows) |
|
206 { |
|
207 DPRINT; |
|
208 m_layoutRows = rows; |
|
209 } |
|
210 |
|
211 /*! |
|
212 InfoWidgetLayoutManager::rowHeight() |
|
213 */ |
|
214 qreal InfoWidgetLayoutManager::rowHeight() const |
|
215 { |
|
216 DPRINT; |
|
217 HbStyle style; |
|
218 qreal rowHeight; |
|
219 |
|
220 bool ok = style.parameter("hb-param-graphic-size-primary-small", |
|
221 rowHeight); |
|
222 if (!ok) { |
|
223 DPRINT << ": ERROR! Paremeters reading failed!! Using default"; |
|
224 rowHeight = 26.8; |
|
225 } |
|
226 |
|
227 DPRINT << ": rowHeight: " << rowHeight; |
|
228 return rowHeight; |
|
229 } |
|
230 |
|
231 /*! |
|
232 InfoWidgetLayoutManager::contentWidget() |
|
233 */ |
|
234 QGraphicsWidget* InfoWidgetLayoutManager::contentWidget() |
|
235 { |
|
236 DPRINT; |
|
237 return getWidget(RoleContent); |
|
238 } |
|
239 |
|
240 /*! |
|
241 InfoWidgetLayoutManager::getWidget(); |
|
242 */ |
|
243 QGraphicsWidget* InfoWidgetLayoutManager::getWidget(LayoutItemRole itemRole) |
|
244 { |
|
245 DPRINT << ": item role: " << itemRole; |
|
246 |
|
247 QGraphicsWidget *widget = m_widgets.value(itemRole); |
|
248 if (widget) { |
|
249 DPRINT << ": widget: " << widget; |
|
250 } |
|
251 |
|
252 return widget; |
|
253 } |
|
254 |
|
255 /*! |
|
256 InfoWidgetLayoutManager::removeWidget(); |
|
257 */ |
|
258 void InfoWidgetLayoutManager::removeWidget(LayoutItemRole itemRole) |
|
259 { |
|
260 DPRINT << ": item role: " << itemRole; |
|
261 |
|
262 QGraphicsWidget *widget = m_widgets.value(itemRole); |
|
263 if (widget) { |
|
264 DPRINT << ": removing widget: " << widget; |
|
265 m_widgets.remove(itemRole); |
|
266 delete widget; |
|
267 } |
|
268 } |
|
269 |
|
270 /*! |
|
271 InfoWidgetLayoutManager::hideWidget(); |
|
272 */ |
|
273 void InfoWidgetLayoutManager::hideWidget(LayoutItemRole itemRole) |
|
274 { |
|
275 DPRINT << ": item role: " << itemRole; |
|
276 |
|
277 QGraphicsWidget *widget = m_widgets.value(itemRole); |
|
278 if (widget) { |
|
279 DPRINT << ": hiding widget: " << widget; |
|
280 widget->hide(); |
|
281 } |
|
282 } |
|
283 |
|
284 /*! |
|
285 InfoWidgetLayoutManager::hideAll(); |
|
286 */ |
|
287 void InfoWidgetLayoutManager::hideAll() |
|
288 { |
|
289 DPRINT << ": IN"; |
|
290 |
|
291 QMapIterator<LayoutItemRole, QGraphicsWidget *> iterator(m_widgets); |
|
292 while (iterator.hasNext()) { |
|
293 iterator.next(); |
|
294 QGraphicsWidget *widget = iterator.value(); |
|
295 if (widget) { |
|
296 widget->hide(); |
|
297 } |
|
298 } |
|
299 |
|
300 DPRINT << ": OUT"; |
|
301 } |
|
302 |
|
303 /*! |
|
304 InfoWidgetLayoutManager::showAll(); |
|
305 */ |
|
306 void InfoWidgetLayoutManager::showAll() |
|
307 { |
|
308 DPRINT << ": IN"; |
|
309 |
|
310 QMapIterator<LayoutItemRole, QGraphicsWidget *> iterator(m_widgets); |
|
311 while (iterator.hasNext()) { |
|
312 iterator.next(); |
|
313 QGraphicsWidget *widget = iterator.value(); |
|
314 if (widget) { |
|
315 widget->show(); |
|
316 } |
|
317 } |
|
318 |
|
319 DPRINT << ": OUT"; |
|
320 } |
|
321 |
|
322 /*! |
|
323 InfoWidgetLayoutManager::layoutInfoDisplay() |
|
324 */ |
|
325 QGraphicsLayout* InfoWidgetLayoutManager::layoutInfoDisplay() |
|
326 { |
|
327 DPRINT << ": IN"; |
|
328 |
|
329 hideAll(); |
|
330 |
|
331 m_displayRole = InfoDisplay; |
|
332 m_widgets = m_infoDisplayWidgets; |
|
333 |
|
334 QGraphicsLayout *activeLayout(NULL); |
|
335 DPRINT << ": getting content item and using its layout for activeLayout"; |
|
336 QGraphicsWidget *content = getWidget(RoleContent); |
|
337 if (content) { |
|
338 DPRINT << ": content found, getting layout"; |
|
339 activeLayout = content->layout(); |
|
340 } |
|
341 |
|
342 DPRINT << ": OUT"; |
|
343 return activeLayout; |
|
344 } |
|
345 |
|
346 /*! |
|
347 InfoWidgetLayoutManager::layoutSettingsDisplay() |
|
348 */ |
|
349 QGraphicsLayout* InfoWidgetLayoutManager::layoutSettingsDisplay() |
|
350 { |
|
351 DPRINT << ": IN"; |
|
352 |
|
353 hideAll(); |
|
354 |
|
355 m_displayRole = SettingsDisplay; |
|
356 m_widgets = m_settingsDisplayWidgets; |
|
357 |
|
358 QGraphicsLayout *activeLayout(NULL); |
|
359 DPRINT << ": getting content item and using its layout for activeLayout"; |
|
360 QGraphicsWidget *content = getWidget(RoleContent); |
|
361 if (content) { |
|
362 DPRINT << ": content found, getting layout"; |
|
363 activeLayout = content->layout(); |
|
364 } |
|
365 |
|
366 DPRINT << ": OUT"; |
|
367 return activeLayout; |
|
368 } |
|
369 |
|
370 /*! |
|
371 InfoWidgetLayoutManager::loadWidgets() |
|
372 */ |
|
373 bool InfoWidgetLayoutManager::loadWidgets(const DisplayRole displayRole, |
|
374 const QList<LayoutItemRole> &displayWidgets, |
|
375 QMap<LayoutItemRole, QGraphicsWidget *> &widgetMap) |
|
376 { |
|
377 DPRINT << ": IN"; |
|
378 bool loadResult(false); |
|
379 |
|
380 // Cleanup previously loaded content in case of any data |
|
381 widgetMap.clear(); |
|
382 |
|
383 if (!m_documentLoader) { |
|
384 m_documentLoader = new InfoWidgetDocumentLoader; |
|
385 } |
|
386 Q_ASSERT(m_documentLoader); |
|
387 |
|
388 bool loaded = false; |
|
389 m_documentLoader->load(INFOWIDGET_DOCML_FILE, &loaded); |
|
390 |
|
391 Q_ASSERT_X(loaded, |
|
392 "InfoWidgetLayoutManager", |
|
393 "Invalid docml file"); |
|
394 |
|
395 DPRINT << ": document " << INFOWIDGET_DOCML_FILE << " loaded successfully"; |
|
396 |
|
397 QGraphicsWidget *widget(NULL); |
|
398 LayoutItemRole currentWidgetRole; |
|
399 |
|
400 foreach (currentWidgetRole, displayWidgets) { |
|
401 DPRINT << ": iterating displayWidgets, current role: " << static_cast<int>(currentWidgetRole); |
|
402 |
|
403 widget = loadWidget(*m_documentLoader, displayRole, currentWidgetRole); |
|
404 if (widget) { |
|
405 DPRINT << ": widget found, inserting to widget map"; |
|
406 widgetMap.insert(currentWidgetRole, widget); |
|
407 widget = NULL; |
|
408 } else { |
|
409 DCRITICAL << ": ERROR, widget not found!"; |
|
410 } |
|
411 } |
|
412 |
|
413 if (widgetMap.count() == displayWidgets.count()) { |
|
414 DPRINT << ": all widgets loaded"; |
|
415 loadResult = true; |
|
416 } else { |
|
417 DCRITICAL << ": error, all widgets were not loaded"; |
|
418 } |
|
419 |
|
420 DPRINT << ": OUT"; |
|
421 return loadResult; |
|
422 } |
|
423 |
|
424 /*! |
|
425 InfoWidgetLayoutManager::reloadWidgets() |
|
426 */ |
|
427 bool InfoWidgetLayoutManager::reloadWidgets(const DisplayRole displayRole) |
|
428 { |
|
429 QList<LayoutItemRole> displayWidgetRoles = widgetRoles(displayRole); |
|
430 bool loadResult(false); |
|
431 |
|
432 switch (displayRole) { |
|
433 case InfoDisplay: |
|
434 loadResult = loadWidgets(displayRole, |
|
435 displayWidgetRoles, |
|
436 m_infoDisplayWidgets); |
|
437 break; |
|
438 case SettingsDisplay: // Fall through |
|
439 default: |
|
440 break; |
|
441 } |
|
442 return loadResult; |
|
443 } |
|
444 |
|
445 /*! |
|
446 InfoWidgetLayoutManager::loadWidget() |
|
447 |
|
448 Initialize loader with corresponding document file before calling this single widget loader utility |
|
449 */ |
|
450 QGraphicsWidget* InfoWidgetLayoutManager::loadWidget(InfoWidgetDocumentLoader &loader, |
|
451 DisplayRole displayRole, |
|
452 LayoutItemRole widgetRole) |
|
453 { |
|
454 DPRINT << ": IN"; |
|
455 |
|
456 QString widgetPrefix; |
|
457 if (displayRole == InfoDisplay) { |
|
458 widgetPrefix = LAYOUT_PREFIX_INFO_DISPLAY; |
|
459 } else if (displayRole == SettingsDisplay) { |
|
460 widgetPrefix = LAYOUT_PREFIX_SETTINGS_DISPLAY; |
|
461 } |
|
462 |
|
463 QGraphicsWidget *widget(NULL); |
|
464 QString widgetName = widgetPrefix; |
|
465 |
|
466 switch (widgetRole) |
|
467 { |
|
468 case RoleContent: |
|
469 widgetName.append(LAYOUT_NAME_CONTENT); |
|
470 break; |
|
471 case RoleMcnMarqueeItem: |
|
472 widgetName.append(LAYOUT_NAME_MCNMARQUEEITEM); |
|
473 break; |
|
474 case RoleSpnLabel: |
|
475 widgetName.append(LAYOUT_NAME_SPNLABEL); |
|
476 break; |
|
477 case RoleSatMarqueeItem: |
|
478 widgetName.append(LAYOUT_NAME_SATMARQUEEITEM); |
|
479 break; |
|
480 case RoleSpnIcon: |
|
481 widgetName.append(LAYOUT_NAME_SPNICON); |
|
482 break; |
|
483 case RoleMcnIcon: |
|
484 widgetName.append(LAYOUT_NAME_MCNICON); |
|
485 break; |
|
486 case RoleSatTextIcon: |
|
487 widgetName.append(LAYOUT_NAME_SATTEXTICON); |
|
488 break; |
|
489 case RoleSpnCheckBox: |
|
490 widgetName.append(LAYOUT_NAME_SPNCHECKBOX); |
|
491 break; |
|
492 case RoleMcnCheckBox: |
|
493 widgetName.append(LAYOUT_NAME_MCNCHECKBOX); |
|
494 break; |
|
495 case RoleSatTextCheckBox: |
|
496 widgetName.append(LAYOUT_NAME_SATTEXTCHECKBOX); |
|
497 break; |
|
498 case RoleOkButton: |
|
499 widgetName.append(LAYOUT_NAME_OKBUTTON); |
|
500 break; |
|
501 case RoleContainer: |
|
502 widgetName.append(LAYOUT_NAME_CONTAINER); |
|
503 break; |
|
504 case RoleSettingsContainer: |
|
505 widgetName.append(LAYOUT_NAME_SETTINGSCONTAINER); |
|
506 break; |
|
507 |
|
508 case RoleUndefined: // Fall through |
|
509 default: |
|
510 break; |
|
511 } |
|
512 |
|
513 widget = qobject_cast<QGraphicsWidget *>(loader.findWidget(widgetName)); |
|
514 if (!widget) { |
|
515 DCRITICAL << ": ERROR, widget " << widgetName << " not found!"; |
|
516 } |
|
517 |
|
518 DPRINT << ": OUT"; |
|
519 return widget; |
|
520 } |
|
521 |
|
522 /*! |
|
523 InfoWidgetLayoutManager::widgetRoles() |
|
524 |
|
525 Returns supported widget roles for specific display |
|
526 */ |
|
527 const QList<InfoWidgetLayoutManager::LayoutItemRole> InfoWidgetLayoutManager::widgetRoles( |
|
528 DisplayRole displayRole) const |
|
529 { |
|
530 DPRINT << ": IN"; |
|
531 |
|
532 QList<LayoutItemRole> widgetRoles; |
|
533 |
|
534 // Fill supported layout item roles for specific display |
|
535 switch (displayRole) { |
|
536 case SettingsDisplay: |
|
537 widgetRoles.append(RoleContent); |
|
538 widgetRoles.append(RoleSpnCheckBox); |
|
539 widgetRoles.append(RoleMcnCheckBox); |
|
540 widgetRoles.append(RoleSatTextCheckBox); |
|
541 widgetRoles.append(RoleOkButton); |
|
542 widgetRoles.append(RoleSettingsContainer); |
|
543 break; |
|
544 case InfoDisplay: |
|
545 widgetRoles.append(RoleContent); |
|
546 widgetRoles.append(RoleSpnIcon); |
|
547 widgetRoles.append(RoleSpnLabel); |
|
548 widgetRoles.append(RoleMcnIcon); |
|
549 widgetRoles.append(RoleMcnMarqueeItem); |
|
550 widgetRoles.append(RoleSatTextIcon); |
|
551 widgetRoles.append(RoleSatMarqueeItem); |
|
552 break; |
|
553 default: |
|
554 break; |
|
555 } |
|
556 |
|
557 DPRINT << ": widgetRoles.count() : " << widgetRoles.count(); |
|
558 DPRINT << ": OUT"; |
|
559 return widgetRoles; |
|
560 } |
|
561 |
|
562 // End of File. |
|
563 |
|
564 |