diff options
author | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-07-24 02:05:42 (GMT) |
---|---|---|
committer | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-07-24 02:05:42 (GMT) |
commit | 940b5bf333d6022fe5d3a037d6b1d74c6b9fe36e (patch) | |
tree | fe9efacdf7f836c596fa4231769b092650746f0b /src/gui/graphicsview/qgraphicsitem.cpp | |
parent | 3b974f5b45429675630040224a3ce34b762cc360 (diff) | |
parent | e646d08593dc18cad4e59176c2fe8c10fa5b9497 (diff) | |
download | Qt-940b5bf333d6022fe5d3a037d6b1d74c6b9fe36e.zip Qt-940b5bf333d6022fe5d3a037d6b1d74c6b9fe36e.tar.gz Qt-940b5bf333d6022fe5d3a037d6b1d74c6b9fe36e.tar.bz2 |
Merge branch 'kinetic-graphicseffect' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-graphicseffect
Diffstat (limited to 'src/gui/graphicsview/qgraphicsitem.cpp')
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.cpp | 100 |
1 files changed, 38 insertions, 62 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index c395e21..7533fa4 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -552,7 +552,6 @@ #ifndef QT_NO_GRAPHICSVIEW -#include "qgraphicseffect.h" #include "qgraphicsscene.h" #include "qgraphicsscene_p.h" #include "qgraphicssceneevent.h" @@ -1180,6 +1179,7 @@ QGraphicsItem::~QGraphicsItem() else d_ptr->setParentItemHelper(0); + delete d_ptr->graphicsEffect; delete d_ptr->transformData; delete d_ptr; @@ -2190,39 +2190,53 @@ void QGraphicsItem::setOpacity(qreal opacity) } /*! + Returns a pointer to this item's effect if it has one; otherwise 0. + \since 4.6 - Returns this item's \e effect if it has one; otherwise, - returns 0. */ -QGraphicsEffect *QGraphicsItem::effect() const +QGraphicsEffect *QGraphicsItem::graphicsEffect() const { - QGraphicsEffect *fx = 0; - if (d_ptr->hasEffect) - fx = d_ptr->extra(QGraphicsItemPrivate::ExtraEffect).value<QGraphicsEffect*>(); - - return fx; + return d_ptr->graphicsEffect; } /*! + Sets \a effect as the item's effect. If there already is an effect installed + on this item, QGraphicsItem won't let you install another. You must first + delete the existing effect (returned by graphicsEffect()) before you can call + setGraphicsEffect() with the new effect. + + If \a effect is the installed on a different item, setGraphicsEffect() will remove + the effect from the item and install it on this item. + + \note This function will apply the effect on itself and all its children. + \since 4.6 - Sets \e effect as the item's effect. It will replace the previous effect - the item might have. */ -void QGraphicsItem::setEffect(QGraphicsEffect *effect) +void QGraphicsItem::setGraphicsEffect(QGraphicsEffect *effect) { - if (effect) { - d_ptr->hasEffect = true; - d_ptr->setExtra(QGraphicsItemPrivate::ExtraEffect, QVariant::fromValue(effect)); + if (d_ptr->graphicsEffect == effect) + return; + + if (d_ptr->graphicsEffect && effect) { + qWarning("QGraphicsItem::setGraphicsEffect: Attempting to set QGraphicsEffect " + "%p on %p, which already has an effect installed", effect, this); + return; + } + + if (!effect) { + // Unset current effect. + QGraphicsEffectPrivate *oldEffectPrivate = d_ptr->graphicsEffect->d_func(); + d_ptr->graphicsEffect = 0; + if (oldEffectPrivate) + oldEffectPrivate->setGraphicsEffectSource(0); // deletes the current source. } else { - d_ptr->hasEffect = false; - d_ptr->unsetExtra(QGraphicsItemPrivate::ExtraEffect); - void *ptr = d_ptr->extra(QGraphicsItemPrivate::ExtraEffectPixmap).value<void*>(); - QPixmap *pixmap = reinterpret_cast<QPixmap*>(ptr); - delete pixmap; - d_ptr->unsetExtra(QGraphicsItemPrivate::ExtraEffectPixmap); + // Set new effect. + effect->d_func()->setGraphicsEffectSource(new QGraphicsItemEffectSource(this)); + d_ptr->graphicsEffect = effect; } - update(); + if (d_ptr->scene) + d_ptr->scene->d_func()->markDirty(this); } /*! @@ -2236,10 +2250,8 @@ void QGraphicsItem::setEffect(QGraphicsEffect *effect) */ QRectF QGraphicsItem::effectiveBoundingRect() const { - QGraphicsEffect *fx = effect(); - if (fx) - return fx->boundingRectFor(this); - + if (d_ptr->graphicsEffect) + return d_ptr->graphicsEffect->boundingRect(); return boundingRect(); } @@ -2273,42 +2285,6 @@ QRectF QGraphicsItem::sceneEffectiveBoundingRect() const } /*! - \internal - - Used by QGraphicsScene. -*/ -QPixmap *QGraphicsItem::effectPixmap() -{ - if (!d_ptr->hasEffect) - return 0; - - // the exact size of the pixmap is not a big deal - // as long as it contains the effective bounding rect - // TODO: use smart resizing etc - // TODO: store per device and do everything in device coordinate? - // TODO: use layer - QRect rect = effectiveBoundingRect().toAlignedRect(); - - void *ptr = d_ptr->extra(QGraphicsItemPrivate::ExtraEffectPixmap).value<void*>(); - QPixmap *pixmap = reinterpret_cast<QPixmap*>(ptr); - bool avail = true; - if (!pixmap) - avail = false; - if (avail && pixmap->size() != rect.size()) - avail = false; - - if (!avail) { - delete pixmap; - pixmap = new QPixmap(rect.size()); - pixmap->fill(Qt::transparent); - ptr = reinterpret_cast<void*>(pixmap); - d_ptr->setExtra(QGraphicsItemPrivate::ExtraEffectPixmap, QVariant::fromValue(ptr)); - } - - return pixmap; -} - -/*! Returns true if this item can accept drag and drop events; otherwise, returns false. By default, items do not accept drag and drop events; items are transparent to drag and drop. |