src/hbcore/image/hbframedrawer.cpp
changeset 34 ed14f46c0e55
parent 6 c3690ec91ef8
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
   245 \internal
   245 \internal
   246 */
   246 */
   247 HbFrameDrawerPrivate::~HbFrameDrawerPrivate()
   247 HbFrameDrawerPrivate::~HbFrameDrawerPrivate()
   248 {
   248 {
   249     unLoadIcon();
   249     unLoadIcon();
   250     //Unregister the HbFrameDrawerPrivate Instance to HbIconLoader
   250     // Unregister the HbFrameDrawerPrivate Instance to HbIconLoader.
   251     HbIconLoader::global()->removeFrameDrawerInfo(this);
   251     // However it may already have been destroyed, if the app is shuting down
       
   252     // so be prepared for null ptr too.
       
   253     HbIconLoader *loader = HbIconLoader::global();
       
   254     if (loader) {
       
   255         loader->removeFrameDrawerInfo(this);
       
   256     }
   252 }
   257 }
   253 
   258 
   254 /*!
   259 /*!
   255 \internal
   260 \internal
   256 */
   261 */
   369     data.multiPartIconId = multiPartIconId();
   374     data.multiPartIconId = multiPartIconId();
   370     multiPartSizeData = data;
   375     multiPartSizeData = data;
   371 
   376 
   372     // Create the frame icon and add it in the icon cache
   377     // Create the frame icon and add it in the icon cache
   373     HbIconLoader *loader = HbIconLoader::global();
   378     HbIconLoader *loader = HbIconLoader::global();
       
   379     if (!loader) {
       
   380         return;
       
   381     }
   374 
   382 
   375     //If it's one-piece frame-item, it's loaded using HbIconLoader::loadIcon()
   383     //If it's one-piece frame-item, it's loaded using HbIconLoader::loadIcon()
   376     if (frameParts == 1) {
   384     if (frameParts == 1) {
   377         HbIconImpl *iconImpl =  loader->loadIcon(frameGraphicsName, HbIconLoader::AnyType,
   385         HbIconImpl *iconImpl =  loader->loadIcon(frameGraphicsName, HbIconLoader::AnyType,
   378                                 HbIconLoader::AnyPurpose,
   386                                 HbIconLoader::AnyPurpose,
   395 
   403 
   396         QVector<HbIconImpl *> listOfIcons;
   404         QVector<HbIconImpl *> listOfIcons;
   397 
   405 
   398         //For multi-piece frame-items, HbIocnLoader::loadMultipieceIcon is used
   406         //For multi-piece frame-items, HbIocnLoader::loadMultipieceIcon is used
   399         //This function returns the consolidate (stitched) icon created on the themeserver.
   407         //This function returns the consolidate (stitched) icon created on the themeserver.
   400         //If the consolidated icon-creation on themeserver fails, then server returns a list
   408         //If the consolidated icon-creation on themeserver fails, then the consolidated
   401         //of individual frame-items.
   409         //icon is created on the client-side (fallback)
   402         HbIconImpl *iconImpl = loader->loadMultiPieceIcon(multiPieceFileNames, data, frameIconSize,
   410         HbIconImpl *iconImpl = loader->loadMultiPieceIcon(multiPieceFileNames, data, frameIconSize,
   403                                Qt::IgnoreAspectRatio, QIcon::Normal, iconLoaderOptions(),
   411                                Qt::IgnoreAspectRatio, QIcon::Normal, iconLoaderOptions(),
   404                                listOfIcons, color);
   412                                listOfIcons, color);
   405 
   413 
   406         if (iconImpl) {
   414         if (iconImpl) {
   970         frameParts = 0;
   978         frameParts = 0;
   971     }
   979     }
   972 }
   980 }
   973 
   981 
   974 /*!
   982 /*!
   975 *   Resets the MaskableIcon
   983  * Drops the underlying icon(s).  No need to send an unload req to server because the
   976 */
   984  * server drops the icon by itself in this case.
       
   985  */
   977 void HbFrameDrawerPrivate::resetMaskableIcon()
   986 void HbFrameDrawerPrivate::resetMaskableIcon()
   978 {
   987 {
   979 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON)
       
   980     HbIconLoader *loader = HbIconLoader::global();
   988     HbIconLoader *loader = HbIconLoader::global();
   981     if (icon) {
   989     if (icon) {
   982         //consolidated icon case
   990         //consolidated icon case
   983         icon->decrementRefCount();
   991         icon->decrementRefCount();
   984         if (icon->refCount() == 0 && icon->isCreatedOnServer()) {
   992         if (icon->refCount() == 0) {
   985             // remove the item from cache and delete the icon
   993             // remove the item from cache and delete the icon
   986             loader->removeItemInCache(icon->iconImpl());
   994             if (loader) {
       
   995                 loader->removeItemInCache(icon->iconImpl());
       
   996             }
   987             icon->dispose();
   997             icon->dispose();
   988         }
   998         }
   989         icon = 0;
   999         icon = 0;
   990     } else {
  1000     } else {
   991         int count = fallbackMaskableIconList.count();
  1001         int count = fallbackMaskableIconList.count();
   992         if (count) {
  1002         if (count) {
   993             // for each item in fallbackMaskableIconList - decrement the reference count and
  1003             // for each item in fallbackMaskableIconList - decrement the reference count and
   994             // remove the item in cache, dispose if needed.
  1004             // remove the item in cache, dispose if needed.
   995             foreach(HbMaskableIconImpl * impl, fallbackMaskableIconList) {
  1005             foreach(HbMaskableIconImpl * impl, fallbackMaskableIconList) {
   996                 impl->decrementRefCount();
  1006                 impl->decrementRefCount();
   997                 if (impl->refCount() == 0 && impl->isCreatedOnServer()) {
  1007                 if (impl->refCount() == 0) {
   998                     loader->removeItemInCache(impl->iconImpl());
  1008                     if (loader) {
       
  1009                         loader->removeItemInCache(impl->iconImpl());
       
  1010                     }
   999                     impl->dispose();
  1011                     impl->dispose();
  1000                 }
  1012                 }
  1001             }
  1013             }
  1002             fallbackMaskableIconList.clear();
  1014             fallbackMaskableIconList.clear();
  1003         }
  1015         }
  1004     }
  1016     }
  1005     frameParts = 0;
  1017     frameParts = 0;
  1006 #endif
       
  1007 }
  1018 }
  1008 
  1019 
  1009 HbIconLoader::IconLoaderOptions HbFrameDrawerPrivate::iconLoaderOptions()
  1020 HbIconLoader::IconLoaderOptions HbFrameDrawerPrivate::iconLoaderOptions()
  1010 {
  1021 {
  1011     HbIconLoader::IconLoaderOptions options = DEFAULT_OPTIONS;
  1022     HbIconLoader::IconLoaderOptions options = DEFAULT_OPTIONS;
  1065 {
  1076 {
  1066     HbIconLoader *loader = HbIconLoader::global();
  1077     HbIconLoader *loader = HbIconLoader::global();
  1067     if (icon) {
  1078     if (icon) {
  1068         //If a consolidated (stitched) icon was created on the themeserver, then
  1079         //If a consolidated (stitched) icon was created on the themeserver, then
  1069         //HbIconLoader::unloadIcon() is used to unload it.
  1080         //HbIconLoader::unloadIcon() is used to unload it.
  1070         loader->unLoadIcon(icon->iconImpl(), unloadedByServer);
  1081         if (loader) {
       
  1082             loader->unLoadIcon(icon->iconImpl(), unloadedByServer);
       
  1083         }
  1071         icon->dispose();
  1084         icon->dispose();
  1072         icon = 0;
  1085         icon = 0;
  1073     }
  1086     }
  1074 
  1087 
  1075     // get a vector of QVector<HbIconImpl*> from QVector<HbMaskableIconImpl*> for unloading.
  1088     // get a vector of QVector<HbIconImpl*> from QVector<HbMaskableIconImpl*> for unloading.
  1093     }
  1106     }
  1094     fallbackIconList.clear();  // vector of HbIconImpl*
  1107     fallbackIconList.clear();  // vector of HbIconImpl*
  1095     fallbackMaskableIconList.clear(); // vector of HbMaskableIconImpl*
  1108     fallbackMaskableIconList.clear(); // vector of HbMaskableIconImpl*
  1096 }
  1109 }
  1097 
  1110 
       
  1111 // This is called from HbIconLoader when building for tools.
       
  1112 // It is not in use in normal builds.
  1098 void HbFrameDrawerPrivate::themeChange(const QStringList &updatedFiles)
  1113 void HbFrameDrawerPrivate::themeChange(const QStringList &updatedFiles)
  1099 {
  1114 {
  1100     bool unloadIcons = false;
  1115     bool unloadIcons = false;
  1101     if (updatedFiles.count() == 0 || (icon && updatedFiles.contains(icon->iconFileName()))) {
  1116     if (updatedFiles.count() == 0 || (icon && updatedFiles.contains(icon->iconFileName()))) {
  1102         unloadIcons = true;
  1117         unloadIcons = true;
  1343 */
  1358 */
  1344 void HbFrameDrawer::paint(QPainter *painter, const QRectF &rect) const
  1359 void HbFrameDrawer::paint(QPainter *painter, const QRectF &rect) const
  1345 {
  1360 {
  1346     const_cast<HbFrameDrawer *>(this)->setRect(rect);
  1361     const_cast<HbFrameDrawer *>(this)->setRect(rect);
  1347 
  1362 
  1348     if (d->frameGraphicsName.isEmpty() || d->type == HbFrameDrawer::Undefined || d->rect.isEmpty()) {
  1363     HbIconLoader *loader = HbIconLoader::global();
       
  1364     if (d->frameGraphicsName.isEmpty() || d->type == HbFrameDrawer::Undefined || d->rect.isEmpty() || !loader) {
  1349         return;
  1365         return;
  1350     }
  1366     }
  1351 
  1367 
  1352     // Lazy graphics rasterizing is used.
  1368     // Lazy graphics rasterizing is used.
  1353     // Rasterize the frame parts now if that has not been done yet.
  1369     // Rasterize the frame parts now if that has not been done yet.
  1356     }
  1372     }
  1357 
  1373 
  1358     // update the rendering mode
  1374     // update the rendering mode
  1359     QPaintEngine *paintEngine = painter->paintEngine();
  1375     QPaintEngine *paintEngine = painter->paintEngine();
  1360     if (paintEngine) {
  1376     if (paintEngine) {
  1361         HbIconLoader::global()->updateRenderingMode(paintEngine->type());
  1377         loader->updateRenderingMode(paintEngine->type());
  1362     }
  1378     }
  1363     d->prepareFrameIcon();
  1379     d->prepareFrameIcon();
  1364     d->prevRect = rect.toRect();
  1380     d->prevRect = rect.toRect();
  1365     // Paint the frame
  1381     // Paint the frame
  1366     d->paint(painter);
  1382     d->paint(painter);
  1596     return QSize(0, 0);
  1612     return QSize(0, 0);
  1597 }
  1613 }
  1598 
  1614 
  1599 /*!
  1615 /*!
  1600 * This function should be called when the theme changes. This clears the used frame
  1616 * This function should be called when the theme changes. This clears the used frame
  1601 * graphic.
  1617 * graphics. This is typically handled by HbFrameItem so there is no need to call this function
       
  1618 * manually when using the framedrawer with a HbFrameItem.
  1602 */
  1619 */
  1603 void HbFrameDrawer::themeChanged()
  1620 void HbFrameDrawer::themeChanged()
  1604 {
  1621 {
  1605 #ifndef HB_TOOL_INTERFACE
  1622 #ifndef HB_TOOL_INTERFACE
  1606     // This needs to be disabled to prevent full theme updates when using partial updates with tools.
  1623     // This needs to be disabled to prevent full theme updates when using partial updates with tools.