src/hbcore/image/hbiconanimationmanager.cpp
changeset 5 627c4a0fd0e7
parent 2 06ff229162e9
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    31 #include "hbinstance.h"
    31 #include "hbinstance.h"
    32 #include "hbmainwindow.h"
    32 #include "hbmainwindow.h"
    33 #include "hbiconanimator.h"
    33 #include "hbiconanimator.h"
    34 #include "hbiconanimator_p.h"
    34 #include "hbiconanimator_p.h"
    35 #include "hbtheme.h"
    35 #include "hbtheme.h"
    36 #include "hbimagetraces_p.h"
       
    37 #include "hbiconanimation_p.h"
    36 #include "hbiconanimation_p.h"
    38 #include "hbimagetraces_p.h"
    37 #include "hbimagetraces_p.h"
    39 
    38 
    40 // Private class
    39 // Private class
    41 
    40 
    63 \internal
    62 \internal
    64 */
    63 */
    65 bool HbIconAnimationManagerPrivate::addDefinitionFile(const QString &definitionFileName)
    64 bool HbIconAnimationManagerPrivate::addDefinitionFile(const QString &definitionFileName)
    66 {
    65 {
    67     // Stop right away if the file has already been added.
    66     // Stop right away if the file has already been added.
    68     foreach (const QString &iconName, animations.keys()) {
    67     QList<QString> keys = animations.keys();
       
    68     foreach(const QString & iconName, keys) {
    69         if (animations.operator[](iconName).definitionFileName == definitionFileName) {
    69         if (animations.operator[](iconName).definitionFileName == definitionFileName) {
    70             return true;
    70             return true;
    71         }
    71         }
    72     }
    72     }
    73 
    73 
    74     // Check if there is a file with the given name in the current theme.
    74     // Check if there is a file with the given name in the current theme.
    75     QString pathInTheme = HbIconLoader::global()->findSharedResource(definitionFileName, Hb::AnimationResource);
    75     // Attach the .axml suffix if needed, just for the theme lookup.
       
    76     QString fileNameWithSuffix = definitionFileName;
       
    77     if (!fileNameWithSuffix.contains('.')) {
       
    78         fileNameWithSuffix.append(QLatin1String(".axml"));
       
    79     }
       
    80     QString pathInTheme = HbIconLoader::global()->findSharedResource(fileNameWithSuffix, Hb::AnimationResource);
    76 #ifdef HB_ICON_TRACES
    81 #ifdef HB_ICON_TRACES
    77     qDebug() << definitionFileName << " => " << pathInTheme;
    82     qDebug() << definitionFileName << " => " << pathInTheme;
    78 #endif
    83 #endif
    79 
    84 
    80     // In case of theme usage definitionFileName will just be a simple name and
    85     // In case of theme usage definitionFileName will just be a simple name and
    81     // realFileName will point to the name with the full path.
    86     // realFileName will point to the name with the full path.
    82     const QString *realFileName = pathInTheme.isEmpty() ? &definitionFileName : &pathInTheme;
    87     const QString *realFileName = pathInTheme.isEmpty() ? &definitionFileName : &pathInTheme;
    83 
    88 
    84     // Parse the filename and add entries in the hash table, first try the themeserver.
    89     // Parse the filename and add entries in the hash table, first try the themeserver.
    85     bool ret = parser.parseDefinitionFileShared(definitionFileName,
    90     bool ret = parser.parseDefinitionFileShared(definitionFileName,
    86                                                 animations, *realFileName);
    91                animations, *realFileName);
    87     if (!ret) {
    92     if (!ret) {
    88         // If themeserver did not return anything then try the file locally.
    93         // If themeserver did not return anything then try the file locally.
    89         ret = parser.parseDefinitionFile(definitionFileName,
    94         ret = parser.parseDefinitionFile(definitionFileName,
    90                                          animations, *realFileName);
    95                                          animations, *realFileName);
    91     }
    96     }
   151   \internal
   156   \internal
   152 */
   157 */
   153 void HbIconAnimationManagerPrivate::handleAnimationResume()
   158 void HbIconAnimationManagerPrivate::handleAnimationResume()
   154 {
   159 {
   155     // resume all paused animations
   160     // resume all paused animations
   156     foreach (HbIconAnimation *anim, playingAnims) {
   161     foreach(HbIconAnimation * anim, playingAnims) {
   157         if (anim->pausedDueToBackground()) {
   162         if (anim->pausedDueToBackground()) {
   158 
   163 
   159             #ifdef HB_ICON_TRACES
   164 #ifdef HB_ICON_TRACES
   160             qDebug() << "Foreground gained - resuming animation:" << anim->iconName();
   165             qDebug() << "Foreground gained - resuming animation:" << anim->iconName();
   161             #endif
   166 #endif
   162 
   167 
   163             anim->resume();
   168             anim->resume();
   164         }
   169         }
   165     }
   170     }
   166 }
   171 }
   169   \internal
   174   \internal
   170 */
   175 */
   171 void HbIconAnimationManagerPrivate::handleAnimationPause()
   176 void HbIconAnimationManagerPrivate::handleAnimationPause()
   172 {
   177 {
   173     // pause all playing animations
   178     // pause all playing animations
   174     foreach (HbIconAnimation *anim, playingAnims) {
   179     foreach(HbIconAnimation * anim, playingAnims) {
   175         if (!anim->paused()) {
   180         if (!anim->paused()) {
   176             
   181 
   177             #ifdef HB_ICON_TRACES
   182 #ifdef HB_ICON_TRACES
   178             qDebug() << "Foreground lost - pausing animation:" << anim->iconName();
   183             qDebug() << "Foreground lost - pausing animation:" << anim->iconName();
   179             #endif            
   184 #endif
   180             
   185 
   181             anim->pause();
   186             anim->pause();
   182             anim->setPausedDueToBackground(true);
   187             anim->setPausedDueToBackground(true);
   183         }
   188         }
   184     }
   189     }
   185 }
   190 }
   188   \internal
   193   \internal
   189 */
   194 */
   190 void HbIconAnimationManagerPrivate::handleThemeChanged()
   195 void HbIconAnimationManagerPrivate::handleThemeChanged()
   191 {
   196 {
   192     // The theme is being changed, stop all on-going animations.
   197     // The theme is being changed, stop all on-going animations.
   193     foreach (HbIconAnimation *anim, playingAnims) {
   198     foreach(HbIconAnimation * anim, playingAnims) {
   194         anim->stop();
   199         anim->stop();
   195     }
   200     }
   196 }
   201 }
   197 
   202 
   198 /*!
   203 /*!
   202 {
   207 {
   203     // Theme has changed, clear name list and animation data, and reload all
   208     // Theme has changed, clear name list and animation data, and reload all
   204     // animation definitions (or at least try to reload; some defs may now be
   209     // animation definitions (or at least try to reload; some defs may now be
   205     // missing if they were present in the previous theme but not in the new
   210     // missing if they were present in the previous theme but not in the new
   206     // one).
   211     // one).
   207     foreach (const QString &iconName, animations.keys()) {
   212     QList<QString> keys = animations.keys();
       
   213     foreach(const QString & iconName, keys) {
   208         // Do not remove animations that were not created from files.
   214         // Do not remove animations that were not created from files.
   209         if (!animations.operator[](iconName).definitionFileName.isEmpty()) {
   215         if (!animations.operator[](iconName).definitionFileName.isEmpty()) {
   210             animations.remove(iconName);
   216             animations.remove(iconName);
   211         }
   217         }
   212     }
   218     }
   218     //
   224     //
   219     // 2. Theme changes to a theme that does _not_ contain somethingFromTheme.
   225     // 2. Theme changes to a theme that does _not_ contain somethingFromTheme.
   220     //
   226     //
   221     // 3. Theme changes to another theme that _does_ contain somethingFromTheme.
   227     // 3. Theme changes to another theme that _does_ contain somethingFromTheme.
   222     //
   228     //
   223     foreach (const QString &name, allDefNames) {
   229     foreach(const QString & name, allDefNames) {
   224         addDefinitionFile(name);
   230         addDefinitionFile(name);
   225     }
   231     }
   226 }
   232 }
   227 
   233 
   228 void HbIconAnimationManagerPrivate::handleViewChanged(HbView *view)
   234 void HbIconAnimationManagerPrivate::handleViewChanged(HbView *view)
   229 {
   235 {
   230     // Pause all playing animations which do not belong to the new view, resume the ones belonging to it
   236     // Pause all playing animations which do not belong to the new view, resume the ones belonging to it
   231     foreach (HbIconAnimation *anim, playingAnims) {
   237     foreach(HbIconAnimation * anim, playingAnims) {
   232         // If the view of the animation is not resolved, do nothing
   238         // If the view of the animation is not resolved, do nothing
   233         if (anim->view()) {
   239         if (anim->view()) {
   234             if (anim->view() == view) {
   240             if (anim->view() == view) {
   235                 #ifdef HB_ICON_TRACES
   241 #ifdef HB_ICON_TRACES
   236                 qDebug() << "View activated - resuming animation:" << anim->iconName();
   242                 qDebug() << "View activated - resuming animation:" << anim->iconName();
   237                 #endif
   243 #endif
   238                 anim->resume();
   244                 anim->resume();
   239             } else {
   245             } else {
   240                 #ifdef HB_ICON_TRACES
   246 #ifdef HB_ICON_TRACES
   241                 qDebug() << "View deactivated - pausing animation:" << anim->iconName();
   247                 qDebug() << "View deactivated - pausing animation:" << anim->iconName();
   242                 #endif
   248 #endif
   243                 anim->pause();
   249                 anim->pause();
   244             }
   250             }
   245         }
   251         }
   246     }
   252     }
   247 }
   253 }
   259     }
   265     }
   260 
   266 
   261     // Connect to view change signals if not done yet
   267     // Connect to view change signals if not done yet
   262     if (!viewChangeConnected) {
   268     if (!viewChangeConnected) {
   263         QList<HbMainWindow *> windowList = hbInstance->allMainWindows();
   269         QList<HbMainWindow *> windowList = hbInstance->allMainWindows();
   264         Q_FOREACH(const HbMainWindow *window, windowList) {
   270         Q_FOREACH(const HbMainWindow * window, windowList) {
   265             connect(window, SIGNAL(currentViewChanged(HbView*)), SLOT(handleViewChanged(HbView*)));
   271             connect(window, SIGNAL(currentViewChanged(HbView *)), SLOT(handleViewChanged(HbView *)));
   266         }
   272         }
   267         viewChangeConnected = true;
   273         viewChangeConnected = true;
   268     }
   274     }
   269 
   275 
   270     // Resolve the view where the animation is shown if it is not resolved yet,
   276     // Resolve the view where the animation is shown if it is not resolved yet,
   280             if (item) {
   286             if (item) {
   281                 QGraphicsScene *scene = item->scene();
   287                 QGraphicsScene *scene = item->scene();
   282                 if (scene) {
   288                 if (scene) {
   283                     // Resolve the main window having the same scene that the item belongs to
   289                     // Resolve the main window having the same scene that the item belongs to
   284                     QList<HbMainWindow *> windowList = hbInstance->allMainWindows();
   290                     QList<HbMainWindow *> windowList = hbInstance->allMainWindows();
   285                     Q_FOREACH(const HbMainWindow *window, windowList) {
   291                     Q_FOREACH(const HbMainWindow * window, windowList) {
   286                         if (window->scene() == scene) {
   292                         if (window->scene() == scene) {
   287                             anim->setView(window->currentView());
   293                             anim->setView(window->currentView());
   288                             break;
   294                             break;
   289                         }
   295                         }
   290                     }
   296                     }
   388 * <frame duration="1000">anim2_frame4</frame>
   394 * <frame duration="1000">anim2_frame4</frame>
   389 * </icon>
   395 * </icon>
   390 * </animations>
   396 * </animations>
   391 *
   397 *
   392 * \endcode
   398 * \endcode
   393 * 
   399 *
   394 * The frame names e.g. "anim1_frame1" in the example above correspond to the icon name
   400 * The frame names e.g. "anim1_frame1" in the example above correspond to the icon name
   395 * parameters passed in HbIcon constructor when the animation frame icons are loaded.
   401 * parameters passed in HbIcon constructor when the animation frame icons are loaded.
   396 *
   402 *
   397 * Any existing definitions for the same icons are overridden.
   403 * Any existing definitions for the same icons are overridden.
   398 *
   404 *