2022-01-06 19:29:19 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-02-21 18:03:38 +00:00
|
|
|
#include <QRegularExpression>
|
2022-01-06 19:29:19 +00:00
|
|
|
#include <QSyntaxHighlighter>
|
|
|
|
#include <QTextCharFormat>
|
|
|
|
|
|
|
|
class QQuickTextDocument;
|
|
|
|
|
|
|
|
class StatusSyntaxHighlighter : public QSyntaxHighlighter
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2022-02-21 18:03:38 +00:00
|
|
|
StatusSyntaxHighlighter(QTextDocument* parent = nullptr);
|
2022-01-06 19:29:19 +00:00
|
|
|
|
|
|
|
protected:
|
2022-02-21 18:03:38 +00:00
|
|
|
void highlightBlock(const QString& text) override;
|
2022-01-06 19:29:19 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct HighlightingRule
|
|
|
|
{
|
|
|
|
QRegularExpression pattern;
|
|
|
|
QTextCharFormat format;
|
|
|
|
};
|
|
|
|
QVector<HighlightingRule> highlightingRules;
|
|
|
|
|
|
|
|
QTextCharFormat singlelineBoldFormat;
|
|
|
|
QTextCharFormat singleLineItalicFormat;
|
|
|
|
QTextCharFormat singlelineCodeBlockFormat;
|
|
|
|
QTextCharFormat singleLineStrikeThroughFormat;
|
|
|
|
QTextCharFormat multiLineCodeBlockFormat;
|
|
|
|
};
|
|
|
|
|
2022-02-21 18:03:38 +00:00
|
|
|
class StatusSyntaxHighlighterHelper : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QQuickTextDocument* quickTextDocument READ quickTextDocument WRITE setQuickTextDocument NOTIFY
|
|
|
|
quickTextDocumentChanged)
|
2022-01-06 19:29:19 +00:00
|
|
|
public:
|
2022-02-21 18:03:38 +00:00
|
|
|
StatusSyntaxHighlighterHelper(QObject* parent = nullptr)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_quicktextdocument(nullptr)
|
|
|
|
{ }
|
|
|
|
QQuickTextDocument* quickTextDocument() const;
|
|
|
|
void setQuickTextDocument(QQuickTextDocument* quickTextDocument);
|
2022-01-06 19:29:19 +00:00
|
|
|
signals:
|
2022-02-21 18:03:38 +00:00
|
|
|
void quickTextDocumentChanged();
|
2022-01-06 19:29:19 +00:00
|
|
|
|
|
|
|
private:
|
2022-02-21 18:03:38 +00:00
|
|
|
QQuickTextDocument* m_quicktextdocument;
|
2022-01-06 19:29:19 +00:00
|
|
|
};
|