KPIMTextedit Library
emailquotehighlighter.cpp
00001
00021 #include "emailquotehighlighter.h"
00022
00023 #include "textedit.h"
00024
00025 namespace KPIMTextEdit {
00026
00027 class EMailQuoteHighlighter::EMailQuoteHighlighterPrivate
00028 {
00029 public:
00030 QColor col1, col2, col3, misspelledColor;
00031 bool spellCheckingEnabled;
00032 TextEdit *parent;
00033 };
00034
00035 EMailQuoteHighlighter::EMailQuoteHighlighter( TextEdit *textEdit,
00036 const QColor &normalColor,
00037 const QColor "eDepth1,
00038 const QColor "eDepth2,
00039 const QColor "eDepth3,
00040 const QColor &misspelledColor )
00041 : Highlighter( textEdit ),
00042 d( new EMailQuoteHighlighterPrivate() )
00043 {
00044 Q_UNUSED( normalColor );
00045
00046
00047
00048 setAutomatic( false );
00049
00050 setActive( true );
00051 d->col1 = quoteDepth1;
00052 d->col2 = quoteDepth2;
00053 d->col3 = quoteDepth3;
00054 d->misspelledColor = misspelledColor;
00055 d->spellCheckingEnabled = false;
00056 d->parent = textEdit;
00057 }
00058
00059 EMailQuoteHighlighter::~EMailQuoteHighlighter()
00060 {
00061 }
00062
00063 void EMailQuoteHighlighter::setQuoteColor( const QColor &normalColor,
00064 const QColor "eDepth1,
00065 const QColor "eDepth2,
00066 const QColor "eDepth3,
00067 const QColor &misspelledColor )
00068 {
00069 Q_UNUSED( normalColor );
00070 d->col1 = quoteDepth1;
00071 d->col2 = quoteDepth2;
00072 d->col3 = quoteDepth3;
00073 d->misspelledColor = misspelledColor;
00074 }
00075
00076 void EMailQuoteHighlighter::toggleSpellHighlighting( bool on )
00077 {
00078 if ( on != d->spellCheckingEnabled ) {
00079 d->spellCheckingEnabled = on;
00080 rehighlight();
00081 }
00082 }
00083
00084 void EMailQuoteHighlighter::highlightBlock( const QString & text )
00085 {
00086 QString simplified = text;
00087 simplified = simplified.replace( QRegExp( QLatin1String( "\\s" ) ), QString() )
00088 .replace( QLatin1Char( '|' ), QLatin1Char( '>' ) );
00089 while ( simplified.startsWith( QLatin1String(">>>>") ) )
00090 simplified = simplified.mid( 3 );
00091 if ( simplified.startsWith( QLatin1String(">>>") ) ||
00092 simplified.startsWith( QLatin1String("> > >") ) )
00093 setFormat( 0, text.length(), d->col1 );
00094 else if ( simplified.startsWith( QLatin1String(">>") ) ||
00095 simplified.startsWith( QLatin1String("> >") ) )
00096 setFormat( 0, text.length(), d->col2 );
00097 else if ( simplified.startsWith( QLatin1String(">") ) )
00098 setFormat( 0, text.length(), d->col3 );
00099 else if ( d->parent->isLineQuoted( text ) ) {
00100 setFormat( 0, text.length(), d->col1 );
00101 }
00102 else
00103 {
00104 if ( d->spellCheckingEnabled )
00105 Highlighter::highlightBlock( text );
00106 }
00107 setCurrentBlockState( 0 );
00108 }
00109
00110 void EMailQuoteHighlighter::unsetMisspelled( int start, int count )
00111 {
00112 Q_UNUSED( start )
00113 Q_UNUSED( count )
00114 }
00115
00116 void EMailQuoteHighlighter::setMisspelled( int start, int count )
00117 {
00118 setMisspelledColor( d->misspelledColor );
00119 Sonnet::Highlighter::setMisspelled( start, count );
00120 }
00121
00122 }