2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#ifndef HIGHLIGHTER_H
|
|
|
|
#define HIGHLIGHTER_H
|
|
|
|
|
|
|
|
#include <QSyntaxHighlighter>
|
|
|
|
#include <QTextCharFormat>
|
2017-01-19 10:36:59 +00:00
|
|
|
#include <QRegularExpression>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
class QTextDocument;
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
//! [0]
|
|
|
|
class Highlighter : public QSyntaxHighlighter
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-10-07 11:05:48 +00:00
|
|
|
Highlighter(QTextDocument *parent = nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
protected:
|
2016-06-15 08:12:35 +00:00
|
|
|
void highlightBlock(const QString &text) override;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct HighlightingRule
|
|
|
|
{
|
2017-01-19 10:36:59 +00:00
|
|
|
QRegularExpression pattern;
|
2011-04-27 10:05:43 +00:00
|
|
|
QTextCharFormat format;
|
|
|
|
};
|
2020-06-22 08:12:38 +00:00
|
|
|
QList<HighlightingRule> highlightingRules;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2017-01-19 10:36:59 +00:00
|
|
|
QRegularExpression commentStartExpression;
|
|
|
|
QRegularExpression commentEndExpression;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QTextCharFormat keywordFormat;
|
|
|
|
QTextCharFormat classFormat;
|
|
|
|
QTextCharFormat singleLineCommentFormat;
|
|
|
|
QTextCharFormat multiLineCommentFormat;
|
|
|
|
QTextCharFormat quotationFormat;
|
|
|
|
QTextCharFormat functionFormat;
|
|
|
|
};
|
|
|
|
//! [0]
|
|
|
|
|
2012-11-23 12:36:40 +00:00
|
|
|
#endif // HIGHLIGHTER_H
|