diff -r 7516d6d86cf5 -r ed14f46c0e55 src/hbutils/document/hbdocumentloaderactions_p.cpp --- a/src/hbutils/document/hbdocumentloaderactions_p.cpp Mon Oct 04 17:49:30 2010 +0300 +++ b/src/hbutils/document/hbdocumentloaderactions_p.cpp Mon Oct 18 18:23:13 2010 +0300 @@ -41,7 +41,13 @@ #include "hbdocumentloader_p.h" #include #include - +#include +#include +#include +#include +#include +#include +#include class AccessToMetadata : public QObject { @@ -64,10 +70,16 @@ HbXmlLoaderBaseActions(), d( ref ) { - if ( window ) { - mCurrentProfile = HbDeviceProfile::profile(window); + if (window) { + mMainWindow = window; } else { - mCurrentProfile = HbDeviceProfile::current(); + qWarning() << "HbDocumentLoaderActions: Using default main window"; + QList mainWindows = hbInstance->allMainWindows(); + if (mainWindows.isEmpty()) { + qWarning() << "HbDocumentLoaderActions: Default main window not found"; + } else { + mMainWindow = mainWindows.at(0); + } } } @@ -309,16 +321,16 @@ qreal leftVal=0, topVal=0, rightVal=0, bottomVal=0; bool ok = true; - if (left.mType != HbXmlLengthValue::None) { + if (left.mValues.count()) { ok &= toPixels(left, leftVal); } - if (top.mType != HbXmlLengthValue::None) { + if (top.mValues.count()) { ok &= toPixels(top, topVal); } - if (right.mType != HbXmlLengthValue::None) { + if (right.mValues.count()) { ok &= toPixels(right, rightVal); } - if (bottom.mType != HbXmlLengthValue::None) { + if (bottom.mValues.count()) { ok &= toPixels(bottom, bottomVal); } if ( ok ) { @@ -341,10 +353,10 @@ qreal hintWidthVal, hintHeightVal; bool ok = true; - if ( hintWidth.mType != HbXmlLengthValue::None ) { + if ( hintWidth.mValues.count() ) { ok &= toPixels(hintWidth, hintWidthVal); } - if ( hintHeight.mType != HbXmlLengthValue::None ) { + if ( hintHeight.mValues.count() ) { ok &= toPixels(hintHeight, hintHeightVal); } if (!ok) { @@ -354,29 +366,29 @@ // TODO: Use set Size if both declared. It's more efficient. switch (hint) { case Qt::MinimumSize: - if ( hintWidth.mType != HbXmlLengthValue::None ) { + if ( hintWidth.mValues.count() ) { widget->setMinimumWidth(hintWidthVal); } - if ( hintHeight.mType != HbXmlLengthValue::None ) { + if ( hintHeight.mValues.count() ) { widget->setMinimumHeight(hintHeightVal); } break; case Qt::PreferredSize: - if ( hintWidth.mType != HbXmlLengthValue::None ) { + if ( hintWidth.mValues.count() ) { widget->setPreferredWidth(hintWidthVal); } - if ( hintHeight.mType != HbXmlLengthValue::None ) { + if ( hintHeight.mValues.count() ) { widget->setPreferredHeight(hintHeightVal); } break; case Qt::MaximumSize: - if ( hintWidth.mType != HbXmlLengthValue::None ) { + if ( hintWidth.mValues.count() ) { widget->setMaximumWidth(hintWidthVal); } - if ( hintHeight.mType != HbXmlLengthValue::None ) { + if ( hintHeight.mValues.count() ) { widget->setMaximumHeight(hintHeightVal); } break; @@ -387,10 +399,10 @@ if (fixed) { QSizePolicy policy = widget->sizePolicy(); - if ( hintWidth.mType != HbXmlLengthValue::None && hintWidthVal >= 0) { + if ( hintWidth.mValues.count() && hintWidthVal >= 0) { policy.setHorizontalPolicy(QSizePolicy::Fixed); } - if ( hintHeight.mType != HbXmlLengthValue::None && hintHeightVal >= 0) { + if ( hintHeight.mValues.count() && hintHeightVal >= 0) { policy.setVerticalPolicy(QSizePolicy::Fixed); } widget->setSizePolicy(policy); @@ -417,6 +429,19 @@ return result; } +bool HbDocumentLoaderActions::setBackground( const QString &name, HbFrameDrawer::FrameType type ) +{ + HbWidget *widget = qobject_cast(findFromStack()); + if (!widget) { + HB_DOCUMENTLOADER_PRINT( QString( "Cannot set background for non-HbWidget" ) ); + return false; + } + HbFrameItem *frame = new HbFrameItem(name, type, widget); + widget->setBackgroundItem(frame); + + return true; +} + bool HbDocumentLoaderActions::setSizePolicy( QSizePolicy::Policy *horizontalPolicy, QSizePolicy::Policy *verticalPolicy, @@ -541,7 +566,7 @@ anchor = new HbAnchor( srcId, srcEdge, dstId, dstEdge ); } - if ( minLength.mType != HbXmlLengthValue::None ) { + if ( minLength.mValues.count() ) { qreal minVal(0); if ( !toPixels(minLength, minVal) ) { delete anchor; @@ -551,17 +576,21 @@ } } - if ( prefLength.mType != HbXmlLengthValue::None ) { + if ( prefLength.mValues.count() ) { qreal prefVal(0); if ( !toPixels(prefLength, prefVal) ) { delete anchor; return false; } else { - anchor->setPreferredLength( prefVal ); + // if the expression resulted a negative result, we must reverse the direction + if ( prefVal < 0 && dir ) { + *dir = (*dir==HbAnchor::Positive) ? HbAnchor::Negative : HbAnchor::Positive; + } + anchor->setPreferredLength( qAbs(prefVal) ); } } - if ( maxLength.mType != HbXmlLengthValue::None ) { + if ( maxLength.mValues.count() ) { qreal maxVal(0); if ( !toPixels(maxLength, maxVal) ) { delete anchor; @@ -643,7 +672,7 @@ qreal spacingVal; bool setSpacing(false); - if (spacing.mType != HbXmlLengthValue::None) { + if (spacing.mValues.count()) { if ( toPixels(spacing, spacingVal) ) { setSpacing = true; } else { @@ -762,7 +791,7 @@ return false; } - if ( minHeight.mType != HbXmlLengthValue::None ) { + if ( minHeight.mValues.count() ) { qreal minHeightVal; if ( !toPixels(minHeight, minHeightVal) ) { return false; @@ -770,7 +799,7 @@ layout->setRowMinimumHeight( row, minHeightVal ); } - if ( maxHeight.mType != HbXmlLengthValue::None ) { + if ( maxHeight.mValues.count() ) { qreal maxHeightVal; if ( !toPixels(maxHeight, maxHeightVal) ) { return false; @@ -778,7 +807,7 @@ layout->setRowMaximumHeight( row, maxHeightVal ); } - if ( prefHeight.mType != HbXmlLengthValue::None ) { + if ( prefHeight.mValues.count() ) { qreal prefHeightVal; if ( !toPixels(prefHeight, prefHeightVal) ) { return false; @@ -786,7 +815,7 @@ layout->setRowPreferredHeight( row, prefHeightVal ); } - if ( fixedHeight.mType != HbXmlLengthValue::None ) { + if ( fixedHeight.mValues.count() ) { qreal fixedHeightVal; if ( !toPixels(fixedHeight, fixedHeightVal) ) { return false; @@ -794,7 +823,7 @@ layout->setRowFixedHeight( row, fixedHeightVal ); } - if ( rowSpacing.mType != HbXmlLengthValue::None ) { + if ( rowSpacing.mValues.count() ) { qreal rowSpacingVal; if ( !toPixels(rowSpacing, rowSpacingVal) ) { return false; @@ -820,7 +849,7 @@ return false; } - if ( minWidth.mType != HbXmlLengthValue::None ) { + if ( minWidth.mValues.count() ) { qreal minWidthVal; if ( !toPixels(minWidth, minWidthVal) ) { return false; @@ -828,7 +857,7 @@ layout->setColumnMinimumWidth( column, minWidthVal ); } - if ( maxWidth.mType != HbXmlLengthValue::None ) { + if ( maxWidth.mValues.count() ) { qreal maxWidthVal; if ( !toPixels(maxWidth, maxWidthVal) ) { return false; @@ -836,7 +865,7 @@ layout->setColumnMaximumWidth( column, maxWidthVal ); } - if ( prefWidth.mType != HbXmlLengthValue::None ) { + if ( prefWidth.mValues.count() ) { qreal prefWidthVal; if ( !toPixels(prefWidth, prefWidthVal) ) { return false; @@ -844,7 +873,7 @@ layout->setColumnPreferredWidth( column, prefWidthVal ); } - if ( fixedWidth.mType != HbXmlLengthValue::None ) { + if ( fixedWidth.mValues.count() ) { qreal fixedWidthVal; if ( !toPixels(fixedWidth, fixedWidthVal) ) { return false; @@ -852,7 +881,7 @@ layout->setColumnFixedWidth( column, fixedWidthVal ); } - if ( columnSpacing.mType != HbXmlLengthValue::None ) { + if ( columnSpacing.mValues.count() ) { qreal columnSpacingVal; if ( !toPixels(columnSpacing, columnSpacingVal) ) { return false; @@ -888,7 +917,7 @@ qreal spacingVal; bool setSpacing(false); - if (spacing.mType != HbXmlLengthValue::None) { + if (spacing.mValues.count()) { if ( toPixels(spacing, spacingVal) ) { setSpacing = true; } else { @@ -949,7 +978,7 @@ int indexValue = index ? *index : -1; layout->insertItem( indexValue, item ); - if ( spacing.mType != HbXmlLengthValue::None ) { + if ( spacing.mValues.count() ) { qreal spacingVal; if ( !toPixels(spacing, spacingVal) ) { return false; @@ -1007,16 +1036,16 @@ qreal leftVal=0, topVal=0, rightVal=0, bottomVal=0; bool ok = true; - if (left.mType != HbXmlLengthValue::None) { + if (left.mValues.count()) { ok &= toPixels(left, leftVal); } - if (top.mType != HbXmlLengthValue::None) { + if (top.mValues.count()) { ok &= toPixels(top, topVal); } - if (right.mType != HbXmlLengthValue::None) { + if (right.mValues.count()) { ok &= toPixels(right, rightVal); } - if (bottom.mType != HbXmlLengthValue::None) { + if (bottom.mValues.count()) { ok &= toPixels(bottom, bottomVal); } if ( ok ) { @@ -1191,19 +1220,19 @@ HbIcon icon(*iconName); qreal width, height; - if ( widthVal->mType != HbXmlLengthValue::None ) { + if ( widthVal->mValues.count() ) { result = toPixels(*widthVal, width); } - if ( result && heightVal->mType != HbXmlLengthValue::None ) { + if ( result && heightVal->mValues.count() ) { result = toPixels(*heightVal, height); } if ( result ) { - if ( widthVal->mType != HbXmlLengthValue::None && - heightVal->mType != HbXmlLengthValue::None ) { + if ( widthVal->mValues.count() && + heightVal->mValues.count() ) { icon.setSize(QSizeF(width, height)); - } else if ( widthVal->mType != HbXmlLengthValue::None ) { + } else if ( widthVal->mValues.count() ) { icon.setWidth(width); - } else if ( heightVal->mType != HbXmlLengthValue::None ) { + } else if ( heightVal->mValues.count() ) { icon.setHeight(height); } variant.setValue( icon ); @@ -1274,12 +1303,12 @@ quint8* role_b = (quint8*)variable.mParameters.at(0); HbXmlLengthValue* textHeightVal = (HbXmlLengthValue*)variable.mParameters.at(1); qreal textHeight; - if ( textHeightVal->mType != HbXmlLengthValue::None ) { + if ( textHeightVal->mValues.count() ) { result = toPixels(*textHeightVal, textHeight); } if (result) { HbFontSpec fontSpec((HbFontSpec::Role)(*role_b)); - if ( textHeightVal->mType != HbXmlLengthValue::None ) { + if ( textHeightVal->mValues.count() ) { fontSpec.setTextHeight(textHeight); } variant.setValue(fontSpec); @@ -1298,3 +1327,78 @@ } +bool HbDocumentLoaderActions::setObjectTree( QList roots ) +{ + reset(); + addToObjectMap( roots ); + return true; +} + +void HbDocumentLoaderActions::addToObjectMap( QList objects ) +{ + for ( int i = 0; i < objects.size(); i++ ) { + QObject *obj = objects.at(i); + QGraphicsWidget *widget = qobject_cast(obj); + + ObjectMapItem item; + item.mObject = obj; + item.mType = widget ? HbXml::WIDGET : HbXml::OBJECT; + item.mOwned = false; + mObjectMap.insert( obj->objectName(), item ); + + if ( widget ) { + widgetAddedToMap( widget ); + addToObjectMap( widget->childItems() ); + } else { + addToObjectMap( obj->children() ); + } + } +} + +void HbDocumentLoaderActions::addToObjectMap( QList objects ) +{ + for ( int i = 0; i < objects.size(); i++ ) { + if ( objects.at(i)->isWidget() ) { + QGraphicsWidget *widget = static_cast( objects.at(i) ); + ObjectMapItem item; + item.mObject = widget; + item.mType = HbXml::WIDGET; + item.mOwned = false; + mObjectMap.insert( widget->objectName(), item ); + addToObjectMap( widget->childItems() ); + } + } +} + +void HbDocumentLoaderActions::widgetAddedToMap(QGraphicsWidget *widget) +{ + // check the menu/toolbar from view + if ( widget->type() == Hb::ItemType_View ) { + HbView *view = qobject_cast(widget); + HbViewPrivate *viewPrivate = HbViewPrivate::d_ptr( view ); + if ( viewPrivate->menu ) { + QList newObjects; + newObjects << viewPrivate->menu.data(); + addToObjectMap( newObjects ); + } + if ( viewPrivate->toolBar ) { + QList newObjects; + newObjects << viewPrivate->toolBar.data(); + addToObjectMap( newObjects ); + } + // check submenu + } else if ( widget->type() == Hb::ItemType_Menu ) { + QList actions = widget->actions(); + for ( int i = 0; i < actions.count(); i++ ) { + HbAction *action = qobject_cast( actions.at(i) ); + if ( action && action->menu() ) { + QList newObjects; + newObjects << action->menu(); + addToObjectMap( newObjects ); + } + } + } +} + + +