backgroundengine.cpp
#include "backgroundengine.h"
#include "defaultdictionary.h"
#include "dictionary.h"
#include "filter.h"
#include <kdebug.h>
#include <qtimer.h>
using namespace KSpell2;
BackgroundEngine::BackgroundEngine( QObject *parent )
: QObject( parent )
{
m_filter = Filter::defaultFilter();
m_dict = 0;
}
BackgroundEngine::~BackgroundEngine()
{
delete m_dict; m_dict = 0;
}
void BackgroundEngine::setBroker( const Broker::Ptr& broker )
{
m_broker = broker;
delete m_dict;
m_defaultDict = m_broker->defaultDictionary();
m_filter->setSettings( m_broker->settings() );
}
void BackgroundEngine::setText( const QString& text )
{
m_filter->setBuffer( text );
}
QString BackgroundEngine::text() const
{
return m_filter->buffer();
}
void BackgroundEngine::changeLanguage( const QString& lang )
{
delete m_dict;
if ( lang.isEmpty() ) {
m_dict = 0;
} else {
m_dict = m_broker->dictionary( lang );
}
}
QString BackgroundEngine::language() const
{
if ( m_dict )
return m_dict->language();
else
return m_defaultDict->language();
}
void BackgroundEngine::setFilter( Filter *filter )
{
QString oldText = m_filter->buffer();
m_filter = filter;
m_filter->setBuffer( oldText );
}
void BackgroundEngine::start()
{
QTimer::singleShot( 0, this, SLOT(checkNext()) );
}
void BackgroundEngine::stop()
{
}
void BackgroundEngine::continueChecking()
{
QTimer::singleShot( 0, this, SLOT(checkNext()) );
}
void BackgroundEngine::checkNext()
{
Word w = m_filter->nextWord();
if ( w.end ) {
emit done();
return;
}
Dictionary *dict = ( m_dict ) ? m_dict : static_cast<Dictionary*>( m_defaultDict );
if ( !dict->check( w.word ) ) {
//kdDebug()<<"found misspelling "<< w.word <<endl;
emit misspelling( w.word, w.start );
//wait for the handler. the parent will decide itself when to continue
} else
continueChecking();
}
bool BackgroundEngine::checkWord( const QString& word )
{
Dictionary *dict = ( m_dict ) ? m_dict : static_cast<Dictionary*>( m_defaultDict );
return dict->check( word );
}
bool BackgroundEngine::addWord( const QString& word )
{
Dictionary *dict = ( m_dict ) ? m_dict : static_cast<Dictionary*>( m_defaultDict );
return dict->addToPersonal( word );
}
QStringList BackgroundEngine::suggest( const QString& word )
{
Dictionary *dict = ( m_dict ) ? m_dict : static_cast<Dictionary*>( m_defaultDict );
return dict->suggest( word );
}
#include "backgroundengine.moc"
KSpell2::Dictionary::suggest
virtual QStringList suggest(const QString &word)=0
Fetches suggestions for the word.
KSpell2::Dictionary::addToPersonal
virtual bool addToPersonal(const QString &word)=0
Adds word to the list of of personal words.
KSpell2::Dictionary::check
virtual bool check(const QString &word)=0
Checks the given word.
KSpell2::Filter
Filter is used to split text into words which will be spell checked.
Definition: filter.h:65
KSpell2::Dictionary
Class is returned by from Broker.
Definition: dictionary.h:37
KSpell2::Word
Structure abstracts the word and its position in the parent text.
Definition: filter.h:40

KDE Home | KDE Accessibility Home | Description of Access Keys