summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-07-29 00:26:35 (GMT)
committerBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-07-29 06:43:33 (GMT)
commitf0ed432d55ef6da7223ee3d58e45391e3f88be86 (patch)
treece500dfd22b412b0390f1c3bb6909142112dbaf9 /src/gui/graphicsview
parentf55576b670c69b69c5f1140661cf20cbda96853a (diff)
downloadQt-f0ed432d55ef6da7223ee3d58e45391e3f88be86.zip
Qt-f0ed432d55ef6da7223ee3d58e45391e3f88be86.tar.gz
Qt-f0ed432d55ef6da7223ee3d58e45391e3f88be86.tar.bz2
Remove drawIntoPixmap and implement all the effects with the new API.
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r--src/gui/graphicsview/qgraphicseffect.cpp159
-rw-r--r--src/gui/graphicsview/qgraphicseffect.h1
-rw-r--r--src/gui/graphicsview/qgraphicseffect_p.h3
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp32
-rw-r--r--src/gui/graphicsview/qgraphicsitem_p.h1
5 files changed, 37 insertions, 159 deletions
diff --git a/src/gui/graphicsview/qgraphicseffect.cpp b/src/gui/graphicsview/qgraphicseffect.cpp
index 1281847..26dc35c 100644
--- a/src/gui/graphicsview/qgraphicseffect.cpp
+++ b/src/gui/graphicsview/qgraphicseffect.cpp
@@ -121,9 +121,6 @@ const QStyleOption *QGraphicsEffectSource::styleOption() const
void QGraphicsEffectSource::draw(QPainter *painter)
{ d_func()->draw(painter); }
-bool QGraphicsEffectSource::drawIntoPixmap(QPixmap *pixmap, const QPoint &offset)
-{ return d_func()->drawIntoPixmap(pixmap, offset); }
-
QPixmap QGraphicsEffectSource::pixmap(bool deviceCoordinates, QPoint *offset) const
{ return d_func()->pixmap(deviceCoordinates, offset); }
@@ -177,29 +174,6 @@ QRectF QGraphicsEffect::boundingRectFor(const QRectF &rect) const
return rect;
}
-//QRectF QGraphicsEffect::sourceBoundingRect(bool deviceCoordinates) const
-//{
-// Q_D(const QGraphicsEffect);
-// if (d->source)
-// return d->source->boundingRect(deviceCoordinates);
-// return QRectF();
-//}
-
-//void QGraphicsEffect::drawSource(QPainter *painter)
-//{
-// Q_D(QGraphicsEffect);
-// if (d->source)
-// d->source->d_func()->draw(painter);
-//}
-
-//bool QGraphicsEffect::drawSourceIntoPixmap(QPixmap *pixmap, const QPoint &offset)
-//{
-// Q_D(QGraphicsEffect);
-// if (d->source)
-// return d->source->d_func()->drawIntoPixmap(pixmap, offset);
-// return false;
-//}
-
QGraphicsGrayscaleEffect::QGraphicsGrayscaleEffect()
: QGraphicsEffect(*new QGraphicsGrayscaleEffectPrivate)
{}
@@ -210,17 +184,13 @@ QGraphicsGrayscaleEffect::~QGraphicsGrayscaleEffect()
void QGraphicsGrayscaleEffect::draw(QPainter *painter, QGraphicsEffectSource *source)
{
Q_D(QGraphicsGrayscaleEffect);
- // Find the item's bounds in device coordinates.
- const QRect sourceRect = source->boundingRect(/*deviceCoordinates=*/true)
- .toRect().adjusted(-1, -1, 1, 1);
- QPixmap pixmap(sourceRect.size());
- if (!source->drawIntoPixmap(&pixmap, sourceRect.topLeft()))
- return;
+ QPoint offset;
+ const QPixmap pixmap = source->pixmap(true, &offset);
// Draw the pixmap with the filter using an untransformed painter.
QTransform restoreTransform = painter->worldTransform();
painter->setWorldTransform(QTransform());
- d->filter->draw(painter, sourceRect.topLeft(), pixmap, pixmap.rect());
+ d->filter->draw(painter, offset, pixmap, pixmap.rect());
painter->setWorldTransform(restoreTransform);
}
@@ -247,16 +217,13 @@ void QGraphicsColorizeEffect::setColor(const QColor &c)
void QGraphicsColorizeEffect::draw(QPainter *painter, QGraphicsEffectSource *source)
{
Q_D(QGraphicsColorizeEffect);
- const QRect sourceRect = source->boundingRect(/*deviceCoordinates=*/true)
- .toRect().adjusted(-1, -1, 1, 1);
- QPixmap pixmap(sourceRect.size());
- if (!source->drawIntoPixmap(&pixmap, sourceRect.topLeft()))
- return;
+ QPoint offset;
+ const QPixmap pixmap = source->pixmap(true, &offset);
// Draw the pixmap with the filter using an untransformed painter.
QTransform restoreTransform = painter->worldTransform();
painter->setWorldTransform(QTransform());
- d->filter->draw(painter, sourceRect.topLeft(), pixmap, pixmap.rect());
+ d->filter->draw(painter, offset, pixmap, pixmap.rect());
painter->setWorldTransform(restoreTransform);
}
@@ -284,12 +251,8 @@ void QGraphicsPixelizeEffect::setPixelSize(int size)
void QGraphicsPixelizeEffect::draw(QPainter *painter, QGraphicsEffectSource *source)
{
Q_D(QGraphicsPixelizeEffect);
- // Find the item's bounds in device coordinates.
- const QRect sourceRect = source->boundingRect(/*deviceCoordinates=*/true)
- .toRect().adjusted(-1, -1, 1, 1);
- QPixmap pixmap(sourceRect.size());
- if (!source->drawIntoPixmap(&pixmap, sourceRect.topLeft()))
- return;
+ QPoint offset;
+ const QPixmap pixmap = source->pixmap(true, &offset);
// pixelize routine
QImage img = pixmap.toImage().convertToFormat(QImage::Format_ARGB32);
@@ -314,7 +277,7 @@ void QGraphicsPixelizeEffect::draw(QPainter *painter, QGraphicsEffectSource *sou
// Draw using an untransformed painter.
QTransform restoreTransform = painter->worldTransform();
painter->setWorldTransform(QTransform());
- painter->drawImage(sourceRect.topLeft(), img);
+ painter->drawImage(offset, img);
painter->setWorldTransform(restoreTransform);
}
@@ -410,9 +373,6 @@ QRectF QGraphicsBlurEffect::boundingRectFor(const QRectF &rect) const
return d->filter->boundingRectFor(rect);
}
-//QRectF QGraphicsBlurEffect::boundingRectFor(const QRectF &rect) const
-//{
-// Q_D(const QGraphicsBlurEffect);
// return d->filter->boundingRectFor(rect);
//}
@@ -462,15 +422,6 @@ void QGraphicsBloomEffect::setOpacity(qreal alpha)
d->opacity = alpha;
}
-//QRectF QGraphicsBloomEffect::boundingRectFor(nst QGraphicsEffectSource *source) const
-//{
-// Q_D(const QGraphicsBloomEffect);
-// if (!d->source)
-// return QRectF();
-// const qreal delta = d->blurRadius * 3;
-// return sourceBoundingRect().adjusted(-delta, -delta, delta, delta);
-//}
-
QRectF QGraphicsBloomEffect::boundingRectFor(const QRectF &rect) const
{
Q_D(const QGraphicsBloomEffect);
@@ -512,15 +463,11 @@ static QImage composited(const QImage& img1, const QImage& img2, qreal opacity,
void QGraphicsBloomEffect::draw(QPainter *painter, QGraphicsEffectSource *source)
{
Q_D(QGraphicsBloomEffect);
- const QRectF sourceRect = source->boundingRect(/*deviceCoordinates=*/true);
- const QRect effectRect = boundingRectFor(sourceRect).toRect().adjusted(-1, -1, 1, 1);
-
- QPixmap pixmap(effectRect.size());
- if (!source->drawIntoPixmap(&pixmap, effectRect.topLeft()))
- return;
+ QPoint offset;
+ const QPixmap pixmap = source->pixmap(true, &offset);
// bloom routine
- int radius = d->blurRadius;
+ const int radius = d->blurRadius;
QImage img = pixmap.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied);
QImage overlay = blurred(img, img.rect(), radius);
overlay = brightened(overlay, 70);
@@ -529,7 +476,7 @@ void QGraphicsBloomEffect::draw(QPainter *painter, QGraphicsEffectSource *source
// Draw using an untransformed painter.
QTransform restoreTransform = painter->worldTransform();
painter->setWorldTransform(QTransform());
- painter->drawImage(effectRect.topLeft(), img);
+ painter->drawImage(offset - QPoint(radius * 3, radius * 3), img);
painter->setWorldTransform(restoreTransform);
}
@@ -578,14 +525,6 @@ void QGraphicsFrameEffect::setFrameOpacity(qreal opacity)
d->alpha = opacity;
}
-//QRectF QGraphicsFrameEffect::boundingRect() const
-//{
-// Q_D(const QGraphicsFrameEffect);
-// if (!d->source)
-// return QRectF();
-// return d->source->boundingRect().adjusted(-d->width, -d->width, d->width, d->width);
-//}
-
QRectF QGraphicsFrameEffect::boundingRectFor(const QRectF &rect) const
{
Q_D(const QGraphicsFrameEffect);
@@ -614,87 +553,72 @@ QGraphicsShadowEffect::~QGraphicsShadowEffect()
{
}
-QPointF QGraphicsShadowEffect::shadowOffset() const
+QPointF QGraphicsShadowEffect::shadowOffset() const
{
Q_D(const QGraphicsShadowEffect);
return d->offset;
}
-void QGraphicsShadowEffect::setShadowOffset(const QPointF &ofs)
+void QGraphicsShadowEffect::setShadowOffset(const QPointF &ofs)
{
Q_D(QGraphicsShadowEffect);
d->offset = ofs;
}
-int QGraphicsShadowEffect::blurRadius() const
+int QGraphicsShadowEffect::blurRadius() const
{
Q_D(const QGraphicsShadowEffect);
return d->radius;
}
-void QGraphicsShadowEffect::setBlurRadius(int blurRadius)
+void QGraphicsShadowEffect::setBlurRadius(int blurRadius)
{
Q_D(QGraphicsShadowEffect);
d->radius = blurRadius;
}
-qreal QGraphicsShadowEffect::opacity() const
+qreal QGraphicsShadowEffect::opacity() const
{
Q_D(const QGraphicsShadowEffect);
return d->alpha;
}
-void QGraphicsShadowEffect::setOpacity(qreal opacity)
+void QGraphicsShadowEffect::setOpacity(qreal opacity)
{
Q_D(QGraphicsShadowEffect);
d->alpha = opacity;
}
-//QRectF QGraphicsShadowEffect::boundingRect() const
-//{
-// Q_D(const QGraphicsShadowEffect);
-// if (!d->source)
-// return QRectF();
-// const QRectF srcBrect = d->source->boundingRect();
-// QRectF shadowRect = srcBrect;
-// shadowRect.adjust(d->offset.x(), d->offset.y(), d->offset.x(), d->offset.y());
-// QRectF blurRect = shadowRect;
-// qreal delta = d->radius * 3;
-// blurRect.adjust(-delta, -delta, delta, delta);
-// QRectF totalRect = blurRect.united(srcBrect);
-// return totalRect;
-//}
-
QRectF QGraphicsShadowEffect::boundingRectFor(const QRectF &rect) const
{
Q_D(const QGraphicsShadowEffect);
- QRectF shadowRect = rect;
- shadowRect.adjust(d->offset.x(), d->offset.y(), d->offset.x(), d->offset.y());
+ QRectF shadowRect = rect.translated(d->offset);
QRectF blurRect = shadowRect;
qreal delta = d->radius * 3;
blurRect.adjust(-delta, -delta, delta, delta);
- QRectF totalRect = blurRect.united(rect);
- return totalRect;
+ blurRect |= rect;
+ return blurRect;
}
void QGraphicsShadowEffect::draw(QPainter *painter, QGraphicsEffectSource *source)
{
Q_D(QGraphicsShadowEffect);
- if (!d->source)
- return;
-
const QRectF sourceRect = source->boundingRect(/*deviceCoordinates=*/true);
-
- QRectF shadowRect = sourceRect;
- shadowRect.adjust(d->offset.x(), d->offset.y(), d->offset.x(), d->offset.y());
+ const QRectF shadowRect = sourceRect.translated(d->offset);
QRectF blurRect = shadowRect;
qreal delta = d->radius * 3;
blurRect.adjust(-delta, -delta, delta, delta);
- QRect totalRect = blurRect.united(sourceRect).toRect().adjusted(-1, -1, 1, 1);
+ blurRect |= sourceRect;
+ const QRect effectRect = blurRect.toAlignedRect();
- QPixmap pixmap(totalRect.size());
- if (!source->drawIntoPixmap(&pixmap, totalRect.topLeft()))
- return;
+ QPixmap pixmap(effectRect.size());
+ pixmap.fill(Qt::transparent);
+ QPainter pixmapPainter(&pixmap);
+ pixmapPainter.setRenderHints(painter->renderHints());
+ pixmapPainter.setWorldTransform(painter->worldTransform());
+ pixmapPainter.translate(-effectRect.topLeft());
+ source->draw(&pixmapPainter);
+ pixmapPainter.end();
QImage img = pixmap.toImage();
QImage shadowImage(img.size(), QImage::Format_ARGB32);
@@ -705,21 +629,8 @@ void QGraphicsShadowEffect::draw(QPainter *painter, QGraphicsEffectSource *sourc
// Draw using an untransformed painter.
QTransform restoreTransform = painter->worldTransform();
painter->setWorldTransform(QTransform());
-
- QRect shadowAlignedRect = shadowRect.toAlignedRect();
-
- qreal shadowx = blurRect.x() + delta;
- qreal shadowy = blurRect.y() + delta;
- if (blurRect.x() < sourceRect.x())
- shadowx = sourceRect.x() + d->offset.x();
- if (blurRect.y() < sourceRect.y())
- shadowy = blurRect.y() + d->offset.y();
- painter->drawImage(shadowx, shadowy, shadowImage);
-
- qreal itemx = qMin(blurRect.x(), sourceRect.x());
- qreal itemy = qMin(blurRect.y(), sourceRect.y());
- painter->drawPixmap(itemx, itemy, pixmap);
-
+ painter->drawImage(effectRect.topLeft() + d->offset, shadowImage);
+ painter->drawPixmap(effectRect.topLeft(), pixmap);
painter->setWorldTransform(restoreTransform);
}
diff --git a/src/gui/graphicsview/qgraphicseffect.h b/src/gui/graphicsview/qgraphicseffect.h
index 77eebd6..175541f 100644
--- a/src/gui/graphicsview/qgraphicseffect.h
+++ b/src/gui/graphicsview/qgraphicseffect.h
@@ -75,7 +75,6 @@ public:
const QGraphicsItem *graphicsItem() const;
const QStyleOption *styleOption() const;
void draw(QPainter *painter);
- bool drawIntoPixmap(QPixmap *pixmap, const QPoint &offset = QPoint());
QPixmap pixmap(bool deviceCoordinates, QPoint *offset = 0) const;
protected:
diff --git a/src/gui/graphicsview/qgraphicseffect_p.h b/src/gui/graphicsview/qgraphicseffect_p.h
index a575d3b..ddf65e9 100644
--- a/src/gui/graphicsview/qgraphicseffect_p.h
+++ b/src/gui/graphicsview/qgraphicseffect_p.h
@@ -72,7 +72,6 @@ public:
virtual const QGraphicsItem *graphicsItem() const = 0;
virtual const QStyleOption *styleOption() const = 0;
virtual void draw(QPainter *p) = 0;
- virtual bool drawIntoPixmap(QPixmap *, const QPoint &offset = QPoint()) = 0;
virtual QPixmap pixmap(bool deviceCoordinates, QPoint *offset = 0) const = 0;
friend class QGraphicsScenePrivate;
friend class QGraphicsItem;
@@ -168,7 +167,7 @@ class QGraphicsShadowEffectPrivate : public QGraphicsEffectPrivate
{
Q_DECLARE_PUBLIC(QGraphicsShadowEffect)
public:
- QGraphicsShadowEffectPrivate() : offset(4,4), radius(8), alpha(0.7) {}
+ QGraphicsShadowEffectPrivate() : offset(4, 4), radius(8), alpha(0.7) {}
QPointF offset;
int radius;
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index 120ca05..c0fa271 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -9972,7 +9972,7 @@ QPixmap QGraphicsItemEffectSourcePrivate::pixmap(bool deviceCoordinates, QPoint
QPixmap pixmap(effectRect.size());
pixmap.fill(Qt::transparent);
QPainter pixmapPainter(&pixmap);
- pixmapPainter.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing);
+ pixmapPainter.setRenderHints(info->painter->renderHints());
QGraphicsScenePrivate *scened = item->d_ptr->scene->d_func();
scened->draw(item, &pixmapPainter, info->viewTransform, info->transformPtr, info->exposedRegion,
@@ -9981,36 +9981,6 @@ QPixmap QGraphicsItemEffectSourcePrivate::pixmap(bool deviceCoordinates, QPoint
return pixmap;
}
-bool QGraphicsItemEffectSourcePrivate::drawIntoPixmap(QPixmap *pixmap, const QPoint &offset)
-{
- QPoint effectOffset(offset);
-
- QTransform viewTransform(Qt::Uninitialized);
- if (info->viewTransform) {
- viewTransform = *info->viewTransform;
- viewTransform *= QTransform::fromTranslate(-effectOffset.x(), -effectOffset.y());
- } else {
- viewTransform = QTransform::fromTranslate(-effectOffset.x(), -effectOffset.y());
- }
-
- *info->transformPtr *= QTransform::fromTranslate(-effectOffset.x(), -effectOffset.y());
-
- QRegion exposedRegion;
- if (info->exposedRegion) {
- exposedRegion = *info->exposedRegion;
- exposedRegion.translate(-effectOffset.x(), -effectOffset.y());
- }
-
- pixmap->fill(Qt::transparent);
- QPainter pixmapPainter(pixmap);
- pixmapPainter.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing);
- QGraphicsScenePrivate *scened = item->d_ptr->scene->d_func();
- scened->draw(item, &pixmapPainter, &viewTransform, info->transformPtr, &exposedRegion,
- info->widget, info->opacity, 0, info->wasDirtySceneTransform,
- info->drawItem);
- return true;
-}
-
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug debug, QGraphicsItem *item)
{
diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h
index c6161bf..f8b2ebc 100644
--- a/src/gui/graphicsview/qgraphicsitem_p.h
+++ b/src/gui/graphicsview/qgraphicsitem_p.h
@@ -548,7 +548,6 @@ public:
QRectF boundingRect(bool deviceCoordinates) const;
void draw(QPainter *);
- bool drawIntoPixmap(QPixmap *pixmap, const QPoint &offset);
QPixmap pixmap(bool deviceCoordinates, QPoint *offset) const;
QGraphicsItem *item;