• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

KPIMTextedit Library

  • kpimtextedit
emailquotehighlighter.cpp
1
21#include "emailquotehighlighter.h"
22
23#include "textedit.h"
24
25namespace KPIMTextEdit {
26
27class EMailQuoteHighlighter::EMailQuoteHighlighterPrivate
28{
29 public:
30 QColor col1, col2, col3, misspelledColor;
31 bool spellCheckingEnabled;
32 TextEdit *parent;
33};
34
35EMailQuoteHighlighter::EMailQuoteHighlighter( TextEdit *textEdit,
36 const QColor &normalColor,
37 const QColor &quoteDepth1,
38 const QColor &quoteDepth2,
39 const QColor &quoteDepth3,
40 const QColor &misspelledColor )
41 : Highlighter( textEdit, textEdit->configFile() ),
42 d( new EMailQuoteHighlighterPrivate() )
43{
44 Q_UNUSED( normalColor );
45 // Don't automatically disable the spell checker, for example because there
46 // are too many misspelled words. That would also disable quote highlighting.
47 // FIXME: disable this spell checking!
48 setAutomatic( false );
49
50 setActive( true );
51 d->col1 = quoteDepth1;
52 d->col2 = quoteDepth2;
53 d->col3 = quoteDepth3;
54 d->misspelledColor = misspelledColor;
55 d->spellCheckingEnabled = false;
56 d->parent = textEdit;
57}
58
59EMailQuoteHighlighter::~EMailQuoteHighlighter()
60{
61}
62
63QString EMailQuoteHighlighter::highlightText( const QString &text,
64 const QColor &quoteDepth1,
65 const QColor &quoteDepth2,
66 const QColor &quoteDepth3 )
67{
68 const QStringList splitList = text.split( QLatin1Char( '\n' ) );
69 QString result;
70 QStringList::const_iterator it = splitList.constBegin();
71 QStringList::const_iterator end = splitList.constEnd();
72 while ( it != end ) {
73 result.append( highlightParagraph( ( *it ) + QLatin1Char( '\n' ),
74 quoteDepth1, quoteDepth2, quoteDepth3 ) );
75 ++it;
76 }
77 return result;
78}
79
80QString EMailQuoteHighlighter::highlightParagraph( const QString &text,
81 const QColor &quoteDepth1,
82 const QColor &quoteDepth2,
83 const QColor &quoteDepth3 )
84{
85 QString simplified = text;
86 simplified = simplified.remove( QRegExp( QLatin1String( "\\s" ) ) ).
87 replace( QLatin1Char( '|' ), QLatin1Char( '>' ) ).
88 replace( QLatin1String( ">" ), QLatin1String( ">" ) );
89
90 while ( simplified.startsWith( QLatin1String( ">>>>" ) ) ) {
91 simplified = simplified.mid( 3 );
92 }
93
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 );
101 }
102
103 return text;
104}
105
106void EMailQuoteHighlighter::setQuoteColor( const QColor &normalColor,
107 const QColor &quoteDepth1,
108 const QColor &quoteDepth2,
109 const QColor &quoteDepth3,
110 const QColor &misspelledColor )
111{
112 Q_UNUSED( normalColor );
113 d->col1 = quoteDepth1;
114 d->col2 = quoteDepth2;
115 d->col3 = quoteDepth3;
116 d->misspelledColor = misspelledColor;
117}
118
119void EMailQuoteHighlighter::toggleSpellHighlighting( bool on )
120{
121 if ( on != d->spellCheckingEnabled ) {
122 d->spellCheckingEnabled = on;
123 rehighlight();
124 }
125}
126
127void EMailQuoteHighlighter::highlightBlock( const QString &text )
128{
129 QString simplified = text;
130 simplified = simplified.remove( QRegExp( QLatin1String( "\\s" ) ) ).
131 replace( QLatin1Char( '|' ), QLatin1Char( '>' ) );
132
133 while ( simplified.startsWith( QLatin1String( ">>>>" ) ) ) {
134 simplified = simplified.mid( 3 );
135 }
136
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 ); // FIXME: custom quote prefix
145 // can't handle multiple levels
146 } else if ( d->spellCheckingEnabled ) {
147 Highlighter::highlightBlock( text );
148 return; //setCurrentBlockState already done in Highlighter::highlightBlock
149 }
150 setCurrentBlockState( 0 );
151}
152
153void EMailQuoteHighlighter::unsetMisspelled( int start, int count )
154{
155 Q_UNUSED( start );
156 Q_UNUSED( count );
157}
158
159void EMailQuoteHighlighter::setMisspelled( int start, int count )
160{
161 setMisspelledColor( d->misspelledColor );
162 Sonnet::Highlighter::setMisspelled( start, count );
163}
164
165}
KPIMTextEdit::EMailQuoteHighlighter::EMailQuoteHighlighter
EMailQuoteHighlighter(TextEdit *textEdit, const QColor &normalColor=Qt::black, const QColor &quoteDepth1=QColor(0x00, 0x80, 0x00), const QColor &quoteDepth2=QColor(0x00, 0x80, 0x00), const QColor &quoteDepth3=QColor(0x00, 0x80, 0x00), const QColor &misspelledColor=Qt::red)
Constructor.
Definition emailquotehighlighter.cpp:35
KPIMTextEdit::EMailQuoteHighlighter::setMisspelled
virtual void setMisspelled(int start, int count)
Reimplemented to set the color of the misspelled word to a color defined by setQuoteColor().
Definition emailquotehighlighter.cpp:159
KPIMTextEdit::EMailQuoteHighlighter::highlightText
static QString highlightText(const QString &text, const QColor &quoteDepth1=QColor(0x00, 0x80, 0x00), const QColor &quoteDepth2=QColor(0x00, 0x80, 0x00), const QColor &quoteDepth3=QColor(0x00, 0x80, 0x00))
Use this static method to get a text consisting of multiple lines highligted.
Definition emailquotehighlighter.cpp:63
KPIMTextEdit::EMailQuoteHighlighter::toggleSpellHighlighting
void toggleSpellHighlighting(bool on)
Turns spellcheck highlighting on or off.
Definition emailquotehighlighter.cpp:119
KPIMTextEdit::EMailQuoteHighlighter::unsetMisspelled
virtual void unsetMisspelled(int start, int count)
Reimplemented, the base version sets the text color to black, which is not what we want.
Definition emailquotehighlighter.cpp:153
KPIMTextEdit::EMailQuoteHighlighter::highlightParagraph
static QString highlightParagraph(const QString &text, const QColor &quoteDepth1=QColor(0x00, 0x80, 0x00), const QColor &quoteDepth2=QColor(0x00, 0x80, 0x00), const QColor &quoteDepth3=QColor(0x00, 0x80, 0x00))
Use this static method to get proper highlighting for a single line.
Definition emailquotehighlighter.cpp:80
KPIMTextEdit::EMailQuoteHighlighter::setQuoteColor
void setQuoteColor(const QColor &normalColor, const QColor &quoteDepth1, const QColor &quoteDepth2, const QColor &quoteDepth3, const QColor &misspelledColor=Qt::red)
Sets the colors used for highlighting quoted text and spelling mistakes.
Definition emailquotehighlighter.cpp:106
KPIMTextEdit::EMailQuoteHighlighter::highlightBlock
virtual void highlightBlock(const QString &text)
Reimplemented to highlight quote blocks.
Definition emailquotehighlighter.cpp:127
KPIMTextEdit::TextEdit
Special textedit that provides additional features which are useful for PIM applications like mail cl...
Definition textedit.h:87
KPIMTextEdit
Copyright (C) 2006 Laurent Montel montel@kde.org Copyright (C) 2008 Thomas McGuire mcguire@kde....
Definition emailquotehighlighter.cpp:25
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KPIMTextedit Library

Skip menu "KPIMTextedit Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal