ksyntaxhighlighter.h
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 #ifndef KSYNTAXHIGHLIGHTER_H 00025 #define KSYNTAXHIGHLIGHTER_H 00026 00027 #include <tqtextedit.h> 00028 #include <tqsyntaxhighlighter.h> 00029 #include <tqcolor.h> 00030 #include <tqstringlist.h> 00031 00032 #include <tdelibs_export.h> 00033 00034 class TQAccel; 00035 class TQTimer; 00036 class KSpell; 00037 class KSpellConfig; 00038 00042 class TDEUI_EXPORT KSyntaxHighlighter : public TQSyntaxHighlighter 00043 { 00044 public: 00045 enum SyntaxMode { 00046 PlainTextMode, 00047 RichTextMode 00048 }; 00049 KSyntaxHighlighter( TQTextEdit *textEdit, 00050 bool colorQuoting = false, 00051 const TQColor& QuoteColor0 = black, 00052 const TQColor& QuoteColor1 = TQColor( 0x00, 0x80, 0x00 ), 00053 const TQColor& QuoteColor2 = TQColor( 0x00, 0x80, 0x00 ), 00054 const TQColor& QuoteColor3 = TQColor( 0x00, 0x80, 0x00 ), 00055 SyntaxMode mode = PlainTextMode ); 00056 ~KSyntaxHighlighter(); 00057 00058 int highlightParagraph( const TQString& text, int endStateOfLastPara ); 00059 00060 private: 00061 class KSyntaxHighlighterPrivate; 00062 KSyntaxHighlighterPrivate *d; 00063 }; 00064 00065 class TDEUI_EXPORT KSpellingHighlighter : public KSyntaxHighlighter 00066 { 00067 public: 00068 KSpellingHighlighter( TQTextEdit *textEdit, 00069 const TQColor& spellColor = red, 00070 bool colorQuoting = false, 00071 const TQColor& QuoteColor0 = black, 00072 const TQColor& QuoteColor1 = TQColor( 0x00, 0x80, 0x00 ), 00073 const TQColor& QuoteColor2 = TQColor( 0x00, 0x80, 0x00 ), 00074 const TQColor& QuoteColor3 = TQColor( 0x00, 0x80, 0x00 ) ); 00075 ~KSpellingHighlighter(); 00076 00077 virtual int highlightParagraph( const TQString &text, 00078 int endStateOfLastPara ); 00079 virtual bool isMisspelled( const TQString& word ) = 0; 00080 bool intraWordEditing() const; 00081 void setIntraWordEditing( bool editing ); 00082 static TQStringList personalWords(); 00083 00084 private: 00085 void flushCurrentWord(); 00086 00087 class KSpellingHighlighterPrivate; 00088 KSpellingHighlighterPrivate *d; 00089 }; 00090 00094 class TDEUI_EXPORT KDictSpellingHighlighter : public TQObject, public KSpellingHighlighter 00095 { 00096 Q_OBJECT 00097 00098 public: 00099 KDictSpellingHighlighter( TQTextEdit *textEdit, 00100 bool spellCheckingActive = true, 00101 bool autoEnable = true, 00102 const TQColor& spellColor = red, 00103 bool colorQuoting = false, 00104 const TQColor& QuoteColor0 = black, 00105 const TQColor& QuoteColor1 = TQColor( 0x00, 0x80, 0x00 ), 00106 const TQColor& QuoteColor2 = TQColor( 0x00, 0x70, 0x00 ), 00107 const TQColor& QuoteColor3 = TQColor( 0x00, 0x60, 0x00 ), 00108 KSpellConfig *spellConfig = 0 ); 00109 ~KDictSpellingHighlighter(); 00110 00111 virtual bool isMisspelled( const TQString &word ); 00112 static void dictionaryChanged(); 00113 void restartBackgroundSpellCheck(); 00114 00127 void setActive( bool active ); 00128 00136 bool isActive() const; 00137 00149 void setAutomatic( bool automatic ); 00150 00158 bool automatic() const; 00159 00160 signals: 00161 void activeChanged(const TQString &); 00162 void newSuggestions(const TQString& originalword, const TQStringList& suggestions, 00163 unsigned int pos); 00164 00165 protected: 00166 TQString spellKey(); 00167 bool eventFilter(TQObject *o, TQEvent *e); 00168 00169 protected slots: 00170 void slotMisspelling( const TQString &originalWord, const TQStringList &suggestions, unsigned int pos ); 00171 void slotCorrected( const TQString &originalWord, const TQString &, unsigned int ); 00172 void slotRehighlight(); 00173 void slotDictionaryChanged(); 00174 void slotSpellReady( KSpell *spell ); 00175 void slotAutoDetection(); 00176 void slotLocalSpellConfigChanged(); 00177 void slotKSpellNotResponding(); 00178 00179 private: 00180 class KDictSpellingHighlighterPrivate; 00181 KDictSpellingHighlighterPrivate *d; 00182 }; 00183 00184 #endif