summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/graphicsview/blurpicker/blureffect.cpp70
-rw-r--r--examples/graphicsview/blurpicker/blureffect.h68
-rw-r--r--examples/graphicsview/blurpicker/blurpicker.cpp134
-rw-r--r--examples/graphicsview/blurpicker/blurpicker.h75
-rw-r--r--examples/graphicsview/blurpicker/blurpicker.pro9
-rw-r--r--examples/graphicsview/blurpicker/blurpicker.qrc14
-rw-r--r--examples/graphicsview/blurpicker/images/README.txt5
-rw-r--r--examples/graphicsview/blurpicker/images/accessories-calculator.pngbin0 -> 3760 bytes
-rw-r--r--examples/graphicsview/blurpicker/images/accessories-text-editor.pngbin0 -> 4746 bytes
-rw-r--r--examples/graphicsview/blurpicker/images/background.jpgbin0 -> 16259 bytes
-rw-r--r--examples/graphicsview/blurpicker/images/help-browser.pngbin0 -> 5392 bytes
-rw-r--r--examples/graphicsview/blurpicker/images/internet-group-chat.pngbin0 -> 2809 bytes
-rw-r--r--examples/graphicsview/blurpicker/images/internet-mail.pngbin0 -> 3899 bytes
-rw-r--r--examples/graphicsview/blurpicker/images/internet-web-browser.pngbin0 -> 6376 bytes
-rw-r--r--examples/graphicsview/blurpicker/images/office-calendar.pngbin0 -> 4010 bytes
-rw-r--r--examples/graphicsview/blurpicker/images/system-users.pngbin0 -> 5353 bytes
-rw-r--r--examples/graphicsview/blurpicker/main.cpp55
-rw-r--r--examples/graphicsview/graphicsview.pro2
-rw-r--r--examples/graphicsview/lighting/lighting.cpp121
-rw-r--r--examples/graphicsview/lighting/lighting.h71
-rw-r--r--examples/graphicsview/lighting/lighting.pro8
-rw-r--r--examples/graphicsview/lighting/main.cpp55
-rw-r--r--examples/graphicsview/lighting/shadoweffect.cpp75
-rw-r--r--examples/graphicsview/lighting/shadoweffect.h66
24 files changed, 828 insertions, 0 deletions
diff --git a/examples/graphicsview/blurpicker/blureffect.cpp b/examples/graphicsview/blurpicker/blureffect.cpp
new file mode 100644
index 000000000..8345d0b8e
--- /dev/null
+++ b/examples/graphicsview/blurpicker/blureffect.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "blureffect.h"
+
+#include <QDebug>
+
+BlurEffect::BlurEffect(QObject *parent)
+ : QGraphicsBlurEffect()
+ , m_baseLine(200)
+{
+}
+
+void BlurEffect::adjustForItem(const QGraphicsItem *item)
+{
+ qreal y = m_baseLine - item->pos().y();
+ qreal radius = qBound(0.0, y / 32, 16.0);
+ setBlurRadius(radius);
+}
+
+QRectF BlurEffect::boundingRectFor(const QGraphicsItem *item)
+{
+ adjustForItem(item);
+ return QGraphicsBlurEffect::boundingRectFor(item);
+}
+
+void BlurEffect::drawItem(QGraphicsItem *item, QPainter *painter,
+ const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ adjustForItem(item);
+ QGraphicsBlurEffect::drawItem(item, painter, option, widget);
+}
diff --git a/examples/graphicsview/blurpicker/blureffect.h b/examples/graphicsview/blurpicker/blureffect.h
new file mode 100644
index 000000000..24a686729
--- /dev/null
+++ b/examples/graphicsview/blurpicker/blureffect.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BLUREFFECT_H
+#define BLUREFFECT_H
+
+#include <QGraphicsEffect>
+#include <QGraphicsItem>
+
+class BlurEffect: public QGraphicsBlurEffect
+{
+public:
+ BlurEffect(QObject *parent = 0);
+
+ void setBaseLine(qreal y) { m_baseLine = y; }
+
+ QRectF boundingRectFor(const QGraphicsItem *item);
+
+ void drawItem(QGraphicsItem *item, QPainter *painter,
+ const QStyleOptionGraphicsItem *option = 0,
+ QWidget *widget = 0);
+
+private:
+ void adjustForItem(const QGraphicsItem *item);
+
+private:
+ qreal m_baseLine;
+};
+
+#endif // BLUREFFECT_H
diff --git a/examples/graphicsview/blurpicker/blurpicker.cpp b/examples/graphicsview/blurpicker/blurpicker.cpp
new file mode 100644
index 000000000..887d7ef88
--- /dev/null
+++ b/examples/graphicsview/blurpicker/blurpicker.cpp
@@ -0,0 +1,134 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "blurpicker.h"
+
+#include <QtGui>
+
+#include "blureffect.h"
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+BlurPicker::BlurPicker(QWidget *parent): QGraphicsView(parent), m_index(0.0)
+{
+ setBackgroundBrush(QPixmap(":/images/background.jpg"));
+ setScene(&m_scene);
+
+ setupScene();
+ updateIconPositions();
+
+ connect(&m_timeLine, SIGNAL(valueChanged(qreal)), SLOT(updateIconPositions()));
+ m_timeLine.setDuration(400);
+
+ setRenderHint(QPainter::Antialiasing, true);
+ setFrameStyle(QFrame::NoFrame);
+}
+
+void BlurPicker::updateIconPositions()
+{
+ m_index = m_timeLine.currentFrame() / 1000.0;
+
+ qreal baseline = 0;
+ for (int i = 0; i < m_icons.count(); ++i) {
+ QGraphicsItem *icon = m_icons[i];
+ qreal a = ((i + m_index) * 2 * M_PI) / m_icons.count();
+ qreal xs = 170 * sin(a);
+ qreal ys = 100 * cos(a);
+ QPointF pos(xs, ys);
+ pos = QTransform().rotate(-20).map(pos);
+ pos -= QPointF(40, 40);
+ icon->setPos(pos);
+ baseline = qMax(baseline, ys);
+ }
+
+ m_blurEffect->setBaseLine(baseline);
+ m_scene.update();
+}
+
+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";
+ names << ":/images/help-browser.png";
+ names << ":/images/internet-group-chat.png";
+ names << ":/images/internet-mail.png";
+ names << ":/images/internet-web-browser.png";
+ names << ":/images/office-calendar.png";
+ names << ":/images/system-users.png";
+
+ for (int i = 0; i < names.count(); i++) {
+ QPixmap pixmap(names[i]);
+ QGraphicsPixmapItem *icon = m_scene.addPixmap(pixmap);
+ icon->setZValue(1);
+ icon->setEffect(m_blurEffect);
+ m_icons << icon;
+ }
+
+ QGraphicsPixmapItem *bg = m_scene.addPixmap(QPixmap(":/images/background.jpg"));
+ bg->setZValue(0);
+ bg->setPos(-200, -150);
+}
+
+void BlurPicker::keyPressEvent(QKeyEvent *event)
+{
+ if (event->key() == Qt::Key_Left) {
+ if (m_timeLine.state() == QTimeLine::NotRunning) {
+ m_timeLine.setFrameRange(m_index * 1000, m_index * 1000 - 1000);
+ m_timeLine.start();
+ event->accept();
+ }
+ }
+
+ if (event->key() == Qt::Key_Right) {
+ if (m_timeLine.state() == QTimeLine::NotRunning) {
+ m_timeLine.setFrameRange(m_index * 1000, m_index * 1000 + 1000);
+ m_timeLine.start();
+ event->accept();
+ }
+ }
+}
diff --git a/examples/graphicsview/blurpicker/blurpicker.h b/examples/graphicsview/blurpicker/blurpicker.h
new file mode 100644
index 000000000..e41c608d6
--- /dev/null
+++ b/examples/graphicsview/blurpicker/blurpicker.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BLURPICKER_H
+#define BLURPICKER_H
+
+#include <QGraphicsEffect>
+#include <QGraphicsView>
+#include <QTimeLine>
+
+#include "blureffect.h"
+
+class BlurPicker: public QGraphicsView
+{
+ Q_OBJECT
+
+public:
+ BlurPicker(QWidget *parent = 0);
+
+protected:
+ void keyPressEvent(QKeyEvent *event);
+
+private slots:
+ void updateIconPositions();
+
+private:
+ void setupScene();
+
+private:
+ qreal m_index;
+ QGraphicsScene m_scene;
+ BlurEffect *m_blurEffect;
+ QList<QGraphicsItem*> m_icons;
+ QTimeLine m_timeLine;
+};
+
+#endif // BLURPICKER_H
diff --git a/examples/graphicsview/blurpicker/blurpicker.pro b/examples/graphicsview/blurpicker/blurpicker.pro
new file mode 100644
index 000000000..e42cc0f95
--- /dev/null
+++ b/examples/graphicsview/blurpicker/blurpicker.pro
@@ -0,0 +1,9 @@
+SOURCES += main.cpp blurpicker.cpp blureffect.cpp
+HEADERS += blurpicker.h blureffect.h
+RESOURCES += blurpicker.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/blurpicker
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS blurpicker.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/blurpicker
+INSTALLS += target sources
diff --git a/examples/graphicsview/blurpicker/blurpicker.qrc b/examples/graphicsview/blurpicker/blurpicker.qrc
new file mode 100644
index 000000000..e88eaca96
--- /dev/null
+++ b/examples/graphicsview/blurpicker/blurpicker.qrc
@@ -0,0 +1,14 @@
+<RCC>
+ <qresource prefix="/" >
+ <file>images/background.jpg</file>
+ <file>images/accessories-calculator.png</file>
+ <file>images/accessories-text-editor.png</file>
+ <file>images/help-browser.png</file>
+ <file>images/internet-group-chat.png</file>
+ <file>images/internet-mail.png</file>
+ <file>images/internet-web-browser.png</file>
+ <file>images/office-calendar.png</file>
+ <file>images/system-users.png</file>
+ </qresource>
+</RCC>
+
diff --git a/examples/graphicsview/blurpicker/images/README.txt b/examples/graphicsview/blurpicker/images/README.txt
new file mode 100644
index 000000000..0927e177d
--- /dev/null
+++ b/examples/graphicsview/blurpicker/images/README.txt
@@ -0,0 +1,5 @@
+The background is taken from a public domain photo at:
+http://www.photos8.com/view/computer_board2-800x600.html
+
+All other icons are from the Tango Desktop project:
+http://tango.freedesktop.org/Tango_Desktop_Project
diff --git a/examples/graphicsview/blurpicker/images/accessories-calculator.png b/examples/graphicsview/blurpicker/images/accessories-calculator.png
new file mode 100644
index 000000000..4e7661f65
--- /dev/null
+++ b/examples/graphicsview/blurpicker/images/accessories-calculator.png
Binary files differ
diff --git a/examples/graphicsview/blurpicker/images/accessories-text-editor.png b/examples/graphicsview/blurpicker/images/accessories-text-editor.png
new file mode 100644
index 000000000..33bef0bc1
--- /dev/null
+++ b/examples/graphicsview/blurpicker/images/accessories-text-editor.png
Binary files differ
diff --git a/examples/graphicsview/blurpicker/images/background.jpg b/examples/graphicsview/blurpicker/images/background.jpg
new file mode 100644
index 000000000..e75b38899
--- /dev/null
+++ b/examples/graphicsview/blurpicker/images/background.jpg
Binary files differ
diff --git a/examples/graphicsview/blurpicker/images/help-browser.png b/examples/graphicsview/blurpicker/images/help-browser.png
new file mode 100644
index 000000000..8ef4fae91
--- /dev/null
+++ b/examples/graphicsview/blurpicker/images/help-browser.png
Binary files differ
diff --git a/examples/graphicsview/blurpicker/images/internet-group-chat.png b/examples/graphicsview/blurpicker/images/internet-group-chat.png
new file mode 100644
index 000000000..dd92d9394
--- /dev/null
+++ b/examples/graphicsview/blurpicker/images/internet-group-chat.png
Binary files differ
diff --git a/examples/graphicsview/blurpicker/images/internet-mail.png b/examples/graphicsview/blurpicker/images/internet-mail.png
new file mode 100644
index 000000000..7e6b93be8
--- /dev/null
+++ b/examples/graphicsview/blurpicker/images/internet-mail.png
Binary files differ
diff --git a/examples/graphicsview/blurpicker/images/internet-web-browser.png b/examples/graphicsview/blurpicker/images/internet-web-browser.png
new file mode 100644
index 000000000..a979a92b4
--- /dev/null
+++ b/examples/graphicsview/blurpicker/images/internet-web-browser.png
Binary files differ
diff --git a/examples/graphicsview/blurpicker/images/office-calendar.png b/examples/graphicsview/blurpicker/images/office-calendar.png
new file mode 100644
index 000000000..e09590682
--- /dev/null
+++ b/examples/graphicsview/blurpicker/images/office-calendar.png
Binary files differ
diff --git a/examples/graphicsview/blurpicker/images/system-users.png b/examples/graphicsview/blurpicker/images/system-users.png
new file mode 100644
index 000000000..a7f630a5b
--- /dev/null
+++ b/examples/graphicsview/blurpicker/images/system-users.png
Binary files differ
diff --git a/examples/graphicsview/blurpicker/main.cpp b/examples/graphicsview/blurpicker/main.cpp
new file mode 100644
index 000000000..b88a51d79
--- /dev/null
+++ b/examples/graphicsview/blurpicker/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "blurpicker.h"
+#include <QApplication>
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ BlurPicker blurPicker;
+ blurPicker.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Application Picker"));
+ blurPicker.setFixedSize(400, 300);
+ blurPicker.show();
+
+ return app.exec();
+}
diff --git a/examples/graphicsview/graphicsview.pro b/examples/graphicsview/graphicsview.pro
index 66eb0b41f..185c85603 100644
--- a/examples/graphicsview/graphicsview.pro
+++ b/examples/graphicsview/graphicsview.pro
@@ -6,6 +6,8 @@ SUBDIRS = \
diagramscene \
dragdroprobot \
padnavigator \
+ lighting \
+ blurpicker \
basicgraphicslayouts
contains(QT_CONFIG, qt3support):SUBDIRS += portedcanvas portedasteroids
diff --git a/examples/graphicsview/lighting/lighting.cpp b/examples/graphicsview/lighting/lighting.cpp
new file mode 100644
index 000000000..445d7f964
--- /dev/null
+++ b/examples/graphicsview/lighting/lighting.cpp
@@ -0,0 +1,121 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "lighting.h"
+
+#include <QtGui>
+
+#include "shadoweffect.h"
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+Lighting::Lighting(QWidget *parent): QGraphicsView(parent), angle(0.0)
+{
+ setScene(&m_scene);
+
+ setupScene();
+
+ QTimer *timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), SLOT(animate()));
+ timer->setInterval(30);
+ timer->start();
+
+ setRenderHint(QPainter::Antialiasing, true);
+ setFrameStyle(QFrame::NoFrame);
+}
+
+void Lighting::setupScene()
+{
+ m_scene.setSceneRect(-300, -200, 600, 460);
+
+ QLinearGradient linearGrad(QPointF(-100, -100), QPointF(100, 100));
+ linearGrad.setColorAt(0, QColor(255, 255, 255));
+ linearGrad.setColorAt(1, QColor(192, 192, 255));
+ setBackgroundBrush(linearGrad);
+
+ QRadialGradient radialGrad(30, 30, 30);
+ radialGrad.setColorAt(0, Qt::yellow);
+ radialGrad.setColorAt(0.2, Qt::yellow);
+ radialGrad.setColorAt(1, Qt::transparent);
+ QPixmap pixmap(60, 60);
+ pixmap.fill(Qt::transparent);
+ QPainter painter(&pixmap);
+ painter.setPen(Qt::NoPen);
+ painter.setBrush(radialGrad);
+ painter.drawEllipse(0, 0, 60, 60);
+ painter.end();
+
+ 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;
+ if ((i + j) & 1)
+ item = new QGraphicsEllipseItem(0, 0, 50, 50);
+ else
+ item = new QGraphicsRectItem(0, 0, 50, 50);
+
+ item->setPen(QPen(Qt::black));
+ item->setBrush(QBrush(Qt::white));
+ item->setEffect(m_shadowEffect);
+ item->setZValue(1);
+ item->setPos(i * 80, j * 80);
+ m_scene.addItem(item);
+ m_items << item;
+ }
+
+
+}
+
+void Lighting::animate()
+{
+ angle += (M_PI / 30);
+ qreal xs = 200 * sin(angle) - 40 + 25;
+ qreal ys = 200 * cos(angle) - 40 + 25;
+ m_lightSource->setPos(xs, ys);
+ m_scene.update();
+}
+
diff --git a/examples/graphicsview/lighting/lighting.h b/examples/graphicsview/lighting/lighting.h
new file mode 100644
index 000000000..66237f61a
--- /dev/null
+++ b/examples/graphicsview/lighting/lighting.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef LIGHTING_H
+#define LIGHTING_H
+
+#include <QGraphicsEffect>
+#include <QGraphicsView>
+
+#include "shadoweffect.h"
+
+class Lighting: public QGraphicsView
+{
+ Q_OBJECT
+
+public:
+ Lighting(QWidget *parent = 0);
+
+private slots:
+ void animate();
+
+private:
+ void setupScene();
+
+private:
+ qreal angle;
+ QGraphicsScene m_scene;
+ QGraphicsItem *m_lightSource;
+ ShadowEffect *m_shadowEffect;
+ QList<QGraphicsItem*> m_items;
+};
+
+#endif // LIGHTING_H
diff --git a/examples/graphicsview/lighting/lighting.pro b/examples/graphicsview/lighting/lighting.pro
new file mode 100644
index 000000000..440bb53c7
--- /dev/null
+++ b/examples/graphicsview/lighting/lighting.pro
@@ -0,0 +1,8 @@
+SOURCES += main.cpp lighting.cpp shadoweffect.cpp
+HEADERS += lighting.h shadoweffect.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/lighting
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS lighting.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/lighting
+INSTALLS += target sources
diff --git a/examples/graphicsview/lighting/main.cpp b/examples/graphicsview/lighting/main.cpp
new file mode 100644
index 000000000..07415f68c
--- /dev/null
+++ b/examples/graphicsview/lighting/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "lighting.h"
+#include <QApplication>
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ Lighting lighting;
+ lighting.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Lighting and Shadows"));
+ lighting.resize(640, 480);
+ lighting.show();
+
+ return app.exec();
+}
diff --git a/examples/graphicsview/lighting/shadoweffect.cpp b/examples/graphicsview/lighting/shadoweffect.cpp
new file mode 100644
index 000000000..726cbd095
--- /dev/null
+++ b/examples/graphicsview/lighting/shadoweffect.cpp
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "shadoweffect.h"
+
+#include <math.h>
+
+ShadowEffect::ShadowEffect(QGraphicsItem *source, QObject *parent)
+ : QGraphicsShadowEffect(parent)
+ , m_lightSource(source)
+{
+ setBlurRadius(8);
+}
+
+void ShadowEffect::adjustForItem(const QGraphicsItem *item)
+{
+ QPointF delta = item->pos() - m_lightSource->pos();
+ setShadowOffset(delta.toPoint() / 30);
+
+ qreal dx = delta.x();
+ qreal dy = delta.y();
+ qreal dd = sqrt(dx * dx + dy * dy);
+ setOpacity(qBound(0.4, 1 - dd / 200.0, 0.7));
+}
+
+QRectF ShadowEffect::boundingRectFor(const QGraphicsItem *item)
+{
+ adjustForItem(item);
+ return QGraphicsShadowEffect::boundingRectFor(item);
+}
+
+void ShadowEffect::drawItem(QGraphicsItem *item, QPainter *painter,
+ const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ adjustForItem(item);
+ QGraphicsShadowEffect::drawItem(item, painter, option, widget);
+}
diff --git a/examples/graphicsview/lighting/shadoweffect.h b/examples/graphicsview/lighting/shadoweffect.h
new file mode 100644
index 000000000..02d0bf1fd
--- /dev/null
+++ b/examples/graphicsview/lighting/shadoweffect.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SHADOWEFFECT_H
+#define SHADOWEFFECT_H
+
+#include <QGraphicsEffect>
+#include <QGraphicsItem>
+
+class ShadowEffect: public QGraphicsShadowEffect
+{
+public:
+ ShadowEffect(QGraphicsItem *source, QObject *parent = 0);
+
+ QRectF boundingRectFor(const QGraphicsItem *item);
+
+ void drawItem(QGraphicsItem *item, QPainter *painter,
+ const QStyleOptionGraphicsItem *option = 0,
+ QWidget *widget = 0);
+
+private:
+ void adjustForItem(const QGraphicsItem *item);
+
+private:
+ QGraphicsItem *m_lightSource;
+};
+
+#endif // SHADOWEFFECT_H