88 */ |
88 */ |
89 InfoWidgetLayoutManager::InfoWidgetLayoutManager(QObject *parent) |
89 InfoWidgetLayoutManager::InfoWidgetLayoutManager(QObject *parent) |
90 : QObject(parent), |
90 : QObject(parent), |
91 m_documentLoader(NULL), |
91 m_documentLoader(NULL), |
92 m_displayRole(InfoDisplay), |
92 m_displayRole(InfoDisplay), |
93 m_layoutRows(0), |
|
94 m_cachedLayoutRowHeight(0.0) |
93 m_cachedLayoutRowHeight(0.0) |
95 { |
94 { |
96 DPRINT; |
95 DPRINT; |
97 // Fill supported layout item roles for info display |
96 m_documentLoader.reset(new InfoWidgetDocumentLoader); |
98 QList<LayoutItemRole> displayWidgetRoles = widgetRoles(InfoDisplay); |
|
99 |
|
100 // Try to load all widgets in list by widget role |
|
101 bool loadResult = loadWidgets(InfoDisplay, |
|
102 displayWidgetRoles, |
|
103 m_infoDisplayWidgets); |
|
104 |
|
105 // Fill supported layout item roles for settings display |
|
106 displayWidgetRoles = widgetRoles(SettingsDialog); |
|
107 |
|
108 // Try to load all widgets in list by widget role |
|
109 loadResult = loadWidgets(SettingsDialog, |
|
110 displayWidgetRoles, |
|
111 m_settingsDialogWidgets); |
|
112 } |
97 } |
113 |
98 |
114 /*! |
99 /*! |
115 Destructor. |
100 Destructor. |
116 */ |
101 */ |
117 InfoWidgetLayoutManager::~InfoWidgetLayoutManager() |
102 InfoWidgetLayoutManager::~InfoWidgetLayoutManager() |
118 { |
103 { |
119 DPRINT; |
104 DPRINT; |
120 if (m_documentLoader) { |
|
121 delete m_documentLoader; |
|
122 } |
|
123 } |
105 } |
124 |
106 |
125 /*! |
107 /*! |
126 Destroy all widgets. |
108 Destroy all widgets. |
127 Deletes parent widgets of each display |
109 Deletes parent widgets of each display |
181 if (m_cachedLayoutRowHeight == 0.0) { |
145 if (m_cachedLayoutRowHeight == 0.0) { |
182 bool ok = hbInstance->style()->parameter("hb-param-graphic-size-primary-small", |
146 bool ok = hbInstance->style()->parameter("hb-param-graphic-size-primary-small", |
183 m_cachedLayoutRowHeight); |
147 m_cachedLayoutRowHeight); |
184 DPRINT << ": row height from style: " << m_cachedLayoutRowHeight; |
148 DPRINT << ": row height from style: " << m_cachedLayoutRowHeight; |
185 if (!ok) { |
149 if (!ok) { |
186 DWARNING << ": Error, paremeters reading failed!!"; |
150 DWARNING << ": Error, paremeters reading failed!"; |
187 } |
151 } |
188 } |
152 } |
189 return m_cachedLayoutRowHeight; |
153 return m_cachedLayoutRowHeight; |
190 } |
154 } |
191 |
155 |
193 Check if text fits to given rect width. |
157 Check if text fits to given rect width. |
194 */ |
158 */ |
195 bool InfoWidgetLayoutManager::textFitsToRect(QString text, |
159 bool InfoWidgetLayoutManager::textFitsToRect(QString text, |
196 QFont font, QRectF rect) const |
160 QFont font, QRectF rect) const |
197 { |
161 { |
|
162 DPRINT; |
198 bool fits(true); |
163 bool fits(true); |
199 if (!rect.isEmpty()) { |
164 if (!rect.isEmpty()) { |
200 QFontMetricsF metrics(font); |
165 QFontMetricsF metrics(font); |
201 qreal width = metrics.boundingRect(text).width(); |
166 qreal width = metrics.boundingRect(text).width(); |
202 if (width > rect.width() ) { |
167 if (width > rect.width() ) { |
224 { |
189 { |
225 DPRINT; |
190 DPRINT; |
226 QList<HbMarqueeItem *> items; |
191 QList<HbMarqueeItem *> items; |
227 |
192 |
228 QList<LayoutItemRole> marqueeItemRoles; |
193 QList<LayoutItemRole> marqueeItemRoles; |
229 marqueeItemRoles.append(RoleSpnMarqueeItem); |
194 marqueeItemRoles.append(RoleSpnMarqueeItem); |
230 marqueeItemRoles.append(RoleMcnMarqueeItem); |
195 marqueeItemRoles.append(RoleMcnMarqueeItem); |
231 marqueeItemRoles.append(RoleSatMarqueeItem); |
196 marqueeItemRoles.append(RoleSatMarqueeItem); |
232 |
197 |
233 foreach (LayoutItemRole role, marqueeItemRoles) { |
198 foreach (LayoutItemRole role, marqueeItemRoles) { |
234 QGraphicsWidget *widget = getWidget(role); |
199 QGraphicsWidget *widget = getWidget(role); |
235 if (widget) { |
200 if (widget) { |
236 HbMarqueeItem *item = |
201 HbMarqueeItem *item = |
237 qobject_cast<HbMarqueeItem*>(widget); |
202 qobject_cast<HbMarqueeItem*>(widget); |
247 /*! |
212 /*! |
248 Get widget with given item role. |
213 Get widget with given item role. |
249 */ |
214 */ |
250 QGraphicsWidget* InfoWidgetLayoutManager::getWidget(LayoutItemRole itemRole) |
215 QGraphicsWidget* InfoWidgetLayoutManager::getWidget(LayoutItemRole itemRole) |
251 { |
216 { |
252 QGraphicsWidget *widget = m_widgets.value(itemRole); |
217 return m_widgets.value(itemRole); |
253 return widget; |
|
254 } |
218 } |
255 |
219 |
256 /*! |
220 /*! |
257 Get object with given item role. |
221 Get object with given item role. |
258 */ |
222 */ |
259 QObject* InfoWidgetLayoutManager::getObject(LayoutItemRole itemRole) |
223 QObject* InfoWidgetLayoutManager::getObject(LayoutItemRole itemRole) |
260 { |
224 { |
261 QObject *object = m_objects.value(itemRole); |
225 return m_objects.value(itemRole); |
262 return object; |
|
263 } |
226 } |
264 |
227 |
265 /*! |
228 /*! |
266 Remove widget with given item role. |
229 Remove widget with given item role. |
267 */ |
230 */ |
275 delete widget; |
238 delete widget; |
276 } else { |
239 } else { |
277 widget->deleteLater(); |
240 widget->deleteLater(); |
278 } |
241 } |
279 } |
242 } |
280 |
|
281 m_widgets.remove(itemRole); |
243 m_widgets.remove(itemRole); |
282 m_infoDisplayWidgets.remove(itemRole); |
244 m_infoDisplayWidgets.remove(itemRole); |
283 m_settingsDialogWidgets.remove(itemRole); |
245 m_settingsDialogWidgets.remove(itemRole); |
284 } |
246 } |
285 |
247 |
286 /*! |
248 /*! |
287 Returns info display layout. |
249 Returns info display layout. |
288 */ |
250 */ |
289 QGraphicsLayout* InfoWidgetLayoutManager::layoutInfoDisplay() |
251 QGraphicsWidget* InfoWidgetLayoutManager::layoutInfoDisplay() |
290 { |
252 { |
291 DPRINT; |
253 DPRINT; |
292 m_displayRole = InfoDisplay; |
254 m_displayRole = InfoDisplay; |
|
255 |
|
256 loadWidgets(InfoWidgetLayoutManager::InfoDisplay); |
293 m_widgets = m_infoDisplayWidgets; |
257 m_widgets = m_infoDisplayWidgets; |
294 |
258 |
295 QGraphicsLayout *activeLayout(NULL); |
259 QGraphicsWidget *infoDisplay = getWidget(RoleContent); |
296 QGraphicsWidget *content = getWidget(RoleContent); |
260 Q_ASSERT(infoDisplay); |
297 if (content) { |
261 return infoDisplay; |
298 DPRINT << ": content found, getting layout"; |
|
299 activeLayout = content->layout(); |
|
300 } |
|
301 return activeLayout; |
|
302 } |
262 } |
303 |
263 |
304 /*! |
264 /*! |
305 Returns settings dialog layout. |
265 Returns settings dialog layout. |
306 */ |
266 */ |
307 QGraphicsLayout* InfoWidgetLayoutManager::layoutSettingsDialog() |
267 QGraphicsWidget* InfoWidgetLayoutManager::layoutSettingsDialog() |
308 { |
268 { |
309 DPRINT; |
269 DPRINT; |
310 m_displayRole = SettingsDialog; |
270 m_displayRole = SettingsDialog; |
|
271 loadWidgets(InfoWidgetLayoutManager::SettingsDialog); |
311 m_widgets = m_settingsDialogWidgets; |
272 m_widgets = m_settingsDialogWidgets; |
312 |
273 |
313 QGraphicsLayout *activeLayout(NULL); |
274 QGraphicsWidget *dialog = getWidget(RoleSettingsDialog); |
314 QGraphicsWidget *dialog = getWidget(RoleSettingsDialog); |
275 Q_ASSERT(dialog); |
315 if (dialog) { |
276 |
316 activeLayout = dialog->layout(); |
277 HbAction *okAction = qobject_cast<HbAction *>( |
317 |
278 getObject(RoleOkAction)); |
318 HbAction *okAction = qobject_cast<HbAction *>( |
279 HbAction *cancelAction = qobject_cast<HbAction *>( |
319 getObject(RoleOkAction)); |
280 getObject(RoleCancelAction)); |
320 if (okAction) { |
281 if (okAction && cancelAction) { |
321 dialog->addAction(okAction); |
282 dialog->addAction(okAction); |
322 } |
283 dialog->addAction(cancelAction); |
323 |
284 } |
324 HbAction *cancelAction = qobject_cast<HbAction *>( |
285 return dialog; |
325 getObject(RoleCancelAction)); |
|
326 if (cancelAction) { |
|
327 dialog->addAction(cancelAction); |
|
328 } |
|
329 } |
|
330 return activeLayout; |
|
331 } |
286 } |
332 |
287 |
333 /*! |
288 /*! |
334 Load widgets from document for given display role. |
289 Load widgets from document for given display role. |
335 */ |
290 */ |
340 DPRINT; |
295 DPRINT; |
341 bool loadResult(true); |
296 bool loadResult(true); |
342 |
297 |
343 // Cleanup previously loaded content in case of any data |
298 // Cleanup previously loaded content in case of any data |
344 widgetMap.clear(); |
299 widgetMap.clear(); |
345 |
|
346 if (!m_documentLoader) { |
|
347 m_documentLoader = new InfoWidgetDocumentLoader; |
|
348 } |
|
349 Q_ASSERT(m_documentLoader); |
|
350 |
300 |
351 bool loaded = true; |
301 bool loaded = true; |
352 if (displayRole != SettingsDialog) { |
302 if (displayRole != SettingsDialog) { |
353 m_documentLoader->load(INFOWIDGET_DOCML_FILE, &loaded); |
303 m_documentLoader->load(INFOWIDGET_DOCML_FILE, &loaded); |
354 } else { |
304 } else { |
356 } |
306 } |
357 |
307 |
358 Q_ASSERT_X(loaded, |
308 Q_ASSERT_X(loaded, |
359 "InfoWidgetLayoutManager", |
309 "InfoWidgetLayoutManager", |
360 "Invalid docml file"); |
310 "Invalid docml file"); |
361 |
|
362 |
311 |
363 foreach (LayoutItemRole role, displayWidgets) { |
312 foreach (LayoutItemRole role, displayWidgets) { |
364 QGraphicsWidget *widget = |
313 QGraphicsWidget *widget = |
365 loadWidget(*m_documentLoader, displayRole, role); |
314 loadWidget(*m_documentLoader, displayRole, role); |
366 if (widget) { |
315 if (widget) { |
392 |
341 |
393 return loadResult; |
342 return loadResult; |
394 } |
343 } |
395 |
344 |
396 /*! |
345 /*! |
397 Restores widgets from layout document. |
346 Loads or restores widgets from layout document. |
398 Called when layout items have been deleted |
347 Called when layout items haven't been loaded yet, or |
399 and items should be shown again. |
348 have been deleted and items should be shown again. |
400 */ |
349 */ |
401 bool InfoWidgetLayoutManager::reloadWidgets(const DisplayRole displayRole) |
350 bool InfoWidgetLayoutManager::loadWidgets(const DisplayRole displayRole) |
402 { |
351 { |
403 QList<LayoutItemRole> displayWidgetRoles = widgetRoles(displayRole); |
352 QList<LayoutItemRole> displayWidgetRoles = widgetRoles(displayRole); |
404 bool loadResult(false); |
353 bool loadResult(false); |
405 |
|
406 switch (displayRole) { |
354 switch (displayRole) { |
407 case InfoDisplay: |
355 case InfoDisplay: |
408 loadResult = loadWidgets(displayRole, |
356 loadResult = loadWidgets(displayRole, |
409 displayWidgetRoles, |
357 displayWidgetRoles, |
410 m_infoDisplayWidgets); |
358 m_infoDisplayWidgets); |
533 DisplayRole displayRole) const |
480 DisplayRole displayRole) const |
534 { |
481 { |
535 QList<LayoutItemRole> widgetRoles; |
482 QList<LayoutItemRole> widgetRoles; |
536 switch (displayRole) { |
483 switch (displayRole) { |
537 case InfoDisplay: |
484 case InfoDisplay: |
538 // Fill supported layout item roles for info display |
|
539 widgetRoles.append(RoleContent); |
485 widgetRoles.append(RoleContent); |
540 widgetRoles.append(RoleSpnIcon); |
486 widgetRoles.append(RoleSpnIcon); |
541 widgetRoles.append(RoleSpnMarqueeItem); |
487 widgetRoles.append(RoleSpnMarqueeItem); |
542 widgetRoles.append(RoleMcnIcon); |
488 widgetRoles.append(RoleMcnIcon); |
543 widgetRoles.append(RoleMcnMarqueeItem); |
489 widgetRoles.append(RoleMcnMarqueeItem); |
544 widgetRoles.append(RoleSatTextIcon); |
490 widgetRoles.append(RoleSatTextIcon); |
545 widgetRoles.append(RoleSatMarqueeItem); |
491 widgetRoles.append(RoleSatMarqueeItem); |
546 break; |
492 break; |
547 case SettingsDialog: |
493 case SettingsDialog: |
548 // Fill supported layout item roles for settings display |
|
549 widgetRoles.append(RoleSettingsDialog); |
494 widgetRoles.append(RoleSettingsDialog); |
550 widgetRoles.append(RoleSettingsContainer); |
495 widgetRoles.append(RoleSettingsContainer); |
551 widgetRoles.append(RoleSpnCheckBox); |
496 widgetRoles.append(RoleSpnCheckBox); |
552 widgetRoles.append(RoleMcnCheckBox); |
497 widgetRoles.append(RoleMcnCheckBox); |
553 widgetRoles.append(RoleSatTextCheckBox); |
498 widgetRoles.append(RoleSatTextCheckBox); |