src/hbcore/image/hbiconengine.cpp
changeset 5 627c4a0fd0e7
parent 3 11d3954df52a
child 7 923ff622b8b9
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    32 #include "hblayoutdirectionnotifier_p.h"
    32 #include "hblayoutdirectionnotifier_p.h"
    33 #include "hbiconanimation_p.h"
    33 #include "hbiconanimation_p.h"
    34 #include "hbimagetraces_p.h"
    34 #include "hbimagetraces_p.h"
    35 #include "hbiconimpl_p.h"
    35 #include "hbiconimpl_p.h"
    36 #include "hbpixmapiconimpl_p.h"
    36 #include "hbpixmapiconimpl_p.h"
       
    37 #include "hbbadgeicon_p.h"
       
    38 
    37 #include <hbinstance.h>
    39 #include <hbinstance.h>
    38 #include <hbiconanimator.h>
    40 #include <hbiconanimator.h>
    39 #include <hbiconanimator_p.h>
    41 #include <hbiconanimator_p.h>
    40 #include "hbbadgeicon_p.h"
    42 
    41 
    43 
    42 #include <QObject>
    44 #include <QObject>
    43 #include <QPainter>
    45 #include <QPainter>
    44 #include <QDebug>
    46 #include <QDebug>
    45 
    47 
    65     void appendLoadFail(QIcon::Mode mode, QIcon::State state);
    67     void appendLoadFail(QIcon::Mode mode, QIcon::State state);
    66     void removeLoadFail(QIcon::Mode mode, QIcon::State state);
    68     void removeLoadFail(QIcon::Mode mode, QIcon::State state);
    67     void unLoadIcon(bool unloadedByServer = false);
    69     void unLoadIcon(bool unloadedByServer = false);
    68 
    70 
    69     void addBadge(Qt::Alignment alignment,
    71     void addBadge(Qt::Alignment alignment,
    70                       const HbIcon& badge,
    72                   const HbIcon &badge,
    71                       int z=0);
    73                   int z = 0);
    72     bool removeBadge(const HbIcon& badge);
    74     bool removeBadge(const HbIcon &badge);
    73     void removeAllBadges();
    75     void removeAllBadges();
    74     const QList<HbBadgeIconInfo> badges() const;
    76     const QList<HbBadgeIconInfo> badges() const;
    75     bool isBadged() const;
    77     bool isBadged() const;
    76 
    78 
    77     QColor colorToUse(const QString &iconName) const;
    79     QColor colorToUse(const QString &iconName) const;
    78 
    80 
    79 public:
    81 public:
    80     QSizeF size;
    82     QSizeF size;
    81 
    83 
    82     struct IconName
    84     struct IconName {
    83     {
       
    84         QIcon::Mode mode;
    85         QIcon::Mode mode;
    85         QIcon::State state;
    86         QIcon::State state;
    86         QString name;
    87         QString name;
    87     };
    88     };
    88 
    89 
   105     QVector<int> loadFailed;
   106     QVector<int> loadFailed;
   106 
   107 
   107     HbIcon::Flags flags;
   108     HbIcon::Flags flags;
   108     HbIcon::MirroringMode mirroringMode;
   109     HbIcon::MirroringMode mirroringMode;
   109 
   110 
   110     enum DefaultMirroring
   111     enum DefaultMirroring {
   111     {
       
   112         Unknown = 0,
   112         Unknown = 0,
   113         Enabled = 1,
   113         Enabled = 1,
   114         Disabled = 2
   114         Disabled = 2
   115     };
   115     };
   116     DefaultMirroring defaultMirroring;
   116     DefaultMirroring defaultMirroring;
   160 }
   160 }
   161 
   161 
   162 HbIconEnginePrivate::HbIconEnginePrivate(const HbIconEnginePrivate &other) :
   162 HbIconEnginePrivate::HbIconEnginePrivate(const HbIconEnginePrivate &other) :
   163     size(other.size),
   163     size(other.size),
   164     iconNames(other.iconNames),
   164     iconNames(other.iconNames),
   165     // Pixmap is cleared if other object uses animation
   165     pixmap(other.animator ? QPixmap() : other.pixmap), // Pixmap is cleared if other object uses animation.
   166     pixmap(other.animator ? QPixmap() : other.pixmap),
       
   167     aspectRatioMode(other.aspectRatioMode),
   166     aspectRatioMode(other.aspectRatioMode),
   168     mode(other.mode),
   167     mode(other.mode),
   169     state(other.state),
   168     state(other.state),
   170     defaultSize(other.defaultSize),
   169     defaultSize(other.defaultSize),
   171     defaultSizeFailed(other.defaultSizeFailed),
   170     defaultSizeFailed(other.defaultSizeFailed),
   172     loadFailed(other.loadFailed),
   171     loadFailed(other.loadFailed),
   173     flags(other.flags),
   172     flags(other.flags),
   174     mirroringMode(other.mirroringMode),
   173     mirroringMode(other.mirroringMode),
   175     defaultMirroring(other.defaultMirroring),
   174     defaultMirroring(other.defaultMirroring),
   176     // Animator is instance specific and not copied
   175     animator(0), // Animator is instance specific and not copied.
   177     animator(0),
   176     color(other.color), // No copy for themedColor, that one is an internal, instance-specific setting.
   178     color(other.color),
   177     icon(0),  // HbIconImpl is instance specific, it is recreated when icon is painted.
   179     // HbIconImpl is instance specific, it is recreated when icon is painted
       
   180     icon(0),
       
   181     badgeInfo(0),
   178     badgeInfo(0),
   182     signalConnectionsSet(false),
   179     signalConnectionsSet(false),
   183     iconType(INVALID_FORMAT)
   180     iconType(INVALID_FORMAT)
   184 {
   181 {
   185     if (other.badgeInfo) {
   182     if (other.badgeInfo) {
   225     stream >> temp;
   222     stream >> temp;
   226     mirroringMode = (HbIcon::MirroringMode)temp;
   223     mirroringMode = (HbIcon::MirroringMode)temp;
   227     stream >> temp;
   224     stream >> temp;
   228     defaultMirroring = (HbIconEnginePrivate::DefaultMirroring)temp;
   225     defaultMirroring = (HbIconEnginePrivate::DefaultMirroring)temp;
   229     stream >> color;
   226     stream >> color;
       
   227     // Do not store themedColor, see the copy ctor.
   230 
   228 
   231     badgeInfo->internalize(stream);
   229     badgeInfo->internalize(stream);
   232 }
   230 }
   233 
   231 
   234 void HbIconEnginePrivate::externalize(QDataStream &stream)
   232 void HbIconEnginePrivate::externalize(QDataStream &stream)
   235 {
   233 {
   236     // Externalize parameters that are needed to reconstruct the icon
   234     // Externalize parameters that are needed to reconstruct the icon
   237     stream << size;
   235     stream << size;
   238     stream << iconNames.count();
   236     stream << iconNames.count();
   239     Q_FOREACH(const IconName &name, iconNames) {
   237     Q_FOREACH(const IconName & name, iconNames) {
   240         stream << (qint32)(name.mode);
   238         stream << (qint32)(name.mode);
   241         stream << (qint32)(name.state);
   239         stream << (qint32)(name.state);
   242         stream << name.name;
   240         stream << name.name;
   243     }
   241     }
   244     stream << (qint32)flags;
   242     stream << (qint32)flags;
   275     delete badgeInfo;
   273     delete badgeInfo;
   276 }
   274 }
   277 /*!
   275 /*!
   278   \internal
   276   \internal
   279 
   277 
   280   Initiates an IPC call to the ThemeServer to unload ( decrement ref count ) 
   278   Initiates an IPC call to the ThemeServer to unload ( decrement ref count )
   281   the icon if created on server side.
   279   the icon if created on server side.
   282  
   280 
   283  */
   281  */
   284 void HbIconEnginePrivate::unLoadIcon(bool unloadedByServer)
   282 void HbIconEnginePrivate::unLoadIcon(bool unloadedByServer)
   285 {
   283 {
   286     if (icon) {
   284     if (icon) {
   287         HbIconLoader *loader = HbIconLoader::global();
   285         HbIconLoader *loader = HbIconLoader::global();
   318 {
   316 {
   319     // If mirroring mode is default, check automatic mirroring from loader.
   317     // If mirroring mode is default, check automatic mirroring from loader.
   320     if (mirroringMode == HbIcon::Default && defaultMirroring == Unknown) {
   318     if (mirroringMode == HbIcon::Default && defaultMirroring == Unknown) {
   321         HbIconLoader *loader = HbIconLoader::global();
   319         HbIconLoader *loader = HbIconLoader::global();
   322         defaultMirroring = loader->isAutomaticallyMirrored(
   320         defaultMirroring = loader->isAutomaticallyMirrored(
   323             iconName(QIcon::Normal, QIcon::Off)) ? Enabled : Disabled;
   321                                iconName(QIcon::Normal, QIcon::Off)) ? Enabled : Disabled;
   324     }
   322     }
   325 
   323 
   326     bool basedOnLayoutDir = false;
   324     bool basedOnLayoutDir = false;
   327     // Handle the different mirroring modes
   325     // Handle the different mirroring modes
   328 
   326 
   331         if (defaultMirroring == Enabled) {
   329         if (defaultMirroring == Enabled) {
   332             basedOnLayoutDir = true;
   330             basedOnLayoutDir = true;
   333         } else if (defaultMirroring == Disabled) {
   331         } else if (defaultMirroring == Disabled) {
   334             return false;
   332             return false;
   335         }
   333         }
   336     // Forced
   334         // Forced
   337     } else if (mirroringMode == HbIcon::Forced) {
   335     } else if (mirroringMode == HbIcon::Forced) {
   338         return true;
   336         return true;
   339     // Prevented
   337         // Prevented
   340     } else if (mirroringMode == HbIcon::Prevented) {
   338     } else if (mirroringMode == HbIcon::Prevented) {
   341         return false;
   339         return false;
   342     // LayoutDirection
   340         // LayoutDirection
   343     } else if (mirroringMode == HbIcon::LayoutDirection) {
   341     } else if (mirroringMode == HbIcon::LayoutDirection) {
   344         basedOnLayoutDir = true;
   342         basedOnLayoutDir = true;
   345     }
   343     }
   346 
   344 
   347     if (basedOnLayoutDir) {
   345     if (basedOnLayoutDir) {
   348         // e.g. some unit tests do not have primary window at this point so need to do NULL checks here.
   346         // e.g. some unit tests do not have primary window at this point so need to do NULL checks here.
   349         if (hbInstance) {
   347         if (hbInstance) {
   350             QList<HbMainWindow*> allWindows = hbInstance->allMainWindows();
   348             QList<HbMainWindow *> allWindows = hbInstance->allMainWindows();
   351             
   349 
   352             if ( !allWindows.isEmpty() &&
   350             if (!allWindows.isEmpty() &&
   353                  allWindows.value(0) &&
   351                     allWindows.value(0) &&
   354                  allWindows.value(0)->layoutDirection() == Qt::RightToLeft) {
   352                     allWindows.value(0)->layoutDirection() == Qt::RightToLeft) {
   355                 return true;
   353                 return true;
   356             }
   354             }
   357             return false;
   355             return false;
   358         }
   356         }
   359     }
   357     }
   386 
   384 
   387 QString HbIconEnginePrivate::iconName(QIcon::Mode mode, QIcon::State state) const
   385 QString HbIconEnginePrivate::iconName(QIcon::Mode mode, QIcon::State state) const
   388 {
   386 {
   389     QString ret;
   387     QString ret;
   390 
   388 
   391     Q_FOREACH(const HbIconEnginePrivate::IconName &name, iconNames) {
   389     Q_FOREACH(const HbIconEnginePrivate::IconName & name, iconNames) {
   392         if (name.mode == mode && name.state == state) {
   390         if (name.mode == mode && name.state == state) {
   393             ret = name.name;
   391             ret = name.name;
   394             break;
   392             break;
   395         }
   393         }
   396     }
   394     }
   425 inline bool isMonoIcon(const QString &name)
   423 inline bool isMonoIcon(const QString &name)
   426 {
   424 {
   427     // Even when the Colorized flag is not set certain icons from the theme must be
   425     // Even when the Colorized flag is not set certain icons from the theme must be
   428     // colorized. These mono icons are recognized from their name. The check should not be
   426     // colorized. These mono icons are recognized from their name. The check should not be
   429     // done for normal files, only for logical theme graphics names.
   427     // done for normal files, only for logical theme graphics names.
   430     return name.startsWith("qtg_mono_") && !name.contains('.');
   428     return name.startsWith(QLatin1String("qtg_mono_")) && !name.contains('.');
   431 }
   429 }
   432 
   430 
   433 QColor HbIconEnginePrivate::colorToUse(const QString &iconName) const
   431 QColor HbIconEnginePrivate::colorToUse(const QString &iconName) const
   434 {
   432 {
   435     if (flags.testFlag(HbIcon::Colorized) || isMonoIcon(iconName)) {
   433     if (flags.testFlag(HbIcon::Colorized) || isMonoIcon(iconName)) {
   438         return QColor();
   436         return QColor();
   439     }
   437     }
   440 }
   438 }
   441 
   439 
   442 void HbIconEnginePrivate::addBadge(Qt::Alignment align,
   440 void HbIconEnginePrivate::addBadge(Qt::Alignment align,
   443                       const HbIcon& icon,
   441                                    const HbIcon &icon,
   444                       int z)
   442                                    int z)
   445 {
   443 {
   446     if (!badgeInfo) {
   444     if (!badgeInfo) {
   447         badgeInfo = new HbBadgeIcon();
   445         badgeInfo = new HbBadgeIcon();
   448     }
   446     }
   449     badgeInfo->addBadge(align, icon, z);
   447     badgeInfo->addBadge(align, icon, z);
   450 }
   448 }
   451 
   449 
   452 bool HbIconEnginePrivate::removeBadge(const HbIcon& badge)
   450 bool HbIconEnginePrivate::removeBadge(const HbIcon &badge)
   453 {
   451 {
   454     return badgeInfo ? badgeInfo->removeBadge(badge) : false;
   452     return badgeInfo ? badgeInfo->removeBadge(badge) : false;
   455 }
   453 }
   456 
   454 
   457 void HbIconEnginePrivate::removeAllBadges()
   455 void HbIconEnginePrivate::removeAllBadges()
   479     QIconEngineV2(),
   477     QIconEngineV2(),
   480     d(new HbIconEnginePrivate(QString()))
   478     d(new HbIconEnginePrivate(QString()))
   481 {
   479 {
   482     // Register the HbIconEngine Instance to HbIconLoader
   480     // Register the HbIconEngine Instance to HbIconLoader
   483     HbIconLoader *loader = HbIconLoader::global();
   481     HbIconLoader *loader = HbIconLoader::global();
   484     loader->storeIconEngineInfo(this);    
   482     loader->storeIconEngineInfo(this);
   485 }
   483 }
   486 
   484 
   487 HbIconEngine::HbIconEngine(const QString &iconName) :
   485 HbIconEngine::HbIconEngine(const QString &iconName) :
   488     QObject(),
   486     QObject(),
   489     QIconEngineV2(),
   487     QIconEngineV2(),
   490     d(new HbIconEnginePrivate(iconName))
   488     d(new HbIconEnginePrivate(iconName))
   491 {
   489 {
   492     // Register the HbIconEngine Instance to HbIconLoader
   490     // Register the HbIconEngine Instance to HbIconLoader
   493     HbIconLoader *loader = HbIconLoader::global();    
   491     HbIconLoader *loader = HbIconLoader::global();
   494     loader->storeIconEngineInfo(this);
   492     loader->storeIconEngineInfo(this);
   495 }
   493 }
   496 
   494 
   497 HbIconEngine::HbIconEngine(const HbIconEngine &other) :
   495 HbIconEngine::HbIconEngine(const HbIconEngine &other) :
   498     QObject(),
   496     QObject(),
   624 {
   622 {
   625     if (d->mirroringMode != mode) {
   623     if (d->mirroringMode != mode) {
   626         // Mirroring changed, clear stored icon content
   624         // Mirroring changed, clear stored icon content
   627         clearStoredIconContent();
   625         clearStoredIconContent();
   628     }
   626     }
   629     
   627 
   630     d->mirroringMode = mode;
   628     d->mirroringMode = mode;
   631 }
   629 }
   632 
   630 
   633 QSize HbIconEngine::actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state)
   631 QSize HbIconEngine::actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state)
   634 {
   632 {
   657     }
   655     }
   658 
   656 
   659     // If size has not been defined, use icon's default size.
   657     // If size has not been defined, use icon's default size.
   660     if (!s.isValid()) {
   658     if (!s.isValid()) {
   661         // With size (0,0), loader uses the icon's default size.
   659         // With size (0,0), loader uses the icon's default size.
   662         s = QSize(0,0);
   660         s = QSize(0, 0);
   663     }
   661     }
   664 
   662 
   665     QIcon::Mode modeForLoader = mode;
   663     QIcon::Mode modeForLoader = mode;
   666 
   664 
   667     QString name = iconName(mode, state);
   665     QString name = iconName(mode, state);
   676     if (!name.isEmpty()) {
   674     if (!name.isEmpty()) {
   677         HbIconLoader *loader = HbIconLoader::global();
   675         HbIconLoader *loader = HbIconLoader::global();
   678 
   676 
   679         // If requested size is not the same as set in the engine, get a new pixmap from loader
   677         // If requested size is not the same as set in the engine, get a new pixmap from loader
   680         if (pixelSize != size().toSize()) {
   678         if (pixelSize != size().toSize()) {
   681              // Clear the old icon first
   679             // Clear the old icon first
   682             d->unLoadIcon();
   680             d->unLoadIcon();
   683             
   681 
   684             d->icon = loader->loadIcon(
   682             d->icon = loader->loadIcon(
   685                 name,
   683                           name,
   686                 HbIconLoader::AnyType,
   684                           HbIconLoader::AnyType,
   687                 HbIconLoader::AnyPurpose,
   685                           HbIconLoader::AnyPurpose,
   688                 s,
   686                           s,
   689                 Qt::KeepAspectRatio,
   687                           Qt::KeepAspectRatio,
   690                 modeForLoader,
   688                           modeForLoader,
   691                 d->iconLoaderOptions(),
   689                           d->iconLoaderOptions(),
   692                 0,
   690                           0,
   693                 d->colorToUse(name));
   691                           d->colorToUse(name));
   694             
   692 
   695             if (d->icon){
   693             if (d->icon) {
   696                 // Draw badges on this pixmap
   694                 // Draw badges on this pixmap
   697                 QPainter painter(&d->pixmap);
   695                 QPainter painter(&d->pixmap);
   698                 if (d->badgeInfo) {
   696                 if (d->badgeInfo) {
   699                     d->badgeInfo->paint(&painter, QRectF(QPointF(0, 0), pixelSize), mode, state, d->isMirrored());
   697                     d->badgeInfo->paint(&painter, QRectF(QPointF(0, 0), pixelSize), mode, state, d->isMirrored());
   700                 }
   698                 }
   701                 d->pixmap = d->icon->pixmap();
   699                 d->pixmap = d->icon->pixmap();
   702                 return d->pixmap;
   700                 return d->pixmap;
   703             }
   701             }
   704       
   702 
   705         }
   703         }
   706         // Requested size was same as set in engine, use the pixmap stored in engine
   704         // Requested size was same as set in engine, use the pixmap stored in engine
   707         else {
   705         else {
   708             if (!d->icon || Qt::KeepAspectRatio != d->aspectRatioMode || mode != d->mode || state != d->state) {
   706             if (!d->icon || Qt::KeepAspectRatio != d->aspectRatioMode || mode != d->mode || state != d->state) {
   709                 d->aspectRatioMode = Qt::KeepAspectRatio;
   707                 d->aspectRatioMode = Qt::KeepAspectRatio;
   710                 d->mode = mode;
   708                 d->mode = mode;
   711                 d->state = state;
   709                 d->state = state;
   712                 // Clear the old icon first
   710                 // Clear the old icon first
   713                 d->unLoadIcon();
   711                 d->unLoadIcon();
   714                 d->icon  = loader->loadIcon(
   712                 d->icon  = loader->loadIcon(
   715                     name,
   713                                name,
   716                     HbIconLoader::AnyType,
   714                                HbIconLoader::AnyType,
   717                     HbIconLoader::AnyPurpose, 
   715                                HbIconLoader::AnyPurpose,
   718                     s,
   716                                s,
   719                     Qt::KeepAspectRatio,
   717                                Qt::KeepAspectRatio,
   720                     modeForLoader,
   718                                modeForLoader,
   721                     d->iconLoaderOptions(),
   719                                d->iconLoaderOptions(),
   722                     0,
   720                                0,
   723                     d->colorToUse(name));
   721                                d->colorToUse(name));
   724 
   722 
   725                 // If loading failed, store information so it is not retried.
   723                 // If loading failed, store information so it is not retried.
   726                 if (!d->icon) {
   724                 if (!d->icon) {
   727                     d->appendLoadFail(mode, state); 
   725                     d->appendLoadFail(mode, state);
   728                 }
   726                 }
   729             }
   727             }
   730             if (d->icon) {
   728             if (d->icon) {
   731                 d->pixmap = d->icon->pixmap();
   729                 d->pixmap = d->icon->pixmap();
   732                 // Draw badges on this pixmap
   730                 // Draw badges on this pixmap
   733                 QPainter painter(&d->pixmap);
   731                 QPainter painter(&d->pixmap);
   734                 if (d->badgeInfo){
   732                 if (d->badgeInfo) {
   735                     d->badgeInfo->paint(&painter, QRectF(QPointF(0, 0), pixelSize), mode, state, d->isMirrored());
   733                     d->badgeInfo->paint(&painter, QRectF(QPointF(0, 0), pixelSize), mode, state, d->isMirrored());
   736                 }
   734                 }
   737                 return d->pixmap;
   735                 return d->pixmap;
   738             }
   736             }
   739         }
   737         }
   773 
   771 
   774 QSizeF HbIconEngine::defaultSize() const
   772 QSizeF HbIconEngine::defaultSize() const
   775 {
   773 {
   776     QString name = iconName();
   774     QString name = iconName();
   777     if (!d->defaultSizeFailed && !d->defaultSize.isValid() && !name.isEmpty()) {
   775     if (!d->defaultSizeFailed && !d->defaultSize.isValid() && !name.isEmpty()) {
   778         if (d->icon){
   776         if (d->icon) {
   779             d->defaultSize = d->icon->defaultSize();
   777             d->defaultSize = d->icon->defaultSize();
   780         } else {
   778         } else {
   781             HbIconLoader *loader = HbIconLoader::global();
   779             HbIconLoader *loader = HbIconLoader::global();
   782             d->defaultSize = loader->defaultSize(name, QString(), d->iconLoaderOptions());
   780             d->defaultSize = loader->defaultSize(name, QString(), d->iconLoaderOptions());
   783         }
   781         }
   807         // Size changed, invalidate pixmap stored in this object.
   805         // Size changed, invalidate pixmap stored in this object.
   808         clearStoredIconContent(KeepDefaultSize);
   806         clearStoredIconContent(KeepDefaultSize);
   809     }
   807     }
   810 }
   808 }
   811 
   809 
   812 void HbIconEngine::paint( QPainter *painter,
   810 void HbIconEngine::paint(QPainter *painter,
   813                           const QRect &rect,
   811                          const QRect &rect,
   814                           QIcon::Mode mode,
   812                          QIcon::Mode mode,
   815                           QIcon::State state )
   813                          QIcon::State state)
   816 {
   814 {
   817     // This method is called by QIcon and it should paint the icon with the size defined by 'rect'.
   815     // This method is called by QIcon and it should paint the icon with the size defined by 'rect'.
   818     HbIconImpl* icon = 0;
   816     HbIconImpl *icon = 0;
   819     
   817 
   820     // update the rendering mode
   818     // update the rendering mode
   821     HbIconLoader::global()->updateRenderingMode(painter->paintEngine()->type());
   819     QPaintEngine *paintEngine = painter->paintEngine();
   822     
   820     if (paintEngine) {
       
   821         HbIconLoader::global()->updateRenderingMode(paintEngine->type());
       
   822     }
       
   823 
   823     icon = paintHelper(rect.size(), Qt::KeepAspectRatio, mode, state);
   824     icon = paintHelper(rect.size(), Qt::KeepAspectRatio, mode, state);
   824     if (icon) {
   825     if (icon) {
   825         icon->paint(painter, rect, Qt::AlignCenter);
   826         icon->paint(painter, rect, Qt::AlignCenter);
   826         HbIconLoader::global()->unLoadIcon(icon);
   827         HbIconLoader::global()->unLoadIcon(icon);
   827         icon->dispose();
   828         icon->dispose();
   831             d->badgeInfo->paint(painter, rect, mode, state, icon->isMirrored());
   832             d->badgeInfo->paint(painter, rect, mode, state, icon->isMirrored());
   832         }
   833         }
   833     }
   834     }
   834 }
   835 }
   835 
   836 
   836 void HbIconEngine::paint( QPainter *painter,
   837 void HbIconEngine::paint(QPainter *painter,
   837                           const QRectF &rect,
   838                          const QRectF &rect,
   838                           Qt::AspectRatioMode aspectRatioMode,
   839                          Qt::AspectRatioMode aspectRatioMode,
   839                           Qt::Alignment alignment,
   840                          Qt::Alignment alignment,
   840                           QIcon::Mode mode,
   841                          QIcon::Mode mode,
   841                           QIcon::State state)
   842                          QIcon::State state)
   842 {
   843 {
   843     // If loading the pixmap has failed, do not retry forever
   844     // If loading the pixmap has failed, do not retry forever
   844     if (loadFailed(mode, state)) {
   845     if (loadFailed(mode, state)) {
   845         return;
   846         return;
   846     }
   847     }
   853     }
   854     }
   854 
   855 
   855     // FrameSet animations need to be reloaded if size related parameters have changed,
   856     // FrameSet animations need to be reloaded if size related parameters have changed,
   856     // so delete the current animation in that case.
   857     // so delete the current animation in that case.
   857     HbIconAnimation *anim = animation();
   858     HbIconAnimation *anim = animation();
   858     if (anim && anim->type() == HbIconAnimation::FrameSet) {        
   859     if (anim && anim->type() == HbIconAnimation::FrameSet) {
   859         if ( ( (!s.isEmpty() || !anim->size().isEmpty()) && s != anim->size() ) ||
   860         if (((!s.isEmpty() || !anim->size().isEmpty()) && s != anim->size()) ||
   860             aspectRatioMode != anim->aspectRatioMode()) {
   861                 aspectRatioMode != anim->aspectRatioMode()) {
   861 #ifdef HB_ICON_TRACES
   862 #ifdef HB_ICON_TRACES
   862             qDebug("HbIconEngine: deleting anim");
   863             qDebug("HbIconEngine: deleting anim");
   863 #endif
   864 #endif
   864             delete anim;
   865             delete anim;
   865             d->animator->d->animation = 0;
   866             d->animator->d->animation = 0;
   867     }
   868     }
   868 
   869 
   869     // If size has not been defined, use icon's default size.
   870     // If size has not been defined, use icon's default size.
   870     if (!s.isValid()) {
   871     if (!s.isValid()) {
   871         // With size (0,0), loader uses the icon's default size.
   872         // With size (0,0), loader uses the icon's default size.
   872         s = QSizeF(0,0);
   873         s = QSizeF(0, 0);
   873     }
   874     }
   874 
   875 
   875     // If pixmap has not been loaded yet or parameters affecting to pixmap have changed,
   876     // If pixmap has not been loaded yet or parameters affecting to pixmap have changed,
   876     // load the pixmap using paintHelper.
   877     // load the pixmap using paintHelper.
   877     if ((!d->icon) || aspectRatioMode != d->aspectRatioMode || mode != d->mode || state != d->state) {
   878     if ((!d->icon) || aspectRatioMode != d->aspectRatioMode || mode != d->mode || state != d->state) {
   879         d->mode = mode;
   880         d->mode = mode;
   880         d->state = state;
   881         d->state = state;
   881         // If icon parameters changed unload the icon first, and get the new icon
   882         // If icon parameters changed unload the icon first, and get the new icon
   882         d->unLoadIcon();
   883         d->unLoadIcon();
   883         // Update the rendering mode
   884         // Update the rendering mode
   884         HbIconLoader::global()->updateRenderingMode(painter->paintEngine()->type());        
   885         QPaintEngine *paintEngine = painter->paintEngine();
       
   886         if (paintEngine) {
       
   887             HbIconLoader::global()->updateRenderingMode(paintEngine->type());
       
   888         }
   885         d->icon = paintHelper(s, aspectRatioMode, mode, state);
   889         d->icon = paintHelper(s, aspectRatioMode, mode, state);
   886         if ( d->icon && d->icon->isCreatedOnServer() ) {
   890         if (d->icon && d->icon->isCreatedOnServer()) {
   887             d->iconType = d->icon->iconData().type;
   891             d->iconType = d->icon->iconData().type;
   888         }
   892         }
   889     }
   893     }
   890 
   894 
   891     // Adjust the alignment and draw the icon.
   895     // Adjust the alignment and draw the icon.
   905 }
   909 }
   906 
   910 
   907 void HbIconEngine::setAnimator(HbIconAnimator *animator)
   911 void HbIconEngine::setAnimator(HbIconAnimator *animator)
   908 {
   912 {
   909     d->animator = animator;
   913     d->animator = animator;
   910     // Reconnect animation signals    
   914     // Reconnect animation signals
   911     HbIconAnimation *anim = animation();
   915     HbIconAnimation *anim = animation();
   912 
   916 
   913     if (anim) {
   917     if (anim) {
   914         disconnect(anim); // To make sure we don't get multiple signals
   918         disconnect(anim); // To make sure we don't get multiple signals
   915         connect(anim, SIGNAL(animationUpdated()), this, SLOT(handleAnimationUpdated()));
   919         connect(anim, SIGNAL(animationUpdated()), this, SLOT(handleAnimationUpdated()));
   917         connect(anim, SIGNAL(animationStopped()), this, SLOT(handleAnimationStopped()));
   921         connect(anim, SIGNAL(animationStopped()), this, SLOT(handleAnimationStopped()));
   918         connect(anim, SIGNAL(animationFinished()), this, SLOT(handleAnimationFinished()));
   922         connect(anim, SIGNAL(animationFinished()), this, SLOT(handleAnimationFinished()));
   919     }
   923     }
   920 }
   924 }
   921 
   925 
   922 HbIconImpl* HbIconEngine::paintHelper(
   926 HbIconImpl *HbIconEngine::paintHelper(
   923     const QSizeF &size,
   927     const QSizeF &size,
   924     Qt::AspectRatioMode aspectRatioMode,
   928     Qt::AspectRatioMode aspectRatioMode,
   925     QIcon::Mode mode,
   929     QIcon::Mode mode,
   926     QIcon::State state)
   930     QIcon::State state)
   927 {
   931 {
   930     // set afterwards (after construction but before the first paint).
   934     // set afterwards (after construction but before the first paint).
   931     ensureSignalConnections();
   935     ensureSignalConnections();
   932 
   936 
   933     QString name = iconName(mode, state);
   937     QString name = iconName(mode, state);
   934     QIcon::Mode modeForLoader = mode;
   938     QIcon::Mode modeForLoader = mode;
   935     HbIconImpl *icon = NULL;
   939     HbIconImpl *icon = 0;
   936     if (name.isEmpty()) {
   940     if (name.isEmpty()) {
   937         // Icon name not defined for this mode and state, use default icon name
   941         // Icon name not defined for this mode and state, use default icon name
   938         name = iconName(QIcon::Normal, QIcon::Off);
   942         name = iconName(QIcon::Normal, QIcon::Off);
   939     } else {
   943     } else {
   940         // Icon name was defined for this mode and state, do not apply mode in loader
   944         // Icon name was defined for this mode and state, do not apply mode in loader
   960     else {
   964     else {
   961         if (!name.isEmpty()) {
   965         if (!name.isEmpty()) {
   962             HbIconLoader *loader = HbIconLoader::global();
   966             HbIconLoader *loader = HbIconLoader::global();
   963 
   967 
   964             icon = loader->loadIcon(
   968             icon = loader->loadIcon(
   965                 name,
   969                        name,
   966                 HbIconLoader::AnyType,
   970                        HbIconLoader::AnyType,
   967                 HbIconLoader::AnyPurpose,
   971                        HbIconLoader::AnyPurpose,
   968                 size,
   972                        size,
   969                 aspectRatioMode,
   973                        aspectRatioMode,
   970                 modeForLoader,
   974                        modeForLoader,
   971                 d->iconLoaderOptions(),
   975                        d->iconLoaderOptions(),
   972                 d->animator,
   976                        d->animator,
   973                 d->colorToUse(name));
   977                        d->colorToUse(name));
   974 
   978 
   975             // If loading failed, store information so it is not retried in every repaint.
   979             // If loading failed, store information so it is not retried in every repaint.
   976             if (!icon) {
   980             if (!icon) {
   977                 d->appendLoadFail(mode, state);
   981                 d->appendLoadFail(mode, state);
   978             }
   982             }
  1001     but does not touch the settings, e.g. the size, state, flags, unlike clear().
  1005     but does not touch the settings, e.g. the size, state, flags, unlike clear().
  1002 
  1006 
  1003     This function is called when some parameters change so that the content has
  1007     This function is called when some parameters change so that the content has
  1004     to be reloaded, and in low-graphics-memory situations to get rid of all
  1008     to be reloaded, and in low-graphics-memory situations to get rid of all
  1005     cached image data for the icon.
  1009     cached image data for the icon.
  1006     
  1010 
  1007     The goal in the OOGM case is to destroy all unnecessary QPixmaps which will in turn
  1011     The goal in the OOGM case is to destroy all unnecessary QPixmaps which will in turn
  1008     lead to freeing graphics memory (in case we are running on the OpenVG paint engine).
  1012     lead to freeing graphics memory (in case we are running on the OpenVG paint engine).
  1009     The data will be reloaded (well, at least tried to be reloaded) when the icon is
  1013     The data will be reloaded (well, at least tried to be reloaded) when the icon is
  1010     painted the next time.
  1014     painted the next time.
  1011  */
  1015  */
  1063 
  1067 
  1064 void HbIconEngine::themeChange(const QStringList &updatedFiles)
  1068 void HbIconEngine::themeChange(const QStringList &updatedFiles)
  1065 {
  1069 {
  1066     // Theme has changed, clear stored icon content
  1070     // Theme has changed, clear stored icon content
  1067     // Server side icon cache is already cleared when theme is changed
  1071     // Server side icon cache is already cleared when theme is changed
  1068     if (updatedFiles.count() == 0 || (d->icon && updatedFiles.contains(d->icon->iconFileName())) ) {
  1072     if (updatedFiles.count() == 0 || (d->icon && updatedFiles.contains(d->icon->iconFileName()))) {
  1069         clearStoredIconContent(UnloadedByServer);
  1073         clearStoredIconContent(UnloadedByServer);
  1070     }
  1074     }
  1071 }
  1075 }
  1072 
  1076 
  1073 void HbIconEngine::handleLayoutDirectionChanged()
  1077 void HbIconEngine::handleLayoutDirectionChanged()
  1074 {
  1078 {
  1075     if ((d->mirroringMode == HbIcon::Default && d->defaultMirroring == HbIconEnginePrivate::Enabled) ||
  1079     if ((d->mirroringMode == HbIcon::Default && d->defaultMirroring == HbIconEnginePrivate::Enabled) ||
  1076          d->mirroringMode == HbIcon::LayoutDirection) {
  1080             d->mirroringMode == HbIcon::LayoutDirection) {
  1077         // This icon is automatically mirrored based on layout direction.
  1081         // This icon is automatically mirrored based on layout direction.
  1078 
  1082 
  1079         // Clear the stored icon content and its default size because the layout direction just changed.
  1083         // Clear the stored icon content and its default size because the layout direction just changed.
  1080         // Lazy loading is used, new pixmap will be rasterized when it's required by paint method.
  1084         // Lazy loading is used, new pixmap will be rasterized when it's required by paint method.
  1081         clearStoredIconContent();
  1085         clearStoredIconContent();
  1139     if (anim) {
  1143     if (anim) {
  1140         // Update parameters in animation
  1144         // Update parameters in animation
  1141         anim->setSize(size());
  1145         anim->setSize(size());
  1142         anim->setAspectRatioMode(d->aspectRatioMode);
  1146         anim->setAspectRatioMode(d->aspectRatioMode);
  1143         anim->setMode(d->mode);
  1147         anim->setMode(d->mode);
  1144         // Get the current frame as pixmap from the animation        
  1148         // Get the current frame as pixmap from the animation
  1145         return anim->currentFrame();
  1149         return anim->currentFrame();
  1146     } else {
  1150     } else {
  1147         return QPixmap();
  1151         return QPixmap();
  1148     }
  1152     }
  1149 }
  1153 }
  1150 
  1154 
  1151 /*!
  1155 /*!
  1152  * Removes the item in the cache if the ref. count is 0 and does delete on
  1156  * Removes the item in the cache if the ref. count is 0 and does delete on
  1153  * HbIconImpl and Resets the IconImpl. 
  1157  * HbIconImpl and Resets the IconImpl.
  1154  */
  1158  */
  1155 void HbIconEngine::resetIconImpl() const
  1159 void HbIconEngine::resetIconImpl() const
  1156  {  
  1160 {
  1157 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON)
  1161 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON)
  1158     if ( (d->iconType == SGIMAGE) || (d->iconType == NVG) ) {
  1162     if ((d->iconType == SGIMAGE) || (d->iconType == NVG)) {
  1159         if ( d->icon ) {
  1163         if (d->icon) {
  1160             d->icon->decrementRefCount();
  1164             d->icon->decrementRefCount();
  1161             if ( d->icon->refCount() == 0 && d->icon->isCreatedOnServer() ) {
  1165             if (d->icon->refCount() == 0 && d->icon->isCreatedOnServer()) {
  1162                 HbIconLoader *loader = HbIconLoader::global();
  1166                 HbIconLoader *loader = HbIconLoader::global();
  1163                 loader->removeItemInCache(d->icon);
  1167                 loader->removeItemInCache(d->icon);
  1164                 d->icon->dispose();
  1168                 d->icon->dispose();
  1165             }
  1169             }
  1166             d->icon = 0;
  1170             d->icon = 0;
  1167         }
  1171         }
  1168     }
  1172     }
  1169 #endif
  1173 #endif
  1170  }
  1174 }
  1171 
  1175 
  1172 void HbIconEngine::addBadge(Qt::Alignment align,
  1176 void HbIconEngine::addBadge(Qt::Alignment align,
  1173                       const HbIcon& icon,
  1177                             const HbIcon &icon,
  1174                       int z)
  1178                             int z)
  1175 {
  1179 {
  1176     d->addBadge(align, icon, z);
  1180     d->addBadge(align, icon, z);
  1177 }
  1181 }
  1178 
  1182 
  1179 bool HbIconEngine::removeBadge(const HbIcon& badge)
  1183 bool HbIconEngine::removeBadge(const HbIcon &badge)
  1180 {
  1184 {
  1181     return d->removeBadge(badge);
  1185     return d->removeBadge(badge);
  1182 }
  1186 }
  1183 
  1187 
  1184 void HbIconEngine::removeAllBadges()
  1188 void HbIconEngine::removeAllBadges()