diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2009-03-23 09:34:13 (GMT) |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2009-03-23 09:34:13 (GMT) |
commit | 67ad0519fd165acee4a4d2a94fa502e9e4847bd0 (patch) | |
tree | 1dbf50b3dff8d5ca7e9344733968c72704eb15ff /examples/painting/svgviewer | |
download | Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.zip Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.tar.gz Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.tar.bz2 |
Long live Qt!
Diffstat (limited to 'examples/painting/svgviewer')
-rw-r--r-- | examples/painting/svgviewer/files/bubbles.svg | 215 | ||||
-rw-r--r-- | examples/painting/svgviewer/files/cubic.svg | 77 | ||||
-rw-r--r-- | examples/painting/svgviewer/files/spheres.svg | 72 | ||||
-rw-r--r-- | examples/painting/svgviewer/main.cpp | 63 | ||||
-rw-r--r-- | examples/painting/svgviewer/mainwindow.cpp | 164 | ||||
-rw-r--r-- | examples/painting/svgviewer/mainwindow.h | 81 | ||||
-rw-r--r-- | examples/painting/svgviewer/svgview.cpp | 188 | ||||
-rw-r--r-- | examples/painting/svgviewer/svgview.h | 84 | ||||
-rw-r--r-- | examples/painting/svgviewer/svgviewer.pro | 23 | ||||
-rw-r--r-- | examples/painting/svgviewer/svgviewer.qrc | 6 |
10 files changed, 973 insertions, 0 deletions
diff --git a/examples/painting/svgviewer/files/bubbles.svg b/examples/painting/svgviewer/files/bubbles.svg new file mode 100644 index 0000000..65867da --- /dev/null +++ b/examples/painting/svgviewer/files/bubbles.svg @@ -0,0 +1,215 @@ +<?xml version="1.0" standalone="no"?> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> +<svg width="20cm" height="15cm" viewBox="0 0 800 600" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink/" + baseProfile="tiny" version="1.2"> + <title>Spheres</title> + <desc>Semi-transparent bubbles on a colored background.</desc> + <defs> + <!-- Create radial gradients for each bubble. --> + <radialGradient id="blueBubble" gradientUnits="userSpaceOnUse" + cx="0" cy="0" r="100" fx="-50" fy="-50"> + <stop offset="0%" stop-color="white" stop-opacity="1" /> + <stop offset="25%" stop-color="#cdcdff" stop-opacity=".65" /> + <stop offset="100%" stop-color="#cdaacd" stop-opacity=".75" /> + </radialGradient> + <radialGradient id="redBubble" gradientUnits="userSpaceOnUse" + cx="0" cy="0" r="100" fx="-50" fy="-50"> + <stop offset="0%" stop-color="white" stop-opacity="1" /> + <stop offset="25%" stop-color="#ffcdcd" stop-opacity=".65" /> + <stop offset="100%" stop-color="#bbbb99" stop-opacity=".75" /> + </radialGradient> + <radialGradient id="greenBubble" gradientUnits="userSpaceOnUse" + cx="0" cy="0" r="100" fx="-50" fy="-50"> + <stop offset="0%" stop-color="white" stop-opacity="1" /> + <stop offset="25%" stop-color="#cdffcd" stop-opacity=".65" /> + <stop offset="100%" stop-color="#99aaaa" stop-opacity=".75" /> + </radialGradient> + <radialGradient id="yellowBubble" gradientUnits="userSpaceOnUse" + cx="0" cy="0" r="100" fx="-50" fy="-50"> + <stop offset="0%" stop-color="white" stop-opacity="1" /> + <stop offset="25%" stop-color="#ffffcd" stop-opacity=".65" /> + <stop offset="100%" stop-color="#bbbbaa" stop-opacity=".75" /> + </radialGradient> + <radialGradient id="background" gradientUnits="userSpaceOnUse" + cx="0" cy="0" r="400" fx="250" fy="250"> + <stop offset="0%" stop-color="#ffffee" /> + <stop offset="100%" stop-color="#ccccaa" /> + </radialGradient> + <linearGradient id="surface" gradientUnits="userSpaceOnUse" + x1="-100" y1="200" x2="400" y2="200"> + <stop offset="0%" stop-color="#ffffcc" /> + <stop offset="100%" stop-color="#bbbb88" /> + </linearGradient> + + <!-- Create radial gradients for each circle to make them look like + spheres. --> + <radialGradient id="blueSphere" gradientUnits="userSpaceOnUse" + cx="0" cy="0" r="100" fx="-50" fy="-50"> + <stop offset="0%" stop-color="white" /> + <stop offset="75%" stop-color="blue" /> + <stop offset="100%" stop-color="#222244" /> + </radialGradient> + <radialGradient id="redSphere" gradientUnits="userSpaceOnUse" + cx="0" cy="0" r="100" fx="-50" fy="-50"> + <stop offset="0%" stop-color="white" /> + <stop offset="75%" stop-color="red" /> + <stop offset="100%" stop-color="#442222" /> + </radialGradient> + <radialGradient id="greenSphere" gradientUnits="userSpaceOnUse" + cx="0" cy="0" r="100" fx="-50" fy="-50"> + <stop offset="0%" stop-color="white" /> + <stop offset="75%" stop-color="green" /> + <stop offset="100%" stop-color="#113311" /> + </radialGradient> + <radialGradient id="yellowSphere" gradientUnits="userSpaceOnUse" + cx="0" cy="0" r="100" fx="-50" fy="-50"> + <stop offset="0%" stop-color="white" /> + <stop offset="75%" stop-color="yellow" /> + <stop offset="100%" stop-color="#444422" /> + </radialGradient> + <radialGradient id="shadowGrad" gradientUnits="userSpaceOnUse" + cx="0" cy="0" r="100" fx="-50" fy="50"> + <stop offset="0%" stop-color="black" stop-opacity="1.0" /> + <stop offset="100%" stop-color="white" stop-opacity="0.0" /> + </radialGradient> + + <!-- Define a shadow for each sphere. --> + <circle id="shadow" fill="url(#shadowGrad)" cx="0" cy="0" r="100" /> + <g id="bubble"> + <circle fill="black" cx="0" cy="0" r="50" /> + <circle fill="#a6ce39" cx="0" cy="0" r="33" /> + <path fill="black" d="M 37,50 L 50,37 L 12,-1 L 22,-11 L 10,-24 L -24,10 + L -11,22 L -1,12 Z" /> + <circle cx="0" cy="0" r="100" /> + </g> + </defs> + <g> + <rect fill="url(#background)" x="0" y="0" width="800" height="600" /> + </g> + + <g transform="translate(200,700)"> + <use xlink:href="#bubble" fill="url(#blueBubble)" /> + <animateTransform attributeName="transform" type="translate" + values="0,0; 0,-800" begin="1s" dur="10s" fill="freeze" repeatCount="indefinite" /> + </g> + <g transform="translate(315,700)"> + <g transform="scale(0.5,0.5)"> + <use xlink:href="#bubble" fill="url(#redBubble)" /> + </g> + <animateTransform attributeName="transform" type="translate" + values="0,0; 0,-800" begin="3s" dur="7s" fill="freeze" repeatCount="indefinite" /> + </g> + <g transform="translate(80,700)"> + <g transform="scale(0.65,0.65)"> + <use xlink:href="#bubble" fill="url(#greenBubble)" /> + </g> + <animateTransform attributeName="transform" type="translate" + values="0,0; 0,-800" begin="5s" dur="9s" fill="freeze" repeatCount="indefinite" /> + </g> + <g transform="translate(255,700)"> + <g transform="scale(0.3,0.3)"> + <use xlink:href="#bubble" fill="url(#yellowBubble)" /> + </g> + <animateTransform attributeName="transform" type="translate" + values="0,0; 0,-800" begin="2s" dur="6s" fill="freeze" repeatCount="indefinite" /> + </g> + <g transform="translate(565,700)"> + <g transform="scale(0.4,0.4)"> + <use xlink:href="#bubble" fill="url(#blueBubble)" /> + </g> + <animateTransform attributeName="transform" type="translate" + values="0,0; 0,-800" begin="4s" dur="8s" fill="freeze" repeatCount="indefinite" /> + </g> + <g transform="translate(715,700)"> + <g transform="scale(0.6,0.6)"> + <use xlink:href="#bubble" fill="url(#redBubble)" /> + </g> + <animateTransform attributeName="transform" type="translate" + values="0,0; 0,-800" begin="1s" dur="4s" fill="freeze" repeatCount="indefinite" /> + </g> + <g transform="translate(645,700)"> + <g transform="scale(0.375,0.375)"> + <use xlink:href="#bubble" fill="url(#greenBubble)" /> + </g> + <animateTransform attributeName="transform" type="translate" + values="0,0; 0,-800" begin="0s" dur="11s" fill="freeze" repeatCount="indefinite" /> + </g> + <g transform="translate(555,700)"> + <g transform="scale(0.9,0.9)"> + <use xlink:href="#bubble" fill="url(#yellowBubble)" /> + </g> + <animateTransform attributeName="transform" type="translate" + values="0,0; 0,-800" begin="3s" dur="7.5s" fill="freeze" repeatCount="indefinite" /> + </g> + + <g transform="translate(360,700)"> + <g transform="scale(0.5,0.5)"> + <use xlink:href="#bubble" fill="url(#blueBubble)" /> + </g> + <animateTransform attributeName="transform" type="translate" + values="0,0; 0,-800" begin="3s" dur="6s" fill="freeze" repeatCount="indefinite" /> + </g> + <g transform="translate(215,700)"> + <g transform="scale(0.45,0.45)"> + <use xlink:href="#bubble" fill="url(#redBubble)" /> + </g> + <animateTransform attributeName="transform" type="translate" + values="0,0; 0,-800" begin="5.5s" dur="7s" fill="freeze" repeatCount="indefinite" /> + </g> + <g transform="translate(420,700)"> + <g transform="scale(0.75,0.75)"> + <use xlink:href="#bubble" fill="url(#greenBubble)" /> + </g> + <animateTransform attributeName="transform" type="translate" + values="0,0; 0,-800" begin="1s" dur="9s" fill="freeze" repeatCount="indefinite" /> + </g> + <g transform="translate(815,700)"> + <g transform="scale(0.6,0.6)"> + <use xlink:href="#bubble" fill="url(#yellowBubble)" /> + </g> + <animateTransform attributeName="transform" type="translate" + values="0,0; 0,-800" begin="2s" dur="9.5s" fill="freeze" repeatCount="indefinite" /> + </g> + + <g transform="translate(225,375)" > + <g transform="scale(1.0,0.5)" > + <path d="M 0 0 L 350 0 L 450 450 L -100 450 z" + fill="url(#surface)" stroke="none" /> + </g> + </g> + <g transform="translate(200,0)" > + <g transform="translate(200,490) scale(2.0,1.0) rotate(45)" > + <rect fill="#a6ce39" x="-69" y="-69" width="138" height="138" /> + <circle fill="black" cx="0" cy="0" r="50" /> + <circle fill="#a6ce39" cx="0" cy="0" r="33" /> + <path fill="black" d="M 37,50 L 50,37 L 12,-1 L 22,-11 L 10,-24 L -24,10 + L -11,22 L -1,12 Z" /> + <animateTransform attributeName="transform" type="rotate" values="0; 360" + begin="0s" dur="10s" fill="freeze" repeatCount="indefinite" /> + </g> + <g transform="translate(200,375)"> + <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" /> + <circle fill="url(#blueSphere)" cx="0" cy="0" r="100" /> + </g> + <g transform="translate(315,440)"> + <g transform="scale(0.5,0.5)"> + <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" /> + <circle fill="url(#redSphere)" cx="0" cy="0" r="100" /> + </g> + </g> + <g transform="translate(80,475)"> + <g transform="scale(0.65,0.65)"> + <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" /> + <circle fill="url(#greenSphere)" cx="0" cy="0" r="100" /> + </g> + </g> + <g transform="translate(255,525)"> + <g transform="scale(0.3,0.3)"> + <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" /> + <circle fill="url(#yellowSphere)" cx="0" cy="0" r="100" /> + </g> + </g> + </g> +</svg> diff --git a/examples/painting/svgviewer/files/cubic.svg b/examples/painting/svgviewer/files/cubic.svg new file mode 100644 index 0000000..492bb72 --- /dev/null +++ b/examples/painting/svgviewer/files/cubic.svg @@ -0,0 +1,77 @@ +<?xml version="1.0" standalone="no"?> +<svg width="10cm" height="10cm" viewBox="0 0 1000 1000" + xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny"> + <title>Example cubic02 - cubic Bezier commands in path data</title> + <desc>Picture showing examples of "C" and "S" commands, + along with annotations showing the control points + and end points</desc> + + <rect fill="none" stroke="blue" stroke-width="1" x="1" y="1" width="998" height="998" /> + + <!-- Path 1 --> + <polyline fill="none" stroke="#888888" stroke-width="2" points="100,200 100,100" /> + <polyline fill="none" stroke="#888888" stroke-width="2" points="400,100 400,200" /> + <path fill="none" stroke="red" stroke-width="5" d="M100,200 C100,100 400,100 400,200" /> + <circle fill="none" stroke="#888888" stroke-width="2" cx="100" cy="200" r="10" /> + <circle fill="none" stroke="#888888" stroke-width="2" cx="400" cy="200" r="10" /> + <circle class="CtlPoint" cx="100" cy="100" r="10" /> + <circle class="CtlPoint" cx="400" cy="100" r="10" /> + <text text-anchor="middle" font-size="22" font-family="Verdana" x="250" y="275">M100,200 C100,100 400,100 400,200</text> + + <!-- Path 2 --> + <polyline fill="none" stroke="#888888" stroke-width="2" points="100,500 25,400" /> + <polyline fill="none" stroke="#888888" stroke-width="2" points="475,400 400,500" /> + <path fill="none" stroke="red" stroke-width="5" d="M100,500 C25,400 475,400 400,500" /> + <circle fill="none" stroke="#888888" stroke-width="2" cx="100" cy="500" r="10" /> + <circle fill="none" stroke="#888888" stroke-width="2" cx="400" cy="500" r="10" /> + <circle fill="#888888" stroke="none" cx="25" cy="400" r="10" /> + <circle fill="#888888" stroke="none" cx="475" cy="400" r="10" /> + <text text-anchor="middle" font-size="22" font-family="Verdana" x="250" y="575">M100,500 C25,400 475,400 400,500</text> + + <!-- Path 3 --> + <polyline fill="none" stroke="#888888" stroke-width="2" points="100,800 175,700" /> + <polyline fill="none" stroke="#888888" stroke-width="2" points="325,700 400,800" /> + <path fill="none" stroke="red" stroke-width="5" d="M100,800 C175,700 325,700 400,800" /> + <circle fill="none" stroke="#888888" stroke-width="2" cx="100" cy="800" r="10" /> + <circle fill="none" stroke="#888888" stroke-width="2" cx="400" cy="800" r="10" /> + <circle fill="#888888" stroke="none" cx="175" cy="700" r="10" /> + <circle fill="#888888" stroke="none" cx="325" cy="700" r="10" /> + <text text-anchor="middle" font-size="22" font-family="Verdana" x="250" y="875">M100,800 C175,700 325,700 400,800</text> + + <!-- Path 4 --> + <polyline fill="none" stroke="#888888" stroke-width="2" points="600,200 675,100" /> + <polyline fill="none" stroke="#888888" stroke-width="2" points="975,100 900,200" /> + <path fill="none" stroke="red" stroke-width="5" d="M600,200 C675,100 975,100 900,200" /> + <circle fill="none" stroke="#888888" stroke-width="2" cx="600" cy="200" r="10" /> + <circle fill="none" stroke="#888888" stroke-width="2" cx="900" cy="200" r="10" /> + <circle fill="#888888" stroke="none" cx="675" cy="100" r="10" /> + <circle fill="#888888" stroke="none" cx="975" cy="100" r="10" /> + <text text-anchor="middle" font-size="22" font-family="Verdana" x="750" y="275">M600,200 C675,100 975,100 900,200</text> + + <!-- Path 5 --> + <polyline fill="none" stroke="#888888" stroke-width="2" points="600,500 600,350" /> + <polyline fill="none" stroke="#888888" stroke-width="2" points="900,650 900,500" /> + <path fill="none" stroke="red" stroke-width="5" d="M600,500 C600,350 900,650 900,500" /> + <circle fill="none" stroke="#888888" stroke-width="2" cx="600" cy="500" r="10" /> + <circle fill="none" stroke="#888888" stroke-width="2" cx="900" cy="500" r="10" /> + <circle fill="#888888" stroke="none" cx="600" cy="350" r="10" /> + <circle fill="#888888" stroke="none" cx="900" cy="650" r="10" /> + <text text-anchor="middle" font-size="22" font-family="Verdana" x="750" y="575">M600,500 C600,350 900,650 900,500</text> + + <!-- Path 6 (C and S command) --> + <polyline fill="none" stroke="#888888" stroke-width="2" points="600,800 625,700" /> + <polyline fill="none" stroke="#888888" stroke-width="2" points="725,700 750,800" /> + <polyline fill="none" stroke="#888888" stroke-width="2" points="750,800 775,900" /> + <polyline fill="none" stroke="#888888" stroke-width="2" points="875,900 900,800" /> + <path fill="none" stroke="red" stroke-width="5" d="M600,800 C625,700 725,700 750,800 + S875,900 900,800" /> + <circle fill="none" stroke="#888888" stroke-width="2" cx="600" cy="800" r="10" /> + <circle fill="none" stroke="#888888" stroke-width="2" cx="750" cy="800" r="10" /> + <circle fill="none" stroke="#888888" stroke-width="2" cx="900" cy="800" r="10" /> + <circle fill="#888888" stroke="none" cx="625" cy="700" r="10" /> + <circle fill="#888888" stroke="none" cx="725" cy="700" r="10" /> + <circle fill="#888888" stroke="none" cx="875" cy="900" r="10" /> + <circle fill="none" stroke="blue" stroke-width="4" cx="775" cy="900" r="9" /> + <text text-anchor="middle" font-size="22" font-family="Verdana" x="750" y="945">M600,800 C625,700 725,700 750,800</text> + <text text-anchor="middle" font-size="22" font-family="Verdana" x="750" y="975">S875,900 900,800</text> +</svg> diff --git a/examples/painting/svgviewer/files/spheres.svg b/examples/painting/svgviewer/files/spheres.svg new file mode 100644 index 0000000..b23164b --- /dev/null +++ b/examples/painting/svgviewer/files/spheres.svg @@ -0,0 +1,72 @@ +<?xml version="1.0" standalone="no"?> +<svg width="8cm" height="8cm" viewBox="0 0 400 400" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink/" + baseProfile="tiny" version="1.2"> + <title>Spheres</title> + <desc>Gradient filled spheres with different colors.</desc> + <defs> + <!-- Create radial gradients for each circle to make them look like + spheres. --> + <radialGradient id="blueSphere" gradientUnits="userSpaceOnUse" + cx="0" cy="0" r="100" fx="-50" fy="-50"> + <stop offset="0%" stop-color="white" /> + <stop offset="75%" stop-color="blue" /> + <stop offset="100%" stop-color="#222244" /> + </radialGradient> + <radialGradient id="redSphere" gradientUnits="userSpaceOnUse" + cx="0" cy="0" r="100" fx="-50" fy="-50"> + <stop offset="0%" stop-color="white" /> + <stop offset="75%" stop-color="red" /> + <stop offset="100%" stop-color="#442222" /> + </radialGradient> + <radialGradient id="greenSphere" gradientUnits="userSpaceOnUse" + cx="0" cy="0" r="100" fx="-50" fy="-50"> + <stop offset="0%" stop-color="white" /> + <stop offset="75%" stop-color="green" /> + <stop offset="100%" stop-color="#113311" /> + </radialGradient> + <radialGradient id="yellowSphere" gradientUnits="userSpaceOnUse" + cx="0" cy="0" r="100" fx="-50" fy="-50"> + <stop offset="0%" stop-color="white" /> + <stop offset="75%" stop-color="yellow" /> + <stop offset="100%" stop-color="#444422" /> + </radialGradient> + <radialGradient id="shadowGrad" gradientUnits="userSpaceOnUse" + cx="0" cy="0" r="100" fx="-50" fy="50"> + <stop offset="0%" stop-color="black" stop-opacity="1.0" /> + <stop offset="100%" stop-color="white" stop-opacity="0.0" /> + </radialGradient> + + <!-- Define a shadow for each sphere. --> + <circle id="shadow" fill="url(#shadowGrad)" cx="0" cy="0" r="100" /> + </defs> + <g fill="#ffee99" stroke="none" > + <rect x="0" y="0" width="400" height="400" /> + </g> + <g fill="white" stroke="none" > + <rect x="0" y="175" width="400" height="225" /> + </g> + <g transform="translate(200,175)"> + <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" /> + <circle fill="url(#blueSphere)" cx="0" cy="0" r="100" /> + </g> + <g transform="translate(315,240)"> + <g transform="scale(0.5,0.5)"> + <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" /> + <circle fill="url(#redSphere)" cx="0" cy="0" r="100" /> + </g> + </g> + <g transform="translate(80,275)"> + <g transform="scale(0.65,0.65)"> + <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" /> + <circle fill="url(#greenSphere)" cx="0" cy="0" r="100" /> + </g> + </g> + <g transform="translate(255,325)"> + <g transform="scale(0.3,0.3)"> + <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" /> + <circle fill="url(#yellowSphere)" cx="0" cy="0" r="100" /> + </g> + </g> +</svg> diff --git a/examples/painting/svgviewer/main.cpp b/examples/painting/svgviewer/main.cpp new file mode 100644 index 0000000..18520f7 --- /dev/null +++ b/examples/painting/svgviewer/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> +#include <QString> +#ifndef QT_NO_OPENGL +#include <QGLFormat> +#endif + +#include "mainwindow.h" + +int main(int argc, char **argv) +{ + Q_INIT_RESOURCE(svgviewer); + + QApplication app(argc, argv); + + MainWindow window; + if (argc == 2) + window.openFile(argv[1]); + else + window.openFile(":/files/bubbles.svg"); + window.show(); + return app.exec(); +} diff --git a/examples/painting/svgviewer/mainwindow.cpp b/examples/painting/svgviewer/mainwindow.cpp new file mode 100644 index 0000000..22393eb --- /dev/null +++ b/examples/painting/svgviewer/mainwindow.cpp @@ -0,0 +1,164 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "mainwindow.h" + +#include <QtGui> + +#include "svgview.h" + +MainWindow::MainWindow() + : QMainWindow() + , m_view(new SvgView) +{ + QMenu *fileMenu = new QMenu(tr("&File"), this); + QAction *openAction = fileMenu->addAction(tr("&Open...")); + openAction->setShortcut(QKeySequence(tr("Ctrl+O"))); + QAction *quitAction = fileMenu->addAction(tr("E&xit")); + quitAction->setShortcut(QKeySequence(tr("Ctrl+Q"))); + + menuBar()->addMenu(fileMenu); + + QMenu *viewMenu = new QMenu(tr("&View"), this); + m_backgroundAction = viewMenu->addAction(tr("&Background")); + m_backgroundAction->setEnabled(false); + m_backgroundAction->setCheckable(true); + m_backgroundAction->setChecked(false); + connect(m_backgroundAction, SIGNAL(toggled(bool)), m_view, SLOT(setViewBackground(bool))); + + m_outlineAction = viewMenu->addAction(tr("&Outline")); + m_outlineAction->setEnabled(false); + m_outlineAction->setCheckable(true); + m_outlineAction->setChecked(true); + connect(m_outlineAction, SIGNAL(toggled(bool)), m_view, SLOT(setViewOutline(bool))); + + menuBar()->addMenu(viewMenu); + + QMenu *rendererMenu = new QMenu(tr("&Renderer"), this); + m_nativeAction = rendererMenu->addAction(tr("&Native")); + m_nativeAction->setCheckable(true); + m_nativeAction->setChecked(true); +#ifndef QT_NO_OPENGL + m_glAction = rendererMenu->addAction(tr("&OpenGL")); + m_glAction->setCheckable(true); +#endif + m_imageAction = rendererMenu->addAction(tr("&Image")); + m_imageAction->setCheckable(true); + +#ifndef QT_NO_OPENGL + rendererMenu->addSeparator(); + m_highQualityAntialiasingAction = rendererMenu->addAction(tr("&High Quality Antialiasing")); + m_highQualityAntialiasingAction->setEnabled(false); + m_highQualityAntialiasingAction->setCheckable(true); + m_highQualityAntialiasingAction->setChecked(false); + connect(m_highQualityAntialiasingAction, SIGNAL(toggled(bool)), m_view, SLOT(setHighQualityAntialiasing(bool))); +#endif + + QActionGroup *rendererGroup = new QActionGroup(this); + rendererGroup->addAction(m_nativeAction); +#ifndef QT_NO_OPENGL + rendererGroup->addAction(m_glAction); +#endif + rendererGroup->addAction(m_imageAction); + + menuBar()->addMenu(rendererMenu); + + connect(openAction, SIGNAL(triggered()), this, SLOT(openFile())); + connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + connect(rendererGroup, SIGNAL(triggered(QAction *)), + this, SLOT(setRenderer(QAction *))); + + setCentralWidget(m_view); + setWindowTitle(tr("SVG Viewer")); +} + +void MainWindow::openFile(const QString &path) +{ + QString fileName; + if (path.isNull()) + fileName = QFileDialog::getOpenFileName(this, tr("Open SVG File"), + m_currentPath, "SVG files (*.svg *.svgz *.svg.gz)"); + else + fileName = path; + + if (!fileName.isEmpty()) { + QFile file(fileName); + if (!file.exists()) { + QMessageBox::critical(this, tr("Open SVG File"), + QString("Could not open file '%1'.").arg(fileName)); + + m_outlineAction->setEnabled(false); + m_backgroundAction->setEnabled(false); + return; + } + + m_view->openFile(file); + + if (!fileName.startsWith(":/")) { + m_currentPath = fileName; + setWindowTitle(tr("%1 - SVGViewer").arg(m_currentPath)); + } + + m_outlineAction->setEnabled(true); + m_backgroundAction->setEnabled(true); + + resize(m_view->sizeHint() + QSize(80, 80 + menuBar()->height())); + } +} + +void MainWindow::setRenderer(QAction *action) +{ +#ifndef QT_NO_OPENGL + m_highQualityAntialiasingAction->setEnabled(false); +#endif + + if (action == m_nativeAction) + m_view->setRenderer(SvgView::Native); +#ifndef QT_NO_OPENGL + else if (action == m_glAction) { + m_highQualityAntialiasingAction->setEnabled(true); + m_view->setRenderer(SvgView::OpenGL); + } +#endif + else if (action == m_imageAction) { + m_view->setRenderer(SvgView::Image); + } +} diff --git a/examples/painting/svgviewer/mainwindow.h b/examples/painting/svgviewer/mainwindow.h new file mode 100644 index 0000000..5df430b --- /dev/null +++ b/examples/painting/svgviewer/mainwindow.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> +#include <QString> + +class SvgView; + +QT_BEGIN_NAMESPACE +class QAction; +class QGraphicsView; +class QGraphicsScene; +class QGraphicsRectItem; +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void openFile(const QString &path = QString()); + void setRenderer(QAction *action); + +private: + QAction *m_nativeAction; + QAction *m_glAction; + QAction *m_imageAction; + QAction *m_highQualityAntialiasingAction; + QAction *m_backgroundAction; + QAction *m_outlineAction; + + SvgView *m_view; + + QString m_currentPath; +}; + +#endif diff --git a/examples/painting/svgviewer/svgview.cpp b/examples/painting/svgviewer/svgview.cpp new file mode 100644 index 0000000..daf7bf0 --- /dev/null +++ b/examples/painting/svgviewer/svgview.cpp @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "svgview.h" + +#include <QFile> +#include <QWheelEvent> +#include <QMouseEvent> +#include <QGraphicsRectItem> +#include <QGraphicsSvgItem> +#include <QPaintEvent> +#include <qmath.h> + +#ifndef QT_NO_OPENGL +#include <QGLWidget> +#endif + +SvgView::SvgView(QWidget *parent) + : QGraphicsView(parent) + , m_renderer(Native) + , m_svgItem(0) + , m_backgroundItem(0) + , m_outlineItem(0) +{ + setScene(new QGraphicsScene(this)); + setTransformationAnchor(AnchorUnderMouse); + setDragMode(ScrollHandDrag); + + // Prepare background check-board pattern + QPixmap tilePixmap(64, 64); + tilePixmap.fill(Qt::white); + QPainter tilePainter(&tilePixmap); + QColor color(220, 220, 220); + tilePainter.fillRect(0, 0, 32, 32, color); + tilePainter.fillRect(32, 32, 32, 32, color); + tilePainter.end(); + + setBackgroundBrush(tilePixmap); +} + +void SvgView::drawBackground(QPainter *p, const QRectF &) +{ + p->save(); + p->resetTransform(); + p->drawTiledPixmap(viewport()->rect(), backgroundBrush().texture()); + p->restore(); +} + +void SvgView::openFile(const QFile &file) +{ + if (!file.exists()) + return; + + QGraphicsScene *s = scene(); + + bool drawBackground = (m_backgroundItem ? m_backgroundItem->isVisible() : false); + bool drawOutline = (m_outlineItem ? m_outlineItem->isVisible() : true); + + s->clear(); + resetTransform(); + + m_svgItem = new QGraphicsSvgItem(file.fileName()); + m_svgItem->setFlags(QGraphicsItem::ItemClipsToShape); + m_svgItem->setCacheMode(QGraphicsItem::NoCache); + m_svgItem->setZValue(0); + + m_backgroundItem = new QGraphicsRectItem(m_svgItem->boundingRect()); + m_backgroundItem->setBrush(Qt::white); + m_backgroundItem->setPen(Qt::NoPen); + m_backgroundItem->setVisible(drawBackground); + m_backgroundItem->setZValue(-1); + + m_outlineItem = new QGraphicsRectItem(m_svgItem->boundingRect()); + QPen outline(Qt::black, 2, Qt::DashLine); + outline.setCosmetic(true); + m_outlineItem->setPen(outline); + m_outlineItem->setBrush(Qt::NoBrush); + m_outlineItem->setVisible(drawOutline); + m_outlineItem->setZValue(1); + + s->addItem(m_backgroundItem); + s->addItem(m_svgItem); + s->addItem(m_outlineItem); + + s->setSceneRect(m_outlineItem->boundingRect().adjusted(-10, -10, 10, 10)); +} + +void SvgView::setRenderer(RendererType type) +{ + m_renderer = type; + + if (m_renderer == OpenGL) { +#ifndef QT_NO_OPENGL + setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); +#endif + } else { + setViewport(new QWidget); + } +} + +void SvgView::setHighQualityAntialiasing(bool highQualityAntialiasing) +{ +#ifndef QT_NO_OPENGL + setRenderHint(QPainter::HighQualityAntialiasing, highQualityAntialiasing); +#else + Q_UNUSED(highQualityAntialiasing); +#endif +} + +void SvgView::setViewBackground(bool enable) +{ + if (!m_backgroundItem) + return; + + m_backgroundItem->setVisible(enable); +} + +void SvgView::setViewOutline(bool enable) +{ + if (!m_outlineItem) + return; + + m_outlineItem->setVisible(enable); +} + +void SvgView::paintEvent(QPaintEvent *event) +{ + if (m_renderer == Image) { + if (m_image.size() != viewport()->size()) { + m_image = QImage(viewport()->size(), QImage::Format_ARGB32_Premultiplied); + } + + QPainter imagePainter(&m_image); + QGraphicsView::render(&imagePainter); + imagePainter.end(); + + QPainter p(viewport()); + p.drawImage(0, 0, m_image); + + } else { + QGraphicsView::paintEvent(event); + } +} + +void SvgView::wheelEvent(QWheelEvent *event) +{ + qreal factor = qPow(1.2, event->delta() / 240.0); + scale(factor, factor); + event->accept(); +} + diff --git a/examples/painting/svgviewer/svgview.h b/examples/painting/svgviewer/svgview.h new file mode 100644 index 0000000..993268a --- /dev/null +++ b/examples/painting/svgviewer/svgview.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SVGVIEW_H +#define SVGVIEW_H + +#include <QGraphicsView> + +QT_BEGIN_NAMESPACE +class QWheelEvent; +class QPaintEvent; +class QFile; +QT_END_NAMESPACE + +class SvgView : public QGraphicsView +{ + Q_OBJECT + +public: + enum RendererType { Native, OpenGL, Image }; + + SvgView(QWidget *parent = 0); + + void openFile(const QFile &file); + void setRenderer(RendererType type = Native); + void drawBackground(QPainter *p, const QRectF &rect); + +public slots: + void setHighQualityAntialiasing(bool highQualityAntialiasing); + void setViewBackground(bool enable); + void setViewOutline(bool enable); + +protected: + void wheelEvent(QWheelEvent *event); + void paintEvent(QPaintEvent *event); + +private: + RendererType m_renderer; + + QGraphicsItem *m_svgItem; + QGraphicsRectItem *m_backgroundItem; + QGraphicsRectItem *m_outlineItem; + + QImage m_image; +}; +#endif // SVGVIEW_H diff --git a/examples/painting/svgviewer/svgviewer.pro b/examples/painting/svgviewer/svgviewer.pro new file mode 100644 index 0000000..b29e218 --- /dev/null +++ b/examples/painting/svgviewer/svgviewer.pro @@ -0,0 +1,23 @@ +HEADERS = mainwindow.h \ + svgview.h +RESOURCES = svgviewer.qrc +SOURCES = main.cpp \ + mainwindow.cpp \ + svgview.cpp +QT += svg xml + +contains(QT_CONFIG, opengl): QT += opengl + +CONFIG += console + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/painting/svgviewer +sources.files = $$SOURCES $$HEADERS $$RESOURCES svgviewer.pro files +sources.path = $$[QT_INSTALL_EXAMPLES]/painting/svgviewer +INSTALLS += target sources + +wince*: { + addFiles.sources = files\*.svg + addFiles.path = \My Documents + DEPLOYMENT += addFiles +} diff --git a/examples/painting/svgviewer/svgviewer.qrc b/examples/painting/svgviewer/svgviewer.qrc new file mode 100644 index 0000000..db611f5 --- /dev/null +++ b/examples/painting/svgviewer/svgviewer.qrc @@ -0,0 +1,6 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource prefix="/"> + <file>files/bubbles.svg</file> +</qresource> +</RCC> + |