Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

latexhelpers.h

Go to the documentation of this file.
00001 //Based on http://doc.trolltech.com/qq/qq21-syntaxhighlighter.html#example
00002 /*
00003 For general Scribus (>=1.3.2) copyright and licensing information please refer
00004 to the COPYING file provided with the program. Following this notice may exist
00005 a copyright and/or license notice that predates the release of Scribus 1.3.2
00006 for which a new license (GPL+exception) is in place.
00007 */
00008 /***************************************************************************
00009                         latexhelpers.h  -  description
00010                         -------------------
00011 copyright            : Scribus Team
00012 ***************************************************************************/
00013 
00014 /***************************************************************************
00015 *                                                                         *
00016 *   This program is free software; you can redistribute it and/or modify  *
00017 *   it under the terms of the GNU General Public License as published by  *
00018 *   the Free Software Foundation; either version 2 of the License, or     *
00019 *   (at your option) any later version.                                   *
00020 *                                                                         *
00021 ***************************************************************************/
00022 
00023 #ifndef LATEXHELPERS_H
00024 #define LATEXHELPERS_H
00025 
00026 #include <QSyntaxHighlighter>
00027 #include <QXmlStreamReader>
00028 #include <QString>
00029 #include <QObject>
00030 #include <QPointer>
00031 
00032 class LatexHighlighter : public QSyntaxHighlighter
00033 {
00034     Q_OBJECT
00035 
00036     public:
00037         enum Construct {
00038             Math,
00039             Command,
00040             ScribusSpecial,
00041             BlockName,
00042             Comment,
00043             LastConstruct = Comment
00044         };
00045 
00046         LatexHighlighter(QTextDocument *document);
00047 
00048         void setFormatFor(Construct construct,
00049                           const QTextCharFormat &format);
00050         QTextCharFormat formatFor(Construct construct) const
00051         { return m_formats[construct]; }
00052     
00053     protected:
00054         enum State {
00055             NormalState = -1,
00056             InDisplayMath,
00057             InMath,
00058         };
00059     
00060         void highlightBlock(const QString &text);
00061     
00062     private:
00063         QTextCharFormat m_formats[LastConstruct + 1];
00064 };
00065 
00066 class I18nXmlStreamReader : public QXmlStreamReader
00067 {
00068     public:
00069         I18nXmlStreamReader() : QXmlStreamReader() {}
00070         I18nXmlStreamReader(QIODevice *device) : QXmlStreamReader(device) {}
00071         QString readI18nText(bool unindent=false);
00072 };
00073 
00074 class LatexConfigParser
00075 {
00076     public:
00077         LatexConfigParser() {};
00078         bool parseConfigFile(QString fn);
00079         QString executable() const { return m_executable; }
00080         QString imageExtension() const { return m_imageExtension; }
00085         QString highlighter() const; //TODO
00086         QString emptyFrameText() const { return m_emptyFrameText; }
00087         QString preamble() const { return m_preamble; }
00088         QString postamble() const { return m_postamble; }
00089         QString description() const { return m_description; }
00090         QString error() const { return m_error; }
00091         QString icon() const { return m_icon; }
00092         QString filename() const { return m_filename; }
00093         QMap<QString,QString> properties;
00094     protected:
00095         QString m_error;
00096         QString m_description, m_executable, m_imageExtension, m_emptyFrameText;
00097         QString m_preamble, m_postamble, m_highlight_kate, m_highlight_file, m_icon;
00098         QString m_filename;
00099         I18nXmlStreamReader xml;
00100         void formatError(QString message);
00101         void parseElements();
00102         void parseTab();
00103         void ignoreList();
00104 };
00105 
00106 class LatexConfigCache;
00107 class LatexConfigCache {
00108     public:
00109         static LatexConfigCache* instance();
00110         static QStringList defaultConfigs();
00111         LatexConfigCache() {}
00112         LatexConfigParser* parser(QString filename, bool warnOnError = false);
00113         bool hasError(QString filename);
00114     protected:
00115         void createParser(QString filename, bool warnOnError);
00116     private:
00117         QMap<QString, LatexConfigParser*> parsers;
00118         QMap<QString, bool> error;
00119         static LatexConfigCache *_instance;
00120 };
00121 
00122 
00123 #endif
Created with personalized Doxygen. This is documentation for GPL software Scribus - Open Source Desktop Publishing.