| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#ifndef HIGHLIGHTER_H |
| 24 |
#define HIGHLIGHTER_H |
| 25 |
|
| 26 |
#include <QSyntaxHighlighter> |
| 27 |
|
| 28 |
#include <QHash> |
| 29 |
#include <QTextCharFormat> |
| 30 |
#include <QStringList> |
| 31 |
#include <QRegularExpression> |
| 32 |
|
| 33 |
#include <QTextDocument> |
| 34 |
|
| 35 |
enum CsdSection { UnknownSection, OptionsSection, OrchestraSection, ScoreSection }; |
| 36 |
|
| 37 |
struct ParenthesisInfo |
| 38 |
{ |
| 39 |
char character; |
| 40 |
int position; |
| 41 |
}; |
| 42 |
|
| 43 |
class TextBlockData : public QTextBlockUserData |
| 44 |
{ |
| 45 |
public: |
| 46 |
TextBlockData(); |
| 47 |
|
| 48 |
QVector<ParenthesisInfo *> parentheses(); |
| 49 |
void insert(ParenthesisInfo *info); |
| 50 |
CsdSection section; |
| 51 |
void clearParenthesis() { m_parentheses.clear(); } |
| 52 |
|
| 53 |
private: |
| 54 |
QVector<ParenthesisInfo *> m_parentheses; |
| 55 |
|
| 56 |
}; |
| 57 |
|
| 58 |
class Highlighter : public QSyntaxHighlighter |
| 59 |
{ |
| 60 |
Q_OBJECT |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public: |
| 66 |
Highlighter(QTextDocument *parent = 0); |
| 67 |
~Highlighter(); |
| 68 |
void setOpcodeNameList(QStringList list); |
| 69 |
void setDisabledOpcodes(QStringList list); |
| 70 |
void setColorVariables(bool color); |
| 71 |
void setMode(int mode); |
| 72 |
void setTheme(const QString &theme); |
| 73 |
void enableScoreSyntaxHighlighting(bool status) { |
| 74 |
m_scoreSyntaxHighlighting = status; |
| 75 |
} |
| 76 |
QTextCharFormat getFormat(QString tag); |
| 77 |
|
| 78 |
|
| 79 |
enum Construct { |
| 80 |
Entity, |
| 81 |
Tag, |
| 82 |
Comment, |
| 83 |
LastConstruct = Comment |
| 84 |
}; |
| 85 |
|
| 86 |
void setFormatFor(Construct construct, const QTextCharFormat &format); |
| 87 |
QTextCharFormat formatFor(Construct construct) const |
| 88 |
{ return m_formats[construct]; } |
| 89 |
|
| 90 |
void setUDOs(QStringList udos); |
| 91 |
|
| 92 |
protected: |
| 93 |
enum State { |
| 94 |
NormalState = -1, |
| 95 |
InComment, |
| 96 |
InTag |
| 97 |
}; |
| 98 |
|
| 99 |
|
| 100 |
protected: |
| 101 |
void highlightBlock(const QString &text); |
| 102 |
void highlightCsoundBlock(const QString &text); |
| 103 |
void highlightPythonBlock(const QString &text); |
| 104 |
void highlightXmlBlock(const QString &text); |
| 105 |
void highlightHtmlBlock(const QString &text); |
| 106 |
void highlightScore(const QString &text, int start, int end); |
| 107 |
int findOpcode(QString opcodeName, int start = 0, int end = -1); |
| 108 |
bool isOpcode(QString name); |
| 109 |
|
| 110 |
private: |
| 111 |
struct HighlightingRule |
| 112 |
{ |
| 113 |
QRegularExpression pattern; |
| 114 |
QTextCharFormat format; |
| 115 |
int group; |
| 116 |
}; |
| 117 |
QVector<HighlightingRule> highlightingRules; |
| 118 |
QVector<HighlightingRule> lastHighlightingRules; |
| 119 |
|
| 120 |
QRegularExpression commentStartExpression; |
| 121 |
QRegularExpression commentEndExpression; |
| 122 |
QRegularExpression rxScoreLetter; |
| 123 |
QRegularExpression rxQuotation; |
| 124 |
|
| 125 |
QTextCharFormat csdtagFormat, instFormat, headerFormat; |
| 126 |
QTextCharFormat irateFormat, krateFormat, arateFormat, girateFormat, gkrateFormat, garateFormat; |
| 127 |
QTextCharFormat stringVarFormat, gstringVarFormat, fsigFormat, gfsigFormat; |
| 128 |
QTextCharFormat opcodeFormat, udoFormat, macroDefineFormat, pfieldFormat; |
| 129 |
QTextCharFormat singleLineCommentFormat, importantCommentFormat; |
| 130 |
QTextCharFormat multiLineCommentFormat; |
| 131 |
QTextCharFormat quotationFormat; |
| 132 |
QTextCharFormat functionFormat; |
| 133 |
QTextCharFormat nameFormat; |
| 134 |
QTextCharFormat ioFormat; |
| 135 |
QTextCharFormat deprecatedFormat; |
| 136 |
QTextCharFormat operatorFormat; |
| 137 |
QTextCharFormat scoreLetterFormat; |
| 138 |
QTextCharFormat errorFormat; |
| 139 |
|
| 140 |
QTextCharFormat labelFormat; |
| 141 |
QTextCharFormat csoundOptionFormat; |
| 142 |
QTextCharFormat defaultFormat; |
| 143 |
|
| 144 |
QStringList tagPatterns, headerPatterns, instPatterns, |
| 145 |
keywordLiterals, htmlKeywords, javascriptKeywords, |
| 146 |
csoundOptions, ioPatterns; |
| 147 |
QStringList operatorPatterns; |
| 148 |
|
| 149 |
QSet<QString> deprecatedOpcodes; |
| 150 |
|
| 151 |
|
| 152 |
QStringList pythonKeywords; |
| 153 |
QTextCharFormat keywordFormat; |
| 154 |
QRegularExpression csoundOptionsRx, csoundOptionsRx2; |
| 155 |
|
| 156 |
|
| 157 |
void setLastRules(); |
| 158 |
|
| 159 |
QStringList m_opcodeList; |
| 160 |
QSet<QString> m_opcodesSet; |
| 161 |
|
| 162 |
bool colorVariables; |
| 163 |
|
| 164 |
int m_mode; |
| 165 |
|
| 166 |
bool m_scoreSyntaxHighlighting; |
| 167 |
|
| 168 |
QString m_theme; |
| 169 |
|
| 170 |
|
| 171 |
QTextCharFormat jsKeywordFormat, htmlTagFormat; |
| 172 |
QTextCharFormat m_formats[LastConstruct + 1]; |
| 173 |
|
| 174 |
QStringList m_parsedUDOs; |
| 175 |
}; |
| 176 |
|
| 177 |
#endif |