latexhelpers.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 #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;
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