QTeXEngine.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef Q_TEX_ENGINE_H
00030 #define Q_TEX_ENGINE_H
00031
00032 #include <QPaintDevice>
00033 #include <QPaintEngine>
00034 #include <QPrinter>
00035
00036 class QFile;
00037 class QTeXPaintEngine;
00038
00039 class QTeXPaintDevice : public QPaintDevice
00040 {
00041 public:
00042 enum Unit{pt, bp, mm, cm, in, ex, em};
00043 enum OutputMode{Tikz, Pgf};
00044
00045 QTeXPaintDevice(const QString& fileName, const QSize& s = QSize(), Unit u = pt);
00046 ~QTeXPaintDevice();
00047
00048 virtual QPaintEngine * paintEngine () const;
00050 void setColorMode(QPrinter::ColorMode mode);
00052 void setOutputMode(OutputMode mode);
00054 void setUnit(Unit u);
00056 void setSize(const QSize& s){d_size = s;};
00058 void setDocumentMode(bool on = true);
00060 void setEscapeTextMode(bool on = true);
00062 void exportFontSizes(bool on = true);
00064 void setTextHorizontalAlignment(Qt::Alignment alignment);
00065
00066 protected:
00067 virtual int metric ( PaintDeviceMetric ) const;
00068
00069 private:
00071 QSize d_size;
00072 QTeXPaintEngine* engine;
00073 };
00074
00075 class QTeXPaintEngine : public QPaintEngine
00076 {
00077 public:
00078 QTeXPaintEngine(const QString&, QTeXPaintDevice::Unit u = QTeXPaintDevice::pt);
00079 ~QTeXPaintEngine(){};
00080 virtual bool begin(QPaintDevice*);
00081 virtual bool end();
00082 virtual void updateState( const QPaintEngineState & ) {};
00083 virtual void drawEllipse(const QRectF &);
00084 virtual QPaintEngine::Type type() const {return QPaintEngine::User;};
00085 virtual void drawPoints ( const QPointF * points, int pointCount );
00086 virtual void drawLines ( const QLineF * , int );
00087 virtual void drawPath ( const QPainterPath & path );
00088 virtual void drawPolygon ( const QPointF * , int , PolygonDrawMode );
00089 virtual void drawTextItem ( const QPointF & , const QTextItem & );
00090 virtual void drawRects ( const QRectF * , int );
00091 virtual void drawPixmap ( const QRectF &, const QPixmap &, const QRectF &);
00092 virtual void drawImage(const QRectF &, const QImage &, const QRectF &, Qt::ImageConversionFlags);
00093
00095 void setUnit(QTeXPaintDevice::Unit u){d_unit = u;};
00097 void setGrayScale(bool on = true){d_gray_scale = on;};
00099 void setOutputMode(QTeXPaintDevice::OutputMode mode){d_pgf_mode = (mode == QTeXPaintDevice::Pgf) ? true : false;};
00100 void setDocumentMode(bool on = true){d_document_mode = on;};
00102 void setEscapeTextMode(bool on = true){d_escape_text = on;};
00103 void exportFontSizes(bool on = true){d_font_size = on;};
00104 void setTextHorizontalAlignment(Qt::Alignment alignment){d_horizontal_alignment = alignment;};
00105
00106 private:
00107 enum Shape{Line, Polygon, Polyline, Rect, Ellipse, Path, Points};
00109 bool emptyStringOperation();
00110 QString unit();
00111 double unitFactor();
00112 double resFactorX();
00113 double resFactorY();
00114
00115 QString pgfPoint(const QPointF& p);
00116 QString tikzPoint(const QPointF& p);
00117
00118 QPointF convertPoint(const QPointF& p);
00119 QString color(const QColor& col);
00120 QString defineColor(const QColor& c, const QString& name);
00121
00122 QString pgfPen(const QPen& pen);
00123 QString tikzPen(const QPen& pen);
00124
00125 QString pgfBrush(const QBrush& brush);
00126 QString tikzBrush(const QBrush& brush);
00127
00128 QString beginScope();
00129 QString endScope();
00130
00131 QString clipPath();
00132 bool changedClipping();
00133
00134 QString path(const QPainterPath & path);
00135 QString pgfPath(const QPainterPath & path);
00136 QString tikzPath(const QPainterPath & path);
00137
00138 QString drawShape(Shape shape, const QString & path);
00139 QString drawPgfShape(Shape shape, const QString & path);
00140 QString drawTikzShape(Shape shape, const QString & path);
00141
00143 void drawPixmap(const QPixmap &pix, const QRectF &p);
00144 void writeToFile(const QString& s);
00145 QString indentString(const QString& s);
00147 bool addNewBrushColor();
00148 bool addNewPatternColor();
00149 bool addNewPenColor();
00150
00151 QFile *file;
00153 QString fname;
00154 int d_pixmap_index;
00155 bool d_pgf_mode;
00156 bool d_open_scope;
00157 bool d_gray_scale;
00158 bool d_document_mode;
00159 bool d_escape_text;
00160 bool d_font_size;
00161 QPainterPath d_clip_path;
00162 QColor d_current_color, d_pattern_color;
00163 QTeXPaintDevice::Unit d_unit;
00164 Qt::Alignment d_horizontal_alignment;
00165 };
00166 #endif