22 #include "highlighter.h" 24 #include "dictionary.h" 27 #include <tdeconfig.h> 30 #include <tqtextedit.h> 37 class Highlighter::Private
43 TQDict<Dictionary> dictCache;
46 Highlighter::Highlighter( TQTextEdit *textEdit,
47 const TQString& configFile,
49 : TQSyntaxHighlighter( textEdit )
53 if ( !configFile.isEmpty() )
58 d->filter->setSettings( d->broker->settings() );
59 d->dict = d->broker->dictionary();
61 d->dictCache.insert( d->broker->settings()->defaultLanguage(),
65 Highlighter::~Highlighter()
70 int Highlighter::highlightParagraph(
const TQString& text,
71 int endStateOfLastPara )
73 Q_UNUSED( endStateOfLastPara );
75 textEdit()->getCursorPosition( ¶, &index );
76 const int lengthPosition = text.length() - 1;
78 if ( index != lengthPosition ||
79 ( lengthPosition > 0 && !text[lengthPosition-1].isLetter() ) ) {
80 d->filter->setBuffer( text );
81 Word w = d->filter->nextWord();
83 if ( !d->dict->check( w.word ) ) {
84 setMisspelled( w.start, w.word.length() );
86 unsetMisspelled( w.start, w.word.length() );
87 w = d->filter->nextWord();
95 Filter *Highlighter::currentFilter()
const 100 void Highlighter::setCurrentFilter( Filter *filter )
103 d->filter->setSettings( d->broker->settings() );
106 TQString Highlighter::currentLanguage()
const 108 return d->dict->language();
111 void Highlighter::setCurrentLanguage(
const TQString& lang )
113 if ( !d->dictCache.find( lang ) ) {
114 Dictionary *dict = d->broker->dictionary( lang );
116 d->dictCache.insert( lang, dict );
118 kdDebug()<<
"No dictionary for \"" 120 <<
"\" staying with the current language." 125 d->dict = d->dictCache[lang];
128 void Highlighter::setMisspelled(
int start,
int count )
130 setFormat( start , count, TQt::red );
133 void Highlighter::unsetMisspelled(
int start,
int count )
135 setFormat( start, count, TQt::black );
static Broker * openBroker(TDESharedConfig *config=0)
Constructs the broker.