KDECore
backgroundengine.cpp
Go to the documentation of this file.
00001 00020 #include "backgroundengine_p.h" 00021 00022 #include "spellerplugin_p.h" 00023 #include "filter_p.h" 00024 00025 #include <kdebug.h> 00026 00027 #include <QtCore/QTimer> 00028 00029 using namespace Sonnet; 00030 00031 BackgroundEngine::BackgroundEngine(QObject *parent) 00032 : QObject(parent) 00033 { 00034 m_filter = Filter::defaultFilter(); 00035 } 00036 00037 BackgroundEngine::~BackgroundEngine() 00038 { 00039 delete m_filter; 00040 } 00041 00042 void BackgroundEngine::setSpeller(const Speller &speller) 00043 { 00044 m_dict = speller; 00045 } 00046 00047 void BackgroundEngine::setText(const QString &text) 00048 { 00049 m_filter->setBuffer(text); 00050 } 00051 00052 QString BackgroundEngine::text() const 00053 { 00054 return m_filter->buffer(); 00055 } 00056 00057 void BackgroundEngine::changeLanguage(const QString &lang) 00058 { 00059 m_dict.setLanguage(lang); 00060 } 00061 00062 QString BackgroundEngine::language() const 00063 { 00064 return m_dict.language(); 00065 } 00066 00067 void BackgroundEngine::setFilter(Filter *filter) 00068 { 00069 QString oldText = m_filter->buffer(); 00070 m_filter = filter; 00071 m_filter->setBuffer(oldText); 00072 } 00073 00074 void BackgroundEngine::start() 00075 { 00076 QTimer::singleShot(0, this, SLOT(checkNext())); 00077 } 00078 00079 void BackgroundEngine::stop() 00080 { 00081 } 00082 00083 void BackgroundEngine::continueChecking() 00084 { 00085 QTimer::singleShot(0, this, SLOT(checkNext())); 00086 } 00087 00088 void BackgroundEngine::checkNext() 00089 { 00090 Word w = m_filter->nextWord(); 00091 if (w.end) { 00092 emit done(); 00093 return; 00094 } 00095 00096 if (KDE_ISUNLIKELY( m_dict.isMisspelled(w.word) )) { 00097 //kDebug()<<"found misspelling "<< w.word; 00098 emit misspelling(w.word, w.start); 00099 //wait for the handler. the parent will decide itself when to continue 00100 } else 00101 continueChecking(); 00102 } 00103 00104 bool BackgroundEngine::checkWord(const QString &word) 00105 { 00106 return m_dict.isCorrect(word); 00107 } 00108 00109 bool BackgroundEngine::addWord(const QString &word) 00110 { 00111 return m_dict.addToPersonal(word); 00112 } 00113 00114 QStringList BackgroundEngine::suggest(const QString &word) 00115 { 00116 return m_dict.suggest(word); 00117 } 00118 00119 #include "backgroundengine_p.moc"
KDE 4.6 API Reference