summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-07-24 02:05:42 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-07-24 02:05:42 (GMT)
commit940b5bf333d6022fe5d3a037d6b1d74c6b9fe36e (patch)
treefe9efacdf7f836c596fa4231769b092650746f0b /examples
parent3b974f5b45429675630040224a3ce34b762cc360 (diff)
parente646d08593dc18cad4e59176c2fe8c10fa5b9497 (diff)
downloadQt-940b5bf333d6022fe5d3a037d6b1d74c6b9fe36e.zip
Qt-940b5bf333d6022fe5d3a037d6b1d74c6b9fe36e.tar.gz
Qt-940b5bf333d6022fe5d3a037d6b1d74c6b9fe36e.tar.bz2
Merge branch 'kinetic-graphicseffect' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-graphicseffect
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.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.cpp21
-rw-r--r--examples/graphicsview/lighting/shadoweffect.h11
8 files changed, 32 insertions, 42 deletions
diff --git a/examples/graphicsview/blurpicker/blureffect.cpp b/examples/graphicsview/blurpicker/blureffect.cpp
index 8345d0b..43791c6 100644
--- a/examples/graphicsview/blurpicker/blureffect.cpp
+++ b/examples/graphicsview/blurpicker/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/blurpicker/blureffect.h b/examples/graphicsview/blurpicker/blureffect.h
index 24a6867..2aea8bf 100644
--- a/examples/graphicsview/blurpicker/blureffect.h
+++ b/examples/graphicsview/blurpicker/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/blurpicker/blurpicker.cpp b/examples/graphicsview/blurpicker/blurpicker.cpp
index 887d7ef..9904dfa 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->graphicsEffect())->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(icon));
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..63f0a6c 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(item, 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..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, QObject *parent)
- : QGraphicsShadowEffect(parent)
- , m_lightSource(source)
+ShadowEffect::ShadowEffect(QGraphicsItem *item, QGraphicsItem *source)
+ : QGraphicsShadowEffect()
+ , 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 02d0bf1..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, QObject *parent = 0);
+ 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;
};