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 QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
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** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QPICTURE_H
41#define QPICTURE_H
42
43#include <QtGui/qtguiglobal.h>
44#include <QtCore/qiodevice.h>
45#include <QtCore/qstringlist.h>
46#include <QtCore/qsharedpointer.h>
47#include <QtGui/qpaintdevice.h>
48
49QT_BEGIN_NAMESPACE
50
51
52#ifndef QT_NO_PICTURE
53
54class QPicturePrivate;
55class Q_GUI_EXPORT QPicture : public QPaintDevice
56{
57 Q_DECLARE_PRIVATE(QPicture)
58public:
59 explicit QPicture(int formatVersion = -1);
60 QPicture(const QPicture &);
61 ~QPicture();
62
63 bool isNull() const;
64
65 int devType() const override;
66 uint size() const;
67 const char* data() const;
68 virtual void setData(const char* data, uint size);
69
70 bool play(QPainter *p);
71
72 bool load(QIODevice *dev, const char *format = nullptr);
73 bool load(const QString &fileName, const char *format = nullptr);
74 bool save(QIODevice *dev, const char *format = nullptr);
75 bool save(const QString &fileName, const char *format = nullptr);
76
77 QRect boundingRect() const;
78 void setBoundingRect(const QRect &r);
79
80 QPicture& operator=(const QPicture &p);
81 inline QPicture &operator=(QPicture &&other) noexcept
82 { qSwap(value1&: d_ptr, value2&: other.d_ptr); return *this; }
83 inline void swap(QPicture &other) noexcept
84 { d_ptr.swap(other&: other.d_ptr); }
85 void detach();
86 bool isDetached() const;
87
88 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &in, const QPicture &p);
89 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &in, QPicture &p);
90
91#if QT_DEPRECATED_SINCE(5, 10)
92 static QT_DEPRECATED const char* pictureFormat(const QString &fileName);
93 static QT_DEPRECATED QList<QByteArray> inputFormats();
94 static QT_DEPRECATED QList<QByteArray> outputFormats();
95 static QT_DEPRECATED QStringList inputFormatList();
96 static QT_DEPRECATED QStringList outputFormatList();
97#endif // QT_DEPRECATED_SINCE(5, 10)
98
99 QPaintEngine *paintEngine() const override;
100
101protected:
102 QPicture(QPicturePrivate &data);
103
104 int metric(PaintDeviceMetric m) const override;
105
106private:
107 bool exec(QPainter *p, QDataStream &ds, int i);
108
109 QExplicitlySharedDataPointer<QPicturePrivate> d_ptr;
110 friend class QPicturePaintEngine;
111 friend class QAlphaPaintEngine;
112 friend class QPreviewPaintEngine;
113
114public:
115 typedef QExplicitlySharedDataPointer<QPicturePrivate> DataPtr;
116 inline DataPtr &data_ptr() { return d_ptr; }
117};
118
119Q_DECLARE_SHARED(QPicture)
120
121
122#ifndef QT_NO_PICTUREIO
123class QIODevice;
124class QPictureIO;
125typedef void (*picture_io_handler)(QPictureIO *); // picture IO handler
126
127struct QPictureIOData;
128
129class Q_GUI_EXPORT QPictureIO
130{
131public:
132 QPictureIO();
133 QPictureIO(QIODevice *ioDevice, const char *format);
134 QPictureIO(const QString &fileName, const char *format);
135 ~QPictureIO();
136
137 const QPicture &picture() const;
138 int status() const;
139 const char *format() const;
140 QIODevice *ioDevice() const;
141 QString fileName() const;
142 int quality() const;
143 QString description() const;
144 const char *parameters() const;
145 float gamma() const;
146
147 void setPicture(const QPicture &);
148 void setStatus(int);
149 void setFormat(const char *);
150 void setIODevice(QIODevice *);
151 void setFileName(const QString &);
152 void setQuality(int);
153 void setDescription(const QString &);
154 void setParameters(const char *);
155 void setGamma(float);
156
157 bool read();
158 bool write();
159
160 static QByteArray pictureFormat(const QString &fileName);
161 static QByteArray pictureFormat(QIODevice *);
162 static QList<QByteArray> inputFormats();
163 static QList<QByteArray> outputFormats();
164
165 static void defineIOHandler(const char *format,
166 const char *header,
167 const char *flags,
168 picture_io_handler read_picture,
169 picture_io_handler write_picture);
170
171private:
172 Q_DISABLE_COPY(QPictureIO)
173
174 void init();
175
176 QPictureIOData *d;
177};
178
179#endif //QT_NO_PICTUREIO
180
181
182/*****************************************************************************
183 QPicture stream functions
184 *****************************************************************************/
185
186#ifndef QT_NO_DATASTREAM
187Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPicture &);
188Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPicture &);
189#endif
190
191#endif // QT_NO_PICTURE
192
193QT_END_NAMESPACE
194
195#endif // QPICTURE_H
196

source code of qtbase/src/gui/image/qpicture.h