From 610aa1737a206fe97628a3375a543400ea0761fa Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Fri, 24 Jul 2009 12:51:31 +1000 Subject: Update QGraphicsShaderEffect to match new API --- examples/graphicsview/customshader/blureffect.cpp | 19 +++++++++---------- examples/graphicsview/customshader/blureffect.h | 11 +++++------ examples/graphicsview/customshader/blurpicker.cpp | 11 +++++------ examples/graphicsview/customshader/blurpicker.h | 3 --- .../graphicsview/customshader/customshadereffect.cpp | 4 ++-- .../graphicsview/customshader/customshadereffect.h | 2 +- 6 files changed, 22 insertions(+), 28 deletions(-) (limited to 'examples') diff --git a/examples/graphicsview/customshader/blureffect.cpp b/examples/graphicsview/customshader/blureffect.cpp index 8345d0b8e..43791c6fb 100644 --- a/examples/graphicsview/customshader/blureffect.cpp +++ b/examples/graphicsview/customshader/blureffect.cpp @@ -43,28 +43,27 @@ #include -BlurEffect::BlurEffect(QObject *parent) +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(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/customshader/blureffect.h b/examples/graphicsview/customshader/blureffect.h index 24a686729..2aea8bf33 100644 --- a/examples/graphicsview/customshader/blureffect.h +++ b/examples/graphicsview/customshader/blureffect.h @@ -48,21 +48,20 @@ class BlurEffect: public QGraphicsBlurEffect { public: - BlurEffect(QObject *parent = 0); + 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/customshader/blurpicker.cpp b/examples/graphicsview/customshader/blurpicker.cpp index 32bfc898d..de8031275 100644 --- a/examples/graphicsview/customshader/blurpicker.cpp +++ b/examples/graphicsview/customshader/blurpicker.cpp @@ -44,6 +44,7 @@ #include #include "blureffect.h" +#include "customshadereffect.h" #ifndef M_PI #define M_PI 3.14159265358979323846 @@ -79,9 +80,10 @@ void BlurPicker::updateIconPositions() pos -= QPointF(40, 40); icon->setPos(pos); baseline = qMax(baseline, ys); + if (i != 3) + static_cast(icon->graphicsEffect())->setBaseLine(baseline); } - m_blurEffect->setBaseLine(baseline); m_scene.update(); } @@ -89,9 +91,6 @@ void BlurPicker::setupScene() { m_scene.setSceneRect(-200, -120, 400, 240); - m_blurEffect = new BlurEffect(this); - m_customEffect = new CustomShaderEffect(this); - QStringList names; names << ":/images/accessories-calculator.png"; names << ":/images/accessories-text-editor.png"; @@ -107,9 +106,9 @@ void BlurPicker::setupScene() QGraphicsPixmapItem *icon = m_scene.addPixmap(pixmap); icon->setZValue(1); if (i == 3) - icon->setEffect(m_customEffect); + icon->setGraphicsEffect(new CustomShaderEffect()); else - icon->setEffect(m_blurEffect); + icon->setGraphicsEffect(new BlurEffect(icon)); m_icons << icon; } diff --git a/examples/graphicsview/customshader/blurpicker.h b/examples/graphicsview/customshader/blurpicker.h index b4ac97b70..b7ea3b4e0 100644 --- a/examples/graphicsview/customshader/blurpicker.h +++ b/examples/graphicsview/customshader/blurpicker.h @@ -47,7 +47,6 @@ #include #include "blureffect.h" -#include "customshadereffect.h" class BlurPicker: public QGraphicsView { @@ -68,8 +67,6 @@ private: private: qreal m_index; QGraphicsScene m_scene; - BlurEffect *m_blurEffect; - CustomShaderEffect *m_customEffect; QList m_icons; QTimeLine m_timeLine; }; diff --git a/examples/graphicsview/customshader/customshadereffect.cpp b/examples/graphicsview/customshader/customshadereffect.cpp index 9f1945d6e..293123c4b 100644 --- a/examples/graphicsview/customshader/customshadereffect.cpp +++ b/examples/graphicsview/customshader/customshadereffect.cpp @@ -53,8 +53,8 @@ static char const colorizeShaderCode[] = " return vec4(colorize.rgb, src.a);\n" "}"; -CustomShaderEffect::CustomShaderEffect(QObject *parent) - : QGraphicsShaderEffect(parent), +CustomShaderEffect::CustomShaderEffect() + : QGraphicsShaderEffect(), color(Qt::red) { setPixelShaderFragment(colorizeShaderCode); diff --git a/examples/graphicsview/customshader/customshadereffect.h b/examples/graphicsview/customshader/customshadereffect.h index b4e0fb9f0..6482bd540 100644 --- a/examples/graphicsview/customshader/customshadereffect.h +++ b/examples/graphicsview/customshader/customshadereffect.h @@ -49,7 +49,7 @@ class CustomShaderEffect: public QGraphicsShaderEffect { public: - CustomShaderEffect(QObject *parent = 0); + CustomShaderEffect(); QColor effectColor() const { return color; } void setEffectColor(const QColor& c); -- cgit v1.2.3