kmail

kmedit.h

00001 /* -*- mode: C++; c-file-style: "gnu" -*-
00002  * KMComposeWin Header File
00003  * Author: Markus Wuebben <markus.wuebben@kde.org>
00004  */
00005 #ifndef __KMAIL_KMEDIT_H__
00006 #define __KMAIL_KMEDIT_H__
00007 
00008 #include <kdeversion.h>
00009 #include <keditcl.h>
00010 #include <kspell.h>
00011 #include <ksyntaxhighlighter.h>
00012 #include <tqmap.h>
00013 #include <tqstringlist.h>
00014 #include <tqclipboard.h>
00015 
00016 class KMComposeWin;
00017 class KSpellConfig;
00018 class SpellingFilter;
00019 class KTempFile;
00020 class KDirWatch;
00021 class KProcess;
00022 class TQPopupMenu;
00023 
00029 class KMSpell : public KSpell
00030 {
00031   public:
00032 
00033     KMSpell( TQObject *receiver, const char *slot, KSpellConfig *spellConfig );
00034     using KSpell::writePersonalDictionary;
00035 };
00036 
00040 class KMSyntaxHighter : public KDictSpellingHighlighter
00041 {
00042   public:
00043 
00044     KMSyntaxHighter( TQTextEdit *textEdit,
00045                      bool spellCheckingActive = true,
00046                      bool autoEnable = true,
00047                      const TQColor& spellColor = red,
00048                      bool colorQuoting = false,
00049                      const TQColor& QuoteColor0 = black,
00050                      const TQColor& QuoteColor1 = TQColor( 0x00, 0x80, 0x00 ),
00051                      const TQColor& QuoteColor2 = TQColor( 0x00, 0x70, 0x00 ),
00052                      const TQColor& QuoteColor3 = TQColor( 0x00, 0x60, 0x00 ),
00053                      KSpellConfig *spellConfig = 0 );
00054 
00056     virtual bool isMisspelled( const TQString &word );
00057 
00058     void ignoreWord( const TQString &word );
00059 
00060     TQStringList ignoredWords() const;
00061 
00062   private:
00063     TQStringList mIgnoredWords;
00064 };
00065 
00066 class KMEdit : public KEdit {
00067   Q_OBJECT
00068   TQ_OBJECT
00069 public:
00070   KMEdit(TQWidget *parent=0,KMComposeWin* composer=0,
00071          KSpellConfig* spellConfig = 0,
00072      const char *name=0);
00073   ~KMEdit();
00074 
00078   void spellcheck();
00079 
00083   TQString brokenText();
00084 
00088   int autoSpellChecking( bool );
00089 
00093   void setUseExternalEditor( bool use ) { mUseExtEditor = use; }
00094   void setExternalEditorPath( const TQString & path ) { mExtEditor = path; }
00095 
00102   bool checkExternalEditorFinished();
00103 
00104   TQPopupMenu* createPopupMenu(const TQPoint&);
00105   void setSpellCheckingActive(bool spellCheckingActive);
00106 
00108   void contentsDragEnterEvent(TQDragEnterEvent *e);
00109   void contentsDragMoveEvent(TQDragMoveEvent *e);
00110   void contentsDropEvent(TQDropEvent *e);
00111 
00112   void deleteAutoSpellChecking();
00113 
00114   unsigned int lineBreakColumn() const;
00115   
00117   void setCursorPositionFromStart(unsigned int pos);
00118 
00119   int indexOfCurrentLineStart( int paragraph, int index );
00120 
00121 signals:
00122   void spellcheck_done(int result);
00123   void attachPNGImageData(const TQByteArray &image);
00124   void pasteImage();
00125   void focusUp();
00126   void focusChanged( bool );
00127   void selectionAvailable( bool );
00128   void insertSnippet();
00129 public slots:
00130   void initializeAutoSpellChecking();
00131   void slotSpellcheck2(KSpell*);
00132   void slotSpellResult(const TQString&);
00133   void slotSpellDone();
00134   void slotExternalEditorDone(KProcess*);
00135   void slotMisspelling(const TQString &, const TQStringList &, unsigned int);
00136   void slotCorrected (const TQString &, const TQString &, unsigned int);
00137   void addSuggestion(const TQString& text, const TQStringList& lst, unsigned int );
00138   void cut();
00139   void clear();
00140   void del();
00141   void paste();
00142 protected:
00146   bool eventFilter(TQObject*, TQEvent*);
00147   void keyPressEvent( TQKeyEvent* );
00148 
00149   void contentsMouseReleaseEvent( TQMouseEvent * e );
00150 
00153   virtual void contentsMouseDoubleClickEvent( TQMouseEvent *e );
00154 
00155 private slots:
00156   void slotExternalEditorTempFileChanged( const TQString & fileName );
00157   void slotSelectionChanged() {
00158     // use !text.isEmpty() here, as null-selections exist, but make no sense
00159     emit selectionAvailable( !selectedText().isEmpty() );
00160   }
00161 
00164   void spellerReady( KSpell *speller );
00165 
00167   void spellerDied();
00168 
00170   void createSpellers();
00171 
00172 private:
00173   void killExternalEditor();
00174 
00175 private:
00176   KMComposeWin* mComposer;
00177 
00178   // This is the speller used for the spellcheck dialog. It is only active as long as the spellcheck
00179   // dialog is shown
00180   KSpell *mKSpellForDialog;
00181 
00182   // This is the speller used when right-clicking a word and choosing "add to dictionary". It lives
00183   // as long as the composer lives.
00184   KMSpell *mSpeller;
00185 
00186   KSpellConfig *mSpellConfig;
00187   TQMap<TQString,TQStringList> mReplacements;
00188   SpellingFilter* mSpellingFilter;
00189   KTempFile *mExtEditorTempFile;
00190   KDirWatch *mExtEditorTempFileWatcher;
00191   KProcess  *mExtEditorProcess;
00192   bool      mUseExtEditor;
00193   TQString   mExtEditor;
00194   bool      mWasModifiedBeforeSpellCheck;
00195   KMSyntaxHighter *mHighlighter;
00196   bool mSpellLineEdit;
00197   TQClipboard::Mode mPasteMode;
00198 };
00199 
00200 #endif // __KMAIL_KMEDIT_H__
00201