backgroundchecker.cpp
#include "backgroundchecker.h"
#include "broker.h"
#include "backgroundengine.h"
//#include "backgroundthread.h"
//#include "threadevents.h"
#include <kdebug.h>
using namespace KSpell2;
class BackgroundChecker::Private
{
public:
//BackgroundThread thread;
BackgroundEngine *engine;
QString currentText;
};
BackgroundChecker::BackgroundChecker( const Broker::Ptr& broker, QObject* parent,
const char *name )
: QObject( parent, name )
{
d = new Private;
//d->thread.setReceiver( this );
//d->thread.setBroker( broker );
d->engine = new BackgroundEngine( this );
d->engine->setBroker( broker );
connect( d->engine, SIGNAL(misspelling( const QString&, int )),
SIGNAL(misspelling( const QString&, int )) );
connect( d->engine, SIGNAL(done()),
SLOT(slotEngineDone()) );
}
BackgroundChecker::~BackgroundChecker()
{
delete d;
}
void BackgroundChecker::checkText( const QString& text )
{
d->currentText = text;
//d->thread.setText( text );
d->engine->setText( text );
d->engine->start();
}
void BackgroundChecker::start()
{
d->currentText = getMoreText();
// ## what if d->currentText.isEmpty()?
//kdDebug()<<"KSpell BackgroundChecker: starting with : \"" << d->currentText << "\""<<endl;
//d->thread.setText( d->currentText );
d->engine->setText( d->currentText );
d->engine->start();
}
void BackgroundChecker::stop()
{
//d->thread.stop();
d->engine->stop();
}
QString BackgroundChecker::getMoreText()
{
return QString::null;
}
void BackgroundChecker::finishedCurrentFeed()
{
}
void BackgroundChecker::setFilter( Filter *filter )
{
//d->thread.setFilter( filter );
d->engine->setFilter( filter );
}
Filter *BackgroundChecker::filter() const
{
//return d->thread.filter();
return d->engine->filter();
}
Broker *BackgroundChecker::broker() const
{
//return d->thread.broker();
return d->engine->broker();
}
bool BackgroundChecker::checkWord( const QString& word )
{
//kdDebug()<<"checking word \""<<word<< "\""<<endl;
return d->engine->checkWord( word );
}
bool BackgroundChecker::addWord( const QString& word )
{
return d->engine->addWord( word );
}
QStringList BackgroundChecker::suggest( const QString& word ) const
{
//return d->thread.suggest( word );
return d->engine->suggest( word );
}
void BackgroundChecker::changeLanguage( const QString& lang )
{
//d->thread.changeLanguage( lang );
d->engine->changeLanguage( lang );
}
void BackgroundChecker::continueChecking()
{
d->engine->continueChecking();
}
void BackgroundChecker::slotEngineDone()
{
finishedCurrentFeed();
d->currentText = getMoreText();
if ( d->currentText.isNull() ) {
emit done();
} else {
//d->thread.setText( d->currentText );
d->engine->setText( d->currentText );
d->engine->start();
}
}
#if 0
void BackgroundChecker::customEvent( QCustomEvent *event )
{
if ( (int)event->type() == FoundMisspelling ) {
MisspellingEvent *me = static_cast<MisspellingEvent*>( event );
kdDebug()<<"Found misspelling of \"" << me->word() << "\"" <<endl;
QString currentWord = d->currentText.mid( me->position(), me->word().length() );
if ( currentWord == me->word() )
emit misspelling( me->word(), me->position() );
else {
kdDebug()<<"Cleaning up misspelling for old text which is \""<<currentWord
<<"\" and should be \""<<me->word()<<"\""<<endl;
}
} else if ( (int)event->type() == FinishedChecking ) {
d->currentText = getMoreText();
if ( d->currentText.isEmpty() )
emit done();
else
d->thread.setText( d->currentText );
} else {
QObject::customEvent( event );
}
}
#endif
#include "backgroundchecker.moc"
KSpell2::BackgroundChecker::misspelling
void misspelling(const QString &word, int start)
Emitted whenever a misspelled word is found.
KSpell2::BackgroundChecker::checkText
void checkText(const QString &)
This method is used to spell check static text.
Definition: backgroundchecker.cpp:60
KSpell2::Filter
Filter is used to split text into words which will be spell checked.
Definition: filter.h:65
KSpell2::BackgroundChecker::getMoreText
virtual QString getMoreText()
This function is called to get the text to spell check.
Definition: backgroundchecker.cpp:84
KSpell2::Broker
Class used to deal with dictionaries.
Definition: broker.h:48
KSpell2::BackgroundChecker::finishedCurrentFeed
virtual void finishedCurrentFeed()
This function will be called whenever the background checker will be finished text which it got from ...
Definition: backgroundchecker.cpp:89
KSpell2::BackgroundChecker::done
void done()
Emitted after the whole text has been spell checked.
KSpell2::BackgroundChecker::continueChecking
virtual void continueChecking()
After emitting misspelling signal the background checker stops.
Definition: backgroundchecker.cpp:134

KDE Home | KDE Accessibility Home | Description of Access Keys