src/hbcore/effects/hbeffectxmlparser.cpp
changeset 5 627c4a0fd0e7
parent 0 16d8024aca5e
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    44 
    44 
    45 /*
    45 /*
    46   Constructor.
    46   Constructor.
    47 */
    47 */
    48 HbEffectXmlParser::HbEffectXmlParser()
    48 HbEffectXmlParser::HbEffectXmlParser()
    49     :mFxmlData(0)
    49     : mFxmlData(0)
    50 {
    50 {
    51 }
    51 }
    52 
    52 
    53 /*
    53 /*
    54   Destructor.
    54   Destructor.
    72                 readVisuals();
    72                 readVisuals();
    73             } else {
    73             } else {
    74                 qWarning("HbEffectXmlParser: Document element is invalid (not <layers>");
    74                 qWarning("HbEffectXmlParser: Document element is invalid (not <layers>");
    75                 raiseError("HbEffectXmlParser::read The document is not an valid effect definitions document.");
    75                 raiseError("HbEffectXmlParser::read The document is not an valid effect definitions document.");
    76             }
    76             }
    77         }        
    77         }
    78     }
    78     }
    79 
    79 
    80     if (error()) {
    80     if (error()) {
    81         qWarning("HbEffectXmlParser: failed with %d (%s)", error(), qPrintable(errorString()));
    81         qWarning("HbEffectXmlParser: failed with %d (%s)", error(), qPrintable(errorString()));
    82     }
    82     }
   139 
   139 
   140     while (!atEnd()) {
   140     while (!atEnd()) {
   141         readNext();
   141         readNext();
   142 
   142 
   143         if (isEndElement()) {
   143         if (isEndElement()) {
   144             if (name() == FXML_LAYERS)
   144             if (name() == FXML_LAYERS) {
   145                 break;
   145                 break;
       
   146             }
   146         }
   147         }
   147 
   148 
   148         if (isStartElement()) {
   149         if (isStartElement()) {
   149             if (name() == FXML_VISUAL) {
   150             if (name() == FXML_VISUAL) {
   150                 readVisualData();
   151                 readVisualData();
   151             }
   152             }
   152 
   153 
   153             else if (name() == FXML_LAYERGROUP) {
   154             else if (name() == FXML_LAYERGROUP) {
   154                 // Not needed
   155                 // Not needed
   155             }
   156             } else if (name() == FXML_BLENDING) {
   156             else if (name() == FXML_BLENDING) {
       
   157                 readBlendingElement();
   157                 readBlendingElement();
   158             }
   158             } else if (name() == FXML_COMMENT) {
   159             else if (name() == FXML_COMMENT) {
       
   160                 // Comments are skipped
   159                 // Comments are skipped
   161             }
   160             } else if (name() == FXML_FILTER) {
   162             else if (name() == FXML_FILTER) {
       
   163 #ifdef HB_FILTER_EFFECTS
   161 #ifdef HB_FILTER_EFFECTS
   164                 readFilterData();
   162                 readFilterData();
   165 #endif
   163 #endif
   166             }
   164             }
   167 
   165 
   184         }
   182         }
   185 
   183 
   186         if (isStartElement()) {
   184         if (isStartElement()) {
   187             if (name() == FXML_PARAM) {
   185             if (name() == FXML_PARAM) {
   188                 mFxmlData->appendParamData(readParamData());
   186                 mFxmlData->appendParamData(readParamData());
   189             }
   187             } else if (name() == FXML_FILTER) {
   190             else if (name() == FXML_FILTER) {
       
   191 #ifdef HB_FILTER_EFFECTS
   188 #ifdef HB_FILTER_EFFECTS
   192                 readFilterData();
   189                 readFilterData();
   193 #endif
   190 #endif
   194             }
   191             } else {
   195             else {
       
   196                 readUnknownElement();
   192                 readUnknownElement();
   197             }
   193             }
   198         }
   194         }
   199     }
   195     }
   200 }
   196 }
   209     HbEffectFxmlFilterData filterData(mFxmlData->memoryType());
   205     HbEffectFxmlFilterData filterData(mFxmlData->memoryType());
   210 
   206 
   211     // Parse filter type
   207     // Parse filter type
   212     QXmlStreamAttributes attrs = attributes();
   208     QXmlStreamAttributes attrs = attributes();
   213 
   209 
   214     foreach (const QXmlStreamAttribute &attr, attrs) {
   210     foreach(const QXmlStreamAttribute & attr, attrs) {
   215         // "type" = ...
   211         // "type" = ...
   216         if (attr.name().toString() == FXML_PARAM_TYPE) {
   212         if (attr.name().toString() == FXML_PARAM_TYPE) {
   217             filterData.setType(attr.value().toString());
   213             filterData.setType(attr.value().toString());
   218             break;
   214             break;
   219         }
   215         }
   245 #endif
   241 #endif
   246 }
   242 }
   247 
   243 
   248 // This parses information inside one <param> field.
   244 // This parses information inside one <param> field.
   249 // E.g. "scale_x", "scale_y", "scale_origin_x"
   245 // E.g. "scale_x", "scale_y", "scale_origin_x"
   250 // 
   246 //
   251 HbEffectFxmlParamData HbEffectXmlParser::readParamData()
   247 HbEffectFxmlParamData HbEffectXmlParser::readParamData()
   252 {
   248 {
   253     Q_ASSERT(isStartElement() && name() == FXML_PARAM);
   249     Q_ASSERT(isStartElement() && name() == FXML_PARAM);
   254     
   250 
   255     HbEffectFxmlParamData param(mFxmlData->memoryType());
   251     HbEffectFxmlParamData param(mFxmlData->memoryType());
   256     HbKeyFrame kf(mFxmlData->memoryType());
   252     HbKeyFrame kf(mFxmlData->memoryType());
   257 
   253 
   258     QXmlStreamAttributes attrs = attributes();
   254     QXmlStreamAttributes attrs = attributes();
   259 
   255 
   260     // Populate the PARAM attributes
   256     // Populate the PARAM attributes
   261     foreach (const QXmlStreamAttribute &attr, attrs) {
   257     foreach(const QXmlStreamAttribute & attr, attrs) {
   262         // "name" = ...
   258         // "name" = ...
   263         if (attr.name().toString() == FXML_PARAM_NAME) {
   259         if (attr.name().toString() == FXML_PARAM_NAME) {
   264             param.setName(attr.value().toString());
   260             param.setName(attr.value().toString());
   265         }
   261         }
   266         // "type" = ...
   262         // "type" = ...
   291                 param.setAttribute(FXML_STYLE, readElementText());
   287                 param.setAttribute(FXML_STYLE, readElementText());
   292             }
   288             }
   293             // <marker> tag
   289             // <marker> tag
   294             else if (name() == FXML_MARKER) {
   290             else if (name() == FXML_MARKER) {
   295                 QXmlStreamAttributes attrs = attributes();
   291                 QXmlStreamAttributes attrs = attributes();
   296                 
   292 
   297                 enum {
   293                 enum {
   298                     Undefined = 0,
   294                     Undefined = 0,
   299                     Start,
   295                     Start,
   300                     End
   296                     End
   301                 } loopType = Undefined;
   297                 } loopType = Undefined;
   302 
   298 
   303                 // Fetch "type" attribute from <marker> tag
   299                 // Fetch "type" attribute from <marker> tag
   304                 foreach (const QXmlStreamAttribute &attr, attrs) {
   300                 foreach(const QXmlStreamAttribute & attr, attrs) {
   305                     if (attr.name().toString() == FXML_PARAM_TYPE) {
   301                     if (attr.name().toString() == FXML_PARAM_TYPE) {
   306                         QString s = attr.value().toString();
   302                         QString s = attr.value().toString();
   307                         if (s == FXML_LOOP_START) {
   303                         if (s == FXML_LOOP_START) {
   308                             loopType = Start;
   304                             loopType = Start;
   309                         } else if (s == FXML_LOOP_END) {
   305                         } else if (s == FXML_LOOP_END) {
   313                     }
   309                     }
   314                 }
   310                 }
   315 
   311 
   316                 if (loopType != Undefined) {
   312                 if (loopType != Undefined) {
   317                     // Fetch "at" attribute from <marker> tag
   313                     // Fetch "at" attribute from <marker> tag
   318                     foreach (const QXmlStreamAttribute &attr, attrs) {
   314                     foreach(const QXmlStreamAttribute & attr, attrs) {
   319                         if (attr.name().toString() == FXML_PARAM_AT) {
   315                         if (attr.name().toString() == FXML_PARAM_AT) {
   320                             QString s = attr.value().toString();
   316                             QString s = attr.value().toString();
   321                             bool ok = false;
   317                             bool ok = false;
   322                             float f = s.toFloat(&ok);
   318                             float f = s.toFloat(&ok);
   323                             if (ok) {
   319                             if (ok) {
   341             }
   337             }
   342 
   338 
   343             // <keyframe> tag
   339             // <keyframe> tag
   344             else if (name() == FXML_KEYFRAME) {
   340             else if (name() == FXML_KEYFRAME) {
   345                 QXmlStreamAttributes attrs = attributes();
   341                 QXmlStreamAttributes attrs = attributes();
   346                 
   342 
   347                 bool ok = false;
   343                 bool ok = false;
   348 
   344 
   349                 // Fetch "at" attribute from <keyframe> tag
   345                 // Fetch "at" attribute from <keyframe> tag
   350                 foreach (const QXmlStreamAttribute &attr, attrs) {
   346                 foreach(const QXmlStreamAttribute & attr, attrs) {
   351                     if (attr.name().toString() == FXML_PARAM_AT) {
   347                     if (attr.name().toString() == FXML_PARAM_AT) {
   352                         QString s = attr.value().toString();
   348                         QString s = attr.value().toString();
   353                         kf.pos = s.toFloat(&ok);
   349                         kf.pos = s.toFloat(&ok);
   354                         break;
   350                         break;
   355                     }
   351                     }
   371                 if (ok && kf.pos >= 0.0 && kf.pos <= 1.0) {
   367                 if (ok && kf.pos >= 0.0 && kf.pos <= 1.0) {
   372                     param.append(kf);
   368                     param.append(kf);
   373                 }
   369                 }
   374             }
   370             }
   375             //<start> element
   371             //<start> element
   376             else if(name() == FXML_KEYWORD_START) {
   372             else if (name() == FXML_KEYWORD_START) {
   377 
   373 
   378                 QXmlStreamAttributes attrs = attributes();
   374                 QXmlStreamAttributes attrs = attributes();
   379                 foreach (const QXmlStreamAttribute &attr, attrs) {
   375                 foreach(const QXmlStreamAttribute & attr, attrs) {
   380                     if( attr.name() == FXML_PARAM_REF ) {
   376                     if (attr.name() == FXML_PARAM_REF) {
   381                         param.setStartRef(attr.value().toString());
   377                         param.setStartRef(attr.value().toString());
   382                     }
   378                     }
   383                 }
   379                 }
   384                 param.setAttribute(FXML_KEYWORD_START, readElementText());
   380                 param.setAttribute(FXML_KEYWORD_START, readElementText());
   385             }
   381             }
   386             //<end> element
   382             //<end> element
   387             else if(name() == FXML_KEYWORD_END) {                
   383             else if (name() == FXML_KEYWORD_END) {
   388                 QXmlStreamAttributes attrs = attributes();
   384                 QXmlStreamAttributes attrs = attributes();
   389                 foreach (const QXmlStreamAttribute &attr, attrs) {
   385                 foreach(const QXmlStreamAttribute & attr, attrs) {
   390                     if( attr.name() == FXML_PARAM_REF ) {
   386                     if (attr.name() == FXML_PARAM_REF) {
   391                         param.setEndRef(attr.value().toString());
   387                         param.setEndRef(attr.value().toString());
   392                     }
   388                     }
   393                 }
   389                 }
   394                 param.setAttribute(FXML_KEYWORD_END, readElementText());
   390                 param.setAttribute(FXML_KEYWORD_END, readElementText());
   395             }
   391             } else {
   396             else {
       
   397                 readUnknownElement();
   392                 readUnknownElement();
   398             }
   393             }
   399         }
   394         }
   400         // Value of the param
   395         // Value of the param
   401         else if (isCharacters()) {
   396         else if (isCharacters()) {