lib Library API Documentation

koAutoFormat.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00003                  2001       Sven Leiber         <s.leiber@web.de>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #ifndef koautoformat_h
00022 #define koautoformat_h
00023 
00024 #include <qstring.h>
00025 #include <qmap.h>
00026 #include <qvaluelist.h>
00027 #include <qstringlist.h>
00028 #include <qptrvector.h>
00029 #include <qdom.h>
00030 #include <qdict.h>
00031 #include <qlabel.h>
00032 #include <qwidget.h>
00033 #include <koffice_export.h>
00034 
00035 class KoDocument;
00036 class KoTextParag;
00037 class KoTextObject;
00038 class KoVariableCollection;
00039 class KoVariableFormatCollection;
00040 class KCompletion;
00041 class KoTextCursor;
00042 class KCommand;
00043 class KoSearchContext;
00044 class KoTextFormat;
00045 
00046 
00047 
00048 
00049 class KoCompletionBox : public QLabel
00050 {
00051   Q_OBJECT
00052   public:
00053     KoCompletionBox( QWidget * parent = 0, const char * name = 0, WFlags f = 0 );
00054     ~KoCompletionBox();
00055     QString& lastWord();
00056     void setLastWord(QString const &);
00057 
00058   protected:
00059     void mousePressEvent( QMouseEvent * );
00060 
00061   private:
00062     QString m_lastWord;
00063 };
00064 
00065 
00066 
00067 /******************************************************************/
00068 /* Class: KWAutoFormatEntry                */
00069 /******************************************************************/
00070 class KoAutoFormatEntry
00071 {
00072 public:
00073     // The text to find is actually the key in KWAutoFormat's map.
00074     // What we replace it with is replace().
00075     KoAutoFormatEntry(const QString& replace = QString::null);
00076     ~KoAutoFormatEntry();
00077     QString replace() const { return m_replace; }
00078     void  changeReplace(const QString & rep){ m_replace = rep; }
00079 
00080     KoSearchContext *formatEntryContext()const;
00081     void createNewEntryContext();
00082     void setFormatEntryContext( KoSearchContext * );
00083     void clearFormatEntryContext( );
00084 
00085 protected:
00086     QString m_replace;
00087     // For formatting in the replacement - not implemented yet
00088     KoSearchContext *m_formatOptions;
00089 };
00090 
00091 typedef QMap< QString, KoAutoFormatEntry > KoAutoFormatEntryMap;
00092 
00093 /******************************************************************/
00094 /* Class: KoAutoFormat                        */
00095 /******************************************************************/
00096 class KOTEXT_EXPORT KoAutoFormat
00097 {
00098 public:
00103     KoAutoFormat( KoDocument *_doc, KoVariableCollection *_varCollection, KoVariableFormatCollection *_varFormatCollection );
00104 
00106     KoAutoFormat( const KoAutoFormat& format );
00107 
00108     ~KoAutoFormat();
00109 
00110     enum KeyCompletionAction { Enter = 0, Tab = 1, Space = 2, End = 3, Right = 4};
00111 
00112     KCommand *applyAutoFormat( KoTextObject * obj );
00117     void doAutoFormat( KoTextCursor* cursor, KoTextParag *parag, int index, QChar ch,KoTextObject *txtObj );
00118 
00122     bool doCompletion( KoTextCursor* textEditCursor, KoTextParag *parag, int const index,KoTextObject *txtObj );
00123 
00124     bool doToolTipCompletion( KoTextCursor* textEditCursor, KoTextParag *parag, int index,KoTextObject *txtObj,int keyPress );
00125     void showToolTipBox(KoTextParag *parag,  int index, QWidget *widget, const QPoint &pos);
00126     void removeToolTipCompletion();
00127 
00128     bool doIgnoreDoubleSpace( KoTextParag *parag, int index,QChar ch );
00129 
00133     static QString getLastWord( KoTextParag *parag, int const index );
00134     QString getLastWord( const int max_words, KoTextParag *parag, int const index );
00135 
00141     static QString getWordAfterSpace( KoTextParag * parag, int const index);
00142 
00143     // Config for the typographic quotes. Used by the dialog.
00144     struct TypographicQuotes
00145     {
00146     QChar begin, end;
00147     bool replace; // aka enabled
00148     };
00149 
00150     // Configuration (on/off/settings). Called by the dialog.
00151     void configTypographicDoubleQuotes( TypographicQuotes _tq );
00152     void configTypographicSimpleQuotes( TypographicQuotes _tq );
00153 
00154     void configUpperCase( bool _uc );
00155     void configUpperUpper( bool _uu );
00156     void configAdvancedAutocorrect( bool _aa );
00157     void configAutoDetectUrl(bool _au);
00158     void configIgnoreDoubleSpace( bool _ids);
00159     void configRemoveSpaceBeginEndLine( bool _space);
00160     void configUseBulletStyle( bool _ubs);
00161 
00162     void configBulletStyle( QChar b );
00163 
00164     void configAutoChangeFormat( bool b);
00165 
00166     void configAutoReplaceNumber( bool b );
00167 
00168     void configAutoNumberStyle( bool b );
00169 
00170     void configCompletion( bool b );
00171 
00172     void configToolTipCompletion( bool b );
00173 
00174     void configAppendSpace( bool b);
00175 
00176     void configMinWordLength( uint val );
00177 
00178     void configNbMaxCompletionWord( uint val );
00179 
00180     void configAddCompletionWord( bool b );
00181 
00182     void configIncludeTwoUpperUpperLetterException( bool b);
00183 
00184     void configIncludeAbbreviation( bool b );
00185 
00186     void configAutoSuperScript( bool b );
00187 
00188     void configCorrectionWithFormat( bool b);
00189 
00190     void configCapitalizeNameOfDays( bool b);
00191 
00192     void configAutoFormatLanguage( const QString &_lang);
00193 
00194     void configKeyCompletionAction( KeyCompletionAction action );
00195 
00196     TypographicQuotes getConfigTypographicSimpleQuotes() const
00197     { return m_typographicSimpleQuotes; }
00198 
00199     TypographicQuotes getConfigTypographicDoubleQuotes() const
00200     { return m_typographicDoubleQuotes; }
00201 
00202     TypographicQuotes getDefaultTypographicDoubleQuotes() const
00203         { return m_typographicDefaultDoubleQuotes; }
00204 
00205     TypographicQuotes getDefaultTypographicSimpleQuotes() const
00206         { return m_typographicDefaultSimpleQuotes; }
00207 
00208     bool getConfigUpperCase() const
00209     { return m_convertUpperCase; }
00210     bool getConfigUpperUpper() const
00211     { return m_convertUpperUpper; }
00212     bool getConfigAdvancedAutoCorrect() const
00213     { return m_advancedAutoCorrect;}
00214     bool getConfigAutoDetectUrl() const
00215     { return m_autoDetectUrl;}
00216 
00217     bool getConfigIgnoreDoubleSpace() const
00218     { return m_ignoreDoubleSpace;}
00219 
00220     bool getConfigRemoveSpaceBeginEndLine() const
00221     { return m_removeSpaceBeginEndLine;}
00222 
00223     bool getConfigUseBulletSyle() const
00224     { return m_useBulletStyle;}
00225 
00226     QChar getConfigBulletStyle() const
00227     { return m_bulletStyle; }
00228 
00229     bool getConfigAutoChangeFormat() const
00230     { return m_autoChangeFormat;}
00231 
00232     bool getConfigAutoReplaceNumber() const
00233     { return m_autoReplaceNumber; }
00234 
00235     bool getConfigAutoNumberStyle() const
00236     { return m_useAutoNumberStyle; }
00237 
00238     bool getConfigCompletion() const
00239     { return m_completion; }
00240 
00241     bool getConfigToolTipCompletion() const
00242     { return m_toolTipCompletion; }
00243 
00244     bool getConfigAppendSpace() const
00245     { return m_completionAppendSpace; }
00246 
00247     uint getConfigMinWordLength() const
00248     { return m_minCompletionWordLength; }
00249 
00250     uint getConfigNbMaxCompletionWord() const
00251     { return m_nbMaxCompletionWord; }
00252 
00253     bool getConfigAddCompletionWord() const
00254     { return m_addCompletionWord; }
00255 
00256     bool getConfigIncludeTwoUpperUpperLetterException() const
00257     { return m_includeTwoUpperLetterException; }
00258 
00259     bool getConfigIncludeAbbreviation() const
00260     { return m_includeAbbreviation; }
00261 
00262     bool getConfigAutoSuperScript(  ) const
00263     { return m_bAutoSuperScript; }
00264 
00265     bool getConfigCorrectionWithFormat() const
00266     { return m_bAutoCorrectionWithFormat; }
00267 
00268     bool getConfigCapitalizeNameOfDays() const
00269         { return m_bCapitalizeNameOfDays; }
00270 
00271     QString getConfigAutoFormatLanguage( )const
00272         { return m_autoFormatLanguage;}
00273 
00274     KeyCompletionAction getConfigKeyAction() const
00275         { return m_keyCompletionAction;}
00276 
00277     const QDict<KoAutoFormatEntry> & getAutoFormatEntries() const{
00278         return m_entries;
00279     }
00280 
00281     KoAutoFormatEntry * findFormatEntry(const QString & text) {
00282         return m_entries[text];
00283     }
00284 
00285     // Add/remove entries, called by the dialog
00286     void addAutoFormatEntry( const QString &key, KoAutoFormatEntry *entry ) {
00287     m_entries.insert( key, entry );
00288     buildMaxLen();
00289     }
00290 
00291     void addAutoFormatEntry( const QString &key, const QString &replace );
00292 
00293 
00294     void removeAutoFormatEntry( const QString &key ) {
00295         m_entries.setAutoDelete(true);
00296         m_entries.remove( key );
00297         m_entries.setAutoDelete(false);
00298     buildMaxLen();
00299     }
00300 
00301     // Copy all autoformat entries from another KWAutoFormat. Called by the dialog
00302     void copyAutoFormatEntries( const KoAutoFormat & other )
00303     { m_entries = other.m_entries; }
00304 
00305     void copyListException( const QStringList & _list)
00306     { m_upperCaseExceptions=_list;}
00307 
00308     void copyListTwoUpperCaseException( const QStringList &_list)
00309     { m_twoUpperLetterException=_list; }
00310 
00311     QStringList listException() const {return m_upperCaseExceptions;}
00312 
00313     QStringList listTwoUpperLetterException() const {return m_twoUpperLetterException;}
00314 
00315     QStringList listCompletion() const;
00316 
00317     KCompletion *getCompletion() const { return m_listCompletion; }
00318 
00319     int nbSuperScriptEntry() const
00320         { return m_superScriptEntries.count(); }
00321 
00322     // Read/save config ( into kwordrc )
00323     void readConfig(bool force = false);
00324     void saveConfig();
00325 
00326     static bool isUpper( const QChar &c );
00327     static bool isLower( const QChar &c );
00328     static bool isMark( const QChar &c ); // End of sentence
00329     static bool isSeparator( const QChar &c );
00330 
00331     void updateMaxWords();
00332 protected:
00333     //return a ref to index otherwise when we uperCase, index is bad !
00334     KCommand *doAutoCorrect( KoTextCursor* textEditCursor, KoTextParag *parag, int & index, KoTextObject *txtObj );
00335     KCommand *doUpperCase( KoTextCursor* textEditCursor, KoTextParag *parag, int index, const QString & word , KoTextObject *txtObj );
00336     KCommand * doTypographicQuotes( KoTextCursor* textEditCursor, KoTextParag *parag, int index, KoTextObject *txtObj, bool doubleQuotes );
00337     void buildMaxLen();
00338 
00339     void doAutoDetectUrl( KoTextCursor *textEditCursor, KoTextParag *parag, int & index, QString & word, KoTextObject *txtObj );
00340     KCommand *doRemoveSpaceBeginEndLine( KoTextCursor *textEditCursor, KoTextParag *parag, KoTextObject *txtObj, int& index );
00341     KCommand *doAutoChangeFormat( KoTextCursor *textEditCursor, KoTextParag *parag, int index, const QString & word, KoTextObject *txtObj );
00342     KCommand *doUseBulletStyle(KoTextCursor *textEditCursor, KoTextParag *parag, KoTextObject *txtObj, int& index );
00343 
00344     KCommand *doAutoReplaceNumber( KoTextCursor* textEditCursor, KoTextParag *parag, int & index, const QString & word , KoTextObject *txtObj );
00345 
00346     KCommand *doUseNumberStyle(KoTextCursor * /*textEditCursor*/, KoTextParag *parag, KoTextObject *txtObj, int& index );
00347 
00348     void doAutoIncludeUpperUpper(KoTextCursor *textEditCursor, KoTextParag *parag, KoTextObject *txtObj );
00349     void doAutoIncludeAbbreviation(KoTextCursor *textEditCursor, KoTextParag *parag, KoTextObject *txtObj );
00350 
00351     KCommand *doAutoSuperScript( KoTextCursor* textEditCursor, KoTextParag *parag, int index, const QString & word , KoTextObject *txtObj );
00352 
00353     KCommand *doCapitalizeNameOfDays( KoTextCursor* textEditCursor, KoTextParag *parag, int index, const QString & word , KoTextObject *txtObj );
00354 
00355     static void changeTextFormat(KoSearchContext *formatOptions, KoTextFormat * format, int & flags );
00356     void loadEntry( const QDomElement &nl, bool _allLanguages = false);
00357     QDomElement saveEntry( QDictIterator<KoAutoFormatEntry> _entry, QDomDocument doc);
00358 private:
00359     void detectStartOfLink(KoTextParag * parag, int const index, bool const insertedDot);
00360     void autoFormatIsActive();
00361     void loadListOfWordCompletion();
00362     void loadAutoCorrection( const QDomElement & _de, bool _allLanguages = false );
00363     void loadAllLanguagesAutoCorrection();
00364     KCommand *autoFormatWord( KoTextCursor* textEditCursor, KoTextParag *parag, int &index, KoTextObject *txtObj, QString * _wordArray, bool _allLanguages );
00365     void readAutoCorrectConfig();
00366 
00367     KoDocument *m_doc;
00368     KoVariableCollection *m_varCollection;
00369     KoVariableFormatCollection *m_varFormatCollection;
00370 
00371     QString m_autoFormatLanguage;
00372     bool m_configRead;
00373     bool m_convertUpperCase, m_convertUpperUpper,m_advancedAutoCorrect;
00374     bool m_autoDetectUrl, m_ignoreDoubleSpace, m_removeSpaceBeginEndLine;
00375     bool m_useBulletStyle, m_autoChangeFormat, m_autoReplaceNumber;
00376     bool m_useAutoNumberStyle;
00377     bool m_completion;
00378     bool m_toolTipCompletion;
00379     bool m_completionAppendSpace;
00380     bool m_addCompletionWord;
00381     bool m_includeTwoUpperLetterException;
00382     bool m_includeAbbreviation;
00383     bool m_ignoreUpperCase;
00384     bool m_bAutoFormatActive;
00385 
00386     bool m_bAutoSuperScript;
00387     bool m_bAutoCorrectionWithFormat;
00388     bool m_bCapitalizeNameOfDays;
00390     bool m_wordInserted;
00391     QChar m_bulletStyle;
00392 
00393     TypographicQuotes m_typographicSimpleQuotes;
00394 
00395     TypographicQuotes m_typographicDoubleQuotes;
00396 
00397     TypographicQuotes m_typographicDefaultDoubleQuotes;
00398 
00399     TypographicQuotes m_typographicDefaultSimpleQuotes;
00400 
00401     KCompletion *m_listCompletion;
00402 
00403     QDict<KoAutoFormatEntry> m_entries;
00404     QDict<KoAutoFormatEntry> m_allLanguages;
00405 
00406     KoAutoFormatEntryMap m_superScriptEntries;
00407 
00408     QStringList m_upperCaseExceptions;
00409     QStringList m_twoUpperLetterException;
00410 
00411     uint m_maxFindLength;
00412     uint m_minCompletionWordLength;
00413     uint m_nbMaxCompletionWord;
00414     uint m_countMaxWords;
00415     QStringList m_cacheNameOfDays;
00416     KoCompletionBox *m_completionBox;
00417     KeyCompletionAction m_keyCompletionAction;
00418 };
00419 
00420 #endif
KDE Logo
This file is part of the documentation for lib Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:39:58 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003