phoneplugins/infowidgetplugin/infowidget/src/infowidgetlayoutmanager.cpp
changeset 46 bc5a64e5bc3c
parent 45 6b911d05207e
child 50 377c906a8701
equal deleted inserted replaced
45:6b911d05207e 46:bc5a64e5bc3c
    13  *
    13  *
    14  * Description:
    14  * Description:
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 #include "infowidgetlayoutmanager.h"
       
    19 #include <QtGlobal>
    18 #include <QtGlobal>
    20 #include <QObject>
    19 #include <QObject>
    21 #include <QGraphicsWidget>
    20 #include <QGraphicsWidget>
    22 #include <hbdocumentloader.h>
    21 #include <hbdocumentloader.h>
    23 #include <hblabel.h>
    22 #include <hblabel.h>
    24 #include <hbaction.h>
    23 #include <hbaction.h>
    25 #include <hbmarqueeitem.h>
    24 #include <hbmarqueeitem.h>
    26 #include <hbiconitem.h> 
    25 #include <hbiconitem.h> 
    27 #include <hbpushbutton.h>
    26 #include <hbpushbutton.h>
       
    27 #include <hbinstance.h>
       
    28 #include "infowidgetlayoutmanager.h"
    28 #include "infowidgetlogging.h"
    29 #include "infowidgetlogging.h"
    29 
    30 
    30 /*!
    31 /*!
    31   \class InfoWidgetDocumentLoader
    32   \class InfoWidgetDocumentLoader
    32   \brief Custom document loader for Operator info widget  
    33   \brief Custom document loader for Operator info widget  
    65 const char LAYOUT_NAME_SETTINGSDIALOG[] = "settingsDialog"; 
    66 const char LAYOUT_NAME_SETTINGSDIALOG[] = "settingsDialog"; 
    66 const char LAYOUT_NAME_SETTINGSCONTAINER[] = "settingsContainer";
    67 const char LAYOUT_NAME_SETTINGSCONTAINER[] = "settingsContainer";
    67 const char LAYOUT_NAME_CONTAINER[] = "container";
    68 const char LAYOUT_NAME_CONTAINER[] = "container";
    68 
    69 
    69 /*!
    70 /*!
    70   InfoWidgetDocumentLoader::InfoWidgetDocumentLoader()
    71   Create object from document. 
    71  */
       
    72 InfoWidgetDocumentLoader::InfoWidgetDocumentLoader()
       
    73 {
       
    74 }
       
    75 
       
    76 /*!
       
    77   InfoWidgetDocumentLoader::createObject()
       
    78  */
    72  */
    79 QObject *InfoWidgetDocumentLoader::createObject(
    73 QObject *InfoWidgetDocumentLoader::createObject(
    80     const QString &type,
    74     const QString &type,
    81     const QString &name)
    75     const QString &name)
    82 {
    76 {
    83     DPRINT << ": IN";
    77     DPRINT;
    84     
       
    85     DPRINT << ": type: "<< type;
       
    86     DPRINT << ": name: "<< name;
       
    87     
       
    88     if ( type == HbMarqueeItem::staticMetaObject.className() ) {
    78     if ( type == HbMarqueeItem::staticMetaObject.className() ) {
    89         DPRINT << ": HbMarqueeItem";
       
    90         QObject *object = new HbMarqueeItem;
    79         QObject *object = new HbMarqueeItem;
    91         object->setObjectName(name);
    80         object->setObjectName(name);
    92         DPRINT << ": HbMarqueeitem found, OUT";
       
    93         return object;
    81         return object;
    94     }
    82     }
    95     
       
    96     DPRINT << ": OUT";
       
    97     return HbDocumentLoader::createObject(type, name);
    83     return HbDocumentLoader::createObject(type, name);
    98 }
    84 }
    99 
    85 
   100 /*!
    86 /*!
   101    InfoWidgetLayoutManager::InfoWidgetLayoutManager()
    87    Constructor. 
   102 */
    88 */
   103 InfoWidgetLayoutManager::InfoWidgetLayoutManager(QObject *parent) 
    89 InfoWidgetLayoutManager::InfoWidgetLayoutManager(QObject *parent) 
   104 : QObject(parent), 
    90 : QObject(parent), 
   105   m_documentLoader(NULL), 
    91   m_documentLoader(NULL), 
   106   m_displayRole(InfoDisplay),
    92   m_displayRole(InfoDisplay),
   107   m_layoutRows(0)
    93   m_layoutRows(0),
   108 {
    94   m_cachedLayoutRowHeight(0.0)
   109     DPRINT << ": IN"; 
    95 {
   110     
    96     DPRINT; 
   111     // Fill supported layout item roles for info display
    97     // Fill supported layout item roles for info display
   112     QList<LayoutItemRole> displayWidgetRoles = widgetRoles(InfoDisplay);
    98     QList<LayoutItemRole> displayWidgetRoles = widgetRoles(InfoDisplay);
   113     
    99     
   114     // Try to load all widgets in list by widget role 
   100     // Try to load all widgets in list by widget role 
   115     bool loadResult = loadWidgets(InfoDisplay, 
   101     bool loadResult = loadWidgets(InfoDisplay, 
   116             displayWidgetRoles,
   102             displayWidgetRoles,
   117             m_infoDisplayWidgets); 
   103             m_infoDisplayWidgets); 
   118     DPRINT << ": info display widget load result: " << loadResult;
       
   119     
   104     
   120     // Fill supported layout item roles for settings display
   105     // Fill supported layout item roles for settings display
   121     displayWidgetRoles = widgetRoles(SettingsDialog);
   106     displayWidgetRoles = widgetRoles(SettingsDialog);
   122   
   107 
   123     // Try to load all widgets in list by widget role 
   108     // Try to load all widgets in list by widget role 
   124     loadResult = loadWidgets(SettingsDialog, 
   109     loadResult = loadWidgets(SettingsDialog, 
   125             displayWidgetRoles,
   110             displayWidgetRoles,
   126             m_settingsDialogWidgets); 
   111             m_settingsDialogWidgets); 
   127     DPRINT << ": settings dialog widget load result: " << loadResult;
   112 }
   128     
   113 
   129     DPRINT << ": OUT";
   114 /*!
   130 }
   115    Destructor. 
   131 
       
   132 /*!
       
   133    InfoWidgetLayoutManager::~InfoWidgetLayoutManager()
       
   134 */
   116 */
   135 InfoWidgetLayoutManager::~InfoWidgetLayoutManager()
   117 InfoWidgetLayoutManager::~InfoWidgetLayoutManager()
   136 {
   118 {
   137     DPRINT << ": IN";
   119     DPRINT;
   138     
       
   139     if (m_documentLoader) { 
   120     if (m_documentLoader) { 
   140         delete m_documentLoader;
   121         delete m_documentLoader;
   141     }
   122     }
   142     
   123 }
   143     DPRINT << ": OUT";
   124 
   144 }
   125 /*!
   145 
   126    Destroy all widgets. 
   146 /*!
   127    Deletes parent widgets of each display 
   147    InfoWidgetLayoutManager::destroyWidgets()
   128    causing deletion of child items. 
   148 */
   129 */
   149 void InfoWidgetLayoutManager::destroyWidgets()
   130 void InfoWidgetLayoutManager::destroyWidgets()
   150 {
   131 {
   151     DPRINT << ": IN";
   132     DPRINT;
   152     
       
   153     // Destroy parent items 
   133     // Destroy parent items 
   154     removeWidget(RoleContent); 
   134     removeWidget(RoleContent); 
   155     removeWidget(RoleSettingsDialog); 
   135     removeWidget(RoleSettingsDialog); 
   156 
       
   157     DPRINT << ": OUT";    
       
   158 }
   136 }
   159 
   137 
   160 /*!
   138 /*!
   161    InfoWidgetLayoutManager::currentDisplayRole()
   139    InfoWidgetLayoutManager::currentDisplayRole()
   162 */
   140 */
   174     DPRINT; 
   152     DPRINT; 
   175     return m_widgets.keys(); 
   153     return m_widgets.keys(); 
   176 } 
   154 } 
   177 
   155 
   178 /*!
   156 /*!
   179    InfoWidgetLayoutManager::layoutRows()
   157    Returns count of layout rows. 
   180 */
   158 */
   181 int InfoWidgetLayoutManager::layoutRows() const 
   159 int InfoWidgetLayoutManager::layoutRows() const 
   182 {
   160 {
   183     DPRINT; 
   161     DPRINT; 
   184     return m_layoutRows;
   162     return m_layoutRows;
   185 } 
   163 } 
   186 
   164 
   187 /*!
   165 /*!
   188    InfoWidgetLayoutManager::setLayoutRows()
   166    Set count of layout rows.  
   189 */
   167 */
   190 void InfoWidgetLayoutManager::setLayoutRows(int rows) 
   168 void InfoWidgetLayoutManager::setLayoutRows(int rows) 
   191 {
   169 {
   192     DPRINT; 
   170     DPRINT; 
   193     m_layoutRows = rows; 
   171     m_layoutRows = rows; 
   194 } 
   172 } 
   195 
   173 
   196 /*!
   174 /*!
   197    InfoWidgetLayoutManager::layoutRowHeight()
   175    Read row height from style. 
   198    
   176 */
   199    Read size from style, currently graphics icon size used
   177 qreal InfoWidgetLayoutManager::layoutRowHeight()
   200    as it defines row height in layout. Real font height 
   178 {
   201    and layout spacing could be used instead. 
   179     DPRINT;
   202 */
   180     // Read from style only if not already initialized
   203 qreal InfoWidgetLayoutManager::layoutRowHeight() const
   181     if (m_cachedLayoutRowHeight == 0.0) { 
   204 {
   182         bool ok = hbInstance->style()->parameter("hb-param-graphic-size-primary-small", 
   205     DPRINT; 
   183                 m_cachedLayoutRowHeight);
   206     HbStyle style; 
   184             DPRINT << ": row height from style: " << m_cachedLayoutRowHeight;
   207     qreal rowHeight;
   185         if (!ok) {
   208 
   186             DWARNING << ": Error, paremeters reading failed!!";
   209     bool ok = style.parameter("hb-param-graphic-size-primary-small", 
   187         }
   210             rowHeight);
   188     }
   211     if (!ok) {
   189     return m_cachedLayoutRowHeight;
   212         DWARNING << ": Paremeters reading failed!! Using default";
   190 }
   213         rowHeight = 26.8;
   191 
   214     }
   192 /*!
   215     
   193    Check if text fits to given rect width.  
   216     DPRINT << ": rowHeight: " << rowHeight;
       
   217     return rowHeight; 
       
   218 }
       
   219 
       
   220 /*!
       
   221    InfoWidgetLayoutManager::textFitsToRect()
       
   222    
       
   223    Check if text fits to given rect width. Return true also if 
       
   224    text width is null, or text width AND rect width is null.   
       
   225 */
   194 */
   226 bool InfoWidgetLayoutManager::textFitsToRect(QString text, 
   195 bool InfoWidgetLayoutManager::textFitsToRect(QString text, 
   227         QFont font, QRectF rect)
   196         QFont font, QRectF rect) const 
   228 {
   197 {
   229     bool fits(true);
   198     bool fits(true);
   230     if (!rect.isEmpty()) { 
   199     if (!rect.isEmpty()) { 
   231         QFontMetricsF metrics(font);
   200         QFontMetricsF metrics(font);
   232         qreal width = metrics.boundingRect(text).width();
   201         qreal width = metrics.boundingRect(text).width();
   233         if (width > rect.width() ) {
   202         if (width > rect.width() ) {
   234             fits = false; 
   203             fits = false; 
   235         }
   204         }
   236     }
   205     }
   237     
       
   238     DPRINT << ": fits: " << fits;
       
   239     return fits; 
   206     return fits; 
   240 }
   207 }
   241 
   208 
   242 /*!
   209 /*!
   243    InfoWidgetLayoutManager::contentWidget()
   210    Returns content widget.  
       
   211    The content widget is layout main widget and parent for 
       
   212    sub-widgets in current display.     
   244 */
   213 */
   245 QGraphicsWidget* InfoWidgetLayoutManager::contentWidget()
   214 QGraphicsWidget* InfoWidgetLayoutManager::contentWidget()
   246 {
   215 {
   247     DPRINT; 
   216     DPRINT; 
   248     return getWidget(RoleContent); 
   217     return getWidget(RoleContent); 
   249 }
   218 }
   250 
   219 
   251 /*!
   220 /*!
   252    InfoWidgetLayoutManager::marqueeItems()
   221    Returns list of marquee items.  
   253 */
   222 */
   254 QList<HbMarqueeItem *> InfoWidgetLayoutManager::marqueeItems() 
   223 QList<HbMarqueeItem *> InfoWidgetLayoutManager::marqueeItems() 
   255 {
   224 {
   256     DPRINT;
   225     DPRINT;
   257     QList<HbMarqueeItem *> items;
   226     QList<HbMarqueeItem *> items;
   259     QList<LayoutItemRole> marqueeItemRoles; 
   228     QList<LayoutItemRole> marqueeItemRoles; 
   260     marqueeItemRoles.append(RoleSpnMarqueeItem);
   229     marqueeItemRoles.append(RoleSpnMarqueeItem);
   261     marqueeItemRoles.append(RoleMcnMarqueeItem);
   230     marqueeItemRoles.append(RoleMcnMarqueeItem);
   262     marqueeItemRoles.append(RoleSatMarqueeItem);
   231     marqueeItemRoles.append(RoleSatMarqueeItem);
   263     
   232     
   264     LayoutItemRole role;
   233     foreach (LayoutItemRole role, marqueeItemRoles) {
   265     HbMarqueeItem *item(NULL);
   234         QGraphicsWidget *widget = getWidget(role); 
   266     QGraphicsWidget *widget(NULL); 
       
   267     foreach (role, marqueeItemRoles) {
       
   268         widget = getWidget(role); 
       
   269         if (widget) {
   235         if (widget) {
   270             item = qobject_cast<HbMarqueeItem*>(widget); 
   236             HbMarqueeItem *item = 
       
   237                     qobject_cast<HbMarqueeItem*>(widget); 
   271             if (item) {
   238             if (item) {
   272                 items.append(item); 
   239                 items.append(item); 
   273                 item = NULL; 
   240                 item = NULL; 
   274             }
   241             }
   275         }
   242         }
   276     }
   243     }
   277     DPRINT << ": count of marquee items: " << items.count(); 
       
   278     return items; 
   244     return items; 
   279 }
   245 }
   280 
   246 
   281 /*!
   247 /*!
   282    InfoWidgetLayoutManager::getWidget();
   248    Get widget with given item role. 
   283 */
   249 */
   284 QGraphicsWidget* InfoWidgetLayoutManager::getWidget(LayoutItemRole itemRole)
   250 QGraphicsWidget* InfoWidgetLayoutManager::getWidget(LayoutItemRole itemRole)
   285 {
   251 {
   286     DPRINT << ": item role: " << itemRole;
   252     QGraphicsWidget *widget = m_widgets.value(itemRole); 
   287     
   253     return widget; 
       
   254 }
       
   255 
       
   256 /*!
       
   257    Get object with given item role. 
       
   258 */
       
   259 QObject* InfoWidgetLayoutManager::getObject(LayoutItemRole itemRole)
       
   260 {
       
   261     QObject *object = m_objects.value(itemRole); 
       
   262     return object; 
       
   263 }
       
   264 
       
   265 /*!
       
   266    Remove widget with given item role. 
       
   267 */
       
   268 void InfoWidgetLayoutManager::removeWidget(LayoutItemRole itemRole, 
       
   269         bool deleteLater)
       
   270 {
       
   271     DPRINT;
   288     QGraphicsWidget *widget = m_widgets.value(itemRole); 
   272     QGraphicsWidget *widget = m_widgets.value(itemRole); 
   289     if (widget) {
   273     if (widget) {
   290         DPRINT << ": widget: " << widget;
       
   291     }
       
   292     
       
   293     return widget; 
       
   294 }
       
   295 
       
   296 /*!
       
   297    InfoWidgetLayoutManager::getObject();
       
   298 */
       
   299 QObject* InfoWidgetLayoutManager::getObject(LayoutItemRole itemRole)
       
   300 {
       
   301     DPRINT << ": item role: " << itemRole;
       
   302     
       
   303     QObject *object = m_objects.value(itemRole); 
       
   304     if (object) {
       
   305         DPRINT << ": object: " << object;
       
   306     }
       
   307     
       
   308     return object; 
       
   309 }
       
   310 
       
   311 /*!
       
   312    InfoWidgetLayoutManager::removeWidget();
       
   313 */
       
   314 void InfoWidgetLayoutManager::removeWidget(LayoutItemRole itemRole, 
       
   315         bool deleteLater)
       
   316 {
       
   317     DPRINT << ": item role: " << itemRole;
       
   318     
       
   319     QGraphicsWidget *widget = m_widgets.value(itemRole); 
       
   320     if (widget) {
       
   321         DPRINT << ": removing widget: " << widget;        
       
   322         m_widgets.remove(itemRole);
       
   323         if (!deleteLater) {
   274         if (!deleteLater) {
   324             delete widget;
   275             delete widget;
   325         } else {
   276         } else {
   326             widget->deleteLater(); 
   277             widget->deleteLater(); 
   327         }
   278         }
   328     }
   279     }
   329     
   280     
   330     widget = m_infoDisplayWidgets.value(itemRole); 
   281     m_widgets.remove(itemRole);
   331     if (widget) {
   282     m_infoDisplayWidgets.remove(itemRole);
   332         DPRINT << ": removing widget from m_infoDisplayWidgets";        
   283     m_settingsDialogWidgets.remove(itemRole);
   333         m_infoDisplayWidgets.remove(itemRole);
   284 }
   334     }
   285 
   335     
   286 /*!
   336     widget = m_settingsDialogWidgets.value(itemRole); 
   287     Returns info display layout.  
   337     if (widget) {
       
   338         DPRINT << ": removing widget from m_settingsDialogWidgets";         
       
   339         m_settingsDialogWidgets.remove(itemRole);
       
   340     }
       
   341 }
       
   342 
       
   343 /*!
       
   344     InfoWidgetLayoutManager::layoutInfoDisplay()
       
   345 */
   288 */
   346 QGraphicsLayout* InfoWidgetLayoutManager::layoutInfoDisplay()
   289 QGraphicsLayout* InfoWidgetLayoutManager::layoutInfoDisplay()
   347 {   
   290 {   
   348     DPRINT << ": IN";
   291     DPRINT;
   349 
       
   350     m_displayRole = InfoDisplay;
   292     m_displayRole = InfoDisplay;
   351     m_widgets = m_infoDisplayWidgets; 
   293     m_widgets = m_infoDisplayWidgets; 
   352            
   294            
   353     QGraphicsLayout *activeLayout(NULL); 
   295     QGraphicsLayout *activeLayout(NULL); 
   354     DPRINT << ": getting content item and using its layout for activeLayout";
       
   355     QGraphicsWidget *content = getWidget(RoleContent); 
   296     QGraphicsWidget *content = getWidget(RoleContent); 
   356     if (content) {
   297     if (content) {
   357         DPRINT << ": content found, getting layout";
   298         DPRINT << ": content found, getting layout";
   358         activeLayout = content->layout(); 
   299         activeLayout = content->layout(); 
   359     }
   300     }
   360 
       
   361     DPRINT  << ": OUT";
       
   362     return activeLayout; 
   301     return activeLayout; 
   363 }
   302 }
   364 
   303 
   365 /*!
   304 /*!
   366     InfoWidgetLayoutManager::layoutSettingsDialog()
   305     Returns settings dialog layout. 
   367 */
   306 */
   368 QGraphicsLayout* InfoWidgetLayoutManager::layoutSettingsDialog()
   307 QGraphicsLayout* InfoWidgetLayoutManager::layoutSettingsDialog()
   369 {   
   308 {   
   370     DPRINT << ": IN";
   309     DPRINT;
   371     
       
   372     m_displayRole = SettingsDialog;
   310     m_displayRole = SettingsDialog;
   373     m_widgets = m_settingsDialogWidgets; 
   311     m_widgets = m_settingsDialogWidgets; 
   374     
   312     
   375     QGraphicsLayout *activeLayout(NULL); 
   313     QGraphicsLayout *activeLayout(NULL); 
   376     DPRINT << ": getting settingsDialog item";
       
   377     QGraphicsWidget *dialog = getWidget(RoleSettingsDialog); 
   314     QGraphicsWidget *dialog = getWidget(RoleSettingsDialog); 
   378     if (dialog) {
   315     if (dialog) {
   379         DPRINT << ": dialog found, getting layout";
       
   380         activeLayout = dialog->layout(); 
   316         activeLayout = dialog->layout(); 
   381         
   317 
   382         HbAction *okAction = qobject_cast<HbAction *>(getObject(RoleOkAction));
   318         HbAction *okAction = qobject_cast<HbAction *>(
       
   319                 getObject(RoleOkAction));
   383         if (okAction) {
   320         if (okAction) {
   384             dialog->addAction(okAction); 
   321             dialog->addAction(okAction); 
   385         }
   322         }
   386         
   323         
   387         HbAction *cancelAction = qobject_cast<HbAction *>(getObject(RoleCancelAction));
   324         HbAction *cancelAction = qobject_cast<HbAction *>(
       
   325                 getObject(RoleCancelAction));
   388         if (cancelAction) {
   326         if (cancelAction) {
   389             dialog->addAction(cancelAction);
   327             dialog->addAction(cancelAction);
   390         }
   328         }
   391     }
   329     }
   392 
       
   393     DPRINT  << ": OUT";
       
   394     return activeLayout;    
   330     return activeLayout;    
   395 }
   331 }
   396 
   332 
   397 /*!
   333 /*!
   398     InfoWidgetLayoutManager::loadWidgets()
   334     Load widgets from document for given display role.
   399 */
   335 */
   400 bool InfoWidgetLayoutManager::loadWidgets(const DisplayRole displayRole, 
   336 bool InfoWidgetLayoutManager::loadWidgets(const DisplayRole displayRole, 
   401         const QList<LayoutItemRole> &displayWidgets,
   337         const QList<LayoutItemRole> &displayWidgets,
   402         QMap<LayoutItemRole, QGraphicsWidget *> &widgetMap)
   338         QMap<LayoutItemRole, QGraphicsWidget *> &widgetMap)
   403 {
   339 {
   404     DPRINT << ": IN";
   340     DPRINT;
   405     bool loadResult(true); 
   341     bool loadResult(true); 
   406 
   342 
   407     // Cleanup previously loaded content in case of any data  
   343     // Cleanup previously loaded content in case of any data  
   408     widgetMap.clear(); 
   344     widgetMap.clear(); 
   409     
   345     
   410     if (!m_documentLoader) {
   346     if (!m_documentLoader) {
   411         m_documentLoader = new InfoWidgetDocumentLoader;
   347         m_documentLoader = new InfoWidgetDocumentLoader;
   412     }
   348     }
   413     
       
   414     Q_ASSERT(m_documentLoader); 
   349     Q_ASSERT(m_documentLoader); 
   415     
   350     
   416     bool loaded = true;
   351     bool loaded = true;
   417     if (displayRole != SettingsDialog) {
   352     if (displayRole != SettingsDialog) {
   418         m_documentLoader->load(INFOWIDGET_DOCML_FILE, &loaded);
   353         m_documentLoader->load(INFOWIDGET_DOCML_FILE, &loaded);
   422     
   357     
   423     Q_ASSERT_X(loaded, 
   358     Q_ASSERT_X(loaded, 
   424             "InfoWidgetLayoutManager", 
   359             "InfoWidgetLayoutManager", 
   425             "Invalid docml file");    
   360             "Invalid docml file");    
   426     
   361     
   427     QGraphicsWidget *widget(NULL);
   362     
   428     LayoutItemRole currentWidgetRole;
   363     foreach (LayoutItemRole role, displayWidgets) {
   429     bool allWidgetsLoaded(true); 
   364         QGraphicsWidget *widget = 
   430     
   365                 loadWidget(*m_documentLoader, displayRole, role);
   431     foreach (currentWidgetRole, displayWidgets) {
       
   432         widget = loadWidget(*m_documentLoader, displayRole, currentWidgetRole);
       
   433            if (widget) {
   366            if (widget) {
   434                widgetMap.insert(currentWidgetRole, widget);
   367                widgetMap.insert(role, widget);
   435                widget = NULL;
   368                widget = NULL;
   436            } else {
   369            } 
   437                allWidgetsLoaded = false; 
   370     }
   438                DWARNING << ": widget not found!";
   371     
   439            }
   372     if (widgetMap.count() == displayWidgets.count()) {
   440     }
       
   441     
       
   442     DPRINT << ": allWidgetsLoaded: " << allWidgetsLoaded;
       
   443             
       
   444     int widgetCount = widgetMap.count(); 
       
   445     if (widgetCount == displayWidgets.count()) {
       
   446         loadResult = true;
   373         loadResult = true;
   447         } else {
   374         } else {
   448             DWARNING << ": all widgets were not loaded!";
   375             DWARNING << ": all widgets were not loaded!";
   449             loadResult = false;
   376             loadResult = false;
   450         }        
   377         }        
   451     
   378 
       
   379     m_objects.clear();
   452     if (displayRole == SettingsDialog) {
   380     if (displayRole == SettingsDialog) {
   453         m_objects.clear();
       
   454         QObject *okAction = 
   381         QObject *okAction = 
   455                 loadObject(*m_documentLoader, 
   382                 loadObject(*m_documentLoader, 
   456                         displayRole, 
   383                         displayRole, 
   457                         RoleOkAction);
   384                         RoleOkAction);
   458                 m_objects.insert(RoleOkAction, okAction); 
   385                 m_objects.insert(RoleOkAction, okAction); 
   460                 loadObject(*m_documentLoader, 
   387                 loadObject(*m_documentLoader, 
   461                         displayRole, 
   388                         displayRole, 
   462                         RoleCancelAction); 
   389                         RoleCancelAction); 
   463                 m_objects.insert(RoleCancelAction, cancelAction); 
   390                 m_objects.insert(RoleCancelAction, cancelAction); 
   464     } 
   391     } 
   465     
   392 
   466     DPRINT << ": OUT";
       
   467     return loadResult; 
   393     return loadResult; 
   468 }
   394 }
   469 
   395 
   470 /*!
   396 /*!
   471     InfoWidgetLayoutManager::reloadWidgets()
   397     Restores widgets from layout document. 
       
   398     Called when layout items have been deleted  
       
   399     and items should be shown again. 
   472 */
   400 */
   473 bool InfoWidgetLayoutManager::reloadWidgets(const DisplayRole displayRole)
   401 bool InfoWidgetLayoutManager::reloadWidgets(const DisplayRole displayRole)
   474 {
   402 {
   475     QList<LayoutItemRole> displayWidgetRoles = widgetRoles(displayRole); 
   403     QList<LayoutItemRole> displayWidgetRoles = widgetRoles(displayRole); 
   476     bool loadResult(false); 
   404     bool loadResult(false); 
   491     }
   419     }
   492     return loadResult; 
   420     return loadResult; 
   493 }
   421 }
   494 
   422 
   495 /*!
   423 /*!
   496     InfoWidgetLayoutManager::loadWidget()
   424     Loads widget by given widget role id.
   497     
       
   498     Initialize loader with corresponding document file 
       
   499     before calling this single widget loader utility   
       
   500 */
   425 */
   501 QGraphicsWidget* InfoWidgetLayoutManager::loadWidget(InfoWidgetDocumentLoader &loader, 
   426 QGraphicsWidget* InfoWidgetLayoutManager::loadWidget(InfoWidgetDocumentLoader &loader, 
   502         DisplayRole displayRole, 
   427         DisplayRole displayRole, 
   503         LayoutItemRole widgetRole)
   428         LayoutItemRole widgetRole)
   504 {
   429 {
   505     DPRINT << ": IN";
   430     DPRINT;
   506      
       
   507     QString widgetPrefix; 
   431     QString widgetPrefix; 
   508     if (displayRole == InfoDisplay) {
   432     if (displayRole == InfoDisplay) {
   509         widgetPrefix = LAYOUT_PREFIX_INFO_DISPLAY;
   433         widgetPrefix = LAYOUT_PREFIX_INFO_DISPLAY;
   510     } else if (displayRole == SettingsDialog) {
   434     } else if (displayRole == SettingsDialog) {
   511         widgetPrefix = LAYOUT_PREFIX_SETTINGS_DIALOG;
   435         widgetPrefix = LAYOUT_PREFIX_SETTINGS_DIALOG;
   512     }
   436     }
   513         
   437         
   514     QGraphicsWidget *widget(NULL);
       
   515     QString widgetName = widgetPrefix;
   438     QString widgetName = widgetPrefix;
   516     
       
   517     switch (widgetRole) 
   439     switch (widgetRole) 
   518         {
   440         {
   519         case RoleContent: 
   441         case RoleContent: 
   520             widgetName.append(LAYOUT_NAME_CONTENT);
   442             widgetName.append(LAYOUT_NAME_CONTENT);
   521         break;     
   443         break;     
   559         case RoleUndefined: // Fall through 
   481         case RoleUndefined: // Fall through 
   560         default: 
   482         default: 
   561             break; 
   483             break; 
   562         }
   484         }
   563     
   485     
   564     DPRINT << ": widget name: " << widgetName;
   486     QGraphicsWidget *widget = qobject_cast<QGraphicsWidget *>(
   565     widget = qobject_cast<QGraphicsWidget *>(loader.findWidget(widgetName));
   487             loader.findWidget(widgetName));
   566     
       
   567     if (widget) {
       
   568         DPRINT << ": widget found: " << widgetName;
       
   569     } else {
       
   570         DPRINT << ": ERROR, widget not found!";
       
   571     }
       
   572            
       
   573     DPRINT << ": OUT";
       
   574     return widget; 
   488     return widget; 
   575 }
   489 }
   576 
   490 
   577 /*!
   491 /*!
   578     InfoWidgetLayoutManager::loadObject()
   492     Loads object by given object role id. 
   579     
       
   580     Initialize loader with corresponding document 
       
   581     file before calling this single object loader utility   
       
   582 */
   493 */
   583 QObject* InfoWidgetLayoutManager::loadObject(InfoWidgetDocumentLoader &loader, 
   494 QObject* InfoWidgetLayoutManager::loadObject(InfoWidgetDocumentLoader &loader, 
   584         DisplayRole displayRole, 
   495         DisplayRole displayRole, 
   585         LayoutItemRole objectRole)
   496         LayoutItemRole objectRole)
   586 {
   497 {
   587     DPRINT << ": IN";
   498     DPRINT;
   588      
       
   589     QString objectPrefix; 
   499     QString objectPrefix; 
   590     if (displayRole == InfoDisplay) {
   500     if (displayRole == InfoDisplay) {
   591         objectPrefix = LAYOUT_PREFIX_INFO_DISPLAY;
   501         objectPrefix = LAYOUT_PREFIX_INFO_DISPLAY;
   592     } else if (displayRole == SettingsDialog) {
   502     } else if (displayRole == SettingsDialog) {
   593         objectPrefix = LAYOUT_PREFIX_SETTINGS_DIALOG;
   503         objectPrefix = LAYOUT_PREFIX_SETTINGS_DIALOG;
   594     }
   504     }
   595         
   505         
   596     QObject *object(NULL);
       
   597     QString objectName = objectPrefix;
   506     QString objectName = objectPrefix;
   598     
       
   599     switch (objectRole) 
   507     switch (objectRole) 
   600         {
   508         {
   601         case RoleOkAction: 
   509         case RoleOkAction: 
   602             objectName.append(LAYOUT_NAME_OKACTION);
   510             objectName.append(LAYOUT_NAME_OKACTION);
   603         break;
   511         break;
   607 
   515 
   608         case RoleUndefined: // Fall through 
   516         case RoleUndefined: // Fall through 
   609         default: 
   517         default: 
   610             break; 
   518             break; 
   611         }
   519         }
   612     
   520 
   613     DPRINT << ": object name: " << objectName;
   521     QObject *object = qobject_cast<QObject *>(loader.findObject(objectName));
   614     object = qobject_cast<QObject *>(loader.findObject(objectName));
   522     if (!object) {
   615     
   523         DWARNING << ": ERROR, object not found!";
   616     if (object) {
       
   617         DPRINT << ": object found: " << objectName;
       
   618     } else {
       
   619         DPRINT << ": ERROR, object not found!";
       
   620     }
   524     }
   621            
   525            
   622     DPRINT << ": OUT";
       
   623     return object; 
   526     return object; 
   624 }
   527 }
   625 
   528 
   626 
   529 /*!
   627 /*!
   530     Returns supported widget roles for specific display.
   628     InfoWidgetLayoutManager::widgetRoles()
       
   629     
       
   630     Returns supported widget roles for specific display
       
   631 */
   531 */
   632 const QList<InfoWidgetLayoutManager::LayoutItemRole> InfoWidgetLayoutManager::widgetRoles(
   532 const QList<InfoWidgetLayoutManager::LayoutItemRole> InfoWidgetLayoutManager::widgetRoles(
   633         DisplayRole displayRole) const
   533         DisplayRole displayRole) const
   634 {
   534 {
   635     QList<LayoutItemRole> widgetRoles; 
   535     QList<LayoutItemRole> widgetRoles; 
   655             
   555             
   656         default: 
   556         default: 
   657             break; 
   557             break; 
   658     }
   558     }
   659     
   559     
   660     DPRINT << ": widgetRoles.count() : " << widgetRoles.count();
       
   661     return widgetRoles; 
   560     return widgetRoles; 
   662 }    
   561 }    
   663     
   562     
   664 // End of File. 
   563 // End of File. 
   665 
   564