src/hbcore/image/hbiconanimation.cpp
changeset 28 b7da29130b0e
parent 21 4633027730f5
equal deleted inserted replaced
23:e6ad4ef83b23 28:b7da29130b0e
   333 
   333 
   334     HbIconAnimation(animator, iconName),
   334     HbIconAnimation(animator, iconName),
   335     mImageRenderer(renderer),
   335     mImageRenderer(renderer),
   336     mIconFileName(iconFileName),
   336     mIconFileName(iconFileName),
   337     mType(type),
   337     mType(type),
   338     mTimerEntry(0)
   338     mTimerEntry(0),
       
   339     mDoNotResetLoopCount(false)
   339 {
   340 {
   340     // This class supports these types
   341     // This class supports these types
   341     Q_ASSERT(mType == MNG || mType == GIF);
   342     Q_ASSERT(mType == MNG || mType == GIF);
   342 
   343 
   343     // Read the first frame. QImageReader::read() must be called before
   344     // Read the first frame. QImageReader::read() must be called before
   398         // Recreate the image reader. It's slow but QImageReader::jumpToImage does not work.
   399         // Recreate the image reader. It's slow but QImageReader::jumpToImage does not work.
   399         delete mImageRenderer;
   400         delete mImageRenderer;
   400         mImageRenderer = 0;
   401         mImageRenderer = 0;
   401         mImageRenderer = new QImageReader(mIconFileName, mType == MNG ? "MNG" : "GIF");
   402         mImageRenderer = new QImageReader(mIconFileName, mType == MNG ? "MNG" : "GIF");
   402 
   403 
   403         // Reset the loop count.
   404         if (mDoNotResetLoopCount) {
   404         if (mCustomLoopCountSet) {
   405             mDoNotResetLoopCount = false;
   405             mLoopCount = mCustomLoopCount;
       
   406         } else {
   406         } else {
   407             mLoopCount = mImageRenderer->loopCount();
   407             // Reset the loop count.
       
   408             if (mCustomLoopCountSet) {
       
   409                 mLoopCount = mCustomLoopCount;
       
   410             } else {
       
   411                 mLoopCount = mImageRenderer->loopCount();
       
   412             }
   408         }
   413         }
   409 
   414 
   410         // New image reader starts from the first frame. Handle animation update.
   415         // New image reader starts from the first frame. Handle animation update.
   411         notifyAnimationStarted();
   416         notifyAnimationStarted();
   412         handleAnimationUpdated();
   417         handleAnimationUpdated();
   431         // QImageReader::jumpToImage does not work so cannot jump to the last frame if it has not been read yet.
   436         // QImageReader::jumpToImage does not work so cannot jump to the last frame if it has not been read yet.
   432         while (true) {
   437         while (true) {
   433             QImage img = mImageRenderer->read();
   438             QImage img = mImageRenderer->read();
   434             // Reached last frame?
   439             // Reached last frame?
   435             if (!mImageRenderer->canRead()) {
   440             if (!mImageRenderer->canRead()) {
       
   441                 // Must get rid of the old pixmap first, in case of very large frames
       
   442                 // keeping both the old and new frame in memory would not succeed.
       
   443                 mCurrentFrame = QPixmap(); // This call is not superfluous.
   436                 mCurrentFrame = QPixmap::fromImage(img);
   444                 mCurrentFrame = QPixmap::fromImage(img);
   437                 mLastFrame = mCurrentFrame;
   445                 mLastFrame = mCurrentFrame;
   438                 break;
   446                 break;
   439             }
   447             }
   440         }
   448         }
   526         mTimerEntry = HbTimer::instance()->addTimeout(mTimerInterval, this, SLOT(handleAnimationUpdated()));
   534         mTimerEntry = HbTimer::instance()->addTimeout(mTimerInterval, this, SLOT(handleAnimationUpdated()));
   527     }
   535     }
   528 
   536 
   529     // Store the new frame in the current frame pixmap
   537     // Store the new frame in the current frame pixmap
   530     if (!img.isNull()) {
   538     if (!img.isNull()) {
       
   539         // Must get rid of the old pixmap first, in case of very large frames
       
   540         // keeping both the old and new frame in memory would not succeed.
       
   541         // (with the OpenVG paint engine QPixmap will create a new QImage if
       
   542         // the pixel format is different and it will be different here...)
       
   543         mCurrentFrame = QPixmap(); // This call is not superfluous.
   531         mCurrentFrame = QPixmap::fromImage(img);
   544         mCurrentFrame = QPixmap::fromImage(img);
   532     }
   545     }
   533     // Reached the last frame. Store it so it can be used by stop().
   546     // Reached the last frame. Store it so it can be used by stop().
   534     else {
   547     else {
   535         mLastFrame = mCurrentFrame;
   548         mLastFrame = mCurrentFrame;
   549         } else {
   562         } else {
   550             finished = false;
   563             finished = false;
   551             if (mLoopCount > 0) {
   564             if (mLoopCount > 0) {
   552                 --mLoopCount;
   565                 --mLoopCount;
   553             }
   566             }
       
   567             mDoNotResetLoopCount = true;
   554             start();
   568             start();
   555         }
   569         }
   556     }
   570     }
   557 }
   571 }
   558 
   572