File indexing completed on 2024-12-22 04:28:11
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "textcustomeditor_export.h" 0010 0011 #include <KSyntaxHighlighting/SyntaxHighlighter> 0012 #include <Sonnet/Highlighter> 0013 0014 namespace KSyntaxHighlighting 0015 { 0016 class Format; 0017 } 0018 0019 namespace TextCustomEditor 0020 { 0021 class PlainTextEditor; 0022 class PlainTextSyntaxSpellCheckingHighlighterPrivate; 0023 /** 0024 * @brief The PlainTextSyntaxSpellCheckingHighlighter class 0025 * @author Laurent Montel <montel@kde.org> 0026 */ 0027 class TEXTCUSTOMEDITOR_EXPORT PlainTextSyntaxSpellCheckingHighlighter : public Sonnet::Highlighter, public KSyntaxHighlighting::AbstractHighlighter 0028 { 0029 public: 0030 explicit PlainTextSyntaxSpellCheckingHighlighter(PlainTextEditor *plainText, const QColor &misspelledColor = Qt::red); 0031 ~PlainTextSyntaxSpellCheckingHighlighter() override; 0032 0033 void toggleSpellHighlighting(bool on); 0034 0035 void setDefinition(const KSyntaxHighlighting::Definition &def) override; 0036 0037 /** 0038 * Reimplemented to highlight quote blocks. 0039 */ 0040 void highlightBlock(const QString &text) override; 0041 0042 protected: 0043 /** 0044 * Reimplemented, the base version sets the text color to black, which 0045 * is not what we want. We do nothing, the format is already reset by 0046 * Qt. 0047 * @param start the beginning of text 0048 * @param count the amount of characters to set 0049 */ 0050 void unsetMisspelled(int start, int count) override; 0051 0052 /** 0053 * Reimplemented to set the color of the misspelled word to a color 0054 * defined by setQuoteColor(). 0055 */ 0056 void setMisspelled(int start, int count) override; 0057 0058 void applyFormat(int offset, int length, const KSyntaxHighlighting::Format &format) override; 0059 0060 private: 0061 std::unique_ptr<PlainTextSyntaxSpellCheckingHighlighterPrivate> const d; 0062 }; 0063 }