summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-07-23 15:11:54 (GMT)
committerBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-07-24 01:03:19 (GMT)
commite646d08593dc18cad4e59176c2fe8c10fa5b9497 (patch)
treef1babc50eaddbe47327bcb7b7adb938c6a5820e0 /examples
parent8e18256d023e6e78081a34b573d548d52137575d (diff)
downloadQt-e646d08593dc18cad4e59176c2fe8c10fa5b9497.zip
Qt-e646d08593dc18cad4e59176c2fe8c10fa5b9497.tar.gz
Qt-e646d08593dc18cad4e59176c2fe8c10fa5b9497.tar.bz2
Make QGraphicsEffect independent of QGraphicsItem.
This makes it possible to basically implement support for graphics effects on pretty much everything, e.g. QWidget. We currently only support effects on QGraphicsItem, but there's more to come :-)
Diffstat (limited to 'examples')
-rw-r--r--examples/graphicsview/blurpicker/blureffect.cpp19
-rw-r--r--examples/graphicsview/blurpicker/blureffect.h11
-rw-r--r--examples/graphicsview/blurpicker/blurpicker.cpp4
-rw-r--r--examples/graphicsview/lighting/lighting.cpp2
-rw-r--r--examples/graphicsview/lighting/shadoweffect.cpp19
-rw-r--r--examples/graphicsview/lighting/shadoweffect.h11
6 files changed, 31 insertions, 35 deletions
diff --git a/examples/graphicsview/blurpicker/blureffect.cpp b/examples/graphicsview/blurpicker/blureffect.cpp
index 6c2095d..43791c6 100644
--- a/examples/graphicsview/blurpicker/blureffect.cpp
+++ b/examples/graphicsview/blurpicker/blureffect.cpp
@@ -43,28 +43,27 @@
#include <QDebug>
-BlurEffect::BlurEffect()
+BlurEffect::BlurEffect(QGraphicsItem *item)
: QGraphicsBlurEffect()
- , m_baseLine(200)
+ , m_baseLine(200), item(item)
{
}
-void BlurEffect::adjustForItem(const QGraphicsItem *item)
+void BlurEffect::adjustForItem()
{
qreal y = m_baseLine - item->pos().y();
qreal radius = qBound(0.0, y / 32, 16.0);
setBlurRadius(radius);
}
-QRectF BlurEffect::boundingRectFor(const QGraphicsItem *item)
+QRectF BlurEffect::boundingRect() const
{
- adjustForItem(item);
- return QGraphicsBlurEffect::boundingRectFor(item);
+ const_cast<BlurEffect *>(this)->adjustForItem();
+ return QGraphicsBlurEffect::boundingRect();
}
-void BlurEffect::drawItem(QGraphicsItem *item, QPainter *painter,
- const QStyleOptionGraphicsItem *option, QWidget *widget)
+void BlurEffect::draw(QPainter *painter)
{
- adjustForItem(item);
- QGraphicsBlurEffect::drawItem(item, painter, option, widget);
+ adjustForItem();
+ QGraphicsBlurEffect::draw(painter);
}
diff --git a/examples/graphicsview/blurpicker/blureffect.h b/examples/graphicsview/blurpicker/blureffect.h
index cafd910..2aea8bf 100644
--- a/examples/graphicsview/blurpicker/blureffect.h
+++ b/examples/graphicsview/blurpicker/blureffect.h
@@ -48,21 +48,20 @@
class BlurEffect: public QGraphicsBlurEffect
{
public:
- BlurEffect();
+ BlurEffect(QGraphicsItem *item);
void setBaseLine(qreal y) { m_baseLine = y; }
- QRectF boundingRectFor(const QGraphicsItem *item);
+ QRectF boundingRect() const;
- void drawItem(QGraphicsItem *item, QPainter *painter,
- const QStyleOptionGraphicsItem *option = 0,
- QWidget *widget = 0);
+ void draw(QPainter *painter);
private:
- void adjustForItem(const QGraphicsItem *item);
+ void adjustForItem();
private:
qreal m_baseLine;
+ QGraphicsItem *item;
};
#endif // BLUREFFECT_H
diff --git a/examples/graphicsview/blurpicker/blurpicker.cpp b/examples/graphicsview/blurpicker/blurpicker.cpp
index 10ce44f..9904dfa 100644
--- a/examples/graphicsview/blurpicker/blurpicker.cpp
+++ b/examples/graphicsview/blurpicker/blurpicker.cpp
@@ -79,7 +79,7 @@ void BlurPicker::updateIconPositions()
pos -= QPointF(40, 40);
icon->setPos(pos);
baseline = qMax(baseline, ys);
- static_cast<BlurEffect *>(icon->effect())->setBaseLine(baseline);
+ static_cast<BlurEffect *>(icon->graphicsEffect())->setBaseLine(baseline);
}
m_scene.update();
@@ -103,7 +103,7 @@ void BlurPicker::setupScene()
QPixmap pixmap(names[i]);
QGraphicsPixmapItem *icon = m_scene.addPixmap(pixmap);
icon->setZValue(1);
- icon->setGraphicsEffect(new BlurEffect);
+ icon->setGraphicsEffect(new BlurEffect(icon));
m_icons << icon;
}
diff --git a/examples/graphicsview/lighting/lighting.cpp b/examples/graphicsview/lighting/lighting.cpp
index fff2204..63f0a6c 100644
--- a/examples/graphicsview/lighting/lighting.cpp
+++ b/examples/graphicsview/lighting/lighting.cpp
@@ -98,7 +98,7 @@ void Lighting::setupScene()
item->setPen(QPen(Qt::black));
item->setBrush(QBrush(Qt::white));
- item->setGraphicsEffect(new ShadowEffect(m_lightSource));
+ item->setGraphicsEffect(new ShadowEffect(item, m_lightSource));
item->setZValue(1);
item->setPos(i * 80, j * 80);
m_scene.addItem(item);
diff --git a/examples/graphicsview/lighting/shadoweffect.cpp b/examples/graphicsview/lighting/shadoweffect.cpp
index c1d384a..e2dd864 100644
--- a/examples/graphicsview/lighting/shadoweffect.cpp
+++ b/examples/graphicsview/lighting/shadoweffect.cpp
@@ -43,14 +43,14 @@
#include <math.h>
-ShadowEffect::ShadowEffect(QGraphicsItem *source)
+ShadowEffect::ShadowEffect(QGraphicsItem *item, QGraphicsItem *source)
: QGraphicsShadowEffect()
- , m_lightSource(source)
+ , item(item), m_lightSource(source)
{
setBlurRadius(8);
}
-void ShadowEffect::adjustForItem(const QGraphicsItem *item)
+void ShadowEffect::adjustForItem()
{
QPointF delta = item->pos() - m_lightSource->pos();
setShadowOffset(delta.toPoint() / 30);
@@ -61,15 +61,14 @@ void ShadowEffect::adjustForItem(const QGraphicsItem *item)
setOpacity(qBound(0.4, 1 - dd / 200.0, 0.7));
}
-QRectF ShadowEffect::boundingRectFor(const QGraphicsItem *item)
+QRectF ShadowEffect::boundingRect() const
{
- adjustForItem(item);
- return QGraphicsShadowEffect::boundingRectFor(item);
+ const_cast<ShadowEffect *>(this)->adjustForItem();
+ return QGraphicsShadowEffect::boundingRect();
}
-void ShadowEffect::drawItem(QGraphicsItem *item, QPainter *painter,
- const QStyleOptionGraphicsItem *option, QWidget *widget)
+void ShadowEffect::draw(QPainter *painter)
{
- adjustForItem(item);
- QGraphicsShadowEffect::drawItem(item, painter, option, widget);
+ adjustForItem();
+ QGraphicsShadowEffect::draw(painter);
}
diff --git a/examples/graphicsview/lighting/shadoweffect.h b/examples/graphicsview/lighting/shadoweffect.h
index 09b63e3..d4aa440 100644
--- a/examples/graphicsview/lighting/shadoweffect.h
+++ b/examples/graphicsview/lighting/shadoweffect.h
@@ -48,18 +48,17 @@
class ShadowEffect: public QGraphicsShadowEffect
{
public:
- ShadowEffect(QGraphicsItem *source);
+ ShadowEffect(QGraphicsItem *item, QGraphicsItem *source);
- QRectF boundingRectFor(const QGraphicsItem *item);
+ QRectF boundingRect() const;
- void drawItem(QGraphicsItem *item, QPainter *painter,
- const QStyleOptionGraphicsItem *option = 0,
- QWidget *widget = 0);
+ void draw(QPainter *painter);
private:
- void adjustForItem(const QGraphicsItem *item);
+ void adjustForItem();
private:
+ QGraphicsItem *item;
QGraphicsItem *m_lightSource;
};