22#include "highlighter.h"
24#include "dictionary.h"
30#include <tqtextedit.h>
37class Highlighter::Private
43 TQDict<Dictionary> dictCache;
46Highlighter::Highlighter( TQTextEdit *textEdit,
47 const TQString& configFile,
49 : TQSyntaxHighlighter( textEdit )
53 if ( !configFile.isEmpty() )
54 d->broker = Broker::openBroker( TDESharedConfig::openConfig( configFile ) );
56 d->broker = Broker::openBroker();
58 d->filter->setSettings( d->broker->settings() );
59 d->dict = d->broker->dictionary();
61 d->dictCache.insert( d->broker->settings()->defaultLanguage(),
65Highlighter::~Highlighter()
70int 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();
95Filter *Highlighter::currentFilter()
const
100void Highlighter::setCurrentFilter( Filter *filter )
103 d->filter->setSettings( d->broker->settings() );
106TQString Highlighter::currentLanguage()
const
108 return d->dict->language();
111void 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];
128void Highlighter::setMisspelled(
int start,
int count )
130 setFormat( start , count, TQt::red );
133void Highlighter::unsetMisspelled(
int start,
int count )
135 setFormat( start, count, TQt::black );