src/hbutils/document/hbdocumentloaderactions_p.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 30 80e4d18b72f5
equal deleted inserted replaced
7:923ff622b8b9 21:4633027730f5
    39 #include <hbdocumentloader.h>
    39 #include <hbdocumentloader.h>
    40 
    40 
    41 #include "hbdocumentloader_p.h"
    41 #include "hbdocumentloader_p.h"
    42 #include <hbwidget_p.h>
    42 #include <hbwidget_p.h>
    43 #include <hbwidgetbase_p.h>
    43 #include <hbwidgetbase_p.h>
       
    44 #include <hbview.h>
       
    45 #include <hbview_p.h>
       
    46 #include <hbmenu.h>
       
    47 #include <hbtoolbar.h>
       
    48 #include <hbaction.h>
    44 
    49 
    45 
    50 
    46 class AccessToMetadata : public QObject
    51 class AccessToMetadata : public QObject
    47     {
    52     {
    48     public:
    53     public:
   555         qreal prefVal(0);
   560         qreal prefVal(0);
   556         if ( !toPixels(prefLength, prefVal) ) {
   561         if ( !toPixels(prefLength, prefVal) ) {
   557             delete anchor;
   562             delete anchor;
   558             return false;
   563             return false;
   559         } else {
   564         } else {
   560             anchor->setPreferredLength( prefVal );
   565             // if the expression resulted a negative result, we must reverse the direction
       
   566             if ( prefLength.mType == HbXmlLengthValue::Expression && prefVal < 0 && dir ) {
       
   567                 *dir = (*dir==HbAnchor::Positive) ? HbAnchor::Negative : HbAnchor::Positive;
       
   568             }
       
   569             anchor->setPreferredLength( qAbs(prefVal) );         
   561         }
   570         }
   562     }
   571     }
   563 
   572 
   564     if ( maxLength.mType != HbXmlLengthValue::None ) {
   573     if ( maxLength.mType != HbXmlLengthValue::None ) {
   565         qreal maxVal(0);
   574         qreal maxVal(0);
  1296 
  1305 
  1297     return result;
  1306     return result;
  1298 }
  1307 }
  1299 
  1308 
  1300 
  1309 
       
  1310 bool HbDocumentLoaderActions::setObjectTree( QList<QObject *> roots )
       
  1311 {
       
  1312     reset();
       
  1313     addToObjectMap( roots );
       
  1314     return true;
       
  1315 }
       
  1316 
       
  1317 void HbDocumentLoaderActions::addToObjectMap( QList<QObject *> objects )
       
  1318 {
       
  1319     for ( int i = 0; i < objects.size(); i++ ) {
       
  1320         QObject *obj = objects.at(i);
       
  1321         QGraphicsWidget *widget = qobject_cast<QGraphicsWidget*>(obj);
       
  1322 
       
  1323         ObjectMapItem item;
       
  1324         item.mObject = obj;
       
  1325         item.mType = widget ? HbXml::WIDGET : HbXml::OBJECT;
       
  1326         item.mOwned = false;
       
  1327         mObjectMap.insert( obj->objectName(), item );
       
  1328 
       
  1329         if ( widget ) {
       
  1330             widgetAddedToMap( widget );
       
  1331             addToObjectMap( widget->childItems() );
       
  1332         } else {
       
  1333             addToObjectMap( obj->children() );
       
  1334         }
       
  1335     }
       
  1336 }
       
  1337 
       
  1338 void HbDocumentLoaderActions::addToObjectMap( QList<QGraphicsItem *> objects )
       
  1339 {
       
  1340     for ( int i = 0; i < objects.size(); i++ ) {
       
  1341         if ( objects.at(i)->isWidget() ) {
       
  1342             QGraphicsWidget *widget = static_cast<QGraphicsWidget *>( objects.at(i) );
       
  1343             ObjectMapItem item;
       
  1344             item.mObject = widget;
       
  1345             item.mType = HbXml::WIDGET;
       
  1346             item.mOwned = false;
       
  1347             mObjectMap.insert( widget->objectName(), item );
       
  1348             addToObjectMap( widget->childItems() );
       
  1349         }
       
  1350     }    
       
  1351 }
       
  1352 
       
  1353 void HbDocumentLoaderActions::widgetAddedToMap(QGraphicsWidget *widget)
       
  1354 {
       
  1355     // check the menu/toolbar from view
       
  1356     if ( widget->type() == Hb::ItemType_View ) {
       
  1357         HbView *view = qobject_cast<HbView*>(widget);
       
  1358         HbViewPrivate *viewPrivate = HbViewPrivate::d_ptr( view );
       
  1359         if ( viewPrivate->menu ) {
       
  1360             QList<QObject *> newObjects;
       
  1361             newObjects << viewPrivate->menu.data();
       
  1362             addToObjectMap( newObjects );
       
  1363         }
       
  1364         if ( viewPrivate->toolBar ) {
       
  1365             QList<QObject *> newObjects;
       
  1366             newObjects << viewPrivate->toolBar.data();
       
  1367             addToObjectMap( newObjects );
       
  1368         }
       
  1369     // check submenu
       
  1370     } else if ( widget->type() == Hb::ItemType_Menu ) {
       
  1371         QList<QAction *> actions = widget->actions();
       
  1372         for ( int i = 0; i < actions.count(); i++ ) {
       
  1373             HbAction *action = qobject_cast<HbAction *>( actions.at(i) );
       
  1374             if ( action && action->menu() ) {
       
  1375                 QList<QObject *> newObjects;
       
  1376                 newObjects << action->menu();
       
  1377                 addToObjectMap( newObjects );
       
  1378             }
       
  1379         }
       
  1380     }
       
  1381 }
       
  1382 
       
  1383 
       
  1384