1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:BSD$
|
---|
10 | ** You may use this file under the terms of the BSD license as follows:
|
---|
11 | **
|
---|
12 | ** "Redistribution and use in source and binary forms, with or without
|
---|
13 | ** modification, are permitted provided that the following conditions are
|
---|
14 | ** met:
|
---|
15 | ** * Redistributions of source code must retain the above copyright
|
---|
16 | ** notice, this list of conditions and the following disclaimer.
|
---|
17 | ** * Redistributions in binary form must reproduce the above copyright
|
---|
18 | ** notice, this list of conditions and the following disclaimer in
|
---|
19 | ** the documentation and/or other materials provided with the
|
---|
20 | ** distribution.
|
---|
21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
---|
22 | ** the names of its contributors may be used to endorse or promote
|
---|
23 | ** products derived from this software without specific prior written
|
---|
24 | ** permission.
|
---|
25 | **
|
---|
26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
---|
30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
---|
37 | ** $QT_END_LICENSE$
|
---|
38 | **
|
---|
39 | ****************************************************************************/
|
---|
40 |
|
---|
41 | #include <QtGui>
|
---|
42 |
|
---|
43 | void myProcessing(const QString &)
|
---|
44 | {
|
---|
45 | }
|
---|
46 |
|
---|
47 | int main()
|
---|
48 | {
|
---|
49 | QWidget myWidget;
|
---|
50 | {
|
---|
51 | // RECORD
|
---|
52 | //! [0]
|
---|
53 | QPicture picture;
|
---|
54 | QPainter painter;
|
---|
55 | painter.begin(&picture); // paint in picture
|
---|
56 | painter.drawEllipse(10,20, 80,70); // draw an ellipse
|
---|
57 | painter.end(); // painting done
|
---|
58 | picture.save("drawing.pic"); // save picture
|
---|
59 | //! [0]
|
---|
60 | }
|
---|
61 |
|
---|
62 | {
|
---|
63 | // REPLAY
|
---|
64 | //! [1]
|
---|
65 | QPicture picture;
|
---|
66 | picture.load("drawing.pic"); // load picture
|
---|
67 | QPainter painter;
|
---|
68 | painter.begin(&myImage); // paint in myImage
|
---|
69 | painter.drawPicture(0, 0, picture); // draw the picture at (0,0)
|
---|
70 | painter.end(); // painting done
|
---|
71 | //! [1]
|
---|
72 | }
|
---|
73 |
|
---|
74 | QPicture myPicture;
|
---|
75 | {
|
---|
76 | // FORMATS
|
---|
77 | //! [2]
|
---|
78 | QStringList list = QPicture::inputFormatList();
|
---|
79 | foreach (const QString &string, list)
|
---|
80 | myProcessing(string);
|
---|
81 | //! [2]
|
---|
82 | }
|
---|
83 |
|
---|
84 | {
|
---|
85 | // OUTPUT
|
---|
86 | //! [3]
|
---|
87 | QStringList list = QPicture::outputFormatList();
|
---|
88 | foreach (const QString &string, list)
|
---|
89 | myProcessing(string);
|
---|
90 | //! [3]
|
---|
91 | }
|
---|
92 |
|
---|
93 | {
|
---|
94 | // PIC READ
|
---|
95 | //! [4]
|
---|
96 | QPictureIO iio;
|
---|
97 | QPixmap pixmap;
|
---|
98 | iio.setFileName("vegeburger.pic");
|
---|
99 | if (iio.read()) { // OK
|
---|
100 | QPicture picture = iio.picture();
|
---|
101 | QPainter painter(&pixmap);
|
---|
102 | painter.drawPicture(0, 0, picture);
|
---|
103 | }
|
---|
104 | //! [4]
|
---|
105 | }
|
---|
106 |
|
---|
107 | {
|
---|
108 | QPixmap pixmap;
|
---|
109 | // PIC WRITE
|
---|
110 | //! [5]
|
---|
111 | QPictureIO iio;
|
---|
112 | QPicture picture;
|
---|
113 | QPainter painter(&picture);
|
---|
114 | painter.drawPixmap(0, 0, pixmap);
|
---|
115 | iio.setPicture(picture);
|
---|
116 | iio.setFileName("vegeburger.pic");
|
---|
117 | iio.setFormat("PIC");
|
---|
118 | if (iio.write())
|
---|
119 | return true; // returned true if written successfully
|
---|
120 | //! [5]
|
---|
121 | }
|
---|
122 |
|
---|
123 | }
|
---|
124 |
|
---|
125 | // SVG READ
|
---|
126 | //! [6]
|
---|
127 | void readSVG(QPictureIO *picture)
|
---|
128 | {
|
---|
129 | // read the picture using the picture->ioDevice()
|
---|
130 | }
|
---|
131 | //! [6]
|
---|
132 |
|
---|
133 | // SVG WRITE
|
---|
134 | //! [7]
|
---|
135 | void writeSVG(QPictureIO *picture)
|
---|
136 | {
|
---|
137 | // write the picture using the picture->ioDevice()
|
---|
138 | }
|
---|
139 | //! [7]
|
---|
140 |
|
---|
141 | // USE SVG
|
---|
142 | void foo() {
|
---|
143 |
|
---|
144 | //! [8]
|
---|
145 | // add the SVG picture handler
|
---|
146 | // ...
|
---|
147 | //! [8]
|
---|
148 | QPictureIO::defineIOHandler("SVG", 0, 0, readSVG, writeSVG);
|
---|
149 | // ...
|
---|
150 |
|
---|
151 | }
|
---|