src/hbcore/image/hbiconanimationparser.cpp
changeset 5 627c4a0fd0e7
parent 2 06ff229162e9
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    85 #ifdef HB_ICON_TRACES
    85 #ifdef HB_ICON_TRACES
    86         qDebug() << "HbIconAnimationParser: File opening failed:" << realFileName;
    86         qDebug() << "HbIconAnimationParser: File opening failed:" << realFileName;
    87 #endif
    87 #endif
    88         return false;
    88         return false;
    89     }
    89     }
    90     
    90 
    91     setDevice(&file);
    91     setDevice(&file);
    92     bool ret = doParseFile(fileName, animations);
    92     bool ret = doParseFile(fileName, animations);
    93     file.close();
    93     file.close();
    94 
    94 
    95     return ret;
    95     return ret;
   105 
   105 
   106         if (isStartElement()) {
   106         if (isStartElement()) {
   107             if (name() == "animations") {
   107             if (name() == "animations") {
   108                 ret = readAnimations(fileName, animations);
   108                 ret = readAnimations(fileName, animations);
   109             }
   109             }
   110         }        
   110         }
   111     }
   111     }
   112 
   112 
   113 #ifdef HB_ICON_TRACES
   113 #ifdef HB_ICON_TRACES
   114     qDebug() << "Parsing of" << *fileName << "finished with success code" << ret;
   114     qDebug() << "Parsing of" << *fileName << "finished with success code" << ret;
   115 #endif
   115 #endif
   163  * Parses the icon data.
   163  * Parses the icon data.
   164  */
   164  */
   165 QString HbIconAnimationParser::readIconData(HbIconAnimationData &data)
   165 QString HbIconAnimationParser::readIconData(HbIconAnimationData &data)
   166 {
   166 {
   167     Q_ASSERT(isStartElement() && name() == "icon");
   167     Q_ASSERT(isStartElement() && name() == "icon");
   168     
   168 
   169     QString iconName;
   169     QString iconName;
   170     int defaultDuration = 0;
   170     int defaultDuration = 0;
   171     QStack< QPair<int, int> > repStk;
   171     QStack< QPair<int, int> > repStk;
   172 
   172 
   173     QXmlStreamAttributes attrs = attributes();
   173     QXmlStreamAttributes attrs = attributes();
   174 
   174 
   175     // Get old frame list from definition. It should be empty at this point.
   175     // Get old frame list from definition. It should be empty at this point.
   176     QList<HbIconAnimationDefinition::AnimationFrame> frames = data.def.frameList();
   176     QList<HbIconAnimationDefinition::AnimationFrame> frames = data.def.frameList();
   177 
   177 
   178     // Read icon attributes
   178     // Read icon attributes
   179     foreach (const QXmlStreamAttribute &attr, attrs) {
   179     foreach(const QXmlStreamAttribute & attr, attrs) {
   180         // "name" = ...
   180         // "name" = ...
   181         if (attr.name().toString() == "name") {
   181         if (attr.name().toString() == "name") {
   182             iconName = attr.value().toString();
   182             iconName = attr.value().toString();
   183         } else if (attr.name().toString() == "playmode") {
   183         } else if (attr.name().toString() == "playmode") {
   184             // Defaults to "playonce"
   184             // Defaults to "playonce"
   224                 HbIconAnimationDefinition::AnimationFrame frame;
   224                 HbIconAnimationDefinition::AnimationFrame frame;
   225                 frame.duration = defaultDuration;
   225                 frame.duration = defaultDuration;
   226 
   226 
   227                 QXmlStreamAttributes attrs = attributes();
   227                 QXmlStreamAttributes attrs = attributes();
   228                 // Read attributes
   228                 // Read attributes
   229                 foreach (const QXmlStreamAttribute &attr, attrs) {
   229                 foreach(const QXmlStreamAttribute & attr, attrs) {
   230                     // duration attribute
   230                     // duration attribute
   231                     if (attr.name().toString() == "duration") {
   231                     if (attr.name().toString() == "duration") {
   232                         frame.duration = attr.value().toString().toInt();
   232                         frame.duration = attr.value().toString().toInt();
   233                         if (frame.duration < 0) {
   233                         if (frame.duration < 0) {
   234                             frame.duration = 0;
   234                             frame.duration = 0;
   244                 //     <frame src=":/graphicsitemdemo/frame2.svg"/>
   244                 //     <frame src=":/graphicsitemdemo/frame2.svg"/>
   245                 //     ...
   245                 //     ...
   246                 // </loop>
   246                 // </loop>
   247                 int repeatCount = 0;
   247                 int repeatCount = 0;
   248                 QXmlStreamAttributes attrs = attributes();
   248                 QXmlStreamAttributes attrs = attributes();
   249                 foreach (const QXmlStreamAttribute &attr, attrs) {
   249                 foreach(const QXmlStreamAttribute & attr, attrs) {
   250                     if (attr.name().toString() == "count") {
   250                     if (attr.name().toString() == "count") {
   251                         repeatCount = attr.value().toString().toInt();
   251                         repeatCount = attr.value().toString().toInt();
   252                     }
   252                     }
   253                 }
   253                 }
   254                 // If count attribute is not given or is <= 0 then the loop element is ignored.
   254                 // If count attribute is not given or is <= 0 then the loop element is ignored.
   255                 if (repeatCount > 0) {
   255                 if (repeatCount > 0) {
   256                     // Target frame index for this loop's last frame will be the index of
   256                     // Target frame index for this loop's last frame will be the index of
   257                     // the frame that comes next.
   257                     // the frame that comes next.
   258                     repStk.push(QPair<int, int>(frames.count(), repeatCount)); 
   258                     repStk.push(QPair<int, int>(frames.count(), repeatCount));
   259                 }
   259                 }
   260 
   260 
   261             } else {
   261             } else {
   262                 readUnknownElement();
   262                 readUnknownElement();
   263             }
   263             }