File indexing completed on 2024-04-28 07:46:38
0001 /* 0002 SPDX-FileCopyrightText: 2008-2009 Michel Ludwig <michel.ludwig@kdemail.net> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef SPELLCHECK_H 0008 #define SPELLCHECK_H 0009 0010 #include <QList> 0011 #include <QObject> 0012 #include <QPair> 0013 #include <QString> 0014 0015 #include <ktexteditor/document.h> 0016 #include <sonnet/backgroundchecker.h> 0017 #include <sonnet/speller.h> 0018 0019 namespace KTextEditor 0020 { 0021 class DocumentPrivate; 0022 } 0023 0024 class KateSpellCheckManager : public QObject 0025 { 0026 Q_OBJECT 0027 0028 typedef QPair<KTextEditor::Range, QString> RangeDictionaryPair; 0029 0030 public: 0031 explicit KateSpellCheckManager(QObject *parent = nullptr); 0032 ~KateSpellCheckManager() override; 0033 0034 static QStringList suggestions(const QString &word, const QString &dictionary); 0035 0036 void ignoreWord(const QString &word, const QString &dictionary); 0037 void addToDictionary(const QString &word, const QString &dictionary); 0038 0039 /** 0040 * 'r2' is a subrange of 'r1', which is extracted from 'r1' and the remaining ranges are returned 0041 **/ 0042 static QList<KTextEditor::Range> rangeDifference(KTextEditor::Range r1, KTextEditor::Range r2); 0043 0044 Q_SIGNALS: 0045 /** 0046 * These signals are used to propagate the dictionary changes to the 0047 * BackgroundChecker instance in other components (e.g. onTheFlyChecker). 0048 */ 0049 void wordAddedToDictionary(const QString &word); 0050 void wordIgnored(const QString &word); 0051 0052 public: 0053 static QList<QPair<KTextEditor::Range, QString>> spellCheckLanguageRanges(KTextEditor::DocumentPrivate *doc, KTextEditor::Range range); 0054 0055 QList<QPair<KTextEditor::Range, QString>> spellCheckWrtHighlightingRanges(KTextEditor::DocumentPrivate *doc, 0056 KTextEditor::Range range, 0057 const QString &dictionary = QString(), 0058 bool singleLine = false, 0059 bool returnSingleRange = false); 0060 QList<QPair<KTextEditor::Range, QString>> spellCheckRanges(KTextEditor::DocumentPrivate *doc, KTextEditor::Range range, bool singleLine = false); 0061 0062 static void replaceCharactersEncodedIfNecessary(const QString &newWord, KTextEditor::DocumentPrivate *doc, KTextEditor::Range replacementRange); 0063 0064 private: 0065 static void trimRange(KTextEditor::DocumentPrivate *doc, KTextEditor::Range &r); 0066 }; 0067 0068 #endif