summaryrefslogtreecommitdiffstats
path: root/examples/painting
diff options
context:
space:
mode:
Diffstat (limited to 'examples/painting')
-rw-r--r--examples/painting/composition/composition.cpp544
-rw-r--r--examples/painting/composition/composition.h193
-rw-r--r--examples/painting/composition/composition.html23
-rw-r--r--examples/painting/composition/composition.pro29
-rw-r--r--examples/painting/composition/composition.qrc8
-rw-r--r--examples/painting/composition/flower.jpgbin0 -> 49616 bytes
-rw-r--r--examples/painting/composition/flower_alpha.jpgbin0 -> 67326 bytes
-rw-r--r--examples/painting/composition/main.cpp68
-rw-r--r--examples/painting/deform/deform.pro24
-rw-r--r--examples/painting/deform/deform.qrc6
-rw-r--r--examples/painting/deform/main.cpp72
-rw-r--r--examples/painting/deform/pathdeform.cpp647
-rw-r--r--examples/painting/deform/pathdeform.h153
-rw-r--r--examples/painting/deform/pathdeform.html24
-rw-r--r--examples/painting/gradients/gradients.cpp516
-rw-r--r--examples/painting/gradients/gradients.h170
-rw-r--r--examples/painting/gradients/gradients.html31
-rw-r--r--examples/painting/gradients/gradients.pro20
-rw-r--r--examples/painting/gradients/gradients.qrc6
-rw-r--r--examples/painting/gradients/main.cpp63
-rw-r--r--examples/painting/pathstroke/main.cpp71
-rw-r--r--examples/painting/pathstroke/pathstroke.cpp686
-rw-r--r--examples/painting/pathstroke/pathstroke.h171
-rw-r--r--examples/painting/pathstroke/pathstroke.html20
-rw-r--r--examples/painting/pathstroke/pathstroke.pro24
-rw-r--r--examples/painting/pathstroke/pathstroke.qrc6
-rw-r--r--examples/painting/shared/arthurstyle.cpp452
-rw-r--r--examples/painting/shared/arthurstyle.h79
-rw-r--r--examples/painting/shared/arthurwidgets.cpp371
-rw-r--r--examples/painting/shared/arthurwidgets.h137
-rw-r--r--examples/painting/shared/hoverpoints.cpp415
-rw-r--r--examples/painting/shared/hoverpoints.h162
-rw-r--r--examples/painting/shared/images/bg_pattern.pngbin0 -> 104 bytes
-rw-r--r--examples/painting/shared/images/button_normal_cap_left.pngbin0 -> 654 bytes
-rw-r--r--examples/painting/shared/images/button_normal_cap_right.pngbin0 -> 674 bytes
-rw-r--r--examples/painting/shared/images/button_normal_stretch.pngbin0 -> 185 bytes
-rw-r--r--examples/painting/shared/images/button_pressed_cap_left.pngbin0 -> 710 bytes
-rw-r--r--examples/painting/shared/images/button_pressed_cap_right.pngbin0 -> 785 bytes
-rw-r--r--examples/painting/shared/images/button_pressed_stretch.pngbin0 -> 217 bytes
-rw-r--r--examples/painting/shared/images/curve_thing_edit-6.pngbin0 -> 58097 bytes
-rw-r--r--examples/painting/shared/images/frame_bottom.pngbin0 -> 166 bytes
-rw-r--r--examples/painting/shared/images/frame_bottomleft.pngbin0 -> 602 bytes
-rw-r--r--examples/painting/shared/images/frame_bottomright.pngbin0 -> 553 bytes
-rw-r--r--examples/painting/shared/images/frame_left.pngbin0 -> 182 bytes
-rw-r--r--examples/painting/shared/images/frame_right.pngbin0 -> 175 bytes
-rw-r--r--examples/painting/shared/images/frame_top.pngbin0 -> 188 bytes
-rw-r--r--examples/painting/shared/images/frame_topleft.pngbin0 -> 801 bytes
-rw-r--r--examples/painting/shared/images/frame_topright.pngbin0 -> 851 bytes
-rw-r--r--examples/painting/shared/images/groupframe_bottom_left.pngbin0 -> 397 bytes
-rw-r--r--examples/painting/shared/images/groupframe_bottom_right.pngbin0 -> 383 bytes
-rw-r--r--examples/painting/shared/images/groupframe_bottom_stretch.pngbin0 -> 141 bytes
-rw-r--r--examples/painting/shared/images/groupframe_left_stretch.pngbin0 -> 132 bytes
-rw-r--r--examples/painting/shared/images/groupframe_right_stretch.pngbin0 -> 113 bytes
-rw-r--r--examples/painting/shared/images/groupframe_top_stretch.pngbin0 -> 115 bytes
-rw-r--r--examples/painting/shared/images/groupframe_topleft.pngbin0 -> 412 bytes
-rw-r--r--examples/painting/shared/images/groupframe_topright.pngbin0 -> 449 bytes
-rw-r--r--examples/painting/shared/images/line_dash_dot.pngbin0 -> 151 bytes
-rw-r--r--examples/painting/shared/images/line_dash_dot_dot.pngbin0 -> 155 bytes
-rw-r--r--examples/painting/shared/images/line_dashed.pngbin0 -> 121 bytes
-rw-r--r--examples/painting/shared/images/line_dotted.pngbin0 -> 116 bytes
-rw-r--r--examples/painting/shared/images/line_solid.pngbin0 -> 110 bytes
-rw-r--r--examples/painting/shared/images/radiobutton-off.pngbin0 -> 442 bytes
-rw-r--r--examples/painting/shared/images/radiobutton-on.pngbin0 -> 474 bytes
-rw-r--r--examples/painting/shared/images/radiobutton_off.pngbin0 -> 442 bytes
-rw-r--r--examples/painting/shared/images/radiobutton_on.pngbin0 -> 499 bytes
-rw-r--r--examples/painting/shared/images/slider_bar.pngbin0 -> 748 bytes
-rw-r--r--examples/painting/shared/images/slider_thumb_off.pngbin0 -> 823 bytes
-rw-r--r--examples/painting/shared/images/slider_thumb_on.pngbin0 -> 798 bytes
-rw-r--r--examples/painting/shared/images/title_cap_left.pngbin0 -> 179 bytes
-rw-r--r--examples/painting/shared/images/title_cap_right.pngbin0 -> 184 bytes
-rw-r--r--examples/painting/shared/images/title_stretch.pngbin0 -> 106 bytes
-rw-r--r--examples/painting/shared/shared.pri21
-rw-r--r--examples/painting/shared/shared.pro39
-rw-r--r--examples/painting/shared/shared.qrc39
74 files changed, 5290 insertions, 0 deletions
diff --git a/examples/painting/composition/composition.cpp b/examples/painting/composition/composition.cpp
new file mode 100644
index 0000000000..b3f810b26c
--- /dev/null
+++ b/examples/painting/composition/composition.cpp
@@ -0,0 +1,544 @@
+/****************************************************************************
+**
+** 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 demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "composition.h"
+#include <QBoxLayout>
+#include <QRadioButton>
+#include <QTimer>
+#include <QDateTime>
+#include <QSlider>
+#include <QMouseEvent>
+#include <qmath.h>
+
+const int animationInterval = 15; // update every 16 ms = ~60FPS
+
+CompositionWidget::CompositionWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ CompositionRenderer *view = new CompositionRenderer(this);
+
+ QGroupBox *mainGroup = new QGroupBox(parent);
+ mainGroup->setTitle(tr("Composition Modes"));
+
+ QGroupBox *modesGroup = new QGroupBox(mainGroup);
+ modesGroup->setTitle(tr("Mode"));
+
+ rbClear = new QRadioButton(tr("Clear"), modesGroup);
+ connect(rbClear, SIGNAL(clicked()), view, SLOT(setClearMode()));
+ rbSource = new QRadioButton(tr("Source"), modesGroup);
+ connect(rbSource, SIGNAL(clicked()), view, SLOT(setSourceMode()));
+ rbDest = new QRadioButton(tr("Destination"), modesGroup);
+ connect(rbDest, SIGNAL(clicked()), view, SLOT(setDestMode()));
+ rbSourceOver = new QRadioButton(tr("Source Over"), modesGroup);
+ connect(rbSourceOver, SIGNAL(clicked()), view, SLOT(setSourceOverMode()));
+ rbDestOver = new QRadioButton(tr("Destination Over"), modesGroup);
+ connect(rbDestOver, SIGNAL(clicked()), view, SLOT(setDestOverMode()));
+ rbSourceIn = new QRadioButton(tr("Source In"), modesGroup);
+ connect(rbSourceIn, SIGNAL(clicked()), view, SLOT(setSourceInMode()));
+ rbDestIn = new QRadioButton(tr("Dest In"), modesGroup);
+ connect(rbDestIn, SIGNAL(clicked()), view, SLOT(setDestInMode()));
+ rbSourceOut = new QRadioButton(tr("Source Out"), modesGroup);
+ connect(rbSourceOut, SIGNAL(clicked()), view, SLOT(setSourceOutMode()));
+ rbDestOut = new QRadioButton(tr("Dest Out"), modesGroup);
+ connect(rbDestOut, SIGNAL(clicked()), view, SLOT(setDestOutMode()));
+ rbSourceAtop = new QRadioButton(tr("Source Atop"), modesGroup);
+ connect(rbSourceAtop, SIGNAL(clicked()), view, SLOT(setSourceAtopMode()));
+ rbDestAtop = new QRadioButton(tr("Dest Atop"), modesGroup);
+ connect(rbDestAtop, SIGNAL(clicked()), view, SLOT(setDestAtopMode()));
+ rbXor = new QRadioButton(tr("Xor"), modesGroup);
+ connect(rbXor, SIGNAL(clicked()), view, SLOT(setXorMode()));
+
+ rbPlus = new QRadioButton(tr("Plus"), modesGroup);
+ connect(rbPlus, SIGNAL(clicked()), view, SLOT(setPlusMode()));
+ rbMultiply = new QRadioButton(tr("Multiply"), modesGroup);
+ connect(rbMultiply, SIGNAL(clicked()), view, SLOT(setMultiplyMode()));
+ rbScreen = new QRadioButton(tr("Screen"), modesGroup);
+ connect(rbScreen, SIGNAL(clicked()), view, SLOT(setScreenMode()));
+ rbOverlay = new QRadioButton(tr("Overlay"), modesGroup);
+ connect(rbOverlay, SIGNAL(clicked()), view, SLOT(setOverlayMode()));
+ rbDarken = new QRadioButton(tr("Darken"), modesGroup);
+ connect(rbDarken, SIGNAL(clicked()), view, SLOT(setDarkenMode()));
+ rbLighten = new QRadioButton(tr("Lighten"), modesGroup);
+ connect(rbLighten, SIGNAL(clicked()), view, SLOT(setLightenMode()));
+ rbColorDodge = new QRadioButton(tr("Color Dodge"), modesGroup);
+ connect(rbColorDodge, SIGNAL(clicked()), view, SLOT(setColorDodgeMode()));
+ rbColorBurn = new QRadioButton(tr("Color Burn"), modesGroup);
+ connect(rbColorBurn, SIGNAL(clicked()), view, SLOT(setColorBurnMode()));
+ rbHardLight = new QRadioButton(tr("Hard Light"), modesGroup);
+ connect(rbHardLight, SIGNAL(clicked()), view, SLOT(setHardLightMode()));
+ rbSoftLight = new QRadioButton(tr("Soft Light"), modesGroup);
+ connect(rbSoftLight, SIGNAL(clicked()), view, SLOT(setSoftLightMode()));
+ rbDifference = new QRadioButton(tr("Difference"), modesGroup);
+ connect(rbDifference, SIGNAL(clicked()), view, SLOT(setDifferenceMode()));
+ rbExclusion = new QRadioButton(tr("Exclusion"), modesGroup);
+ connect(rbExclusion, SIGNAL(clicked()), view, SLOT(setExclusionMode()));
+
+ QGroupBox *circleColorGroup = new QGroupBox(mainGroup);
+ circleColorGroup->setTitle(tr("Circle color"));
+ QSlider *circleColorSlider = new QSlider(Qt::Horizontal, circleColorGroup);
+ circleColorSlider->setRange(0, 359);
+ circleColorSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+ connect(circleColorSlider, SIGNAL(valueChanged(int)), view, SLOT(setCircleColor(int)));
+
+ QGroupBox *circleAlphaGroup = new QGroupBox(mainGroup);
+ circleAlphaGroup->setTitle(tr("Circle alpha"));
+ QSlider *circleAlphaSlider = new QSlider(Qt::Horizontal, circleAlphaGroup);
+ circleAlphaSlider->setRange(0, 255);
+ circleAlphaSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+ connect(circleAlphaSlider, SIGNAL(valueChanged(int)), view, SLOT(setCircleAlpha(int)));
+
+ QPushButton *showSourceButton = new QPushButton(mainGroup);
+ showSourceButton->setText(tr("Show Source"));
+#if defined(QT_OPENGL_SUPPORT) && !defined(QT_OPENGL_ES)
+ QPushButton *enableOpenGLButton = new QPushButton(mainGroup);
+ enableOpenGLButton->setText(tr("Use OpenGL"));
+ enableOpenGLButton->setCheckable(true);
+ enableOpenGLButton->setChecked(view->usesOpenGL());
+
+ if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers())
+ enableOpenGLButton->hide();
+#endif
+ QPushButton *whatsThisButton = new QPushButton(mainGroup);
+ whatsThisButton->setText(tr("What's This?"));
+ whatsThisButton->setCheckable(true);
+
+ QPushButton *animateButton = new QPushButton(mainGroup);
+ animateButton->setText(tr("Animated"));
+ animateButton->setCheckable(true);
+ animateButton->setChecked(true);
+
+ QHBoxLayout *viewLayout = new QHBoxLayout(this);
+ viewLayout->addWidget(view);
+ viewLayout->addWidget(mainGroup);
+
+ QVBoxLayout *mainGroupLayout = new QVBoxLayout(mainGroup);
+ mainGroupLayout->addWidget(circleColorGroup);
+ mainGroupLayout->addWidget(circleAlphaGroup);
+ mainGroupLayout->addWidget(modesGroup);
+ mainGroupLayout->addStretch();
+ mainGroupLayout->addWidget(animateButton);
+ mainGroupLayout->addWidget(whatsThisButton);
+ mainGroupLayout->addWidget(showSourceButton);
+#if defined(QT_OPENGL_SUPPORT) && !defined(QT_OPENGL_ES)
+ mainGroupLayout->addWidget(enableOpenGLButton);
+#endif
+
+ QGridLayout *modesLayout = new QGridLayout(modesGroup);
+ modesLayout->addWidget(rbClear, 0, 0);
+ modesLayout->addWidget(rbSource, 1, 0);
+ modesLayout->addWidget(rbDest, 2, 0);
+ modesLayout->addWidget(rbSourceOver, 3, 0);
+ modesLayout->addWidget(rbDestOver, 4, 0);
+ modesLayout->addWidget(rbSourceIn, 5, 0);
+ modesLayout->addWidget(rbDestIn, 6, 0);
+ modesLayout->addWidget(rbSourceOut, 7, 0);
+ modesLayout->addWidget(rbDestOut, 8, 0);
+ modesLayout->addWidget(rbSourceAtop, 9, 0);
+ modesLayout->addWidget(rbDestAtop, 10, 0);
+ modesLayout->addWidget(rbXor, 11, 0);
+
+ modesLayout->addWidget(rbPlus, 0, 1);
+ modesLayout->addWidget(rbMultiply, 1, 1);
+ modesLayout->addWidget(rbScreen, 2, 1);
+ modesLayout->addWidget(rbOverlay, 3, 1);
+ modesLayout->addWidget(rbDarken, 4, 1);
+ modesLayout->addWidget(rbLighten, 5, 1);
+ modesLayout->addWidget(rbColorDodge, 6, 1);
+ modesLayout->addWidget(rbColorBurn, 7, 1);
+ modesLayout->addWidget(rbHardLight, 8, 1);
+ modesLayout->addWidget(rbSoftLight, 9, 1);
+ modesLayout->addWidget(rbDifference, 10, 1);
+ modesLayout->addWidget(rbExclusion, 11, 1);
+
+
+ QVBoxLayout *circleColorLayout = new QVBoxLayout(circleColorGroup);
+ circleColorLayout->addWidget(circleColorSlider);
+
+ QVBoxLayout *circleAlphaLayout = new QVBoxLayout(circleAlphaGroup);
+ circleAlphaLayout->addWidget(circleAlphaSlider);
+
+ view->loadDescription(":res/composition/composition.html");
+ view->loadSourceFile(":res/composition/composition.cpp");
+
+ connect(whatsThisButton, SIGNAL(clicked(bool)), view, SLOT(setDescriptionEnabled(bool)));
+ connect(view, SIGNAL(descriptionEnabledChanged(bool)), whatsThisButton, SLOT(setChecked(bool)));
+ connect(showSourceButton, SIGNAL(clicked()), view, SLOT(showSource()));
+#if defined(QT_OPENGL_SUPPORT) && !defined(QT_OPENGL_ES)
+ connect(enableOpenGLButton, SIGNAL(clicked(bool)), view, SLOT(enableOpenGL(bool)));
+#endif
+ connect(animateButton, SIGNAL(toggled(bool)), view, SLOT(setAnimationEnabled(bool)));
+
+ circleColorSlider->setValue(270);
+ circleAlphaSlider->setValue(200);
+ rbSourceOut->animateClick();
+
+ setWindowTitle(tr("Composition Modes"));
+}
+
+
+void CompositionWidget::nextMode()
+{
+ /*
+ if (!m_animation_enabled)
+ return;
+ if (rbClear->isChecked()) rbSource->animateClick();
+ if (rbSource->isChecked()) rbDest->animateClick();
+ if (rbDest->isChecked()) rbSourceOver->animateClick();
+ if (rbSourceOver->isChecked()) rbDestOver->animateClick();
+ if (rbDestOver->isChecked()) rbSourceIn->animateClick();
+ if (rbSourceIn->isChecked()) rbDestIn->animateClick();
+ if (rbDestIn->isChecked()) rbSourceOut->animateClick();
+ if (rbSourceOut->isChecked()) rbDestOut->animateClick();
+ if (rbDestOut->isChecked()) rbSourceAtop->animateClick();
+ if (rbSourceAtop->isChecked()) rbDestAtop->animateClick();
+ if (rbDestAtop->isChecked()) rbXor->animateClick();
+ if (rbXor->isChecked()) rbClear->animateClick();
+ */
+}
+
+CompositionRenderer::CompositionRenderer(QWidget *parent)
+ : ArthurFrame(parent)
+{
+ m_animation_enabled = true;
+ m_animationTimer = startTimer(animationInterval);
+#ifdef Q_WS_QWS
+ m_image = QPixmap(":res/composition/flower.jpg");
+ m_image.setAlphaChannel(QPixmap(":res/composition/flower_alpha.jpg"));
+#else
+ m_image = QImage(":res/composition/flower.jpg");
+ m_image.setAlphaChannel(QImage(":res/composition/flower_alpha.jpg"));
+#endif
+ m_circle_alpha = 127;
+ m_circle_hue = 255;
+ m_current_object = NoObject;
+ m_composition_mode = QPainter::CompositionMode_SourceOut;
+
+ m_circle_pos = QPoint(200, 100);
+
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+#ifdef QT_OPENGL_SUPPORT
+ m_pbuffer = 0;
+ m_pbuffer_size = 1024;
+#endif
+}
+
+QRectF rectangle_around(const QPointF &p, const QSizeF &size = QSize(250, 200))
+{
+ QRectF rect(p, size);
+ rect.translate(-size.width()/2, -size.height()/2);
+ return rect;
+}
+
+void CompositionRenderer::setAnimationEnabled(bool enabled)
+{
+ if (m_animation_enabled == enabled)
+ return;
+ m_animation_enabled = enabled;
+ if (enabled) {
+ Q_ASSERT(!m_animationTimer);
+ m_animationTimer = startTimer(animationInterval);
+ } else {
+ killTimer(m_animationTimer);
+ m_animationTimer = 0;
+ }
+}
+
+void CompositionRenderer::updateCirclePos()
+{
+ if (m_current_object != NoObject)
+ return;
+ QDateTime dt = QDateTime::currentDateTime();
+ qreal t = (dt.toTime_t() * 1000 + dt.time().msec()) / 1000.0;
+
+ qreal x = width() / qreal(2) + (qCos(t*8/11) + qSin(-t)) * width() / qreal(4);
+ qreal y = height() / qreal(2) + (qSin(t*6/7) + qCos(t * qreal(1.5))) * height() / qreal(4);
+
+ setCirclePos(QLineF(m_circle_pos, QPointF(x, y)).pointAt(0.02));
+}
+
+void CompositionRenderer::drawBase(QPainter &p)
+{
+ p.setPen(Qt::NoPen);
+
+ QLinearGradient rect_gradient(0, 0, 0, height());
+ rect_gradient.setColorAt(0, Qt::red);
+ rect_gradient.setColorAt(.17, Qt::yellow);
+ rect_gradient.setColorAt(.33, Qt::green);
+ rect_gradient.setColorAt(.50, Qt::cyan);
+ rect_gradient.setColorAt(.66, Qt::blue);
+ rect_gradient.setColorAt(.81, Qt::magenta);
+ rect_gradient.setColorAt(1, Qt::red);
+ p.setBrush(rect_gradient);
+ p.drawRect(width() / 2, 0, width() / 2, height());
+
+ QLinearGradient alpha_gradient(0, 0, width(), 0);
+ alpha_gradient.setColorAt(0, Qt::white);
+ alpha_gradient.setColorAt(0.2, Qt::white);
+ alpha_gradient.setColorAt(0.5, Qt::transparent);
+ alpha_gradient.setColorAt(0.8, Qt::white);
+ alpha_gradient.setColorAt(1, Qt::white);
+
+ p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
+ p.setBrush(alpha_gradient);
+ p.drawRect(0, 0, width(), height());
+
+ p.setCompositionMode(QPainter::CompositionMode_DestinationOver);
+
+ p.setPen(Qt::NoPen);
+ p.setRenderHint(QPainter::SmoothPixmapTransform);
+#ifdef Q_WS_QWS
+ p.drawPixmap(rect(), m_image);
+#else
+ p.drawImage(rect(), m_image);
+#endif
+}
+
+void CompositionRenderer::drawSource(QPainter &p)
+{
+ p.setPen(Qt::NoPen);
+ p.setRenderHint(QPainter::Antialiasing);
+ p.setCompositionMode(m_composition_mode);
+
+ QRectF circle_rect = rectangle_around(m_circle_pos);
+ QColor color = QColor::fromHsvF(m_circle_hue / 360.0, 1, 1, m_circle_alpha / 255.0);
+ QLinearGradient circle_gradient(circle_rect.topLeft(), circle_rect.bottomRight());
+ circle_gradient.setColorAt(0, color.light());
+ circle_gradient.setColorAt(0.5, color);
+ circle_gradient.setColorAt(1, color.dark());
+ p.setBrush(circle_gradient);
+
+ p.drawEllipse(circle_rect);
+}
+
+void CompositionRenderer::paint(QPainter *painter)
+{
+#if defined(QT_OPENGL_SUPPORT) && !defined(QT_OPENGL_ES)
+ if (usesOpenGL()) {
+
+ int new_pbuf_size = m_pbuffer_size;
+ if (size().width() > m_pbuffer_size ||
+ size().height() > m_pbuffer_size)
+ new_pbuf_size *= 2;
+
+ if (size().width() < m_pbuffer_size/2 &&
+ size().height() < m_pbuffer_size/2)
+ new_pbuf_size /= 2;
+
+ if (!m_pbuffer || new_pbuf_size != m_pbuffer_size) {
+ if (m_pbuffer) {
+ m_pbuffer->deleteTexture(m_base_tex);
+ m_pbuffer->deleteTexture(m_compositing_tex);
+ delete m_pbuffer;
+ }
+
+ m_pbuffer = new QGLPixelBuffer(QSize(new_pbuf_size, new_pbuf_size), QGLFormat::defaultFormat(), glWidget());
+ m_pbuffer->makeCurrent();
+ m_base_tex = m_pbuffer->generateDynamicTexture();
+ m_compositing_tex = m_pbuffer->generateDynamicTexture();
+ m_pbuffer_size = new_pbuf_size;
+ }
+
+ if (size() != m_previous_size) {
+ m_previous_size = size();
+ QPainter p(m_pbuffer);
+ p.setCompositionMode(QPainter::CompositionMode_Source);
+ p.fillRect(QRect(0, 0, m_pbuffer->width(), m_pbuffer->height()), Qt::transparent);
+ drawBase(p);
+ p.end();
+ m_pbuffer->updateDynamicTexture(m_base_tex);
+ }
+
+ qreal x_fraction = width()/float(m_pbuffer->width());
+ qreal y_fraction = height()/float(m_pbuffer->height());
+
+ {
+ QPainter p(m_pbuffer);
+ p.setCompositionMode(QPainter::CompositionMode_Source);
+ p.fillRect(QRect(0, 0, m_pbuffer->width(), m_pbuffer->height()), Qt::transparent);
+
+ p.save(); // Needed when using the GL1 engine
+ p.beginNativePainting(); // Needed when using the GL2 engine
+
+ glBindTexture(GL_TEXTURE_2D, m_base_tex);
+ glEnable(GL_TEXTURE_2D);
+ glColor4f(1.,1.,1.,1.);
+
+ glBegin(GL_QUADS);
+ {
+ glTexCoord2f(0, 1.0);
+ glVertex2f(0, 0);
+
+ glTexCoord2f(x_fraction, 1.0);
+ glVertex2f(width(), 0);
+
+ glTexCoord2f(x_fraction, 1.0-y_fraction);
+ glVertex2f(width(), height());
+
+ glTexCoord2f(0, 1.0-y_fraction);
+ glVertex2f(0, height());
+ }
+ glEnd();
+
+ glDisable(GL_TEXTURE_2D);
+
+ p.endNativePainting(); // Needed when using the GL2 engine
+ p.restore(); // Needed when using the GL1 engine
+
+ drawSource(p);
+ p.end();
+ m_pbuffer->updateDynamicTexture(m_compositing_tex);
+ }
+
+ painter->beginNativePainting(); // Needed when using the GL2 engine
+ glWidget()->makeCurrent(); // Needed when using the GL1 engine
+ glBindTexture(GL_TEXTURE_2D, m_compositing_tex);
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ glColor4f(1.,1.,1.,1.);
+ glBegin(GL_QUADS);
+ {
+ glTexCoord2f(0, 1.0);
+ glVertex2f(0, 0);
+
+ glTexCoord2f(x_fraction, 1.0);
+ glVertex2f(width(), 0);
+
+ glTexCoord2f(x_fraction, 1.0-y_fraction);
+ glVertex2f(width(), height());
+
+ glTexCoord2f(0, 1.0-y_fraction);
+ glVertex2f(0, height());
+ }
+ glEnd();
+ glDisable(GL_TEXTURE_2D);
+ painter->endNativePainting(); // Needed when using the GL2 engine
+ } else
+#endif
+ {
+ // using a QImage
+ if (m_buffer.size() != size()) {
+#ifdef Q_WS_QWS
+ m_base_buffer = QPixmap(size());
+ m_base_buffer.fill(Qt::transparent);
+#else
+ m_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied);
+ m_base_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied);
+
+ m_base_buffer.fill(0);
+#endif
+
+ QPainter p(&m_base_buffer);
+
+ drawBase(p);
+ }
+
+#ifdef Q_WS_QWS
+ m_buffer = m_base_buffer;
+#else
+ memcpy(m_buffer.bits(), m_base_buffer.bits(), m_buffer.byteCount());
+#endif
+
+ {
+ QPainter p(&m_buffer);
+ drawSource(p);
+ }
+
+#ifdef Q_WS_QWS
+ painter->drawPixmap(0, 0, m_buffer);
+#else
+ painter->drawImage(0, 0, m_buffer);
+#endif
+ }
+}
+
+void CompositionRenderer::mousePressEvent(QMouseEvent *e)
+{
+ setDescriptionEnabled(false);
+
+ QRectF circle = rectangle_around(m_circle_pos);
+
+ if (circle.contains(e->pos())) {
+ m_current_object = Circle;
+ m_offset = circle.center() - e->pos();
+ } else {
+ m_current_object = NoObject;
+ }
+ if (m_animation_enabled) {
+ killTimer(m_animationTimer);
+ m_animationTimer = 0;
+ }
+}
+
+void CompositionRenderer::mouseMoveEvent(QMouseEvent *e)
+{
+ if (m_current_object == Circle) setCirclePos(e->pos() + m_offset);
+}
+
+void CompositionRenderer::mouseReleaseEvent(QMouseEvent *)
+{
+ m_current_object = NoObject;
+
+ if (m_animation_enabled) {
+ Q_ASSERT(!m_animationTimer);
+ m_animationTimer = startTimer(animationInterval);
+ }
+}
+
+void CompositionRenderer::timerEvent(QTimerEvent *event)
+{
+ if (event->timerId() == m_animationTimer)
+ updateCirclePos();
+}
+
+void CompositionRenderer::setCirclePos(const QPointF &pos)
+{
+ const QRect oldRect = rectangle_around(m_circle_pos).toAlignedRect();
+ m_circle_pos = pos;
+ const QRect newRect = rectangle_around(m_circle_pos).toAlignedRect();
+#if defined(QT_OPENGL_SUPPORT) && !defined(QT_OPENGL_ES)
+ if (usesOpenGL())
+ update();
+ else
+#endif
+ update(oldRect | newRect);
+}
+
diff --git a/examples/painting/composition/composition.h b/examples/painting/composition/composition.h
new file mode 100644
index 0000000000..86e8f5c0df
--- /dev/null
+++ b/examples/painting/composition/composition.h
@@ -0,0 +1,193 @@
+/****************************************************************************
+**
+** 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 demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef COMPOSITION_H
+#define COMPOSITION_H
+
+#include "arthurwidgets.h"
+
+#include <QPainter>
+#include <QEvent>
+
+QT_FORWARD_DECLARE_CLASS(QPushButton)
+QT_FORWARD_DECLARE_CLASS(QRadioButton)
+
+#ifdef QT_OPENGL_SUPPORT
+#include <QtOpenGL>
+#endif
+
+class CompositionWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ CompositionWidget(QWidget *parent);
+
+public slots:
+void nextMode();
+
+private:
+ bool m_cycle_enabled;
+
+ QRadioButton *rbClear;
+ QRadioButton *rbSource;
+ QRadioButton *rbDest;
+ QRadioButton *rbSourceOver;
+ QRadioButton *rbDestOver;
+ QRadioButton *rbSourceIn;
+ QRadioButton *rbDestIn;
+ QRadioButton *rbSourceOut;
+ QRadioButton *rbDestOut;
+ QRadioButton *rbSourceAtop;
+ QRadioButton *rbDestAtop;
+ QRadioButton *rbXor;
+
+ QRadioButton *rbPlus;
+ QRadioButton *rbMultiply;
+ QRadioButton *rbScreen;
+ QRadioButton *rbOverlay;
+ QRadioButton *rbDarken;
+ QRadioButton *rbLighten;
+ QRadioButton *rbColorDodge;
+ QRadioButton *rbColorBurn;
+ QRadioButton *rbHardLight;
+ QRadioButton *rbSoftLight;
+ QRadioButton *rbDifference;
+ QRadioButton *rbExclusion;
+};
+
+class CompositionRenderer : public ArthurFrame
+{
+ Q_OBJECT
+
+ enum ObjectType { NoObject, Circle, Rectangle, Image };
+
+ Q_PROPERTY(int circleColor READ circleColor WRITE setCircleColor)
+ Q_PROPERTY(int circleAlpha READ circleAlpha WRITE setCircleAlpha)
+ Q_PROPERTY(bool animation READ animationEnabled WRITE setAnimationEnabled)
+
+public:
+ CompositionRenderer(QWidget *parent);
+
+ void paint(QPainter *);
+
+ void setCirclePos(const QPointF &pos);
+
+ QSize sizeHint() const { return QSize(500, 400); }
+
+ bool animationEnabled() const { return m_animation_enabled; }
+ int circleColor() const { return m_circle_hue; }
+ int circleAlpha() const { return m_circle_alpha; }
+
+protected:
+ void mousePressEvent(QMouseEvent *);
+ void mouseMoveEvent(QMouseEvent *);
+ void mouseReleaseEvent(QMouseEvent *);
+ void timerEvent(QTimerEvent *);
+
+public slots:
+ void setClearMode() { m_composition_mode = QPainter::CompositionMode_Clear; update(); }
+ void setSourceMode() { m_composition_mode = QPainter::CompositionMode_Source; update(); }
+ void setDestMode() { m_composition_mode = QPainter::CompositionMode_Destination; update(); }
+ void setSourceOverMode() { m_composition_mode = QPainter::CompositionMode_SourceOver; update(); }
+ void setDestOverMode() { m_composition_mode = QPainter::CompositionMode_DestinationOver; update(); }
+ void setSourceInMode() { m_composition_mode = QPainter::CompositionMode_SourceIn; update(); }
+ void setDestInMode() { m_composition_mode = QPainter::CompositionMode_DestinationIn; update(); }
+ void setSourceOutMode() { m_composition_mode = QPainter::CompositionMode_SourceOut; update(); }
+ void setDestOutMode() { m_composition_mode = QPainter::CompositionMode_DestinationOut; update(); }
+ void setSourceAtopMode() { m_composition_mode = QPainter::CompositionMode_SourceAtop; update(); }
+ void setDestAtopMode() { m_composition_mode = QPainter::CompositionMode_DestinationAtop; update(); }
+ void setXorMode() { m_composition_mode = QPainter::CompositionMode_Xor; update(); }
+
+ void setPlusMode() { m_composition_mode = QPainter::CompositionMode_Plus; update(); }
+ void setMultiplyMode() { m_composition_mode = QPainter::CompositionMode_Multiply; update(); }
+ void setScreenMode() { m_composition_mode = QPainter::CompositionMode_Screen; update(); }
+ void setOverlayMode() { m_composition_mode = QPainter::CompositionMode_Overlay; update(); }
+ void setDarkenMode() { m_composition_mode = QPainter::CompositionMode_Darken; update(); }
+ void setLightenMode() { m_composition_mode = QPainter::CompositionMode_Lighten; update(); }
+ void setColorDodgeMode() { m_composition_mode = QPainter::CompositionMode_ColorDodge; update(); }
+ void setColorBurnMode() { m_composition_mode = QPainter::CompositionMode_ColorBurn; update(); }
+ void setHardLightMode() { m_composition_mode = QPainter::CompositionMode_HardLight; update(); }
+ void setSoftLightMode() { m_composition_mode = QPainter::CompositionMode_SoftLight; update(); }
+ void setDifferenceMode() { m_composition_mode = QPainter::CompositionMode_Difference; update(); }
+ void setExclusionMode() { m_composition_mode = QPainter::CompositionMode_Exclusion; update(); }
+
+ void setCircleAlpha(int alpha) { m_circle_alpha = alpha; update(); }
+ void setCircleColor(int hue) { m_circle_hue = hue; update(); }
+ void setAnimationEnabled(bool enabled);
+
+private:
+ void updateCirclePos();
+ void drawBase(QPainter &p);
+ void drawSource(QPainter &p);
+
+ QPainter::CompositionMode m_composition_mode;
+
+#ifdef Q_WS_QWS
+ QPixmap m_image;
+ QPixmap m_buffer;
+ QPixmap m_base_buffer;
+#else
+ QImage m_image;
+ QImage m_buffer;
+ QImage m_base_buffer;
+#endif
+
+ int m_circle_alpha;
+ int m_circle_hue;
+
+ QPointF m_circle_pos;
+ QPointF m_offset;
+
+ ObjectType m_current_object;
+ bool m_animation_enabled;
+ int m_animationTimer;
+
+#ifdef QT_OPENGL_SUPPORT
+ QGLPixelBuffer *m_pbuffer;
+ GLuint m_base_tex;
+ GLuint m_compositing_tex;
+ int m_pbuffer_size; // width==height==size of pbuffer
+ QSize m_previous_size;
+#endif
+};
+
+#endif // COMPOSITION_H
diff --git a/examples/painting/composition/composition.html b/examples/painting/composition/composition.html
new file mode 100644
index 0000000000..1848ad8bd1
--- /dev/null
+++ b/examples/painting/composition/composition.html
@@ -0,0 +1,23 @@
+<html>
+
+<h1>Demo for composition modes</h1>
+
+<p>
+ This demo shows some of the more advanced composition modes supported by Qt.
+</p>
+
+<p>
+ The two most common forms of composition are <b>Source</b> and <b>SourceOver</b>.
+ <b>Source</b> is used to draw opaque objects onto a paint device. In this mode,
+ each pixel in the source replaces the corresponding pixel in the destination.
+ In <b>SourceOver</b> composition mode, the source object is transparent and is
+ drawn on top of the destination.
+</p>
+
+<p>
+ In addition to these standard modes, Qt defines the complete set of composition
+ modes as defined by Thomas Porter and Tom Duff. See the <tt>QPainter</tt> documentation
+ for details.
+</p>
+
+</html>
diff --git a/examples/painting/composition/composition.pro b/examples/painting/composition/composition.pro
new file mode 100644
index 0000000000..59b91126b9
--- /dev/null
+++ b/examples/painting/composition/composition.pro
@@ -0,0 +1,29 @@
+SOURCES += main.cpp composition.cpp
+HEADERS += composition.h
+
+SHARED_FOLDER = ../shared
+
+include($$SHARED_FOLDER/shared.pri)
+
+RESOURCES += composition.qrc
+contains(QT_CONFIG, opengl) {
+ DEFINES += QT_OPENGL_SUPPORT
+ QT += opengl
+}
+
+# install
+target.path = $$[QT_INSTALL_DEMOS]/qtbase/composition
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.png *.jpg *.pro *.html
+sources.path = $$[QT_INSTALL_DEMOS]/qtbase/composition
+INSTALLS += target sources
+
+symbian: CONFIG += qt_demo
+
+win32-msvc* {
+ QMAKE_CXXFLAGS += /Zm500
+ QMAKE_CFLAGS += /Zm500
+}
+
+wince* {
+ DEPLOYMENT_PLUGIN += qjpeg
+}
diff --git a/examples/painting/composition/composition.qrc b/examples/painting/composition/composition.qrc
new file mode 100644
index 0000000000..d02c397ee8
--- /dev/null
+++ b/examples/painting/composition/composition.qrc
@@ -0,0 +1,8 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/res/composition">
+ <file>composition.cpp</file>
+ <file>composition.html</file>
+ <file>flower.jpg</file>
+ <file>flower_alpha.jpg</file>
+</qresource>
+</RCC>
diff --git a/examples/painting/composition/flower.jpg b/examples/painting/composition/flower.jpg
new file mode 100644
index 0000000000..f8e022c98c
--- /dev/null
+++ b/examples/painting/composition/flower.jpg
Binary files differ
diff --git a/examples/painting/composition/flower_alpha.jpg b/examples/painting/composition/flower_alpha.jpg
new file mode 100644
index 0000000000..6a3c2a02ef
--- /dev/null
+++ b/examples/painting/composition/flower_alpha.jpg
Binary files differ
diff --git a/examples/painting/composition/main.cpp b/examples/painting/composition/main.cpp
new file mode 100644
index 0000000000..d6bc170a97
--- /dev/null
+++ b/examples/painting/composition/main.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** 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 demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "composition.h"
+
+#include <QApplication>
+#ifdef QT_OPENGL_SUPPORT
+#include <QtOpenGL>
+#endif
+
+int main(int argc, char **argv)
+{
+ // Q_INIT_RESOURCE(deform);
+
+#ifdef QT_OPENGL_SUPPORT
+ QGL::setPreferredPaintEngine(QPaintEngine::OpenGL);
+#endif
+ QApplication app(argc, argv);
+
+ CompositionWidget compWidget(0);
+ QStyle *arthurStyle = new ArthurStyle();
+ compWidget.setStyle(arthurStyle);
+
+ QList<QWidget *> widgets = compWidget.findChildren<QWidget *>();
+ foreach (QWidget *w, widgets)
+ w->setStyle(arthurStyle);
+ compWidget.show();
+
+ return app.exec();
+}
diff --git a/examples/painting/deform/deform.pro b/examples/painting/deform/deform.pro
new file mode 100644
index 0000000000..3393b8e83c
--- /dev/null
+++ b/examples/painting/deform/deform.pro
@@ -0,0 +1,24 @@
+SOURCES += main.cpp pathdeform.cpp
+HEADERS += pathdeform.h
+
+SHARED_FOLDER = ../shared
+
+include($$SHARED_FOLDER/shared.pri)
+
+RESOURCES += deform.qrc
+
+contains(QT_CONFIG, opengl) {
+ DEFINES += QT_OPENGL_SUPPORT
+ QT += opengl
+}
+
+# install
+target.path = $$[QT_INSTALL_DEMOS]/qtbase/deform
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.html
+sources.path = $$[QT_INSTALL_DEMOS]/qtbase/deform
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000A63D
+ CONFIG += qt_demo
+}
diff --git a/examples/painting/deform/deform.qrc b/examples/painting/deform/deform.qrc
new file mode 100644
index 0000000000..2e59ebcfc5
--- /dev/null
+++ b/examples/painting/deform/deform.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/res/deform">
+ <file>pathdeform.cpp</file>
+ <file>pathdeform.html</file>
+</qresource>
+</RCC>
diff --git a/examples/painting/deform/main.cpp b/examples/painting/deform/main.cpp
new file mode 100644
index 0000000000..c49117a2f2
--- /dev/null
+++ b/examples/painting/deform/main.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** 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 demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "pathdeform.h"
+
+#include <QApplication>
+#include <QDebug>
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(deform);
+
+ QApplication app(argc, argv);
+
+ bool smallScreen = QApplication::arguments().contains("-small-screen");
+
+ PathDeformWidget deformWidget(0, smallScreen);
+
+ QStyle *arthurStyle = new ArthurStyle();
+ deformWidget.setStyle(arthurStyle);
+ QList<QWidget *> widgets = deformWidget.findChildren<QWidget *>();
+ foreach (QWidget *w, widgets)
+ w->setStyle(arthurStyle);
+
+ if (smallScreen)
+ deformWidget.showFullScreen();
+ else
+ deformWidget.show();
+
+#ifdef QT_KEYPAD_NAVIGATION
+ QApplication::setNavigationMode(Qt::NavigationModeCursorAuto);
+#endif
+ return app.exec();
+}
diff --git a/examples/painting/deform/pathdeform.cpp b/examples/painting/deform/pathdeform.cpp
new file mode 100644
index 0000000000..f80ef2b8be
--- /dev/null
+++ b/examples/painting/deform/pathdeform.cpp
@@ -0,0 +1,647 @@
+/****************************************************************************
+**
+** 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 demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "pathdeform.h"
+
+#include <QApplication>
+#include <QtDebug>
+#include <QMouseEvent>
+#include <QTimerEvent>
+#include <QLayout>
+#include <QLineEdit>
+#include <QPainter>
+#include <QSlider>
+#include <QLabel>
+#include <QDesktopWidget>
+#include <qmath.h>
+
+PathDeformControls::PathDeformControls(QWidget *parent, PathDeformRenderer* renderer, bool smallScreen)
+ : QWidget(parent)
+{
+ m_renderer = renderer;
+
+ if (smallScreen)
+ layoutForSmallScreen();
+ else
+ layoutForDesktop();
+}
+
+
+void PathDeformControls::layoutForDesktop()
+{
+ QGroupBox* mainGroup = new QGroupBox(this);
+ mainGroup->setTitle(tr("Controls"));
+
+ QGroupBox *radiusGroup = new QGroupBox(mainGroup);
+ radiusGroup->setTitle(tr("Lens Radius"));
+ QSlider *radiusSlider = new QSlider(Qt::Horizontal, radiusGroup);
+ radiusSlider->setRange(15, 150);
+ radiusSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+
+ QGroupBox *deformGroup = new QGroupBox(mainGroup);
+ deformGroup->setTitle(tr("Deformation"));
+ QSlider *deformSlider = new QSlider(Qt::Horizontal, deformGroup);
+ deformSlider->setRange(-100, 100);
+ deformSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+
+ QGroupBox *fontSizeGroup = new QGroupBox(mainGroup);
+ fontSizeGroup->setTitle(tr("Font Size"));
+ QSlider *fontSizeSlider = new QSlider(Qt::Horizontal, fontSizeGroup);
+ fontSizeSlider->setRange(16, 200);
+ fontSizeSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+
+ QGroupBox *textGroup = new QGroupBox(mainGroup);
+ textGroup->setTitle(tr("Text"));
+ QLineEdit *textInput = new QLineEdit(textGroup);
+
+ QPushButton *animateButton = new QPushButton(mainGroup);
+ animateButton->setText(tr("Animated"));
+ animateButton->setCheckable(true);
+
+ QPushButton *showSourceButton = new QPushButton(mainGroup);
+ showSourceButton->setText(tr("Show Source"));
+
+#ifdef QT_OPENGL_SUPPORT
+ QPushButton *enableOpenGLButton = new QPushButton(mainGroup);
+ enableOpenGLButton->setText(tr("Use OpenGL"));
+ enableOpenGLButton->setCheckable(true);
+ enableOpenGLButton->setChecked(m_renderer->usesOpenGL());
+ if (!QGLFormat::hasOpenGL())
+ enableOpenGLButton->hide();
+#endif
+
+ QPushButton *whatsThisButton = new QPushButton(mainGroup);
+ whatsThisButton->setText(tr("What's This?"));
+ whatsThisButton->setCheckable(true);
+
+
+ mainGroup->setFixedWidth(180);
+
+ QVBoxLayout *mainGroupLayout = new QVBoxLayout(mainGroup);
+ mainGroupLayout->addWidget(radiusGroup);
+ mainGroupLayout->addWidget(deformGroup);
+ mainGroupLayout->addWidget(fontSizeGroup);
+ mainGroupLayout->addWidget(textGroup);
+ mainGroupLayout->addWidget(animateButton);
+ mainGroupLayout->addStretch(1);
+#ifdef QT_OPENGL_SUPPORT
+ mainGroupLayout->addWidget(enableOpenGLButton);
+#endif
+ mainGroupLayout->addWidget(showSourceButton);
+ mainGroupLayout->addWidget(whatsThisButton);
+
+ QVBoxLayout *radiusGroupLayout = new QVBoxLayout(radiusGroup);
+ radiusGroupLayout->addWidget(radiusSlider);
+
+ QVBoxLayout *deformGroupLayout = new QVBoxLayout(deformGroup);
+ deformGroupLayout->addWidget(deformSlider);
+
+ QVBoxLayout *fontSizeGroupLayout = new QVBoxLayout(fontSizeGroup);
+ fontSizeGroupLayout->addWidget(fontSizeSlider);
+
+ QVBoxLayout *textGroupLayout = new QVBoxLayout(textGroup);
+ textGroupLayout->addWidget(textInput);
+
+ QVBoxLayout * mainLayout = new QVBoxLayout(this);
+ mainLayout->addWidget(mainGroup);
+ mainLayout->setMargin(0);
+
+ connect(radiusSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setRadius(int)));
+ connect(deformSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setIntensity(int)));
+ connect(fontSizeSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setFontSize(int)));
+ connect(animateButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setAnimated(bool)));
+#ifdef QT_OPENGL_SUPPORT
+ connect(enableOpenGLButton, SIGNAL(clicked(bool)), m_renderer, SLOT(enableOpenGL(bool)));
+#endif
+
+ connect(textInput, SIGNAL(textChanged(QString)), m_renderer, SLOT(setText(QString)));
+ connect(m_renderer, SIGNAL(descriptionEnabledChanged(bool)),
+ whatsThisButton, SLOT(setChecked(bool)));
+ connect(whatsThisButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setDescriptionEnabled(bool)));
+ connect(showSourceButton, SIGNAL(clicked()), m_renderer, SLOT(showSource()));
+
+ animateButton->animateClick();
+ deformSlider->setValue(80);
+ fontSizeSlider->setValue(120);
+ radiusSlider->setValue(100);
+ textInput->setText(tr("Qt"));
+}
+
+void PathDeformControls::layoutForSmallScreen()
+{
+ QGroupBox* mainGroup = new QGroupBox(this);
+ mainGroup->setTitle(tr("Controls"));
+
+ QLabel *radiusLabel = new QLabel(mainGroup);
+ radiusLabel->setText(tr("Lens Radius:"));
+ QSlider *radiusSlider = new QSlider(Qt::Horizontal, mainGroup);
+ radiusSlider->setRange(15, 150);
+ radiusSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+
+ QLabel *deformLabel = new QLabel(mainGroup);
+ deformLabel->setText(tr("Deformation:"));
+ QSlider *deformSlider = new QSlider(Qt::Horizontal, mainGroup);
+ deformSlider->setRange(-100, 100);
+ deformSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+
+ QLabel *fontSizeLabel = new QLabel(mainGroup);
+ fontSizeLabel->setText(tr("Font Size:"));
+ QSlider *fontSizeSlider = new QSlider(Qt::Horizontal, mainGroup);
+ fontSizeSlider->setRange(16, 200);
+ fontSizeSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+
+ QPushButton *animateButton = new QPushButton(tr("Animated"), mainGroup);
+ animateButton->setCheckable(true);
+
+#ifdef QT_OPENGL_SUPPORT
+ QPushButton *enableOpenGLButton = new QPushButton(mainGroup);
+ enableOpenGLButton->setText(tr("Use OpenGL"));
+ enableOpenGLButton->setCheckable(mainGroup);
+ enableOpenGLButton->setChecked(m_renderer->usesOpenGL());
+ if (!QGLFormat::hasOpenGL())
+ enableOpenGLButton->hide();
+#endif
+
+ QPushButton *quitButton = new QPushButton(tr("Quit"), mainGroup);
+ QPushButton *okButton = new QPushButton(tr("OK"), mainGroup);
+
+
+ QGridLayout *mainGroupLayout = new QGridLayout(mainGroup);
+ mainGroupLayout->setMargin(0);
+ mainGroupLayout->addWidget(radiusLabel, 0, 0, Qt::AlignRight);
+ mainGroupLayout->addWidget(radiusSlider, 0, 1);
+ mainGroupLayout->addWidget(deformLabel, 1, 0, Qt::AlignRight);
+ mainGroupLayout->addWidget(deformSlider, 1, 1);
+ mainGroupLayout->addWidget(fontSizeLabel, 2, 0, Qt::AlignRight);
+ mainGroupLayout->addWidget(fontSizeSlider, 2, 1);
+ mainGroupLayout->addWidget(animateButton, 3,0, 1,2);
+#ifdef QT_OPENGL_SUPPORT
+ mainGroupLayout->addWidget(enableOpenGLButton, 4,0, 1,2);
+#endif
+
+ QVBoxLayout *mainLayout = new QVBoxLayout(this);
+ mainLayout->addWidget(mainGroup);
+ mainLayout->addStretch(1);
+ mainLayout->addWidget(okButton);
+ mainLayout->addWidget(quitButton);
+
+ connect(quitButton, SIGNAL(clicked()), this, SLOT(emitQuitSignal()));
+ connect(okButton, SIGNAL(clicked()), this, SLOT(emitOkSignal()));
+ connect(radiusSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setRadius(int)));
+ connect(deformSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setIntensity(int)));
+ connect(fontSizeSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setFontSize(int)));
+ connect(animateButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setAnimated(bool)));
+#ifdef QT_OPENGL_SUPPORT
+ connect(enableOpenGLButton, SIGNAL(clicked(bool)), m_renderer, SLOT(enableOpenGL(bool)));
+#endif
+
+
+ animateButton->animateClick();
+ deformSlider->setValue(80);
+ fontSizeSlider->setValue(120);
+
+ QRect screen_size = QApplication::desktop()->screenGeometry();
+ radiusSlider->setValue(qMin(screen_size.width(), screen_size.height())/5);
+
+ m_renderer->setText(tr("Qt"));
+}
+
+
+void PathDeformControls::emitQuitSignal()
+{ emit quitPressed(); }
+
+void PathDeformControls::emitOkSignal()
+{ emit okPressed(); }
+
+
+PathDeformWidget::PathDeformWidget(QWidget *parent, bool smallScreen)
+ : QWidget(parent)
+{
+ setWindowTitle(tr("Vector Deformation"));
+
+ m_renderer = new PathDeformRenderer(this, smallScreen);
+ m_renderer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+
+ // Layouts
+ QHBoxLayout *mainLayout = new QHBoxLayout(this);
+ mainLayout->addWidget(m_renderer);
+
+ m_controls = new PathDeformControls(0, m_renderer, smallScreen);
+ m_controls->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
+
+ if (!smallScreen)
+ mainLayout->addWidget(m_controls);
+
+ m_renderer->loadSourceFile(":res/deform/pathdeform.cpp");
+ m_renderer->loadDescription(":res/deform/pathdeform.html");
+ m_renderer->setDescriptionEnabled(false);
+
+ connect(m_renderer, SIGNAL(clicked()), this, SLOT(showControls()));
+ connect(m_controls, SIGNAL(okPressed()), this, SLOT(hideControls()));
+ connect(m_controls, SIGNAL(quitPressed()), QApplication::instance(), SLOT(quit()));
+}
+
+
+void PathDeformWidget::showControls()
+{
+ m_controls->showFullScreen();
+}
+
+void PathDeformWidget::hideControls()
+{
+ m_controls->hide();
+}
+
+void PathDeformWidget::setStyle( QStyle * style )
+{
+ QWidget::setStyle(style);
+ if (m_controls != 0)
+ {
+ m_controls->setStyle(style);
+
+ QList<QWidget *> widgets = m_controls->findChildren<QWidget *>();
+ foreach (QWidget *w, widgets)
+ w->setStyle(style);
+ }
+}
+
+static inline QRect circle_bounds(const QPointF &center, qreal radius, qreal compensation)
+{
+ return QRect(qRound(center.x() - radius - compensation),
+ qRound(center.y() - radius - compensation),
+ qRound((radius + compensation) * 2),
+ qRound((radius + compensation) * 2));
+
+}
+
+const int LENS_EXTENT = 10;
+
+PathDeformRenderer::PathDeformRenderer(QWidget *widget, bool smallScreen)
+ : ArthurFrame(widget)
+{
+ m_radius = 100;
+ m_pos = QPointF(m_radius, m_radius);
+ m_direction = QPointF(1, 1);
+ m_fontSize = 24;
+ m_animated = true;
+ m_repaintTimer.start(25, this);
+ m_repaintTracker.start();
+ m_intensity = 100;
+ m_smallScreen = smallScreen;
+
+// m_fpsTimer.start(1000, this);
+// m_fpsCounter = 0;
+
+ generateLensPixmap();
+}
+
+void PathDeformRenderer::setText(const QString &text)
+{
+ m_text = text;
+
+ QFont f("times new roman,utopia");
+ f.setStyleStrategy(QFont::ForceOutline);
+ f.setPointSize(m_fontSize);
+ f.setStyleHint(QFont::Times);
+
+ QFontMetrics fm(f);
+
+ m_paths.clear();
+ m_pathBounds = QRect();
+
+ QPointF advance(0, 0);
+
+ bool do_quick = true;
+ for (int i=0; i<text.size(); ++i) {
+ if (text.at(i).unicode() >= 0x4ff && text.at(i).unicode() <= 0x1e00) {
+ do_quick = false;
+ break;
+ }
+ }
+
+ if (do_quick) {
+ for (int i=0; i<text.size(); ++i) {
+ QPainterPath path;
+ path.addText(advance, f, text.mid(i, 1));
+ m_pathBounds |= path.boundingRect();
+ m_paths << path;
+ advance += QPointF(fm.width(text.mid(i, 1)), 0);
+ }
+ } else {
+ QPainterPath path;
+ path.addText(advance, f, text);
+ m_pathBounds |= path.boundingRect();
+ m_paths << path;
+ }
+
+ for (int i=0; i<m_paths.size(); ++i)
+ m_paths[i] = m_paths[i] * QMatrix(1, 0, 0, 1, -m_pathBounds.x(), -m_pathBounds.y());
+
+ update();
+}
+
+
+void PathDeformRenderer::generateLensPixmap()
+{
+ qreal rad = m_radius + LENS_EXTENT;
+
+ QRect bounds = circle_bounds(QPointF(), rad, 0);
+
+ QPainter painter;
+
+ if (preferImage()) {
+ m_lens_image = QImage(bounds.size(), QImage::Format_ARGB32_Premultiplied);
+ m_lens_image.fill(0);
+ painter.begin(&m_lens_image);
+ } else {
+ m_lens_pixmap = QPixmap(bounds.size());
+ m_lens_pixmap.fill(Qt::transparent);
+ painter.begin(&m_lens_pixmap);
+ }
+
+ QRadialGradient gr(rad, rad, rad, 3 * rad / 5, 3 * rad / 5);
+ gr.setColorAt(0.0, QColor(255, 255, 255, 191));
+ gr.setColorAt(0.2, QColor(255, 255, 127, 191));
+ gr.setColorAt(0.9, QColor(150, 150, 200, 63));
+ gr.setColorAt(0.95, QColor(0, 0, 0, 127));
+ gr.setColorAt(1, QColor(0, 0, 0, 0));
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.setBrush(gr);
+ painter.setPen(Qt::NoPen);
+ painter.drawEllipse(0, 0, bounds.width(), bounds.height());
+}
+
+
+void PathDeformRenderer::setAnimated(bool animated)
+{
+ m_animated = animated;
+
+ if (m_animated) {
+// m_fpsTimer.start(1000, this);
+// m_fpsCounter = 0;
+ m_repaintTimer.start(25, this);
+ m_repaintTracker.start();
+ } else {
+// m_fpsTimer.stop();
+ m_repaintTimer.stop();
+ }
+}
+
+void PathDeformRenderer::timerEvent(QTimerEvent *e)
+{
+
+ if (e->timerId() == m_repaintTimer.timerId()) {
+
+ if (QLineF(QPointF(0,0), m_direction).length() > 1)
+ m_direction *= 0.995;
+ qreal time = m_repaintTracker.restart();
+
+ QRect rectBefore = circle_bounds(m_pos, m_radius, m_fontSize);
+
+ qreal dx = m_direction.x();
+ qreal dy = m_direction.y();
+ if (time > 0) {
+ dx = dx * time * .1;
+ dy = dy * time * .1;
+ }
+
+ m_pos += QPointF(dx, dy);
+
+
+
+ if (m_pos.x() - m_radius < 0) {
+ m_direction.setX(-m_direction.x());
+ m_pos.setX(m_radius);
+ } else if (m_pos.x() + m_radius > width()) {
+ m_direction.setX(-m_direction.x());
+ m_pos.setX(width() - m_radius);
+ }
+
+ if (m_pos.y() - m_radius < 0) {
+ m_direction.setY(-m_direction.y());
+ m_pos.setY(m_radius);
+ } else if (m_pos.y() + m_radius > height()) {
+ m_direction.setY(-m_direction.y());
+ m_pos.setY(height() - m_radius);
+ }
+
+#ifdef QT_OPENGL_SUPPORT
+ if (usesOpenGL()) {
+ update();
+ } else
+#endif
+ {
+ QRect rectAfter = circle_bounds(m_pos, m_radius, m_fontSize);
+ update(rectAfter | rectBefore);
+ QApplication::syncX();
+ }
+ }
+// else if (e->timerId() == m_fpsTimer.timerId()) {
+// printf("fps: %d\n", m_fpsCounter);
+// emit frameRate(m_fpsCounter);
+// m_fpsCounter = 0;
+
+// }
+}
+
+void PathDeformRenderer::mousePressEvent(QMouseEvent *e)
+{
+ setDescriptionEnabled(false);
+
+ m_repaintTimer.stop();
+ m_offset = QPointF();
+ if (QLineF(m_pos, e->pos()).length() <= m_radius)
+ m_offset = m_pos - e->pos();
+
+ m_mousePress = e->pos();
+
+ // If we're not running in small screen mode, always assume we're dragging
+ m_mouseDrag = !m_smallScreen;
+
+ mouseMoveEvent(e);
+}
+
+void PathDeformRenderer::mouseReleaseEvent(QMouseEvent *e)
+{
+ if (e->buttons() == Qt::NoButton && m_animated) {
+ m_repaintTimer.start(10, this);
+ m_repaintTracker.start();
+ }
+
+ if (!m_mouseDrag && m_smallScreen)
+ emit clicked();
+}
+
+void PathDeformRenderer::mouseMoveEvent(QMouseEvent *e)
+{
+ if (!m_mouseDrag && (QLineF(m_mousePress, e->pos()).length() > 25.0) )
+ m_mouseDrag = true;
+
+ if (m_mouseDrag) {
+ QRect rectBefore = circle_bounds(m_pos, m_radius, m_fontSize);
+ if (e->type() == QEvent::MouseMove) {
+ QLineF line(m_pos, e->pos() + m_offset);
+ line.setLength(line.length() * .1);
+ QPointF dir(line.dx(), line.dy());
+ m_direction = (m_direction + dir) / 2;
+ }
+ m_pos = e->pos() + m_offset;
+#ifdef QT_OPENGL_SUPPORT
+ if (usesOpenGL()) {
+ update();
+ } else
+#endif
+ {
+ QRect rectAfter = circle_bounds(m_pos, m_radius, m_fontSize);
+ update(rectBefore | rectAfter);
+ }
+ }
+}
+
+QPainterPath PathDeformRenderer::lensDeform(const QPainterPath &source, const QPointF &offset)
+{
+ QPainterPath path;
+ path.addPath(source);
+
+ qreal flip = m_intensity / qreal(100);
+
+ for (int i=0; i<path.elementCount(); ++i) {
+ const QPainterPath::Element &e = path.elementAt(i);
+
+ qreal x = e.x + offset.x();
+ qreal y = e.y + offset.y();
+
+ qreal dx = x - m_pos.x();
+ qreal dy = y - m_pos.y();
+ qreal len = m_radius - qSqrt(dx * dx + dy * dy);
+
+ if (len > 0) {
+ path.setElementPositionAt(i,
+ x + flip * dx * len / m_radius,
+ y + flip * dy * len / m_radius);
+ } else {
+ path.setElementPositionAt(i, x, y);
+ }
+
+ }
+
+ return path;
+}
+
+
+void PathDeformRenderer::paint(QPainter *painter)
+{
+ int pad_x = 5;
+ int pad_y = 5;
+
+ int skip_x = qRound(m_pathBounds.width() + pad_x + m_fontSize/2);
+ int skip_y = qRound(m_pathBounds.height() + pad_y);
+
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(Qt::black);
+
+ QRectF clip(painter->clipPath().boundingRect());
+
+ int overlap = pad_x / 2;
+
+ for (int start_y=0; start_y < height(); start_y += skip_y) {
+
+ if (start_y > clip.bottom())
+ break;
+
+ int start_x = -overlap;
+ for (; start_x < width(); start_x += skip_x) {
+
+ if (start_y + skip_y >= clip.top() &&
+ start_x + skip_x >= clip.left() &&
+ start_x <= clip.right()) {
+ for (int i=0; i<m_paths.size(); ++i) {
+ QPainterPath path = lensDeform(m_paths[i], QPointF(start_x, start_y));
+ painter->drawPath(path);
+ }
+ }
+ }
+ overlap = skip_x - (start_x - width());
+
+ }
+
+ if (preferImage()) {
+ painter->drawImage(m_pos - QPointF(m_radius + LENS_EXTENT, m_radius + LENS_EXTENT),
+ m_lens_image);
+ } else {
+ painter->drawPixmap(m_pos - QPointF(m_radius + LENS_EXTENT, m_radius + LENS_EXTENT),
+ m_lens_pixmap);
+ }
+}
+
+
+
+void PathDeformRenderer::setRadius(int radius)
+{
+ qreal max = qMax(m_radius, (qreal)radius);
+ m_radius = radius;
+ generateLensPixmap();
+ if (!m_animated || m_radius < max) {
+#ifdef QT_OPENGL_SUPPORT
+ if (usesOpenGL()) {
+ update();
+ } else
+#endif
+ {
+ update(circle_bounds(m_pos, max, m_fontSize));
+ }
+ }
+}
+
+void PathDeformRenderer::setIntensity(int intensity)
+{
+ m_intensity = intensity;
+ if (!m_animated) {
+#ifdef QT_OPENGL_SUPPORT
+ if (usesOpenGL()) {
+ update();
+ } else
+#endif
+ {
+ update(circle_bounds(m_pos, m_radius, m_fontSize));
+ }
+ }
+}
diff --git a/examples/painting/deform/pathdeform.h b/examples/painting/deform/pathdeform.h
new file mode 100644
index 0000000000..73a1955082
--- /dev/null
+++ b/examples/painting/deform/pathdeform.h
@@ -0,0 +1,153 @@
+/****************************************************************************
+**
+** 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 demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PATHDEFORM_H
+#define PATHDEFORM_H
+
+#include "arthurwidgets.h"
+
+#include <QPainterPath>
+#include <QBasicTimer>
+#include <QDateTime>
+
+class PathDeformRenderer : public ArthurFrame
+{
+ Q_OBJECT
+ Q_PROPERTY(bool animated READ animated WRITE setAnimated)
+ Q_PROPERTY(int radius READ radius WRITE setRadius)
+ Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize)
+ Q_PROPERTY(int intensity READ intensity WRITE setIntensity)
+ Q_PROPERTY(QString text READ text WRITE setText)
+
+public:
+ PathDeformRenderer(QWidget *widget, bool smallScreen = false);
+
+ void paint(QPainter *painter);
+
+ void mousePressEvent(QMouseEvent *e);
+ void mouseReleaseEvent(QMouseEvent *e);
+ void mouseMoveEvent(QMouseEvent *e);
+ void timerEvent(QTimerEvent *e);
+
+ QSize sizeHint() const { return QSize(600, 500); }
+
+ bool animated() const { return m_animated; }
+ int radius() const { return int(m_radius); }
+ int fontSize() const { return m_fontSize; }
+ int intensity() const { return int(m_intensity); }
+ QString text() const { return m_text; }
+
+public slots:
+ void setRadius(int radius);
+ void setFontSize(int fontSize) { m_fontSize = fontSize; setText(m_text); }
+ void setText(const QString &text);
+ void setIntensity(int intensity);
+
+ void setAnimated(bool animated);
+
+signals:
+ void clicked();
+// void frameRate(double fps);
+
+private:
+ void generateLensPixmap();
+ QPainterPath lensDeform(const QPainterPath &source, const QPointF &offset);
+
+ QBasicTimer m_repaintTimer;
+// QBasicTimer m_fpsTimer;
+// int m_fpsCounter;
+ QTime m_repaintTracker;
+
+ QVector<QPainterPath> m_paths;
+ QVector<QPointF> m_advances;
+ QRectF m_pathBounds;
+ QString m_text;
+
+ QPixmap m_lens_pixmap;
+ QImage m_lens_image;
+
+ int m_fontSize;
+ bool m_animated;
+
+ qreal m_intensity;
+ qreal m_radius;
+ QPointF m_pos;
+ QPointF m_offset;
+ QPointF m_direction;
+ QPointF m_mousePress;
+ bool m_mouseDrag;
+ bool m_smallScreen;
+};
+
+class PathDeformControls : public QWidget
+{
+ Q_OBJECT
+public:
+ PathDeformControls(QWidget *parent, PathDeformRenderer* renderer, bool smallScreen);
+signals:
+ void okPressed();
+ void quitPressed();
+private:
+ PathDeformRenderer* m_renderer;
+ void layoutForDesktop();
+ void layoutForSmallScreen();
+private slots:
+ void emitQuitSignal();
+ void emitOkSignal();
+};
+
+class PathDeformWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ PathDeformWidget(QWidget *parent, bool smallScreen);
+ void setStyle ( QStyle * style );
+
+private:
+ PathDeformRenderer *m_renderer;
+ PathDeformControls *m_controls;
+
+private slots:
+ void showControls();
+ void hideControls();
+};
+
+#endif // PATHDEFORM_H
diff --git a/examples/painting/deform/pathdeform.html b/examples/painting/deform/pathdeform.html
new file mode 100644
index 0000000000..b3f63a8e0a
--- /dev/null
+++ b/examples/painting/deform/pathdeform.html
@@ -0,0 +1,24 @@
+<html>
+<center>
+<h2>Vector deformation</h2>
+</center>
+
+<p>This demo shows how to use advanced vector techniques to draw text
+using a <code>QPainterPath</code>.</p>
+
+<p>We define a vector deformation field in the shape of a lens and apply
+this to all points in a path. This means that what is rendered on
+screen is not pixel manipulation, but modified vector representations of
+the glyphs themselves. This is visible from the high quality of the
+antialiased edges for the deformed glyphs.</p>
+
+<p>To get a fairly complex path we allow the user to type in text and
+convert the text to paths. This is done using the
+<code>QPainterPath::addText()</code> function.</p>
+
+<p>The lens is drawn using a single call to <code>drawEllipse()</code>, using
+a <code>QRadialGradient</code> to fill it with a specialized color table,
+giving the effect of the Sun's reflection and a drop shadow. The lens
+is cached as a pixmap for better performance.</p>
+
+</html>
diff --git a/examples/painting/gradients/gradients.cpp b/examples/painting/gradients/gradients.cpp
new file mode 100644
index 0000000000..d8b739b3b0
--- /dev/null
+++ b/examples/painting/gradients/gradients.cpp
@@ -0,0 +1,516 @@
+/****************************************************************************
+**
+** 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 demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "gradients.h"
+#include "hoverpoints.h"
+
+ShadeWidget::ShadeWidget(ShadeType type, QWidget *parent)
+ : QWidget(parent), m_shade_type(type), m_alpha_gradient(QLinearGradient(0, 0, 0, 0))
+{
+
+ // Checkers background
+ if (m_shade_type == ARGBShade) {
+ QPixmap pm(20, 20);
+ QPainter pmp(&pm);
+ pmp.fillRect(0, 0, 10, 10, Qt::lightGray);
+ pmp.fillRect(10, 10, 10, 10, Qt::lightGray);
+ pmp.fillRect(0, 10, 10, 10, Qt::darkGray);
+ pmp.fillRect(10, 0, 10, 10, Qt::darkGray);
+ pmp.end();
+ QPalette pal = palette();
+ pal.setBrush(backgroundRole(), QBrush(pm));
+ setAutoFillBackground(true);
+ setPalette(pal);
+
+ } else {
+ setAttribute(Qt::WA_NoBackground);
+
+ }
+
+ QPolygonF points;
+ points << QPointF(0, sizeHint().height())
+ << QPointF(sizeHint().width(), 0);
+
+ m_hoverPoints = new HoverPoints(this, HoverPoints::CircleShape);
+// m_hoverPoints->setConnectionType(HoverPoints::LineConnection);
+ m_hoverPoints->setPoints(points);
+ m_hoverPoints->setPointLock(0, HoverPoints::LockToLeft);
+ m_hoverPoints->setPointLock(1, HoverPoints::LockToRight);
+ m_hoverPoints->setSortType(HoverPoints::XSort);
+
+ setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+
+ connect(m_hoverPoints, SIGNAL(pointsChanged(QPolygonF)), this, SIGNAL(colorsChanged()));
+}
+
+
+QPolygonF ShadeWidget::points() const
+{
+ return m_hoverPoints->points();
+}
+
+
+uint ShadeWidget::colorAt(int x)
+{
+ generateShade();
+
+ QPolygonF pts = m_hoverPoints->points();
+ for (int i=1; i < pts.size(); ++i) {
+ if (pts.at(i-1).x() <= x && pts.at(i).x() >= x) {
+ QLineF l(pts.at(i-1), pts.at(i));
+ l.setLength(l.length() * ((x - l.x1()) / l.dx()));
+ return m_shade.pixel(qRound(qMin(l.x2(), (qreal(m_shade.width() - 1)))),
+ qRound(qMin(l.y2(), qreal(m_shade.height() - 1))));
+ }
+ }
+ return 0;
+}
+
+
+void ShadeWidget::setGradientStops(const QGradientStops &stops)
+{
+ if (m_shade_type == ARGBShade) {
+ m_alpha_gradient = QLinearGradient(0, 0, width(), 0);
+
+ for (int i=0; i<stops.size(); ++i) {
+ QColor c = stops.at(i).second;
+ m_alpha_gradient.setColorAt(stops.at(i).first, QColor(c.red(), c.green(), c.blue()));
+ }
+
+ m_shade = QImage();
+ generateShade();
+ update();
+ }
+}
+
+
+void ShadeWidget::paintEvent(QPaintEvent *)
+{
+ generateShade();
+
+ QPainter p(this);
+ p.drawImage(0, 0, m_shade);
+
+ p.setPen(QColor(146, 146, 146));
+ p.drawRect(0, 0, width() - 1, height() - 1);
+}
+
+
+void ShadeWidget::generateShade()
+{
+ if (m_shade.isNull() || m_shade.size() != size()) {
+
+ if (m_shade_type == ARGBShade) {
+ m_shade = QImage(size(), QImage::Format_ARGB32_Premultiplied);
+ m_shade.fill(0);
+
+ QPainter p(&m_shade);
+ p.fillRect(rect(), m_alpha_gradient);
+
+ p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
+ QLinearGradient fade(0, 0, 0, height());
+ fade.setColorAt(0, QColor(0, 0, 0, 255));
+ fade.setColorAt(1, QColor(0, 0, 0, 0));
+ p.fillRect(rect(), fade);
+
+ } else {
+ m_shade = QImage(size(), QImage::Format_RGB32);
+ QLinearGradient shade(0, 0, 0, height());
+ shade.setColorAt(1, Qt::black);
+
+ if (m_shade_type == RedShade)
+ shade.setColorAt(0, Qt::red);
+ else if (m_shade_type == GreenShade)
+ shade.setColorAt(0, Qt::green);
+ else
+ shade.setColorAt(0, Qt::blue);
+
+ QPainter p(&m_shade);
+ p.fillRect(rect(), shade);
+ }
+ }
+
+
+}
+
+
+GradientEditor::GradientEditor(QWidget *parent)
+ : QWidget(parent)
+{
+ QVBoxLayout *vbox = new QVBoxLayout(this);
+ vbox->setSpacing(1);
+ vbox->setMargin(1);
+
+ m_red_shade = new ShadeWidget(ShadeWidget::RedShade, this);
+ m_green_shade = new ShadeWidget(ShadeWidget::GreenShade, this);
+ m_blue_shade = new ShadeWidget(ShadeWidget::BlueShade, this);
+ m_alpha_shade = new ShadeWidget(ShadeWidget::ARGBShade, this);
+
+ vbox->addWidget(m_red_shade);
+ vbox->addWidget(m_green_shade);
+ vbox->addWidget(m_blue_shade);
+ vbox->addWidget(m_alpha_shade);
+
+ connect(m_red_shade, SIGNAL(colorsChanged()), this, SLOT(pointsUpdated()));
+ connect(m_green_shade, SIGNAL(colorsChanged()), this, SLOT(pointsUpdated()));
+ connect(m_blue_shade, SIGNAL(colorsChanged()), this, SLOT(pointsUpdated()));
+ connect(m_alpha_shade, SIGNAL(colorsChanged()), this, SLOT(pointsUpdated()));
+}
+
+
+inline static bool x_less_than(const QPointF &p1, const QPointF &p2)
+{
+ return p1.x() < p2.x();
+}
+
+
+void GradientEditor::pointsUpdated()
+{
+ qreal w = m_alpha_shade->width();
+
+ QGradientStops stops;
+
+ QPolygonF points;
+
+ points += m_red_shade->points();
+ points += m_green_shade->points();
+ points += m_blue_shade->points();
+ points += m_alpha_shade->points();
+
+ qSort(points.begin(), points.end(), x_less_than);
+
+ for (int i=0; i<points.size(); ++i) {
+ qreal x = int(points.at(i).x());
+ if (i < points.size() - 1 && x == points.at(i+1).x())
+ continue;
+ QColor color((0x00ff0000 & m_red_shade->colorAt(int(x))) >> 16,
+ (0x0000ff00 & m_green_shade->colorAt(int(x))) >> 8,
+ (0x000000ff & m_blue_shade->colorAt(int(x))),
+ (0xff000000 & m_alpha_shade->colorAt(int(x))) >> 24);
+
+ if (x / w > 1)
+ return;
+
+ stops << QGradientStop(x / w, color);
+ }
+
+ m_alpha_shade->setGradientStops(stops);
+
+ emit gradientStopsChanged(stops);
+}
+
+
+static void set_shade_points(const QPolygonF &points, ShadeWidget *shade)
+{
+ shade->hoverPoints()->setPoints(points);
+ shade->hoverPoints()->setPointLock(0, HoverPoints::LockToLeft);
+ shade->hoverPoints()->setPointLock(points.size() - 1, HoverPoints::LockToRight);
+ shade->update();
+}
+
+void GradientEditor::setGradientStops(const QGradientStops &stops)
+{
+ QPolygonF pts_red, pts_green, pts_blue, pts_alpha;
+
+ qreal h_red = m_red_shade->height();
+ qreal h_green = m_green_shade->height();
+ qreal h_blue = m_blue_shade->height();
+ qreal h_alpha = m_alpha_shade->height();
+
+ for (int i=0; i<stops.size(); ++i) {
+ qreal pos = stops.at(i).first;
+ QRgb color = stops.at(i).second.rgba();
+ pts_red << QPointF(pos * m_red_shade->width(), h_red - qRed(color) * h_red / 255);
+ pts_green << QPointF(pos * m_green_shade->width(), h_green - qGreen(color) * h_green / 255);
+ pts_blue << QPointF(pos * m_blue_shade->width(), h_blue - qBlue(color) * h_blue / 255);
+ pts_alpha << QPointF(pos * m_alpha_shade->width(), h_alpha - qAlpha(color) * h_alpha / 255);
+ }
+
+ set_shade_points(pts_red, m_red_shade);
+ set_shade_points(pts_green, m_green_shade);
+ set_shade_points(pts_blue, m_blue_shade);
+ set_shade_points(pts_alpha, m_alpha_shade);
+
+}
+
+GradientWidget::GradientWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ setWindowTitle(tr("Gradients"));
+
+ m_renderer = new GradientRenderer(this);
+
+ QGroupBox *mainGroup = new QGroupBox(this);
+ mainGroup->setTitle(tr("Gradients"));
+
+ QGroupBox *editorGroup = new QGroupBox(mainGroup);
+ editorGroup->setTitle(tr("Color Editor"));
+ m_editor = new GradientEditor(editorGroup);
+
+ QGroupBox *typeGroup = new QGroupBox(mainGroup);
+ typeGroup->setTitle(tr("Gradient Type"));
+ m_linearButton = new QRadioButton(tr("Linear Gradient"), typeGroup);
+ m_radialButton = new QRadioButton(tr("Radial Gradient"), typeGroup);
+ m_conicalButton = new QRadioButton(tr("Conical Gradient"), typeGroup);
+
+ QGroupBox *spreadGroup = new QGroupBox(mainGroup);
+ spreadGroup->setTitle(tr("Spread Method"));
+ m_padSpreadButton = new QRadioButton(tr("Pad Spread"), spreadGroup);
+ m_reflectSpreadButton = new QRadioButton(tr("Reflect Spread"), spreadGroup);
+ m_repeatSpreadButton = new QRadioButton(tr("Repeat Spread"), spreadGroup);
+
+ QGroupBox *defaultsGroup = new QGroupBox(mainGroup);
+ defaultsGroup->setTitle(tr("Defaults"));
+ QPushButton *default1Button = new QPushButton(tr("1"), defaultsGroup);
+ QPushButton *default2Button = new QPushButton(tr("2"), defaultsGroup);
+ QPushButton *default3Button = new QPushButton(tr("3"), defaultsGroup);
+ QPushButton *default4Button = new QPushButton(tr("Reset"), editorGroup);
+
+ QPushButton *showSourceButton = new QPushButton(mainGroup);
+ showSourceButton->setText(tr("Show Source"));
+#ifdef QT_OPENGL_SUPPORT
+ QPushButton *enableOpenGLButton = new QPushButton(mainGroup);
+ enableOpenGLButton->setText(tr("Use OpenGL"));
+ enableOpenGLButton->setCheckable(true);
+ enableOpenGLButton->setChecked(m_renderer->usesOpenGL());
+ if (!QGLFormat::hasOpenGL())
+ enableOpenGLButton->hide();
+#endif
+ QPushButton *whatsThisButton = new QPushButton(mainGroup);
+ whatsThisButton->setText(tr("What's This?"));
+ whatsThisButton->setCheckable(true);
+
+ // Layouts
+ QHBoxLayout *mainLayout = new QHBoxLayout(this);
+ mainLayout->addWidget(m_renderer);
+ mainLayout->addWidget(mainGroup);
+
+ mainGroup->setFixedWidth(180);
+ QVBoxLayout *mainGroupLayout = new QVBoxLayout(mainGroup);
+ mainGroupLayout->addWidget(editorGroup);
+ mainGroupLayout->addWidget(typeGroup);
+ mainGroupLayout->addWidget(spreadGroup);
+ mainGroupLayout->addWidget(defaultsGroup);
+ mainGroupLayout->addStretch(1);
+ mainGroupLayout->addWidget(showSourceButton);
+#ifdef QT_OPENGL_SUPPORT
+ mainGroupLayout->addWidget(enableOpenGLButton);
+#endif
+ mainGroupLayout->addWidget(whatsThisButton);
+
+ QVBoxLayout *editorGroupLayout = new QVBoxLayout(editorGroup);
+ editorGroupLayout->addWidget(m_editor);
+
+ QVBoxLayout *typeGroupLayout = new QVBoxLayout(typeGroup);
+ typeGroupLayout->addWidget(m_linearButton);
+ typeGroupLayout->addWidget(m_radialButton);
+ typeGroupLayout->addWidget(m_conicalButton);
+
+ QVBoxLayout *spreadGroupLayout = new QVBoxLayout(spreadGroup);
+ spreadGroupLayout->addWidget(m_padSpreadButton);
+ spreadGroupLayout->addWidget(m_repeatSpreadButton);
+ spreadGroupLayout->addWidget(m_reflectSpreadButton);
+
+ QHBoxLayout *defaultsGroupLayout = new QHBoxLayout(defaultsGroup);
+ defaultsGroupLayout->addWidget(default1Button);
+ defaultsGroupLayout->addWidget(default2Button);
+ defaultsGroupLayout->addWidget(default3Button);
+ editorGroupLayout->addWidget(default4Button);
+
+ connect(m_editor, SIGNAL(gradientStopsChanged(QGradientStops)),
+ m_renderer, SLOT(setGradientStops(QGradientStops)));
+
+ connect(m_linearButton, SIGNAL(clicked()), m_renderer, SLOT(setLinearGradient()));
+ connect(m_radialButton, SIGNAL(clicked()), m_renderer, SLOT(setRadialGradient()));
+ connect(m_conicalButton, SIGNAL(clicked()), m_renderer, SLOT(setConicalGradient()));
+
+ connect(m_padSpreadButton, SIGNAL(clicked()), m_renderer, SLOT(setPadSpread()));
+ connect(m_reflectSpreadButton, SIGNAL(clicked()), m_renderer, SLOT(setReflectSpread()));
+ connect(m_repeatSpreadButton, SIGNAL(clicked()), m_renderer, SLOT(setRepeatSpread()));
+
+ connect(default1Button, SIGNAL(clicked()), this, SLOT(setDefault1()));
+ connect(default2Button, SIGNAL(clicked()), this, SLOT(setDefault2()));
+ connect(default3Button, SIGNAL(clicked()), this, SLOT(setDefault3()));
+ connect(default4Button, SIGNAL(clicked()), this, SLOT(setDefault4()));
+
+ connect(showSourceButton, SIGNAL(clicked()), m_renderer, SLOT(showSource()));
+#ifdef QT_OPENGL_SUPPORT
+ connect(enableOpenGLButton, SIGNAL(clicked(bool)), m_renderer, SLOT(enableOpenGL(bool)));
+#endif
+ connect(whatsThisButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setDescriptionEnabled(bool)));
+ connect(whatsThisButton, SIGNAL(clicked(bool)),
+ m_renderer->hoverPoints(), SLOT(setDisabled(bool)));
+ connect(m_renderer, SIGNAL(descriptionEnabledChanged(bool)),
+ whatsThisButton, SLOT(setChecked(bool)));
+ connect(m_renderer, SIGNAL(descriptionEnabledChanged(bool)),
+ m_renderer->hoverPoints(), SLOT(setDisabled(bool)));
+
+ m_renderer->loadSourceFile(":res/gradients/gradients.cpp");
+ m_renderer->loadDescription(":res/gradients/gradients.html");
+
+ QTimer::singleShot(50, this, SLOT(setDefault1()));
+}
+
+void GradientWidget::setDefault(int config)
+{
+ QGradientStops stops;
+ QPolygonF points;
+ switch (config) {
+ case 1:
+ stops << QGradientStop(0.00, QColor::fromRgba(0));
+ stops << QGradientStop(0.04, QColor::fromRgba(0xff131360));
+ stops << QGradientStop(0.08, QColor::fromRgba(0xff202ccc));
+ stops << QGradientStop(0.42, QColor::fromRgba(0xff93d3f9));
+ stops << QGradientStop(0.51, QColor::fromRgba(0xffb3e6ff));
+ stops << QGradientStop(0.73, QColor::fromRgba(0xffffffec));
+ stops << QGradientStop(0.92, QColor::fromRgba(0xff5353d9));
+ stops << QGradientStop(0.96, QColor::fromRgba(0xff262666));
+ stops << QGradientStop(1.00, QColor::fromRgba(0));
+ m_linearButton->animateClick();
+ m_repeatSpreadButton->animateClick();
+ break;
+
+ case 2:
+ stops << QGradientStop(0.00, QColor::fromRgba(0xffffffff));
+ stops << QGradientStop(0.11, QColor::fromRgba(0xfff9ffa0));
+ stops << QGradientStop(0.13, QColor::fromRgba(0xfff9ff99));
+ stops << QGradientStop(0.14, QColor::fromRgba(0xfff3ff86));
+ stops << QGradientStop(0.49, QColor::fromRgba(0xff93b353));
+ stops << QGradientStop(0.87, QColor::fromRgba(0xff264619));
+ stops << QGradientStop(0.96, QColor::fromRgba(0xff0c1306));
+ stops << QGradientStop(1.00, QColor::fromRgba(0));
+ m_radialButton->animateClick();
+ m_padSpreadButton->animateClick();
+ break;
+
+ case 3:
+ stops << QGradientStop(0.00, QColor::fromRgba(0));
+ stops << QGradientStop(0.10, QColor::fromRgba(0xffe0cc73));
+ stops << QGradientStop(0.17, QColor::fromRgba(0xffc6a006));
+ stops << QGradientStop(0.46, QColor::fromRgba(0xff600659));
+ stops << QGradientStop(0.72, QColor::fromRgba(0xff0680ac));
+ stops << QGradientStop(0.92, QColor::fromRgba(0xffb9d9e6));
+ stops << QGradientStop(1.00, QColor::fromRgba(0));
+ m_conicalButton->animateClick();
+ m_padSpreadButton->animateClick();
+ break;
+
+ case 4:
+ stops << QGradientStop(0.00, QColor::fromRgba(0xff000000));
+ stops << QGradientStop(1.00, QColor::fromRgba(0xffffffff));
+ break;
+
+ default:
+ qWarning("bad default: %d\n", config);
+ break;
+ }
+
+ QPolygonF pts;
+ int h_off = m_renderer->width() / 10;
+ int v_off = m_renderer->height() / 8;
+ pts << QPointF(m_renderer->width() / 2, m_renderer->height() / 2)
+ << QPointF(m_renderer->width() / 2 - h_off, m_renderer->height() / 2 - v_off);
+
+ m_editor->setGradientStops(stops);
+ m_renderer->hoverPoints()->setPoints(pts);
+ m_renderer->setGradientStops(stops);
+}
+
+
+GradientRenderer::GradientRenderer(QWidget *parent)
+ : ArthurFrame(parent)
+{
+ m_hoverPoints = new HoverPoints(this, HoverPoints::CircleShape);
+ m_hoverPoints->setPointSize(QSize(20, 20));
+ m_hoverPoints->setConnectionType(HoverPoints::NoConnection);
+ m_hoverPoints->setEditable(false);
+
+ QVector<QPointF> points;
+ points << QPointF(100, 100) << QPointF(200, 200);
+ m_hoverPoints->setPoints(points);
+
+ m_spread = QGradient::PadSpread;
+ m_gradientType = Qt::LinearGradientPattern;
+}
+
+void GradientRenderer::setGradientStops(const QGradientStops &stops)
+{
+ m_stops = stops;
+ update();
+}
+
+
+void GradientRenderer::mousePressEvent(QMouseEvent *)
+{
+ setDescriptionEnabled(false);
+}
+
+void GradientRenderer::paint(QPainter *p)
+{
+ QPolygonF pts = m_hoverPoints->points();
+
+ QGradient g;
+
+ if (m_gradientType == Qt::LinearGradientPattern) {
+ g = QLinearGradient(pts.at(0), pts.at(1));
+
+ } else if (m_gradientType == Qt::RadialGradientPattern) {
+ g = QRadialGradient(pts.at(0), qMin(width(), height()) / 3.0, pts.at(1));
+
+ } else {
+ QLineF l(pts.at(0), pts.at(1));
+ qreal angle = l.angle(QLineF(0, 0, 1, 0));
+ if (l.dy() > 0)
+ angle = 360 - angle;
+ g = QConicalGradient(pts.at(0), angle);
+ }
+
+ for (int i=0; i<m_stops.size(); ++i)
+ g.setColorAt(m_stops.at(i).first, m_stops.at(i).second);
+
+ g.setSpread(m_spread);
+
+ p->setBrush(g);
+ p->setPen(Qt::NoPen);
+
+ p->drawRect(rect());
+
+}
diff --git a/examples/painting/gradients/gradients.h b/examples/painting/gradients/gradients.h
new file mode 100644
index 0000000000..e1a2bcb41e
--- /dev/null
+++ b/examples/painting/gradients/gradients.h
@@ -0,0 +1,170 @@
+/****************************************************************************
+**
+** 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 demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GRADIENTS_H
+#define GRADIENTS_H
+
+#include "arthurwidgets.h"
+
+#include <QtGui>
+
+class HoverPoints;
+
+
+class ShadeWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ enum ShadeType {
+ RedShade,
+ GreenShade,
+ BlueShade,
+ ARGBShade
+ };
+
+ ShadeWidget(ShadeType type, QWidget *parent);
+
+ void setGradientStops(const QGradientStops &stops);
+
+ void paintEvent(QPaintEvent *e);
+
+ QSize sizeHint() const { return QSize(150, 40); }
+ QPolygonF points() const;
+
+ HoverPoints *hoverPoints() const { return m_hoverPoints; }
+
+ uint colorAt(int x);
+
+signals:
+ void colorsChanged();
+
+private:
+ void generateShade();
+
+ ShadeType m_shade_type;
+ QImage m_shade;
+ HoverPoints *m_hoverPoints;
+ QLinearGradient m_alpha_gradient;
+};
+
+class GradientEditor : public QWidget
+{
+ Q_OBJECT
+public:
+ GradientEditor(QWidget *parent);
+
+ void setGradientStops(const QGradientStops &stops);
+
+public slots:
+ void pointsUpdated();
+
+signals:
+ void gradientStopsChanged(const QGradientStops &stops);
+
+private:
+ ShadeWidget *m_red_shade;
+ ShadeWidget *m_green_shade;
+ ShadeWidget *m_blue_shade;
+ ShadeWidget *m_alpha_shade;
+};
+
+
+class GradientRenderer : public ArthurFrame
+{
+ Q_OBJECT
+public:
+ GradientRenderer(QWidget *parent);
+ void paint(QPainter *p);
+
+ QSize sizeHint() const { return QSize(400, 400); }
+
+ HoverPoints *hoverPoints() const { return m_hoverPoints; }
+ void mousePressEvent(QMouseEvent *e);
+
+public slots:
+ void setGradientStops(const QGradientStops &stops);
+
+ void setPadSpread() { m_spread = QGradient::PadSpread; update(); }
+ void setRepeatSpread() { m_spread = QGradient::RepeatSpread; update(); }
+ void setReflectSpread() { m_spread = QGradient::ReflectSpread; update(); }
+
+ void setLinearGradient() { m_gradientType = Qt::LinearGradientPattern; update(); }
+ void setRadialGradient() { m_gradientType = Qt::RadialGradientPattern; update(); }
+ void setConicalGradient() { m_gradientType = Qt::ConicalGradientPattern; update(); }
+
+
+private:
+ QGradientStops m_stops;
+ HoverPoints *m_hoverPoints;
+
+ QGradient::Spread m_spread;
+ Qt::BrushStyle m_gradientType;
+};
+
+
+class GradientWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ GradientWidget(QWidget *parent);
+
+public slots:
+ void setDefault1() { setDefault(1); }
+ void setDefault2() { setDefault(2); }
+ void setDefault3() { setDefault(3); }
+ void setDefault4() { setDefault(4); }
+
+private:
+ void setDefault(int i);
+
+ GradientRenderer *m_renderer;
+ GradientEditor *m_editor;
+
+ QRadioButton *m_linearButton;
+ QRadioButton *m_radialButton;
+ QRadioButton *m_conicalButton;
+ QRadioButton *m_padSpreadButton;
+ QRadioButton *m_reflectSpreadButton;
+ QRadioButton *m_repeatSpreadButton;
+
+};
+
+#endif // GRADIENTS_H
diff --git a/examples/painting/gradients/gradients.html b/examples/painting/gradients/gradients.html
new file mode 100644
index 0000000000..1ea2c0ed6c
--- /dev/null
+++ b/examples/painting/gradients/gradients.html
@@ -0,0 +1,31 @@
+<html>
+<center>
+<h2>Gradients</h2>
+</center>
+
+<p>In this demo we show the various types of gradients that can
+be used in Qt.</p>
+
+<p>There are three types of gradients:
+
+<ul>
+ <li><b>Linear</b> gradients interpolate colors between start and end
+ points.</li>
+ <li><b>Radial</b> gradients interpolate colors between a focal point and the
+ points on a circle surrounding it.</li>
+ <li><b>Conical</b> gradients interpolate colors around a center point.</li>
+</ul>
+
+</p>
+
+<p>The panel on the right contains a color table editor that defines
+the colors in the gradient. The three topmost controls determine the red,
+green and blue components while the last defines the alpha of the
+gradient. You can move points, and add new ones, by clicking with the left
+mouse button, and remove points by clicking with the right button.</p>
+
+<p>There are three default configurations available at the bottom of
+the page that are provided as suggestions on how a color table could be
+configured.</p>
+
+</html>
diff --git a/examples/painting/gradients/gradients.pro b/examples/painting/gradients/gradients.pro
new file mode 100644
index 0000000000..ed4120e01c
--- /dev/null
+++ b/examples/painting/gradients/gradients.pro
@@ -0,0 +1,20 @@
+SOURCES += main.cpp gradients.cpp
+HEADERS += gradients.h
+
+SHARED_FOLDER = ../shared
+
+include($$SHARED_FOLDER/shared.pri)
+
+RESOURCES += gradients.qrc
+contains(QT_CONFIG, opengl) {
+ DEFINES += QT_OPENGL_SUPPORT
+ QT += opengl
+}
+
+# install
+target.path = $$[QT_INSTALL_DEMOS]/qtbase/gradients
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.html
+sources.path = $$[QT_INSTALL_DEMOS]/qtbase/gradients
+INSTALLS += target sources
+
+symbian: CONFIG += qt_demo
diff --git a/examples/painting/gradients/gradients.qrc b/examples/painting/gradients/gradients.qrc
new file mode 100644
index 0000000000..fb971eb17b
--- /dev/null
+++ b/examples/painting/gradients/gradients.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/res/gradients">
+ <file>gradients.cpp</file>
+ <file>gradients.html</file>
+</qresource>
+</RCC>
diff --git a/examples/painting/gradients/main.cpp b/examples/painting/gradients/main.cpp
new file mode 100644
index 0000000000..1d2f0d5775
--- /dev/null
+++ b/examples/painting/gradients/main.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** 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 demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "gradients.h"
+
+#include <QApplication>
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(gradients);
+
+ QApplication app(argc, argv);
+
+ GradientWidget gradientWidget(0);
+ QStyle *arthurStyle = new ArthurStyle();
+ gradientWidget.setStyle(arthurStyle);
+ QList<QWidget *> widgets = gradientWidget.findChildren<QWidget *>();
+ foreach (QWidget *w, widgets) {
+ w->setStyle(arthurStyle);
+ w->setAttribute(Qt::WA_AcceptTouchEvents);
+ }
+ gradientWidget.show();
+
+ return app.exec();
+}
diff --git a/examples/painting/pathstroke/main.cpp b/examples/painting/pathstroke/main.cpp
new file mode 100644
index 0000000000..b357f99336
--- /dev/null
+++ b/examples/painting/pathstroke/main.cpp
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** 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 demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "pathstroke.h"
+#include <QApplication>
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(pathstroke);
+
+ QApplication app(argc, argv);
+
+ bool smallScreen = QApplication::arguments().contains("-small-screen");
+
+ PathStrokeWidget pathStrokeWidget(smallScreen);
+ QStyle *arthurStyle = new ArthurStyle();
+ pathStrokeWidget.setStyle(arthurStyle);
+ QList<QWidget *> widgets = pathStrokeWidget.findChildren<QWidget *>();
+ foreach (QWidget *w, widgets) {
+ w->setStyle(arthurStyle);
+ w->setAttribute(Qt::WA_AcceptTouchEvents);
+ }
+
+ if (smallScreen)
+ pathStrokeWidget.showFullScreen();
+ else
+ pathStrokeWidget.show();
+
+#ifdef QT_KEYPAD_NAVIGATION
+ QApplication::setNavigationMode(Qt::NavigationModeCursorAuto);
+#endif
+ return app.exec();
+}
diff --git a/examples/painting/pathstroke/pathstroke.cpp b/examples/painting/pathstroke/pathstroke.cpp
new file mode 100644
index 0000000000..02c35f7721
--- /dev/null
+++ b/examples/painting/pathstroke/pathstroke.cpp
@@ -0,0 +1,686 @@
+/****************************************************************************
+**
+** 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 demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "pathstroke.h"
+#include "arthurstyle.h"
+#include "arthurwidgets.h"
+
+#include <stdio.h>
+
+extern void draw_round_rect(QPainter *p, const QRect &bounds, int radius);
+
+
+PathStrokeControls::PathStrokeControls(QWidget* parent, PathStrokeRenderer* renderer, bool smallScreen)
+ : QWidget(parent)
+{
+ m_renderer = renderer;
+
+ if (smallScreen)
+ layoutForSmallScreens();
+ else
+ layoutForDesktop();
+}
+
+void PathStrokeControls::createCommonControls(QWidget* parent)
+{
+ m_capGroup = new QGroupBox(parent);
+ m_capGroup->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
+ QRadioButton *flatCap = new QRadioButton(m_capGroup);
+ QRadioButton *squareCap = new QRadioButton(m_capGroup);
+ QRadioButton *roundCap = new QRadioButton(m_capGroup);
+ m_capGroup->setTitle(tr("Cap Style"));
+ flatCap->setText(tr("Flat"));
+ squareCap->setText(tr("Square"));
+ roundCap->setText(tr("Round"));
+ flatCap->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ squareCap->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ roundCap->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+
+ m_joinGroup = new QGroupBox(parent);
+ m_joinGroup->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
+ QRadioButton *bevelJoin = new QRadioButton(m_joinGroup);
+ QRadioButton *miterJoin = new QRadioButton(m_joinGroup);
+ QRadioButton *roundJoin = new QRadioButton(m_joinGroup);
+ m_joinGroup->setTitle(tr("Join Style"));
+ bevelJoin->setText(tr("Bevel"));
+ miterJoin->setText(tr("Miter"));
+ roundJoin->setText(tr("Round"));
+
+ m_styleGroup = new QGroupBox(parent);
+ m_styleGroup->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
+ QRadioButton *solidLine = new QRadioButton(m_styleGroup);
+ QRadioButton *dashLine = new QRadioButton(m_styleGroup);
+ QRadioButton *dotLine = new QRadioButton(m_styleGroup);
+ QRadioButton *dashDotLine = new QRadioButton(m_styleGroup);
+ QRadioButton *dashDotDotLine = new QRadioButton(m_styleGroup);
+ QRadioButton *customDashLine = new QRadioButton(m_styleGroup);
+ m_styleGroup->setTitle(tr("Pen Style"));
+
+ QPixmap line_solid(":res/images/line_solid.png");
+ solidLine->setIcon(line_solid);
+ solidLine->setIconSize(line_solid.size());
+ QPixmap line_dashed(":res/images/line_dashed.png");
+ dashLine->setIcon(line_dashed);
+ dashLine->setIconSize(line_dashed.size());
+ QPixmap line_dotted(":res/images/line_dotted.png");
+ dotLine->setIcon(line_dotted);
+ dotLine->setIconSize(line_dotted.size());
+ QPixmap line_dash_dot(":res/images/line_dash_dot.png");
+ dashDotLine->setIcon(line_dash_dot);
+ dashDotLine->setIconSize(line_dash_dot.size());
+ QPixmap line_dash_dot_dot(":res/images/line_dash_dot_dot.png");
+ dashDotDotLine->setIcon(line_dash_dot_dot);
+ dashDotDotLine->setIconSize(line_dash_dot_dot.size());
+ customDashLine->setText(tr("Custom"));
+
+ int fixedHeight = bevelJoin->sizeHint().height();
+ solidLine->setFixedHeight(fixedHeight);
+ dashLine->setFixedHeight(fixedHeight);
+ dotLine->setFixedHeight(fixedHeight);
+ dashDotLine->setFixedHeight(fixedHeight);
+ dashDotDotLine->setFixedHeight(fixedHeight);
+
+ m_pathModeGroup = new QGroupBox(parent);
+ m_pathModeGroup->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
+ QRadioButton *curveMode = new QRadioButton(m_pathModeGroup);
+ QRadioButton *lineMode = new QRadioButton(m_pathModeGroup);
+ m_pathModeGroup->setTitle(tr("Line Style"));
+ curveMode->setText(tr("Curves"));
+ lineMode->setText(tr("Lines"));
+
+
+ // Layouts
+ QVBoxLayout *capGroupLayout = new QVBoxLayout(m_capGroup);
+ capGroupLayout->addWidget(flatCap);
+ capGroupLayout->addWidget(squareCap);
+ capGroupLayout->addWidget(roundCap);
+
+ QVBoxLayout *joinGroupLayout = new QVBoxLayout(m_joinGroup);
+ joinGroupLayout->addWidget(bevelJoin);
+ joinGroupLayout->addWidget(miterJoin);
+ joinGroupLayout->addWidget(roundJoin);
+
+ QVBoxLayout *styleGroupLayout = new QVBoxLayout(m_styleGroup);
+ styleGroupLayout->addWidget(solidLine);
+ styleGroupLayout->addWidget(dashLine);
+ styleGroupLayout->addWidget(dotLine);
+ styleGroupLayout->addWidget(dashDotLine);
+ styleGroupLayout->addWidget(dashDotDotLine);
+ styleGroupLayout->addWidget(customDashLine);
+
+ QVBoxLayout *pathModeGroupLayout = new QVBoxLayout(m_pathModeGroup);
+ pathModeGroupLayout->addWidget(curveMode);
+ pathModeGroupLayout->addWidget(lineMode);
+
+
+ // Connections
+ connect(flatCap, SIGNAL(clicked()), m_renderer, SLOT(setFlatCap()));
+ connect(squareCap, SIGNAL(clicked()), m_renderer, SLOT(setSquareCap()));
+ connect(roundCap, SIGNAL(clicked()), m_renderer, SLOT(setRoundCap()));
+
+ connect(bevelJoin, SIGNAL(clicked()), m_renderer, SLOT(setBevelJoin()));
+ connect(miterJoin, SIGNAL(clicked()), m_renderer, SLOT(setMiterJoin()));
+ connect(roundJoin, SIGNAL(clicked()), m_renderer, SLOT(setRoundJoin()));
+
+ connect(curveMode, SIGNAL(clicked()), m_renderer, SLOT(setCurveMode()));
+ connect(lineMode, SIGNAL(clicked()), m_renderer, SLOT(setLineMode()));
+
+ connect(solidLine, SIGNAL(clicked()), m_renderer, SLOT(setSolidLine()));
+ connect(dashLine, SIGNAL(clicked()), m_renderer, SLOT(setDashLine()));
+ connect(dotLine, SIGNAL(clicked()), m_renderer, SLOT(setDotLine()));
+ connect(dashDotLine, SIGNAL(clicked()), m_renderer, SLOT(setDashDotLine()));
+ connect(dashDotDotLine, SIGNAL(clicked()), m_renderer, SLOT(setDashDotDotLine()));
+ connect(customDashLine, SIGNAL(clicked()), m_renderer, SLOT(setCustomDashLine()));
+
+ // Set the defaults:
+ flatCap->setChecked(true);
+ bevelJoin->setChecked(true);
+ curveMode->setChecked(true);
+ solidLine->setChecked(true);
+}
+
+
+void PathStrokeControls::layoutForDesktop()
+{
+ QGroupBox *mainGroup = new QGroupBox(this);
+ mainGroup->setFixedWidth(180);
+ mainGroup->setTitle(tr("Path Stroking"));
+
+ createCommonControls(mainGroup);
+
+ QGroupBox* penWidthGroup = new QGroupBox(mainGroup);
+ QSlider *penWidth = new QSlider(Qt::Horizontal, penWidthGroup);
+ penWidth->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+ penWidthGroup->setTitle(tr("Pen Width"));
+ penWidth->setRange(0, 500);
+
+ QPushButton *animated = new QPushButton(mainGroup);
+ animated->setText(tr("Animate"));
+ animated->setCheckable(true);
+
+ QPushButton *showSourceButton = new QPushButton(mainGroup);
+ showSourceButton->setText(tr("Show Source"));
+#ifdef QT_OPENGL_SUPPORT
+ QPushButton *enableOpenGLButton = new QPushButton(mainGroup);
+ enableOpenGLButton->setText(tr("Use OpenGL"));
+ enableOpenGLButton->setCheckable(true);
+ enableOpenGLButton->setChecked(m_renderer->usesOpenGL());
+ if (!QGLFormat::hasOpenGL())
+ enableOpenGLButton->hide();
+#endif
+ QPushButton *whatsThisButton = new QPushButton(mainGroup);
+ whatsThisButton->setText(tr("What's This?"));
+ whatsThisButton->setCheckable(true);
+
+
+ // Layouts:
+ QVBoxLayout *penWidthLayout = new QVBoxLayout(penWidthGroup);
+ penWidthLayout->addWidget(penWidth);
+
+ QVBoxLayout * mainLayout = new QVBoxLayout(this);
+ mainLayout->setMargin(0);
+ mainLayout->addWidget(mainGroup);
+
+ QVBoxLayout *mainGroupLayout = new QVBoxLayout(mainGroup);
+ mainGroupLayout->setMargin(3);
+ mainGroupLayout->addWidget(m_capGroup);
+ mainGroupLayout->addWidget(m_joinGroup);
+ mainGroupLayout->addWidget(m_styleGroup);
+ mainGroupLayout->addWidget(penWidthGroup);
+ mainGroupLayout->addWidget(m_pathModeGroup);
+ mainGroupLayout->addWidget(animated);
+ mainGroupLayout->addStretch(1);
+ mainGroupLayout->addWidget(showSourceButton);
+#ifdef QT_OPENGL_SUPPORT
+ mainGroupLayout->addWidget(enableOpenGLButton);
+#endif
+ mainGroupLayout->addWidget(whatsThisButton);
+
+
+ // Set up connections
+ connect(animated, SIGNAL(toggled(bool)),
+ m_renderer, SLOT(setAnimation(bool)));
+
+ connect(penWidth, SIGNAL(valueChanged(int)),
+ m_renderer, SLOT(setPenWidth(int)));
+
+ connect(showSourceButton, SIGNAL(clicked()), m_renderer, SLOT(showSource()));
+#ifdef QT_OPENGL_SUPPORT
+ connect(enableOpenGLButton, SIGNAL(clicked(bool)), m_renderer, SLOT(enableOpenGL(bool)));
+#endif
+ connect(whatsThisButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setDescriptionEnabled(bool)));
+ connect(m_renderer, SIGNAL(descriptionEnabledChanged(bool)),
+ whatsThisButton, SLOT(setChecked(bool)));
+
+
+ // Set the defaults
+ animated->setChecked(true);
+ penWidth->setValue(50);
+
+}
+
+void PathStrokeControls::layoutForSmallScreens()
+{
+ createCommonControls(this);
+
+ m_capGroup->layout()->setMargin(0);
+ m_joinGroup->layout()->setMargin(0);
+ m_styleGroup->layout()->setMargin(0);
+ m_pathModeGroup->layout()->setMargin(0);
+
+ QPushButton* okBtn = new QPushButton(tr("OK"), this);
+ okBtn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ okBtn->setMinimumSize(100,okBtn->minimumSize().height());
+
+ QPushButton* quitBtn = new QPushButton(tr("Quit"), this);
+ quitBtn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ quitBtn->setMinimumSize(100, okBtn->minimumSize().height());
+
+ QLabel *penWidthLabel = new QLabel(tr(" Width:"));
+ QSlider *penWidth = new QSlider(Qt::Horizontal, this);
+ penWidth->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+ penWidth->setRange(0, 500);
+
+#ifdef QT_OPENGL_SUPPORT
+ QPushButton *enableOpenGLButton = new QPushButton(this);
+ enableOpenGLButton->setText(tr("Use OpenGL"));
+ enableOpenGLButton->setCheckable(true);
+ enableOpenGLButton->setChecked(m_renderer->usesOpenGL());
+ if (!QGLFormat::hasOpenGL())
+ enableOpenGLButton->hide();
+#endif
+
+ // Layouts:
+ QHBoxLayout *penWidthLayout = new QHBoxLayout(0);
+ penWidthLayout->addWidget(penWidthLabel, 0, Qt::AlignRight);
+ penWidthLayout->addWidget(penWidth);
+
+ QVBoxLayout *leftLayout = new QVBoxLayout(0);
+ leftLayout->addWidget(m_capGroup);
+ leftLayout->addWidget(m_joinGroup);
+#ifdef QT_OPENGL_SUPPORT
+ leftLayout->addWidget(enableOpenGLButton);
+#endif
+ leftLayout->addLayout(penWidthLayout);
+
+ QVBoxLayout *rightLayout = new QVBoxLayout(0);
+ rightLayout->addWidget(m_styleGroup);
+ rightLayout->addWidget(m_pathModeGroup);
+
+ QGridLayout *mainLayout = new QGridLayout(this);
+ mainLayout->setMargin(0);
+
+ // Add spacers around the form items so we don't look stupid at higher resolutions
+ mainLayout->addItem(new QSpacerItem(0,0), 0, 0, 1, 4);
+ mainLayout->addItem(new QSpacerItem(0,0), 1, 0, 2, 1);
+ mainLayout->addItem(new QSpacerItem(0,0), 1, 3, 2, 1);
+ mainLayout->addItem(new QSpacerItem(0,0), 3, 0, 1, 4);
+
+ mainLayout->addLayout(leftLayout, 1, 1);
+ mainLayout->addLayout(rightLayout, 1, 2);
+ mainLayout->addWidget(quitBtn, 2, 1, Qt::AlignHCenter | Qt::AlignTop);
+ mainLayout->addWidget(okBtn, 2, 2, Qt::AlignHCenter | Qt::AlignTop);
+
+#ifdef QT_OPENGL_SUPPORT
+ connect(enableOpenGLButton, SIGNAL(clicked(bool)), m_renderer, SLOT(enableOpenGL(bool)));
+#endif
+
+ connect(penWidth, SIGNAL(valueChanged(int)), m_renderer, SLOT(setPenWidth(int)));
+ connect(quitBtn, SIGNAL(clicked()), this, SLOT(emitQuitSignal()));
+ connect(okBtn, SIGNAL(clicked()), this, SLOT(emitOkSignal()));
+
+ m_renderer->setAnimation(true);
+ penWidth->setValue(50);
+}
+
+void PathStrokeControls::emitQuitSignal()
+{ emit quitPressed(); }
+
+void PathStrokeControls::emitOkSignal()
+{ emit okPressed(); }
+
+
+PathStrokeWidget::PathStrokeWidget(bool smallScreen)
+{
+ setWindowTitle(tr("Path Stroking"));
+
+ // Widget construction and property setting
+ m_renderer = new PathStrokeRenderer(this, smallScreen);
+
+ m_controls = new PathStrokeControls(0, m_renderer, smallScreen);
+
+ // Layouting
+ QHBoxLayout *viewLayout = new QHBoxLayout(this);
+ viewLayout->addWidget(m_renderer);
+
+ if (!smallScreen)
+ viewLayout->addWidget(m_controls);
+
+ m_renderer->loadSourceFile(":res/pathstroke/pathstroke.cpp");
+ m_renderer->loadDescription(":res/pathstroke/pathstroke.html");
+
+ connect(m_renderer, SIGNAL(clicked()), this, SLOT(showControls()));
+ connect(m_controls, SIGNAL(okPressed()), this, SLOT(hideControls()));
+ connect(m_controls, SIGNAL(quitPressed()), QApplication::instance(), SLOT(quit()));
+}
+
+
+void PathStrokeWidget::showControls()
+{
+ m_controls->showFullScreen();
+}
+
+
+void PathStrokeWidget::hideControls()
+{
+ m_controls->hide();
+}
+
+
+void PathStrokeWidget::setStyle( QStyle * style )
+{
+ QWidget::setStyle(style);
+ if (m_controls != 0)
+ {
+ m_controls->setStyle(style);
+
+ QList<QWidget *> widgets = m_controls->findChildren<QWidget *>();
+ foreach (QWidget *w, widgets)
+ w->setStyle(style);
+ }
+}
+
+
+PathStrokeRenderer::PathStrokeRenderer(QWidget *parent, bool smallScreen)
+ : ArthurFrame(parent)
+{
+ m_smallScreen = smallScreen;
+ m_pointSize = 10;
+ m_activePoint = -1;
+ m_capStyle = Qt::FlatCap;
+ m_joinStyle = Qt::BevelJoin;
+ m_pathMode = CurveMode;
+ m_penWidth = 1;
+ m_penStyle = Qt::SolidLine;
+ m_wasAnimated = true;
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ setAttribute(Qt::WA_AcceptTouchEvents);
+}
+
+void PathStrokeRenderer::paint(QPainter *painter)
+{
+ if (m_points.isEmpty())
+ initializePoints();
+
+ painter->setRenderHint(QPainter::Antialiasing);
+
+ QPalette pal = palette();
+ painter->setPen(Qt::NoPen);
+
+ // Construct the path
+ QPainterPath path;
+ path.moveTo(m_points.at(0));
+
+ if (m_pathMode == LineMode) {
+ for (int i=1; i<m_points.size(); ++i) {
+ path.lineTo(m_points.at(i));
+ }
+ } else {
+ int i=1;
+ while (i + 2 < m_points.size()) {
+ path.cubicTo(m_points.at(i), m_points.at(i+1), m_points.at(i+2));
+ i += 3;
+ }
+ while (i < m_points.size()) {
+ path.lineTo(m_points.at(i));
+ ++i;
+ }
+ }
+
+ // Draw the path
+ {
+ QColor lg = Qt::red;
+
+ // The "custom" pen
+ if (m_penStyle == Qt::NoPen) {
+ QPainterPathStroker stroker;
+ stroker.setWidth(m_penWidth);
+ stroker.setJoinStyle(m_joinStyle);
+ stroker.setCapStyle(m_capStyle);
+
+ QVector<qreal> dashes;
+ qreal space = 4;
+ dashes << 1 << space
+ << 3 << space
+ << 9 << space
+ << 27 << space
+ << 9 << space
+ << 3 << space;
+ stroker.setDashPattern(dashes);
+ QPainterPath stroke = stroker.createStroke(path);
+ painter->fillPath(stroke, lg);
+
+ } else {
+ QPen pen(lg, m_penWidth, m_penStyle, m_capStyle, m_joinStyle);
+ painter->strokePath(path, pen);
+ }
+ }
+
+ if (1) {
+ // Draw the control points
+ painter->setPen(QColor(50, 100, 120, 200));
+ painter->setBrush(QColor(200, 200, 210, 120));
+ for (int i=0; i<m_points.size(); ++i) {
+ QPointF pos = m_points.at(i);
+ painter->drawEllipse(QRectF(pos.x() - m_pointSize,
+ pos.y() - m_pointSize,
+ m_pointSize*2, m_pointSize*2));
+ }
+ painter->setPen(QPen(Qt::lightGray, 0, Qt::SolidLine));
+ painter->setBrush(Qt::NoBrush);
+ painter->drawPolyline(m_points);
+ }
+
+}
+
+void PathStrokeRenderer::initializePoints()
+{
+ const int count = 7;
+ m_points.clear();
+ m_vectors.clear();
+
+ QMatrix m;
+ qreal rot = 360 / count;
+ QPointF center(width() / 2, height() / 2);
+ QMatrix vm;
+ vm.shear(2, -1);
+ vm.scale(3, 3);
+
+ for (int i=0; i<count; ++i) {
+ m_vectors << QPointF(.1f, .25f) * (m * vm);
+ m_points << QPointF(0, 100) * m + center;
+ m.rotate(rot);
+ }
+}
+
+void PathStrokeRenderer::updatePoints()
+{
+ qreal pad = 10;
+ qreal left = pad;
+ qreal right = width() - pad;
+ qreal top = pad;
+ qreal bottom = height() - pad;
+
+ Q_ASSERT(m_points.size() == m_vectors.size());
+ for (int i=0; i<m_points.size(); ++i) {
+ QPointF pos = m_points.at(i);
+ QPointF vec = m_vectors.at(i);
+ pos += vec;
+ if (pos.x() < left || pos.x() > right) {
+ vec.setX(-vec.x());
+ pos.setX(pos.x() < left ? left : right);
+ } if (pos.y() < top || pos.y() > bottom) {
+ vec.setY(-vec.y());
+ pos.setY(pos.y() < top ? top : bottom);
+ }
+ m_points[i] = pos;
+ m_vectors[i] = vec;
+ }
+ update();
+}
+
+void PathStrokeRenderer::mousePressEvent(QMouseEvent *e)
+{
+ if (!m_fingerPointMapping.isEmpty())
+ return;
+ setDescriptionEnabled(false);
+ m_activePoint = -1;
+ qreal distance = -1;
+ for (int i=0; i<m_points.size(); ++i) {
+ qreal d = QLineF(e->pos(), m_points.at(i)).length();
+ if ((distance < 0 && d < 8 * m_pointSize) || d < distance) {
+ distance = d;
+ m_activePoint = i;
+ }
+ }
+
+ if (m_activePoint != -1) {
+ m_wasAnimated = m_timer.isActive();
+ setAnimation(false);
+ mouseMoveEvent(e);
+ }
+
+ // If we're not running in small screen mode, always assume we're dragging
+ m_mouseDrag = !m_smallScreen;
+ m_mousePress = e->pos();
+}
+
+void PathStrokeRenderer::mouseMoveEvent(QMouseEvent *e)
+{
+ if (!m_fingerPointMapping.isEmpty())
+ return;
+ // If we've moved more then 25 pixels, assume user is dragging
+ if (!m_mouseDrag && QPoint(m_mousePress - e->pos()).manhattanLength() > 25)
+ m_mouseDrag = true;
+
+ if (m_mouseDrag && m_activePoint >= 0 && m_activePoint < m_points.size()) {
+ m_points[m_activePoint] = e->pos();
+ update();
+ }
+}
+
+void PathStrokeRenderer::mouseReleaseEvent(QMouseEvent *)
+{
+ if (!m_fingerPointMapping.isEmpty())
+ return;
+ m_activePoint = -1;
+ setAnimation(m_wasAnimated);
+
+ if (!m_mouseDrag && m_smallScreen)
+ emit clicked();
+}
+
+void PathStrokeRenderer::timerEvent(QTimerEvent *e)
+{
+ if (e->timerId() == m_timer.timerId()) {
+ updatePoints();
+ QApplication::syncX();
+ } // else if (e->timerId() == m_fpsTimer.timerId()) {
+// emit frameRate(m_frameCount);
+// m_frameCount = 0;
+// }
+}
+
+bool PathStrokeRenderer::event(QEvent *e)
+{
+ bool touchBegin = false;
+ switch (e->type()) {
+ case QEvent::TouchBegin:
+ touchBegin = true;
+ case QEvent::TouchUpdate:
+ {
+ const QTouchEvent *const event = static_cast<const QTouchEvent*>(e);
+ const QList<QTouchEvent::TouchPoint> points = event->touchPoints();
+ foreach (const QTouchEvent::TouchPoint &touchPoint, points) {
+ const int id = touchPoint.id();
+ switch (touchPoint.state()) {
+ case Qt::TouchPointPressed:
+ {
+ // find the point, move it
+ QSet<int> activePoints = QSet<int>::fromList(m_fingerPointMapping.values());
+ int activePoint = -1;
+ qreal distance = -1;
+ const int pointsCount = m_points.size();
+ for (int i=0; i<pointsCount; ++i) {
+ if (activePoints.contains(i))
+ continue;
+
+ qreal d = QLineF(touchPoint.pos(), m_points.at(i)).length();
+ if ((distance < 0 && d < 12 * m_pointSize) || d < distance) {
+ distance = d;
+ activePoint = i;
+ }
+ }
+ if (activePoint != -1) {
+ m_fingerPointMapping.insert(touchPoint.id(), activePoint);
+ m_points[activePoint] = touchPoint.pos();
+ }
+ }
+ break;
+ case Qt::TouchPointReleased:
+ {
+ // move the point and release
+ QHash<int,int>::iterator it = m_fingerPointMapping.find(id);
+ m_points[it.value()] = touchPoint.pos();
+ m_fingerPointMapping.erase(it);
+ }
+ break;
+ case Qt::TouchPointMoved:
+ {
+ // move the point
+ const int pointIdx = m_fingerPointMapping.value(id, -1);
+ if (pointIdx >= 0)
+ m_points[pointIdx] = touchPoint.pos();
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ if (m_fingerPointMapping.isEmpty()) {
+ e->ignore();
+ return false;
+ } else {
+ if (touchBegin) {
+ m_wasAnimated = m_timer.isActive();
+ setAnimation(false);
+ }
+ update();
+ return true;
+ }
+ }
+ break;
+ case QEvent::TouchEnd:
+ if (m_fingerPointMapping.isEmpty()) {
+ e->ignore();
+ return false;
+ }
+ m_fingerPointMapping.clear();
+ setAnimation(m_wasAnimated);
+ return true;
+ break;
+ default:
+ break;
+ }
+ return QWidget::event(e);
+}
+
+void PathStrokeRenderer::setAnimation(bool animation)
+{
+ m_timer.stop();
+// m_fpsTimer.stop();
+
+ if (animation) {
+ m_timer.start(25, this);
+// m_fpsTimer.start(1000, this);
+// m_frameCount = 0;
+ }
+}
diff --git a/examples/painting/pathstroke/pathstroke.h b/examples/painting/pathstroke/pathstroke.h
new file mode 100644
index 0000000000..f0360b6648
--- /dev/null
+++ b/examples/painting/pathstroke/pathstroke.h
@@ -0,0 +1,171 @@
+/****************************************************************************
+**
+** 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 demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PATHSTROKE_H
+#define PATHSTROKE_H
+
+#include "arthurwidgets.h"
+#include <QtGui>
+
+class PathStrokeRenderer : public ArthurFrame
+{
+ Q_OBJECT
+ Q_PROPERTY(bool animation READ animation WRITE setAnimation)
+ Q_PROPERTY(qreal penWidth READ realPenWidth WRITE setRealPenWidth)
+public:
+ enum PathMode { CurveMode, LineMode };
+
+ PathStrokeRenderer(QWidget *parent, bool smallScreen = false);
+
+ void paint(QPainter *);
+ void mousePressEvent(QMouseEvent *e);
+ void mouseMoveEvent(QMouseEvent *e);
+ void mouseReleaseEvent(QMouseEvent *e);
+ void timerEvent(QTimerEvent *e);
+ bool event(QEvent *e);
+
+ QSize sizeHint() const { return QSize(500, 500); }
+
+ bool animation() const { return m_timer.isActive(); }
+
+ qreal realPenWidth() const { return m_penWidth; }
+ void setRealPenWidth(qreal penWidth) { m_penWidth = penWidth; update(); }
+
+signals:
+ void clicked();
+
+public slots:
+ void setPenWidth(int penWidth) { m_penWidth = penWidth / 10.0; update(); }
+ void setAnimation(bool animation);
+
+ void setFlatCap() { m_capStyle = Qt::FlatCap; update(); }
+ void setSquareCap() { m_capStyle = Qt::SquareCap; update(); }
+ void setRoundCap() { m_capStyle = Qt::RoundCap; update(); }
+
+ void setBevelJoin() { m_joinStyle = Qt::BevelJoin; update(); }
+ void setMiterJoin() { m_joinStyle = Qt::MiterJoin; update(); }
+ void setRoundJoin() { m_joinStyle = Qt::RoundJoin; update(); }
+
+ void setCurveMode() { m_pathMode = CurveMode; update(); }
+ void setLineMode() { m_pathMode = LineMode; update(); }
+
+ void setSolidLine() { m_penStyle = Qt::SolidLine; update(); }
+ void setDashLine() { m_penStyle = Qt::DashLine; update(); }
+ void setDotLine() { m_penStyle = Qt::DotLine; update(); }
+ void setDashDotLine() { m_penStyle = Qt::DashDotLine; update(); }
+ void setDashDotDotLine() { m_penStyle = Qt::DashDotDotLine; update(); }
+ void setCustomDashLine() { m_penStyle = Qt::NoPen; update(); }
+
+private:
+ void initializePoints();
+ void updatePoints();
+
+ QBasicTimer m_timer;
+
+ PathMode m_pathMode;
+
+ bool m_wasAnimated;
+
+ qreal m_penWidth;
+ int m_pointCount;
+ int m_pointSize;
+ int m_activePoint;
+ QVector<QPointF> m_points;
+ QVector<QPointF> m_vectors;
+
+ Qt::PenJoinStyle m_joinStyle;
+ Qt::PenCapStyle m_capStyle;
+
+ Qt::PenStyle m_penStyle;
+
+ bool m_smallScreen;
+ QPoint m_mousePress;
+ bool m_mouseDrag;
+
+ QHash<int, int> m_fingerPointMapping;
+};
+
+class PathStrokeControls : public QWidget
+{
+ Q_OBJECT
+public:
+ PathStrokeControls(QWidget* parent, PathStrokeRenderer* renderer, bool smallScreen);
+
+signals:
+ void okPressed();
+ void quitPressed();
+
+private:
+ PathStrokeRenderer* m_renderer;
+
+ QGroupBox *m_capGroup;
+ QGroupBox *m_joinGroup;
+ QGroupBox *m_styleGroup;
+ QGroupBox *m_pathModeGroup;
+
+ void createCommonControls(QWidget* parent);
+ void layoutForDesktop();
+ void layoutForSmallScreens();
+
+private slots:
+ void emitQuitSignal();
+ void emitOkSignal();
+
+};
+
+class PathStrokeWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ PathStrokeWidget(bool smallScreen);
+ void setStyle ( QStyle * style );
+
+private:
+ PathStrokeRenderer *m_renderer;
+ PathStrokeControls *m_controls;
+
+private slots:
+ void showControls();
+ void hideControls();
+
+};
+
+#endif // PATHSTROKE_H
diff --git a/examples/painting/pathstroke/pathstroke.html b/examples/painting/pathstroke/pathstroke.html
new file mode 100644
index 0000000000..9e7e50de76
--- /dev/null
+++ b/examples/painting/pathstroke/pathstroke.html
@@ -0,0 +1,20 @@
+<html>
+<center>
+<h2>Primitive Stroking</h2>
+</center>
+
+<p>In this demo we show some of the various types of pens that can be
+used in Qt.</p>
+
+<p>Qt defines cap styles for how the end points are treated and join
+styles for how path segments are joined together. A standard set of
+predefined dash patterns are also included that can be used with
+<code>QPen</code>.</p>
+
+<p>In addition to the predefined patterns available in
+<code>QPen</code> we also demonstrate direct use of the
+<code>QPainterPathStroker</code> class which can be used to define
+custom dash patterns. You can see this by enabling the
+<i>Custom Pattern</i> option.</p>
+
+</html>
diff --git a/examples/painting/pathstroke/pathstroke.pro b/examples/painting/pathstroke/pathstroke.pro
new file mode 100644
index 0000000000..9bbf8a6f77
--- /dev/null
+++ b/examples/painting/pathstroke/pathstroke.pro
@@ -0,0 +1,24 @@
+SOURCES += main.cpp pathstroke.cpp
+HEADERS += pathstroke.h
+
+SHARED_FOLDER = ../shared
+
+include($$SHARED_FOLDER/shared.pri)
+
+RESOURCES += pathstroke.qrc
+
+contains(QT_CONFIG, opengl) {
+ DEFINES += QT_OPENGL_SUPPORT
+ QT += opengl
+}
+
+# install
+target.path = $$[QT_INSTALL_DEMOS]/qtbase/pathstroke
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.html
+sources.path = $$[QT_INSTALL_DEMOS]/qtbase/pathstroke
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000A63E
+ CONFIG += qt_demo
+}
diff --git a/examples/painting/pathstroke/pathstroke.qrc b/examples/painting/pathstroke/pathstroke.qrc
new file mode 100644
index 0000000000..a9a723409e
--- /dev/null
+++ b/examples/painting/pathstroke/pathstroke.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/res/pathstroke">
+ <file>pathstroke.cpp</file>
+ <file>pathstroke.html</file>
+</qresource>
+</RCC>
diff --git a/examples/painting/shared/arthurstyle.cpp b/examples/painting/shared/arthurstyle.cpp
new file mode 100644
index 0000000000..432b8b34e5
--- /dev/null
+++ b/examples/painting/shared/arthurstyle.cpp
@@ -0,0 +1,452 @@
+/****************************************************************************
+**
+** 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 demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "arthurstyle.h"
+#include "arthurwidgets.h"
+#include <QLayout>
+#include <QPainter>
+#include <QPainterPath>
+#include <QPixmapCache>
+#include <QRadioButton>
+#include <QString>
+#include <QStyleOption>
+#include <QtDebug>
+
+QPixmap cached(const QString &img)
+{
+ if (QPixmap *p = QPixmapCache::find(img))
+ return *p;
+
+ QPixmap pm;
+ pm = QPixmap::fromImage(QImage(img), Qt::OrderedDither | Qt::OrderedAlphaDither);
+ if (pm.isNull())
+ return QPixmap();
+
+ QPixmapCache::insert(img, pm);
+ return pm;
+}
+
+
+ArthurStyle::ArthurStyle()
+ : QWindowsStyle()
+{
+ Q_INIT_RESOURCE(shared);
+}
+
+
+void ArthurStyle::drawHoverRect(QPainter *painter, const QRect &r) const
+{
+ qreal h = r.height();
+ qreal h2 = r.height() / qreal(2);
+ QPainterPath path;
+ path.addRect(r.x() + h2, r.y() + 0, r.width() - h2 * 2, r.height());
+ path.addEllipse(r.x(), r.y(), h, h);
+ path.addEllipse(r.x() + r.width() - h, r.y(), h, h);
+ path.setFillRule(Qt::WindingFill);
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(QColor(191, 215, 191));
+ painter->setRenderHint(QPainter::Antialiasing);
+ painter->drawPath(path);
+}
+
+
+void ArthurStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
+ QPainter *painter, const QWidget *widget) const
+{
+
+ Q_ASSERT(option);
+ switch (element) {
+ case PE_FrameFocusRect:
+ break;
+
+ case PE_IndicatorRadioButton:
+ if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
+ bool hover = (button->state & State_Enabled) && (button->state & State_MouseOver);
+ painter->save();
+ QPixmap radio;
+ if (hover)
+ drawHoverRect(painter, widget->rect());
+
+ if (button->state & State_Sunken)
+ radio = cached(":res/images/radiobutton-on.png");
+ else if (button->state & State_On)
+ radio = cached(":res/images/radiobutton_on.png");
+ else
+ radio = cached(":res/images/radiobutton_off.png");
+ painter->drawPixmap(button->rect.topLeft(), radio);
+
+ painter->restore();
+ }
+ break;
+
+ case PE_PanelButtonCommand:
+ if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
+ bool hover = (button->state & State_Enabled) && (button->state & State_MouseOver);
+
+ painter->save();
+ const QPushButton *pushButton = qobject_cast<const QPushButton *>(widget);
+ Q_ASSERT(pushButton);
+ QWidget *parent = pushButton->parentWidget();
+ if (parent && qobject_cast<QGroupBox *>(parent)) {
+ QLinearGradient lg(0, 0, 0, parent->height());
+ lg.setColorAt(0, QColor(224,224,224));
+ lg.setColorAt(1, QColor(255,255,255));
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(lg);
+ painter->setBrushOrigin(-widget->mapToParent(QPoint(0,0)));
+ painter->drawRect(button->rect);
+ painter->setBrushOrigin(0,0);
+ }
+
+ bool down = (button->state & State_Sunken) || (button->state & State_On);
+
+ QPixmap left, right, mid;
+ if (down) {
+ left = cached(":res/images/button_pressed_cap_left.png");
+ right = cached(":res/images/button_pressed_cap_right.png");
+ mid = cached(":res/images/button_pressed_stretch.png");
+ } else {
+ left = cached(":res/images/button_normal_cap_left.png");
+ right = cached(":res/images/button_normal_cap_right.png");
+ mid = cached(":res/images/button_normal_stretch.png");
+ }
+ painter->drawPixmap(button->rect.topLeft(), left);
+ painter->drawTiledPixmap(QRect(button->rect.x() + left.width(),
+ button->rect.y(),
+ button->rect.width() - left.width() - right.width(),
+ left.height()),
+ mid);
+ painter->drawPixmap(button->rect.x() + button->rect.width() - right.width(),
+ button->rect.y(),
+ right);
+ if (hover)
+ painter->fillRect(widget->rect().adjusted(3,5,-3,-5), QColor(31,127,31,63));
+ painter->restore();
+ }
+ break;
+
+ case PE_FrameGroupBox:
+ if (const QStyleOptionFrameV2 *group
+ = qstyleoption_cast<const QStyleOptionFrameV2 *>(option)) {
+ const QRect &r = group->rect;
+
+ painter->save();
+ int radius = 14;
+ int radius2 = radius*2;
+ QPainterPath clipPath;
+ clipPath.moveTo(radius, 0);
+ clipPath.arcTo(r.right() - radius2, 0, radius2, radius2, 90, -90);
+ clipPath.arcTo(r.right() - radius2, r.bottom() - radius2, radius2, radius2, 0, -90);
+ clipPath.arcTo(r.left(), r.bottom() - radius2, radius2, radius2, 270, -90);
+ clipPath.arcTo(r.left(), r.top(), radius2, radius2, 180, -90);
+ painter->setClipPath(clipPath);
+ QPixmap titleStretch = cached(":res/images/title_stretch.png");
+ QPixmap topLeft = cached(":res/images/groupframe_topleft.png");
+ QPixmap topRight = cached(":res/images/groupframe_topright.png");
+ QPixmap bottomLeft = cached(":res/images/groupframe_bottom_left.png");
+ QPixmap bottomRight = cached(":res/images/groupframe_bottom_right.png");
+ QPixmap leftStretch = cached(":res/images/groupframe_left_stretch.png");
+ QPixmap topStretch = cached(":res/images/groupframe_top_stretch.png");
+ QPixmap rightStretch = cached(":res/images/groupframe_right_stretch.png");
+ QPixmap bottomStretch = cached(":res/images/groupframe_bottom_stretch.png");
+ QLinearGradient lg(0, 0, 0, r.height());
+ lg.setColorAt(0, QColor(224,224,224));
+ lg.setColorAt(1, QColor(255,255,255));
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(lg);
+ painter->drawRect(r.adjusted(0, titleStretch.height()/2, 0, 0));
+ painter->setClipping(false);
+
+ int topFrameOffset = titleStretch.height()/2 - 2;
+ painter->drawPixmap(r.topLeft() + QPoint(0, topFrameOffset), topLeft);
+ painter->drawPixmap(r.topRight() - QPoint(topRight.width()-1, 0)
+ + QPoint(0, topFrameOffset), topRight);
+ painter->drawPixmap(r.bottomLeft() - QPoint(0, bottomLeft.height()-1), bottomLeft);
+ painter->drawPixmap(r.bottomRight() - QPoint(bottomRight.width()-1,
+ bottomRight.height()-1), bottomRight);
+
+ QRect left = r;
+ left.setY(r.y() + topLeft.height() + topFrameOffset);
+ left.setWidth(leftStretch.width());
+ left.setHeight(r.height() - topLeft.height() - bottomLeft.height() - topFrameOffset);
+ painter->drawTiledPixmap(left, leftStretch);
+
+ QRect top = r;
+ top.setX(r.x() + topLeft.width());
+ top.setY(r.y() + topFrameOffset);
+ top.setWidth(r.width() - topLeft.width() - topRight.width());
+ top.setHeight(topLeft.height());
+ painter->drawTiledPixmap(top, topStretch);
+
+ QRect right = r;
+ right.setX(r.right() - rightStretch.width()+1);
+ right.setY(r.y() + topRight.height() + topFrameOffset);
+ right.setWidth(rightStretch.width());
+ right.setHeight(r.height() - topRight.height()
+ - bottomRight.height() - topFrameOffset);
+ painter->drawTiledPixmap(right, rightStretch);
+
+ QRect bottom = r;
+ bottom.setX(r.x() + bottomLeft.width());
+ bottom.setY(r.bottom() - bottomStretch.height()+1);
+ bottom.setWidth(r.width() - bottomLeft.width() - bottomRight.width());
+ bottom.setHeight(bottomLeft.height());
+ painter->drawTiledPixmap(bottom, bottomStretch);
+ painter->restore();
+ }
+ break;
+
+ default:
+ QWindowsStyle::drawPrimitive(element, option, painter, widget);
+ break;
+ }
+ return;
+}
+
+
+void ArthurStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
+ QPainter *painter, const QWidget *widget) const
+{
+ switch (control) {
+ case CC_Slider:
+ if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
+ QRect groove = subControlRect(CC_Slider, option, SC_SliderGroove, widget);
+ QRect handle = subControlRect(CC_Slider, option, SC_SliderHandle, widget);
+
+ painter->save();
+
+ bool hover = (slider->state & State_Enabled) && (slider->state & State_MouseOver);
+ if (hover) {
+ QRect moderated = widget->rect().adjusted(0, 4, 0, -4);
+ drawHoverRect(painter, moderated);
+ }
+
+ if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
+ QPixmap grv = cached(":res/images/slider_bar.png");
+ painter->drawPixmap(QRect(groove.x() + 5, groove.y(),
+ groove.width() - 10, grv.height()),
+ grv);
+ }
+ if ((option->subControls & SC_SliderHandle) && handle.isValid()) {
+ QPixmap hndl = cached(":res/images/slider_thumb_on.png");
+ painter->drawPixmap(handle.topLeft(), hndl);
+ }
+
+ painter->restore();
+ }
+ break;
+ case CC_GroupBox:
+ if (const QStyleOptionGroupBox *groupBox
+ = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
+ QStyleOptionGroupBox groupBoxCopy(*groupBox);
+ groupBoxCopy.subControls &= ~SC_GroupBoxLabel;
+ QWindowsStyle::drawComplexControl(control, &groupBoxCopy, painter, widget);
+
+ if (groupBox->subControls & SC_GroupBoxLabel) {
+ const QRect &r = groupBox->rect;
+ QPixmap titleLeft = cached(":res/images/title_cap_left.png");
+ QPixmap titleRight = cached(":res/images/title_cap_right.png");
+ QPixmap titleStretch = cached(":res/images/title_stretch.png");
+ int txt_width = groupBox->fontMetrics.width(groupBox->text) + 20;
+ painter->drawPixmap(r.center().x() - txt_width/2, 0, titleLeft);
+ QRect tileRect = subControlRect(control, groupBox, SC_GroupBoxLabel, widget);
+ painter->drawTiledPixmap(tileRect, titleStretch);
+ painter->drawPixmap(tileRect.x() + tileRect.width(), 0, titleRight);
+ int opacity = 31;
+ painter->setPen(QColor(0, 0, 0, opacity));
+ painter->drawText(tileRect.translated(0, 1),
+ Qt::AlignVCenter | Qt::AlignHCenter, groupBox->text);
+ painter->drawText(tileRect.translated(2, 1),
+ Qt::AlignVCenter | Qt::AlignHCenter, groupBox->text);
+ painter->setPen(QColor(0, 0, 0, opacity * 2));
+ painter->drawText(tileRect.translated(1, 1),
+ Qt::AlignVCenter | Qt::AlignHCenter, groupBox->text);
+ painter->setPen(Qt::white);
+ painter->drawText(tileRect, Qt::AlignVCenter | Qt::AlignHCenter, groupBox->text);
+ }
+ }
+ break;
+ default:
+ QWindowsStyle::drawComplexControl(control, option, painter, widget);
+ break;
+ }
+ return;
+}
+
+QRect ArthurStyle::subControlRect(ComplexControl control, const QStyleOptionComplex *option,
+ SubControl subControl, const QWidget *widget) const
+{
+ QRect rect;
+
+ switch (control) {
+ default:
+ rect = QWindowsStyle::subControlRect(control, option, subControl, widget);
+ break;
+ case CC_GroupBox:
+ if (const QStyleOptionGroupBox *group
+ = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
+ switch (subControl) {
+ default:
+ rect = QWindowsStyle::subControlRect(control, option, subControl, widget);
+ break;
+ case SC_GroupBoxContents:
+ rect = QWindowsStyle::subControlRect(control, option, subControl, widget);
+ rect.adjust(0, -8, 0, 0);
+ break;
+ case SC_GroupBoxFrame:
+ rect = group->rect;
+ break;
+ case SC_GroupBoxLabel:
+ QPixmap titleLeft = cached(":res/images/title_cap_left.png");
+ QPixmap titleRight = cached(":res/images/title_cap_right.png");
+ QPixmap titleStretch = cached(":res/images/title_stretch.png");
+ int txt_width = group->fontMetrics.width(group->text) + 20;
+ rect = QRect(group->rect.center().x() - txt_width/2 + titleLeft.width(), 0,
+ txt_width - titleLeft.width() - titleRight.width(),
+ titleStretch.height());
+ break;
+ }
+ }
+ break;
+ }
+
+ if (control == CC_Slider && subControl == SC_SliderHandle) {
+ rect.setWidth(13);
+ rect.setHeight(27);
+ } else if (control == CC_Slider && subControl == SC_SliderGroove) {
+ rect.setHeight(9);
+ rect.moveTop(27/2 - 9/2);
+ }
+ return rect;
+}
+
+QSize ArthurStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
+ const QSize &size, const QWidget *widget) const
+{
+ QSize newSize = QWindowsStyle::sizeFromContents(type, option, size, widget);
+
+
+ switch (type) {
+ case CT_RadioButton:
+ newSize += QSize(20, 0);
+ break;
+
+ case CT_PushButton:
+ newSize.setHeight(26);
+ break;
+
+ case CT_Slider:
+ newSize.setHeight(27);
+ break;
+
+ default:
+ break;
+ }
+
+ return newSize;
+}
+
+int ArthurStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QWidget *widget) const
+{
+ if (pm == PM_SliderLength)
+ return 13;
+ return QWindowsStyle::pixelMetric(pm, opt, widget);
+}
+
+void ArthurStyle::polish(QWidget *widget)
+{
+ if (widget->layout() && qobject_cast<QGroupBox *>(widget)) {
+ if (widget->findChildren<QGroupBox *>().size() == 0) {
+ widget->layout()->setSpacing(0);
+ widget->layout()->setMargin(12);
+ } else {
+ widget->layout()->setMargin(13);
+ }
+ }
+
+ if (qobject_cast<QPushButton *>(widget)
+ || qobject_cast<QRadioButton *>(widget)
+ || qobject_cast<QSlider *>(widget)) {
+ widget->setAttribute(Qt::WA_Hover);
+ }
+
+ QPalette pal = widget->palette();
+ if (widget->isWindow()) {
+ pal.setColor(QPalette::Background, QColor(241, 241, 241));
+ widget->setPalette(pal);
+ }
+
+}
+
+void ArthurStyle::unpolish(QWidget *widget)
+{
+ if (qobject_cast<QPushButton *>(widget)
+ || qobject_cast<QRadioButton *>(widget)
+ || qobject_cast<QSlider *>(widget)) {
+ widget->setAttribute(Qt::WA_Hover, false);
+ }
+}
+
+void ArthurStyle::polish(QPalette &palette)
+{
+ palette.setColor(QPalette::Background, QColor(241, 241, 241));
+}
+
+QRect ArthurStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
+{
+ QRect r;
+ switch(element) {
+ case SE_RadioButtonClickRect:
+ r = widget->rect();
+ break;
+ case SE_RadioButtonContents:
+ r = widget->rect().adjusted(20, 0, 0, 0);
+ break;
+ default:
+ r = QWindowsStyle::subElementRect(element, option, widget);
+ break;
+ }
+
+ if (qobject_cast<const QRadioButton*>(widget))
+ r = r.adjusted(5, 0, -5, 0);
+
+ return r;
+}
diff --git a/examples/painting/shared/arthurstyle.h b/examples/painting/shared/arthurstyle.h
new file mode 100644
index 0000000000..32c7fad970
--- /dev/null
+++ b/examples/painting/shared/arthurstyle.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ARTHURSTYLE_H
+#define ARTHURSTYLE_H
+
+#include <QWindowsStyle>
+
+QT_USE_NAMESPACE
+
+class ArthurStyle : public QWindowsStyle
+{
+public:
+ ArthurStyle();
+
+ void drawHoverRect(QPainter *painter, const QRect &rect) const;
+
+ void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
+ QPainter *painter, const QWidget *widget = 0) const;
+// void drawControl(ControlElement element, const QStyleOption *option,
+// QPainter *painter, const QWidget *widget) const;
+ void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
+ QPainter *painter, const QWidget *widget) const;
+ QSize sizeFromContents(ContentsType type, const QStyleOption *option,
+ const QSize &size, const QWidget *widget) const;
+
+ QRect subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const;
+ QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt,
+ SubControl sc, const QWidget *widget) const;
+
+// SubControl hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option,
+// const QPoint &pos, const QWidget *widget = 0) const;
+
+ int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const;
+
+ void polish(QPalette &palette);
+ void polish(QWidget *widget);
+ void unpolish(QWidget *widget);
+};
+
+#endif
diff --git a/examples/painting/shared/arthurwidgets.cpp b/examples/painting/shared/arthurwidgets.cpp
new file mode 100644
index 0000000000..b3c75f0fc4
--- /dev/null
+++ b/examples/painting/shared/arthurwidgets.cpp
@@ -0,0 +1,371 @@
+/****************************************************************************
+**
+** 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 demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "arthurwidgets.h"
+#include <QApplication>
+#include <QPainter>
+#include <QPainterPath>
+#include <QPixmapCache>
+#include <QtEvents>
+#include <QTextDocument>
+#include <QAbstractTextDocumentLayout>
+#include <QFile>
+#include <QTextBrowser>
+#include <QBoxLayout>
+
+#include <private/qpixmapdata_p.h>
+
+extern QPixmap cached(const QString &img);
+
+ArthurFrame::ArthurFrame(QWidget *parent)
+ : QWidget(parent)
+ , m_prefer_image(false)
+{
+#ifdef QT_OPENGL_SUPPORT
+ glw = 0;
+ m_use_opengl = false;
+ QGLFormat f = QGLFormat::defaultFormat();
+ f.setSampleBuffers(true);
+ f.setStencil(true);
+ f.setAlpha(true);
+ f.setAlphaBufferSize(8);
+ QGLFormat::setDefaultFormat(f);
+#endif
+ m_document = 0;
+ m_show_doc = false;
+
+ m_tile = QPixmap(128, 128);
+ m_tile.fill(Qt::white);
+ QPainter pt(&m_tile);
+ QColor color(230, 230, 230);
+ pt.fillRect(0, 0, 64, 64, color);
+ pt.fillRect(64, 64, 64, 64, color);
+ pt.end();
+
+// QPalette pal = palette();
+// pal.setBrush(backgroundRole(), m_tile);
+// setPalette(pal);
+
+#ifdef Q_WS_X11
+ QPixmap xRenderPixmap(1, 1);
+ m_prefer_image = xRenderPixmap.pixmapData()->classId() == QPixmapData::X11Class && !xRenderPixmap.x11PictureHandle();
+#endif
+}
+
+
+#ifdef QT_OPENGL_SUPPORT
+void ArthurFrame::enableOpenGL(bool use_opengl)
+{
+ m_use_opengl = use_opengl;
+
+ if (!glw) {
+ glw = new GLWidget(this);
+ glw->setAutoFillBackground(false);
+ glw->disableAutoBufferSwap();
+ QApplication::postEvent(this, new QResizeEvent(size(), size()));
+ }
+
+ if (use_opengl) {
+ glw->show();
+ } else {
+ glw->hide();
+ }
+
+ update();
+}
+#endif
+
+void ArthurFrame::paintEvent(QPaintEvent *e)
+{
+#ifdef Q_WS_QWS
+ static QPixmap *static_image = 0;
+#else
+ static QImage *static_image = 0;
+#endif
+ QPainter painter;
+ if (preferImage()
+#ifdef QT_OPENGL_SUPPORT
+ && !m_use_opengl
+#endif
+ ) {
+ if (!static_image || static_image->size() != size()) {
+ delete static_image;
+#ifdef Q_WS_QWS
+ static_image = new QPixmap(size());
+#else
+ static_image = new QImage(size(), QImage::Format_RGB32);
+#endif
+ }
+ painter.begin(static_image);
+
+ int o = 10;
+
+ QBrush bg = palette().brush(QPalette::Background);
+ painter.fillRect(0, 0, o, o, bg);
+ painter.fillRect(width() - o, 0, o, o, bg);
+ painter.fillRect(0, height() - o, o, o, bg);
+ painter.fillRect(width() - o, height() - o, o, o, bg);
+ } else {
+#ifdef QT_OPENGL_SUPPORT
+ if (m_use_opengl) {
+ painter.begin(glw);
+ painter.fillRect(QRectF(0, 0, glw->width(), glw->height()), palette().color(backgroundRole()));
+ } else {
+ painter.begin(this);
+ }
+#else
+ painter.begin(this);
+#endif
+ }
+
+ painter.setClipRect(e->rect());
+
+ painter.setRenderHint(QPainter::Antialiasing);
+
+ QPainterPath clipPath;
+
+ QRect r = rect();
+ qreal left = r.x() + 1;
+ qreal top = r.y() + 1;
+ qreal right = r.right();
+ qreal bottom = r.bottom();
+ qreal radius2 = 8 * 2;
+
+ clipPath.moveTo(right - radius2, top);
+ clipPath.arcTo(right - radius2, top, radius2, radius2, 90, -90);
+ clipPath.arcTo(right - radius2, bottom - radius2, radius2, radius2, 0, -90);
+ clipPath.arcTo(left, bottom - radius2, radius2, radius2, 270, -90);
+ clipPath.arcTo(left, top, radius2, radius2, 180, -90);
+ clipPath.closeSubpath();
+
+ painter.save();
+ painter.setClipPath(clipPath, Qt::IntersectClip);
+
+ painter.drawTiledPixmap(rect(), m_tile);
+
+ // client painting
+
+ paint(&painter);
+
+ painter.restore();
+
+ painter.save();
+ if (m_show_doc)
+ paintDescription(&painter);
+ painter.restore();
+
+ int level = 180;
+ painter.setPen(QPen(QColor(level, level, level), 2));
+ painter.setBrush(Qt::NoBrush);
+ painter.drawPath(clipPath);
+
+ if (preferImage()
+#ifdef QT_OPENGL_SUPPORT
+ && !m_use_opengl
+#endif
+ ) {
+ painter.end();
+ painter.begin(this);
+#ifdef Q_WS_QWS
+ painter.drawPixmap(e->rect(), *static_image, e->rect());
+#else
+ painter.drawImage(e->rect(), *static_image, e->rect());
+#endif
+ }
+
+#ifdef QT_OPENGL_SUPPORT
+ if (m_use_opengl && (inherits("PathDeformRenderer") || inherits("PathStrokeRenderer") || inherits("CompositionRenderer") || m_show_doc))
+ glw->swapBuffers();
+#endif
+}
+
+void ArthurFrame::resizeEvent(QResizeEvent *e)
+{
+#ifdef QT_OPENGL_SUPPORT
+ if (glw)
+ glw->setGeometry(0, 0, e->size().width()-1, e->size().height()-1);
+#endif
+ QWidget::resizeEvent(e);
+}
+
+void ArthurFrame::setDescriptionEnabled(bool enabled)
+{
+ if (m_show_doc != enabled) {
+ m_show_doc = enabled;
+ emit descriptionEnabledChanged(m_show_doc);
+ update();
+ }
+}
+
+void ArthurFrame::loadDescription(const QString &fileName)
+{
+ QFile textFile(fileName);
+ QString text;
+ if (!textFile.open(QFile::ReadOnly))
+ text = QString("Unable to load resource file: '%1'").arg(fileName);
+ else
+ text = textFile.readAll();
+ setDescription(text);
+}
+
+
+void ArthurFrame::setDescription(const QString &text)
+{
+ m_document = new QTextDocument(this);
+ m_document->setHtml(text);
+}
+
+void ArthurFrame::paintDescription(QPainter *painter)
+{
+ if (!m_document)
+ return;
+
+ int pageWidth = qMax(width() - 100, 100);
+ int pageHeight = qMax(height() - 100, 100);
+ if (pageWidth != m_document->pageSize().width()) {
+ m_document->setPageSize(QSize(pageWidth, pageHeight));
+ }
+
+ QRect textRect(width() / 2 - pageWidth / 2,
+ height() / 2 - pageHeight / 2,
+ pageWidth,
+ pageHeight);
+ int pad = 10;
+ QRect clearRect = textRect.adjusted(-pad, -pad, pad, pad);
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(QColor(0, 0, 0, 63));
+ int shade = 10;
+ painter->drawRect(clearRect.x() + clearRect.width() + 1,
+ clearRect.y() + shade,
+ shade,
+ clearRect.height() + 1);
+ painter->drawRect(clearRect.x() + shade,
+ clearRect.y() + clearRect.height() + 1,
+ clearRect.width() - shade + 1,
+ shade);
+
+ painter->setRenderHint(QPainter::Antialiasing, false);
+ painter->setBrush(QColor(255, 255, 255, 220));
+ painter->setPen(Qt::black);
+ painter->drawRect(clearRect);
+
+ painter->setClipRegion(textRect, Qt::IntersectClip);
+ painter->translate(textRect.topLeft());
+
+ QAbstractTextDocumentLayout::PaintContext ctx;
+
+ QLinearGradient g(0, 0, 0, textRect.height());
+ g.setColorAt(0, Qt::black);
+ g.setColorAt(0.9, Qt::black);
+ g.setColorAt(1, Qt::transparent);
+
+ QPalette pal = palette();
+ pal.setBrush(QPalette::Text, g);
+
+ ctx.palette = pal;
+ ctx.clip = QRect(0, 0, textRect.width(), textRect.height());
+ m_document->documentLayout()->draw(painter, ctx);
+}
+
+void ArthurFrame::loadSourceFile(const QString &sourceFile)
+{
+ m_sourceFileName = sourceFile;
+}
+
+void ArthurFrame::showSource()
+{
+ // Check for existing source
+ if (findChild<QTextBrowser *>())
+ return;
+
+ QString contents;
+ if (m_sourceFileName.isEmpty()) {
+ contents = QString("No source for widget: '%1'").arg(objectName());
+ } else {
+ QFile f(m_sourceFileName);
+ if (!f.open(QFile::ReadOnly))
+ contents = QString("Could not open file: '%1'").arg(m_sourceFileName);
+ else
+ contents = f.readAll();
+ }
+
+ contents.replace('&', "&amp;");
+ contents.replace('<', "&lt;");
+ contents.replace('>', "&gt;");
+
+ QStringList keywords;
+ keywords << "for " << "if " << "switch " << " int " << "#include " << "const"
+ << "void " << "uint " << "case " << "double " << "#define " << "static"
+ << "new" << "this";
+
+ foreach (QString keyword, keywords)
+ contents.replace(keyword, QLatin1String("<font color=olive>") + keyword + QLatin1String("</font>"));
+ contents.replace("(int ", "(<font color=olive><b>int </b></font>");
+
+ QStringList ppKeywords;
+ ppKeywords << "#ifdef" << "#ifndef" << "#if" << "#endif" << "#else";
+
+ foreach (QString keyword, ppKeywords)
+ contents.replace(keyword, QLatin1String("<font color=navy>") + keyword + QLatin1String("</font>"));
+
+ contents.replace(QRegExp("(\\d\\d?)"), QLatin1String("<font color=navy>\\1</font>"));
+
+ QRegExp commentRe("(//.+)\\n");
+ commentRe.setMinimal(true);
+ contents.replace(commentRe, QLatin1String("<font color=red>\\1</font>\n"));
+
+ QRegExp stringLiteralRe("(\".+\")");
+ stringLiteralRe.setMinimal(true);
+ contents.replace(stringLiteralRe, QLatin1String("<font color=green>\\1</font>"));
+
+ QString html = contents;
+ html.prepend("<html><pre>");
+ html.append("</pre></html>");
+
+ QTextBrowser *sourceViewer = new QTextBrowser(0);
+ sourceViewer->setWindowTitle("Source: " + m_sourceFileName.mid(5));
+ sourceViewer->setParent(this, Qt::Dialog);
+ sourceViewer->setAttribute(Qt::WA_DeleteOnClose);
+ sourceViewer->setLineWrapMode(QTextEdit::NoWrap);
+ sourceViewer->setHtml(html);
+ sourceViewer->resize(600, 600);
+ sourceViewer->show();
+}
diff --git a/examples/painting/shared/arthurwidgets.h b/examples/painting/shared/arthurwidgets.h
new file mode 100644
index 0000000000..dc8f92505d
--- /dev/null
+++ b/examples/painting/shared/arthurwidgets.h
@@ -0,0 +1,137 @@
+/****************************************************************************
+**
+** 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 demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ARTHURWIDGETS_H
+#define ARTHURWIDGETS_H
+
+#include "arthurstyle.h"
+#include <QBitmap>
+#include <QPushButton>
+#include <QGroupBox>
+
+#if defined(QT_OPENGL_SUPPORT)
+#include <QGLWidget>
+#include <QEvent>
+class GLWidget : public QGLWidget
+{
+public:
+ GLWidget(QWidget *parent)
+ : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
+ {
+ setAttribute(Qt::WA_AcceptTouchEvents);
+ }
+ void disableAutoBufferSwap() { setAutoBufferSwap(false); }
+ void paintEvent(QPaintEvent *) { parentWidget()->update(); }
+protected:
+ bool event(QEvent *event)
+ {
+ switch (event->type()) {
+ case QEvent::TouchBegin:
+ case QEvent::TouchUpdate:
+ case QEvent::TouchEnd:
+ event->ignore();
+ return false;
+ break;
+ default:
+ break;
+ }
+ return QGLWidget::event(event);
+ }
+};
+#endif
+
+QT_FORWARD_DECLARE_CLASS(QTextDocument)
+QT_FORWARD_DECLARE_CLASS(QTextEdit)
+QT_FORWARD_DECLARE_CLASS(QVBoxLayout)
+
+class ArthurFrame : public QWidget
+{
+ Q_OBJECT
+public:
+ ArthurFrame(QWidget *parent);
+ virtual void paint(QPainter *) {}
+
+
+ void paintDescription(QPainter *p);
+
+ void loadDescription(const QString &filename);
+ void setDescription(const QString &htmlDesc);
+
+ void loadSourceFile(const QString &fileName);
+
+ bool preferImage() const { return m_prefer_image; }
+
+#if defined(QT_OPENGL_SUPPORT)
+ QGLWidget *glWidget() const { return glw; }
+#endif
+
+public slots:
+ void setPreferImage(bool pi) { m_prefer_image = pi; }
+ void setDescriptionEnabled(bool enabled);
+ void showSource();
+
+#if defined(QT_OPENGL_SUPPORT)
+ void enableOpenGL(bool use_opengl);
+ bool usesOpenGL() { return m_use_opengl; }
+#endif
+
+signals:
+ void descriptionEnabledChanged(bool);
+
+protected:
+ void paintEvent(QPaintEvent *);
+ void resizeEvent(QResizeEvent *);
+
+#if defined(QT_OPENGL_SUPPORT)
+ GLWidget *glw;
+ bool m_use_opengl;
+#endif
+ QPixmap m_tile;
+
+ bool m_show_doc;
+ bool m_prefer_image;
+ QTextDocument *m_document;
+
+ QString m_sourceFileName;
+
+};
+
+#endif
diff --git a/examples/painting/shared/hoverpoints.cpp b/examples/painting/shared/hoverpoints.cpp
new file mode 100644
index 0000000000..36c24186d3
--- /dev/null
+++ b/examples/painting/shared/hoverpoints.cpp
@@ -0,0 +1,415 @@
+/****************************************************************************
+**
+** 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 demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifdef QT_OPENGL_SUPPORT
+#include <QGLWidget>
+#endif
+
+#include "arthurwidgets.h"
+#include "hoverpoints.h"
+
+#define printf
+
+HoverPoints::HoverPoints(QWidget *widget, PointShape shape)
+ : QObject(widget)
+{
+ m_widget = widget;
+ widget->installEventFilter(this);
+ widget->setAttribute(Qt::WA_AcceptTouchEvents);
+
+ m_connectionType = CurveConnection;
+ m_sortType = NoSort;
+ m_shape = shape;
+ m_pointPen = QPen(QColor(255, 255, 255, 191), 1);
+ m_connectionPen = QPen(QColor(255, 255, 255, 127), 2);
+ m_pointBrush = QBrush(QColor(191, 191, 191, 127));
+ m_pointSize = QSize(11, 11);
+ m_currentIndex = -1;
+ m_editable = true;
+ m_enabled = true;
+
+ connect(this, SIGNAL(pointsChanged(QPolygonF)),
+ m_widget, SLOT(update()));
+}
+
+
+void HoverPoints::setEnabled(bool enabled)
+{
+ if (m_enabled != enabled) {
+ m_enabled = enabled;
+ m_widget->update();
+ }
+}
+
+
+bool HoverPoints::eventFilter(QObject *object, QEvent *event)
+{
+ if (object == m_widget && m_enabled) {
+ switch (event->type()) {
+
+ case QEvent::MouseButtonPress:
+ {
+ if (!m_fingerPointMapping.isEmpty())
+ return true;
+ QMouseEvent *me = (QMouseEvent *) event;
+
+ QPointF clickPos = me->pos();
+ int index = -1;
+ for (int i=0; i<m_points.size(); ++i) {
+ QPainterPath path;
+ if (m_shape == CircleShape)
+ path.addEllipse(pointBoundingRect(i));
+ else
+ path.addRect(pointBoundingRect(i));
+
+ if (path.contains(clickPos)) {
+ index = i;
+ break;
+ }
+ }
+
+ if (me->button() == Qt::LeftButton) {
+ if (index == -1) {
+ if (!m_editable)
+ return false;
+ int pos = 0;
+ // Insert sort for x or y
+ if (m_sortType == XSort) {
+ for (int i=0; i<m_points.size(); ++i)
+ if (m_points.at(i).x() > clickPos.x()) {
+ pos = i;
+ break;
+ }
+ } else if (m_sortType == YSort) {
+ for (int i=0; i<m_points.size(); ++i)
+ if (m_points.at(i).y() > clickPos.y()) {
+ pos = i;
+ break;
+ }
+ }
+
+ m_points.insert(pos, clickPos);
+ m_locks.insert(pos, 0);
+ m_currentIndex = pos;
+ firePointChange();
+ } else {
+ m_currentIndex = index;
+ }
+ return true;
+
+ } else if (me->button() == Qt::RightButton) {
+ if (index >= 0 && m_editable) {
+ if (m_locks[index] == 0) {
+ m_locks.remove(index);
+ m_points.remove(index);
+ }
+ firePointChange();
+ return true;
+ }
+ }
+
+ }
+ break;
+
+ case QEvent::MouseButtonRelease:
+ if (!m_fingerPointMapping.isEmpty())
+ return true;
+ m_currentIndex = -1;
+ break;
+
+ case QEvent::MouseMove:
+ if (!m_fingerPointMapping.isEmpty())
+ return true;
+ if (m_currentIndex >= 0)
+ movePoint(m_currentIndex, ((QMouseEvent *)event)->pos());
+ break;
+ case QEvent::TouchBegin:
+ case QEvent::TouchUpdate:
+ {
+ const QTouchEvent *const touchEvent = static_cast<const QTouchEvent*>(event);
+ const QList<QTouchEvent::TouchPoint> points = touchEvent->touchPoints();
+ const qreal pointSize = qMax(m_pointSize.width(), m_pointSize.height());
+ foreach (const QTouchEvent::TouchPoint &touchPoint, points) {
+ const int id = touchPoint.id();
+ switch (touchPoint.state()) {
+ case Qt::TouchPointPressed:
+ {
+ // find the point, move it
+ QSet<int> activePoints = QSet<int>::fromList(m_fingerPointMapping.values());
+ int activePoint = -1;
+ qreal distance = -1;
+ const int pointsCount = m_points.size();
+ const int activePointCount = activePoints.size();
+ if (pointsCount == 2 && activePointCount == 1) { // only two points
+ activePoint = activePoints.contains(0) ? 1 : 0;
+ } else {
+ for (int i=0; i<pointsCount; ++i) {
+ if (activePoints.contains(i))
+ continue;
+
+ qreal d = QLineF(touchPoint.pos(), m_points.at(i)).length();
+ if ((distance < 0 && d < 12 * pointSize) || d < distance) {
+ distance = d;
+ activePoint = i;
+ }
+
+ }
+ }
+ if (activePoint != -1) {
+ m_fingerPointMapping.insert(touchPoint.id(), activePoint);
+ movePoint(activePoint, touchPoint.pos());
+ }
+ }
+ break;
+ case Qt::TouchPointReleased:
+ {
+ // move the point and release
+ QHash<int,int>::iterator it = m_fingerPointMapping.find(id);
+ movePoint(it.value(), touchPoint.pos());
+ m_fingerPointMapping.erase(it);
+ }
+ break;
+ case Qt::TouchPointMoved:
+ {
+ // move the point
+ const int pointIdx = m_fingerPointMapping.value(id, -1);
+ if (pointIdx >= 0) // do we track this point?
+ movePoint(pointIdx, touchPoint.pos());
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ if (m_fingerPointMapping.isEmpty()) {
+ event->ignore();
+ return false;
+ } else {
+ return true;
+ }
+ }
+ break;
+ case QEvent::TouchEnd:
+ if (m_fingerPointMapping.isEmpty()) {
+ event->ignore();
+ return false;
+ }
+ return true;
+ break;
+
+ case QEvent::Resize:
+ {
+ QResizeEvent *e = (QResizeEvent *) event;
+ if (e->oldSize().width() == 0 || e->oldSize().height() == 0)
+ break;
+ qreal stretch_x = e->size().width() / qreal(e->oldSize().width());
+ qreal stretch_y = e->size().height() / qreal(e->oldSize().height());
+ for (int i=0; i<m_points.size(); ++i) {
+ QPointF p = m_points[i];
+ movePoint(i, QPointF(p.x() * stretch_x, p.y() * stretch_y), false);
+ }
+
+ firePointChange();
+ break;
+ }
+
+ case QEvent::Paint:
+ {
+ QWidget *that_widget = m_widget;
+ m_widget = 0;
+ QApplication::sendEvent(object, event);
+ m_widget = that_widget;
+ paintPoints();
+#ifdef QT_OPENGL_SUPPORT
+ ArthurFrame *af = qobject_cast<ArthurFrame *>(that_widget);
+ if (af && af->usesOpenGL())
+ af->glWidget()->swapBuffers();
+#endif
+ return true;
+ }
+ default:
+ break;
+ }
+ }
+
+ return false;
+}
+
+
+void HoverPoints::paintPoints()
+{
+ QPainter p;
+#ifdef QT_OPENGL_SUPPORT
+ ArthurFrame *af = qobject_cast<ArthurFrame *>(m_widget);
+ if (af && af->usesOpenGL())
+ p.begin(af->glWidget());
+ else
+ p.begin(m_widget);
+#else
+ p.begin(m_widget);
+#endif
+
+ p.setRenderHint(QPainter::Antialiasing);
+
+ if (m_connectionPen.style() != Qt::NoPen && m_connectionType != NoConnection) {
+ p.setPen(m_connectionPen);
+
+ if (m_connectionType == CurveConnection) {
+ QPainterPath path;
+ path.moveTo(m_points.at(0));
+ for (int i=1; i<m_points.size(); ++i) {
+ QPointF p1 = m_points.at(i-1);
+ QPointF p2 = m_points.at(i);
+ qreal distance = p2.x() - p1.x();
+
+ path.cubicTo(p1.x() + distance / 2, p1.y(),
+ p1.x() + distance / 2, p2.y(),
+ p2.x(), p2.y());
+ }
+ p.drawPath(path);
+ } else {
+ p.drawPolyline(m_points);
+ }
+ }
+
+ p.setPen(m_pointPen);
+ p.setBrush(m_pointBrush);
+
+ for (int i=0; i<m_points.size(); ++i) {
+ QRectF bounds = pointBoundingRect(i);
+ if (m_shape == CircleShape)
+ p.drawEllipse(bounds);
+ else
+ p.drawRect(bounds);
+ }
+}
+
+static QPointF bound_point(const QPointF &point, const QRectF &bounds, int lock)
+{
+ QPointF p = point;
+
+ qreal left = bounds.left();
+ qreal right = bounds.right();
+ qreal top = bounds.top();
+ qreal bottom = bounds.bottom();
+
+ if (p.x() < left || (lock & HoverPoints::LockToLeft)) p.setX(left);
+ else if (p.x() > right || (lock & HoverPoints::LockToRight)) p.setX(right);
+
+ if (p.y() < top || (lock & HoverPoints::LockToTop)) p.setY(top);
+ else if (p.y() > bottom || (lock & HoverPoints::LockToBottom)) p.setY(bottom);
+
+ return p;
+}
+
+void HoverPoints::setPoints(const QPolygonF &points)
+{
+ if (points.size() != m_points.size())
+ m_fingerPointMapping.clear();
+ m_points.clear();
+ for (int i=0; i<points.size(); ++i)
+ m_points << bound_point(points.at(i), boundingRect(), 0);
+
+ m_locks.clear();
+ if (m_points.size() > 0) {
+ m_locks.resize(m_points.size());
+
+ m_locks.fill(0);
+ }
+}
+
+
+void HoverPoints::movePoint(int index, const QPointF &point, bool emitUpdate)
+{
+ m_points[index] = bound_point(point, boundingRect(), m_locks.at(index));
+ if (emitUpdate)
+ firePointChange();
+}
+
+
+inline static bool x_less_than(const QPointF &p1, const QPointF &p2)
+{
+ return p1.x() < p2.x();
+}
+
+
+inline static bool y_less_than(const QPointF &p1, const QPointF &p2)
+{
+ return p1.y() < p2.y();
+}
+
+void HoverPoints::firePointChange()
+{
+// printf("HoverPoints::firePointChange(), current=%d\n", m_currentIndex);
+
+ if (m_sortType != NoSort) {
+
+ QPointF oldCurrent;
+ if (m_currentIndex != -1) {
+ oldCurrent = m_points[m_currentIndex];
+ }
+
+ if (m_sortType == XSort)
+ qSort(m_points.begin(), m_points.end(), x_less_than);
+ else if (m_sortType == YSort)
+ qSort(m_points.begin(), m_points.end(), y_less_than);
+
+ // Compensate for changed order...
+ if (m_currentIndex != -1) {
+ for (int i=0; i<m_points.size(); ++i) {
+ if (m_points[i] == oldCurrent) {
+ m_currentIndex = i;
+ break;
+ }
+ }
+ }
+
+// printf(" - firePointChange(), current=%d\n", m_currentIndex);
+
+ }
+
+// for (int i=0; i<m_points.size(); ++i) {
+// printf(" - point(%2d)=[%.2f, %.2f], lock=%d\n",
+// i, m_points.at(i).x(), m_points.at(i).y(), m_locks.at(i));
+// }
+
+ emit pointsChanged(m_points);
+}
diff --git a/examples/painting/shared/hoverpoints.h b/examples/painting/shared/hoverpoints.h
new file mode 100644
index 0000000000..aff5d2ac75
--- /dev/null
+++ b/examples/painting/shared/hoverpoints.h
@@ -0,0 +1,162 @@
+/****************************************************************************
+**
+** 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 demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef HOVERPOINTS_H
+#define HOVERPOINTS_H
+
+#include <QtGui>
+
+QT_FORWARD_DECLARE_CLASS(QBypassWidget)
+
+class HoverPoints : public QObject
+{
+ Q_OBJECT
+public:
+ enum PointShape {
+ CircleShape,
+ RectangleShape
+ };
+
+ enum LockType {
+ LockToLeft = 0x01,
+ LockToRight = 0x02,
+ LockToTop = 0x04,
+ LockToBottom = 0x08
+ };
+
+ enum SortType {
+ NoSort,
+ XSort,
+ YSort
+ };
+
+ enum ConnectionType {
+ NoConnection,
+ LineConnection,
+ CurveConnection
+ };
+
+ HoverPoints(QWidget *widget, PointShape shape);
+
+ bool eventFilter(QObject *object, QEvent *event);
+
+ void paintPoints();
+
+ inline QRectF boundingRect() const;
+ void setBoundingRect(const QRectF &boundingRect) { m_bounds = boundingRect; }
+
+ QPolygonF points() const { return m_points; }
+ void setPoints(const QPolygonF &points);
+
+ QSizeF pointSize() const { return m_pointSize; }
+ void setPointSize(const QSizeF &size) { m_pointSize = size; }
+
+ SortType sortType() const { return m_sortType; }
+ void setSortType(SortType sortType) { m_sortType = sortType; }
+
+ ConnectionType connectionType() const { return m_connectionType; }
+ void setConnectionType(ConnectionType connectionType) { m_connectionType = connectionType; }
+
+ void setConnectionPen(const QPen &pen) { m_connectionPen = pen; }
+ void setShapePen(const QPen &pen) { m_pointPen = pen; }
+ void setShapeBrush(const QBrush &brush) { m_pointBrush = brush; }
+
+ void setPointLock(int pos, LockType lock) { m_locks[pos] = lock; }
+
+ void setEditable(bool editable) { m_editable = editable; }
+ bool editable() const { return m_editable; }
+
+public slots:
+ void setEnabled(bool enabled);
+ void setDisabled(bool disabled) { setEnabled(!disabled); }
+
+signals:
+ void pointsChanged(const QPolygonF &points);
+
+public:
+ void firePointChange();
+
+private:
+ inline QRectF pointBoundingRect(int i) const;
+ void movePoint(int i, const QPointF &newPos, bool emitChange = true);
+
+ QWidget *m_widget;
+
+ QPolygonF m_points;
+ QRectF m_bounds;
+ PointShape m_shape;
+ SortType m_sortType;
+ ConnectionType m_connectionType;
+
+ QVector<uint> m_locks;
+
+ QSizeF m_pointSize;
+ int m_currentIndex;
+ bool m_editable;
+ bool m_enabled;
+
+ QHash<int, int> m_fingerPointMapping;
+
+ QPen m_pointPen;
+ QBrush m_pointBrush;
+ QPen m_connectionPen;
+};
+
+
+inline QRectF HoverPoints::pointBoundingRect(int i) const
+{
+ QPointF p = m_points.at(i);
+ qreal w = m_pointSize.width();
+ qreal h = m_pointSize.height();
+ qreal x = p.x() - w / 2;
+ qreal y = p.y() - h / 2;
+ return QRectF(x, y, w, h);
+}
+
+inline QRectF HoverPoints::boundingRect() const
+{
+ if (m_bounds.isEmpty())
+ return m_widget->rect();
+ else
+ return m_bounds;
+}
+
+#endif // HOVERPOINTS_H
diff --git a/examples/painting/shared/images/bg_pattern.png b/examples/painting/shared/images/bg_pattern.png
new file mode 100644
index 0000000000..ee670266f0
--- /dev/null
+++ b/examples/painting/shared/images/bg_pattern.png
Binary files differ
diff --git a/examples/painting/shared/images/button_normal_cap_left.png b/examples/painting/shared/images/button_normal_cap_left.png
new file mode 100644
index 0000000000..db31dd971d
--- /dev/null
+++ b/examples/painting/shared/images/button_normal_cap_left.png
Binary files differ
diff --git a/examples/painting/shared/images/button_normal_cap_right.png b/examples/painting/shared/images/button_normal_cap_right.png
new file mode 100644
index 0000000000..38ead1c719
--- /dev/null
+++ b/examples/painting/shared/images/button_normal_cap_right.png
Binary files differ
diff --git a/examples/painting/shared/images/button_normal_stretch.png b/examples/painting/shared/images/button_normal_stretch.png
new file mode 100644
index 0000000000..87abe67ac9
--- /dev/null
+++ b/examples/painting/shared/images/button_normal_stretch.png
Binary files differ
diff --git a/examples/painting/shared/images/button_pressed_cap_left.png b/examples/painting/shared/images/button_pressed_cap_left.png
new file mode 100644
index 0000000000..66bfc13cb4
--- /dev/null
+++ b/examples/painting/shared/images/button_pressed_cap_left.png
Binary files differ
diff --git a/examples/painting/shared/images/button_pressed_cap_right.png b/examples/painting/shared/images/button_pressed_cap_right.png
new file mode 100644
index 0000000000..3d4cfe25b1
--- /dev/null
+++ b/examples/painting/shared/images/button_pressed_cap_right.png
Binary files differ
diff --git a/examples/painting/shared/images/button_pressed_stretch.png b/examples/painting/shared/images/button_pressed_stretch.png
new file mode 100644
index 0000000000..4dd4ad11e6
--- /dev/null
+++ b/examples/painting/shared/images/button_pressed_stretch.png
Binary files differ
diff --git a/examples/painting/shared/images/curve_thing_edit-6.png b/examples/painting/shared/images/curve_thing_edit-6.png
new file mode 100644
index 0000000000..034b474d02
--- /dev/null
+++ b/examples/painting/shared/images/curve_thing_edit-6.png
Binary files differ
diff --git a/examples/painting/shared/images/frame_bottom.png b/examples/painting/shared/images/frame_bottom.png
new file mode 100644
index 0000000000..889b40d304
--- /dev/null
+++ b/examples/painting/shared/images/frame_bottom.png
Binary files differ
diff --git a/examples/painting/shared/images/frame_bottomleft.png b/examples/painting/shared/images/frame_bottomleft.png
new file mode 100644
index 0000000000..0b3023f397
--- /dev/null
+++ b/examples/painting/shared/images/frame_bottomleft.png
Binary files differ
diff --git a/examples/painting/shared/images/frame_bottomright.png b/examples/painting/shared/images/frame_bottomright.png
new file mode 100644
index 0000000000..0021e35864
--- /dev/null
+++ b/examples/painting/shared/images/frame_bottomright.png
Binary files differ
diff --git a/examples/painting/shared/images/frame_left.png b/examples/painting/shared/images/frame_left.png
new file mode 100644
index 0000000000..40f331c293
--- /dev/null
+++ b/examples/painting/shared/images/frame_left.png
Binary files differ
diff --git a/examples/painting/shared/images/frame_right.png b/examples/painting/shared/images/frame_right.png
new file mode 100644
index 0000000000..023af8c700
--- /dev/null
+++ b/examples/painting/shared/images/frame_right.png
Binary files differ
diff --git a/examples/painting/shared/images/frame_top.png b/examples/painting/shared/images/frame_top.png
new file mode 100644
index 0000000000..001f3a7144
--- /dev/null
+++ b/examples/painting/shared/images/frame_top.png
Binary files differ
diff --git a/examples/painting/shared/images/frame_topleft.png b/examples/painting/shared/images/frame_topleft.png
new file mode 100644
index 0000000000..58c68d407a
--- /dev/null
+++ b/examples/painting/shared/images/frame_topleft.png
Binary files differ
diff --git a/examples/painting/shared/images/frame_topright.png b/examples/painting/shared/images/frame_topright.png
new file mode 100644
index 0000000000..6a7e8d3eb3
--- /dev/null
+++ b/examples/painting/shared/images/frame_topright.png
Binary files differ
diff --git a/examples/painting/shared/images/groupframe_bottom_left.png b/examples/painting/shared/images/groupframe_bottom_left.png
new file mode 100644
index 0000000000..af2fe061e3
--- /dev/null
+++ b/examples/painting/shared/images/groupframe_bottom_left.png
Binary files differ
diff --git a/examples/painting/shared/images/groupframe_bottom_right.png b/examples/painting/shared/images/groupframe_bottom_right.png
new file mode 100644
index 0000000000..fdf2e97b13
--- /dev/null
+++ b/examples/painting/shared/images/groupframe_bottom_right.png
Binary files differ
diff --git a/examples/painting/shared/images/groupframe_bottom_stretch.png b/examples/painting/shared/images/groupframe_bottom_stretch.png
new file mode 100644
index 0000000000..f47b67d7c0
--- /dev/null
+++ b/examples/painting/shared/images/groupframe_bottom_stretch.png
Binary files differ
diff --git a/examples/painting/shared/images/groupframe_left_stretch.png b/examples/painting/shared/images/groupframe_left_stretch.png
new file mode 100644
index 0000000000..c122f462ed
--- /dev/null
+++ b/examples/painting/shared/images/groupframe_left_stretch.png
Binary files differ
diff --git a/examples/painting/shared/images/groupframe_right_stretch.png b/examples/painting/shared/images/groupframe_right_stretch.png
new file mode 100644
index 0000000000..1056b7812a
--- /dev/null
+++ b/examples/painting/shared/images/groupframe_right_stretch.png
Binary files differ
diff --git a/examples/painting/shared/images/groupframe_top_stretch.png b/examples/painting/shared/images/groupframe_top_stretch.png
new file mode 100644
index 0000000000..5746ef96fc
--- /dev/null
+++ b/examples/painting/shared/images/groupframe_top_stretch.png
Binary files differ
diff --git a/examples/painting/shared/images/groupframe_topleft.png b/examples/painting/shared/images/groupframe_topleft.png
new file mode 100644
index 0000000000..98d9cd96b4
--- /dev/null
+++ b/examples/painting/shared/images/groupframe_topleft.png
Binary files differ
diff --git a/examples/painting/shared/images/groupframe_topright.png b/examples/painting/shared/images/groupframe_topright.png
new file mode 100644
index 0000000000..1a0a328c20
--- /dev/null
+++ b/examples/painting/shared/images/groupframe_topright.png
Binary files differ
diff --git a/examples/painting/shared/images/line_dash_dot.png b/examples/painting/shared/images/line_dash_dot.png
new file mode 100644
index 0000000000..1c61442d9f
--- /dev/null
+++ b/examples/painting/shared/images/line_dash_dot.png
Binary files differ
diff --git a/examples/painting/shared/images/line_dash_dot_dot.png b/examples/painting/shared/images/line_dash_dot_dot.png
new file mode 100644
index 0000000000..0d9bb972f9
--- /dev/null
+++ b/examples/painting/shared/images/line_dash_dot_dot.png
Binary files differ
diff --git a/examples/painting/shared/images/line_dashed.png b/examples/painting/shared/images/line_dashed.png
new file mode 100644
index 0000000000..d5bc7ea5fe
--- /dev/null
+++ b/examples/painting/shared/images/line_dashed.png
Binary files differ
diff --git a/examples/painting/shared/images/line_dotted.png b/examples/painting/shared/images/line_dotted.png
new file mode 100644
index 0000000000..a2f9a35925
--- /dev/null
+++ b/examples/painting/shared/images/line_dotted.png
Binary files differ
diff --git a/examples/painting/shared/images/line_solid.png b/examples/painting/shared/images/line_solid.png
new file mode 100644
index 0000000000..60ef3f9485
--- /dev/null
+++ b/examples/painting/shared/images/line_solid.png
Binary files differ
diff --git a/examples/painting/shared/images/radiobutton-off.png b/examples/painting/shared/images/radiobutton-off.png
new file mode 100644
index 0000000000..af1753a3e7
--- /dev/null
+++ b/examples/painting/shared/images/radiobutton-off.png
Binary files differ
diff --git a/examples/painting/shared/images/radiobutton-on.png b/examples/painting/shared/images/radiobutton-on.png
new file mode 100644
index 0000000000..f875838bb5
--- /dev/null
+++ b/examples/painting/shared/images/radiobutton-on.png
Binary files differ
diff --git a/examples/painting/shared/images/radiobutton_off.png b/examples/painting/shared/images/radiobutton_off.png
new file mode 100644
index 0000000000..400906ebfa
--- /dev/null
+++ b/examples/painting/shared/images/radiobutton_off.png
Binary files differ
diff --git a/examples/painting/shared/images/radiobutton_on.png b/examples/painting/shared/images/radiobutton_on.png
new file mode 100644
index 0000000000..50a049ec56
--- /dev/null
+++ b/examples/painting/shared/images/radiobutton_on.png
Binary files differ
diff --git a/examples/painting/shared/images/slider_bar.png b/examples/painting/shared/images/slider_bar.png
new file mode 100644
index 0000000000..1b3d62c007
--- /dev/null
+++ b/examples/painting/shared/images/slider_bar.png
Binary files differ
diff --git a/examples/painting/shared/images/slider_thumb_off.png b/examples/painting/shared/images/slider_thumb_off.png
new file mode 100644
index 0000000000..d7f141daef
--- /dev/null
+++ b/examples/painting/shared/images/slider_thumb_off.png
Binary files differ
diff --git a/examples/painting/shared/images/slider_thumb_on.png b/examples/painting/shared/images/slider_thumb_on.png
new file mode 100644
index 0000000000..8e1f510813
--- /dev/null
+++ b/examples/painting/shared/images/slider_thumb_on.png
Binary files differ
diff --git a/examples/painting/shared/images/title_cap_left.png b/examples/painting/shared/images/title_cap_left.png
new file mode 100644
index 0000000000..2d475070c8
--- /dev/null
+++ b/examples/painting/shared/images/title_cap_left.png
Binary files differ
diff --git a/examples/painting/shared/images/title_cap_right.png b/examples/painting/shared/images/title_cap_right.png
new file mode 100644
index 0000000000..dc3ff8536c
--- /dev/null
+++ b/examples/painting/shared/images/title_cap_right.png
Binary files differ
diff --git a/examples/painting/shared/images/title_stretch.png b/examples/painting/shared/images/title_stretch.png
new file mode 100644
index 0000000000..11043345d0
--- /dev/null
+++ b/examples/painting/shared/images/title_stretch.png
Binary files differ
diff --git a/examples/painting/shared/shared.pri b/examples/painting/shared/shared.pri
new file mode 100644
index 0000000000..fb7b04c0be
--- /dev/null
+++ b/examples/painting/shared/shared.pri
@@ -0,0 +1,21 @@
+INCLUDEPATH += $$SHARED_FOLDER
+
+build_all:!build_pass {
+ CONFIG -= build_all
+ CONFIG += release
+}
+contains(CONFIG, debug_and_release_target) {
+ CONFIG(debug, debug|release) {
+ QMAKE_LIBDIR += $$SHARED_FOLDER/debug
+ } else {
+ QMAKE_LIBDIR += $$SHARED_FOLDER/release
+ }
+} else {
+ QMAKE_LIBDIR += $$SHARED_FOLDER
+}
+
+hpux-acc*:LIBS += $$SHARED_FOLDER/libdemo_shared.a
+hpuxi-acc*:LIBS += $$SHARED_FOLDER/libdemo_shared.a
+symbian:LIBS += -ldemo_shared.lib
+!hpuxi-acc*:!hpux-acc*:!symbian:LIBS += -ldemo_shared
+
diff --git a/examples/painting/shared/shared.pro b/examples/painting/shared/shared.pro
new file mode 100644
index 0000000000..88d7fbedab
--- /dev/null
+++ b/examples/painting/shared/shared.pro
@@ -0,0 +1,39 @@
+TEMPLATE = lib
+CONFIG += static
+
+contains(QT_CONFIG, opengl)|contains(QT_CONFIG, opengles1)|contains(QT_CONFIG, opengles2) {
+ DEFINES += QT_OPENGL_SUPPORT
+ QT += opengl
+}
+
+build_all:!build_pass {
+ CONFIG -= build_all
+ CONFIG += release
+}
+TARGET = demo_shared
+QT += gui-private
+
+SOURCES += \
+ arthurstyle.cpp\
+ arthurwidgets.cpp \
+ hoverpoints.cpp
+
+HEADERS += \
+ arthurstyle.h \
+ arthurwidgets.h \
+ hoverpoints.h
+
+RESOURCES += shared.qrc
+
+# install
+target.path = $$[QT_INSTALL_DEMOS]/qtbase/shared
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.pri images
+sources.path = $$[QT_INSTALL_DEMOS]/qtbase/shared
+INSTALLS += sources
+
+!cross_compile:INSTALLS += target
+
+symbian {
+ TARGET.UID3 = 0xA000A63C
+ CONFIG += qt_demo
+}
diff --git a/examples/painting/shared/shared.qrc b/examples/painting/shared/shared.qrc
new file mode 100644
index 0000000000..17336ecf80
--- /dev/null
+++ b/examples/painting/shared/shared.qrc
@@ -0,0 +1,39 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/res">
+ <file>images/button_normal_cap_left.png</file>
+ <file>images/button_normal_cap_right.png</file>
+ <file>images/button_normal_stretch.png</file>
+ <file>images/button_pressed_cap_left.png</file>
+ <file>images/button_pressed_cap_right.png</file>
+ <file>images/button_pressed_stretch.png</file>
+ <file>images/radiobutton-on.png</file>
+ <file>images/radiobutton_on.png</file>
+ <file>images/radiobutton_off.png</file>
+ <file>images/slider_bar.png</file>
+ <file>images/slider_thumb_on.png</file>
+ <file>images/groupframe_topleft.png</file>
+ <file>images/groupframe_topright.png</file>
+ <file>images/groupframe_bottom_left.png</file>
+ <file>images/groupframe_bottom_right.png</file>
+ <file>images/groupframe_top_stretch.png</file>
+ <file>images/groupframe_bottom_stretch.png</file>
+ <file>images/groupframe_left_stretch.png</file>
+ <file>images/groupframe_right_stretch.png</file>
+ <file>images/frame_topleft.png</file>
+ <file>images/frame_topright.png</file>
+ <file>images/frame_bottomleft.png</file>
+ <file>images/frame_bottomright.png</file>
+ <file>images/frame_left.png</file>
+ <file>images/frame_top.png</file>
+ <file>images/frame_right.png</file>
+ <file>images/frame_bottom.png</file>
+ <file>images/title_cap_left.png</file>
+ <file>images/title_cap_right.png</file>
+ <file>images/title_stretch.png</file>
+ <file>images/line_dash_dot.png</file>
+ <file>images/line_dotted.png</file>
+ <file>images/line_dashed.png</file>
+ <file>images/line_solid.png</file>
+ <file>images/line_dash_dot_dot.png</file>
+</qresource>
+</RCC>