/tests/arthur/common/qengines.h

https://bitbucket.org/ultra_iter/qt-vtl · C Header · 241 lines · 179 code · 22 blank · 40 comment · 0 complexity · d8e4db8e375e09fedcd12261c9ead610 MD5 · raw file

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