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 );
94 QString result( QLatin1String(
"<font color=\"%1\">%2</font>" ) );
95 if ( simplified.startsWith( QLatin1String(
">>>" ) ) ) {
96 return result.arg( quoteDepth3.name(), text );
97 }
else if ( simplified.startsWith( QLatin1String(
">>" ) ) ) {
98 return result.arg( quoteDepth2.name(), text );
99 }
else if ( simplified.startsWith( QLatin1String(
">" ) ) ) {
100 return result.arg( quoteDepth1.name(), text );
107 const QColor "eDepth1,
108 const QColor "eDepth2,
109 const QColor "eDepth3,
110 const QColor &misspelledColor )
112 Q_UNUSED( normalColor );
113 d->col1 = quoteDepth1;
114 d->col2 = quoteDepth2;
115 d->col3 = quoteDepth3;
116 d->misspelledColor = misspelledColor;
121 if ( on != d->spellCheckingEnabled ) {
122 d->spellCheckingEnabled = on;
129 QString simplified = text;
130 simplified = simplified.remove( QRegExp( QLatin1String(
"\\s" ) ) ).
131 replace( QLatin1Char(
'|' ), QLatin1Char(
'>' ) );
133 while ( simplified.startsWith( QLatin1String(
">>>>" ) ) ) {
134 simplified = simplified.mid( 3 );
137 if ( simplified.startsWith( QLatin1String(
">>>" ) ) ) {
138 setFormat( 0, text.length(), d->col3 );
139 }
else if ( simplified.startsWith( QLatin1String(
">>" ) ) ) {
140 setFormat( 0, text.length(), d->col2 );
141 }
else if ( simplified.startsWith( QLatin1String(
">" ) ) ) {
142 setFormat( 0, text.length(), d->col1 );
143 }
else if ( d->parent->isLineQuoted( text ) ) {
144 setFormat( 0, text.length(), d->col1 );
147 if ( d->spellCheckingEnabled && checkerEnabledByDefault() ) {
148 Highlighter::highlightBlock( text );
151 setCurrentBlockState( 0 );
162 setMisspelledColor( d->misspelledColor );
163 Sonnet::Highlighter::setMisspelled( start, count );