src/hbcore/image/hbiconengine.cpp
changeset 28 b7da29130b0e
parent 23 e6ad4ef83b23
child 30 80e4d18b72f5
equal deleted inserted replaced
23:e6ad4ef83b23 28:b7da29130b0e
   313     HbIconLoader *loader = HbIconLoader::global();
   313     HbIconLoader *loader = HbIconLoader::global();
   314 
   314 
   315     // Ignore the result of any outstanding loadIcon request. The
   315     // Ignore the result of any outstanding loadIcon request. The
   316     // parameters here must match callback and callbackParam passed to
   316     // parameters here must match callback and callbackParam passed to
   317     // HbIconLoader::loadIcon in paintHelper().
   317     // HbIconLoader::loadIcon in paintHelper().
   318     loader->cancelLoadIcon(HbIconEngine::asyncLoadCallback, q);
   318     if (loader) {
       
   319         loader->cancelLoadIcon(HbIconEngine::asyncLoadCallback, q);
       
   320     }
   319 
   321 
   320     if (icon) {
   322     if (icon) {
   321         loader->unLoadIcon(icon, unloadedByServer);
   323         if (loader) {
       
   324             loader->unLoadIcon(icon, unloadedByServer);
       
   325         }
   322         icon->dispose();
   326         icon->dispose();
   323         icon = 0;
   327         icon = 0;
   324     }
   328     }
   325 }
   329 }
   326 
   330 
   542 }
   546 }
   543 
   547 
   544 HbIconEngine::~HbIconEngine()
   548 HbIconEngine::~HbIconEngine()
   545 {
   549 {
   546     // Unregister the HbIconEngine Instance to HbIconLoader
   550     // Unregister the HbIconEngine Instance to HbIconLoader
       
   551     // However it may already have been destroyed, if the app is shuting down
       
   552     // so be prepared for null ptr too.
   547     HbIconLoader *loader = HbIconLoader::global();
   553     HbIconLoader *loader = HbIconLoader::global();
   548     loader->removeIconEngineInfo(this);
   554     if (loader) {
       
   555         loader->removeIconEngineInfo(this);
       
   556     }
   549     delete d;
   557     delete d;
   550 }
   558 }
   551 
   559 
   552 void HbIconEngine::init()
   560 void HbIconEngine::init()
   553 {
   561 {
   554     d->q = this;
   562     d->q = this;
   555     // Register the HbIconEngine Instance to HbIconLoader
   563     // Register the HbIconEngine Instance to HbIconLoader
   556     HbIconLoader *loader = HbIconLoader::global();
   564     HbIconLoader *loader = HbIconLoader::global();
   557     loader->storeIconEngineInfo(this);
   565     if (loader) {    
       
   566         loader->storeIconEngineInfo(this);
       
   567     }
   558 }
   568 }
   559 
   569 
   560 void HbIconEngine::forceFlagUpdate()
   570 void HbIconEngine::forceFlagUpdate()
   561 {
   571 {
   562     HbIcon::Flags newFlags = d->flags;
   572     HbIcon::Flags newFlags = d->flags;
   730                           0,
   740                           0,
   731                           d->colorToUse(name));
   741                           d->colorToUse(name));
   732 
   742 
   733             if (d->icon) {
   743             if (d->icon) {
   734                 // Draw badges on this pixmap
   744                 // Draw badges on this pixmap
   735                 QPainter painter(&d->pixmap);
       
   736                 if (d->badgeInfo) {
   745                 if (d->badgeInfo) {
       
   746                     QPainter painter(&d->pixmap);
   737                     d->badgeInfo->paint(&painter, QRectF(QPointF(0, 0), pixelSize), mode, state, d->isMirrored());
   747                     d->badgeInfo->paint(&painter, QRectF(QPointF(0, 0), pixelSize), mode, state, d->isMirrored());
   738                 }
   748                 }
   739                 d->pixmap = d->icon->pixmap();
   749                 d->pixmap = d->icon->pixmap();
   740                 return d->pixmap;
   750                 return d->pixmap;
   741             }
   751             }
   766                 }
   776                 }
   767             }
   777             }
   768             if (d->icon) {
   778             if (d->icon) {
   769                 d->pixmap = d->icon->pixmap();
   779                 d->pixmap = d->icon->pixmap();
   770                 // Draw badges on this pixmap
   780                 // Draw badges on this pixmap
   771                 QPainter painter(&d->pixmap);
       
   772                 if (d->badgeInfo) {
   781                 if (d->badgeInfo) {
       
   782                     QPainter painter(&d->pixmap);
   773                     d->badgeInfo->paint(&painter, QRectF(QPointF(0, 0), pixelSize), mode, state, d->isMirrored());
   783                     d->badgeInfo->paint(&painter, QRectF(QPointF(0, 0), pixelSize), mode, state, d->isMirrored());
   774                 }
   784                 }
   775                 return d->pixmap;
   785                 return d->pixmap;
   776             }
   786             }
   777         }
   787         }
   850                          const QRect &rect,
   860                          const QRect &rect,
   851                          QIcon::Mode mode,
   861                          QIcon::Mode mode,
   852                          QIcon::State state)
   862                          QIcon::State state)
   853 {
   863 {
   854     // This method is called by QIcon and it should paint the icon with the size defined by 'rect'.
   864     // This method is called by QIcon and it should paint the icon with the size defined by 'rect'.
       
   865 
       
   866     HbIconLoader *loader = HbIconLoader::global();
       
   867     if (!loader) {
       
   868         return;
       
   869     }
       
   870 
   855     HbIconImpl *icon = 0;
   871     HbIconImpl *icon = 0;
   856 
   872 
   857     // update the rendering mode
   873     // update the rendering mode
   858     QPaintEngine *paintEngine = painter->paintEngine();
   874     QPaintEngine *paintEngine = painter->paintEngine();
   859     if (paintEngine) {
   875     if (paintEngine) {
   860         HbIconLoader::global()->updateRenderingMode(paintEngine->type());
   876         loader->updateRenderingMode(paintEngine->type());
   861     }
   877     }
   862 
   878 
   863     if (d->async) {
   879     if (d->async) {
   864         setAsync(false, 0, 0);
   880         setAsync(false, 0, 0);
   865     }
   881     }
   866     icon = paintHelper(rect.size(), Qt::KeepAspectRatio, mode, state);
   882     icon = paintHelper(rect.size(), Qt::KeepAspectRatio, mode, state);
   867     if (icon) {
   883     if (icon) {
   868         icon->paint(painter, rect, Qt::AlignCenter);
   884         icon->paint(painter, rect, Qt::AlignCenter);
   869         HbIconLoader::global()->unLoadIcon(icon);
   885         loader->unLoadIcon(icon);
   870         icon->dispose();
   886         icon->dispose();
   871 
   887 
   872         // Now paint any necessary badges.
   888         // Now paint any necessary badges.
   873         if (d->badgeInfo) {
   889         if (d->badgeInfo) {
   874             d->badgeInfo->paint(painter, rect, mode, state, icon->isMirrored());
   890             d->badgeInfo->paint(painter, rect, mode, state, icon->isMirrored());
   881                          Qt::AspectRatioMode aspectRatioMode,
   897                          Qt::AspectRatioMode aspectRatioMode,
   882                          Qt::Alignment alignment,
   898                          Qt::Alignment alignment,
   883                          QIcon::Mode mode,
   899                          QIcon::Mode mode,
   884                          QIcon::State state)
   900                          QIcon::State state)
   885 {
   901 {
       
   902     HbIconLoader *loader = HbIconLoader::global();
       
   903     if (!loader) {
       
   904         return;
       
   905     }
       
   906     
   886     // If loading the pixmap has failed, do not retry forever
   907     // If loading the pixmap has failed, do not retry forever
   887     if (loadFailed(mode, state)) {
   908     if (loadFailed(mode, state)) {
   888         return;
   909         return;
   889     }
   910     }
   890 
   911 
   924         // If icon parameters changed unload the icon first, and get the new icon
   945         // If icon parameters changed unload the icon first, and get the new icon
   925         d->unLoadIcon();
   946         d->unLoadIcon();
   926         // Update the rendering mode
   947         // Update the rendering mode
   927         QPaintEngine *paintEngine = painter->paintEngine();
   948         QPaintEngine *paintEngine = painter->paintEngine();
   928         if (paintEngine) {
   949         if (paintEngine) {
   929             HbIconLoader::global()->updateRenderingMode(paintEngine->type());
   950             loader->updateRenderingMode(paintEngine->type());
   930         }
   951         }
   931         d->icon = paintHelper(s, aspectRatioMode, mode, state);
   952         d->icon = paintHelper(s, aspectRatioMode, mode, state);
   932         if (d->icon && d->icon->isCreatedOnServer()) {
   953         if (d->icon && d->icon->isCreatedOnServer()) {
   933             d->iconType = d->icon->iconData().type;
   954             d->iconType = d->icon->iconData().type;
   934         }
   955         }
  1159 void HbIconEngine::ensureSignalConnections()
  1180 void HbIconEngine::ensureSignalConnections()
  1160 {
  1181 {
  1161     if (!d->signalConnectionsSet) {
  1182     if (!d->signalConnectionsSet) {
  1162         d->signalConnectionsSet = true;
  1183         d->signalConnectionsSet = true;
  1163         if (!d->flags.testFlag(HbIcon::NonThemeable)) {
  1184         if (!d->flags.testFlag(HbIcon::NonThemeable)) {
  1164             connect(&hbInstance->theme()->d_ptr->iconTheme, SIGNAL(iconsUpdated(const QStringList &)), this, SLOT(themeChange(const QStringList &)));
  1185             connect(&hbInstance->theme()->d_ptr->iconTheme, SIGNAL(iconsUpdated(QStringList)),
       
  1186                 SLOT(themeChange(QStringList)));
  1165             connect(HbLayoutDirectionNotifier::instance(), SIGNAL(layoutDirectionChanged()),
  1187             connect(HbLayoutDirectionNotifier::instance(), SIGNAL(layoutDirectionChanged()),
  1166                     this, SLOT(handleLayoutDirectionChanged()));
  1188                 SLOT(handleLayoutDirectionChanged()));
  1167             // No need to worry about missed notifications because if the icon was not
  1189             // No need to worry about missed notifications because if the icon was not
  1168             // painted before then there is nothing to clear.
  1190             // painted before then there is nothing to clear.
  1169         }
  1191         }
  1170     }
  1192     }
  1171 }
  1193 }
  1266  * notification is received (on the server-side).
  1288  * notification is received (on the server-side).
  1267  */
  1289  */
  1268 void HbIconEngine::resetIconImpl() const
  1290 void HbIconEngine::resetIconImpl() const
  1269 {
  1291 {
  1270 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON)
  1292 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON)
  1271     if ((d->iconType == SGIMAGE) || (d->iconType == NVG)) {
  1293     
  1272         if (d->icon) {
  1294         if (d->icon) {
  1273             d->icon->decrementRefCount();
  1295             d->icon->decrementRefCount();
  1274             if (d->icon->refCount() == 0 && d->icon->isCreatedOnServer()) {
  1296             if (d->icon->refCount() == 0 && d->icon->isCreatedOnServer()) {
  1275                 HbIconLoader *loader = HbIconLoader::global();
  1297                 HbIconLoader *loader = HbIconLoader::global();
  1276                 loader->removeItemInCache(d->icon);
  1298                 loader->removeItemInCache(d->icon);
  1277             }
  1299             }
  1278             d->icon->dispose();
  1300             d->icon->dispose();
  1279             d->icon = 0;
  1301             d->icon = 0;
  1280         }
  1302         }
  1281     }
  1303     
  1282 #endif
  1304 #endif
  1283 }
  1305 }
  1284 
  1306 
  1285 void HbIconEngine::addBadge(Qt::Alignment align,
  1307 void HbIconEngine::addBadge(Qt::Alignment align,
  1286                             const HbIcon &icon,
  1308                             const HbIcon &icon,