From dfe289850f068f19ba4a83ab4e7e22a7e09c13c9 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sat, 26 Jan 2013 13:17:21 -0600 Subject: Rename a number of libraries and executables to avoid conflicts with KDE4 --- tdespell2/ui/highlighter.cpp | 150 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 tdespell2/ui/highlighter.cpp (limited to 'tdespell2/ui/highlighter.cpp') diff --git a/tdespell2/ui/highlighter.cpp b/tdespell2/ui/highlighter.cpp new file mode 100644 index 000000000..2d185462d --- /dev/null +++ b/tdespell2/ui/highlighter.cpp @@ -0,0 +1,150 @@ +/* + * highlighter.cpp + * + * Copyright (C) 2004 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "highlighter.h" +#include "broker.h" +#include "dictionary.h" +#include "settings.h" + +#include +#include + +#include +#include +#include +#include + +namespace KSpell2 { + +class Highlighter::Private +{ +public: + Filter *filter; + Broker::Ptr broker; + Dictionary *dict; + TQDict dictCache; +}; + +Highlighter::Highlighter( TQTextEdit *textEdit, + const TQString& configFile, + Filter *filter) + : TQSyntaxHighlighter( textEdit ) +{ + d = new Private; + d->filter = filter; + if ( !configFile.isEmpty() ) + d->broker = Broker::openBroker( KSharedConfig::openConfig( configFile ) ); + else + d->broker = Broker::openBroker(); + + d->filter->setSettings( d->broker->settings() ); + d->dict = d->broker->dictionary(); + Q_ASSERT( d->dict ); + d->dictCache.insert( d->broker->settings()->defaultLanguage(), + d->dict ); +} + +Highlighter::~Highlighter() +{ + delete d; d = 0; +} + +int Highlighter::highlightParagraph( const TQString& text, + int endStateOfLastPara ) +{ + Q_UNUSED( endStateOfLastPara ); + int para, index; + textEdit()->getCursorPosition( ¶, &index ); + const int lengthPosition = text.length() - 1; + + if ( index != lengthPosition || + ( lengthPosition > 0 && !text[lengthPosition-1].isLetter() ) ) { + d->filter->setBuffer( text ); + Word w = d->filter->nextWord(); + while ( !w.end ) { + if ( !d->dict->check( w.word ) ) { + setMisspelled( w.start, w.word.length() ); + } else + unsetMisspelled( w.start, w.word.length() ); + w = d->filter->nextWord(); + } + } + //TQTimer::singleShot( 0, this, TQT_SLOT(checkWords()) ); + + return 0; +} + +Filter *Highlighter::currentFilter() const +{ + return d->filter; +} + +void Highlighter::setCurrentFilter( Filter *filter ) +{ + d->filter = filter; + d->filter->setSettings( d->broker->settings() ); +} + +TQString Highlighter::currentLanguage() const +{ + return d->dict->language(); +} + +void Highlighter::setCurrentLanguage( const TQString& lang ) +{ + if ( !d->dictCache.find( lang ) ) { + Dictionary *dict = d->broker->dictionary( lang ); + if ( dict ) { + d->dictCache.insert( lang, dict ); + } else { + kdDebug()<<"No dictionary for \"" + <dict = d->dictCache[lang]; +} + +void Highlighter::setMisspelled( int start, int count ) +{ + setFormat( start , count, Qt::red ); +} + +void Highlighter::unsetMisspelled( int start, int count ) +{ + setFormat( start, count, Qt::black ); +} + +/* +void Highlighter::checkWords() +{ + Word w = d->filter->nextWord(); + if ( !w.end ) { + if ( !d->dict->check( w.word ) ) { + setFormat( w.start, w.word.length(), + Qt::red ); + } + } +}*/ + +} -- cgit v1.2.1