1/*************************************************************************************
2 * Copyright (C) 2007 by Aleix Pol <aleixpol@kde.org> *
3 * *
4 * This program is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU General Public License *
6 * as published by the Free Software Foundation; either version 2 *
7 * of the License, or (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
17 *************************************************************************************/
18
19#ifndef ALGEBRAHIGHLIGHTER_H
20#define ALGEBRAHIGHLIGHTER_H
21
22#include <QSyntaxHighlighter>
23#include "analitzaguiexport.h"
24
25/**
26 * The AlgebraHighlighter class is used to highlight the ExpressionEdit text.
27 * @author <aleixpol@kde.org>
28 */
29
30namespace Analitza { class Analyzer; }
31
32class ANALITZAGUI_EXPORT AlgebraHighlighter : public QSyntaxHighlighter
33{
34 public:
35 /** Defines the format status that could be used. */
36 typedef enum {
37 Expression, /**< String expression format. */
38 MathML, /**< MathML format. */
39 Autodetect /**< Try to guess which format is being used. */
40 } Mode;
41
42 /** Constructor. Creates an AlgebraHighlighter from a QTextDocument @p doc. */
43 explicit AlgebraHighlighter(QTextDocument *doc, const Analitza::Analyzer* na=0);
44 //int highlightParagraph(const QString &text, int endStateOfLastPara);
45
46 /** Returns the currently highlight mode. */
47 Mode mode() { return m_mode; }
48
49 /** Sets the highlight mode. */
50 void setMode(const Mode& newMode){ m_mode=newMode; rehighlight(); }
51
52 /**
53 * Returns whether something wrong has been found. It is an uncomplete way
54 * to know if it is correct because doesn't do any recursive check, but could be useful.
55 * @returns whether it is a lexically correct expression.
56 */
57 bool isCorrect() const { return m_correct; }
58
59 /** Sets the cursor position. */
60 void setPos(uint p) { m_pos=p; }
61
62 /** Sets the corresponding Analitza class. */
63 void setAnalitza(const Analitza::Analyzer* na) { a = na; }
64
65 ///@returns the name of the function that's being edited, if any
66 QString editingName() const;
67
68 ///@returns the number of the parameter that's being edited
69 int editingParameter() const;
70 bool editingBounds() const;
71 private:
72 void highlightBlock(const QString &text);
73
74 enum MMLtokEnum { //For mathml highlighting
75 gt,
76 lt,
77 tag,
78 value
79 };
80
81 bool m_correct;
82 int antnum;
83 Mode m_mode;
84 uint m_pos;
85 int m_editingParameter;
86 QString m_editingName;
87 bool m_editingBounds;
88 QString m_aName;
89
90 QTextCharFormat bold;
91 const Analitza::Analyzer* a;
92};
93
94#endif
95