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