summaryrefslogtreecommitdiffstats
path: root/examples/effects/lighting/lighting.cpp
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-09-01 14:31:33 (GMT)
committerBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-09-01 14:39:25 (GMT)
commit3dfde91fcbeaf304edd8d0d09e0732597055cd53 (patch)
tree09f5b3a0c75565bdde7736ace1bb4dbc3ea86060 /examples/effects/lighting/lighting.cpp
parent3418320aa5cad4a982f6278be1fbe8ce66c1558f (diff)
downloadQt-3dfde91fcbeaf304edd8d0d09e0732597055cd53.zip
Qt-3dfde91fcbeaf304edd8d0d09e0732597055cd53.tar.gz
Qt-3dfde91fcbeaf304edd8d0d09e0732597055cd53.tar.bz2
Cleanup examples/effects/lighting.
There's no need to re-implement QGraphicsDropShadowEffect anymore.
Diffstat (limited to 'examples/effects/lighting/lighting.cpp')
-rw-r--r--examples/effects/lighting/lighting.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/examples/effects/lighting/lighting.cpp b/examples/effects/lighting/lighting.cpp
index 2294b36..e309e2e 100644
--- a/examples/effects/lighting/lighting.cpp
+++ b/examples/effects/lighting/lighting.cpp
@@ -43,8 +43,6 @@
#include <QtGui>
-#include "shadoweffect.h"
-
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
@@ -98,7 +96,7 @@ void Lighting::setupScene()
item->setPen(QPen(Qt::black));
item->setBrush(QBrush(Qt::white));
- item->setGraphicsEffect(new ShadowEffect(item, m_lightSource));
+ item->setGraphicsEffect(new QGraphicsDropShadowEffect);
item->setZValue(1);
item->setPos(i * 80, j * 80);
m_scene.addItem(item);
@@ -114,6 +112,24 @@ void Lighting::animate()
qreal xs = 200 * sin(angle) - 40 + 25;
qreal ys = 200 * cos(angle) - 40 + 25;
m_lightSource->setPos(xs, ys);
+
+ for (int i = 0; i < m_items.size(); ++i) {
+ QGraphicsItem *item = m_items.at(i);
+ Q_ASSERT(item);
+ QGraphicsDropShadowEffect *effect = static_cast<QGraphicsDropShadowEffect *>(item->graphicsEffect());
+ Q_ASSERT(effect);
+
+ QPointF delta(item->x() - xs, item->y() - ys);
+ effect->setOffset(delta.toPoint() / 30);
+
+ qreal dx = delta.x();
+ qreal dy = delta.y();
+ qreal dd = sqrt(dx * dx + dy * dy);
+ QColor color = effect->color();
+ color.setAlphaF(qBound(0.4, 1 - dd / 200.0, 0.7));
+ effect->setColor(color);
+ }
+
m_scene.update();
}