status-desktop/src-cpp/dotherside/StatusSyntaxHighlighter.h

52 lines
1.3 KiB
C
Raw Normal View History

2022-01-06 19:29:19 +00:00
#pragma once
#include <QRegularExpression>
2022-01-06 19:29:19 +00:00
#include <QSyntaxHighlighter>
#include <QTextCharFormat>
class QQuickTextDocument;
class StatusSyntaxHighlighter : public QSyntaxHighlighter
{
Q_OBJECT
public:
StatusSyntaxHighlighter(QTextDocument* parent = nullptr);
2022-01-06 19:29:19 +00:00
protected:
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;
};
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:
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:
void quickTextDocumentChanged();
2022-01-06 19:29:19 +00:00
private:
QQuickTextDocument* m_quicktextdocument;
2022-01-06 19:29:19 +00:00
};