diff options
Diffstat (limited to 'examples/effects/lighting/lighting.cpp')
-rw-r--r-- | examples/effects/lighting/lighting.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/examples/effects/lighting/lighting.cpp b/examples/effects/lighting/lighting.cpp index 2294b369c4..e309e2ee64 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(); } |