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 public:
00069   KMEdit(TQWidget *parent=0,KMComposeWin* composer=0,
00070          KSpellConfig* spellConfig = 0,
00071      const char *name=0);
00072   ~KMEdit();
00073 
00077   void spellcheck();
00078 
00082   TQString brokenText();
00083 
00087   int autoSpellChecking( bool );
00088 
00092   void setUseExternalEditor( bool use ) { mUseExtEditor = use; }
00093   void setExternalEditorPath( const TQString & path ) { mExtEditor = path; }
00094 
00101   bool checkExternalEditorFinished();
00102 
00103   TQPopupMenu* createPopupMenu(const TQPoint&);
00104   void setSpellCheckingActive(bool spellCheckingActive);
00105 
00107   void contentsDragEnterEvent(TQDragEnterEvent *e);
00108   void contentsDragMoveEvent(TQDragMoveEvent *e);
00109   void contentsDropEvent(TQDropEvent *e);
00110 
00111   void deleteAutoSpellChecking();
00112 
00113   unsigned int lineBreakColumn() const;
00114   
00116   void setCursorPositionFromStart(unsigned int pos);
00117 
00118   int indexOfCurrentLineStart( int paragraph, int index );
00119 
00120 signals:
00121   void spellcheck_done(int result);
00122   void attachPNGImageData(const TQByteArray &image);
00123   void pasteImage();
00124   void focusUp();
00125   void focusChanged( bool );
00126   void selectionAvailable( bool );
00127   void insertSnippet();
00128 public slots:
00129   void initializeAutoSpellChecking();
00130   void slotSpellcheck2(KSpell*);
00131   void slotSpellResult(const TQString&);
00132   void slotSpellDone();
00133   void slotExternalEditorDone(KProcess*);
00134   void slotMisspelling(const TQString &, const TQStringList &, unsigned int);
00135   void slotCorrected (const TQString &, const TQString &, unsigned int);
00136   void addSuggestion(const TQString& text, const TQStringList& lst, unsigned int );
00137   void cut();
00138   void clear();
00139   void del();
00140   void paste();
00141 protected:
00145   bool eventFilter(TQObject*, TQEvent*);
00146   void keyPressEvent( TQKeyEvent* );
00147 
00148   void contentsMouseReleaseEvent( TQMouseEvent * e );
00149 
00152   virtual void contentsMouseDoubleClickEvent( TQMouseEvent *e );
00153 
00154 private slots:
00155   void slotExternalEditorTempFileChanged( const TQString & fileName );
00156   void slotSelectionChanged() {
00157     // use !text.isEmpty() here, as null-selections exist, but make no sense
00158     emit selectionAvailable( !selectedText().isEmpty() );
00159   }
00160 
00163   void spellerReady( KSpell *speller );
00164 
00166   void spellerDied();
00167 
00169   void createSpellers();
00170 
00171 private:
00172   void killExternalEditor();
00173 
00174 private:
00175   KMComposeWin* mComposer;
00176 
00177   // This is the speller used for the spellcheck dialog. It is only active as long as the spellcheck
00178   // dialog is shown
00179   KSpell *mKSpellForDialog;
00180 
00181   // This is the speller used when right-clicking a word and choosing "add to dictionary". It lives
00182   // as long as the composer lives.
00183   KMSpell *mSpeller;
00184 
00185   KSpellConfig *mSpellConfig;
00186   TQMap<TQString,TQStringList> mReplacements;
00187   SpellingFilter* mSpellingFilter;
00188   KTempFile *mExtEditorTempFile;
00189   KDirWatch *mExtEditorTempFileWatcher;
00190   KProcess  *mExtEditorProcess;
00191   bool      mUseExtEditor;
00192   TQString   mExtEditor;
00193   bool      mWasModifiedBeforeSpellCheck;
00194   KMSyntaxHighter *mHighlighter;
00195   bool mSpellLineEdit;
00196   QClipboard::Mode mPasteMode;
00197 };
00198 
00199 #endif // __KMAIL_KMEDIT_H__
00200