QTeXEngine.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : QTeXEngine.h
00003     Project              : QTeXEngine GNU GPL v. 3.0
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2009 by Ion Vasilief
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr
00007     Description          : Enables the export of QPainter grafics to .tex files
00008  ***************************************************************************/
00009 
00010 /***************************************************************************
00011  *                                                                         *
00012  *  This program is free software; you can redistribute it and/or modify   *
00013  *  it under the terms of the GNU General Public License as published by   *
00014  *  the Free Software Foundation; either version 3 of the License, or      *
00015  *  (at your option) any later version.                                    *
00016  *                                                                         *
00017  *  This program is distributed in the hope that it will be useful,        *
00018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00020  *  GNU General Public License for more details.                           *
00021  *                                                                         *
00022  *   You should have received a copy of the GNU General Public License     *
00023  *   along with this program; if not, write to the Free Software           *
00024  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00025  *   Boston, MA  02110-1301  USA                                           *
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

Generated on Mon Aug 17 15:34:11 2009 for QTeXEngine by  doxygen 1.5.8