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