37 #include <QDebug> |
37 #include <QDebug> |
38 |
38 |
39 |
39 |
40 // Document loader version number |
40 // Document loader version number |
41 #define VERSION_MAJOR 1 |
41 #define VERSION_MAJOR 1 |
42 #define VERSION_MINOR 1 |
42 #define VERSION_MINOR 2 |
43 |
43 |
44 #define MIN_SUPPORTED_VERSION_MAJOR 0 |
44 #define MIN_SUPPORTED_VERSION_MAJOR 0 |
45 #define MIN_SUPPORTED_VERSION_MINOR 1 |
45 #define MIN_SUPPORTED_VERSION_MINOR 1 |
46 |
46 |
47 |
47 |
86 QMetaObject metaobject = staticQtMetaObject; |
86 QMetaObject metaobject = staticQtMetaObject; |
87 QMetaEnum e = metaobject.enumerator( metaobject.indexOfEnumerator( enumeration ) ); |
87 QMetaEnum e = metaobject.enumerator( metaobject.indexOfEnumerator( enumeration ) ); |
88 return e.keysToValue( str ); |
88 return e.keysToValue( str ); |
89 } |
89 } |
90 }; |
90 }; |
|
91 |
|
92 static bool toFontSpecRole(const QString &roleString, HbFontSpec::Role &role) |
|
93 { |
|
94 bool success(false); |
|
95 int enumInt = HbFontSpec::staticMetaObject.enumerator( |
|
96 HbFontSpec::staticMetaObject.indexOfEnumerator("Role")).keyToValue(roleString.toLatin1()); |
|
97 if (enumInt >= 0) { |
|
98 success = true; |
|
99 role = static_cast<HbFontSpec::Role>(enumInt); |
|
100 } |
|
101 return success; |
|
102 } |
91 |
103 |
92 /* |
104 /* |
93 \class HbDocumentLoaderSyntax |
105 \class HbDocumentLoaderSyntax |
94 \internal |
106 \internal |
95 \proto |
107 \proto |
136 switch( mCurrentLayoutType ) { |
148 switch( mCurrentLayoutType ) { |
137 case LAYOUT_ANCHOR: |
149 case LAYOUT_ANCHOR: |
138 { |
150 { |
139 HB_DOCUMENTLOADER_PRINT( "GENERAL LAYOUT START ITEM: ANCHOR ITEM" ); |
151 HB_DOCUMENTLOADER_PRINT( "GENERAL LAYOUT START ITEM: ANCHOR ITEM" ); |
140 if( mReader.name() == lexemValue( AL_ANCHOR ) ) { |
152 if( mReader.name() == lexemValue( AL_ANCHOR ) ) { |
141 |
153 result = readAnchorLayoutStartItem(false); |
142 const QString src = attribute( AL_SRC_NAME ); |
154 } else if( mReader.name() == lexemValue( AL_MAPPING ) ) { |
143 const QString dst = attribute( AL_DST_NAME ); |
155 const QString item = attribute( AL_MAPPING_ITEM ); |
144 const QString srcEdgeStr = attribute( AL_SRC_EDGE ); |
156 const QString id = attribute( AL_MAPPING_ID ); |
145 const QString dstEdgeStr = attribute( AL_DST_EDGE ); |
157 const QString action = attribute( ATTR_ACTION ); |
146 const QString spacing = attribute( AL_SPACING ); |
158 bool remove = false; |
147 const QString spacer = attribute( AL_SPACER ); |
159 if ( !action.isEmpty() ) { |
148 HbXmlLengthValue spacingVal; |
160 if (!action.compare("remove", Qt::CaseInsensitive)) { |
149 result = true; |
161 remove = true; |
150 if( !spacing.isEmpty() ) { |
162 } else if (action.compare("set", Qt::CaseInsensitive)) { |
151 result = toLengthValue( spacing, spacingVal ); |
163 qWarning() << "Invalid anchoritem action, line " << mReader.lineNumber(); |
152 } |
164 return false; |
153 Hb::Edge srcEdge, dstEdge; |
165 } |
154 result &= getAnchorEdge( srcEdgeStr, srcEdge ); |
166 } |
155 result &= getAnchorEdge( dstEdgeStr, dstEdge ); |
167 |
156 if ( result ) { |
168 result = mActions->setAnchorLayoutMapping( item, id, remove ); |
157 result = mActions->addAnchorLayoutEdge( src, srcEdge, dst, dstEdge, spacingVal, spacer ); |
|
158 } |
|
159 } |
169 } |
160 break; |
170 break; |
161 } |
171 } |
162 case LAYOUT_GRID: |
172 case LAYOUT_GRID: |
163 { |
173 { |
760 return false; |
771 return false; |
761 } |
772 } |
762 return true; |
773 return true; |
763 } |
774 } |
764 |
775 |
765 bool HbDocumentLoaderSyntax::processSpacerItem() |
|
766 { |
|
767 const QString name = attribute( ATTR_NAME ); |
|
768 const QString widget = attribute( ATTR_WIDGET ); |
|
769 |
|
770 bool pushOK = mActions->pushSpacerItem( name, widget ); |
|
771 if( !pushOK ) { |
|
772 qWarning() << "Error in object processing, line " << mReader.lineNumber(); |
|
773 return false; |
|
774 } |
|
775 return true; |
|
776 } |
|
777 |
|
778 bool HbDocumentLoaderSyntax::processLayout() |
776 bool HbDocumentLoaderSyntax::processLayout() |
779 { |
777 { |
780 bool result = false; |
778 bool result = false; |
781 const QString layout_type = attribute( ATTR_TYPE ); |
779 const QString layout_type = attribute( ATTR_TYPE ); |
782 const QString widget = attribute( ATTR_WIDGET ); |
780 const QString widget = attribute( ATTR_WIDGET ); |
|
781 const QString action = attribute( ATTR_ACTION ); |
|
782 bool modify = false; |
|
783 if ( !action.isEmpty() ) { |
|
784 if (!action.compare("modify", Qt::CaseInsensitive)) { |
|
785 modify = true; |
|
786 } else if (action.compare("create", Qt::CaseInsensitive)) { |
|
787 qWarning() << "Invalid layout action, line " << mReader.lineNumber(); |
|
788 return false; |
|
789 } |
|
790 } |
783 |
791 |
784 if( layout_type == lexemValue( LAYOUT_ANCHOR ) ) { |
792 if( layout_type == lexemValue( LAYOUT_ANCHOR ) ) { |
785 |
793 |
786 mCurrentLayoutType = LAYOUT_ANCHOR; |
794 mCurrentLayoutType = LAYOUT_ANCHOR; |
787 result = mActions->createAnchorLayout( widget ); |
795 result = mActions->createAnchorLayout( widget, modify ); |
788 |
796 |
789 } else if( layout_type == lexemValue( LAYOUT_GRID ) ) { |
797 } else if( layout_type == lexemValue( LAYOUT_GRID ) ) { |
790 |
798 |
791 result = true; |
799 result = true; |
792 mCurrentLayoutType = LAYOUT_GRID; |
800 mCurrentLayoutType = LAYOUT_GRID; |
794 HbXmlLengthValue spacingValue; |
802 HbXmlLengthValue spacingValue; |
795 if( !spacing.isEmpty() ) { |
803 if( !spacing.isEmpty() ) { |
796 result = toLengthValue( spacing, spacingValue ); |
804 result = toLengthValue( spacing, spacingValue ); |
797 } |
805 } |
798 if (result) { |
806 if (result) { |
799 result = mActions->createGridLayout( widget, spacingValue ); |
807 result = mActions->createGridLayout( widget, spacingValue, modify ); |
800 } |
808 } |
801 |
809 |
802 } else if( layout_type == lexemValue( LAYOUT_LINEAR ) ) { |
810 } else if( layout_type == lexemValue( LAYOUT_LINEAR ) ) { |
803 |
811 |
804 result = true; |
812 result = true; |
824 HbXmlLengthValue spacingValue; |
832 HbXmlLengthValue spacingValue; |
825 if( result && !spacing.isEmpty() ) { |
833 if( result && !spacing.isEmpty() ) { |
826 result = toLengthValue( spacing, spacingValue ); |
834 result = toLengthValue( spacing, spacingValue ); |
827 } |
835 } |
828 if (result) { |
836 if (result) { |
829 result = mActions->createLinearLayout( widget, orient_p, spacingValue ); |
837 result = mActions->createLinearLayout( widget, orient_p, spacingValue, modify ); |
830 } |
838 } |
831 |
839 |
832 } else if( layout_type == lexemValue( LAYOUT_STACK ) ) { |
840 } else if( layout_type == lexemValue( LAYOUT_STACK ) ) { |
833 |
841 |
834 mCurrentLayoutType = LAYOUT_STACK; |
842 mCurrentLayoutType = LAYOUT_STACK; |
835 result = mActions->createStackedLayout( widget ); |
843 result = mActions->createStackedLayout( widget, modify ); |
836 |
844 |
837 } else if( layout_type == lexemValue( LAYOUT_NULL ) ) { |
845 } else if( layout_type == lexemValue( LAYOUT_NULL ) ) { |
838 |
846 |
839 mCurrentLayoutType = LAYOUT_NULL; |
847 mCurrentLayoutType = LAYOUT_NULL; |
840 result = mActions->createNullLayout( widget ); |
848 result = mActions->createNullLayout( widget ); |
880 qWarning() << "No property name defined, line " << mReader.lineNumber(); |
888 qWarning() << "No property name defined, line " << mReader.lineNumber(); |
881 result = false; |
889 result = false; |
882 } |
890 } |
883 if (result) { |
891 if (result) { |
884 mCurrentContainerNames << propertyName; |
892 mCurrentContainerNames << propertyName; |
|
893 qDeleteAll(mCurrentContainer); |
885 mCurrentContainer.clear(); |
894 mCurrentContainer.clear(); |
886 } |
895 } |
887 } else { |
896 } else { |
888 result = HbXmlLoaderBaseSyntax::processContainer(); |
897 result = HbXmlLoaderBaseSyntax::processContainer(); |
889 if( !result ) { |
898 if( !result ) { |
941 return false; |
950 return false; |
942 } |
951 } |
943 return true; |
952 return true; |
944 } |
953 } |
945 |
954 |
946 static bool convertSizePolicy_Policy( const QString& policyS, QSizePolicy::Policy *&policy ) |
|
947 { |
|
948 if ( policyS.isEmpty() ) { |
|
949 return false; |
|
950 } |
|
951 |
|
952 const QMetaObject *meta = &QSizePolicy::staticMetaObject; |
|
953 const int enumIndex = meta->indexOfEnumerator("Policy"); |
|
954 Q_ASSERT( enumIndex != -1 ); |
|
955 QMetaEnum metaEnum = meta->enumerator(enumIndex); |
|
956 const QByteArray byteArray = policyS.toUtf8(); |
|
957 const int policyI = metaEnum.keyToValue(byteArray.data()); |
|
958 |
|
959 if ( policyI == -1 ) { |
|
960 return false; |
|
961 } |
|
962 |
|
963 policy = (QSizePolicy::Policy *)new int(policyI); |
|
964 return true; |
|
965 } |
|
966 |
|
967 bool HbDocumentLoaderSyntax::processVariable() |
955 bool HbDocumentLoaderSyntax::processVariable() |
968 { |
956 { |
969 bool result = false; |
957 bool result = false; |
970 const QString type = mReader.name().toString(); |
958 const QString type = mReader.name().toString(); |
971 |
959 |
1005 const QString horizontalStretchS = attribute( ATTR_HORIZONTALSTRETCH ); |
993 const QString horizontalStretchS = attribute( ATTR_HORIZONTALSTRETCH ); |
1006 const QString verticalStretchS = attribute( ATTR_VERTICALSTRETCH ); |
994 const QString verticalStretchS = attribute( ATTR_VERTICALSTRETCH ); |
1007 |
995 |
1008 result = true; |
996 result = true; |
1009 |
997 |
1010 QSizePolicy::Policy *hPol = 0; |
998 QSizePolicy::Policy hPol; |
|
999 QSizePolicy::Policy *hPolP = 0; |
1011 if ( !horizontalPolicyS.isEmpty() ) { |
1000 if ( !horizontalPolicyS.isEmpty() ) { |
1012 result = convertSizePolicy_Policy( horizontalPolicyS, hPol ); |
1001 result = toSizePolicy( horizontalPolicyS, hPol ); |
1013 } |
1002 hPolP = &hPol; |
1014 |
1003 } |
1015 QSizePolicy::Policy *vPol = 0; |
1004 |
|
1005 QSizePolicy::Policy vPol; |
|
1006 QSizePolicy::Policy *vPolP = 0; |
1016 if ( result && !verticalPolicyS.isEmpty() ) { |
1007 if ( result && !verticalPolicyS.isEmpty() ) { |
1017 result = convertSizePolicy_Policy( verticalPolicyS, vPol ); |
1008 result = toSizePolicy( verticalPolicyS, vPol ); |
1018 } |
1009 vPolP = &vPol; |
1019 |
1010 } |
1020 int *hStretch = 0; |
1011 |
|
1012 int hStretch; |
|
1013 int *hStretchP = 0; |
1021 if ( result && !horizontalStretchS.isEmpty() ) { |
1014 if ( result && !horizontalStretchS.isEmpty() ) { |
1022 const int intValue = horizontalStretchS.toInt( &result ); |
1015 const int intValue = horizontalStretchS.toInt( &result ); |
1023 if ( result ) { |
1016 if ( result ) { |
1024 if ( intValue >= 0 && intValue < 256 ) { |
1017 if ( intValue >= 0 && intValue < 256 ) { |
1025 hStretch = new int( intValue ); |
1018 hStretch = intValue; |
|
1019 hStretchP = &hStretch; |
1026 } else { |
1020 } else { |
1027 result = false; |
1021 result = false; |
1028 } |
1022 } |
1029 } |
1023 } |
1030 } |
1024 } |
1031 |
1025 |
1032 int *vStretch = 0; |
1026 int vStretch; |
|
1027 int *vStretchP = 0; |
1033 if ( result && !verticalStretchS.isEmpty() ) { |
1028 if ( result && !verticalStretchS.isEmpty() ) { |
1034 const int intValue = verticalStretchS.toInt( &result ); |
1029 const int intValue = verticalStretchS.toInt( &result ); |
1035 if ( result ) { |
1030 if ( result ) { |
1036 if ( intValue >= 0 && intValue < 256 ) { |
1031 if ( intValue >= 0 && intValue < 256 ) { |
1037 vStretch = new int( intValue ); |
1032 vStretch = intValue; |
|
1033 vStretchP = &vStretch; |
1038 } else { |
1034 } else { |
1039 result = false; |
1035 result = false; |
1040 } |
1036 } |
1041 } |
1037 } |
1042 } |
1038 } |
1043 |
1039 |
1044 if ( result ) { |
1040 if ( result ) { |
1045 result = mActions->setSizePolicy( hPol, vPol, hStretch, vStretch ); |
1041 result = mActions->setSizePolicy( hPolP, vPolP, hStretchP, vStretchP ); |
1046 } |
1042 } |
1047 delete hPol; |
|
1048 delete vPol; |
|
1049 delete hStretch; |
|
1050 delete vStretch; |
|
1051 |
1043 |
1052 if (!result) { |
1044 if (!result) { |
1053 qWarning() << "Invalid size policy, line " << mReader.lineNumber(); |
1045 qWarning() << "Invalid size policy, line " << mReader.lineNumber(); |
1054 } |
1046 } |
1055 |
1047 |
1190 variable.mType = HbXmlVariable::ENUMS; |
1182 variable.mType = HbXmlVariable::ENUMS; |
1191 variable.mParameters.append(value); |
1183 variable.mParameters.append(value); |
1192 } else if ( type == lexemValue( TYPE_BOOL ) ) { |
1184 } else if ( type == lexemValue( TYPE_BOOL ) ) { |
1193 bool *boolVal = new bool(); |
1185 bool *boolVal = new bool(); |
1194 const QString value = attribute( ATTR_VALUE ); |
1186 const QString value = attribute( ATTR_VALUE ); |
1195 if (value == lexemValue( VALUE_BOOL_TRUE ) ) { |
1187 ok = toBool( value, *boolVal ); |
1196 *boolVal = true; |
|
1197 } else if (value == lexemValue( VALUE_BOOL_FALSE ) ) { |
|
1198 *boolVal = false; |
|
1199 } else { |
|
1200 ok = false; |
|
1201 } |
|
1202 if (ok) { |
1188 if (ok) { |
1203 variable.mType = HbXmlVariable::BOOL; |
1189 variable.mType = HbXmlVariable::BOOL; |
1204 variable.mParameters.append(boolVal); |
1190 variable.mParameters.append(boolVal); |
1205 } else { |
1191 } else { |
1206 delete boolVal; |
1192 delete boolVal; |
1394 + QString::number( VERSION_MINOR ) + QString( " (" ) |
1380 + QString::number( VERSION_MINOR ) + QString( " (" ) |
1395 + QString::number( MIN_SUPPORTED_VERSION_MAJOR ) + QString( "." ) |
1381 + QString::number( MIN_SUPPORTED_VERSION_MAJOR ) + QString( "." ) |
1396 + QString::number( MIN_SUPPORTED_VERSION_MINOR ) + QString( ")" ) ); |
1382 + QString::number( MIN_SUPPORTED_VERSION_MINOR ) + QString( ")" ) ); |
1397 } |
1383 } |
1398 |
1384 |
1399 bool HbDocumentLoaderSyntax::toFontSpecRole(const QString &roleString, HbFontSpec::Role &role) |
|
1400 { |
|
1401 bool success(false); |
|
1402 int enumInt = HbFontSpec::staticMetaObject.enumerator( |
|
1403 HbFontSpec::staticMetaObject.indexOfEnumerator("Role")).keyToValue(roleString.toLatin1()); |
|
1404 if (enumInt >= 0) { |
|
1405 success = true; |
|
1406 role = static_cast<HbFontSpec::Role>(enumInt); |
|
1407 } |
|
1408 return success; |
|
1409 } |
|