1// qpicture.sip generated by MetaSIP
2//
3// This file is part of the QtGui Python extension module.
4//
5// Copyright (c) 2021 Riverbank Computing Limited <info@riverbankcomputing.com>
6//
7// This file is part of PyQt5.
8//
9// This file may be used under the terms of the GNU General Public License
10// version 3.0 as published by the Free Software Foundation and appearing in
11// the file LICENSE included in the packaging of this file.  Please review the
12// following information to ensure the GNU General Public License version 3.0
13// requirements will be met: http://www.gnu.org/copyleft/gpl.html.
14//
15// If you do not wish to use this file under the terms of the GPL version 3.0
16// then you may purchase a commercial license.  For more information contact
17// info@riverbankcomputing.com.
18//
19// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21
22
23class QPicture : QPaintDevice
24{
25%TypeHeaderCode
26#include <qpicture.h>
27%End
28
29public:
30    explicit QPicture(int formatVersion = -1);
31    QPicture(const QPicture &);
32    virtual ~QPicture();
33    bool isNull() const;
34    virtual int devType() const;
35    uint size() const;
36    const char *data() const /Encoding="None"/;
37    virtual void setData(const char *data /Array/, uint size /ArraySize/);
38    bool play(QPainter *p);
39    bool load(QIODevice *dev, const char *format = 0) /ReleaseGIL/;
40    bool load(const QString &fileName, const char *format = 0) /ReleaseGIL/;
41    bool save(QIODevice *dev, const char *format = 0) /ReleaseGIL/;
42    bool save(const QString &fileName, const char *format = 0) /ReleaseGIL/;
43    QRect boundingRect() const;
44    void setBoundingRect(const QRect &r);
45    void detach();
46    bool isDetached() const;
47    virtual QPaintEngine *paintEngine() const;
48
49protected:
50    virtual int metric(QPaintDevice::PaintDeviceMetric m) const;
51
52public:
53    void swap(QPicture &other /Constrained/);
54};
55
56class QPictureIO
57{
58%TypeHeaderCode
59#include <qpicture.h>
60%End
61
62%TypeCode
63// This defines the mapping between picture formats and the corresponding
64// Python i/o handler callables.
65struct qtgui_pio {
66    const char *format;     // The format.
67    PyObject *read;         // The read handler.
68    PyObject *write;        // The write handler.
69    qtgui_pio *next;        // The next in the list.
70};
71
72
73// The head of the list.
74static qtgui_pio *qtgui_pio_head = 0;
75
76
77// Find the entry for the given picture.
78static const qtgui_pio *qtgui_pio_find(QPictureIO *pio)
79{
80    for (const qtgui_pio *p = qtgui_pio_head; p; p = p->next)
81        if (qstrcmp(pio->format(), p->format) == 0)
82            return p;
83
84    return 0;
85}
86
87
88// This is the C++ read handler.
89static void qtgui_pio_read(QPictureIO *pio)
90{
91    const qtgui_pio *p = qtgui_pio_find(pio);
92
93    if (p && p->read)
94    {
95        Py_XDECREF(sipCallMethod(0, p->read, "D", pio, sipType_QPictureIO, NULL));
96    }
97}
98
99
100// This is the C++ write handler.
101static void qtgui_pio_write(QPictureIO *pio)
102{
103    const qtgui_pio *p = qtgui_pio_find(pio);
104
105    if (p && p->write)
106    {
107        Py_XDECREF(sipCallMethod(0, p->write, "D", pio, sipType_QPictureIO, NULL));
108    }
109}
110%End
111
112public:
113    QPictureIO();
114    QPictureIO(QIODevice *ioDevice, const char *format);
115    QPictureIO(const QString &fileName, const char *format);
116    ~QPictureIO();
117    const QPicture &picture() const;
118    int status() const;
119    const char *format() const;
120    QIODevice *ioDevice() const;
121    QString fileName() const;
122    int quality() const;
123    QString description() const;
124    const char *parameters() const;
125    float gamma() const;
126    void setPicture(const QPicture &);
127    void setStatus(int);
128    void setFormat(const char *);
129    void setIODevice(QIODevice *);
130    void setFileName(const QString &);
131    void setQuality(int);
132    void setDescription(const QString &);
133    void setParameters(const char *);
134    void setGamma(float);
135    bool read() /ReleaseGIL/;
136    bool write() /ReleaseGIL/;
137    static QByteArray pictureFormat(const QString &fileName);
138    static QByteArray pictureFormat(QIODevice *);
139    static QList<QByteArray> inputFormats();
140    static QList<QByteArray> outputFormats();
141    static void defineIOHandler(const char *format, const char *header, const char *flags, SIP_PYCALLABLE read_picture /AllowNone,TypeHint="Optional[Callable[[QPictureIO], None]]"/, SIP_PYCALLABLE write_picture /AllowNone,TypeHint="Optional[Callable[[QPictureIO], None]]"/);
142%MethodCode
143        // Convert None to NULL.
144        if (a3 == Py_None)
145            a3 = 0;
146
147        if (a4 == Py_None)
148            a4 = 0;
149
150        // See if we already know about the format.
151        qtgui_pio *p;
152
153        for (p = qtgui_pio_head; p; p = p->next)
154            if (qstrcmp(a0, p->format) == 0)
155                break;
156
157        if (!p)
158        {
159            // Handle the new format.
160            p = new qtgui_pio;
161            p->format = qstrdup(a0);
162            p->read = 0;
163            p->write = 0;
164            p->next = qtgui_pio_head;
165
166            qtgui_pio_head = p;
167        }
168
169        // Replace the old callables with the new ones.
170        Py_XDECREF(p->read);
171        p->read = a3;
172        Py_XINCREF(p->read);
173
174        Py_XDECREF(p->write);
175        p->write = a4;
176        Py_XINCREF(p->write);
177
178        // Install the generic handlers.
179        QPictureIO::defineIOHandler(a0, a1, a2, qtgui_pio_read, qtgui_pio_write);
180%End
181
182private:
183    QPictureIO(const QPictureIO &);
184};
185
186QDataStream &operator<<(QDataStream &in, const QPicture &p /Constrained/) /ReleaseGIL/;
187QDataStream &operator>>(QDataStream &in, QPicture &p /Constrained/) /ReleaseGIL/;
188