summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-07-22 07:15:55 (GMT)
committerBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-07-23 23:26:20 (GMT)
commit8e18256d023e6e78081a34b573d548d52137575d (patch)
tree1c604917bab463f545fba3233f18e500ad6f6a14
parent787f2252077434581101df64d0f0d576c26b7ce8 (diff)
downloadQt-8e18256d023e6e78081a34b573d548d52137575d.zip
Qt-8e18256d023e6e78081a34b573d548d52137575d.tar.gz
Qt-8e18256d023e6e78081a34b573d548d52137575d.tar.bz2
QGraphicsEffect API cleanup.
-rw-r--r--examples/graphicsview/blurpicker/blureffect.cpp2
-rw-r--r--examples/graphicsview/blurpicker/blureffect.h2
-rw-r--r--examples/graphicsview/blurpicker/blurpicker.cpp6
-rw-r--r--examples/graphicsview/blurpicker/blurpicker.h1
-rw-r--r--examples/graphicsview/lighting/lighting.cpp4
-rw-r--r--examples/graphicsview/lighting/lighting.h1
-rw-r--r--examples/graphicsview/lighting/shadoweffect.cpp4
-rw-r--r--examples/graphicsview/lighting/shadoweffect.h2
-rw-r--r--src/gui/graphicsview/graphicsview.pri3
-rw-r--r--src/gui/graphicsview/qgraphicseffect.cpp178
-rw-r--r--src/gui/graphicsview/qgraphicseffect.h37
-rw-r--r--src/gui/graphicsview/qgraphicseffect_p.h150
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp53
-rw-r--r--src/gui/graphicsview/qgraphicsitem.h4
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp4
15 files changed, 234 insertions, 217 deletions
diff --git a/examples/graphicsview/blurpicker/blureffect.cpp b/examples/graphicsview/blurpicker/blureffect.cpp
index 8345d0b..6c2095d 100644
--- a/examples/graphicsview/blurpicker/blureffect.cpp
+++ b/examples/graphicsview/blurpicker/blureffect.cpp
@@ -43,7 +43,7 @@
#include <QDebug>
-BlurEffect::BlurEffect(QObject *parent)
+BlurEffect::BlurEffect()
: QGraphicsBlurEffect()
, m_baseLine(200)
{
diff --git a/examples/graphicsview/blurpicker/blureffect.h b/examples/graphicsview/blurpicker/blureffect.h
index 24a6867..cafd910 100644
--- a/examples/graphicsview/blurpicker/blureffect.h
+++ b/examples/graphicsview/blurpicker/blureffect.h
@@ -48,7 +48,7 @@
class BlurEffect: public QGraphicsBlurEffect
{
public:
- BlurEffect(QObject *parent = 0);
+ BlurEffect();
void setBaseLine(qreal y) { m_baseLine = y; }
diff --git a/examples/graphicsview/blurpicker/blurpicker.cpp b/examples/graphicsview/blurpicker/blurpicker.cpp
index 887d7ef..10ce44f 100644
--- a/examples/graphicsview/blurpicker/blurpicker.cpp
+++ b/examples/graphicsview/blurpicker/blurpicker.cpp
@@ -79,9 +79,9 @@ void BlurPicker::updateIconPositions()
pos -= QPointF(40, 40);
icon->setPos(pos);
baseline = qMax(baseline, ys);
+ static_cast<BlurEffect *>(icon->effect())->setBaseLine(baseline);
}
- m_blurEffect->setBaseLine(baseline);
m_scene.update();
}
@@ -89,8 +89,6 @@ void BlurPicker::setupScene()
{
m_scene.setSceneRect(-200, -120, 400, 240);
- m_blurEffect = new BlurEffect(this);
-
QStringList names;
names << ":/images/accessories-calculator.png";
names << ":/images/accessories-text-editor.png";
@@ -105,7 +103,7 @@ void BlurPicker::setupScene()
QPixmap pixmap(names[i]);
QGraphicsPixmapItem *icon = m_scene.addPixmap(pixmap);
icon->setZValue(1);
- icon->setEffect(m_blurEffect);
+ icon->setGraphicsEffect(new BlurEffect);
m_icons << icon;
}
diff --git a/examples/graphicsview/blurpicker/blurpicker.h b/examples/graphicsview/blurpicker/blurpicker.h
index e41c608..b7ea3b4 100644
--- a/examples/graphicsview/blurpicker/blurpicker.h
+++ b/examples/graphicsview/blurpicker/blurpicker.h
@@ -67,7 +67,6 @@ private:
private:
qreal m_index;
QGraphicsScene m_scene;
- BlurEffect *m_blurEffect;
QList<QGraphicsItem*> m_icons;
QTimeLine m_timeLine;
};
diff --git a/examples/graphicsview/lighting/lighting.cpp b/examples/graphicsview/lighting/lighting.cpp
index 445d7f9..fff2204 100644
--- a/examples/graphicsview/lighting/lighting.cpp
+++ b/examples/graphicsview/lighting/lighting.cpp
@@ -88,8 +88,6 @@ void Lighting::setupScene()
m_lightSource = m_scene.addPixmap(pixmap);
m_lightSource->setZValue(2);
- m_shadowEffect = new ShadowEffect(m_lightSource, this);
-
for (int i = -2; i < 3; ++i)
for (int j = -2; j < 3; ++j) {
QAbstractGraphicsShapeItem *item;
@@ -100,7 +98,7 @@ void Lighting::setupScene()
item->setPen(QPen(Qt::black));
item->setBrush(QBrush(Qt::white));
- item->setEffect(m_shadowEffect);
+ item->setGraphicsEffect(new ShadowEffect(m_lightSource));
item->setZValue(1);
item->setPos(i * 80, j * 80);
m_scene.addItem(item);
diff --git a/examples/graphicsview/lighting/lighting.h b/examples/graphicsview/lighting/lighting.h
index 66237f6..70a4d48 100644
--- a/examples/graphicsview/lighting/lighting.h
+++ b/examples/graphicsview/lighting/lighting.h
@@ -64,7 +64,6 @@ private:
qreal angle;
QGraphicsScene m_scene;
QGraphicsItem *m_lightSource;
- ShadowEffect *m_shadowEffect;
QList<QGraphicsItem*> m_items;
};
diff --git a/examples/graphicsview/lighting/shadoweffect.cpp b/examples/graphicsview/lighting/shadoweffect.cpp
index 726cbd0..c1d384a 100644
--- a/examples/graphicsview/lighting/shadoweffect.cpp
+++ b/examples/graphicsview/lighting/shadoweffect.cpp
@@ -43,8 +43,8 @@
#include <math.h>
-ShadowEffect::ShadowEffect(QGraphicsItem *source, QObject *parent)
- : QGraphicsShadowEffect(parent)
+ShadowEffect::ShadowEffect(QGraphicsItem *source)
+ : QGraphicsShadowEffect()
, m_lightSource(source)
{
setBlurRadius(8);
diff --git a/examples/graphicsview/lighting/shadoweffect.h b/examples/graphicsview/lighting/shadoweffect.h
index 02d0bf1..09b63e3 100644
--- a/examples/graphicsview/lighting/shadoweffect.h
+++ b/examples/graphicsview/lighting/shadoweffect.h
@@ -48,7 +48,7 @@
class ShadowEffect: public QGraphicsShadowEffect
{
public:
- ShadowEffect(QGraphicsItem *source, QObject *parent = 0);
+ ShadowEffect(QGraphicsItem *source);
QRectF boundingRectFor(const QGraphicsItem *item);
diff --git a/src/gui/graphicsview/graphicsview.pri b/src/gui/graphicsview/graphicsview.pri
index c3cb574..55bb9e0 100644
--- a/src/gui/graphicsview/graphicsview.pri
+++ b/src/gui/graphicsview/graphicsview.pri
@@ -21,7 +21,8 @@ HEADERS += graphicsview/qgraphicsgridlayout.h \
graphicsview/qgraphicswidget.h \
graphicsview/qgraphicswidget_p.h \
graphicsview/qgridlayoutengine_p.h \
- graphicsview/qgraphicseffect.h
+ graphicsview/qgraphicseffect.h \
+ graphicsview/qgraphicseffect_p.h \
SOURCES += graphicsview/qgraphicsgridlayout.cpp \
graphicsview/qgraphicsitem.cpp \
diff --git a/src/gui/graphicsview/qgraphicseffect.cpp b/src/gui/graphicsview/qgraphicseffect.cpp
index 6b1f12a..c173d1b 100644
--- a/src/gui/graphicsview/qgraphicseffect.cpp
+++ b/src/gui/graphicsview/qgraphicseffect.cpp
@@ -39,7 +39,7 @@
**
****************************************************************************/
-#include "qgraphicseffect.h"
+#include "qgraphicseffect_p.h"
#ifndef QT_NO_GRAPHICSVIEW
@@ -48,9 +48,6 @@
#include <QtGui/qgraphicsscene.h>
#include <QtGui/qpainter.h>
-#include <private/qobject_p.h>
-#include <private/qpixmapfilter_p.h>
-
/*
List of known drawbacks which are being discussed:
@@ -105,19 +102,11 @@
*/
-/*!
- \internal
-*/
-class QGraphicsEffectPrivate : public QObjectPrivate
-{
- Q_DECLARE_PUBLIC(QGraphicsEffect)
-public:
- QGraphicsEffectPrivate() {}
-};
-
-QGraphicsEffect::QGraphicsEffect(QObject *parent)
- : QObject(*new QGraphicsEffectPrivate, parent)
+QGraphicsEffect::QGraphicsEffect()
+ : QObject(*new QGraphicsEffectPrivate, 0)
{
+ Q_D(QGraphicsEffect);
+ d->parentItem = 0;
}
QGraphicsEffect::~QGraphicsEffect()
@@ -134,9 +123,11 @@ QRectF QGraphicsEffect::boundingRectFor(const QGraphicsItem *item)
/*! \internal
*/
-QGraphicsEffect::QGraphicsEffect(QGraphicsEffectPrivate &dd, QObject *parent)
- : QObject(dd, parent)
+QGraphicsEffect::QGraphicsEffect(QGraphicsEffectPrivate &dd)
+ : QObject(dd, 0)
{
+ Q_D(QGraphicsEffect);
+ d->parentItem = 0;
}
// this helper function is only for subclasses of QGraphicsEffect
@@ -151,27 +142,8 @@ QPixmap* QGraphicsEffect::drawItemOnPixmap(QPainter *painter, QGraphicsItem *ite
return item->scene()->drawItemOnPixmap(painter, item, option, widget, flags);
}
-/*!
- \internal
-*/
-class QGraphicsGrayscaleEffectPrivate : public QGraphicsEffectPrivate
-{
- Q_DECLARE_PUBLIC(QGraphicsGrayscaleEffect)
-public:
- QGraphicsGrayscaleEffectPrivate() {
- filter = new QPixmapColorizeFilter;
- filter->setColor(Qt::black);
- }
-
- ~QGraphicsGrayscaleEffectPrivate() {
- delete filter;
- }
-
- QPixmapColorizeFilter *filter;
-};
-
-QGraphicsGrayscaleEffect::QGraphicsGrayscaleEffect(QObject *parent)
- : QGraphicsEffect(*new QGraphicsGrayscaleEffectPrivate, parent)
+QGraphicsGrayscaleEffect::QGraphicsGrayscaleEffect()
+ : QGraphicsEffect(*new QGraphicsGrayscaleEffectPrivate)
{
}
@@ -201,26 +173,8 @@ void QGraphicsGrayscaleEffect::drawItem(QGraphicsItem *item, QPainter *painter,
painter->setWorldTransform(restoreTransform);
}
-/*!
- \internal
-*/
-class QGraphicsColorizeEffectPrivate : public QGraphicsEffectPrivate
-{
- Q_DECLARE_PUBLIC(QGraphicsColorizeEffect)
-public:
- QGraphicsColorizeEffectPrivate() {
- filter = new QPixmapColorizeFilter;
- }
-
- ~QGraphicsColorizeEffectPrivate() {
- delete filter;
- }
-
- QPixmapColorizeFilter *filter;
-};
-
-QGraphicsColorizeEffect::QGraphicsColorizeEffect(QObject *parent)
- : QGraphicsEffect(*new QGraphicsColorizeEffectPrivate, parent)
+QGraphicsColorizeEffect::QGraphicsColorizeEffect()
+ : QGraphicsEffect(*new QGraphicsColorizeEffectPrivate)
{
}
@@ -262,21 +216,8 @@ void QGraphicsColorizeEffect::drawItem(QGraphicsItem *item, QPainter *painter,
painter->setWorldTransform(restoreTransform);
}
-/*!
- \internal
-*/
-class QGraphicsPixelizeEffectPrivate : public QGraphicsEffectPrivate
-{
- Q_DECLARE_PUBLIC(QGraphicsPixelizeEffect)
-public:
- QGraphicsPixelizeEffectPrivate()
- : pixelSize(3) { }
-
- int pixelSize;
-};
-
-QGraphicsPixelizeEffect::QGraphicsPixelizeEffect(QObject *parent)
- : QGraphicsEffect(*new QGraphicsPixelizeEffectPrivate, parent)
+QGraphicsPixelizeEffect::QGraphicsPixelizeEffect()
+ : QGraphicsEffect(*new QGraphicsPixelizeEffectPrivate)
{
}
@@ -338,27 +279,8 @@ void QGraphicsPixelizeEffect::drawItem(QGraphicsItem *item, QPainter *painter,
painter->setWorldTransform(restoreTransform);
}
-/*!
- \internal
-*/
-class QGraphicsBlurEffectPrivate : public QGraphicsEffectPrivate
-{
- Q_DECLARE_PUBLIC(QGraphicsBlurEffect)
-public:
- QGraphicsBlurEffectPrivate()
- {
- filter = new QPixmapBlurFilter;
- }
- ~QGraphicsBlurEffectPrivate()
- {
- delete filter;
- }
-
- QPixmapBlurFilter *filter;
-};
-
-QGraphicsBlurEffect::QGraphicsBlurEffect(QObject *parent)
- : QGraphicsEffect(*new QGraphicsBlurEffectPrivate, parent)
+QGraphicsBlurEffect::QGraphicsBlurEffect()
+ : QGraphicsEffect(*new QGraphicsBlurEffectPrivate)
{
}
@@ -471,23 +393,8 @@ void QGraphicsBlurEffect::drawItem(QGraphicsItem *item, QPainter *painter,
painter->setWorldTransform(restoreTransform);
}
-/*!
- \internal
-*/
-class QGraphicsBloomEffectPrivate : public QGraphicsEffectPrivate
-{
- Q_DECLARE_PUBLIC(QGraphicsBlurEffect)
-public:
- QGraphicsBloomEffectPrivate()
- : blurRadius(6)
- , opacity(0.7) { }
-
- int blurRadius;
- qreal opacity;
-};
-
-QGraphicsBloomEffect::QGraphicsBloomEffect(QObject *parent)
- : QGraphicsEffect(*new QGraphicsBloomEffectPrivate, parent)
+QGraphicsBloomEffect::QGraphicsBloomEffect()
+ : QGraphicsEffect(*new QGraphicsBloomEffectPrivate)
{
}
@@ -588,27 +495,8 @@ void QGraphicsBloomEffect::drawItem(QGraphicsItem *item, QPainter *painter,
painter->setWorldTransform(restoreTransform);
}
-/*!
- \internal
-*/
-class QGraphicsFrameEffectPrivate : public QGraphicsEffectPrivate
-{
- Q_DECLARE_PUBLIC(QGraphicsFrameEffect)
-public:
- QGraphicsFrameEffectPrivate()
- : color(Qt::blue)
- , width(5)
- , alpha(0.6)
- {
- }
-
- QColor color;
- qreal width;
- qreal alpha;
-};
-
-QGraphicsFrameEffect::QGraphicsFrameEffect(QObject *parent)
- : QGraphicsEffect(*new QGraphicsFrameEffectPrivate, parent)
+QGraphicsFrameEffect::QGraphicsFrameEffect()
+ : QGraphicsEffect(*new QGraphicsFrameEffectPrivate)
{
}
@@ -693,28 +581,8 @@ void QGraphicsFrameEffect::drawItem(QGraphicsItem *item, QPainter *painter,
painter->restore();
}
-
-/*!
- \internal
-*/
-class QGraphicsShadowEffectPrivate : public QGraphicsEffectPrivate
-{
- Q_DECLARE_PUBLIC(QGraphicsShadowEffect)
-public:
- QGraphicsShadowEffectPrivate()
- : offset(4,4)
- , radius(8)
- , alpha(0.7)
- {
- }
-
- QPointF offset;
- int radius;
- qreal alpha;
-};
-
-QGraphicsShadowEffect::QGraphicsShadowEffect(QObject *parent)
- : QGraphicsEffect(*new QGraphicsShadowEffectPrivate, parent)
+QGraphicsShadowEffect::QGraphicsShadowEffect()
+ : QGraphicsEffect(*new QGraphicsShadowEffectPrivate)
{
}
diff --git a/src/gui/graphicsview/qgraphicseffect.h b/src/gui/graphicsview/qgraphicseffect.h
index 29d97a6..9f6e342 100644
--- a/src/gui/graphicsview/qgraphicseffect.h
+++ b/src/gui/graphicsview/qgraphicseffect.h
@@ -67,10 +67,8 @@ class QGraphicsEffectPrivate;
class Q_GUI_EXPORT QGraphicsEffect : public QObject
{
Q_OBJECT
-
public:
-
- QGraphicsEffect(QObject *parent = 0);
+ QGraphicsEffect();
virtual ~QGraphicsEffect();
virtual QRectF boundingRectFor(const QGraphicsItem *item);
@@ -80,11 +78,12 @@ public:
QWidget *widget = 0) = 0;
protected:
- QGraphicsEffect(QGraphicsEffectPrivate &d, QObject* parent);
+ QGraphicsEffect(QGraphicsEffectPrivate &d);
QPixmap* drawItemOnPixmap(QPainter *painter, QGraphicsItem *item,
const QStyleOptionGraphicsItem *option, QWidget *widget, int flags);
private:
+ friend class QGraphicsItem;
Q_DECLARE_PRIVATE(QGraphicsEffect)
Q_DISABLE_COPY(QGraphicsEffect)
};
@@ -93,10 +92,8 @@ class QGraphicsGrayscaleEffectPrivate;
class Q_GUI_EXPORT QGraphicsGrayscaleEffect: public QGraphicsEffect
{
Q_OBJECT
-
public:
-
- QGraphicsGrayscaleEffect(QObject *parent = 0);
+ QGraphicsGrayscaleEffect();
~QGraphicsGrayscaleEffect();
void drawItem(QGraphicsItem *item, QPainter *painter,
@@ -111,10 +108,8 @@ private:
class QGraphicsColorizeEffectPrivate;
class Q_GUI_EXPORT QGraphicsColorizeEffect: public QGraphicsEffect {
Q_OBJECT
-
public:
-
- QGraphicsColorizeEffect(QObject *parent = 0);
+ QGraphicsColorizeEffect();
~QGraphicsColorizeEffect();
QColor color() const;
@@ -132,10 +127,8 @@ private:
class QGraphicsPixelizeEffectPrivate;
class Q_GUI_EXPORT QGraphicsPixelizeEffect: public QGraphicsEffect {
Q_OBJECT
-
public:
-
- QGraphicsPixelizeEffect(QObject *parent = 0);
+ QGraphicsPixelizeEffect();
~QGraphicsPixelizeEffect();
int pixelSize() const;
@@ -153,10 +146,8 @@ private:
class QGraphicsBlurEffectPrivate;
class Q_GUI_EXPORT QGraphicsBlurEffect: public QGraphicsEffect {
Q_OBJECT
-
public:
-
- QGraphicsBlurEffect(QObject *parent = 0);
+ QGraphicsBlurEffect();
~QGraphicsBlurEffect();
int blurRadius() const;
@@ -176,10 +167,8 @@ private:
class QGraphicsBloomEffectPrivate;
class Q_GUI_EXPORT QGraphicsBloomEffect: public QGraphicsEffect {
Q_OBJECT
-
public:
-
- QGraphicsBloomEffect(QObject *parent = 0);
+ QGraphicsBloomEffect();
~QGraphicsBloomEffect();
int blurRadius() const;
@@ -202,10 +191,8 @@ private:
class QGraphicsFrameEffectPrivate;
class Q_GUI_EXPORT QGraphicsFrameEffect: public QGraphicsEffect {
Q_OBJECT
-
public:
-
- QGraphicsFrameEffect(QObject *parent = 0);
+ QGraphicsFrameEffect();
~QGraphicsFrameEffect();
QColor frameColor() const;
@@ -230,10 +217,8 @@ private:
class QGraphicsShadowEffectPrivate;
class Q_GUI_EXPORT QGraphicsShadowEffect: public QGraphicsEffect {
Q_OBJECT
-
public:
-
- QGraphicsShadowEffect(QObject *parent = 0);
+ QGraphicsShadowEffect();
~QGraphicsShadowEffect();
QPointF shadowOffset() const;
@@ -253,8 +238,6 @@ public:
const QStyleOptionGraphicsItem *option = 0,
QWidget *widget = 0);
-protected:
-
private:
Q_DECLARE_PRIVATE(QGraphicsShadowEffect)
Q_DISABLE_COPY(QGraphicsShadowEffect)
diff --git a/src/gui/graphicsview/qgraphicseffect_p.h b/src/gui/graphicsview/qgraphicseffect_p.h
new file mode 100644
index 0000000..999e013
--- /dev/null
+++ b/src/gui/graphicsview/qgraphicseffect_p.h
@@ -0,0 +1,150 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGRAPHICSEFFECT_P_H
+#define QGRAPHICSEFFECT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
+// file may change from version to version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qgraphicseffect.h"
+#include <private/qobject_p.h>
+#include <private/qpixmapfilter_p.h>
+
+#if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
+
+QT_BEGIN_NAMESPACE
+
+class QGraphicsEffectPrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QGraphicsEffect)
+public:
+ QGraphicsEffectPrivate(): parentItem(0) {}
+ QGraphicsItem *parentItem;
+};
+
+class QGraphicsGrayscaleEffectPrivate : public QGraphicsEffectPrivate
+{
+ Q_DECLARE_PUBLIC(QGraphicsGrayscaleEffect)
+public:
+ QGraphicsGrayscaleEffectPrivate()
+ {
+ filter = new QPixmapColorizeFilter;
+ filter->setColor(Qt::black);
+ }
+ ~QGraphicsGrayscaleEffectPrivate() { delete filter; }
+
+ QPixmapColorizeFilter *filter;
+};
+
+class QGraphicsColorizeEffectPrivate : public QGraphicsEffectPrivate
+{
+ Q_DECLARE_PUBLIC(QGraphicsColorizeEffect)
+public:
+ QGraphicsColorizeEffectPrivate() { filter = new QPixmapColorizeFilter; }
+ ~QGraphicsColorizeEffectPrivate() { delete filter; }
+
+ QPixmapColorizeFilter *filter;
+};
+
+class QGraphicsPixelizeEffectPrivate : public QGraphicsEffectPrivate
+{
+ Q_DECLARE_PUBLIC(QGraphicsPixelizeEffect)
+public:
+ QGraphicsPixelizeEffectPrivate() : pixelSize(3) {}
+
+ int pixelSize;
+};
+
+class QGraphicsBlurEffectPrivate : public QGraphicsEffectPrivate
+{
+ Q_DECLARE_PUBLIC(QGraphicsBlurEffect)
+public:
+ QGraphicsBlurEffectPrivate() : blurRadius(4) {}
+
+ int blurRadius;
+};
+
+class QGraphicsBloomEffectPrivate : public QGraphicsEffectPrivate
+{
+ Q_DECLARE_PUBLIC(QGraphicsBlurEffect)
+public:
+ QGraphicsBloomEffectPrivate() : blurRadius(6), opacity(0.7) {}
+
+ int blurRadius;
+ qreal opacity;
+};
+
+class QGraphicsFrameEffectPrivate : public QGraphicsEffectPrivate
+{
+ Q_DECLARE_PUBLIC(QGraphicsFrameEffect)
+public:
+ QGraphicsFrameEffectPrivate() : color(Qt::blue), width(5), alpha(0.6) {}
+
+ QColor color;
+ qreal width;
+ qreal alpha;
+};
+
+class QGraphicsShadowEffectPrivate : public QGraphicsEffectPrivate
+{
+ Q_DECLARE_PUBLIC(QGraphicsShadowEffect)
+public:
+ QGraphicsShadowEffectPrivate() : offset(4,4), radius(8), alpha(0.7) {}
+
+ QPointF offset;
+ int radius;
+ qreal alpha;
+};
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_GRAPHICSVIEW
+
+#endif // QGRAPHICSEFFECT_P_H
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index a044fbd..3a350e0 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -552,7 +552,7 @@
#ifndef QT_NO_GRAPHICSVIEW
-#include "qgraphicseffect.h"
+#include "qgraphicseffect_p.h"
#include "qgraphicsscene.h"
#include "qgraphicsscene_p.h"
#include "qgraphicssceneevent.h"
@@ -1180,6 +1180,8 @@ QGraphicsItem::~QGraphicsItem()
else
d_ptr->setParentItemHelper(0);
+ QGraphicsEffect *e = graphicsEffect();
+ delete e;
delete d_ptr->transformData;
delete d_ptr;
@@ -2190,11 +2192,11 @@ 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)
@@ -2204,22 +2206,41 @@ QGraphicsEffect *QGraphicsItem::effect() const
}
/*!
+ 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 (QGraphicsEffect *currentEffect = this->graphicsEffect()) {
+ if (currentEffect != effect) {
+ qWarning("QGraphicsItem::setEffect: Attempting to set QGraphicsEffect "
+ "%p on %p, which already has an effect", effect, this);
+ }
+ return;
+ }
+
+ if (effect->d_func()->parentItem)
+ effect->d_func()->parentItem->setGraphicsEffect(0);
+ effect->d_func()->parentItem = this;
+ d_ptr->hasEffect = true;
+ d_ptr->setExtra(QGraphicsItemPrivate::ExtraEffect, QVariant::fromValue(effect));
} 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);
+ 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);
}
update();
@@ -2236,7 +2257,7 @@ void QGraphicsItem::setEffect(QGraphicsEffect *effect)
*/
QRectF QGraphicsItem::effectiveBoundingRect() const
{
- QGraphicsEffect *fx = effect();
+ QGraphicsEffect *fx = graphicsEffect();
if (fx)
return fx->boundingRectFor(this);
diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h
index c230928..0beb07c 100644
--- a/src/gui/graphicsview/qgraphicsitem.h
+++ b/src/gui/graphicsview/qgraphicsitem.h
@@ -208,8 +208,8 @@ public:
void setOpacity(qreal opacity);
// Effect
- QGraphicsEffect *effect() const;
- void setEffect(QGraphicsEffect *effect);
+ QGraphicsEffect *graphicsEffect() const;
+ void setGraphicsEffect(QGraphicsEffect *effect);
QRectF effectiveBoundingRect() const;
QRectF sceneEffectiveBoundingRect() const;
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index 2807673..c56f34c 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -3928,8 +3928,8 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte
#endif
// Render using effect, works now only for no cache mode
- if (noCache && itemd->hasEffect && item->effect()) {
- item->effect()->drawItem(item, painter, option, widget);
+ if (noCache && itemd->hasEffect && item->graphicsEffect()) {
+ item->graphicsEffect()->drawItem(item, painter, option, widget);
return;
}