src/hbcore/ovgeffects/hbvgeffect.cpp
changeset 5 627c4a0fd0e7
parent 0 16d8024aca5e
child 7 923ff622b8b9
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    38  * \class HbVgEffect
    38  * \class HbVgEffect
    39  *
    39  *
    40  * \brief Abstract base class for OpenVG effects.
    40  * \brief Abstract base class for OpenVG effects.
    41  *
    41  *
    42  * \internal
    42  * \internal
    43  * 
    43  *
    44  * Brief guide for creating new effects:
    44  * Brief guide for creating new effects:
    45  * <ul>
    45  * <ul>
    46  *
    46  *
    47  *    <li>Derive from HbVgEffect.
    47  *    <li>Derive from HbVgEffect.
    48  *
    48  *
   120  * the underlying VGImage handle.  Typically used with dstPixmap and
   120  * the underlying VGImage handle.  Typically used with dstPixmap and
   121  * tmpPixmap.
   121  * tmpPixmap.
   122  *
   122  *
   123  * \internal
   123  * \internal
   124  */
   124  */
   125 VGImage HbVgEffectPrivate::ensurePixmap(QPixmap *pixmap, const QSize& size)
   125 VGImage HbVgEffectPrivate::ensurePixmap(QPixmap *pixmap, const QSize &size)
   126 {
   126 {
   127     if (pixmap->size() != size)
   127     if (pixmap->size() != size) {
   128         *pixmap = QPixmap(size);
   128         *pixmap = QPixmap(size);
       
   129     }
   129     return qPixmapToVGImage(*pixmap);
   130     return qPixmapToVGImage(*pixmap);
   130 }
   131 }
   131 #endif
   132 #endif
   132 
   133 
   133 /*!
   134 /*!
   163         const QGraphicsItem *srcItem = q->sourceItemForRoot();
   164         const QGraphicsItem *srcItem = q->sourceItemForRoot();
   164         if (srcItem) {
   165         if (srcItem) {
   165             QGraphicsScene *scene = srcItem->scene();
   166             QGraphicsScene *scene = srcItem->scene();
   166             if (scene) {
   167             if (scene) {
   167                 QList<QGraphicsView *> views = scene->views();
   168                 QList<QGraphicsView *> views = scene->views();
   168                 foreach (QGraphicsView *view, views) {
   169                 foreach(QGraphicsView * view, views) {
   169                     mainWindow = qobject_cast<HbMainWindow *>(view);
   170                     mainWindow = qobject_cast<HbMainWindow *>(view);
   170                     if (mainWindow)
   171                     if (mainWindow) {
   171                         break;
   172                         break;
       
   173                     }
   172                 }
   174                 }
   173             }
   175             }
   174         }
   176         }
   175     }
   177     }
   176     return mainWindow ? HbMainWindowPrivate::d_ptr(mainWindow)->rotation() : 0;
   178     return mainWindow ? HbMainWindowPrivate::d_ptr(mainWindow)->rotation() : 0;
   188         lastRotationTransformAngle = rotation;
   190         lastRotationTransformAngle = rotation;
   189         lastRotationTransform = QTransform().rotate(rotation);
   191         lastRotationTransform = QTransform().rotate(rotation);
   190     }
   192     }
   191     return lastRotationTransform;
   193     return lastRotationTransform;
   192 }
   194 }
   193     
   195 
   194 /*!
   196 /*!
   195  * Maps the given translation offset to an offset that is based on the current
   197  * Maps the given translation offset to an offset that is based on the current
   196  * rotation of the graphics view. Effects are drawing directly, in device
   198  * rotation of the graphics view. Effects are drawing directly, in device
   197  * coordinates, however they must take into account the rotation of the graphics
   199  * coordinates, however they must take into account the rotation of the graphics
   198  * view too. Therefore any translation they use must be mapped using this
   200  * view too. Therefore any translation they use must be mapped using this
   347  * \sa opacity()
   349  * \sa opacity()
   348  */
   350  */
   349 void HbVgEffect::setOpacity(qreal opacity)
   351 void HbVgEffect::setOpacity(qreal opacity)
   350 {
   352 {
   351     Q_D(HbVgEffect);
   353     Q_D(HbVgEffect);
   352     if (d->opacity == opacity)
   354     if (d->opacity == opacity) {
   353         return;
   355         return;
       
   356     }
   354     d->opacity = opacity;
   357     d->opacity = opacity;
   355     updateEffect();
   358     updateEffect();
   356     emit opacityChanged(opacity);
   359     emit opacityChanged(opacity);
   357 }
   360 }
   358 
   361 
   365  */
   368  */
   366 void HbVgEffect::draw(QPainter *painter)
   369 void HbVgEffect::draw(QPainter *painter)
   367 {
   370 {
   368     // Just draw the source without effects if the painter's paint engine
   371     // Just draw the source without effects if the painter's paint engine
   369     // is not using OpenVG.
   372     // is not using OpenVG.
   370     if (painter->paintEngine()->type() != QPaintEngine::OpenVG) {
   373     QPaintEngine *paintEngine = painter->paintEngine();
       
   374     if (!paintEngine || paintEngine->type() != QPaintEngine::OpenVG) {
   371         drawSource(painter);
   375         drawSource(painter);
   372         return;
   376         return;
   373     }
   377     }
   374 
   378 
   375 #ifdef HB_EFFECTS_OPENVG
   379 #ifdef HB_EFFECTS_OPENVG
   460  * \sa caching()
   464  * \sa caching()
   461  */
   465  */
   462 void HbVgEffect::setCaching(bool caching)
   466 void HbVgEffect::setCaching(bool caching)
   463 {
   467 {
   464     Q_D(HbVgEffect);
   468     Q_D(HbVgEffect);
   465     if (d->caching == caching)
   469     if (d->caching == caching) {
   466         return;
   470         return;
       
   471     }
   467     d->caching = caching;
   472     d->caching = caching;
   468     emit cachingChanged(caching);
   473     emit cachingChanged(caching);
   469 }
   474 }
   470 
   475 
   471 /*!
   476 /*!
   490             // too. The size check is important because the effects will
   495             // too. The size check is important because the effects will
   491             // typically render their source using device coordinates which
   496             // typically render their source using device coordinates which
   492             // causes a clipping to the device viewport, therefore the cached
   497             // causes a clipping to the device viewport, therefore the cached
   493             // pixmap for an item that was/is clipped should not be used.
   498             // pixmap for an item that was/is clipped should not be used.
   494             if (QPixmapCache::find(key, &cachedPm)
   499             if (QPixmapCache::find(key, &cachedPm)
   495                 && (size.isNull() || cachedPm.size() == size))
   500                     && (size.isNull() || cachedPm.size() == size)) {
   496             {
       
   497 #ifdef HBVG_TRACES
   501 #ifdef HBVG_TRACES
   498                 qDebug("HbVgEffect [%x]: cache hit", (int) this);
   502                 qDebug("HbVgEffect [%x]: cache hit", (int) this);
   499 #endif
   503 #endif
   500                 return cachedPm;
   504                 return cachedPm;
   501             }
   505             }
   532  * (not related to effects) are left intact in the global pixmap cache.
   536  * (not related to effects) are left intact in the global pixmap cache.
   533  */
   537  */
   534 void HbVgEffect::releaseCachedResources()
   538 void HbVgEffect::releaseCachedResources()
   535 {
   539 {
   536     QSet<QString> *keys = cacheKeys();
   540     QSet<QString> *keys = cacheKeys();
   537     foreach (const QString &key, *keys) {
   541     foreach(const QString & key, *keys) {
   538         QPixmapCache::remove(key);
   542         QPixmapCache::remove(key);
   539     }
   543     }
   540     keys->clear();
   544     keys->clear();
   541 }
   545 }
   542 
   546