summaryrefslogtreecommitdiffstats
path: root/src/gui/effects
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar@trolltech.com>2009-10-26 09:39:38 (GMT)
committerGunnar Sletta <gunnar@trolltech.com>2009-10-27 07:50:27 (GMT)
commitc39fac87d62ef15867dc5571d03530d7e7240aa7 (patch)
treee947eb70c239619cf20db288300f3b0dd4423d92 /src/gui/effects
parentf6480ca465af9617956752e60d9be3a19b710e0f (diff)
downloadQt-c39fac87d62ef15867dc5571d03530d7e7240aa7.zip
Qt-c39fac87d62ef15867dc5571d03530d7e7240aa7.tar.gz
Qt-c39fac87d62ef15867dc5571d03530d7e7240aa7.tar.bz2
Options on how to get a pixmap from an effect source
Usable for future optimizations. Reviewed-by: Samuel
Diffstat (limited to 'src/gui/effects')
-rw-r--r--src/gui/effects/qgraphicseffect.cpp22
-rw-r--r--src/gui/effects/qgraphicseffect.h10
-rw-r--r--src/gui/effects/qgraphicseffect_p.h3
3 files changed, 28 insertions, 7 deletions
diff --git a/src/gui/effects/qgraphicseffect.cpp b/src/gui/effects/qgraphicseffect.cpp
index f20480b..647fd1b 100644
--- a/src/gui/effects/qgraphicseffect.cpp
+++ b/src/gui/effects/qgraphicseffect.cpp
@@ -97,6 +97,7 @@
*/
#include "qgraphicseffect_p.h"
+#include <QtGui/qgraphicsitem.h>
#include <QtGui/qimage.h>
#include <QtGui/qpainter.h>
@@ -248,16 +249,22 @@ bool QGraphicsEffectSource::isPixmap() const
\sa QGraphicsEffect::draw(), boundingRect(), deviceRect()
*/
-QPixmap QGraphicsEffectSource::pixmap(Qt::CoordinateSystem system, QPoint *offset) const
+QPixmap QGraphicsEffectSource::pixmap(Qt::CoordinateSystem system, QPoint *offset, PixmapPadMode mode) const
{
Q_D(const QGraphicsEffectSource);
+ // Shortcut, no cache for childless pixmap items...
+ const QGraphicsItem *item = graphicsItem();
+ if (system == Qt::LogicalCoordinates && mode == NoExpandPadMode && item && isPixmap()) {
+ return ((QGraphicsPixmapItem *) item)->pixmap();
+ }
+
QPixmap pm;
if (d->m_cachedSystem == system)
QPixmapCache::find(d->m_cacheKey, &pm);
if (pm.isNull()) {
- pm = d->pixmap(system, &d->m_cachedOffset);
+ pm = d->pixmap(system, &d->m_cachedOffset, mode);
d->m_cachedSystem = system;
d->invalidateCache();
@@ -565,7 +572,8 @@ void QGraphicsColorizeEffect::draw(QPainter *painter, QGraphicsEffectSource *sou
QPoint offset;
if (source->isPixmap()) {
// No point in drawing in device coordinates (pixmap will be scaled anyways).
- const QPixmap pixmap = source->pixmap(Qt::LogicalCoordinates, &offset);
+ const QPixmap pixmap = source->pixmap(Qt::LogicalCoordinates, &offset,
+ QGraphicsEffectSource::NoExpandPadMode);
d->filter->draw(painter, offset, pixmap);
return;
}
@@ -776,6 +784,8 @@ void QGraphicsDropShadowEffect::setOffset(const QPointF &offset)
By default, the horizontal shadow offset is 8 pixels.
+
+
\sa yOffset(), offset()
*/
@@ -1029,7 +1039,8 @@ void QGraphicsOpacityEffect::draw(QPainter *painter, QGraphicsEffectSource *sour
if (source->isPixmap()) {
// No point in drawing in device coordinates (pixmap will be scaled anyways).
if (!d->hasOpacityMask) {
- const QPixmap pixmap = source->pixmap(Qt::LogicalCoordinates, &offset);
+ const QPixmap pixmap = source->pixmap(Qt::LogicalCoordinates, &offset,
+ QGraphicsEffectSource::NoExpandPadMode);
painter->drawPixmap(offset, pixmap);
} else {
QRect srcBrect = source->boundingRect().toAlignedRect();
@@ -1050,7 +1061,8 @@ void QGraphicsOpacityEffect::draw(QPainter *painter, QGraphicsEffectSource *sour
} else {
// Draw pixmap in device coordinates to avoid pixmap scaling;
if (!d->hasOpacityMask) {
- const QPixmap pixmap = source->pixmap(Qt::DeviceCoordinates, &offset);
+ const QPixmap pixmap = source->pixmap(Qt::DeviceCoordinates, &offset,
+ QGraphicsEffectSource::NoExpandPadMode);
painter->setWorldTransform(QTransform());
painter->drawPixmap(offset, pixmap);
} else {
diff --git a/src/gui/effects/qgraphicseffect.h b/src/gui/effects/qgraphicseffect.h
index 019e808..abf03b3 100644
--- a/src/gui/effects/qgraphicseffect.h
+++ b/src/gui/effects/qgraphicseffect.h
@@ -64,6 +64,12 @@ class Q_GUI_EXPORT QGraphicsEffectSource : public QObject
{
Q_OBJECT
public:
+ enum PixmapPadMode {
+ NoExpandPadMode,
+ ExpandToTransparentBorderPadMode,
+ ExpandToEffectRectPadMode
+ };
+
~QGraphicsEffectSource();
const QGraphicsItem *graphicsItem() const;
const QWidget *widget() const;
@@ -75,7 +81,9 @@ public:
QRectF boundingRect(Qt::CoordinateSystem coordinateSystem = Qt::LogicalCoordinates) const;
QRect deviceRect() const;
- QPixmap pixmap(Qt::CoordinateSystem system = Qt::LogicalCoordinates, QPoint *offset = 0) const;
+ QPixmap pixmap(Qt::CoordinateSystem system = Qt::LogicalCoordinates,
+ QPoint *offset = 0,
+ PixmapPadMode mode = ExpandToEffectRectPadMode) const;
protected:
QGraphicsEffectSource(QGraphicsEffectSourcePrivate &dd, QObject *parent = 0);
diff --git a/src/gui/effects/qgraphicseffect_p.h b/src/gui/effects/qgraphicseffect_p.h
index 24d8696..dff84a1 100644
--- a/src/gui/effects/qgraphicseffect_p.h
+++ b/src/gui/effects/qgraphicseffect_p.h
@@ -77,7 +77,8 @@ public:
virtual void draw(QPainter *p) = 0;
virtual void update() = 0;
virtual bool isPixmap() const = 0;
- virtual QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset = 0) const = 0;
+ virtual QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset = 0,
+ QGraphicsEffectSource::PixmapPadMode mode = QGraphicsEffectSource::ExpandToTransparentBorderPadMode) const = 0;
virtual void effectBoundingRectChanged() = 0;
void invalidateCache() const { QPixmapCache::remove(m_cacheKey); }