2023-05-08 17:11:54 +02:00
|
|
|
// Copyright (C) 2023 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-12-14 16:04:07 +01:00
|
|
|
#include <texteditor/fontsettings.h>
|
2023-05-08 17:11:54 +02:00
|
|
|
#include <texteditor/syntaxhighlighter.h>
|
2023-12-14 16:04:07 +01:00
|
|
|
#include <texteditor/texteditorsettings.h>
|
2023-05-08 17:11:54 +02:00
|
|
|
|
|
|
|
|
#include <KSyntaxHighlighting/Definition>
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QPointer>
|
|
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QTextDocument;
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
|
|
namespace TextEditor {
|
|
|
|
|
|
|
|
|
|
class SyntaxHighlighterRunnerPrivate;
|
|
|
|
|
|
|
|
|
|
class TEXTEDITOR_EXPORT BaseSyntaxHighlighterRunner : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
using SyntaxHighLighterCreator = std::function<SyntaxHighlighter *()>;
|
|
|
|
|
struct BlockPreeditData {
|
|
|
|
|
int position;
|
|
|
|
|
QString text;
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 16:04:07 +01:00
|
|
|
BaseSyntaxHighlighterRunner(SyntaxHighLighterCreator creator,
|
|
|
|
|
QTextDocument *document,
|
|
|
|
|
const TextEditor::FontSettings &fontSettings
|
|
|
|
|
= TextEditorSettings::fontSettings());
|
2023-05-08 17:11:54 +02:00
|
|
|
virtual ~BaseSyntaxHighlighterRunner();
|
|
|
|
|
|
|
|
|
|
void setExtraFormats(const QMap<int, QList<QTextLayout::FormatRange>> &formats);
|
|
|
|
|
void clearExtraFormats(const QList<int> &blockNumbers);
|
|
|
|
|
void clearAllExtraFormats();
|
|
|
|
|
void setFontSettings(const TextEditor::FontSettings &fontSettings);
|
|
|
|
|
void setLanguageFeaturesFlags(unsigned int flags);
|
|
|
|
|
void setEnabled(bool enabled);
|
|
|
|
|
void rehighlight();
|
|
|
|
|
|
2023-11-28 14:58:58 +01:00
|
|
|
QString definitionName();
|
|
|
|
|
void setDefinitionName(const QString &name);
|
2023-05-08 17:11:54 +02:00
|
|
|
|
|
|
|
|
QTextDocument *document() const { return m_document; }
|
|
|
|
|
SyntaxHighLighterCreator creator() const { return m_creator; }
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
std::unique_ptr<SyntaxHighlighterRunnerPrivate> d;
|
|
|
|
|
QPointer<QTextDocument> m_document = nullptr;
|
|
|
|
|
void applyFormatRanges(const SyntaxHighlighter::Result &result);
|
|
|
|
|
void cloneDocumentData(int from, int charsRemoved, int charsAdded);
|
|
|
|
|
void cloneDocument(int from,
|
|
|
|
|
int charsRemoved,
|
|
|
|
|
const QString textAdded,
|
|
|
|
|
const QMap<int, BlockPreeditData> &blocksPreedit);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
SyntaxHighLighterCreator m_creator;
|
2023-11-28 14:58:58 +01:00
|
|
|
QString m_definitionName;
|
2023-05-08 17:11:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TEXTEDITOR_EXPORT ThreadedSyntaxHighlighterRunner : public BaseSyntaxHighlighterRunner
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ThreadedSyntaxHighlighterRunner(SyntaxHighLighterCreator SyntaxHighLighterCreator,
|
|
|
|
|
QTextDocument *document);
|
|
|
|
|
~ThreadedSyntaxHighlighterRunner();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QThread m_thread;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace TextEditor
|
|
|
|
|
|