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 class KoDocument; 00032 class KoTextParag; 00033 class KoTextObject; 00034 class KoVariableCollection; 00035 class KoVariableFormatCollection; 00036 class KCompletion; 00037 class KoTextCursor; 00038 class KCommand; 00039 class KoSearchContext; 00040 class KoTextFormat; 00041 00042 /******************************************************************/ 00043 /* Class: KWAutoFormatEntry */ 00044 /******************************************************************/ 00045 class KoAutoFormatEntry 00046 { 00047 public: 00048 // The text to find is actually the key in KWAutoFormat's map. 00049 // What we replace it with is replace(). 00050 KoAutoFormatEntry(const QString& replace = QString::null); 00051 ~KoAutoFormatEntry(); 00052 QString replace() const { return m_replace; } 00053 void changeReplace(const QString & rep){ m_replace = rep; } 00054 00055 KoSearchContext *formatEntryContext()const; 00056 void createNewEntryContext(); 00057 void setFormatEntryContext( KoSearchContext * ); 00058 void clearFormatEntryContext( ); 00059 00060 protected: 00061 QString m_replace; 00062 // For formatting in the replacement - not implemented yet 00063 KoSearchContext *m_formatOptions; 00064 }; 00065 00066 typedef QMap< QString, KoAutoFormatEntry > KoAutoFormatEntryMap; 00067 00068 /******************************************************************/ 00069 /* Class: KoAutoFormat */ 00070 /******************************************************************/ 00071 class KoAutoFormat 00072 { 00073 public: 00078 KoAutoFormat( KoDocument *_doc, KoVariableCollection *_varCollection, KoVariableFormatCollection *_varFormatCollection ); 00079 00081 KoAutoFormat( const KoAutoFormat& format ); 00082 00083 ~KoAutoFormat(); 00084 00085 KCommand *applyAutoFormat( KoTextObject * obj ); 00090 void doAutoFormat( KoTextCursor* cursor, KoTextParag *parag, int index, QChar ch,KoTextObject *txtObj ); 00091 00095 void doCompletion( KoTextCursor* textEditCursor, KoTextParag *parag, int index,KoTextObject *txtObj ); 00096 00097 00098 bool doIgnoreDoubleSpace( KoTextParag *parag, int index,QChar ch ); 00099 00103 static QString getLastWord( KoTextParag *parag, int index ); 00104 00110 static QString getWordAfterSpace( KoTextParag * parag, int index); 00111 00112 // Config for the typographic quotes. Used by the dialog. 00113 struct TypographicQuotes 00114 { 00115 QChar begin, end; 00116 bool replace; // aka enabled 00117 }; 00118 00119 // Configuration (on/off/settings). Called by the dialog. 00120 void configTypographicDoubleQuotes( TypographicQuotes _tq ); 00121 void configTypographicSimpleQuotes( TypographicQuotes _tq ); 00122 00123 void configUpperCase( bool _uc ); 00124 void configUpperUpper( bool _uu ); 00125 void configAdvancedAutocorrect( bool _aa ); 00126 void configAutoDetectUrl(bool _au); 00127 void configIgnoreDoubleSpace( bool _ids); 00128 void configRemoveSpaceBeginEndLine( bool _space); 00129 void configUseBulletStyle( bool _ubs); 00130 00131 void configBulletStyle( QChar b ); 00132 00133 void configAutoChangeFormat( bool b); 00134 00135 void configAutoReplaceNumber( bool b ); 00136 00137 void configAutoNumberStyle( bool b ); 00138 00139 void configCompletion( bool b ); 00140 00141 void configAppendSpace( bool b); 00142 00143 void configMinWordLength( uint val ); 00144 00145 void configNbMaxCompletionWord( uint val ); 00146 00147 void configAddCompletionWord( bool b ); 00148 00149 void configIncludeTwoUpperUpperLetterException( bool b); 00150 00151 void configIncludeAbbreviation( bool b ); 00152 00153 void configAutoSuperScript( bool b ); 00154 00155 void configCorrectionWithFormat( bool b); 00156 00157 void configCapitalizeNameOfDays( bool b); 00158 00159 void configAutoFormatLanguage( const QString &_lang); 00160 00161 TypographicQuotes getConfigTypographicSimpleQuotes() const 00162 { return m_typographicSimpleQuotes; } 00163 00164 TypographicQuotes getConfigTypographicDoubleQuotes() const 00165 { return m_typographicDoubleQuotes; } 00166 00167 TypographicQuotes getDefaultTypographicDoubleQuotes() const 00168 { return m_typographicDefaultDoubleQuotes; } 00169 00170 TypographicQuotes getDefaultTypographicSimpleQuotes() const 00171 { return m_typographicDefaultSimpleQuotes; } 00172 00173 bool getConfigUpperCase() const 00174 { return m_convertUpperCase; } 00175 bool getConfigUpperUpper() const 00176 { return m_convertUpperUpper; } 00177 bool getConfigAdvancedAutoCorrect() const 00178 { return m_advancedAutoCorrect;} 00179 bool getConfigAutoDetectUrl() const 00180 { return m_autoDetectUrl;} 00181 00182 bool getConfigIgnoreDoubleSpace() const 00183 { return m_ignoreDoubleSpace;} 00184 00185 bool getConfigRemoveSpaceBeginEndLine() const 00186 { return m_removeSpaceBeginEndLine;} 00187 00188 bool getConfigUseBulletSyle() const 00189 { return m_useBulletStyle;} 00190 00191 QChar getConfigBulletStyle() const 00192 { return m_bulletStyle; } 00193 00194 bool getConfigAutoChangeFormat() const 00195 { return m_autoChangeFormat;} 00196 00197 bool getConfigAutoReplaceNumber() const 00198 { return m_autoReplaceNumber; } 00199 00200 bool getConfigAutoNumberStyle() const 00201 { return m_useAutoNumberStyle; } 00202 00203 bool getConfigCompletion() const 00204 { return m_completion; } 00205 00206 bool getConfigAppendSpace() const 00207 { return m_completionAppendSpace; } 00208 00209 uint getConfigMinWordLength() const 00210 { return m_minCompletionWordLength; } 00211 00212 uint getConfigNbMaxCompletionWord() const 00213 { return m_nbMaxCompletionWord; } 00214 00215 bool getConfigAddCompletionWord() const 00216 { return m_addCompletionWord; } 00217 00218 bool getConfigIncludeTwoUpperUpperLetterException() const 00219 { return m_includeTwoUpperLetterException; } 00220 00221 bool getConfigIncludeAbbreviation() const 00222 { return m_includeAbbreviation; } 00223 00224 bool getConfigAutoSuperScript( ) const 00225 { return m_bAutoSuperScript; } 00226 00227 bool getConfigCorrectionWithFormat() const 00228 { return m_bAutoCorrectionWithFormat; } 00229 00230 bool getConfigCapitalizeNameOfDays() const 00231 { return m_bCapitalizeNameOfDays; } 00232 00233 QString getConfigAutoFormatLanguage( )const 00234 { return m_autoFormatLanguage;} 00235 00236 00237 const QDict<KoAutoFormatEntry> & getAutoFormatEntries() const{ 00238 return m_entries; 00239 } 00240 00241 KoAutoFormatEntry * findFormatEntry(const QString & text) { 00242 return m_entries[text]; 00243 } 00244 00245 // Add/remove entries, called by the dialog 00246 void addAutoFormatEntry( const QString &key, KoAutoFormatEntry *entry ) { 00247 m_entries.insert( key, entry ); 00248 buildMaxLen(); 00249 } 00250 00251 void addAutoFormatEntry( const QString &key, const QString &replace ); 00252 00253 00254 void removeAutoFormatEntry( const QString &key ) { 00255 m_entries.setAutoDelete(true); 00256 m_entries.remove( key ); 00257 m_entries.setAutoDelete(false); 00258 buildMaxLen(); 00259 } 00260 00261 // Copy all autoformat entries from another KWAutoFormat. Called by the dialog 00262 void copyAutoFormatEntries( const KoAutoFormat & other ) 00263 { m_entries = other.m_entries; } 00264 00265 void copyListException( const QStringList & _list) 00266 { m_upperCaseExceptions=_list;} 00267 00268 void copyListTwoUpperCaseException( const QStringList &_list) 00269 { m_twoUpperLetterException=_list; } 00270 00271 QStringList listException() const {return m_upperCaseExceptions;} 00272 00273 QStringList listTwoUpperLetterException() const {return m_twoUpperLetterException;} 00274 00275 QStringList listCompletion() const; 00276 00277 KCompletion *getCompletion() const { return m_listCompletion; } 00278 00279 int nbSuperScriptEntry() const 00280 { return m_superScriptEntries.count(); } 00281 00282 // Read/save config ( into kwordrc ) 00283 void readConfig(bool force = false); 00284 void saveConfig(); 00285 00286 static bool isUpper( const QChar &c ); 00287 static bool isLower( const QChar &c ); 00288 static bool isMark( const QChar &c ); // End of sentence 00289 static bool isSeparator( const QChar &c ); 00290 protected: 00291 //return a ref to index otherwise when we uperCase, index is bad ! 00292 KCommand *doAutoCorrect( KoTextCursor* textEditCursor, KoTextParag *parag, int & index, KoTextObject *txtObj ); 00293 KCommand *doUpperCase( KoTextCursor* textEditCursor, KoTextParag *parag, int index, const QString & word , KoTextObject *txtObj ); 00294 KCommand * doTypographicQuotes( KoTextCursor* textEditCursor, KoTextParag *parag, int index, KoTextObject *txtObj, bool doubleQuotes ); 00295 void buildMaxLen(); 00296 00297 void doAutoDetectUrl( KoTextCursor *textEditCursor, KoTextParag *parag, int & index, const QString & word, KoTextObject *txtObj ); 00298 KCommand *doRemoveSpaceBeginEndLine( KoTextCursor *textEditCursor, KoTextParag *parag, KoTextObject *txtObj ); 00299 KCommand *doAutoChangeFormat( KoTextCursor *textEditCursor, KoTextParag *parag, int index, const QString & word, KoTextObject *txtObj ); 00300 KCommand *doUseBulletStyle(KoTextCursor *textEditCursor, KoTextParag *parag, KoTextObject *txtObj, int& index ); 00301 00302 KCommand *doAutoReplaceNumber( KoTextCursor* textEditCursor, KoTextParag *parag, int & index, const QString & word , KoTextObject *txtObj ); 00303 00304 KCommand *doUseNumberStyle(KoTextCursor * /*textEditCursor*/, KoTextParag *parag, KoTextObject *txtObj, int& index ); 00305 00306 void doAutoIncludeUpperUpper(KoTextCursor *textEditCursor, KoTextParag *parag, KoTextObject *txtObj ); 00307 void doAutoIncludeAbbreviation(KoTextCursor *textEditCursor, KoTextParag *parag, KoTextObject *txtObj ); 00308 00309 KCommand *doAutoSuperScript( KoTextCursor* textEditCursor, KoTextParag *parag, int index, const QString & word , KoTextObject *txtObj ); 00310 KCommand *scanParag( KoTextParag * parag, KoTextObject * obj ); 00311 00312 KCommand *doCapitalizeNameOfDays( KoTextCursor* textEditCursor, KoTextParag *parag, int index, const QString & word , KoTextObject *txtObj ); 00313 00314 static void changeTextFormat(KoSearchContext *formatOptions, KoTextFormat * format, int & flags ); 00315 void loadEntry( const QDomElement &nl); 00316 QDomElement saveEntry( QDictIterator<KoAutoFormatEntry> _entry, QDomDocument doc); 00317 private: 00318 void detectStartOfLink(const QString &word); 00319 void autoFormatIsActive(); 00320 void loadListOfWordCompletion(); 00321 00322 KoDocument *m_doc; 00323 KoVariableCollection *m_varCollection; 00324 KoVariableFormatCollection *m_varFormatCollection; 00325 00326 QString m_autoFormatLanguage; 00327 bool m_configRead; 00328 bool m_convertUpperCase, m_convertUpperUpper,m_advancedAutoCorrect; 00329 bool m_autoDetectUrl, m_ignoreDoubleSpace, m_removeSpaceBeginEndLine; 00330 bool m_useBulletStyle, m_autoChangeFormat, m_autoReplaceNumber; 00331 bool m_useAutoNumberStyle; 00332 bool m_completion; 00333 bool m_completionAppendSpace; 00334 bool m_addCompletionWord; 00335 bool m_includeTwoUpperLetterException; 00336 bool m_includeAbbreviation; 00337 bool m_ignoreUpperCase; 00338 bool m_bAutoFormatActive; 00339 00340 bool m_bAutoSuperScript; 00341 bool m_bAutoCorrectionWithFormat; 00342 bool m_bCapitalizeNameOfDays; 00343 QChar m_bulletStyle; 00344 00345 TypographicQuotes m_typographicSimpleQuotes; 00346 00347 TypographicQuotes m_typographicDoubleQuotes; 00348 00349 TypographicQuotes m_typographicDefaultDoubleQuotes; 00350 00351 TypographicQuotes m_typographicDefaultSimpleQuotes; 00352 00353 KCompletion *m_listCompletion; 00354 00355 QDict<KoAutoFormatEntry> m_entries; 00356 00357 KoAutoFormatEntryMap m_superScriptEntries; 00358 00359 QStringList m_upperCaseExceptions; 00360 QStringList m_twoUpperLetterException; 00361 00362 uint m_maxFindLength; 00363 uint m_minCompletionWordLength; 00364 uint m_nbMaxCompletionWord; 00365 QStringList m_cacheNameOfDays; 00366 }; 00367 00368 #endif
KDE Logo
This file is part of the documentation for lib Library Version 1.3.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Sep 28 04:03:59 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003