src/hbcore/image/hbvgimageiconrenderer.cpp
changeset 5 627c4a0fd0e7
parent 2 06ff229162e9
child 7 923ff622b8b9
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    27 #include "hbeglstate_p.h"
    27 #include "hbeglstate_p.h"
    28 #include "hbiconimpl_p.h"
    28 #include "hbiconimpl_p.h"
    29 
    29 
    30 #include <QtCore/qvarlengtharray.h>
    30 #include <QtCore/qvarlengtharray.h>
    31 
    31 
    32 HbVgImageIconRenderer::HbVgImageIconRenderer(VGImage img, const QSize & size, HbIconImpl * impl)
    32 HbVgImageIconRenderer::HbVgImageIconRenderer(VGImage img, const QSize &size, HbIconImpl *impl)
    33         : vgImage(img),
    33     : vgImage(img),
    34         iconMode(QIcon::Normal),
    34       iconMode(QIcon::Normal),
    35         specialCaseApplied(false),
    35       specialCaseApplied(false),
    36         rendersize(size),
    36       rendersize(size),
    37         addedToStates(false),
    37       addedToStates(false),
    38         opacityPaint(VG_INVALID_HANDLE),
    38       opacityPaint(VG_INVALID_HANDLE),
    39         lastOpacity(1.0),
    39       lastOpacity(1.0),
    40         iconImpl(impl)
    40       iconImpl(impl)
    41 {
    41 {
    42     eglStates = HbEglStates::global();
    42     eglStates = HbEglStates::global();
    43     eglStates->ref();
    43     eglStates->ref();
    44 }
    44 }
    45 
    45 
    89         }
    89         }
    90         specialCaseApplied = true;
    90         specialCaseApplied = true;
    91     }
    91     }
    92 }
    92 }
    93 
    93 
    94 bool HbVgImageIconRenderer::draw(QPainter * painter, const QPointF & topLeft, const QPainterPath & clipPath)
    94 bool HbVgImageIconRenderer::draw(QPainter *painter, const QPointF &topLeft, const QPainterPath &clipPath)
    95 {
    95 {
    96     if ((iconColor.isValid()) || (iconMode != QIcon::Normal)) {
    96     if ((iconColor.isValid()) || (iconMode != QIcon::Normal)) {
    97         applyIconProperties();
    97         applyIconProperties();
    98     }
    98     }
    99 
    99 
   105     if (!addedToStates && vgImage != VG_INVALID_HANDLE) {
   105     if (!addedToStates && vgImage != VG_INVALID_HANDLE) {
   106         eglStates->addVGImage(&vgImage);
   106         eglStates->addVGImage(&vgImage);
   107         addedToStates = true;
   107         addedToStates = true;
   108     }
   108     }
   109 
   109 
   110     if (vgImage != VG_INVALID_HANDLE) {    
   110     if (vgImage != VG_INVALID_HANDLE) {
   111         QPainterPath oldPath;
   111         QPainterPath oldPath;
   112         bool clipped = painter->hasClipping();
   112         bool wasClipped = painter->hasClipping();
   113         
   113 
   114         if (!clipPath.isEmpty()) {
   114         if (!clipPath.isEmpty()) {
   115             if (!clipped) {
   115             if (!wasClipped) {
   116                 painter->setClipping(true);
   116                 painter->setClipping(true);
   117             }
   117             }
   118             
   118 
   119             QPainterPath intersect(clipPath);
   119             QPainterPath intersect(clipPath);
   120             if (clipped) {
   120             oldPath = painter->clipPath();
   121                 oldPath = painter->clipPath();
   121             if (wasClipped) {
   122                 intersect =  oldPath.intersected(clipPath);
   122                 intersect =  oldPath.intersected(clipPath);
   123                 if (intersect.isEmpty()) {
   123                 if (intersect.isEmpty()) {
   124                     return true;
   124                     return true;
   125                 }
   125                 }
   126             }
   126             }
   127         
   127 
   128             painter->setClipPath(intersect, Qt::ReplaceClip);
   128             painter->setClipPath(intersect, Qt::ReplaceClip);
   129             painter->beginNativePainting();
   129             painter->beginNativePainting();
   130         }
   130         }
   131         
   131 
   132         VGint imageMode      = vgGeti(VG_IMAGE_MODE);
   132         VGint imageMode      = vgGeti(VG_IMAGE_MODE);
   133         VGint matrixMode     = vgGeti(VG_MATRIX_MODE);
   133         VGint matrixMode     = vgGeti(VG_MATRIX_MODE);
   134         VGPaint oldFillPaint = VG_INVALID_HANDLE;
   134         VGPaint oldFillPaint = VG_INVALID_HANDLE;
   135         VGPaint oldStrkPaint = VG_INVALID_HANDLE;
   135         VGPaint oldStrkPaint = VG_INVALID_HANDLE;
   136         VGint   blendMode    = 0;
   136         VGint   blendMode    = 0;
   137         
   137 
   138         updatePainterTransformation(painter, topLeft);
   138         updatePainterTransformation(painter, topLeft);
   139         
   139 
   140         qreal opacity = painter->opacity();
   140         qreal opacity = painter->opacity();
   141 
   141 
   142         if (opacity != lastOpacity || iconMode == QIcon::Selected) {
   142         if (opacity != lastOpacity || iconMode == QIcon::Selected) {
   143             lastOpacity = opacity;
   143             lastOpacity = opacity;
   144             if (opacityPaint == VG_INVALID_HANDLE) {
   144             if (opacityPaint == VG_INVALID_HANDLE) {
   191             vgSeti(VG_BLEND_MODE, blendMode);
   191             vgSeti(VG_BLEND_MODE, blendMode);
   192         }
   192         }
   193 
   193 
   194         if (!clipPath.isEmpty()) {
   194         if (!clipPath.isEmpty()) {
   195             painter->endNativePainting();
   195             painter->endNativePainting();
   196             if (!clipped) {
   196             painter->setClipPath(oldPath);
   197                 painter->setClipPath(oldPath, Qt::NoClip);
   197             painter->setClipping(wasClipped);
   198             } else {
       
   199                 painter->setClipPath(oldPath);
       
   200             }
       
   201             painter->setClipping(clipped);
       
   202         }
   198         }
   203         return true;
   199         return true;
   204     }
   200     }
   205 
   201 
   206     return false;
   202     return false;
   207 }
   203 }
   208 
   204 
   209 
   205 
   210 void HbVgImageIconRenderer::updatePainterTransformation(QPainter * painter, const QPointF & pos)
   206 void HbVgImageIconRenderer::updatePainterTransformation(QPainter *painter, const QPointF &pos)
   211 {
   207 {
   212     VGfloat devh = painter->device()->height() - 1;
   208     VGfloat devh = painter->device()->height() - 1;
   213     QTransform viewport(1.0f, 0.0f, 0.0f,
   209     QTransform viewport(1.0f, 0.0f, 0.0f,
   214                         0.0f, -1.0f, 0.0f,
   210                         0.0f, -1.0f, 0.0f,
   215                         0.5f, devh + 0.5f, 1.0f);
   211                         0.5f, devh + 0.5f, 1.0f);