44 lines
861 B
C++
44 lines
861 B
C++
#ifndef HTMLHIGHLIGHTER_H
|
|
#define HTMLHIGHLIGHTER_H
|
|
|
|
#include <QSyntaxHighlighter>
|
|
#include <QTextCharFormat>
|
|
#include <QTextEdit>
|
|
|
|
/* HTML syntax highlighter based on Qt Quarterly example */
|
|
class HtmlHighlighter : public QSyntaxHighlighter
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
enum Construct {
|
|
Entity,
|
|
Tag,
|
|
Comment,
|
|
Attribute,
|
|
Value,
|
|
LastConstruct = Value
|
|
};
|
|
|
|
HtmlHighlighter(QTextEdit *textEdit);
|
|
|
|
void setFormatFor(Construct construct, const QTextCharFormat &format);
|
|
|
|
QTextCharFormat formatFor(Construct construct) const
|
|
{ return m_formats[construct]; }
|
|
|
|
protected:
|
|
enum State {
|
|
NormalState = -1,
|
|
InComment,
|
|
InTag
|
|
};
|
|
|
|
void highlightBlock(const QString &text) override;
|
|
|
|
private:
|
|
QTextCharFormat m_formats[LastConstruct + 1];
|
|
};
|
|
|
|
#endif // HTMLHIGHLIGHTER_H
|