2014-04-28 21:09:25 +04:00
|
|
|
#pragma once
|
2010-01-30 07:26:05 +03:00
|
|
|
|
|
|
|
#include <QSyntaxHighlighter>
|
2014-02-18 06:30:43 +04:00
|
|
|
#include <QTextDocument>
|
2013-01-13 03:37:20 +04:00
|
|
|
#include <QTextFormat>
|
2014-02-17 23:19:42 +04:00
|
|
|
#include <QTextEdit>
|
2013-01-13 03:37:20 +04:00
|
|
|
#include <QHash>
|
2010-01-30 07:26:05 +03:00
|
|
|
|
|
|
|
class Highlighter : public QSyntaxHighlighter
|
|
|
|
{
|
2014-02-17 23:19:42 +04:00
|
|
|
Q_OBJECT
|
2010-01-30 07:26:05 +03:00
|
|
|
public:
|
2013-01-09 07:15:14 +04:00
|
|
|
enum state_e {NORMAL=-1,QUOTE,COMMENT};
|
2013-01-13 06:07:15 +04:00
|
|
|
QHash<QString, QTextCharFormat> tokenFormats;
|
2013-12-30 01:25:35 +04:00
|
|
|
QTextCharFormat errorFormat;
|
2013-01-13 00:05:10 +04:00
|
|
|
Highlighter(QTextDocument *parent);
|
2010-01-30 07:26:05 +03:00
|
|
|
void highlightBlock(const QString &text);
|
2014-02-17 23:19:42 +04:00
|
|
|
void assignFormatsToTokens(const QString &);
|
|
|
|
void portable_rehighlightBlock( const QTextBlock &text );
|
2013-01-13 00:05:10 +04:00
|
|
|
void highlightError(int error_pos);
|
|
|
|
void unhighlightLastError();
|
|
|
|
private:
|
|
|
|
QTextBlock lastErrorBlock;
|
2013-01-13 03:01:24 +04:00
|
|
|
int errorPos;
|
|
|
|
bool errorState;
|
2013-01-13 03:37:20 +04:00
|
|
|
QMap<QString,QStringList> tokentypes;
|
|
|
|
QMap<QString,QTextCharFormat> typeformats;
|
|
|
|
int lastDocumentPos();
|
2010-01-30 07:26:05 +03:00
|
|
|
};
|