1 | /** |
2 | * Copyright (C) 2006 Laurent Montel <montel@kde.org> |
3 | * Copyright (C) 2008 Thomas McGuire <mcguire@kde.org> |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Lesser General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2.1 of the License, or (at your option) any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Lesser General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Lesser General Public |
16 | * License along with this library; if not, write to the Free Software |
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | * 02110-1301 USA |
19 | */ |
20 | #ifndef KPIMTEXTEDIT_EMAILQUOTEHIGHLIGHTER_H |
21 | #define KPIMTEXTEDIT_EMAILQUOTEHIGHLIGHTER_H |
22 | |
23 | #include "kpimtextedit_export.h" |
24 | |
25 | #include <sonnet/highlighter.h> |
26 | |
27 | #include <memory> |
28 | |
29 | namespace KPIMTextEdit { |
30 | |
31 | class TextEdit; |
32 | |
33 | /** |
34 | * This highlighter highlights spelling mistakes and also highlightes |
35 | * quotes. |
36 | * |
37 | * Spelling mistakes inside quotes will not be highlighted. |
38 | * The quote highlighting color is configurable. |
39 | * |
40 | * Spell highlighting is disabled by default but can be toggled. |
41 | * |
42 | * @since 4.3 |
43 | */ |
44 | class KPIMTEXTEDIT_EXPORT EMailQuoteHighlighter : public Sonnet::Highlighter |
45 | { |
46 | public: |
47 | |
48 | /** |
49 | * Constructor. See setQuoteColor() for the parameters. |
50 | * FIXME: Default colors don't obey color scheme |
51 | */ |
52 | explicit EMailQuoteHighlighter( TextEdit *textEdit, |
53 | const QColor &normalColor = Qt::black, |
54 | const QColor "eDepth1 = QColor( 0x00, 0x80, 0x00 ), |
55 | const QColor "eDepth2 = QColor( 0x00, 0x80, 0x00 ), |
56 | const QColor "eDepth3 = QColor( 0x00, 0x80, 0x00 ), |
57 | const QColor &misspelledColor = Qt::red ); |
58 | |
59 | ~EMailQuoteHighlighter(); |
60 | |
61 | /** |
62 | * Sets the colors used for highlighting quoted text and spelling mistakes. |
63 | * |
64 | * @param quoteDepth1 color for text quoted 1 level deep |
65 | * @param quoteDepth2 color for text quoted 2 level deep |
66 | * @param quoteDepth3 color for text quoted 3 level deep |
67 | * @param misspelledColor color in which misspelled words will be underlined |
68 | * @param normalColor will be ignored, only provided for KNode |
69 | * compatibility. |
70 | */ |
71 | void setQuoteColor( const QColor &normalColor, |
72 | const QColor "eDepth1, |
73 | const QColor "eDepth2, |
74 | const QColor "eDepth3, |
75 | const QColor &misspelledColor = Qt::red ); |
76 | |
77 | /** |
78 | * Turns spellcheck highlighting on or off. |
79 | * |
80 | * @param on if true, spelling mistakes will be highlighted |
81 | */ |
82 | void toggleSpellHighlighting( bool on ); |
83 | |
84 | /** |
85 | * Reimplemented to highlight quote blocks. |
86 | */ |
87 | virtual void highlightBlock ( const QString & text ); |
88 | |
89 | /** |
90 | * Use this static method to get a text consisting of multiple lines |
91 | * highligted. |
92 | * @since 4.4 |
93 | */ |
94 | static QString highlightText( const QString &text, |
95 | const QColor "eDepth1 = QColor( 0x00, 0x80, 0x00 ), |
96 | const QColor "eDepth2 = QColor( 0x00, 0x80, 0x00 ), |
97 | const QColor "eDepth3 = QColor( 0x00, 0x80, 0x00 ) ); |
98 | |
99 | /** |
100 | * Use this static method to get proper highlighting for a single line. |
101 | * @since 4.4 |
102 | */ |
103 | static QString highlightParagraph( const QString &text, |
104 | const QColor "eDepth1 = QColor( 0x00, 0x80, 0x00 ), |
105 | const QColor "eDepth2 = QColor( 0x00, 0x80, 0x00 ), |
106 | const QColor "eDepth3 = QColor( 0x00, 0x80, 0x00 ) ); |
107 | |
108 | protected: |
109 | |
110 | /** |
111 | * Reimplemented, the base version sets the text color to black, which |
112 | * is not what we want. We do nothing, the format is already reset by |
113 | * Qt. |
114 | * @param start the beginning of text |
115 | * @param count the amount of characters to set |
116 | */ |
117 | virtual void unsetMisspelled( int start, int count ); |
118 | |
119 | /** |
120 | * Reimplemented to set the color of the misspelled word to a color |
121 | * defined by setQuoteColor(). |
122 | */ |
123 | virtual void setMisspelled( int start, int count ); |
124 | |
125 | private: |
126 | class EMailQuoteHighlighterPrivate; |
127 | std::auto_ptr<EMailQuoteHighlighterPrivate> d; |
128 | }; |
129 | |
130 | } |
131 | |
132 | #endif |
133 | |