ksyntaxhighlighter.cpp

00001 /*
00002  ksyntaxhighlighter.cpp
00003 
00004  Copyright (c) 2003 Trolltech AS
00005  Copyright (c) 2003 Scott Wheeler <wheeler@kde.org>
00006 
00007  This file is part of the KDE libraries
00008 
00009  This library is free software; you can redistribute it and/or
00010  modify it under the terms of the GNU Library General Public
00011  License version 2 as published by the Free Software Foundation.
00012 
00013  This library is distributed in the hope that it will be useful,
00014  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  Library General Public License for more details.
00017 
00018  You should have received a copy of the GNU Library General Public License
00019  along with this library; see the file COPYING.LIB.  If not, write to
00020  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021  Boston, MA 02110-1301, USA.
00022 */
00023 
00024 #include <qcolor.h>
00025 #include <qregexp.h>
00026 #include <qsyntaxhighlighter.h>
00027 #include <qtimer.h>
00028 
00029 #include <klocale.h>
00030 #include <kconfig.h>
00031 #include <kdebug.h>
00032 #include <kglobal.h>
00033 #include <kspell.h>
00034 #include <kapplication.h>
00035 
00036 #include "ksyntaxhighlighter.h"
00037 
00038 static int dummy, dummy2, dummy3, dummy4;
00039 static int *Okay = &dummy;
00040 static int *NotOkay = &dummy2;
00041 static int *Ignore = &dummy3;
00042 static int *Unknown = &dummy4;
00043 static const int tenSeconds = 10*1000;
00044 
00045 class KSyntaxHighlighter::KSyntaxHighlighterPrivate
00046 {
00047 public:
00048     QColor col1, col2, col3, col4, col5;
00049     SyntaxMode mode;
00050     bool enabled;
00051 };
00052 
00053 class KSpellingHighlighter::KSpellingHighlighterPrivate
00054 {
00055 public:
00056 
00057     KSpellingHighlighterPrivate() :
00058     alwaysEndsWithSpace( true ),
00059     intraWordEditing( false ) {}
00060 
00061     QString currentWord;
00062     int currentPos;
00063     bool alwaysEndsWithSpace;
00064     QColor color;
00065     bool intraWordEditing;
00066 };
00067 
00068 class KDictSpellingHighlighter::KDictSpellingHighlighterPrivate
00069 {
00070 public:
00071     KDictSpellingHighlighterPrivate() :
00072         mDict( 0 ),
00073     spell( 0 ),
00074         mSpellConfig( 0 ),
00075         rehighlightRequest( 0 ),
00076     wordCount( 0 ),
00077     errorCount( 0 ),
00078     autoReady( false ),
00079         globalConfig( true ),
00080     spellReady( false ) {}
00081 
00082     ~KDictSpellingHighlighterPrivate() {
00083     delete rehighlightRequest;
00084     delete spell;
00085     }
00086 
00087     static QDict<int>* sDict()
00088     {
00089     if (!statDict)
00090         statDict = new QDict<int>(50021);
00091     return statDict;
00092     }
00093 
00094     QDict<int>* mDict;
00095     QDict<int> autoDict;
00096     QDict<int> autoIgnoreDict;
00097     static QObject *sDictionaryMonitor;
00098     KSpell *spell;
00099     KSpellConfig *mSpellConfig;
00100     QTimer *rehighlightRequest, *spellTimeout;
00101     QString spellKey;
00102     int wordCount, errorCount;
00103     int checksRequested, checksDone;
00104     int disablePercentage;
00105     int disableWordCount;
00106     bool completeRehighlightRequired;
00107     bool active, automatic, autoReady;
00108     bool globalConfig, spellReady;
00109 private:
00110     static QDict<int>* statDict;
00111 
00112 };
00113 
00114 QDict<int>* KDictSpellingHighlighter::KDictSpellingHighlighterPrivate::statDict = 0;
00115 
00116 
00117 KSyntaxHighlighter::KSyntaxHighlighter( QTextEdit *textEdit,
00118                       bool colorQuoting,
00119                       const QColor& depth0,
00120                       const QColor& depth1,
00121                       const QColor& depth2,
00122                       const QColor& depth3,
00123                       SyntaxMode mode )
00124     : QSyntaxHighlighter( textEdit )
00125 {
00126     d = new KSyntaxHighlighterPrivate();
00127 
00128     d->enabled = colorQuoting;
00129     d->col1 = depth0;
00130     d->col2 = depth1;
00131     d->col3 = depth2;
00132     d->col4 = depth3;
00133     d->col5 = depth0;
00134 
00135     d->mode = mode;
00136 }
00137 
00138 KSyntaxHighlighter::~KSyntaxHighlighter()
00139 {
00140     delete d;
00141 }
00142 
00143 int KSyntaxHighlighter::highlightParagraph( const QString &text, int )
00144 {
00145     if (!d->enabled) {
00146     setFormat( 0, text.length(), textEdit()->viewport()->paletteForegroundColor() );
00147     return 0;
00148     }
00149 
00150     QString simplified = text;
00151     simplified = simplified.replace( QRegExp( "\\s" ), QString::null ).replace( '|', QString::fromLatin1(">") );
00152     while ( simplified.startsWith( QString::fromLatin1(">>>>") ) )
00153     simplified = simplified.mid(3);
00154     if  ( simplified.startsWith( QString::fromLatin1(">>>") ) || simplified.startsWith( QString::fromLatin1("> >    >") ) )
00155     setFormat( 0, text.length(), d->col2 );
00156     else if ( simplified.startsWith( QString::fromLatin1(">>") ) || simplified.startsWith( QString::fromLatin1("> >") ) )
00157     setFormat( 0, text.length(), d->col3 );
00158     else if ( simplified.startsWith( QString::fromLatin1(">") ) )
00159     setFormat( 0, text.length(), d->col4 );
00160     else
00161     setFormat( 0, text.length(), d->col5 );
00162     return 0;
00163 }
00164 
00165 KSpellingHighlighter::KSpellingHighlighter( QTextEdit *textEdit,
00166                         const QColor& spellColor,
00167                         bool colorQuoting,
00168                         const QColor& depth0,
00169                         const QColor& depth1,
00170                         const QColor& depth2,
00171                         const QColor& depth3 )
00172     : KSyntaxHighlighter( textEdit, colorQuoting, depth0, depth1, depth2, depth3 )
00173 {
00174     d = new KSpellingHighlighterPrivate();
00175 
00176     d->color = spellColor;
00177 }
00178 
00179 KSpellingHighlighter::~KSpellingHighlighter()
00180 {
00181     delete d;
00182 }
00183 
00184 int KSpellingHighlighter::highlightParagraph( const QString &text,
00185                           int paraNo )
00186 {
00187     if ( paraNo == -2 )
00188     paraNo = 0;
00189     // leave #includes, diffs, and quoted replies alone
00190     QString diffAndCo( ">|" );
00191 
00192     bool isCode = diffAndCo.find(text[0]) != -1;
00193 
00194     if ( !text.endsWith(" ") )
00195     d->alwaysEndsWithSpace = false;
00196 
00197     KSyntaxHighlighter::highlightParagraph( text, -2 );
00198 
00199     if ( !isCode ) {
00200         int para, index;
00201     textEdit()->getCursorPosition( &para, &index );
00202     int len = text.length();
00203     if ( d->alwaysEndsWithSpace )
00204         len--;
00205 
00206     d->currentPos = 0;
00207     d->currentWord = "";
00208     for ( int i = 0; i < len; i++ ) {
00209         if ( !text[i].isLetter() && (!(text[i] == '\'')) ) {
00210         if ( ( para != paraNo ) ||
00211             !intraWordEditing() ||
00212             ( i - d->currentWord.length() > (uint)index ) ||
00213             ( i < index ) ) {
00214             flushCurrentWord();
00215         } else {
00216             d->currentWord = "";
00217         }
00218         d->currentPos = i + 1;
00219         } else {
00220         d->currentWord += text[i];
00221         }
00222     }
00223     if ( !text[len - 1].isLetter() ||
00224          (uint)( index + 1 ) != text.length() ||
00225          para != paraNo )
00226         flushCurrentWord();
00227     }
00228     return ++paraNo;
00229 }
00230 
00231 QStringList KSpellingHighlighter::personalWords()
00232 {
00233     QStringList l;
00234     l.append( "KMail" );
00235     l.append( "KOrganizer" );
00236     l.append( "KAddressBook" );
00237     l.append( "KHTML" );
00238     l.append( "KIO" );
00239     l.append( "KJS" );
00240     l.append( "Konqueror" );
00241     l.append( "KSpell" );
00242     l.append( "Kontact" );
00243     l.append( "Qt" );
00244     return l;
00245 }
00246 
00247 void KSpellingHighlighter::flushCurrentWord()
00248 {
00249     while ( d->currentWord[0].isPunct() ) {
00250     d->currentWord = d->currentWord.mid( 1 );
00251     d->currentPos++;
00252     }
00253 
00254     QChar ch;
00255     while ( ( ch = d->currentWord[(int) d->currentWord.length() - 1] ).isPunct() &&
00256          ch != '(' && ch != '@' )
00257     d->currentWord.truncate( d->currentWord.length() - 1 );
00258 
00259     if ( !d->currentWord.isEmpty() ) {
00260     if ( isMisspelled( d->currentWord ) ) {
00261         setFormat( d->currentPos, d->currentWord.length(), d->color );
00262 //      setMisspelled( d->currentPos, d->currentWord.length(), true );
00263     }
00264     }
00265     d->currentWord = "";
00266 }
00267 
00268 QObject *KDictSpellingHighlighter::KDictSpellingHighlighterPrivate::sDictionaryMonitor = 0;
00269 
00270 KDictSpellingHighlighter::KDictSpellingHighlighter( QTextEdit *textEdit,
00271                             bool spellCheckingActive ,
00272                             bool autoEnable,
00273                             const QColor& spellColor,
00274                             bool colorQuoting,
00275                             const QColor& depth0,
00276                             const QColor& depth1,
00277                             const QColor& depth2,
00278                             const QColor& depth3,
00279                                                     KSpellConfig *spellConfig )
00280     : KSpellingHighlighter( textEdit, spellColor,
00281                 colorQuoting, depth0, depth1, depth2, depth3 )
00282 {
00283     d = new KDictSpellingHighlighterPrivate();
00284 
00285     d->mSpellConfig = spellConfig;
00286     d->globalConfig = ( !spellConfig );
00287     d->automatic = autoEnable;
00288     d->active = spellCheckingActive;
00289     d->checksRequested = 0;
00290     d->checksDone = 0;
00291     d->completeRehighlightRequired = false;
00292 
00293     KConfig *config = KGlobal::config();
00294     KConfigGroupSaver cs( config, "KSpell" );
00295     d->disablePercentage = config->readNumEntry( "KSpell_AsYouTypeDisablePercentage", 42 );
00296     d->disablePercentage = QMIN( d->disablePercentage, 101 );
00297     d->disableWordCount = config->readNumEntry( "KSpell_AsYouTypeDisableWordCount", 100 );
00298 
00299     textEdit->installEventFilter( this );
00300     textEdit->viewport()->installEventFilter( this );
00301 
00302     d->rehighlightRequest = new QTimer(this);
00303     connect( d->rehighlightRequest, SIGNAL( timeout() ),
00304          this, SLOT( slotRehighlight() ));
00305     d->spellTimeout = new QTimer(this);
00306     connect( d->spellTimeout, SIGNAL( timeout() ),
00307          this, SLOT( slotKSpellNotResponding() ));
00308 
00309     if ( d->globalConfig ) {
00310         d->spellKey = spellKey();
00311 
00312         if ( !d->sDictionaryMonitor )
00313             d->sDictionaryMonitor = new QObject();
00314     }
00315     else {
00316         d->mDict = new QDict<int>(4001);
00317         connect( d->mSpellConfig, SIGNAL( configChanged() ),
00318                  this, SLOT( slotLocalSpellConfigChanged() ) );
00319     }
00320 
00321     slotDictionaryChanged();
00322     startTimer( 2 * 1000 );
00323 }
00324 
00325 KDictSpellingHighlighter::~KDictSpellingHighlighter()
00326 {
00327     delete d->spell;
00328     d->spell = 0;
00329     delete d->mDict;
00330     d->mDict = 0;
00331     delete d;
00332 }
00333 
00334 void KDictSpellingHighlighter::slotSpellReady( KSpell *spell )
00335 {
00336     kdDebug(0) << "KDictSpellingHighlighter::slotSpellReady( " << spell << " )" << endl;
00337     KConfigGroup cg( KGlobal::config(),"KSpell" );
00338     if ( cg.readEntry("KSpell_DoSpellChecking") != "0" )
00339     {
00340       if ( d->globalConfig ) {
00341           connect( d->sDictionaryMonitor, SIGNAL( destroyed()),
00342                    this, SLOT( slotDictionaryChanged() ));
00343       }
00344       if ( spell != d->spell )
00345       {
00346           delete d->spell;
00347           d->spell = spell;
00348       }
00349       d->spellReady = true;
00350       const QStringList l = KSpellingHighlighter::personalWords();
00351       for ( QStringList::ConstIterator it = l.begin(); it != l.end(); ++it ) {
00352           d->spell->addPersonal( *it );
00353       }
00354       connect( spell, SIGNAL( misspelling( const QString &, const QStringList &, unsigned int )),
00355            this, SLOT( slotMisspelling( const QString &, const QStringList &, unsigned int )));
00356       connect( spell, SIGNAL( corrected( const QString &, const QString &, unsigned int )),
00357                this, SLOT( slotCorrected( const QString &, const QString &, unsigned int )));
00358       d->checksRequested = 0;
00359       d->checksDone = 0;
00360       d->completeRehighlightRequired = true;
00361       d->rehighlightRequest->start( 0, true );
00362     }
00363 }
00364 
00365 bool KDictSpellingHighlighter::isMisspelled( const QString &word )
00366 {
00367     if (!d->spellReady)
00368     return false;
00369 
00370     // This debug is expensive, only enable it locally
00371     //kdDebug(0) << "KDictSpellingHighlighter::isMisspelled( \"" << word << "\" )" << endl;
00372     // Normally isMisspelled would look up a dictionary and return
00373     // true or false, but kspell is asynchronous and slow so things
00374     // get tricky...
00375     // For auto detection ignore signature and reply prefix
00376     if ( !d->autoReady )
00377     d->autoIgnoreDict.replace( word, Ignore );
00378 
00379     // "dict" is used as a cache to store the results of KSpell
00380     QDict<int>* dict = ( d->globalConfig ? d->sDict() : d->mDict );
00381     if ( !dict->isEmpty() && (*dict)[word] == NotOkay ) {
00382     if ( d->autoReady && ( d->autoDict[word] != NotOkay )) {
00383         if ( !d->autoIgnoreDict[word] )
00384         ++d->errorCount;
00385         d->autoDict.replace( word, NotOkay );
00386     }
00387 
00388     return d->active;
00389     }
00390     if ( !dict->isEmpty() && (*dict)[word] == Okay ) {
00391     if ( d->autoReady && !d->autoDict[word] ) {
00392         d->autoDict.replace( word, Okay );
00393     }
00394     return false;
00395     }
00396 
00397     if ((dict->isEmpty() || !((*dict)[word])) && d->spell ) {
00398     int para, index;
00399     textEdit()->getCursorPosition( &para, &index );
00400     ++d->wordCount;
00401     dict->replace( word, Unknown );
00402     ++d->checksRequested;
00403     if (currentParagraph() != para)
00404         d->completeRehighlightRequired = true;
00405     d->spellTimeout->start( tenSeconds, true );
00406     d->spell->checkWord( word, false );
00407     }
00408     return false;
00409 }
00410 
00411 bool KSpellingHighlighter::intraWordEditing() const
00412 {
00413     return d->intraWordEditing;
00414 }
00415 
00416 void KSpellingHighlighter::setIntraWordEditing( bool editing )
00417 {
00418     d->intraWordEditing = editing;
00419 }
00420 
00421 void KDictSpellingHighlighter::slotMisspelling (const QString &originalWord, const QStringList &suggestions,
00422                                                 unsigned int pos)
00423 {
00424     Q_UNUSED( suggestions );
00425     // kdDebug() << suggestions.join( " " ).latin1() << endl;
00426     if ( d->globalConfig )
00427         d->sDict()->replace( originalWord, NotOkay );
00428     else
00429         d->mDict->replace( originalWord, NotOkay );
00430 
00431     //Emit this baby so that apps that want to have suggestions in a popup over
00432     //the misspelled word can catch them.
00433     emit newSuggestions( originalWord, suggestions, pos );
00434 }
00435 
00436 void KDictSpellingHighlighter::slotCorrected(const QString &word,
00437                          const QString &,
00438                          unsigned int)
00439 
00440 {
00441     QDict<int>* dict = ( d->globalConfig ? d->sDict() : d->mDict );
00442     if ( !dict->isEmpty() && (*dict)[word] == Unknown ) {
00443         dict->replace( word, Okay );
00444     }
00445     ++d->checksDone;
00446     if (d->checksDone == d->checksRequested) {
00447     d->spellTimeout->stop();
00448       slotRehighlight();
00449     } else {
00450     d->spellTimeout->start( tenSeconds, true );
00451     }
00452 }
00453 
00454 void KDictSpellingHighlighter::dictionaryChanged()
00455 {
00456     QObject *oldMonitor = KDictSpellingHighlighterPrivate::sDictionaryMonitor;
00457     KDictSpellingHighlighterPrivate::sDictionaryMonitor = new QObject();
00458     KDictSpellingHighlighterPrivate::sDict()->clear();
00459     delete oldMonitor;
00460 }
00461 
00462 void KDictSpellingHighlighter::restartBackgroundSpellCheck()
00463 {
00464     kdDebug(0) << "KDictSpellingHighlighter::restartBackgroundSpellCheck()" << endl;
00465     slotDictionaryChanged();
00466 }
00467 
00468 void KDictSpellingHighlighter::setActive( bool active )
00469 {
00470     if ( active == d->active )
00471         return;
00472 
00473     d->active = active;
00474     rehighlight();
00475     if ( d->active )
00476         emit activeChanged( i18n("As-you-type spell checking enabled.") );
00477     else
00478         emit activeChanged( i18n("As-you-type spell checking disabled.") );
00479 }
00480 
00481 bool KDictSpellingHighlighter::isActive() const
00482 {
00483     return d->active;
00484 }
00485 
00486 void KDictSpellingHighlighter::setAutomatic( bool automatic )
00487 {
00488     if ( automatic == d->automatic )
00489         return;
00490 
00491     d->automatic = automatic;
00492     if ( d->automatic )
00493         slotAutoDetection();
00494 }
00495 
00496 bool KDictSpellingHighlighter::automatic() const
00497 {
00498     return d->automatic;
00499 }
00500 
00501 void KDictSpellingHighlighter::slotRehighlight()
00502 {
00503     kdDebug(0) << "KDictSpellingHighlighter::slotRehighlight()" << endl;
00504     if (d->completeRehighlightRequired) {
00505     rehighlight();
00506     } else {
00507     int para, index;
00508     textEdit()->getCursorPosition( &para, &index );
00509     //rehighlight the current para only (undo/redo safe)
00510     bool modified = textEdit()->isModified();
00511     textEdit()->insertAt( "", para, index );
00512     textEdit()->setModified( modified );
00513     }
00514     if (d->checksDone == d->checksRequested)
00515     d->completeRehighlightRequired = false;
00516     QTimer::singleShot( 0, this, SLOT( slotAutoDetection() ));
00517 }
00518 
00519 void KDictSpellingHighlighter::slotDictionaryChanged()
00520 {
00521     delete d->spell;
00522     d->spellReady = false;
00523     d->wordCount = 0;
00524     d->errorCount = 0;
00525     d->autoDict.clear();
00526 
00527     d->spell = new KSpell( 0, i18n( "Incremental Spellcheck" ), this,
00528         SLOT( slotSpellReady( KSpell * ) ), d->mSpellConfig );
00529 }
00530 
00531 void KDictSpellingHighlighter::slotLocalSpellConfigChanged()
00532 {
00533     kdDebug(0) << "KDictSpellingHighlighter::slotSpellConfigChanged()" << endl;
00534     // the spell config has been changed, so we have to restart from scratch
00535     d->mDict->clear();
00536     slotDictionaryChanged();
00537 }
00538 
00539 QString KDictSpellingHighlighter::spellKey()
00540 {
00541     KConfig *config = KGlobal::config();
00542     KConfigGroupSaver cs( config, "KSpell" );
00543     config->reparseConfiguration();
00544     QString key;
00545     key += QString::number( config->readNumEntry( "KSpell_NoRootAffix", 0 ));
00546     key += '/';
00547     key += QString::number( config->readNumEntry( "KSpell_RunTogether", 0 ));
00548     key += '/';
00549     key += config->readEntry( "KSpell_Dictionary", "" );
00550     key += '/';
00551     key += QString::number( config->readNumEntry( "KSpell_DictFromList", false ));
00552     key += '/';
00553     key += QString::number( config->readNumEntry( "KSpell_Encoding", KS_E_ASCII ));
00554     key += '/';
00555     key += QString::number( config->readNumEntry( "KSpell_Client", KS_CLIENT_ISPELL ));
00556     return key;
00557 }
00558 
00559 
00560 // Automatic spell checking support
00561 // In auto spell checking mode disable as-you-type spell checking
00562 // iff more than one third of words are spelt incorrectly.
00563 //
00564 // Words in the signature and reply prefix are ignored.
00565 // Only unique words are counted.
00566 
00567 void KDictSpellingHighlighter::slotAutoDetection()
00568 {
00569     if ( !d->autoReady )
00570     return;
00571 
00572     bool savedActive = d->active;
00573 
00574     if ( d->automatic ) {
00575     // tme = Too many errors
00576     bool tme = d->wordCount >= d->disableWordCount && d->errorCount * 100 >= d->disablePercentage * d->wordCount;
00577     if ( d->active && tme )
00578         d->active = false;
00579     else if ( !d->active && !tme )
00580         d->active = true;
00581     }
00582     if ( d->active != savedActive ) {
00583     if ( d->wordCount > 1 )
00584         if ( d->active )
00585         emit activeChanged( i18n("As-you-type spell checking enabled.") );
00586         else
00587         emit activeChanged( i18n( "Too many misspelled words. "
00588                       "As-you-type spell checking disabled." ) );
00589     d->completeRehighlightRequired = true;
00590     d->rehighlightRequest->start( 100, true );
00591     }
00592 }
00593 
00594 void KDictSpellingHighlighter::slotKSpellNotResponding()
00595 {
00596     static int retries = 0;
00597     if (retries < 10) {
00598         if ( d->globalConfig )
00599         KDictSpellingHighlighter::dictionaryChanged();
00600     else
00601         slotLocalSpellConfigChanged();
00602     } else {
00603     setAutomatic( false );
00604     setActive( false );
00605     }
00606     ++retries;
00607 }
00608 
00609 bool KDictSpellingHighlighter::eventFilter( QObject *o, QEvent *e)
00610 {
00611     if (o == textEdit() && (e->type() == QEvent::FocusIn)) {
00612         if ( d->globalConfig ) {
00613             QString skey = spellKey();
00614             if ( d->spell && d->spellKey != skey ) {
00615                 d->spellKey = skey;
00616                 KDictSpellingHighlighter::dictionaryChanged();
00617             }
00618         }
00619     }
00620 
00621     if (o == textEdit() && (e->type() == QEvent::KeyPress)) {
00622     QKeyEvent *k = static_cast<QKeyEvent *>(e);
00623     d->autoReady = true;
00624     if (d->rehighlightRequest->isActive()) // try to stay out of the users way
00625         d->rehighlightRequest->changeInterval( 500 );
00626     if ( k->key() == Key_Enter ||
00627          k->key() == Key_Return ||
00628          k->key() == Key_Up ||
00629          k->key() == Key_Down ||
00630          k->key() == Key_Left ||
00631          k->key() == Key_Right ||
00632          k->key() == Key_PageUp ||
00633          k->key() == Key_PageDown ||
00634          k->key() == Key_Home ||
00635          k->key() == Key_End ||
00636          (( k->state() & ControlButton ) &&
00637           ((k->key() == Key_A) ||
00638            (k->key() == Key_B) ||
00639            (k->key() == Key_E) ||
00640            (k->key() == Key_N) ||
00641            (k->key() == Key_P))) ) {
00642         if ( intraWordEditing() ) {
00643         setIntraWordEditing( false );
00644         d->completeRehighlightRequired = true;
00645         d->rehighlightRequest->start( 500, true );
00646         }
00647         if (d->checksDone != d->checksRequested) {
00648         // Handle possible change of paragraph while
00649         // words are pending spell checking
00650         d->completeRehighlightRequired = true;
00651         d->rehighlightRequest->start( 500, true );
00652         }
00653     } else {
00654         setIntraWordEditing( true );
00655     }
00656     if ( k->key() == Key_Space ||
00657          k->key() == Key_Enter ||
00658          k->key() == Key_Return ) {
00659         QTimer::singleShot( 0, this, SLOT( slotAutoDetection() ));
00660     }
00661     }
00662 
00663     else if ( o == textEdit()->viewport() &&
00664      ( e->type() == QEvent::MouseButtonPress )) {
00665     d->autoReady = true;
00666     if ( intraWordEditing() ) {
00667         setIntraWordEditing( false );
00668         d->completeRehighlightRequired = true;
00669         d->rehighlightRequest->start( 0, true );
00670     }
00671     }
00672 
00673     return false;
00674 }
00675 
00676 #include "ksyntaxhighlighter.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys