src/hbcore/image/hbframedrawer.cpp
changeset 1 f7ac710697a9
parent 0 16d8024aca5e
child 2 06ff229162e9
equal deleted inserted replaced
0:16d8024aca5e 1:f7ac710697a9
   163     flags(0),
   163     flags(0),
   164     layoutDirection(Qt::LeftToRight),
   164     layoutDirection(Qt::LeftToRight),
   165     graphicsItem(0),
   165     graphicsItem(0),
   166     color(),
   166     color(),
   167     icon(0),
   167     icon(0),
   168     maskChanged(false)
   168     maskChanged(false),
       
   169     clipPath(QPainterPath())
   169 {
   170 {
   170     borderWidths[0]=0.0;
   171     borderWidths[0]=0.0;
   171     borderWidths[1]=0.0;
   172     borderWidths[1]=0.0;
   172     borderWidths[2]=0.0;
   173     borderWidths[2]=0.0;
   173     borderWidths[3]=0.0;
   174     borderWidths[3]=0.0;
       
   175     //Register the HbFrameDrawerPrivate Instance to HbIconLoader
       
   176     HbIconLoader::global()->storeFrameDrawerInfo(this);
   174 }
   177 }
   175 
   178 
   176 /*!
   179 /*!
   177 \internal
   180 \internal
   178 */
   181 */
   187     flags( 0 ),
   190     flags( 0 ),
   188     layoutDirection(Qt::LeftToRight),
   191     layoutDirection(Qt::LeftToRight),
   189     graphicsItem(0),
   192     graphicsItem(0),
   190     color(),
   193     color(),
   191     icon(0),
   194     icon(0),
   192     maskChanged(false)
   195     maskChanged(false),
       
   196     clipPath(QPainterPath())
   193 {
   197 {
   194     borderWidths[0]=0.0;
   198     borderWidths[0]=0.0;
   195     borderWidths[1]=0.0;
   199     borderWidths[1]=0.0;
   196     borderWidths[2]=0.0;
   200     borderWidths[2]=0.0;
   197     borderWidths[3]=0.0;
   201     borderWidths[3]=0.0;
   199     // Remove possible file extension
   203     // Remove possible file extension
   200     int index = this->frameGraphicsName.lastIndexOf(QChar('.'));
   204     int index = this->frameGraphicsName.lastIndexOf(QChar('.'));
   201     if (index>0) {
   205     if (index>0) {
   202         this->frameGraphicsName.resize(index);
   206         this->frameGraphicsName.resize(index);
   203     }
   207     }
       
   208     //Register the HbFrameDrawerPrivate Instance to HbIconLoader
       
   209     HbIconLoader::global()->storeFrameDrawerInfo(this);
   204 }
   210 }
   205 
   211 
   206 /*!
   212 /*!
   207 \internal
   213 \internal
   208 */
   214 */
   218     flags( other.flags ),
   224     flags( other.flags ),
   219     layoutDirection( other.layoutDirection ),
   225     layoutDirection( other.layoutDirection ),
   220     graphicsItem( other.graphicsItem ),
   226     graphicsItem( other.graphicsItem ),
   221     color(other.color),
   227     color(other.color),
   222     icon(0),
   228     icon(0),
   223     maskChanged(false)
   229     maskChanged(false),
       
   230     clipPath(QPainterPath())
   224 {
   231 {
   225     borderWidths[0]=other.borderWidths[0];
   232     borderWidths[0]=other.borderWidths[0];
   226     borderWidths[1]=other.borderWidths[1];
   233     borderWidths[1]=other.borderWidths[1];
   227     borderWidths[2]=other.borderWidths[2];
   234     borderWidths[2]=other.borderWidths[2];
   228     borderWidths[3]=other.borderWidths[3];
   235     borderWidths[3]=other.borderWidths[3];
       
   236     //Register the HbFrameDrawerPrivate Instance to HbIconLoader
       
   237     HbIconLoader::global()->storeFrameDrawerInfo(this);
   229 }
   238 }
   230 
   239 
   231 /*!
   240 /*!
   232 \internal
   241 \internal
   233 */
   242 */
   234 HbFrameDrawerPrivate::~HbFrameDrawerPrivate()
   243 HbFrameDrawerPrivate::~HbFrameDrawerPrivate()
   235 {
   244 {
   236     unLoadIcon();
   245     unLoadIcon();
       
   246     //Unregister the HbFrameDrawerPrivate Instance to HbIconLoader
       
   247     HbIconLoader::global()->removeFrameDrawerInfo(this);
   237 }
   248 }
   238 
   249 
   239 /*!
   250 /*!
   240 \internal
   251 \internal
   241 */
   252 */
   425 
   436 
   426         if (!mask.isNull() && maskChanged) {
   437         if (!mask.isNull() && maskChanged) {
   427             icon->setMask(mask);
   438             icon->setMask(mask);
   428         } 
   439         } 
   429         //paint the stitched icon
   440         //paint the stitched icon
   430         icon->paint(painter, centeredRect, Qt::AlignHCenter);
   441         icon->paint(painter, centeredRect, Qt::AlignHCenter, clipPath);
       
   442         if ( icon->isCreatedOnServer() ) {
       
   443             iconType = icon->iconImpl()->iconData().type;
       
   444         }
   431 
   445 
   432         #ifdef HB_FRAME_DRAWER_TRACES
   446         #ifdef HB_FRAME_DRAWER_TRACES
   433         qDebug() << "FRAMENAME: " << frameGraphicsName << "Drawn at: "
   447         qDebug() << "FRAMENAME: " << frameGraphicsName << "Drawn at: "
   434         << centeredRect.topLeft().x() << "," << centeredRect.topLeft().y() << " | "
   448         << centeredRect.topLeft().x() << "," << centeredRect.topLeft().y() << " | "
   435         << centeredRect.bottomRight().x() << "," << centeredRect.bottomRight().y();
   449         << centeredRect.bottomRight().x() << "," << centeredRect.bottomRight().y();
   450                 if ((!mask.isNull()) && maskChanged) {
   464                 if ((!mask.isNull()) && maskChanged) {
   451                     QBitmap pieceMask ;
   465                     QBitmap pieceMask ;
   452                     QRect maskRect(position.x(), position.y(), multiPartSizeData.targets[i].width(), multiPartSizeData.targets[i].height());
   466                     QRect maskRect(position.x(), position.y(), multiPartSizeData.targets[i].width(), multiPartSizeData.targets[i].height());
   453                     pieceMask = mask.copy(maskRect);
   467                     pieceMask = mask.copy(maskRect);
   454                     fallbackMaskableIconList[i]->setMask(pieceMask);
   468                     fallbackMaskableIconList[i]->setMask(pieceMask);
   455                 } 
       
   456                 if(!multiPartSizeData.targets[i].isEmpty()) {
       
   457                     fallbackMaskableIconList[i]->paint(painter, QRect(position,multiPartSizeData.pixmapSizes[i]), Qt::AlignHCenter);
       
   458                 }
   469                 }
       
   470                 if (!multiPartSizeData.targets[i].isEmpty()) {
       
   471                     fallbackMaskableIconList[i]->paint(painter,
       
   472                             QRect(position, multiPartSizeData.pixmapSizes[i]),
       
   473                             Qt::AlignHCenter, clipPath);
       
   474                 }
       
   475             }
       
   476         }
       
   477         if ( fallbackMaskableIconList[0]->iconImpl()
       
   478              && fallbackMaskableIconList[0]->iconImpl()->isCreatedOnServer() ) {
       
   479             if ( fallbackMaskableIconList[0]->iconImpl()->iconData().type != INVALID_FORMAT ) {
       
   480                 // store the icon type
       
   481                 iconType = fallbackMaskableIconList[0]->iconImpl()->iconData().type;
   459             }
   482             }
   460         }
   483         }
   461     }
   484     }
   462     maskChanged = false;
   485     maskChanged = false;
   463 }
   486 }
   905     if ( resetFrameCount ) {
   928     if ( resetFrameCount ) {
   906         frameParts = 0;
   929         frameParts = 0;
   907     }
   930     }
   908 }
   931 }
   909 
   932 
       
   933 /*!
       
   934 *	Resets the MaskableIcon 
       
   935 */
       
   936 void HbFrameDrawerPrivate::resetMaskableIcon()
       
   937 {
       
   938 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON)    
       
   939     HbIconLoader *loader = HbIconLoader::global();
       
   940     if ( icon ) {  
       
   941       //consolidated icon case 
       
   942       icon->decrementRefCount();    
       
   943       if ( icon->refCount() == 0 && icon->isCreatedOnServer() ) {
       
   944           // remove the item from cache and delete the icon
       
   945           loader->removeItemInCache( icon->iconImpl() );
       
   946           icon->dispose();
       
   947       }
       
   948       icon = 0;              
       
   949     } else {            
       
   950         int count = fallbackMaskableIconList.count();
       
   951         if ( count ) {
       
   952             // for each item in fallbackMaskableIconList - decrement the reference count and
       
   953             // remove the item in cache, dispose if needed.
       
   954             foreach ( HbMaskableIconImpl* impl, fallbackMaskableIconList ) {
       
   955                    impl->decrementRefCount();
       
   956                    if ( impl->refCount() == 0 && impl->isCreatedOnServer() ) {
       
   957                        loader->removeItemInCache( impl->iconImpl() );     
       
   958                        impl->dispose();
       
   959                    } 
       
   960             }                                   
       
   961             fallbackMaskableIconList.clear(); 
       
   962         }
       
   963     }
       
   964     frameParts = 0;
       
   965 #endif
       
   966 }
       
   967 
   910 HbIconLoader::IconLoaderOptions HbFrameDrawerPrivate::iconLoaderOptions()
   968 HbIconLoader::IconLoaderOptions HbFrameDrawerPrivate::iconLoaderOptions()
   911 {
   969 {
   912     HbIconLoader::IconLoaderOptions options = DEFAULT_OPTIONS;
   970     HbIconLoader::IconLoaderOptions options = DEFAULT_OPTIONS;
   913     if (flags & HbFrameDrawerPrivate::DoNotCache) {
   971     if (flags & HbFrameDrawerPrivate::DoNotCache) {
   914         options |= HbIconLoader::DoNotCache;
   972         options |= HbIconLoader::DoNotCache;
   975 
  1033 
   976     // get a vector of QVector<HbIconImpl*> from QVector<HbMaskableIconImpl*> for unloading.
  1034     // get a vector of QVector<HbIconImpl*> from QVector<HbMaskableIconImpl*> for unloading.
   977     QVector<HbIconImpl *> fallbackIconList;
  1035     QVector<HbIconImpl *> fallbackIconList;
   978     int count = fallbackMaskableIconList.count();
  1036     int count = fallbackMaskableIconList.count();
   979     for (int i = 0; i < count ; i++) {
  1037     for (int i = 0; i < count ; i++) {
   980         if (fallbackMaskableIconList[i]) {
  1038         if ( fallbackMaskableIconList.at(i) ) {
   981             fallbackIconList.append(fallbackMaskableIconList[i]->iconImpl());
  1039             fallbackIconList.append(fallbackMaskableIconList.at(i)->iconImpl());
   982         }
  1040         }
   983     }
  1041     }
   984     count = fallbackIconList.count();
  1042     count = fallbackIconList.count();
   985     if (count > 0) {
  1043     if (count > 0) {
   986         //If a consolidated (stitched) icon-creation on themeserver fails, unload-request for all individual
  1044         //If a consolidated (stitched) icon-creation on themeserver fails, unload-request for all individual
   987         //frame-items are batched together in a single IPC, which is initiated in HbIconLoader::unLoadMultiIcon().
  1045         //frame-items are batched together in a single IPC, which is initiated in HbIconLoader::unLoadMultiIcon().
   988         loader->unLoadMultiIcon(fallbackIconList);
  1046         loader->unLoadMultiIcon(fallbackIconList);
   989         for (int i=0; i < count ; i++) {
  1047         for (int i=0; i < count ; i++) {
   990             if (fallbackMaskableIconList[i]) {
  1048             if ( fallbackMaskableIconList.at(i) ) {
   991                 fallbackMaskableIconList[i]->dispose();
  1049                 fallbackMaskableIconList.at(i)->dispose();
   992             }
  1050             }
   993         }
  1051         }
   994      }
  1052      }
   995     fallbackIconList.clear();  // vector of HbIconImpl*
  1053     fallbackIconList.clear();  // vector of HbIconImpl*
   996     fallbackMaskableIconList.clear(); // vector of HbMaskableIconImpl*
  1054     fallbackMaskableIconList.clear(); // vector of HbMaskableIconImpl*
  1378     d->mask = mask;
  1436     d->mask = mask;
  1379     d->maskChanged = true;
  1437     d->maskChanged = true;
  1380 }
  1438 }
  1381 
  1439 
  1382 /*! 
  1440 /*! 
       
  1441 * Sets the \a clipPath to be applied with the entire frame icon.
       
  1442 * 
       
  1443 */
       
  1444 void HbFrameDrawer::setClipPath(const QPainterPath &clipPath)
       
  1445 {
       
  1446     d->clipPath = clipPath;
       
  1447 }
       
  1448 
       
  1449 /*!
       
  1450 * Returns the clippath set on the frame drawer.
       
  1451 * As default, returns a empty QPainterPath.
       
  1452 * \sa setClipPath()
       
  1453 */
       
  1454 
       
  1455 QPainterPath HbFrameDrawer::clipPath() const
       
  1456 {
       
  1457     return d->clipPath;
       
  1458 }
       
  1459 
       
  1460 /*! 
  1383 * Sets the mask to be applied with the the entire frame icon.
  1461 * Sets the mask to be applied with the the entire frame icon.
  1384 * If the mask is also a frame item, use another frame drawer to draw it.
  1462 * If the mask is also a frame item, use another frame drawer to draw it.
  1385 * Mask should be of the same size as returned by frameSize().
  1463 * Mask should be of the same size as returned by frameSize().
  1386 * To unset the mask, set it to a null bitmap.
  1464 * To unset the mask, set it to a null bitmap.
  1387 *
  1465 *
  1483 void HbFrameDrawer::setGraphicsItem( QGraphicsItem *item )
  1561 void HbFrameDrawer::setGraphicsItem( QGraphicsItem *item )
  1484 {
  1562 {
  1485     d->graphicsItem = item;
  1563     d->graphicsItem = item;
  1486 }
  1564 }
  1487 
  1565 
  1488 
  1566 /*!
       
  1567 * Returns the iconType
       
  1568 */
       
  1569 HbIconFormatType HbFrameDrawerPrivate::iconFormatType() const
       
  1570 {
       
  1571     return iconType;
       
  1572 }
  1489 // End of File
  1573 // End of File