File indexing completed on 2024-05-19 05:21:44
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 "kpimtextedit_export.h" 0010 #include <memory> 0011 #include <sonnet/highlighter.h> 0012 namespace KPIMTextEdit 0013 { 0014 class RichTextComposer; 0015 /** 0016 * @short A highlighter for email quoting. 0017 * 0018 * @author Laurent Montel <montel@kde.org> 0019 */ 0020 class RichTextComposer; 0021 class KPIMTEXTEDIT_EXPORT RichTextComposerEmailQuoteHighlighter : public Sonnet::Highlighter 0022 { 0023 Q_OBJECT 0024 public: 0025 /** 0026 * Constructor. See setQuoteColor() for the parameters. 0027 * FIXME: Default colors don't obey color scheme 0028 */ 0029 explicit RichTextComposerEmailQuoteHighlighter(RichTextComposer *textEdit, 0030 const QColor &normalColor = Qt::black, 0031 const QColor "eDepth1 = QColor(0x00, 0x80, 0x00), 0032 const QColor "eDepth2 = QColor(0x00, 0x80, 0x00), 0033 const QColor "eDepth3 = QColor(0x00, 0x80, 0x00), 0034 const QColor &misspelledColor = Qt::red); 0035 0036 ~RichTextComposerEmailQuoteHighlighter() override; 0037 0038 /** 0039 * Sets the colors used for highlighting quoted text and spelling mistakes. 0040 * 0041 * @param quoteDepth1 color for text quoted 1 level deep 0042 * @param quoteDepth2 color for text quoted 2 level deep 0043 * @param quoteDepth3 color for text quoted 3 level deep 0044 * @param misspelledColor color in which misspelled words will be underlined 0045 * @param normalColor will be ignored, only provided for KNode 0046 * compatibility. 0047 */ 0048 void setQuoteColor(const QColor &normalColor, 0049 const QColor "eDepth1, 0050 const QColor "eDepth2, 0051 const QColor "eDepth3, 0052 const QColor &misspelledColor = Qt::red); 0053 0054 /** 0055 * Turns spellcheck highlighting on or off. 0056 * 0057 * @param on if true, spelling mistakes will be highlighted 0058 */ 0059 void toggleSpellHighlighting(bool on); 0060 0061 /** 0062 * Reimplemented to highlight quote blocks. 0063 */ 0064 void highlightBlock(const QString &text) override; 0065 0066 protected: 0067 /** 0068 * Reimplemented, the base version sets the text color to black, which 0069 * is not what we want. We do nothing, the format is already reset by 0070 * Qt. 0071 * @param start the beginning of text 0072 * @param count the amount of characters to set 0073 */ 0074 void unsetMisspelled(int start, int count) override; 0075 0076 /** 0077 * Reimplemented to set the color of the misspelled word to a color 0078 * defined by setQuoteColor(). 0079 */ 0080 void setMisspelled(int start, int count) override; 0081 0082 private: 0083 class RichTextComposerEmailQuoteHighlighterPrivate; 0084 std::unique_ptr<RichTextComposerEmailQuoteHighlighterPrivate> const d; 0085 }; 0086 }