00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef koautoformat_h
00022 #define koautoformat_h
00023
00024 #include <QString>
00025 #include <QMap>
00026 #include <QStringList>
00027 #include <qdom.h>
00028 #include <q3dict.h>
00029 #include <QLabel>
00030 #include <QWidget>
00031 #include <koffice_export.h>
00032
00033 class KoDocument;
00034 class KoTextParag;
00035 class KoTextObject;
00036 class KoVariableCollection;
00037 class KoVariableFormatCollection;
00038 class KCompletion;
00039 class KoTextCursor;
00040 class KCommand;
00041 class KoSearchContext;
00042 class KoTextFormat;
00043
00044
00045
00046
00047 class KoCompletionBox : public QLabel
00048 {
00049 Q_OBJECT
00050 public:
00051 KoCompletionBox( QWidget * parent = 0, const char * name = 0, Qt::WFlags f = 0 );
00052 ~KoCompletionBox();
00053 QString& lastWord();
00054 void setLastWord(QString const &);
00055
00056 protected:
00057 void mousePressEvent( QMouseEvent * );
00058
00059 private:
00060 QString m_lastWord;
00061 };
00062
00063
00064
00065
00066
00067
00068 class KoAutoFormatEntry
00069 {
00070 public:
00071
00072
00073 KoAutoFormatEntry(const QString& replace = QString::null);
00074 ~KoAutoFormatEntry();
00075 QString replace() const { return m_replace; }
00076 void changeReplace(const QString & rep){ m_replace = rep; }
00077
00078 KoSearchContext *formatEntryContext()const;
00079 void createNewEntryContext();
00080 void setFormatEntryContext( KoSearchContext * );
00081 void clearFormatEntryContext( );
00082
00083 protected:
00084 QString m_replace;
00085
00086 KoSearchContext *m_formatOptions;
00087 };
00088
00089 typedef QMap< QString, KoAutoFormatEntry > KoAutoFormatEntryMap;
00090
00091
00092
00093
00094 class KOTEXT_EXPORT KoAutoFormat
00095 {
00096 public:
00101 KoAutoFormat( KoDocument *_doc, KoVariableCollection *_varCollection, KoVariableFormatCollection *_varFormatCollection );
00102
00104 KoAutoFormat( const KoAutoFormat& format );
00105
00106 ~KoAutoFormat();
00107
00108 enum KeyCompletionAction { Enter = 0, Tab = 1, Space = 2, End = 3, Right = 4};
00109
00110 KCommand *applyAutoFormat( KoTextObject * obj );
00115 void doAutoFormat( KoTextCursor* cursor, KoTextParag *parag, int index, QChar ch,KoTextObject *txtObj );
00116
00120 bool doCompletion( KoTextCursor* textEditCursor, KoTextParag *parag, int const index,KoTextObject *txtObj );
00121
00122 bool doToolTipCompletion( KoTextCursor* textEditCursor, KoTextParag *parag, int index,KoTextObject *txtObj,int keyPress );
00123 void showToolTipBox(KoTextParag *parag, int index, QWidget *widget, const QPoint &pos);
00124 void removeToolTipCompletion();
00125
00126 bool doIgnoreDoubleSpace( KoTextParag *parag, int index,QChar ch );
00127
00131 static QString getLastWord( KoTextParag *parag, int const index );
00132 QString getLastWord( const int max_words, KoTextParag *parag, int const index );
00133
00139 static QString getWordAfterSpace( KoTextParag * parag, int const index);
00140
00141
00142 struct TypographicQuotes
00143 {
00144 QChar begin, end;
00145 bool replace;
00146 };
00147
00148
00149 void configTypographicDoubleQuotes( TypographicQuotes _tq );
00150 void configTypographicSimpleQuotes( TypographicQuotes _tq );
00151
00152 void configUpperCase( bool _uc );
00153 void configUpperUpper( bool _uu );
00154 void configAdvancedAutocorrect( bool _aa );
00155 void configAutoDetectUrl(bool _au);
00156 void configIgnoreDoubleSpace( bool _ids);
00157 void configRemoveSpaceBeginEndLine( bool _space);
00158 void configUseBulletStyle( bool _ubs);
00159
00160 void configBulletStyle( QChar b );
00161
00162 void configAutoChangeFormat( bool b);
00163
00164 void configAutoReplaceNumber( bool b );
00165
00166 void configAutoNumberStyle( bool b );
00167
00168 void configCompletion( bool b );
00169
00170 void configToolTipCompletion( bool b );
00171
00172 void configAppendSpace( bool b);
00173
00174 void configMinWordLength( int val );
00175
00176 void configNbMaxCompletionWord( int val );
00177
00178 void configAddCompletionWord( bool b );
00179
00180 void configIncludeTwoUpperUpperLetterException( bool b);
00181
00182 void configIncludeAbbreviation( bool b );
00183
00184 void configAutoSuperScript( bool b );
00185
00186 void configCorrectionWithFormat( bool b);
00187
00188 void configCapitalizeNameOfDays( bool b);
00189
00190 void configAutoFormatLanguage( const QString &_lang);
00191
00192 void configKeyCompletionAction( KeyCompletionAction action );
00193
00194 TypographicQuotes getConfigTypographicSimpleQuotes() const
00195 { return m_typographicSimpleQuotes; }
00196
00197 TypographicQuotes getConfigTypographicDoubleQuotes() const
00198 { return m_typographicDoubleQuotes; }
00199
00200 TypographicQuotes getDefaultTypographicDoubleQuotes() const
00201 { return m_typographicDefaultDoubleQuotes; }
00202
00203 TypographicQuotes getDefaultTypographicSimpleQuotes() const
00204 { return m_typographicDefaultSimpleQuotes; }
00205
00206 bool getConfigUpperCase() const
00207 { return m_convertUpperCase; }
00208 bool getConfigUpperUpper() const
00209 { return m_convertUpperUpper; }
00210 bool getConfigAdvancedAutoCorrect() const
00211 { return m_advancedAutoCorrect;}
00212 bool getConfigAutoDetectUrl() const
00213 { return m_autoDetectUrl;}
00214
00215 bool getConfigIgnoreDoubleSpace() const
00216 { return m_ignoreDoubleSpace;}
00217
00218 bool getConfigRemoveSpaceBeginEndLine() const
00219 { return m_removeSpaceBeginEndLine;}
00220
00221 bool getConfigUseBulletSyle() const
00222 { return m_useBulletStyle;}
00223
00224 QChar getConfigBulletStyle() const
00225 { return m_bulletStyle; }
00226
00227 bool getConfigAutoChangeFormat() const
00228 { return m_autoChangeFormat;}
00229
00230 bool getConfigAutoReplaceNumber() const
00231 { return m_autoReplaceNumber; }
00232
00233 bool getConfigAutoNumberStyle() const
00234 { return m_useAutoNumberStyle; }
00235
00236 bool getConfigCompletion() const
00237 { return m_completion; }
00238
00239 bool getConfigToolTipCompletion() const
00240 { return m_toolTipCompletion; }
00241
00242 bool getConfigAppendSpace() const
00243 { return m_completionAppendSpace; }
00244
00245 int getConfigMinWordLength() const
00246 { return m_minCompletionWordLength; }
00247
00248 int getConfigNbMaxCompletionWord() const
00249 { return m_nbMaxCompletionWord; }
00250
00251 bool getConfigAddCompletionWord() const
00252 { return m_addCompletionWord; }
00253
00254 bool getConfigIncludeTwoUpperUpperLetterException() const
00255 { return m_includeTwoUpperLetterException; }
00256
00257 bool getConfigIncludeAbbreviation() const
00258 { return m_includeAbbreviation; }
00259
00260 bool getConfigAutoSuperScript( ) const
00261 { return m_bAutoSuperScript; }
00262
00263 bool getConfigCorrectionWithFormat() const
00264 { return m_bAutoCorrectionWithFormat; }
00265
00266 bool getConfigCapitalizeNameOfDays() const
00267 { return m_bCapitalizeNameOfDays; }
00268
00269 QString getConfigAutoFormatLanguage( )const
00270 { return m_autoFormatLanguage;}
00271
00272 KeyCompletionAction getConfigKeyAction() const
00273 { return m_keyCompletionAction;}
00274
00275 const Q3Dict<KoAutoFormatEntry> & getAutoFormatEntries() const{
00276 return m_entries;
00277 }
00278
00279 KoAutoFormatEntry * findFormatEntry(const QString & text) {
00280 return m_entries[text];
00281 }
00282
00283
00284 void addAutoFormatEntry( const QString &key, KoAutoFormatEntry *entry ) {
00285 m_entries.insert( key, entry );
00286 buildMaxLen();
00287 }
00288
00289 void addAutoFormatEntry( const QString &key, const QString &replace );
00290
00291
00292 void removeAutoFormatEntry( const QString &key ) {
00293 m_entries.setAutoDelete(true);
00294 m_entries.remove( key );
00295 m_entries.setAutoDelete(false);
00296 buildMaxLen();
00297 }
00298
00299
00300 void copyAutoFormatEntries( const KoAutoFormat & other )
00301 { m_entries = other.m_entries; }
00302
00303 void copyListException( const QStringList & _list)
00304 { m_upperCaseExceptions=_list;}
00305
00306 void copyListTwoUpperCaseException( const QStringList &_list)
00307 { m_twoUpperLetterException=_list; }
00308
00309 QStringList listException() const {return m_upperCaseExceptions;}
00310
00311 QStringList listTwoUpperLetterException() const {return m_twoUpperLetterException;}
00312
00313 QStringList listCompletion() const;
00314
00315 KCompletion *getCompletion() const { return m_listCompletion; }
00316
00317 int nbSuperScriptEntry() const
00318 { return m_superScriptEntries.count(); }
00319
00320
00321 void readConfig(bool force = false);
00322 void saveConfig();
00323
00324 static bool isUpper( const QChar &c );
00325 static bool isLower( const QChar &c );
00326 static bool isMark( const QChar &c );
00327 static bool isSeparator( const QChar &c );
00328
00329 void updateMaxWords();
00330 protected:
00331
00332 KCommand *doAutoCorrect( KoTextCursor* textEditCursor, KoTextParag *parag, int & index, KoTextObject *txtObj );
00333 KCommand *doUpperCase( KoTextCursor* textEditCursor, KoTextParag *parag, int index, const QString & word , KoTextObject *txtObj );
00334 KCommand * doTypographicQuotes( KoTextCursor* textEditCursor, KoTextParag *parag, int index, KoTextObject *txtObj, bool doubleQuotes );
00335 void buildMaxLen();
00336
00337 void doAutoDetectUrl( KoTextCursor *textEditCursor, KoTextParag *parag, int & index, QString & word, KoTextObject *txtObj );
00338 KCommand *doRemoveSpaceBeginEndLine( KoTextCursor *textEditCursor, KoTextParag *parag, KoTextObject *txtObj, int& index );
00339 KCommand *doAutoChangeFormat( KoTextCursor *textEditCursor, KoTextParag *parag, int index, const QString & word, KoTextObject *txtObj );
00340 KCommand *doUseBulletStyle(KoTextCursor *textEditCursor, KoTextParag *parag, KoTextObject *txtObj, int& index );
00341
00342 KCommand *doAutoReplaceNumber( KoTextCursor* textEditCursor, KoTextParag *parag, int & index, const QString & word , KoTextObject *txtObj );
00343
00344 KCommand *doUseNumberStyle(KoTextCursor * , KoTextParag *parag, KoTextObject *txtObj, int& index );
00345
00346 void doAutoIncludeUpperUpper(KoTextCursor *textEditCursor, KoTextParag *parag, KoTextObject *txtObj );
00347 void doAutoIncludeAbbreviation(KoTextCursor *textEditCursor, KoTextParag *parag, KoTextObject *txtObj );
00348
00349 KCommand *doAutoSuperScript( KoTextCursor* textEditCursor, KoTextParag *parag, int index, const QString & word , KoTextObject *txtObj );
00350
00351 KCommand *doCapitalizeNameOfDays( KoTextCursor* textEditCursor, KoTextParag *parag, int index, const QString & word , KoTextObject *txtObj );
00352
00353 static void changeTextFormat(KoSearchContext *formatOptions, KoTextFormat * format, int & flags );
00354 void loadEntry( const QDomElement &nl, bool _allLanguages = false);
00355 QDomElement saveEntry( Q3DictIterator<KoAutoFormatEntry> _entry, QDomDocument doc);
00356 private:
00357 void detectStartOfLink(KoTextParag * parag, int const index, bool const insertedDot);
00358 void autoFormatIsActive();
00359 void loadListOfWordCompletion();
00360 void loadAutoCorrection( const QDomElement & _de, bool _allLanguages = false );
00361 void loadAllLanguagesAutoCorrection();
00362 KCommand *autoFormatWord( KoTextCursor* textEditCursor, KoTextParag *parag, int &index, KoTextObject *txtObj, QString * _wordArray, bool _allLanguages );
00363 void readAutoCorrectConfig();
00364
00365 KoDocument *m_doc;
00366 KoVariableCollection *m_varCollection;
00367 KoVariableFormatCollection *m_varFormatCollection;
00368
00369 QString m_autoFormatLanguage;
00370 bool m_configRead;
00371 bool m_convertUpperCase, m_convertUpperUpper,m_advancedAutoCorrect;
00372 bool m_autoDetectUrl, m_ignoreDoubleSpace, m_removeSpaceBeginEndLine;
00373 bool m_useBulletStyle, m_autoChangeFormat, m_autoReplaceNumber;
00374 bool m_useAutoNumberStyle;
00375 bool m_completion;
00376 bool m_toolTipCompletion;
00377 bool m_completionAppendSpace;
00378 bool m_addCompletionWord;
00379 bool m_includeTwoUpperLetterException;
00380 bool m_includeAbbreviation;
00381 bool m_ignoreUpperCase;
00382 bool m_bAutoFormatActive;
00383
00384 bool m_bAutoSuperScript;
00385 bool m_bAutoCorrectionWithFormat;
00386 bool m_bCapitalizeNameOfDays;
00388 bool m_wordInserted;
00389 QChar m_bulletStyle;
00390
00391 TypographicQuotes m_typographicSimpleQuotes;
00392
00393 TypographicQuotes m_typographicDoubleQuotes;
00394
00395 TypographicQuotes m_typographicDefaultDoubleQuotes;
00396
00397 TypographicQuotes m_typographicDefaultSimpleQuotes;
00398
00399 KCompletion *m_listCompletion;
00400
00401 Q3Dict<KoAutoFormatEntry> m_entries;
00402 Q3Dict<KoAutoFormatEntry> m_allLanguages;
00403
00404 KoAutoFormatEntryMap m_superScriptEntries;
00405
00406 QStringList m_upperCaseExceptions;
00407 QStringList m_twoUpperLetterException;
00408
00409 int m_maxFindLength;
00410 int m_minCompletionWordLength;
00411 int m_nbMaxCompletionWord;
00412 int m_countMaxWords;
00413 QStringList m_cacheNameOfDays;
00414 KoCompletionBox *m_completionBox;
00415 KeyCompletionAction m_keyCompletionAction;
00416 };
00417
00418 #endif