summaryrefslogtreecommitdiff
path: root/examples/painting
diff options
context:
space:
mode:
Diffstat (limited to 'examples/painting')
-rw-r--r--examples/painting/painting.pro2
-rw-r--r--examples/painting/svggenerator/displaywidget.cpp148
-rw-r--r--examples/painting/svggenerator/displaywidget.h79
-rw-r--r--examples/painting/svggenerator/forms/window.ui249
-rw-r--r--examples/painting/svggenerator/main.cpp51
-rw-r--r--examples/painting/svggenerator/resources/shapes.datbin0 -> 2088 bytes
-rw-r--r--examples/painting/svggenerator/svggenerator.pro22
-rw-r--r--examples/painting/svggenerator/svggenerator.qrc5
-rw-r--r--examples/painting/svggenerator/window.cpp100
-rw-r--r--examples/painting/svggenerator/window.h65
-rw-r--r--examples/painting/svgviewer/files/bubbles.svg215
-rw-r--r--examples/painting/svgviewer/files/cubic.svg77
-rw-r--r--examples/painting/svgviewer/files/spheres.svg72
-rw-r--r--examples/painting/svgviewer/main.cpp62
-rw-r--r--examples/painting/svgviewer/mainwindow.cpp163
-rw-r--r--examples/painting/svgviewer/mainwindow.h80
-rw-r--r--examples/painting/svgviewer/svgview.cpp188
-rw-r--r--examples/painting/svgviewer/svgview.h83
-rw-r--r--examples/painting/svgviewer/svgviewer.pro31
-rw-r--r--examples/painting/svgviewer/svgviewer.qrc6
20 files changed, 1698 insertions, 0 deletions
diff --git a/examples/painting/painting.pro b/examples/painting/painting.pro
new file mode 100644
index 0000000..1f1e54b
--- /dev/null
+++ b/examples/painting/painting.pro
@@ -0,0 +1,2 @@
+TEMPLATE = subdirs
+SUBDIRS += svgviewer svggenerator
diff --git a/examples/painting/svggenerator/displaywidget.cpp b/examples/painting/svggenerator/displaywidget.cpp
new file mode 100644
index 0000000..b99aa1f
--- /dev/null
+++ b/examples/painting/svggenerator/displaywidget.cpp
@@ -0,0 +1,148 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "displaywidget.h"
+
+DisplayWidget::DisplayWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ QPainterPath car;
+ QPainterPath house;
+
+ QFile file(":resources/shapes.dat");
+ file.open(QFile::ReadOnly);
+ QDataStream stream(&file);
+ stream >> car >> house >> tree >> moon;
+ file.close();
+
+ shapeMap[Car] = car;
+ shapeMap[House] = house;
+
+ background = Sky;
+ shapeColor = Qt::darkYellow;
+ shape = House;
+}
+
+//! [paint event]
+void DisplayWidget::paintEvent(QPaintEvent * /* event */)
+{
+ QPainter painter;
+ painter.begin(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+ paint(painter);
+ painter.end();
+}
+//! [paint event]
+
+//! [paint function]
+void DisplayWidget::paint(QPainter &painter)
+{
+//![paint picture]
+ painter.setClipRect(QRect(0, 0, 200, 200));
+ painter.setPen(Qt::NoPen);
+
+ switch (background) {
+ case Sky:
+ default:
+ painter.fillRect(QRect(0, 0, 200, 200), Qt::darkBlue);
+ painter.translate(145, 10);
+ painter.setBrush(Qt::white);
+ painter.drawPath(moon);
+ painter.translate(-145, -10);
+ break;
+ case Trees:
+ {
+ painter.fillRect(QRect(0, 0, 200, 200), Qt::darkGreen);
+ painter.setBrush(Qt::green);
+ painter.setPen(Qt::black);
+ for (int y = -55, row = 0; y < 200; y += 50, ++row) {
+ int xs;
+ if (row == 2 || row == 3)
+ xs = 150;
+ else
+ xs = 50;
+ for (int x = 0; x < 200; x += xs) {
+ painter.save();
+ painter.translate(x, y);
+ painter.drawPath(tree);
+ painter.restore();
+ }
+ }
+ break;
+ }
+ case Road:
+ painter.fillRect(QRect(0, 0, 200, 200), Qt::gray);
+ painter.setPen(QPen(Qt::white, 4, Qt::DashLine));
+ painter.drawLine(QLine(0, 35, 200, 35));
+ painter.drawLine(QLine(0, 165, 200, 165));
+ break;
+ }
+
+ painter.setBrush(shapeColor);
+ painter.setPen(Qt::black);
+ painter.translate(100, 100);
+ painter.drawPath(shapeMap[shape]);
+//![paint picture]
+}
+//! [paint function]
+
+QColor DisplayWidget::color() const
+{
+ return shapeColor;
+}
+
+void DisplayWidget::setBackground(Background background)
+{
+ this->background = background;
+ update();
+}
+
+void DisplayWidget::setColor(const QColor &color)
+{
+ this->shapeColor = color;
+ update();
+}
+
+void DisplayWidget::setShape(Shape shape)
+{
+ this->shape = shape;
+ update();
+}
diff --git a/examples/painting/svggenerator/displaywidget.h b/examples/painting/svggenerator/displaywidget.h
new file mode 100644
index 0000000..9252f48
--- /dev/null
+++ b/examples/painting/svggenerator/displaywidget.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DISPLAYWIDGET_H
+#define DISPLAYWIDGET_H
+
+#include <QColor>
+#include <QHash>
+#include <QWidget>
+
+//! [DisplayWidget class definition]
+class DisplayWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ enum Shape { House = 0, Car = 1 };
+ enum Background { Sky = 0, Trees = 1, Road = 2 };
+
+ DisplayWidget(QWidget *parent = 0);
+ QColor color() const;
+ void paint(QPainter &painter);
+
+public slots:
+ void setBackground(Background background);
+ void setColor(const QColor &color);
+ void setShape(Shape shape);
+
+protected:
+ void paintEvent(QPaintEvent *event);
+
+private:
+ Background background;
+ QColor shapeColor;
+ Shape shape;
+ QHash<Shape,QPainterPath> shapeMap;
+ QPainterPath moon;
+ QPainterPath tree;
+};
+//! [DisplayWidget class definition]
+
+#endif
diff --git a/examples/painting/svggenerator/forms/window.ui b/examples/painting/svggenerator/forms/window.ui
new file mode 100644
index 0000000..bf11908
--- /dev/null
+++ b/examples/painting/svggenerator/forms/window.ui
@@ -0,0 +1,249 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Window</class>
+ <widget class="QWidget" name="Window">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>339</width>
+ <height>353</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>SVG Generator</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <property name="sizeConstraint">
+ <enum>QLayout::SetFixedSize</enum>
+ </property>
+ <item row="0" column="0">
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="0" column="1">
+ <widget class="DisplayWidget" name="displayWidget" native="true">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>200</horstretch>
+ <verstretch>200</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>200</width>
+ <height>200</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>200</width>
+ <height>200</height>
+ </size>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <spacer name="horizontalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="1" column="0" colspan="3">
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>&amp;Shape:</string>
+ </property>
+ <property name="buddy">
+ <cstring>shapeComboBox</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QComboBox" name="shapeComboBox">
+ <item>
+ <property name="text">
+ <string>House</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Car</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>&amp;Color:</string>
+ </property>
+ <property name="buddy">
+ <cstring>colorButton</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QToolButton" name="colorButton">
+ <property name="text">
+ <string>Choose Color...</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>&amp;Background:</string>
+ </property>
+ <property name="buddy">
+ <cstring>shapeComboBox_2</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QComboBox" name="shapeComboBox_2">
+ <item>
+ <property name="text">
+ <string>Sky</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Trees</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Road</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="2" column="0" colspan="3">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QToolButton" name="toolButton_2">
+ <property name="text">
+ <string>Save &amp;As...</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>DisplayWidget</class>
+ <extends>QWidget</extends>
+ <header>displaywidget.h</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>shapeComboBox</sender>
+ <signal>currentIndexChanged(int)</signal>
+ <receiver>Window</receiver>
+ <slot>updateShape(int)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>288</x>
+ <y>232</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>336</x>
+ <y>234</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>colorButton</sender>
+ <signal>clicked()</signal>
+ <receiver>Window</receiver>
+ <slot>updateColor()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>301</x>
+ <y>262</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>337</x>
+ <y>267</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>shapeComboBox_2</sender>
+ <signal>currentIndexChanged(int)</signal>
+ <receiver>Window</receiver>
+ <slot>updateBackground(int)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>306</x>
+ <y>299</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>337</x>
+ <y>311</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>toolButton_2</sender>
+ <signal>clicked()</signal>
+ <receiver>Window</receiver>
+ <slot>saveSvg()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>298</x>
+ <y>336</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>307</x>
+ <y>348</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+ <slots>
+ <slot>updateBackground(int)</slot>
+ <slot>updateColor()</slot>
+ <slot>updateShape(int)</slot>
+ <slot>saveSvg()</slot>
+ </slots>
+</ui>
diff --git a/examples/painting/svggenerator/main.cpp b/examples/painting/svggenerator/main.cpp
new file mode 100644
index 0000000..f2079f5
--- /dev/null
+++ b/examples/painting/svggenerator/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "window.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Window window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/painting/svggenerator/resources/shapes.dat b/examples/painting/svggenerator/resources/shapes.dat
new file mode 100644
index 0000000..d9b981e
--- /dev/null
+++ b/examples/painting/svggenerator/resources/shapes.dat
Binary files differ
diff --git a/examples/painting/svggenerator/svggenerator.pro b/examples/painting/svggenerator/svggenerator.pro
new file mode 100644
index 0000000..074780a
--- /dev/null
+++ b/examples/painting/svggenerator/svggenerator.pro
@@ -0,0 +1,22 @@
+FORMS = forms/window.ui
+HEADERS = displaywidget.h \
+ window.h
+RESOURCES = svggenerator.qrc
+SOURCES = displaywidget.cpp \
+ main.cpp \
+ window.cpp
+
+QT += svg
+
+INCLUDEPATH += $$PWD
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtsvg/painting/svggenerator
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS svggenerator.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtsvg/painting/svggenerator
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000CF68
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/painting/svggenerator/svggenerator.qrc b/examples/painting/svggenerator/svggenerator.qrc
new file mode 100644
index 0000000..061d1f6
--- /dev/null
+++ b/examples/painting/svggenerator/svggenerator.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>resources/shapes.dat</file>
+</qresource>
+</RCC>
diff --git a/examples/painting/svggenerator/window.cpp b/examples/painting/svggenerator/window.cpp
new file mode 100644
index 0000000..f3e950e
--- /dev/null
+++ b/examples/painting/svggenerator/window.cpp
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QColorDialog>
+#include <QFileDialog>
+#include <QPainter>
+#include <QSvgGenerator>
+#include "window.h"
+#include "displaywidget.h"
+
+Window::Window(QWidget *parent)
+ : QWidget(parent)
+{
+ setupUi(this);
+}
+
+void Window::updateBackground(int background)
+{
+ displayWidget->setBackground(DisplayWidget::Background(background));
+}
+
+void Window::updateColor()
+{
+ QColor color = QColorDialog::getColor(displayWidget->color());
+ if (color.isValid())
+ displayWidget->setColor(color);
+}
+
+void Window::updateShape(int shape)
+{
+ displayWidget->setShape(DisplayWidget::Shape(shape));
+}
+
+//! [save SVG]
+void Window::saveSvg()
+{
+ QString newPath = QFileDialog::getSaveFileName(this, tr("Save SVG"),
+ path, tr("SVG files (*.svg)"));
+
+ if (newPath.isEmpty())
+ return;
+
+ path = newPath;
+
+//![configure SVG generator]
+ QSvgGenerator generator;
+ generator.setFileName(path);
+ generator.setSize(QSize(200, 200));
+ generator.setViewBox(QRect(0, 0, 200, 200));
+ generator.setTitle(tr("SVG Generator Example Drawing"));
+ generator.setDescription(tr("An SVG drawing created by the SVG Generator "
+ "Example provided with Qt."));
+//![configure SVG generator]
+//![begin painting]
+ QPainter painter;
+ painter.begin(&generator);
+//![begin painting]
+ displayWidget->paint(painter);
+//![end painting]
+ painter.end();
+//![end painting]
+}
+//! [save SVG]
diff --git a/examples/painting/svggenerator/window.h b/examples/painting/svggenerator/window.h
new file mode 100644
index 0000000..6637ec6
--- /dev/null
+++ b/examples/painting/svggenerator/window.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include "ui_window.h"
+
+//! [Window class definition]
+class Window : public QWidget, private Ui::Window
+{
+ Q_OBJECT
+
+public:
+ Window(QWidget *parent = 0);
+
+public slots:
+ void saveSvg();
+ void updateBackground(int background);
+ void updateColor();
+ void updateShape(int shape);
+
+private:
+ QString path;
+};
+//! [Window class definition]
+
+#endif
diff --git a/examples/painting/svgviewer/files/bubbles.svg b/examples/painting/svgviewer/files/bubbles.svg
new file mode 100644
index 0000000..5173012
--- /dev/null
+++ b/examples/painting/svgviewer/files/bubbles.svg
@@ -0,0 +1,215 @@
+<?xml version="1.0" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
+<svg width="20cm" height="15cm" viewBox="0 0 800 600"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink/"
+ baseProfile="tiny" version="1.2">
+ <title>Spheres</title>
+ <desc>Semi-transparent bubbles on a colored background.</desc>
+ <defs>
+ <!-- Create radial gradients for each bubble. -->
+ <radialGradient id="blueBubble" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" stop-opacity="1" />
+ <stop offset="25%" stop-color="#cdcdff" stop-opacity=".65" />
+ <stop offset="100%" stop-color="#cdaacd" stop-opacity=".75" />
+ </radialGradient>
+ <radialGradient id="redBubble" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" stop-opacity="1" />
+ <stop offset="25%" stop-color="#ffcdcd" stop-opacity=".65" />
+ <stop offset="100%" stop-color="#bbbb99" stop-opacity=".75" />
+ </radialGradient>
+ <radialGradient id="greenBubble" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" stop-opacity="1" />
+ <stop offset="25%" stop-color="#cdffcd" stop-opacity=".65" />
+ <stop offset="100%" stop-color="#99aaaa" stop-opacity=".75" />
+ </radialGradient>
+ <radialGradient id="yellowBubble" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" stop-opacity="1" />
+ <stop offset="25%" stop-color="#ffffcd" stop-opacity=".65" />
+ <stop offset="100%" stop-color="#bbbbaa" stop-opacity=".75" />
+ </radialGradient>
+ <radialGradient id="background" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="400" fx="250" fy="250">
+ <stop offset="0%" stop-color="#ffffee" />
+ <stop offset="100%" stop-color="#ccccaa" />
+ </radialGradient>
+ <linearGradient id="surface" gradientUnits="userSpaceOnUse"
+ x1="-100" y1="200" x2="400" y2="200">
+ <stop offset="0%" stop-color="#ffffcc" />
+ <stop offset="100%" stop-color="#bbbb88" />
+ </linearGradient>
+
+ <!-- Create radial gradients for each circle to make them look like
+ spheres. -->
+ <radialGradient id="blueSphere" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" />
+ <stop offset="75%" stop-color="blue" />
+ <stop offset="100%" stop-color="#222244" />
+ </radialGradient>
+ <radialGradient id="redSphere" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" />
+ <stop offset="75%" stop-color="red" />
+ <stop offset="100%" stop-color="#442222" />
+ </radialGradient>
+ <radialGradient id="greenSphere" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" />
+ <stop offset="75%" stop-color="green" />
+ <stop offset="100%" stop-color="#113311" />
+ </radialGradient>
+ <radialGradient id="yellowSphere" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" />
+ <stop offset="75%" stop-color="yellow" />
+ <stop offset="100%" stop-color="#444422" />
+ </radialGradient>
+ <radialGradient id="shadowGrad" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="50">
+ <stop offset="0%" stop-color="black" stop-opacity="1.0" />
+ <stop offset="100%" stop-color="black" stop-opacity="0.0" />
+ </radialGradient>
+
+ <!-- Define a shadow for each sphere. -->
+ <circle id="shadow" fill="url(#shadowGrad)" cx="0" cy="0" r="100" />
+ <g id="bubble">
+ <circle fill="black" cx="0" cy="0" r="50" />
+ <circle fill="#a6ce39" cx="0" cy="0" r="33" />
+ <path fill="black" d="M 37,50 L 50,37 L 12,-1 L 22,-11 L 10,-24 L -24,10
+ L -11,22 L -1,12 Z" />
+ <circle cx="0" cy="0" r="100" />
+ </g>
+ </defs>
+ <g>
+ <rect fill="url(#background)" x="0" y="0" width="800" height="600" />
+ </g>
+
+ <g transform="translate(200,700)">
+ <use xlink:href="#bubble" fill="url(#blueBubble)" />
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="1s" dur="10s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(315,700)">
+ <g transform="scale(0.5,0.5)">
+ <use xlink:href="#bubble" fill="url(#redBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="3s" dur="7s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(80,700)">
+ <g transform="scale(0.65,0.65)">
+ <use xlink:href="#bubble" fill="url(#greenBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="5s" dur="9s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(255,700)">
+ <g transform="scale(0.3,0.3)">
+ <use xlink:href="#bubble" fill="url(#yellowBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="2s" dur="6s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(565,700)">
+ <g transform="scale(0.4,0.4)">
+ <use xlink:href="#bubble" fill="url(#blueBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="4s" dur="8s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(715,700)">
+ <g transform="scale(0.6,0.6)">
+ <use xlink:href="#bubble" fill="url(#redBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="1s" dur="4s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(645,700)">
+ <g transform="scale(0.375,0.375)">
+ <use xlink:href="#bubble" fill="url(#greenBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="0s" dur="11s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(555,700)">
+ <g transform="scale(0.9,0.9)">
+ <use xlink:href="#bubble" fill="url(#yellowBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="3s" dur="7.5s" fill="freeze" repeatCount="indefinite" />
+ </g>
+
+ <g transform="translate(360,700)">
+ <g transform="scale(0.5,0.5)">
+ <use xlink:href="#bubble" fill="url(#blueBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="3s" dur="6s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(215,700)">
+ <g transform="scale(0.45,0.45)">
+ <use xlink:href="#bubble" fill="url(#redBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="5.5s" dur="7s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(420,700)">
+ <g transform="scale(0.75,0.75)">
+ <use xlink:href="#bubble" fill="url(#greenBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="1s" dur="9s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(815,700)">
+ <g transform="scale(0.6,0.6)">
+ <use xlink:href="#bubble" fill="url(#yellowBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="2s" dur="9.5s" fill="freeze" repeatCount="indefinite" />
+ </g>
+
+ <g transform="translate(225,375)" >
+ <g transform="scale(1.0,0.5)" >
+ <path d="M 0 0 L 350 0 L 450 450 L -100 450 z"
+ fill="url(#surface)" stroke="none" />
+ </g>
+ </g>
+ <g transform="translate(200,0)" >
+ <g transform="translate(200,490) scale(2.0,1.0) rotate(45)" >
+ <rect fill="#a6ce39" x="-69" y="-69" width="138" height="138" />
+ <circle fill="black" cx="0" cy="0" r="50" />
+ <circle fill="#a6ce39" cx="0" cy="0" r="33" />
+ <path fill="black" d="M 37,50 L 50,37 L 12,-1 L 22,-11 L 10,-24 L -24,10
+ L -11,22 L -1,12 Z" />
+ <animateTransform attributeName="transform" type="rotate" additive="sum" values="0; 360"
+ begin="0s" dur="10s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(200,375)">
+ <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" />
+ <circle fill="url(#blueSphere)" cx="0" cy="0" r="100" />
+ </g>
+ <g transform="translate(315,440)">
+ <g transform="scale(0.5,0.5)">
+ <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" />
+ <circle fill="url(#redSphere)" cx="0" cy="0" r="100" />
+ </g>
+ </g>
+ <g transform="translate(80,475)">
+ <g transform="scale(0.65,0.65)">
+ <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" />
+ <circle fill="url(#greenSphere)" cx="0" cy="0" r="100" />
+ </g>
+ </g>
+ <g transform="translate(255,525)">
+ <g transform="scale(0.3,0.3)">
+ <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" />
+ <circle fill="url(#yellowSphere)" cx="0" cy="0" r="100" />
+ </g>
+ </g>
+ </g>
+</svg>
diff --git a/examples/painting/svgviewer/files/cubic.svg b/examples/painting/svgviewer/files/cubic.svg
new file mode 100644
index 0000000..492bb72
--- /dev/null
+++ b/examples/painting/svgviewer/files/cubic.svg
@@ -0,0 +1,77 @@
+<?xml version="1.0" standalone="no"?>
+<svg width="10cm" height="10cm" viewBox="0 0 1000 1000"
+ xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny">
+ <title>Example cubic02 - cubic Bezier commands in path data</title>
+ <desc>Picture showing examples of "C" and "S" commands,
+ along with annotations showing the control points
+ and end points</desc>
+
+ <rect fill="none" stroke="blue" stroke-width="1" x="1" y="1" width="998" height="998" />
+
+ <!-- Path 1 -->
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="100,200 100,100" />
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="400,100 400,200" />
+ <path fill="none" stroke="red" stroke-width="5" d="M100,200 C100,100 400,100 400,200" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="100" cy="200" r="10" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="400" cy="200" r="10" />
+ <circle class="CtlPoint" cx="100" cy="100" r="10" />
+ <circle class="CtlPoint" cx="400" cy="100" r="10" />
+ <text text-anchor="middle" font-size="22" font-family="Verdana" x="250" y="275">M100,200 C100,100 400,100 400,200</text>
+
+ <!-- Path 2 -->
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="100,500 25,400" />
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="475,400 400,500" />
+ <path fill="none" stroke="red" stroke-width="5" d="M100,500 C25,400 475,400 400,500" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="100" cy="500" r="10" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="400" cy="500" r="10" />
+ <circle fill="#888888" stroke="none" cx="25" cy="400" r="10" />
+ <circle fill="#888888" stroke="none" cx="475" cy="400" r="10" />
+ <text text-anchor="middle" font-size="22" font-family="Verdana" x="250" y="575">M100,500 C25,400 475,400 400,500</text>
+
+ <!-- Path 3 -->
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="100,800 175,700" />
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="325,700 400,800" />
+ <path fill="none" stroke="red" stroke-width="5" d="M100,800 C175,700 325,700 400,800" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="100" cy="800" r="10" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="400" cy="800" r="10" />
+ <circle fill="#888888" stroke="none" cx="175" cy="700" r="10" />
+ <circle fill="#888888" stroke="none" cx="325" cy="700" r="10" />
+ <text text-anchor="middle" font-size="22" font-family="Verdana" x="250" y="875">M100,800 C175,700 325,700 400,800</text>
+
+ <!-- Path 4 -->
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="600,200 675,100" />
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="975,100 900,200" />
+ <path fill="none" stroke="red" stroke-width="5" d="M600,200 C675,100 975,100 900,200" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="600" cy="200" r="10" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="900" cy="200" r="10" />
+ <circle fill="#888888" stroke="none" cx="675" cy="100" r="10" />
+ <circle fill="#888888" stroke="none" cx="975" cy="100" r="10" />
+ <text text-anchor="middle" font-size="22" font-family="Verdana" x="750" y="275">M600,200 C675,100 975,100 900,200</text>
+
+ <!-- Path 5 -->
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="600,500 600,350" />
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="900,650 900,500" />
+ <path fill="none" stroke="red" stroke-width="5" d="M600,500 C600,350 900,650 900,500" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="600" cy="500" r="10" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="900" cy="500" r="10" />
+ <circle fill="#888888" stroke="none" cx="600" cy="350" r="10" />
+ <circle fill="#888888" stroke="none" cx="900" cy="650" r="10" />
+ <text text-anchor="middle" font-size="22" font-family="Verdana" x="750" y="575">M600,500 C600,350 900,650 900,500</text>
+
+ <!-- Path 6 (C and S command) -->
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="600,800 625,700" />
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="725,700 750,800" />
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="750,800 775,900" />
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="875,900 900,800" />
+ <path fill="none" stroke="red" stroke-width="5" d="M600,800 C625,700 725,700 750,800
+ S875,900 900,800" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="600" cy="800" r="10" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="750" cy="800" r="10" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="900" cy="800" r="10" />
+ <circle fill="#888888" stroke="none" cx="625" cy="700" r="10" />
+ <circle fill="#888888" stroke="none" cx="725" cy="700" r="10" />
+ <circle fill="#888888" stroke="none" cx="875" cy="900" r="10" />
+ <circle fill="none" stroke="blue" stroke-width="4" cx="775" cy="900" r="9" />
+ <text text-anchor="middle" font-size="22" font-family="Verdana" x="750" y="945">M600,800 C625,700 725,700 750,800</text>
+ <text text-anchor="middle" font-size="22" font-family="Verdana" x="750" y="975">S875,900 900,800</text>
+</svg>
diff --git a/examples/painting/svgviewer/files/spheres.svg b/examples/painting/svgviewer/files/spheres.svg
new file mode 100644
index 0000000..b23164b
--- /dev/null
+++ b/examples/painting/svgviewer/files/spheres.svg
@@ -0,0 +1,72 @@
+<?xml version="1.0" standalone="no"?>
+<svg width="8cm" height="8cm" viewBox="0 0 400 400"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink/"
+ baseProfile="tiny" version="1.2">
+ <title>Spheres</title>
+ <desc>Gradient filled spheres with different colors.</desc>
+ <defs>
+ <!-- Create radial gradients for each circle to make them look like
+ spheres. -->
+ <radialGradient id="blueSphere" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" />
+ <stop offset="75%" stop-color="blue" />
+ <stop offset="100%" stop-color="#222244" />
+ </radialGradient>
+ <radialGradient id="redSphere" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" />
+ <stop offset="75%" stop-color="red" />
+ <stop offset="100%" stop-color="#442222" />
+ </radialGradient>
+ <radialGradient id="greenSphere" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" />
+ <stop offset="75%" stop-color="green" />
+ <stop offset="100%" stop-color="#113311" />
+ </radialGradient>
+ <radialGradient id="yellowSphere" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" />
+ <stop offset="75%" stop-color="yellow" />
+ <stop offset="100%" stop-color="#444422" />
+ </radialGradient>
+ <radialGradient id="shadowGrad" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="50">
+ <stop offset="0%" stop-color="black" stop-opacity="1.0" />
+ <stop offset="100%" stop-color="white" stop-opacity="0.0" />
+ </radialGradient>
+
+ <!-- Define a shadow for each sphere. -->
+ <circle id="shadow" fill="url(#shadowGrad)" cx="0" cy="0" r="100" />
+ </defs>
+ <g fill="#ffee99" stroke="none" >
+ <rect x="0" y="0" width="400" height="400" />
+ </g>
+ <g fill="white" stroke="none" >
+ <rect x="0" y="175" width="400" height="225" />
+ </g>
+ <g transform="translate(200,175)">
+ <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" />
+ <circle fill="url(#blueSphere)" cx="0" cy="0" r="100" />
+ </g>
+ <g transform="translate(315,240)">
+ <g transform="scale(0.5,0.5)">
+ <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" />
+ <circle fill="url(#redSphere)" cx="0" cy="0" r="100" />
+ </g>
+ </g>
+ <g transform="translate(80,275)">
+ <g transform="scale(0.65,0.65)">
+ <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" />
+ <circle fill="url(#greenSphere)" cx="0" cy="0" r="100" />
+ </g>
+ </g>
+ <g transform="translate(255,325)">
+ <g transform="scale(0.3,0.3)">
+ <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" />
+ <circle fill="url(#yellowSphere)" cx="0" cy="0" r="100" />
+ </g>
+ </g>
+</svg>
diff --git a/examples/painting/svgviewer/main.cpp b/examples/painting/svgviewer/main.cpp
new file mode 100644
index 0000000..de5cc09
--- /dev/null
+++ b/examples/painting/svgviewer/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QString>
+#ifndef QT_NO_OPENGL
+#include <QGLFormat>
+#endif
+
+#include "mainwindow.h"
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(svgviewer);
+
+ QApplication app(argc, argv);
+
+ MainWindow window;
+ if (argc == 2)
+ window.openFile(argv[1]);
+ else
+ window.openFile(":/files/bubbles.svg");
+ window.show();
+ return app.exec();
+}
diff --git a/examples/painting/svgviewer/mainwindow.cpp b/examples/painting/svgviewer/mainwindow.cpp
new file mode 100644
index 0000000..3821e51
--- /dev/null
+++ b/examples/painting/svgviewer/mainwindow.cpp
@@ -0,0 +1,163 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+
+#include <QtGui>
+
+#include "svgview.h"
+
+MainWindow::MainWindow()
+ : QMainWindow()
+ , m_view(new SvgView)
+{
+ QMenu *fileMenu = new QMenu(tr("&File"), this);
+ QAction *openAction = fileMenu->addAction(tr("&Open..."));
+ openAction->setShortcut(QKeySequence(tr("Ctrl+O")));
+ QAction *quitAction = fileMenu->addAction(tr("E&xit"));
+ quitAction->setShortcuts(QKeySequence::Quit);
+
+ menuBar()->addMenu(fileMenu);
+
+ QMenu *viewMenu = new QMenu(tr("&View"), this);
+ m_backgroundAction = viewMenu->addAction(tr("&Background"));
+ m_backgroundAction->setEnabled(false);
+ m_backgroundAction->setCheckable(true);
+ m_backgroundAction->setChecked(false);
+ connect(m_backgroundAction, SIGNAL(toggled(bool)), m_view, SLOT(setViewBackground(bool)));
+
+ m_outlineAction = viewMenu->addAction(tr("&Outline"));
+ m_outlineAction->setEnabled(false);
+ m_outlineAction->setCheckable(true);
+ m_outlineAction->setChecked(true);
+ connect(m_outlineAction, SIGNAL(toggled(bool)), m_view, SLOT(setViewOutline(bool)));
+
+ menuBar()->addMenu(viewMenu);
+
+ QMenu *rendererMenu = new QMenu(tr("&Renderer"), this);
+ m_nativeAction = rendererMenu->addAction(tr("&Native"));
+ m_nativeAction->setCheckable(true);
+ m_nativeAction->setChecked(true);
+#ifndef QT_NO_OPENGL
+ m_glAction = rendererMenu->addAction(tr("&OpenGL"));
+ m_glAction->setCheckable(true);
+#endif
+ m_imageAction = rendererMenu->addAction(tr("&Image"));
+ m_imageAction->setCheckable(true);
+
+#ifndef QT_NO_OPENGL
+ rendererMenu->addSeparator();
+ m_highQualityAntialiasingAction = rendererMenu->addAction(tr("&High Quality Antialiasing"));
+ m_highQualityAntialiasingAction->setEnabled(false);
+ m_highQualityAntialiasingAction->setCheckable(true);
+ m_highQualityAntialiasingAction->setChecked(false);
+ connect(m_highQualityAntialiasingAction, SIGNAL(toggled(bool)), m_view, SLOT(setHighQualityAntialiasing(bool)));
+#endif
+
+ QActionGroup *rendererGroup = new QActionGroup(this);
+ rendererGroup->addAction(m_nativeAction);
+#ifndef QT_NO_OPENGL
+ rendererGroup->addAction(m_glAction);
+#endif
+ rendererGroup->addAction(m_imageAction);
+
+ menuBar()->addMenu(rendererMenu);
+
+ connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
+ connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+ connect(rendererGroup, SIGNAL(triggered(QAction*)),
+ this, SLOT(setRenderer(QAction*)));
+
+ setCentralWidget(m_view);
+ setWindowTitle(tr("SVG Viewer"));
+}
+
+void MainWindow::openFile(const QString &path)
+{
+ QString fileName;
+ if (path.isNull())
+ fileName = QFileDialog::getOpenFileName(this, tr("Open SVG File"),
+ m_currentPath, "SVG files (*.svg *.svgz *.svg.gz)");
+ else
+ fileName = path;
+
+ if (!fileName.isEmpty()) {
+ QFile file(fileName);
+ if (!file.exists()) {
+ QMessageBox::critical(this, tr("Open SVG File"),
+ QString("Could not open file '%1'.").arg(fileName));
+
+ m_outlineAction->setEnabled(false);
+ m_backgroundAction->setEnabled(false);
+ return;
+ }
+
+ m_view->openFile(file);
+
+ if (!fileName.startsWith(":/")) {
+ m_currentPath = fileName;
+ setWindowTitle(tr("%1 - SVGViewer").arg(m_currentPath));
+ }
+
+ m_outlineAction->setEnabled(true);
+ m_backgroundAction->setEnabled(true);
+
+ resize(m_view->sizeHint() + QSize(80, 80 + menuBar()->height()));
+ }
+}
+
+void MainWindow::setRenderer(QAction *action)
+{
+#ifndef QT_NO_OPENGL
+ m_highQualityAntialiasingAction->setEnabled(false);
+#endif
+
+ if (action == m_nativeAction)
+ m_view->setRenderer(SvgView::Native);
+#ifndef QT_NO_OPENGL
+ else if (action == m_glAction) {
+ m_highQualityAntialiasingAction->setEnabled(true);
+ m_view->setRenderer(SvgView::OpenGL);
+ }
+#endif
+ else if (action == m_imageAction) {
+ m_view->setRenderer(SvgView::Image);
+ }
+}
diff --git a/examples/painting/svgviewer/mainwindow.h b/examples/painting/svgviewer/mainwindow.h
new file mode 100644
index 0000000..eaf72e0
--- /dev/null
+++ b/examples/painting/svgviewer/mainwindow.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QString>
+
+class SvgView;
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QGraphicsView;
+class QGraphicsScene;
+class QGraphicsRectItem;
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+public slots:
+ void openFile(const QString &path = QString());
+ void setRenderer(QAction *action);
+
+private:
+ QAction *m_nativeAction;
+ QAction *m_glAction;
+ QAction *m_imageAction;
+ QAction *m_highQualityAntialiasingAction;
+ QAction *m_backgroundAction;
+ QAction *m_outlineAction;
+
+ SvgView *m_view;
+
+ QString m_currentPath;
+};
+
+#endif
diff --git a/examples/painting/svgviewer/svgview.cpp b/examples/painting/svgviewer/svgview.cpp
new file mode 100644
index 0000000..18f0821
--- /dev/null
+++ b/examples/painting/svgviewer/svgview.cpp
@@ -0,0 +1,188 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "svgview.h"
+
+#include <QFile>
+#include <QWheelEvent>
+#include <QMouseEvent>
+#include <QGraphicsRectItem>
+#include <QGraphicsSvgItem>
+#include <QPaintEvent>
+#include <qmath.h>
+
+#ifndef QT_NO_OPENGL
+#include <QGLWidget>
+#endif
+
+SvgView::SvgView(QWidget *parent)
+ : QGraphicsView(parent)
+ , m_renderer(Native)
+ , m_svgItem(0)
+ , m_backgroundItem(0)
+ , m_outlineItem(0)
+{
+ setScene(new QGraphicsScene(this));
+ setTransformationAnchor(AnchorUnderMouse);
+ setDragMode(ScrollHandDrag);
+ setViewportUpdateMode(FullViewportUpdate);
+
+ // Prepare background check-board pattern
+ QPixmap tilePixmap(64, 64);
+ tilePixmap.fill(Qt::white);
+ QPainter tilePainter(&tilePixmap);
+ QColor color(220, 220, 220);
+ tilePainter.fillRect(0, 0, 32, 32, color);
+ tilePainter.fillRect(32, 32, 32, 32, color);
+ tilePainter.end();
+
+ setBackgroundBrush(tilePixmap);
+}
+
+void SvgView::drawBackground(QPainter *p, const QRectF &)
+{
+ p->save();
+ p->resetTransform();
+ p->drawTiledPixmap(viewport()->rect(), backgroundBrush().texture());
+ p->restore();
+}
+
+void SvgView::openFile(const QFile &file)
+{
+ if (!file.exists())
+ return;
+
+ QGraphicsScene *s = scene();
+
+ bool drawBackground = (m_backgroundItem ? m_backgroundItem->isVisible() : false);
+ bool drawOutline = (m_outlineItem ? m_outlineItem->isVisible() : true);
+
+ s->clear();
+ resetTransform();
+
+ m_svgItem = new QGraphicsSvgItem(file.fileName());
+ m_svgItem->setFlags(QGraphicsItem::ItemClipsToShape);
+ m_svgItem->setCacheMode(QGraphicsItem::NoCache);
+ m_svgItem->setZValue(0);
+
+ m_backgroundItem = new QGraphicsRectItem(m_svgItem->boundingRect());
+ m_backgroundItem->setBrush(Qt::white);
+ m_backgroundItem->setPen(Qt::NoPen);
+ m_backgroundItem->setVisible(drawBackground);
+ m_backgroundItem->setZValue(-1);
+
+ m_outlineItem = new QGraphicsRectItem(m_svgItem->boundingRect());
+ QPen outline(Qt::black, 2, Qt::DashLine);
+ outline.setCosmetic(true);
+ m_outlineItem->setPen(outline);
+ m_outlineItem->setBrush(Qt::NoBrush);
+ m_outlineItem->setVisible(drawOutline);
+ m_outlineItem->setZValue(1);
+
+ s->addItem(m_backgroundItem);
+ s->addItem(m_svgItem);
+ s->addItem(m_outlineItem);
+
+ s->setSceneRect(m_outlineItem->boundingRect().adjusted(-10, -10, 10, 10));
+}
+
+void SvgView::setRenderer(RendererType type)
+{
+ m_renderer = type;
+
+ if (m_renderer == OpenGL) {
+#ifndef QT_NO_OPENGL
+ setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
+#endif
+ } else {
+ setViewport(new QWidget);
+ }
+}
+
+void SvgView::setHighQualityAntialiasing(bool highQualityAntialiasing)
+{
+#ifndef QT_NO_OPENGL
+ setRenderHint(QPainter::HighQualityAntialiasing, highQualityAntialiasing);
+#else
+ Q_UNUSED(highQualityAntialiasing);
+#endif
+}
+
+void SvgView::setViewBackground(bool enable)
+{
+ if (!m_backgroundItem)
+ return;
+
+ m_backgroundItem->setVisible(enable);
+}
+
+void SvgView::setViewOutline(bool enable)
+{
+ if (!m_outlineItem)
+ return;
+
+ m_outlineItem->setVisible(enable);
+}
+
+void SvgView::paintEvent(QPaintEvent *event)
+{
+ if (m_renderer == Image) {
+ if (m_image.size() != viewport()->size()) {
+ m_image = QImage(viewport()->size(), QImage::Format_ARGB32_Premultiplied);
+ }
+
+ QPainter imagePainter(&m_image);
+ QGraphicsView::render(&imagePainter);
+ imagePainter.end();
+
+ QPainter p(viewport());
+ p.drawImage(0, 0, m_image);
+
+ } else {
+ QGraphicsView::paintEvent(event);
+ }
+}
+
+void SvgView::wheelEvent(QWheelEvent *event)
+{
+ qreal factor = qPow(1.2, event->delta() / 240.0);
+ scale(factor, factor);
+ event->accept();
+}
+
diff --git a/examples/painting/svgviewer/svgview.h b/examples/painting/svgviewer/svgview.h
new file mode 100644
index 0000000..a9e24f0
--- /dev/null
+++ b/examples/painting/svgviewer/svgview.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SVGVIEW_H
+#define SVGVIEW_H
+
+#include <QGraphicsView>
+
+QT_BEGIN_NAMESPACE
+class QWheelEvent;
+class QPaintEvent;
+class QFile;
+QT_END_NAMESPACE
+
+class SvgView : public QGraphicsView
+{
+ Q_OBJECT
+
+public:
+ enum RendererType { Native, OpenGL, Image };
+
+ SvgView(QWidget *parent = 0);
+
+ void openFile(const QFile &file);
+ void setRenderer(RendererType type = Native);
+ void drawBackground(QPainter *p, const QRectF &rect);
+
+public slots:
+ void setHighQualityAntialiasing(bool highQualityAntialiasing);
+ void setViewBackground(bool enable);
+ void setViewOutline(bool enable);
+
+protected:
+ void wheelEvent(QWheelEvent *event);
+ void paintEvent(QPaintEvent *event);
+
+private:
+ RendererType m_renderer;
+
+ QGraphicsItem *m_svgItem;
+ QGraphicsRectItem *m_backgroundItem;
+ QGraphicsRectItem *m_outlineItem;
+
+ QImage m_image;
+};
+#endif // SVGVIEW_H
diff --git a/examples/painting/svgviewer/svgviewer.pro b/examples/painting/svgviewer/svgviewer.pro
new file mode 100644
index 0000000..d82c58b
--- /dev/null
+++ b/examples/painting/svgviewer/svgviewer.pro
@@ -0,0 +1,31 @@
+HEADERS = mainwindow.h \
+ svgview.h
+RESOURCES = svgviewer.qrc
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ svgview.cpp
+QT += svg xml
+
+contains(QT_CONFIG, opengl): QT += opengl
+
+CONFIG += console
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtsvg/painting/svgviewer
+sources.files = $$SOURCES $$HEADERS $$RESOURCES svgviewer.pro files
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtsvg/painting/svgviewer
+INSTALLS += target sources
+
+wince*: {
+ addFiles.files = files\\*.svg
+ addFiles.path = "\\My Documents"
+ DEPLOYMENT += addFiles
+}
+
+symbian: {
+ TARGET.UID3 = 0xA000A64E
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+ addFiles.files = files\\*.svg
+ addFiles.path = .
+ DEPLOYMENT += addFiles
+}
diff --git a/examples/painting/svgviewer/svgviewer.qrc b/examples/painting/svgviewer/svgviewer.qrc
new file mode 100644
index 0000000..db611f5
--- /dev/null
+++ b/examples/painting/svgviewer/svgviewer.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>files/bubbles.svg</file>
+</qresource>
+</RCC>
+