Scribus
Open source desktop publishing at your fingertips
latexhelpers.h
1 //Based on http://doc.trolltech.com/qq/qq21-syntaxhighlighter.html#example
2 /*
3 For general Scribus (>=1.3.2) copyright and licensing information please refer
4 to the COPYING file provided with the program. Following this notice may exist
5 a copyright and/or license notice that predates the release of Scribus 1.3.2
6 for which a new license (GPL+exception) is in place.
7 */
8 /***************************************************************************
9  latexhelpers.h - description
10  -------------------
11 copyright : Scribus Team
12 ***************************************************************************/
13 
14 /***************************************************************************
15 * *
16 * This program is free software; you can redistribute it and/or modify *
17 * it under the terms of the GNU General Public License as published by *
18 * the Free Software Foundation; either version 2 of the License, or *
19 * (at your option) any later version. *
20 * *
21 ***************************************************************************/
22 
23 #ifndef LATEXHELPERS_H
24 #define LATEXHELPERS_H
25 
26 #include <QSyntaxHighlighter>
27 #include <QXmlStreamReader>
28 #include <QString>
29 #include <QObject>
30 #include <QPointer>
31 
33 {
34  public:
35  LatexHighlighterRule(){multiline=false;}
36  QRegExp regex;
37  QTextCharFormat format;
38  bool multiline;
39 };
40 
41 class LatexHighlighter : public QSyntaxHighlighter
42 {
43  Q_OBJECT
44 
45  public:
46  LatexHighlighter(QTextDocument *document);
47  void setConfig(QList<LatexHighlighterRule *> *config) { rules = config; rehighlight();}
48  protected:
49  void highlightBlock(const QString &text);
50  private:
51  QList<LatexHighlighterRule *> *rules;
52 };
53 
54 class I18nXmlStreamReader : public QXmlStreamReader
55 {
56  public:
57  I18nXmlStreamReader() : QXmlStreamReader() {}
58  I18nXmlStreamReader(QIODevice *device) : QXmlStreamReader(device) {}
59  QString readI18nText(bool unindent=false);
60 };
61 
63 {
64  public:
65  LatexConfigParser() {};
66  static QString absoluteFilename(QString fn);
67  static QString configBase();
68  bool parseConfigFile(QString fn);
69  QString executable() const;
70  QString imageExtension() const { return m_imageExtension; }
71  QString emptyFrameText() const { return m_emptyFrameText; }
72  QString preamble() const { return m_preamble; }
73  QString postamble() const { return m_postamble; }
74  QString description() const { return m_description; }
75  QString error() const { return m_error; }
76  QString icon() const { return m_icon; }
77  QString filename() const { return m_filename; }
78  QMap<QString,QString> properties;
79  QList<LatexHighlighterRule *> highlighterRules;
80  protected:
81  QString m_error;
82  QString m_description, m_executable, m_imageExtension, m_emptyFrameText;
83  QString m_preamble, m_postamble, m_icon;
84  QString m_filename;
86  void formatError(QString message);
87  void parseElements();
88  void parseTab();
89  void parseHighlighter();
90  void ignoreList();
91  bool StrRefToBool(const QStringRef &str) const;
92 };
93 
94 class LatexConfigCache;
96  public:
97  static LatexConfigCache* instance();
98  static QStringList defaultConfigs();
99  static QMap<QString, QString> defaultCommands();
100  LatexConfigCache() {}
101  LatexConfigParser* parser(QString filename, bool warnOnError = false);
102  bool hasError(QString filename);
103  protected:
104  void createParser(QString filename, bool warnOnError);
105  private:
106  QMap<QString, LatexConfigParser*> parsers;
107  QMap<QString, bool> error;
108  static LatexConfigCache *_instance;
109 };
110 
111 
112 #endif
Definition: latexhelpers.h:41
Definition: latexhelpers.h:95
Definition: latexhelpers.h:32
Definition: latexhelpers.h:62
Definition: latexhelpers.h:54