diff options
author | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-07-24 02:51:31 (GMT) |
---|---|---|
committer | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-07-24 02:51:31 (GMT) |
commit | 610aa1737a206fe97628a3375a543400ea0761fa (patch) | |
tree | a1f1880feb2c868b6a30f6302a5b873badaf2b24 /examples | |
parent | 940b5bf333d6022fe5d3a037d6b1d74c6b9fe36e (diff) | |
download | Qt-610aa1737a206fe97628a3375a543400ea0761fa.zip Qt-610aa1737a206fe97628a3375a543400ea0761fa.tar.gz Qt-610aa1737a206fe97628a3375a543400ea0761fa.tar.bz2 |
Update QGraphicsShaderEffect to match new API
Diffstat (limited to 'examples')
6 files changed, 22 insertions, 28 deletions
diff --git a/examples/graphicsview/customshader/blureffect.cpp b/examples/graphicsview/customshader/blureffect.cpp index 8345d0b..43791c6 100644 --- a/examples/graphicsview/customshader/blureffect.cpp +++ b/examples/graphicsview/customshader/blureffect.cpp @@ -43,28 +43,27 @@ #include <QDebug> -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<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/customshader/blureffect.h b/examples/graphicsview/customshader/blureffect.h index 24a6867..2aea8bf 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 32bfc89..de80312 100644 --- a/examples/graphicsview/customshader/blurpicker.cpp +++ b/examples/graphicsview/customshader/blurpicker.cpp @@ -44,6 +44,7 @@ #include <QtGui> #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<BlurEffect *>(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 b4ac97b..b7ea3b4 100644 --- a/examples/graphicsview/customshader/blurpicker.h +++ b/examples/graphicsview/customshader/blurpicker.h @@ -47,7 +47,6 @@ #include <QTimeLine> #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<QGraphicsItem*> m_icons; QTimeLine m_timeLine; }; diff --git a/examples/graphicsview/customshader/customshadereffect.cpp b/examples/graphicsview/customshader/customshadereffect.cpp index 9f1945d..293123c 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 b4e0fb9..6482bd5 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); |