1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite 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 http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://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 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 #ifndef QENGINES_H
42 #define QENGINES_H
43
44 #if defined(BUILD_OPENGL)
45 #include <QGLPixelBuffer>
46 #endif
47 #include <QPrinter>
48 #include <QPixmap>
49 #include <QImage>
50 #include <QMap>
51 #include <QList>
52 #include <QColor>
53
54 QT_FORWARD_DECLARE_CLASS(QSvgRenderer)
QT_FORWARD_DECLARE_CLASS(QGLWidget)55 QT_FORWARD_DECLARE_CLASS(QGLWidget)
56
57 class QEngine
58 {
59 public:
60 virtual ~QEngine();
61 virtual QString name() const =0;
62 virtual void prepare(const QSize &size, const QColor &fillColor = Qt::white) =0;
63 virtual void render(QSvgRenderer *r, const QString &) =0;
64 virtual void render(const QStringList &qpsScript,
65 const QString &absFilePath) =0;
66 virtual bool drawOnPainter(QPainter *p) =0;
67 virtual void save(const QString &file) =0;
68 virtual void cleanup();
69 };
70
71 class QtEngines
72 {
73 public:
74 static QtEngines *self();
75 QtEngines();
76
77 QList<QEngine*> engines() const;
78 QList<QEngine*> foreignEngines() const;
79
80 QEngine *defaultEngine() const;
81 private:
82 void init();
83 private:
84 QList<QEngine*> m_engines;
85 QList<QEngine*> m_foreignEngines;
86 QEngine *m_defaultEngine;
87 };
88
89 class RasterEngine : public QEngine
90 {
91 public:
92 RasterEngine();
93
94 virtual QString name() const;
95 virtual void prepare(const QSize &size, const QColor &fillColor = Qt::white);
96 virtual void render(QSvgRenderer *r, const QString &);
97 virtual void render(const QStringList &qpsScript,
98 const QString &absFilePath);
99 virtual bool drawOnPainter(QPainter *p);
100 virtual void save(const QString &file);
101 private:
102 QImage image;
103 };
104
105 class NativeEngine : public QEngine
106 {
107 public:
108 NativeEngine();
109
110 virtual QString name() const;
111 virtual void prepare(const QSize &size, const QColor &fillColor = Qt::white);
112 virtual void render(QSvgRenderer *r, const QString &);
113 virtual void render(const QStringList &qpsScript,
114 const QString &absFilePath);
115 virtual bool drawOnPainter(QPainter *p);
116 virtual void save(const QString &file);
117 private:
118 QPixmap pixmap;
119 };
120
121
122 #if defined(BUILD_OPENGL)
123 class GLEngine : public QEngine
124 {
125 public:
126 GLEngine();
127 virtual QString name() const;
128 virtual void prepare(const QSize &_size, const QColor &fillColor = Qt::white);
129 virtual void render(QSvgRenderer *r, const QString &);
130 virtual void render(const QStringList &qpsScript,
131 const QString &absFilePath);
132 virtual bool drawOnPainter(QPainter *p);
133 virtual void save(const QString &file);
134 virtual void cleanup();
135 private:
136 QGLPixelBuffer *pbuffer;
137 QGLWidget *widget;
138 bool usePixelBuffers;
139 QSize size;
140 QColor fillColor;
141 };
142 #endif
143
144 class WidgetEngineWidget;
145 class WidgetEngine : public QEngine
146 {
147 public:
148 WidgetEngine();
149 virtual QString name() const;
150 virtual void prepare(const QSize &_size, const QColor &fillColor = Qt::white);
151 virtual void render(QSvgRenderer *r, const QString &);
152 virtual void render(const QStringList &qpsScript,
153 const QString &absFilePath);
154 virtual bool drawOnPainter(QPainter *p);
155 virtual void save(const QString &file);
156 virtual void cleanup();
157 private:
158 WidgetEngineWidget *m_widget;
159 };
160
161 #ifndef QT_NO_PRINTER
162 class PDFEngine : public QEngine
163 {
164 public:
165 PDFEngine();
166
167 virtual QString name() const;
168 virtual void prepare(const QSize &size, const QColor &fillColor = Qt::white);
169 virtual void render(QSvgRenderer *r, const QString &);
170 virtual void render(const QStringList &qpsScript,
171 const QString &absFilePath);
172 virtual bool drawOnPainter(QPainter *p);
173 virtual void save(const QString &file);
174 virtual void cleanup();
175 private:
176 QPrinter *printer;
177 QSize m_size;
178 QString m_tempFile;
179 };
180
181 #ifdef Q_WS_X11
182 class PSEngine : public QEngine
183 {
184 public:
185 PSEngine();
186
187 virtual QString name() const;
188 virtual void prepare(const QSize &size, const QColor &fillColor = Qt::white);
189 virtual void render(QSvgRenderer *r, const QString &);
190 virtual void render(const QStringList &qpsScript,
191 const QString &absFilePath);
192 virtual bool drawOnPainter(QPainter *p);
193 virtual void save(const QString &file);
194 virtual void cleanup();
195 private:
196 QPrinter *printer;
197 QSize m_size;
198 QString m_tempFile;
199 };
200 #endif
201
202 #ifdef Q_WS_WIN
203 class WinPrintEngine : public QEngine
204 {
205 public:
206 WinPrintEngine();
207
208 virtual QString name() const;
209 virtual void prepare(const QSize &size, const QColor &fillColor = Qt::white);
210 virtual void render(QSvgRenderer *r, const QString &);
211 virtual void render(const QStringList &qpsScript,
212 const QString &absFilePath);
213 virtual bool drawOnPainter(QPainter *p);
214 virtual void save(const QString &file);
215 virtual void cleanup();
216 private:
217 QPrinter *printer;
218 QSize m_size;
219 QString m_tempFile;
220 };
221 #endif
222 #endif //QT_NO_PRINTER
223
224 class RSVGEngine : public QEngine
225 {
226 public:
227 RSVGEngine();
228
229 virtual QString name() const;
230 virtual void prepare(const QSize &size, const QColor &fillColor = Qt::white);
231 virtual void render(QSvgRenderer *r, const QString &);
232 virtual void render(const QStringList &qpsScript,
233 const QString &absFilePath);
234 virtual bool drawOnPainter(QPainter *p);
235 virtual void save(const QString &file);
236 private:
237 QString m_fileName;
238 QSize m_size;
239 };
240
241 #endif
242