summaryrefslogtreecommitdiffstats
path: root/examples/painting
diff options
context:
space:
mode:
Diffstat (limited to 'examples/painting')
-rw-r--r--examples/painting/README42
-rw-r--r--examples/painting/basicdrawing/basicdrawing.pro17
-rw-r--r--examples/painting/basicdrawing/basicdrawing.qrc6
-rw-r--r--examples/painting/basicdrawing/images/brick.pngbin0 -> 767 bytes
-rw-r--r--examples/painting/basicdrawing/images/qt-logo.pngbin0 -> 3696 bytes
-rw-r--r--examples/painting/basicdrawing/main.cpp53
-rw-r--r--examples/painting/basicdrawing/renderarea.cpp207
-rw-r--r--examples/painting/basicdrawing/renderarea.h83
-rw-r--r--examples/painting/basicdrawing/window.cpp261
-rw-r--r--examples/painting/basicdrawing/window.h87
-rw-r--r--examples/painting/concentriccircles/circlewidget.cpp124
-rw-r--r--examples/painting/concentriccircles/circlewidget.h73
-rw-r--r--examples/painting/concentriccircles/concentriccircles.pro16
-rw-r--r--examples/painting/concentriccircles/main.cpp51
-rw-r--r--examples/painting/concentriccircles/window.cpp93
-rw-r--r--examples/painting/concentriccircles/window.h70
-rw-r--r--examples/painting/fontsampler/fontsampler.pro12
-rw-r--r--examples/painting/fontsampler/main.cpp51
-rw-r--r--examples/painting/fontsampler/mainwindow.cpp372
-rw-r--r--examples/painting/fontsampler/mainwindow.h82
-rw-r--r--examples/painting/fontsampler/mainwindowbase.ui140
-rw-r--r--examples/painting/imagecomposition/imagecomposer.cpp208
-rw-r--r--examples/painting/imagecomposition/imagecomposer.h87
-rw-r--r--examples/painting/imagecomposition/imagecomposition.pro15
-rw-r--r--examples/painting/imagecomposition/imagecomposition.qrc6
-rw-r--r--examples/painting/imagecomposition/images/background.pngbin0 -> 18579 bytes
-rw-r--r--examples/painting/imagecomposition/images/blackrectangle.pngbin0 -> 90 bytes
-rw-r--r--examples/painting/imagecomposition/images/butterfly.pngbin0 -> 36868 bytes
-rw-r--r--examples/painting/imagecomposition/images/checker.pngbin0 -> 10384 bytes
-rw-r--r--examples/painting/imagecomposition/main.cpp55
-rw-r--r--examples/painting/painterpaths/main.cpp51
-rw-r--r--examples/painting/painterpaths/painterpaths.pro17
-rw-r--r--examples/painting/painterpaths/renderarea.cpp130
-rw-r--r--examples/painting/painterpaths/renderarea.h80
-rw-r--r--examples/painting/painterpaths/window.cpp288
-rw-r--r--examples/painting/painterpaths/window.h92
-rw-r--r--examples/painting/painting.pro18
-rw-r--r--examples/painting/transformations/main.cpp51
-rw-r--r--examples/painting/transformations/renderarea.cpp172
-rw-r--r--examples/painting/transformations/renderarea.h90
-rw-r--r--examples/painting/transformations/transformations.pro16
-rw-r--r--examples/painting/transformations/window.cpp180
-rw-r--r--examples/painting/transformations/window.h80
43 files changed, 3476 insertions, 0 deletions
diff --git a/examples/painting/README b/examples/painting/README
new file mode 100644
index 0000000000..4f9dca0181
--- /dev/null
+++ b/examples/painting/README
@@ -0,0 +1,42 @@
+Qt's painting system is able to render vector graphics, images, and outline
+font-based text with sub-pixel accuracy accuracy using anti-aliasing to
+improve rendering quality.
+
+These examples show the most common techniques that are used when painting
+with Qt, from basic concepts such as drawing simple primitives to the use of
+transformations.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/painting/basicdrawing/basicdrawing.pro b/examples/painting/basicdrawing/basicdrawing.pro
new file mode 100644
index 0000000000..0e5d3f68b8
--- /dev/null
+++ b/examples/painting/basicdrawing/basicdrawing.pro
@@ -0,0 +1,17 @@
+HEADERS = renderarea.h \
+ window.h
+SOURCES = main.cpp \
+ renderarea.cpp \
+ window.cpp
+RESOURCES = basicdrawing.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/basicdrawing
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS basicdrawing.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/basicdrawing
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000A649
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/painting/basicdrawing/basicdrawing.qrc b/examples/painting/basicdrawing/basicdrawing.qrc
new file mode 100644
index 0000000000..9d8a23a1c8
--- /dev/null
+++ b/examples/painting/basicdrawing/basicdrawing.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/brick.png</file>
+ <file>images/qt-logo.png</file>
+</qresource>
+</RCC>
diff --git a/examples/painting/basicdrawing/images/brick.png b/examples/painting/basicdrawing/images/brick.png
new file mode 100644
index 0000000000..87e7df5b04
--- /dev/null
+++ b/examples/painting/basicdrawing/images/brick.png
Binary files differ
diff --git a/examples/painting/basicdrawing/images/qt-logo.png b/examples/painting/basicdrawing/images/qt-logo.png
new file mode 100644
index 0000000000..a8b452e07a
--- /dev/null
+++ b/examples/painting/basicdrawing/images/qt-logo.png
Binary files differ
diff --git a/examples/painting/basicdrawing/main.cpp b/examples/painting/basicdrawing/main.cpp
new file mode 100644
index 0000000000..6662742166
--- /dev/null
+++ b/examples/painting/basicdrawing/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** 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[])
+{
+ Q_INIT_RESOURCE(basicdrawing);
+
+ QApplication app(argc, argv);
+ Window window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/painting/basicdrawing/renderarea.cpp b/examples/painting/basicdrawing/renderarea.cpp
new file mode 100644
index 0000000000..0906159e0e
--- /dev/null
+++ b/examples/painting/basicdrawing/renderarea.cpp
@@ -0,0 +1,207 @@
+/****************************************************************************
+**
+** 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 "renderarea.h"
+
+//! [0]
+RenderArea::RenderArea(QWidget *parent)
+ : QWidget(parent)
+{
+ shape = Polygon;
+ antialiased = false;
+ transformed = false;
+ pixmap.load(":/images/qt-logo.png");
+
+ setBackgroundRole(QPalette::Base);
+ setAutoFillBackground(true);
+}
+//! [0]
+
+//! [1]
+QSize RenderArea::minimumSizeHint() const
+{
+ return QSize(100, 100);
+}
+//! [1]
+
+//! [2]
+QSize RenderArea::sizeHint() const
+{
+ return QSize(400, 200);
+}
+//! [2]
+
+//! [3]
+void RenderArea::setShape(Shape shape)
+{
+ this->shape = shape;
+ update();
+}
+//! [3]
+
+//! [4]
+void RenderArea::setPen(const QPen &pen)
+{
+ this->pen = pen;
+ update();
+}
+//! [4]
+
+//! [5]
+void RenderArea::setBrush(const QBrush &brush)
+{
+ this->brush = brush;
+ update();
+}
+//! [5]
+
+//! [6]
+void RenderArea::setAntialiased(bool antialiased)
+{
+ this->antialiased = antialiased;
+ update();
+}
+//! [6]
+
+//! [7]
+void RenderArea::setTransformed(bool transformed)
+{
+ this->transformed = transformed;
+ update();
+}
+//! [7]
+
+//! [8]
+void RenderArea::paintEvent(QPaintEvent * /* event */)
+{
+ static const QPoint points[4] = {
+ QPoint(10, 80),
+ QPoint(20, 10),
+ QPoint(80, 30),
+ QPoint(90, 70)
+ };
+
+ QRect rect(10, 20, 80, 60);
+
+ QPainterPath path;
+ path.moveTo(20, 80);
+ path.lineTo(20, 30);
+ path.cubicTo(80, 0, 50, 50, 80, 80);
+
+ int startAngle = 20 * 16;
+ int arcLength = 120 * 16;
+//! [8]
+
+//! [9]
+ QPainter painter(this);
+ painter.setPen(pen);
+ painter.setBrush(brush);
+ if (antialiased)
+ painter.setRenderHint(QPainter::Antialiasing, true);
+//! [9]
+
+//! [10]
+ for (int x = 0; x < width(); x += 100) {
+ for (int y = 0; y < height(); y += 100) {
+ painter.save();
+ painter.translate(x, y);
+//! [10] //! [11]
+ if (transformed) {
+ painter.translate(50, 50);
+ painter.rotate(60.0);
+ painter.scale(0.6, 0.9);
+ painter.translate(-50, -50);
+ }
+//! [11]
+
+//! [12]
+ switch (shape) {
+ case Line:
+ painter.drawLine(rect.bottomLeft(), rect.topRight());
+ break;
+ case Points:
+ painter.drawPoints(points, 4);
+ break;
+ case Polyline:
+ painter.drawPolyline(points, 4);
+ break;
+ case Polygon:
+ painter.drawPolygon(points, 4);
+ break;
+ case Rect:
+ painter.drawRect(rect);
+ break;
+ case RoundedRect:
+ painter.drawRoundedRect(rect, 25, 25, Qt::RelativeSize);
+ break;
+ case Ellipse:
+ painter.drawEllipse(rect);
+ break;
+ case Arc:
+ painter.drawArc(rect, startAngle, arcLength);
+ break;
+ case Chord:
+ painter.drawChord(rect, startAngle, arcLength);
+ break;
+ case Pie:
+ painter.drawPie(rect, startAngle, arcLength);
+ break;
+ case Path:
+ painter.drawPath(path);
+ break;
+ case Text:
+ painter.drawText(rect, Qt::AlignCenter, tr("Qt by\nNokia"));
+ break;
+ case Pixmap:
+ painter.drawPixmap(10, 10, pixmap);
+ }
+//! [12] //! [13]
+ painter.restore();
+ }
+ }
+
+ painter.setRenderHint(QPainter::Antialiasing, false);
+ painter.setPen(palette().dark().color());
+ painter.setBrush(Qt::NoBrush);
+ painter.drawRect(QRect(0, 0, width() - 1, height() - 1));
+}
+//! [13]
diff --git a/examples/painting/basicdrawing/renderarea.h b/examples/painting/basicdrawing/renderarea.h
new file mode 100644
index 0000000000..02e9b268f5
--- /dev/null
+++ b/examples/painting/basicdrawing/renderarea.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 RENDERAREA_H
+#define RENDERAREA_H
+
+#include <QBrush>
+#include <QPen>
+#include <QPixmap>
+#include <QWidget>
+
+//! [0]
+class RenderArea : public QWidget
+{
+ Q_OBJECT
+
+public:
+ enum Shape { Line, Points, Polyline, Polygon, Rect, RoundedRect, Ellipse, Arc,
+ Chord, Pie, Path, Text, Pixmap };
+
+ RenderArea(QWidget *parent = 0);
+
+ QSize minimumSizeHint() const;
+ QSize sizeHint() const;
+
+public slots:
+ void setShape(Shape shape);
+ void setPen(const QPen &pen);
+ void setBrush(const QBrush &brush);
+ void setAntialiased(bool antialiased);
+ void setTransformed(bool transformed);
+
+protected:
+ void paintEvent(QPaintEvent *event);
+
+private:
+ Shape shape;
+ QPen pen;
+ QBrush brush;
+ bool antialiased;
+ bool transformed;
+ QPixmap pixmap;
+};
+//! [0]
+
+#endif
diff --git a/examples/painting/basicdrawing/window.cpp b/examples/painting/basicdrawing/window.cpp
new file mode 100644
index 0000000000..54422a0104
--- /dev/null
+++ b/examples/painting/basicdrawing/window.cpp
@@ -0,0 +1,261 @@
+/****************************************************************************
+**
+** 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 "renderarea.h"
+#include "window.h"
+
+//! [0]
+const int IdRole = Qt::UserRole;
+//! [0]
+
+//! [1]
+Window::Window()
+{
+ renderArea = new RenderArea;
+
+ shapeComboBox = new QComboBox;
+ shapeComboBox->addItem(tr("Polygon"), RenderArea::Polygon);
+ shapeComboBox->addItem(tr("Rectangle"), RenderArea::Rect);
+ shapeComboBox->addItem(tr("Rounded Rectangle"), RenderArea::RoundedRect);
+ shapeComboBox->addItem(tr("Ellipse"), RenderArea::Ellipse);
+ shapeComboBox->addItem(tr("Pie"), RenderArea::Pie);
+ shapeComboBox->addItem(tr("Chord"), RenderArea::Chord);
+ shapeComboBox->addItem(tr("Path"), RenderArea::Path);
+ shapeComboBox->addItem(tr("Line"), RenderArea::Line);
+ shapeComboBox->addItem(tr("Polyline"), RenderArea::Polyline);
+ shapeComboBox->addItem(tr("Arc"), RenderArea::Arc);
+ shapeComboBox->addItem(tr("Points"), RenderArea::Points);
+ shapeComboBox->addItem(tr("Text"), RenderArea::Text);
+ shapeComboBox->addItem(tr("Pixmap"), RenderArea::Pixmap);
+
+ shapeLabel = new QLabel(tr("&Shape:"));
+ shapeLabel->setBuddy(shapeComboBox);
+//! [1]
+
+//! [2]
+ penWidthSpinBox = new QSpinBox;
+ penWidthSpinBox->setRange(0, 20);
+ penWidthSpinBox->setSpecialValueText(tr("0 (cosmetic pen)"));
+
+ penWidthLabel = new QLabel(tr("Pen &Width:"));
+ penWidthLabel->setBuddy(penWidthSpinBox);
+//! [2]
+
+//! [3]
+ penStyleComboBox = new QComboBox;
+ penStyleComboBox->addItem(tr("Solid"), Qt::SolidLine);
+ penStyleComboBox->addItem(tr("Dash"), Qt::DashLine);
+ penStyleComboBox->addItem(tr("Dot"), Qt::DotLine);
+ penStyleComboBox->addItem(tr("Dash Dot"), Qt::DashDotLine);
+ penStyleComboBox->addItem(tr("Dash Dot Dot"), Qt::DashDotDotLine);
+ penStyleComboBox->addItem(tr("None"), Qt::NoPen);
+
+ penStyleLabel = new QLabel(tr("&Pen Style:"));
+ penStyleLabel->setBuddy(penStyleComboBox);
+
+ penCapComboBox = new QComboBox;
+ penCapComboBox->addItem(tr("Flat"), Qt::FlatCap);
+ penCapComboBox->addItem(tr("Square"), Qt::SquareCap);
+ penCapComboBox->addItem(tr("Round"), Qt::RoundCap);
+
+ penCapLabel = new QLabel(tr("Pen &Cap:"));
+ penCapLabel->setBuddy(penCapComboBox);
+
+ penJoinComboBox = new QComboBox;
+ penJoinComboBox->addItem(tr("Miter"), Qt::MiterJoin);
+ penJoinComboBox->addItem(tr("Bevel"), Qt::BevelJoin);
+ penJoinComboBox->addItem(tr("Round"), Qt::RoundJoin);
+
+ penJoinLabel = new QLabel(tr("Pen &Join:"));
+ penJoinLabel->setBuddy(penJoinComboBox);
+//! [3]
+
+//! [4]
+ brushStyleComboBox = new QComboBox;
+ brushStyleComboBox->addItem(tr("Linear Gradient"),
+ Qt::LinearGradientPattern);
+ brushStyleComboBox->addItem(tr("Radial Gradient"),
+ Qt::RadialGradientPattern);
+ brushStyleComboBox->addItem(tr("Conical Gradient"),
+ Qt::ConicalGradientPattern);
+ brushStyleComboBox->addItem(tr("Texture"), Qt::TexturePattern);
+ brushStyleComboBox->addItem(tr("Solid"), Qt::SolidPattern);
+ brushStyleComboBox->addItem(tr("Horizontal"), Qt::HorPattern);
+ brushStyleComboBox->addItem(tr("Vertical"), Qt::VerPattern);
+ brushStyleComboBox->addItem(tr("Cross"), Qt::CrossPattern);
+ brushStyleComboBox->addItem(tr("Backward Diagonal"), Qt::BDiagPattern);
+ brushStyleComboBox->addItem(tr("Forward Diagonal"), Qt::FDiagPattern);
+ brushStyleComboBox->addItem(tr("Diagonal Cross"), Qt::DiagCrossPattern);
+ brushStyleComboBox->addItem(tr("Dense 1"), Qt::Dense1Pattern);
+ brushStyleComboBox->addItem(tr("Dense 2"), Qt::Dense2Pattern);
+ brushStyleComboBox->addItem(tr("Dense 3"), Qt::Dense3Pattern);
+ brushStyleComboBox->addItem(tr("Dense 4"), Qt::Dense4Pattern);
+ brushStyleComboBox->addItem(tr("Dense 5"), Qt::Dense5Pattern);
+ brushStyleComboBox->addItem(tr("Dense 6"), Qt::Dense6Pattern);
+ brushStyleComboBox->addItem(tr("Dense 7"), Qt::Dense7Pattern);
+ brushStyleComboBox->addItem(tr("None"), Qt::NoBrush);
+
+ brushStyleLabel = new QLabel(tr("&Brush Style:"));
+ brushStyleLabel->setBuddy(brushStyleComboBox);
+//! [4]
+
+//! [5]
+ otherOptionsLabel = new QLabel(tr("Other Options:"));
+//! [5] //! [6]
+ antialiasingCheckBox = new QCheckBox(tr("&Antialiasing"));
+//! [6] //! [7]
+ transformationsCheckBox = new QCheckBox(tr("&Transformations"));
+//! [7]
+
+//! [8]
+ connect(shapeComboBox, SIGNAL(activated(int)),
+ this, SLOT(shapeChanged()));
+ connect(penWidthSpinBox, SIGNAL(valueChanged(int)),
+ this, SLOT(penChanged()));
+ connect(penStyleComboBox, SIGNAL(activated(int)),
+ this, SLOT(penChanged()));
+ connect(penCapComboBox, SIGNAL(activated(int)),
+ this, SLOT(penChanged()));
+ connect(penJoinComboBox, SIGNAL(activated(int)),
+ this, SLOT(penChanged()));
+ connect(brushStyleComboBox, SIGNAL(activated(int)),
+ this, SLOT(brushChanged()));
+ connect(antialiasingCheckBox, SIGNAL(toggled(bool)),
+ renderArea, SLOT(setAntialiased(bool)));
+ connect(transformationsCheckBox, SIGNAL(toggled(bool)),
+ renderArea, SLOT(setTransformed(bool)));
+//! [8]
+
+//! [9]
+ QGridLayout *mainLayout = new QGridLayout;
+//! [9] //! [10]
+ mainLayout->setColumnStretch(0, 1);
+ mainLayout->setColumnStretch(3, 1);
+ mainLayout->addWidget(renderArea, 0, 0, 1, 4);
+ mainLayout->setRowMinimumHeight(1, 6);
+ mainLayout->addWidget(shapeLabel, 2, 1, Qt::AlignRight);
+ mainLayout->addWidget(shapeComboBox, 2, 2);
+ mainLayout->addWidget(penWidthLabel, 3, 1, Qt::AlignRight);
+ mainLayout->addWidget(penWidthSpinBox, 3, 2);
+ mainLayout->addWidget(penStyleLabel, 4, 1, Qt::AlignRight);
+ mainLayout->addWidget(penStyleComboBox, 4, 2);
+ mainLayout->addWidget(penCapLabel, 5, 1, Qt::AlignRight);
+ mainLayout->addWidget(penCapComboBox, 5, 2);
+ mainLayout->addWidget(penJoinLabel, 6, 1, Qt::AlignRight);
+ mainLayout->addWidget(penJoinComboBox, 6, 2);
+ mainLayout->addWidget(brushStyleLabel, 7, 1, Qt::AlignRight);
+ mainLayout->addWidget(brushStyleComboBox, 7, 2);
+ mainLayout->setRowMinimumHeight(8, 6);
+ mainLayout->addWidget(otherOptionsLabel, 9, 1, Qt::AlignRight);
+ mainLayout->addWidget(antialiasingCheckBox, 9, 2);
+ mainLayout->addWidget(transformationsCheckBox, 10, 2);
+ setLayout(mainLayout);
+
+ shapeChanged();
+ penChanged();
+ brushChanged();
+ antialiasingCheckBox->setChecked(true);
+
+ setWindowTitle(tr("Basic Drawing"));
+}
+//! [10]
+
+//! [11]
+void Window::shapeChanged()
+{
+ RenderArea::Shape shape = RenderArea::Shape(shapeComboBox->itemData(
+ shapeComboBox->currentIndex(), IdRole).toInt());
+ renderArea->setShape(shape);
+}
+//! [11]
+
+//! [12]
+void Window::penChanged()
+{
+ int width = penWidthSpinBox->value();
+ Qt::PenStyle style = Qt::PenStyle(penStyleComboBox->itemData(
+ penStyleComboBox->currentIndex(), IdRole).toInt());
+ Qt::PenCapStyle cap = Qt::PenCapStyle(penCapComboBox->itemData(
+ penCapComboBox->currentIndex(), IdRole).toInt());
+ Qt::PenJoinStyle join = Qt::PenJoinStyle(penJoinComboBox->itemData(
+ penJoinComboBox->currentIndex(), IdRole).toInt());
+
+ renderArea->setPen(QPen(Qt::blue, width, style, cap, join));
+}
+//! [12]
+
+//! [13]
+void Window::brushChanged()
+{
+ Qt::BrushStyle style = Qt::BrushStyle(brushStyleComboBox->itemData(
+//! [13]
+ brushStyleComboBox->currentIndex(), IdRole).toInt());
+
+//! [14]
+ if (style == Qt::LinearGradientPattern) {
+ QLinearGradient linearGradient(0, 0, 100, 100);
+ linearGradient.setColorAt(0.0, Qt::white);
+ linearGradient.setColorAt(0.2, Qt::green);
+ linearGradient.setColorAt(1.0, Qt::black);
+ renderArea->setBrush(linearGradient);
+//! [14] //! [15]
+ } else if (style == Qt::RadialGradientPattern) {
+ QRadialGradient radialGradient(50, 50, 50, 70, 70);
+ radialGradient.setColorAt(0.0, Qt::white);
+ radialGradient.setColorAt(0.2, Qt::green);
+ radialGradient.setColorAt(1.0, Qt::black);
+ renderArea->setBrush(radialGradient);
+ } else if (style == Qt::ConicalGradientPattern) {
+ QConicalGradient conicalGradient(50, 50, 150);
+ conicalGradient.setColorAt(0.0, Qt::white);
+ conicalGradient.setColorAt(0.2, Qt::green);
+ conicalGradient.setColorAt(1.0, Qt::black);
+ renderArea->setBrush(conicalGradient);
+//! [15] //! [16]
+ } else if (style == Qt::TexturePattern) {
+ renderArea->setBrush(QBrush(QPixmap(":/images/brick.png")));
+//! [16] //! [17]
+ } else {
+ renderArea->setBrush(QBrush(Qt::green, style));
+ }
+}
+//! [17]
diff --git a/examples/painting/basicdrawing/window.h b/examples/painting/basicdrawing/window.h
new file mode 100644
index 0000000000..2f939fb741
--- /dev/null
+++ b/examples/painting/basicdrawing/window.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** 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 <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QCheckBox;
+class QComboBox;
+class QLabel;
+class QSpinBox;
+QT_END_NAMESPACE
+class RenderArea;
+
+//! [0]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+private slots:
+ void shapeChanged();
+ void penChanged();
+ void brushChanged();
+
+private:
+ RenderArea *renderArea;
+ QLabel *shapeLabel;
+ QLabel *penWidthLabel;
+ QLabel *penStyleLabel;
+ QLabel *penCapLabel;
+ QLabel *penJoinLabel;
+ QLabel *brushStyleLabel;
+ QLabel *otherOptionsLabel;
+ QComboBox *shapeComboBox;
+ QSpinBox *penWidthSpinBox;
+ QComboBox *penStyleComboBox;
+ QComboBox *penCapComboBox;
+ QComboBox *penJoinComboBox;
+ QComboBox *brushStyleComboBox;
+ QCheckBox *antialiasingCheckBox;
+ QCheckBox *transformationsCheckBox;
+};
+//! [0]
+
+#endif
diff --git a/examples/painting/concentriccircles/circlewidget.cpp b/examples/painting/concentriccircles/circlewidget.cpp
new file mode 100644
index 0000000000..d801710b99
--- /dev/null
+++ b/examples/painting/concentriccircles/circlewidget.cpp
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** 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 "circlewidget.h"
+
+#include <stdlib.h>
+
+//! [0]
+CircleWidget::CircleWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ floatBased = false;
+ antialiased = false;
+ frameNo = 0;
+
+ setBackgroundRole(QPalette::Base);
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+}
+//! [0]
+
+//! [1]
+void CircleWidget::setFloatBased(bool floatBased)
+{
+ this->floatBased = floatBased;
+ update();
+}
+//! [1]
+
+//! [2]
+void CircleWidget::setAntialiased(bool antialiased)
+{
+ this->antialiased = antialiased;
+ update();
+}
+//! [2]
+
+//! [3]
+QSize CircleWidget::minimumSizeHint() const
+{
+ return QSize(50, 50);
+}
+//! [3]
+
+//! [4]
+QSize CircleWidget::sizeHint() const
+{
+ return QSize(180, 180);
+}
+//! [4]
+
+//! [5]
+void CircleWidget::nextAnimationFrame()
+{
+ ++frameNo;
+ update();
+}
+//! [5]
+
+//! [6]
+void CircleWidget::paintEvent(QPaintEvent *)
+{
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing, antialiased);
+ painter.translate(width() / 2, height() / 2);
+//! [6]
+
+//! [7]
+ for (int diameter = 0; diameter < 256; diameter += 9) {
+ int delta = abs((frameNo % 128) - diameter / 2);
+ int alpha = 255 - (delta * delta) / 4 - diameter;
+//! [7] //! [8]
+ if (alpha > 0) {
+ painter.setPen(QPen(QColor(0, diameter / 2, 127, alpha), 3));
+
+ if (floatBased) {
+ painter.drawEllipse(QRectF(-diameter / 2.0, -diameter / 2.0,
+ diameter, diameter));
+ } else {
+ painter.drawEllipse(QRect(-diameter / 2, -diameter / 2,
+ diameter, diameter));
+ }
+ }
+ }
+}
+//! [8]
diff --git a/examples/painting/concentriccircles/circlewidget.h b/examples/painting/concentriccircles/circlewidget.h
new file mode 100644
index 0000000000..e8f583d643
--- /dev/null
+++ b/examples/painting/concentriccircles/circlewidget.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** 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 CIRCLEWIDGET_H
+#define CIRCLEWIDGET_H
+
+#include <QWidget>
+
+//! [0]
+class CircleWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ CircleWidget(QWidget *parent = 0);
+
+ void setFloatBased(bool floatBased);
+ void setAntialiased(bool antialiased);
+
+ QSize minimumSizeHint() const;
+ QSize sizeHint() const;
+
+public slots:
+ void nextAnimationFrame();
+
+protected:
+ void paintEvent(QPaintEvent *event);
+
+private:
+ bool floatBased;
+ bool antialiased;
+ int frameNo;
+};
+//! [0]
+
+#endif
diff --git a/examples/painting/concentriccircles/concentriccircles.pro b/examples/painting/concentriccircles/concentriccircles.pro
new file mode 100644
index 0000000000..a47ac18193
--- /dev/null
+++ b/examples/painting/concentriccircles/concentriccircles.pro
@@ -0,0 +1,16 @@
+HEADERS = circlewidget.h \
+ window.h
+SOURCES = circlewidget.cpp \
+ main.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/concentriccircles
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS concentriccircles.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/concentriccircles
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000A64A
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/painting/concentriccircles/main.cpp b/examples/painting/concentriccircles/main.cpp
new file mode 100644
index 0000000000..f2079f511b
--- /dev/null
+++ b/examples/painting/concentriccircles/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/concentriccircles/window.cpp b/examples/painting/concentriccircles/window.cpp
new file mode 100644
index 0000000000..a01333be62
--- /dev/null
+++ b/examples/painting/concentriccircles/window.cpp
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** 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 "circlewidget.h"
+#include "window.h"
+
+//! [0]
+Window::Window()
+{
+ aliasedLabel = createLabel(tr("Aliased"));
+ antialiasedLabel = createLabel(tr("Antialiased"));
+ intLabel = createLabel(tr("Int"));
+ floatLabel = createLabel(tr("Float"));
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(aliasedLabel, 0, 1);
+ layout->addWidget(antialiasedLabel, 0, 2);
+ layout->addWidget(intLabel, 1, 0);
+ layout->addWidget(floatLabel, 2, 0);
+//! [0]
+
+//! [1]
+ QTimer *timer = new QTimer(this);
+
+ for (int i = 0; i < 2; ++i) {
+ for (int j = 0; j < 2; ++j) {
+ circleWidgets[i][j] = new CircleWidget;
+ circleWidgets[i][j]->setAntialiased(j != 0);
+ circleWidgets[i][j]->setFloatBased(i != 0);
+
+ connect(timer, SIGNAL(timeout()),
+ circleWidgets[i][j], SLOT(nextAnimationFrame()));
+
+ layout->addWidget(circleWidgets[i][j], i + 1, j + 1);
+ }
+ }
+//! [1] //! [2]
+ timer->start(100);
+ setLayout(layout);
+
+ setWindowTitle(tr("Concentric Circles"));
+}
+//! [2]
+
+//! [3]
+QLabel *Window::createLabel(const QString &text)
+{
+ QLabel *label = new QLabel(text);
+ label->setAlignment(Qt::AlignCenter);
+ label->setMargin(2);
+ label->setFrameStyle(QFrame::Box | QFrame::Sunken);
+ return label;
+}
+//! [3]
diff --git a/examples/painting/concentriccircles/window.h b/examples/painting/concentriccircles/window.h
new file mode 100644
index 0000000000..b5cc7d9a97
--- /dev/null
+++ b/examples/painting/concentriccircles/window.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** 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 <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+QT_END_NAMESPACE
+class CircleWidget;
+
+//! [0]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+private:
+ QLabel *createLabel(const QString &text);
+
+ QLabel *aliasedLabel;
+ QLabel *antialiasedLabel;
+ QLabel *intLabel;
+ QLabel *floatLabel;
+ CircleWidget *circleWidgets[2][2];
+};
+//! [0]
+
+#endif
diff --git a/examples/painting/fontsampler/fontsampler.pro b/examples/painting/fontsampler/fontsampler.pro
new file mode 100644
index 0000000000..9d845c413d
--- /dev/null
+++ b/examples/painting/fontsampler/fontsampler.pro
@@ -0,0 +1,12 @@
+FORMS = mainwindowbase.ui
+HEADERS = mainwindow.h
+SOURCES = main.cpp \
+ mainwindow.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/fontsampler
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS fontsampler.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/fontsampler
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/painting/fontsampler/main.cpp b/examples/painting/fontsampler/main.cpp
new file mode 100644
index 0000000000..01c8adae53
--- /dev/null
+++ b/examples/painting/fontsampler/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 "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/painting/fontsampler/mainwindow.cpp b/examples/painting/fontsampler/mainwindow.cpp
new file mode 100644
index 0000000000..0976d1f971
--- /dev/null
+++ b/examples/painting/fontsampler/mainwindow.cpp
@@ -0,0 +1,372 @@
+/****************************************************************************
+**
+** 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 "mainwindow.h"
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ setupUi(this);
+
+ sampleSizes << 32 << 24 << 16 << 14 << 12 << 8 << 4 << 2 << 1;
+ markedCount = 0;
+ setupFontTree();
+
+ connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+ connect(fontTree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
+ this, SLOT(showFont(QTreeWidgetItem*)));
+ connect(fontTree, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
+ this, SLOT(updateStyles(QTreeWidgetItem*,int)));
+
+ fontTree->setItemSelected(fontTree->topLevelItem(0), true);
+ showFont(fontTree->topLevelItem(0));
+}
+
+void MainWindow::setupFontTree()
+{
+ QFontDatabase database;
+ fontTree->setColumnCount(1);
+ fontTree->setHeaderLabels(QStringList() << tr("Font"));
+
+ foreach (QString family, database.families()) {
+ const QStringList styles = database.styles(family);
+ if (styles.isEmpty())
+ continue;
+
+ QTreeWidgetItem *familyItem = new QTreeWidgetItem(fontTree);
+ familyItem->setText(0, family);
+ familyItem->setCheckState(0, Qt::Unchecked);
+
+ foreach (QString style, styles) {
+ QTreeWidgetItem *styleItem = new QTreeWidgetItem(familyItem);
+ styleItem->setText(0, style);
+ styleItem->setCheckState(0, Qt::Unchecked);
+ styleItem->setData(0, Qt::UserRole,
+ QVariant(database.weight(family, style)));
+ styleItem->setData(0, Qt::UserRole + 1,
+ QVariant(database.italic(family, style)));
+ }
+ }
+}
+
+void MainWindow::on_clearAction_triggered()
+{
+ QTreeWidgetItem *currentItem = fontTree->currentItem();
+ foreach (QTreeWidgetItem *item, fontTree->selectedItems())
+ fontTree->setItemSelected(item, false);
+ fontTree->setItemSelected(currentItem, true);
+}
+
+void MainWindow::on_markAction_triggered()
+{
+ markUnmarkFonts(Qt::Checked);
+}
+
+void MainWindow::on_unmarkAction_triggered()
+{
+ markUnmarkFonts(Qt::Unchecked);
+}
+
+void MainWindow::markUnmarkFonts(Qt::CheckState state)
+{
+ QList<QTreeWidgetItem *> items = fontTree->selectedItems();
+ foreach (QTreeWidgetItem *item, items) {
+ if (item->checkState(0) != state)
+ item->setCheckState(0, state);
+ }
+}
+
+void MainWindow::showFont(QTreeWidgetItem *item)
+{
+ if (!item)
+ return;
+
+ QString family;
+ QString style;
+ int weight;
+ bool italic;
+
+ if (item->parent()) {
+ family = item->parent()->text(0);
+ style = item->text(0);
+ weight = item->data(0, Qt::UserRole).toInt();
+ italic = item->data(0, Qt::UserRole + 1).toBool();
+ } else {
+ family = item->text(0);
+ style = item->child(0)->text(0);
+ weight = item->child(0)->data(0, Qt::UserRole).toInt();
+ italic = item->child(0)->data(0, Qt::UserRole + 1).toBool();
+ }
+
+ QString oldText = textEdit->toPlainText().trimmed();
+ bool modified = textEdit->document()->isModified();
+ textEdit->clear();
+ textEdit->document()->setDefaultFont(QFont(family, 32, weight, italic));
+
+ QTextCursor cursor = textEdit->textCursor();
+ QTextBlockFormat blockFormat;
+ blockFormat.setAlignment(Qt::AlignCenter);
+ cursor.insertBlock(blockFormat);
+
+ if (modified)
+ cursor.insertText(QString(oldText));
+ else
+ cursor.insertText(QString("%1 %2").arg(family).arg(style));
+
+ textEdit->document()->setModified(modified);
+}
+
+void MainWindow::updateStyles(QTreeWidgetItem *item, int column)
+{
+ if (!item || column != 0)
+ return;
+
+ Qt::CheckState state = item->checkState(0);
+ QTreeWidgetItem *parent = item->parent();
+
+ if (parent) {
+
+ // Only count style items.
+ if (state == Qt::Checked)
+ ++markedCount;
+ else
+ --markedCount;
+
+ if (state == Qt::Checked &&
+ parent->checkState(0) == Qt::Unchecked) {
+ // Mark parent items when child items are checked.
+ parent->setCheckState(0, Qt::Checked);
+
+ } else if (state == Qt::Unchecked &&
+ parent->checkState(0) == Qt::Checked) {
+
+ bool marked = false;
+ for (int row = 0; row < parent->childCount(); ++row) {
+ if (parent->child(row)->checkState(0) == Qt::Checked) {
+ marked = true;
+ break;
+ }
+ }
+ // Unmark parent items when all child items are unchecked.
+ if (!marked)
+ parent->setCheckState(0, Qt::Unchecked);
+ }
+ } else {
+ int row;
+ int number = 0;
+ for (row = 0; row < item->childCount(); ++row) {
+ if (item->child(row)->checkState(0) == Qt::Checked)
+ ++number;
+ }
+
+ // Mark/unmark all child items when marking/unmarking top-level
+ // items.
+ if (state == Qt::Checked && number == 0) {
+ for (row = 0; row < item->childCount(); ++row) {
+ if (item->child(row)->checkState(0) == Qt::Unchecked)
+ item->child(row)->setCheckState(0, Qt::Checked);
+ }
+ } else if (state == Qt::Unchecked && number > 0) {
+ for (row = 0; row < item->childCount(); ++row) {
+ if (item->child(row)->checkState(0) == Qt::Checked)
+ item->child(row)->setCheckState(0, Qt::Unchecked);
+ }
+ }
+ }
+
+ printAction->setEnabled(markedCount > 0);
+ printPreviewAction->setEnabled(markedCount > 0);
+}
+
+void MainWindow::on_printAction_triggered()
+{
+ pageMap = currentPageMap();
+
+ if (pageMap.count() == 0)
+ return;
+
+ QPrinter printer(QPrinter::HighResolution);
+ QPrintDialog dialog(&printer, this);
+ if (dialog.exec() != QDialog::Accepted)
+ return;
+
+ int from = printer.fromPage();
+ int to = printer.toPage();
+ if (from <= 0 && to <= 0)
+ printer.setFromTo(1, pageMap.keys().count());
+
+ printDocument(&printer);
+}
+
+void MainWindow::printDocument(QPrinter *printer)
+{
+ printer->setFromTo(1, pageMap.count());
+
+ QProgressDialog progress(tr("Preparing font samples..."), tr("&Cancel"),
+ 0, pageMap.count(), this);
+ progress.setWindowModality(Qt::ApplicationModal);
+ progress.setWindowTitle(tr("Font Sampler"));
+ progress.setMinimum(printer->fromPage() - 1);
+ progress.setMaximum(printer->toPage());
+
+ QPainter painter;
+ painter.begin(printer);
+ bool firstPage = true;
+
+ for (int page = printer->fromPage(); page <= printer->toPage(); ++page) {
+
+ if (!firstPage)
+ printer->newPage();
+
+ qApp->processEvents();
+ if (progress.wasCanceled())
+ break;
+
+ printPage(page - 1, &painter, printer);
+ progress.setValue(page);
+ firstPage = false;
+ }
+
+ painter.end();
+}
+
+void MainWindow::on_printPreviewAction_triggered()
+{
+ pageMap = currentPageMap();
+
+ if (pageMap.count() == 0)
+ return;
+
+ QPrinter printer(QPrinter::HighResolution);
+ QPrintPreviewDialog preview(&printer, this);
+ connect(&preview, SIGNAL(paintRequested(QPrinter*)),
+ this, SLOT(printDocument(QPrinter*)));
+ preview.exec();
+}
+
+QMap<QString, StyleItems> MainWindow::currentPageMap()
+{
+ QMap<QString, StyleItems> pageMap;
+
+ for (int row = 0; row < fontTree->topLevelItemCount(); ++row) {
+ QTreeWidgetItem *familyItem = fontTree->topLevelItem(row);
+ QString family;
+
+ if (familyItem->checkState(0) == Qt::Checked) {
+ family = familyItem->text(0);
+ pageMap[family] = StyleItems();
+ }
+
+ for (int childRow = 0; childRow < familyItem->childCount(); ++childRow) {
+ QTreeWidgetItem *styleItem = familyItem->child(childRow);
+ if (styleItem->checkState(0) == Qt::Checked)
+ pageMap[family].append(styleItem);
+ }
+ }
+
+ return pageMap;
+}
+
+void MainWindow::printPage(int index, QPainter *painter, QPrinter *printer)
+{
+ QString family = pageMap.keys()[index];
+ StyleItems items = pageMap[family];
+
+ // Find the dimensions of the text on each page.
+ qreal width = 0.0;
+ qreal height = 0.0;
+ foreach (QTreeWidgetItem *item, items) {
+ QString style = item->text(0);
+ int weight = item->data(0, Qt::UserRole).toInt();
+ bool italic = item->data(0, Qt::UserRole + 1).toBool();
+
+ // Calculate the maximum width and total height of the text.
+ foreach (int size, sampleSizes) {
+ QFont font(family, size, weight, italic);
+ font = QFont(font, painter->device());
+ QFontMetricsF fontMetrics(font);
+ QRectF rect = fontMetrics.boundingRect(
+ QString("%1 %2").arg(family).arg(style));
+ width = qMax(rect.width(), width);
+ height += rect.height();
+ }
+ }
+
+ qreal xScale = printer->pageRect().width() / width;
+ qreal yScale = printer->pageRect().height() / height;
+ qreal scale = qMin(xScale, yScale);
+
+ qreal remainingHeight = printer->pageRect().height()/scale - height;
+ qreal spaceHeight = (remainingHeight/4.0) / (items.count() + 1);
+ qreal interLineHeight = (remainingHeight/4.0) / (sampleSizes.count() * items.count());
+
+ painter->save();
+ painter->translate(printer->pageRect().width()/2.0, printer->pageRect().height()/2.0);
+ painter->scale(scale, scale);
+ painter->setBrush(QBrush(Qt::black));
+
+ qreal x = -width/2.0;
+ qreal y = -height/2.0 - remainingHeight/4.0 + spaceHeight;
+
+ foreach (QTreeWidgetItem *item, items) {
+ QString style = item->text(0);
+ int weight = item->data(0, Qt::UserRole).toInt();
+ bool italic = item->data(0, Qt::UserRole + 1).toBool();
+
+ // Draw each line of text.
+ foreach (int size, sampleSizes) {
+ QFont font(family, size, weight, italic);
+ font = QFont(font, painter->device());
+ QFontMetricsF fontMetrics(font);
+ QRectF rect = fontMetrics.boundingRect(QString("%1 %2").arg(
+ font.family()).arg(style));
+ y += rect.height();
+ painter->setFont(font);
+ painter->drawText(QPointF(x, y),
+ QString("%1 %2").arg(family).arg(style));
+ y += interLineHeight;
+ }
+ y += spaceHeight;
+ }
+
+ painter->restore();
+}
diff --git a/examples/painting/fontsampler/mainwindow.h b/examples/painting/fontsampler/mainwindow.h
new file mode 100644
index 0000000000..7ea4cd5ed0
--- /dev/null
+++ b/examples/painting/fontsampler/mainwindow.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** 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 "ui_mainwindowbase.h"
+
+QT_BEGIN_NAMESPACE
+class QTextEdit;
+class QTreeWidget;
+class QTreeWidgetItem;
+QT_END_NAMESPACE
+
+typedef QList<QTreeWidgetItem *> StyleItems;
+
+class MainWindow : public QMainWindow, private Ui::MainWindowBase
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+
+public slots:
+ void on_clearAction_triggered();
+ void on_markAction_triggered();
+ void on_printAction_triggered();
+ void on_printPreviewAction_triggered();
+ void on_unmarkAction_triggered();
+ void printDocument(QPrinter *printer);
+ void printPage(int index, QPainter *painter, QPrinter *printer);
+ void showFont(QTreeWidgetItem *item);
+ void updateStyles(QTreeWidgetItem *item, int column);
+
+private:
+ QMap<QString, StyleItems> currentPageMap();
+ void markUnmarkFonts(Qt::CheckState state);
+ void setupFontTree();
+
+ QList<int> sampleSizes;
+ QMap<QString, StyleItems> pageMap;
+ int markedCount;
+};
+
+#endif
diff --git a/examples/painting/fontsampler/mainwindowbase.ui b/examples/painting/fontsampler/mainwindowbase.ui
new file mode 100644
index 0000000000..6545b34083
--- /dev/null
+++ b/examples/painting/fontsampler/mainwindowbase.ui
@@ -0,0 +1,140 @@
+<ui version="4.0" >
+ <author></author>
+ <comment></comment>
+ <exportmacro></exportmacro>
+ <class>MainWindowBase</class>
+ <widget class="QMainWindow" name="MainWindowBase" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>345</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Font Sampler</string>
+ </property>
+ <widget class="QWidget" name="centralwidget" >
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QTextEdit" name="textEdit" />
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menubar" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>24</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menu_Selection" >
+ <property name="title" >
+ <string>&amp;Selection</string>
+ </property>
+ <addaction name="markAction" />
+ <addaction name="unmarkAction" />
+ <addaction name="clearAction" />
+ </widget>
+ <widget class="QMenu" name="menu_File" >
+ <property name="title" >
+ <string>&amp;File</string>
+ </property>
+ <addaction name="printPreviewAction" />
+ <addaction name="printAction" />
+ <addaction name="quitAction" />
+ </widget>
+ <addaction name="menu_File" />
+ <addaction name="menu_Selection" />
+ </widget>
+ <widget class="QStatusBar" name="statusbar" />
+ <widget class="QDockWidget" name="dockWidget" >
+ <property name="features" >
+ <set>QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable|QDockWidget::NoDockWidgetFeatures</set>
+ </property>
+ <property name="windowTitle" >
+ <string>Available Fonts</string>
+ </property>
+ <attribute name="dockWidgetArea" >
+ <number>1</number>
+ </attribute>
+ <widget class="QWidget" name="dockWidgetContents" >
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QTreeWidget" name="fontTree" >
+ <property name="selectionMode" >
+ <enum>QAbstractItemView::ExtendedSelection</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ <action name="printAction" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="text" >
+ <string>&amp;Print...</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+P</string>
+ </property>
+ </action>
+ <action name="quitAction" >
+ <property name="text" >
+ <string>E&amp;xit</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+Q</string>
+ </property>
+ </action>
+ <action name="markAction" >
+ <property name="text" >
+ <string>&amp;Mark</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+M</string>
+ </property>
+ </action>
+ <action name="unmarkAction" >
+ <property name="text" >
+ <string>&amp;Unmark</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+U</string>
+ </property>
+ </action>
+ <action name="clearAction" >
+ <property name="text" >
+ <string>&amp;Clear</string>
+ </property>
+ </action>
+ <action name="printPreviewAction" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="text" >
+ <string>Print Preview...</string>
+ </property>
+ </action>
+ </widget>
+ <pixmapfunction></pixmapfunction>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/painting/imagecomposition/imagecomposer.cpp b/examples/painting/imagecomposition/imagecomposer.cpp
new file mode 100644
index 0000000000..a41f405fd0
--- /dev/null
+++ b/examples/painting/imagecomposition/imagecomposer.cpp
@@ -0,0 +1,208 @@
+/****************************************************************************
+**
+** 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 "imagecomposer.h"
+
+//! [0]
+static const QSize resultSize(200, 200);
+//! [0]
+
+//! [1]
+ImageComposer::ImageComposer()
+{
+ sourceButton = new QToolButton;
+ sourceButton->setIconSize(resultSize);
+
+ operatorComboBox = new QComboBox;
+ addOp(QPainter::CompositionMode_SourceOver, tr("SourceOver"));
+ addOp(QPainter::CompositionMode_DestinationOver, tr("DestinationOver"));
+ addOp(QPainter::CompositionMode_Clear, tr("Clear"));
+ addOp(QPainter::CompositionMode_Source, tr("Source"));
+ addOp(QPainter::CompositionMode_Destination, tr("Destination"));
+ addOp(QPainter::CompositionMode_SourceIn, tr("SourceIn"));
+ addOp(QPainter::CompositionMode_DestinationIn, tr("DestinationIn"));
+ addOp(QPainter::CompositionMode_SourceOut, tr("SourceOut"));
+ addOp(QPainter::CompositionMode_DestinationOut, tr("DestinationOut"));
+ addOp(QPainter::CompositionMode_SourceAtop, tr("SourceAtop"));
+ addOp(QPainter::CompositionMode_DestinationAtop, tr("DestinationAtop"));
+ addOp(QPainter::CompositionMode_Xor, tr("Xor"));
+ addOp(QPainter::CompositionMode_Plus, tr("Plus"));
+ addOp(QPainter::CompositionMode_Multiply, tr("Multiply"));
+ addOp(QPainter::CompositionMode_Screen, tr("Screen"));
+ addOp(QPainter::CompositionMode_Overlay, tr("Overlay"));
+ addOp(QPainter::CompositionMode_Darken, tr("Darken"));
+ addOp(QPainter::CompositionMode_Lighten, tr("Lighten"));
+ addOp(QPainter::CompositionMode_ColorDodge, tr("ColorDodge"));
+ addOp(QPainter::CompositionMode_ColorBurn, tr("ColorBurn"));
+ addOp(QPainter::CompositionMode_HardLight, tr("HardLight"));
+ addOp(QPainter::CompositionMode_SoftLight, tr("SoftLight"));
+ addOp(QPainter::CompositionMode_Difference, tr("Difference"));
+ addOp(QPainter::CompositionMode_Exclusion, tr("Exclusion"));
+//! [1]
+
+//! [2]
+ destinationButton = new QToolButton;
+ destinationButton->setIconSize(resultSize);
+
+ equalLabel = new QLabel(tr("="));
+
+ resultLabel = new QLabel;
+ resultLabel->setMinimumWidth(resultSize.width());
+//! [2]
+
+//! [3]
+ connect(sourceButton, SIGNAL(clicked()), this, SLOT(chooseSource()));
+ connect(operatorComboBox, SIGNAL(activated(int)),
+ this, SLOT(recalculateResult()));
+ connect(destinationButton, SIGNAL(clicked()),
+ this, SLOT(chooseDestination()));
+//! [3]
+
+//! [4]
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(sourceButton, 0, 0, 3, 1);
+ mainLayout->addWidget(operatorComboBox, 1, 1);
+ mainLayout->addWidget(destinationButton, 0, 2, 3, 1);
+ mainLayout->addWidget(equalLabel, 1, 3);
+ mainLayout->addWidget(resultLabel, 0, 4, 3, 1);
+ mainLayout->setSizeConstraint(QLayout::SetFixedSize);
+ setLayout(mainLayout);
+//! [4]
+
+//! [5]
+ resultImage = QImage(resultSize, QImage::Format_ARGB32_Premultiplied);
+
+ loadImage(":/images/butterfly.png", &sourceImage, sourceButton);
+ loadImage(":/images/checker.png", &destinationImage, destinationButton);
+
+ setWindowTitle(tr("Image Composition"));
+}
+//! [5]
+
+//! [6]
+void ImageComposer::chooseSource()
+{
+ chooseImage(tr("Choose Source Image"), &sourceImage, sourceButton);
+}
+//! [6]
+
+//! [7]
+void ImageComposer::chooseDestination()
+{
+ chooseImage(tr("Choose Destination Image"), &destinationImage,
+ destinationButton);
+}
+//! [7]
+
+//! [8]
+void ImageComposer::recalculateResult()
+{
+ QPainter::CompositionMode mode = currentMode();
+
+ QPainter painter(&resultImage);
+ painter.setCompositionMode(QPainter::CompositionMode_Source);
+ painter.fillRect(resultImage.rect(), Qt::transparent);
+ painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
+ painter.drawImage(0, 0, destinationImage);
+ painter.setCompositionMode(mode);
+ painter.drawImage(0, 0, sourceImage);
+ painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
+ painter.fillRect(resultImage.rect(), Qt::white);
+ painter.end();
+
+ resultLabel->setPixmap(QPixmap::fromImage(resultImage));
+}
+//! [8]
+
+//! [9]
+void ImageComposer::addOp(QPainter::CompositionMode mode, const QString &name)
+{
+ operatorComboBox->addItem(name, mode);
+}
+//! [9]
+
+//! [10]
+void ImageComposer::chooseImage(const QString &title, QImage *image,
+ QToolButton *button)
+{
+ QString fileName = QFileDialog::getOpenFileName(this, title);
+ if (!fileName.isEmpty())
+ loadImage(fileName, image, button);
+}
+//! [10]
+
+//! [11]
+void ImageComposer::loadImage(const QString &fileName, QImage *image,
+ QToolButton *button)
+{
+ image->load(fileName);
+
+ QImage fixedImage(resultSize, QImage::Format_ARGB32_Premultiplied);
+ QPainter painter(&fixedImage);
+ painter.setCompositionMode(QPainter::CompositionMode_Source);
+ painter.fillRect(fixedImage.rect(), Qt::transparent);
+ painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
+ painter.drawImage(imagePos(*image), *image);
+ painter.end();
+ button->setIcon(QPixmap::fromImage(fixedImage));
+
+ *image = fixedImage;
+
+ recalculateResult();
+}
+//! [11]
+
+//! [12]
+QPainter::CompositionMode ImageComposer::currentMode() const
+{
+ return (QPainter::CompositionMode)
+ operatorComboBox->itemData(operatorComboBox->currentIndex()).toInt();
+}
+//! [12]
+
+//! [13]
+QPoint ImageComposer::imagePos(const QImage &image) const
+{
+ return QPoint((resultSize.width() - image.width()) / 2,
+ (resultSize.height() - image.height()) / 2);
+}
+//! [13]
diff --git a/examples/painting/imagecomposition/imagecomposer.h b/examples/painting/imagecomposition/imagecomposer.h
new file mode 100644
index 0000000000..2248ba3033
--- /dev/null
+++ b/examples/painting/imagecomposition/imagecomposer.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** 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 IMAGECOMPOSER_H
+#define IMAGECOMPOSER_H
+
+#include <QPainter>
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+class QLabel;
+class QToolButton;
+QT_END_NAMESPACE
+
+//! [0]
+class ImageComposer : public QWidget
+{
+ Q_OBJECT
+
+public:
+ ImageComposer();
+
+private slots:
+ void chooseSource();
+ void chooseDestination();
+ void recalculateResult();
+//! [0]
+
+//! [1]
+private:
+ void addOp(QPainter::CompositionMode mode, const QString &name);
+ void chooseImage(const QString &title, QImage *image, QToolButton *button);
+ void loadImage(const QString &fileName, QImage *image, QToolButton *button);
+ QPainter::CompositionMode currentMode() const;
+ QPoint imagePos(const QImage &image) const;
+
+ QToolButton *sourceButton;
+ QToolButton *destinationButton;
+ QComboBox *operatorComboBox;
+ QLabel *equalLabel;
+ QLabel *resultLabel;
+
+ QImage sourceImage;
+ QImage destinationImage;
+ QImage resultImage;
+};
+//! [1]
+
+#endif
diff --git a/examples/painting/imagecomposition/imagecomposition.pro b/examples/painting/imagecomposition/imagecomposition.pro
new file mode 100644
index 0000000000..883d7edc0c
--- /dev/null
+++ b/examples/painting/imagecomposition/imagecomposition.pro
@@ -0,0 +1,15 @@
+HEADERS = imagecomposer.h
+SOURCES = imagecomposer.cpp \
+ main.cpp
+RESOURCES = imagecomposition.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/imagecomposition
+sources.files = $$SOURCES $$HEADERS $$RESOURCES images *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/imagecomposition
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000A64B
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/painting/imagecomposition/imagecomposition.qrc b/examples/painting/imagecomposition/imagecomposition.qrc
new file mode 100644
index 0000000000..ebba7b2913
--- /dev/null
+++ b/examples/painting/imagecomposition/imagecomposition.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/butterfly.png</file>
+ <file>images/checker.png</file>
+</qresource>
+</RCC>
diff --git a/examples/painting/imagecomposition/images/background.png b/examples/painting/imagecomposition/images/background.png
new file mode 100644
index 0000000000..f6ad899823
--- /dev/null
+++ b/examples/painting/imagecomposition/images/background.png
Binary files differ
diff --git a/examples/painting/imagecomposition/images/blackrectangle.png b/examples/painting/imagecomposition/images/blackrectangle.png
new file mode 100644
index 0000000000..5f2ecf8318
--- /dev/null
+++ b/examples/painting/imagecomposition/images/blackrectangle.png
Binary files differ
diff --git a/examples/painting/imagecomposition/images/butterfly.png b/examples/painting/imagecomposition/images/butterfly.png
new file mode 100644
index 0000000000..f3e050eca2
--- /dev/null
+++ b/examples/painting/imagecomposition/images/butterfly.png
Binary files differ
diff --git a/examples/painting/imagecomposition/images/checker.png b/examples/painting/imagecomposition/images/checker.png
new file mode 100644
index 0000000000..546609de3f
--- /dev/null
+++ b/examples/painting/imagecomposition/images/checker.png
Binary files differ
diff --git a/examples/painting/imagecomposition/main.cpp b/examples/painting/imagecomposition/main.cpp
new file mode 100644
index 0000000000..e70fa5fae9
--- /dev/null
+++ b/examples/painting/imagecomposition/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** 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 "imagecomposer.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(imagecomposition);
+
+ QApplication app(argc, argv);
+ ImageComposer composer;
+ composer.show();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/painting/painterpaths/main.cpp b/examples/painting/painterpaths/main.cpp
new file mode 100644
index 0000000000..f2079f511b
--- /dev/null
+++ b/examples/painting/painterpaths/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/painterpaths/painterpaths.pro b/examples/painting/painterpaths/painterpaths.pro
new file mode 100644
index 0000000000..c61ad897a0
--- /dev/null
+++ b/examples/painting/painterpaths/painterpaths.pro
@@ -0,0 +1,17 @@
+HEADERS = renderarea.h \
+ window.h
+SOURCES = main.cpp \
+ renderarea.cpp \
+ window.cpp
+unix:!mac:!symbian:!vxworks:!integrity:LIBS += -lm
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/painterpaths
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS painterpaths.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/painterpaths
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000A64C
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/painting/painterpaths/renderarea.cpp b/examples/painting/painterpaths/renderarea.cpp
new file mode 100644
index 0000000000..977fe30ed0
--- /dev/null
+++ b/examples/painting/painterpaths/renderarea.cpp
@@ -0,0 +1,130 @@
+/****************************************************************************
+**
+** 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 "renderarea.h"
+
+//! [0]
+RenderArea::RenderArea(const QPainterPath &path, QWidget *parent)
+ : QWidget(parent), path(path)
+{
+ penWidth = 1;
+ rotationAngle = 0;
+ setBackgroundRole(QPalette::Base);
+}
+//! [0]
+
+//! [1]
+QSize RenderArea::minimumSizeHint() const
+{
+ return QSize(50, 50);
+}
+//! [1]
+
+//! [2]
+QSize RenderArea::sizeHint() const
+{
+ return QSize(100, 100);
+}
+//! [2]
+
+//! [3]
+void RenderArea::setFillRule(Qt::FillRule rule)
+{
+ path.setFillRule(rule);
+ update();
+}
+//! [3]
+
+//! [4]
+void RenderArea::setFillGradient(const QColor &color1, const QColor &color2)
+{
+ fillColor1 = color1;
+ fillColor2 = color2;
+ update();
+}
+//! [4]
+
+//! [5]
+void RenderArea::setPenWidth(int width)
+{
+ penWidth = width;
+ update();
+}
+//! [5]
+
+//! [6]
+void RenderArea::setPenColor(const QColor &color)
+{
+ penColor = color;
+ update();
+}
+//! [6]
+
+//! [7]
+void RenderArea::setRotationAngle(int degrees)
+{
+ rotationAngle = degrees;
+ update();
+}
+//! [7]
+
+//! [8]
+void RenderArea::paintEvent(QPaintEvent *)
+{
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+//! [8] //! [9]
+ painter.scale(width() / 100.0, height() / 100.0);
+ painter.translate(50.0, 50.0);
+ painter.rotate(-rotationAngle);
+ painter.translate(-50.0, -50.0);
+
+//! [9] //! [10]
+ painter.setPen(QPen(penColor, penWidth, Qt::SolidLine, Qt::RoundCap,
+ Qt::RoundJoin));
+ QLinearGradient gradient(0, 0, 0, 100);
+ gradient.setColorAt(0.0, fillColor1);
+ gradient.setColorAt(1.0, fillColor2);
+ painter.setBrush(gradient);
+ painter.drawPath(path);
+}
+//! [10]
diff --git a/examples/painting/painterpaths/renderarea.h b/examples/painting/painterpaths/renderarea.h
new file mode 100644
index 0000000000..2c50ecb353
--- /dev/null
+++ b/examples/painting/painterpaths/renderarea.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 RENDERAREA_H
+#define RENDERAREA_H
+
+#include <QPainterPath>
+#include <QWidget>
+
+//! [0]
+class RenderArea : public QWidget
+{
+ Q_OBJECT
+
+public:
+ RenderArea(const QPainterPath &path, QWidget *parent = 0);
+
+ QSize minimumSizeHint() const;
+ QSize sizeHint() const;
+
+public slots:
+ void setFillRule(Qt::FillRule rule);
+ void setFillGradient(const QColor &color1, const QColor &color2);
+ void setPenWidth(int width);
+ void setPenColor(const QColor &color);
+ void setRotationAngle(int degrees);
+
+protected:
+ void paintEvent(QPaintEvent *event);
+//! [0]
+
+//! [1]
+private:
+ QPainterPath path;
+ QColor fillColor1;
+ QColor fillColor2;
+ int penWidth;
+ QColor penColor;
+ int rotationAngle;
+};
+//! [1]
+
+#endif
diff --git a/examples/painting/painterpaths/window.cpp b/examples/painting/painterpaths/window.cpp
new file mode 100644
index 0000000000..429f470b26
--- /dev/null
+++ b/examples/painting/painterpaths/window.cpp
@@ -0,0 +1,288 @@
+/****************************************************************************
+**
+** 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 <math.h>
+
+#include "renderarea.h"
+#include "window.h"
+
+//! [0]
+const float Pi = 3.14159f;
+//! [0]
+
+//! [1]
+Window::Window()
+{
+ QPainterPath rectPath;
+ rectPath.moveTo(20.0, 30.0);
+ rectPath.lineTo(80.0, 30.0);
+ rectPath.lineTo(80.0, 70.0);
+ rectPath.lineTo(20.0, 70.0);
+ rectPath.closeSubpath();
+//! [1]
+
+//! [2]
+ QPainterPath roundRectPath;
+ roundRectPath.moveTo(80.0, 35.0);
+ roundRectPath.arcTo(70.0, 30.0, 10.0, 10.0, 0.0, 90.0);
+ roundRectPath.lineTo(25.0, 30.0);
+ roundRectPath.arcTo(20.0, 30.0, 10.0, 10.0, 90.0, 90.0);
+ roundRectPath.lineTo(20.0, 65.0);
+ roundRectPath.arcTo(20.0, 60.0, 10.0, 10.0, 180.0, 90.0);
+ roundRectPath.lineTo(75.0, 70.0);
+ roundRectPath.arcTo(70.0, 60.0, 10.0, 10.0, 270.0, 90.0);
+ roundRectPath.closeSubpath();
+//! [2]
+
+//! [3]
+ QPainterPath ellipsePath;
+ ellipsePath.moveTo(80.0, 50.0);
+ ellipsePath.arcTo(20.0, 30.0, 60.0, 40.0, 0.0, 360.0);
+//! [3]
+
+//! [4]
+ QPainterPath piePath;
+ piePath.moveTo(50.0, 50.0);
+ piePath.arcTo(20.0, 30.0, 60.0, 40.0, 60.0, 240.0);
+ piePath.closeSubpath();
+//! [4]
+
+//! [5]
+ QPainterPath polygonPath;
+ polygonPath.moveTo(10.0, 80.0);
+ polygonPath.lineTo(20.0, 10.0);
+ polygonPath.lineTo(80.0, 30.0);
+ polygonPath.lineTo(90.0, 70.0);
+ polygonPath.closeSubpath();
+//! [5]
+
+//! [6]
+ QPainterPath groupPath;
+ groupPath.moveTo(60.0, 40.0);
+ groupPath.arcTo(20.0, 20.0, 40.0, 40.0, 0.0, 360.0);
+ groupPath.moveTo(40.0, 40.0);
+ groupPath.lineTo(40.0, 80.0);
+ groupPath.lineTo(80.0, 80.0);
+ groupPath.lineTo(80.0, 40.0);
+ groupPath.closeSubpath();
+//! [6]
+
+//! [7]
+ QPainterPath textPath;
+ QFont timesFont("Times", 50);
+ timesFont.setStyleStrategy(QFont::ForceOutline);
+ textPath.addText(10, 70, timesFont, tr("Qt"));
+//! [7]
+
+//! [8]
+ QPainterPath bezierPath;
+ bezierPath.moveTo(20, 30);
+ bezierPath.cubicTo(80, 0, 50, 50, 80, 80);
+//! [8]
+
+//! [9]
+ QPainterPath starPath;
+ starPath.moveTo(90, 50);
+ for (int i = 1; i < 5; ++i) {
+ starPath.lineTo(50 + 40 * cos(0.8 * i * Pi),
+ 50 + 40 * sin(0.8 * i * Pi));
+ }
+ starPath.closeSubpath();
+//! [9]
+
+//! [10]
+ renderAreas[0] = new RenderArea(rectPath);
+ renderAreas[1] = new RenderArea(roundRectPath);
+ renderAreas[2] = new RenderArea(ellipsePath);
+ renderAreas[3] = new RenderArea(piePath);
+ renderAreas[4] = new RenderArea(polygonPath);
+ renderAreas[5] = new RenderArea(groupPath);
+ renderAreas[6] = new RenderArea(textPath);
+ renderAreas[7] = new RenderArea(bezierPath);
+ renderAreas[8] = new RenderArea(starPath);
+ Q_ASSERT(NumRenderAreas == 9);
+//! [10]
+
+//! [11]
+ fillRuleComboBox = new QComboBox;
+ fillRuleComboBox->addItem(tr("Odd Even"), Qt::OddEvenFill);
+ fillRuleComboBox->addItem(tr("Winding"), Qt::WindingFill);
+
+ fillRuleLabel = new QLabel(tr("Fill &Rule:"));
+ fillRuleLabel->setBuddy(fillRuleComboBox);
+//! [11]
+
+//! [12]
+ fillColor1ComboBox = new QComboBox;
+ populateWithColors(fillColor1ComboBox);
+ fillColor1ComboBox->setCurrentIndex(
+ fillColor1ComboBox->findText("mediumslateblue"));
+
+ fillColor2ComboBox = new QComboBox;
+ populateWithColors(fillColor2ComboBox);
+ fillColor2ComboBox->setCurrentIndex(
+ fillColor2ComboBox->findText("cornsilk"));
+
+ fillGradientLabel = new QLabel(tr("&Fill Gradient:"));
+ fillGradientLabel->setBuddy(fillColor1ComboBox);
+
+ fillToLabel = new QLabel(tr("to"));
+ fillToLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+
+ penWidthSpinBox = new QSpinBox;
+ penWidthSpinBox->setRange(0, 20);
+
+ penWidthLabel = new QLabel(tr("&Pen Width:"));
+ penWidthLabel->setBuddy(penWidthSpinBox);
+
+ penColorComboBox = new QComboBox;
+ populateWithColors(penColorComboBox);
+ penColorComboBox->setCurrentIndex(
+ penColorComboBox->findText("darkslateblue"));
+
+ penColorLabel = new QLabel(tr("Pen &Color:"));
+ penColorLabel->setBuddy(penColorComboBox);
+
+ rotationAngleSpinBox = new QSpinBox;
+ rotationAngleSpinBox->setRange(0, 359);
+ rotationAngleSpinBox->setWrapping(true);
+ rotationAngleSpinBox->setSuffix("\xB0");
+
+ rotationAngleLabel = new QLabel(tr("&Rotation Angle:"));
+ rotationAngleLabel->setBuddy(rotationAngleSpinBox);
+//! [12]
+
+//! [16]
+ connect(fillRuleComboBox, SIGNAL(activated(int)),
+ this, SLOT(fillRuleChanged()));
+ connect(fillColor1ComboBox, SIGNAL(activated(int)),
+ this, SLOT(fillGradientChanged()));
+ connect(fillColor2ComboBox, SIGNAL(activated(int)),
+ this, SLOT(fillGradientChanged()));
+ connect(penColorComboBox, SIGNAL(activated(int)),
+ this, SLOT(penColorChanged()));
+
+ for (int i = 0; i < NumRenderAreas; ++i) {
+ connect(penWidthSpinBox, SIGNAL(valueChanged(int)),
+ renderAreas[i], SLOT(setPenWidth(int)));
+ connect(rotationAngleSpinBox, SIGNAL(valueChanged(int)),
+ renderAreas[i], SLOT(setRotationAngle(int)));
+ }
+
+//! [16] //! [17]
+ QGridLayout *topLayout = new QGridLayout;
+ for (int i = 0; i < NumRenderAreas; ++i)
+ topLayout->addWidget(renderAreas[i], i / 3, i % 3);
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addLayout(topLayout, 0, 0, 1, 4);
+ mainLayout->addWidget(fillRuleLabel, 1, 0);
+ mainLayout->addWidget(fillRuleComboBox, 1, 1, 1, 3);
+ mainLayout->addWidget(fillGradientLabel, 2, 0);
+ mainLayout->addWidget(fillColor1ComboBox, 2, 1);
+ mainLayout->addWidget(fillToLabel, 2, 2);
+ mainLayout->addWidget(fillColor2ComboBox, 2, 3);
+ mainLayout->addWidget(penWidthLabel, 3, 0);
+ mainLayout->addWidget(penWidthSpinBox, 3, 1, 1, 3);
+ mainLayout->addWidget(penColorLabel, 4, 0);
+ mainLayout->addWidget(penColorComboBox, 4, 1, 1, 3);
+ mainLayout->addWidget(rotationAngleLabel, 5, 0);
+ mainLayout->addWidget(rotationAngleSpinBox, 5, 1, 1, 3);
+ setLayout(mainLayout);
+//! [17]
+
+//! [18]
+ fillRuleChanged();
+ fillGradientChanged();
+ penColorChanged();
+ penWidthSpinBox->setValue(2);
+
+ setWindowTitle(tr("Painter Paths"));
+}
+//! [18]
+
+//! [19]
+void Window::fillRuleChanged()
+{
+ Qt::FillRule rule = (Qt::FillRule)currentItemData(fillRuleComboBox).toInt();
+
+ for (int i = 0; i < NumRenderAreas; ++i)
+ renderAreas[i]->setFillRule(rule);
+}
+//! [19]
+
+//! [20]
+void Window::fillGradientChanged()
+{
+ QColor color1 = qvariant_cast<QColor>(currentItemData(fillColor1ComboBox));
+ QColor color2 = qvariant_cast<QColor>(currentItemData(fillColor2ComboBox));
+
+ for (int i = 0; i < NumRenderAreas; ++i)
+ renderAreas[i]->setFillGradient(color1, color2);
+}
+//! [20]
+
+//! [21]
+void Window::penColorChanged()
+{
+ QColor color = qvariant_cast<QColor>(currentItemData(penColorComboBox));
+
+ for (int i = 0; i < NumRenderAreas; ++i)
+ renderAreas[i]->setPenColor(color);
+}
+//! [21]
+
+//! [22]
+void Window::populateWithColors(QComboBox *comboBox)
+{
+ QStringList colorNames = QColor::colorNames();
+ foreach (QString name, colorNames)
+ comboBox->addItem(name, QColor(name));
+}
+//! [22]
+
+//! [23]
+QVariant Window::currentItemData(QComboBox *comboBox)
+{
+ return comboBox->itemData(comboBox->currentIndex());
+}
+//! [23]
diff --git a/examples/painting/painterpaths/window.h b/examples/painting/painterpaths/window.h
new file mode 100644
index 0000000000..4891fdd153
--- /dev/null
+++ b/examples/painting/painterpaths/window.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** 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 <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+class QLabel;
+class QSpinBox;
+QT_END_NAMESPACE
+class RenderArea;
+
+//! [0]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+private slots:
+ void fillRuleChanged();
+ void fillGradientChanged();
+ void penColorChanged();
+//! [0]
+
+//! [1]
+private:
+ void populateWithColors(QComboBox *comboBox);
+ QVariant currentItemData(QComboBox *comboBox);
+//! [1]
+
+//! [2]
+ enum { NumRenderAreas = 9 };
+
+ RenderArea *renderAreas[NumRenderAreas];
+ QLabel *fillRuleLabel;
+ QLabel *fillGradientLabel;
+ QLabel *fillToLabel;
+ QLabel *penWidthLabel;
+ QLabel *penColorLabel;
+ QLabel *rotationAngleLabel;
+ QComboBox *fillRuleComboBox;
+ QComboBox *fillColor1ComboBox;
+ QComboBox *fillColor2ComboBox;
+ QSpinBox *penWidthSpinBox;
+ QComboBox *penColorComboBox;
+ QSpinBox *rotationAngleSpinBox;
+};
+//! [2]
+
+#endif
diff --git a/examples/painting/painting.pro b/examples/painting/painting.pro
new file mode 100644
index 0000000000..1885f217cb
--- /dev/null
+++ b/examples/painting/painting.pro
@@ -0,0 +1,18 @@
+TEMPLATE = subdirs
+SUBDIRS = basicdrawing \
+ concentriccircles \
+ imagecomposition \
+ painterpaths \
+ transformations
+
+!wince*:!symbian: SUBDIRS += fontsampler
+
+contains(QT_CONFIG, svg): SUBDIRS += svggenerator svgviewer
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS painting.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/painting/transformations/main.cpp b/examples/painting/transformations/main.cpp
new file mode 100644
index 0000000000..f2079f511b
--- /dev/null
+++ b/examples/painting/transformations/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/transformations/renderarea.cpp b/examples/painting/transformations/renderarea.cpp
new file mode 100644
index 0000000000..568cfde287
--- /dev/null
+++ b/examples/painting/transformations/renderarea.cpp
@@ -0,0 +1,172 @@
+/****************************************************************************
+**
+** 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 "renderarea.h"
+
+//! [0]
+RenderArea::RenderArea(QWidget *parent)
+ : QWidget(parent)
+{
+ QFont newFont = font();
+ newFont.setPixelSize(12);
+ setFont(newFont);
+
+ QFontMetrics fontMetrics(newFont);
+ xBoundingRect = fontMetrics.boundingRect(tr("x"));
+ yBoundingRect = fontMetrics.boundingRect(tr("y"));
+}
+//! [0]
+
+//! [1]
+void RenderArea::setOperations(const QList<Operation> &operations)
+{
+ this->operations = operations;
+ update();
+}
+//! [1]
+
+//! [2]
+void RenderArea::setShape(const QPainterPath &shape)
+{
+ this->shape = shape;
+ update();
+}
+//! [2]
+
+//! [3]
+QSize RenderArea::minimumSizeHint() const
+{
+ return QSize(182, 182);
+}
+//! [3]
+
+//! [4]
+QSize RenderArea::sizeHint() const
+{
+ return QSize(232, 232);
+}
+//! [4]
+
+//! [5]
+void RenderArea::paintEvent(QPaintEvent *event)
+{
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.fillRect(event->rect(), QBrush(Qt::white));
+
+ painter.translate(66, 66);
+//! [5]
+
+//! [6]
+ painter.save();
+ transformPainter(painter);
+ drawShape(painter);
+ painter.restore();
+//! [6]
+
+//! [7]
+ drawOutline(painter);
+//! [7]
+
+//! [8]
+ transformPainter(painter);
+ drawCoordinates(painter);
+}
+//! [8]
+
+//! [9]
+void RenderArea::drawCoordinates(QPainter &painter)
+{
+ painter.setPen(Qt::red);
+
+ painter.drawLine(0, 0, 50, 0);
+ painter.drawLine(48, -2, 50, 0);
+ painter.drawLine(48, 2, 50, 0);
+ painter.drawText(60 - xBoundingRect.width() / 2,
+ 0 + xBoundingRect.height() / 2, tr("x"));
+
+ painter.drawLine(0, 0, 0, 50);
+ painter.drawLine(-2, 48, 0, 50);
+ painter.drawLine(2, 48, 0, 50);
+ painter.drawText(0 - yBoundingRect.width() / 2,
+ 60 + yBoundingRect.height() / 2, tr("y"));
+}
+//! [9]
+
+//! [10]
+void RenderArea::drawOutline(QPainter &painter)
+{
+ painter.setPen(Qt::darkGreen);
+ painter.setPen(Qt::DashLine);
+ painter.setBrush(Qt::NoBrush);
+ painter.drawRect(0, 0, 100, 100);
+}
+//! [10]
+
+//! [11]
+void RenderArea::drawShape(QPainter &painter)
+{
+ painter.fillPath(shape, Qt::blue);
+}
+//! [11]
+
+//! [12]
+void RenderArea::transformPainter(QPainter &painter)
+{
+ for (int i = 0; i < operations.size(); ++i) {
+ switch (operations[i]) {
+ case Translate:
+ painter.translate(50, 50);
+ break;
+ case Scale:
+ painter.scale(0.75, 0.75);
+ break;
+ case Rotate:
+ painter.rotate(60);
+ break;
+ case NoTransformation:
+ default:
+ ;
+ }
+ }
+}
+//! [12]
diff --git a/examples/painting/transformations/renderarea.h b/examples/painting/transformations/renderarea.h
new file mode 100644
index 0000000000..039430d9a3
--- /dev/null
+++ b/examples/painting/transformations/renderarea.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** 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 RENDERAREA_H
+#define RENDERAREA_H
+
+#include <QFont>
+#include <QList>
+#include <QPainterPath>
+#include <QRect>
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QPaintEvent;
+QT_END_NAMESPACE
+
+//! [0]
+enum Operation { NoTransformation, Translate, Rotate, Scale };
+//! [0]
+
+//! [1]
+class RenderArea : public QWidget
+{
+ Q_OBJECT
+
+public:
+ RenderArea(QWidget *parent = 0);
+
+ void setOperations(const QList<Operation> &operations);
+ void setShape(const QPainterPath &shape);
+
+ QSize minimumSizeHint() const;
+ QSize sizeHint() const;
+
+protected:
+ void paintEvent(QPaintEvent *event);
+//! [1]
+
+//! [2]
+private:
+ void drawCoordinates(QPainter &painter);
+ void drawOutline(QPainter &painter);
+ void drawShape(QPainter &painter);
+ void transformPainter(QPainter &painter);
+
+ QList<Operation> operations;
+ QPainterPath shape;
+ QRect xBoundingRect;
+ QRect yBoundingRect;
+};
+//! [2]
+
+#endif
diff --git a/examples/painting/transformations/transformations.pro b/examples/painting/transformations/transformations.pro
new file mode 100644
index 0000000000..9256f1499a
--- /dev/null
+++ b/examples/painting/transformations/transformations.pro
@@ -0,0 +1,16 @@
+HEADERS = renderarea.h \
+ window.h
+SOURCES = main.cpp \
+ renderarea.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/transformations
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS transformations.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/transformations
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000A64D
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/painting/transformations/window.cpp b/examples/painting/transformations/window.cpp
new file mode 100644
index 0000000000..fc3bcb856d
--- /dev/null
+++ b/examples/painting/transformations/window.cpp
@@ -0,0 +1,180 @@
+/****************************************************************************
+**
+** 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 "window.h"
+
+//! [0]
+Window::Window()
+{
+ originalRenderArea = new RenderArea;
+
+ shapeComboBox = new QComboBox;
+ shapeComboBox->addItem(tr("Clock"));
+ shapeComboBox->addItem(tr("House"));
+ shapeComboBox->addItem(tr("Text"));
+ shapeComboBox->addItem(tr("Truck"));
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(originalRenderArea, 0, 0);
+ layout->addWidget(shapeComboBox, 1, 0);
+//! [0]
+
+//! [1]
+ for (int i = 0; i < NumTransformedAreas; ++i) {
+ transformedRenderAreas[i] = new RenderArea;
+
+ operationComboBoxes[i] = new QComboBox;
+ operationComboBoxes[i]->addItem(tr("No transformation"));
+ operationComboBoxes[i]->addItem(tr("Rotate by 60\xB0"));
+ operationComboBoxes[i]->addItem(tr("Scale to 75%"));
+ operationComboBoxes[i]->addItem(tr("Translate by (50, 50)"));
+
+ connect(operationComboBoxes[i], SIGNAL(activated(int)),
+ this, SLOT(operationChanged()));
+
+ layout->addWidget(transformedRenderAreas[i], 0, i + 1);
+ layout->addWidget(operationComboBoxes[i], 1, i + 1);
+ }
+//! [1]
+
+//! [2]
+ setLayout(layout);
+ setupShapes();
+ shapeSelected(0);
+
+ setWindowTitle(tr("Transformations"));
+}
+//! [2]
+
+//! [3]
+void Window::setupShapes()
+{
+ QPainterPath truck;
+//! [3]
+ truck.setFillRule(Qt::WindingFill);
+ truck.moveTo(0.0, 87.0);
+ truck.lineTo(0.0, 60.0);
+ truck.lineTo(10.0, 60.0);
+ truck.lineTo(35.0, 35.0);
+ truck.lineTo(100.0, 35.0);
+ truck.lineTo(100.0, 87.0);
+ truck.lineTo(0.0, 87.0);
+ truck.moveTo(17.0, 60.0);
+ truck.lineTo(55.0, 60.0);
+ truck.lineTo(55.0, 40.0);
+ truck.lineTo(37.0, 40.0);
+ truck.lineTo(17.0, 60.0);
+ truck.addEllipse(17.0, 75.0, 25.0, 25.0);
+ truck.addEllipse(63.0, 75.0, 25.0, 25.0);
+
+//! [4]
+ QPainterPath clock;
+//! [4]
+ clock.addEllipse(-50.0, -50.0, 100.0, 100.0);
+ clock.addEllipse(-48.0, -48.0, 96.0, 96.0);
+ clock.moveTo(0.0, 0.0);
+ clock.lineTo(-2.0, -2.0);
+ clock.lineTo(0.0, -42.0);
+ clock.lineTo(2.0, -2.0);
+ clock.lineTo(0.0, 0.0);
+ clock.moveTo(0.0, 0.0);
+ clock.lineTo(2.732, -0.732);
+ clock.lineTo(24.495, 14.142);
+ clock.lineTo(0.732, 2.732);
+ clock.lineTo(0.0, 0.0);
+
+//! [5]
+ QPainterPath house;
+//! [5]
+ house.moveTo(-45.0, -20.0);
+ house.lineTo(0.0, -45.0);
+ house.lineTo(45.0, -20.0);
+ house.lineTo(45.0, 45.0);
+ house.lineTo(-45.0, 45.0);
+ house.lineTo(-45.0, -20.0);
+ house.addRect(15.0, 5.0, 20.0, 35.0);
+ house.addRect(-35.0, -15.0, 25.0, 25.0);
+
+//! [6]
+ QPainterPath text;
+//! [6]
+ QFont font;
+ font.setPixelSize(50);
+ QRect fontBoundingRect = QFontMetrics(font).boundingRect(tr("Qt"));
+ text.addText(-QPointF(fontBoundingRect.center()), font, tr("Qt"));
+
+//! [7]
+ shapes.append(clock);
+ shapes.append(house);
+ shapes.append(text);
+ shapes.append(truck);
+
+ connect(shapeComboBox, SIGNAL(activated(int)),
+ this, SLOT(shapeSelected(int)));
+}
+//! [7]
+
+//! [8]
+void Window::operationChanged()
+{
+ static const Operation operationTable[] = {
+ NoTransformation, Rotate, Scale, Translate
+ };
+
+ QList<Operation> operations;
+ for (int i = 0; i < NumTransformedAreas; ++i) {
+ int index = operationComboBoxes[i]->currentIndex();
+ operations.append(operationTable[index]);
+ transformedRenderAreas[i]->setOperations(operations);
+ }
+}
+//! [8]
+
+//! [9]
+void Window::shapeSelected(int index)
+{
+ QPainterPath shape = shapes[index];
+ originalRenderArea->setShape(shape);
+ for (int i = 0; i < NumTransformedAreas; ++i)
+ transformedRenderAreas[i]->setShape(shape);
+}
+//! [9]
diff --git a/examples/painting/transformations/window.h b/examples/painting/transformations/window.h
new file mode 100644
index 0000000000..b7cd575a81
--- /dev/null
+++ b/examples/painting/transformations/window.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 WINDOW_H
+#define WINDOW_H
+
+#include <QList>
+#include <QPainterPath>
+#include <QWidget>
+
+#include "renderarea.h"
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+QT_END_NAMESPACE
+
+//! [0]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+public slots:
+ void operationChanged();
+ void shapeSelected(int index);
+//! [0]
+
+//! [1]
+private:
+ void setupShapes();
+
+ enum { NumTransformedAreas = 3 };
+ RenderArea *originalRenderArea;
+ RenderArea *transformedRenderAreas[NumTransformedAreas];
+ QComboBox *shapeComboBox;
+ QComboBox *operationComboBoxes[NumTransformedAreas];
+ QList<QPainterPath> shapes;
+};
+//! [1]
+
+#endif