21 #include "emailquotehighlighter.h"
25 namespace KPIMTextEdit {
27 class EMailQuoteHighlighter::EMailQuoteHighlighterPrivate
30 QColor col1, col2, col3, misspelledColor;
31 bool spellCheckingEnabled;
36 const QColor &normalColor,
37 const QColor "eDepth1,
38 const QColor "eDepth2,
39 const QColor "eDepth3,
40 const QColor &misspelledColor )
41 : Highlighter( textEdit, textEdit->configFile() ),
42 d( new EMailQuoteHighlighterPrivate() )
44 Q_UNUSED( normalColor );
48 setAutomatic(
false );
51 d->col1 = quoteDepth1;
52 d->col2 = quoteDepth2;
53 d->col3 = quoteDepth3;
54 d->misspelledColor = misspelledColor;
55 d->spellCheckingEnabled =
false;
59 EMailQuoteHighlighter::~EMailQuoteHighlighter()
64 const QColor "eDepth1,
65 const QColor "eDepth2,
66 const QColor "eDepth3 )
68 const QStringList splitList = text.split( QLatin1Char(
'\n' ) );
70 QStringList::const_iterator it = splitList.constBegin();
71 QStringList::const_iterator end = splitList.constEnd();
74 quoteDepth1, quoteDepth2, quoteDepth3 ) );
81 const QColor "eDepth1,
82 const QColor "eDepth2,
83 const QColor "eDepth3 )
85 QString simplified = text;
86 simplified = simplified.remove( QRegExp( QLatin1String(
"\\s" ) ) ).
87 replace( QLatin1Char(
'|' ), QLatin1Char(
'>' ) ).
88 replace( QLatin1String(
">" ), QLatin1String(
">" ) );
90 while ( simplified.startsWith( QLatin1String(
">>>>" ) ) )
91 simplified = simplified.mid( 3 );
93 QString result( QLatin1String(
"<font color=\"%1\">%2</font>" ) );
94 if ( simplified.startsWith( QLatin1String(
">>>" ) ) ) {
95 return result.arg( quoteDepth3.name(), text );
96 }
else if ( simplified.startsWith( QLatin1String(
">>" ) ) ) {
97 return result.arg( quoteDepth2.name(), text );
98 }
else if ( simplified.startsWith( QLatin1String(
">" ) ) ) {
99 return result.arg( quoteDepth1.name(), text );
106 const QColor "eDepth1,
107 const QColor "eDepth2,
108 const QColor "eDepth3,
109 const QColor &misspelledColor )
111 Q_UNUSED( normalColor );
112 d->col1 = quoteDepth1;
113 d->col2 = quoteDepth2;
114 d->col3 = quoteDepth3;
115 d->misspelledColor = misspelledColor;
120 if ( on != d->spellCheckingEnabled ) {
121 d->spellCheckingEnabled = on;
128 QString simplified = text;
129 simplified = simplified.remove( QRegExp( QLatin1String(
"\\s" ) ) ).
130 replace( QLatin1Char(
'|' ), QLatin1Char(
'>' ) );
132 while ( simplified.startsWith( QLatin1String(
">>>>" ) ) ) {
133 simplified = simplified.mid( 3 );
136 if ( simplified.startsWith( QLatin1String(
">>>" ) ) ) {
137 setFormat( 0, text.length(), d->col3 );
138 }
else if ( simplified.startsWith( QLatin1String(
">>" ) ) ) {
139 setFormat( 0, text.length(), d->col2 );
140 }
else if ( simplified.startsWith( QLatin1String(
">" ) ) ) {
141 setFormat( 0, text.length(), d->col1 );
142 }
else if ( d->parent->isLineQuoted( text ) ) {
143 setFormat( 0, text.length(), d->col1 );
146 if ( d->spellCheckingEnabled && checkerEnabledByDefault() ) {
150 setCurrentBlockState( 0 );
161 setMisspelledColor( d->misspelledColor );