21#include "KoAutoFormat.h"
23#include "KoTextObject.h"
24#include "KoTextParag.h"
25#include "KoVariable.h"
26#include "KoParagCounter.h"
27#include <KoDocument.h>
28#include <KoSearchDia.h>
33#include <tdeinstance.h>
35#include <kstandarddirs.h>
39#include <kcompletion.h>
40#include <kcalendarsystem.h>
45#include <tqwhatsthis.h>
50KoCompletionBox::KoCompletionBox( TQWidget * parent,
const char * name, WFlags f)
51 : TQLabel(parent,
name,f)
53 setBackgroundColor(TQColor(
"#FFFFE6"));
54 setFocusPolicy(TQWidget::NoFocus);
55 setFrameShape(TQFrame::Box);
58KoCompletionBox::~KoCompletionBox()
62void KoCompletionBox::mousePressEvent( TQMouseEvent *)
67TQString& KoCompletionBox::lastWord()
72void KoCompletionBox::setLastWord( TQString
const &lastword)
74 m_lastWord = lastword;
77KoAutoFormatEntry::KoAutoFormatEntry(
const TQString& replace)
83KoAutoFormatEntry::~KoAutoFormatEntry()
85 delete m_formatOptions;
89KoSearchContext *KoAutoFormatEntry::formatEntryContext()
const
91 return m_formatOptions;
94void KoAutoFormatEntry::createNewEntryContext()
96 if ( !m_formatOptions )
98 m_formatOptions =
new KoSearchContext();
102void KoAutoFormatEntry::setFormatEntryContext( KoSearchContext *_cont )
104 delete m_formatOptions;
105 m_formatOptions=_cont;
108void KoAutoFormatEntry::clearFormatEntryContext( )
110 delete m_formatOptions;
111 m_formatOptions = 0L;
120 m_varCollection(_varCollection),
121 m_varFormatCollection(_varFormatCollection),
122 m_autoFormatLanguage( TQString()),
123 m_configRead( false ),
124 m_convertUpperCase( false ), m_convertUpperUpper( false ),
125 m_advancedAutoCorrect( true ),
126 m_autoDetectUrl( false ),
127 m_ignoreDoubleSpace( false ),
128 m_removeSpaceBeginEndLine( false ),
129 m_useBulletStyle(false),
130 m_autoChangeFormat(false),
131 m_autoReplaceNumber(false),
132 m_useAutoNumberStyle(false),
134 m_toolTipCompletion(false),
135 m_completionAppendSpace(false),
136 m_addCompletionWord(true),
137 m_includeTwoUpperLetterException(false),
138 m_includeAbbreviation(false),
139 m_ignoreUpperCase(false),
140 m_bAutoFormatActive(true),
141 m_bAutoSuperScript( false ),
142 m_bAutoCorrectionWithFormat( false ),
143 m_bCapitalizeNameOfDays( false ),
144 m_wordInserted( false ),
146 m_typographicSimpleQuotes(),
147 m_typographicDoubleQuotes(),
148 m_typographicDefaultDoubleQuotes(),
149 m_typographicDefaultSimpleQuotes(),
150 m_listCompletion( new TDECompletion ),
152 m_allLanguages(17,false),
153 m_superScriptEntries(),
154 m_upperCaseExceptions(),
155 m_twoUpperLetterException(),
156 m_maxFindLength( 0 ),
157 m_minCompletionWordLength( 5 ),
158 m_nbMaxCompletionWord( 500 ),
161 m_keyCompletionAction( Enter )
165 loadListOfWordCompletion();
166 m_listCompletion->setIgnoreCase(
true );
168 TDELocale tdelocale(m_doc->instance()->instanceName());
169 for (
int i = 1; i <=7; i++)
171 m_cacheNameOfDays.append(tdelocale.calendar()->weekDayName( i ).lower());
175KoAutoFormat::KoAutoFormat(
const KoAutoFormat& format )
176 : m_doc( format.m_doc ),
177 m_varCollection( format.m_varCollection ),
178 m_varFormatCollection( format.m_varFormatCollection ),
179 m_autoFormatLanguage( format.m_autoFormatLanguage),
180 m_configRead( format.m_configRead ),
181 m_convertUpperCase( format.m_convertUpperCase ),
182 m_convertUpperUpper( format.m_convertUpperUpper ),
183 m_advancedAutoCorrect( format.m_advancedAutoCorrect ),
184 m_autoDetectUrl( format.m_autoDetectUrl ),
185 m_ignoreDoubleSpace( format.m_ignoreDoubleSpace ),
186 m_removeSpaceBeginEndLine( format.m_removeSpaceBeginEndLine ),
187 m_useBulletStyle( format.m_useBulletStyle ),
188 m_autoChangeFormat( format.m_autoChangeFormat ),
189 m_autoReplaceNumber( format.m_autoReplaceNumber ),
190 m_useAutoNumberStyle( format.m_useAutoNumberStyle ),
191 m_completion( format.m_completion ),
192 m_toolTipCompletion( format.m_toolTipCompletion),
193 m_completionAppendSpace( format.m_completionAppendSpace ),
194 m_addCompletionWord( format.m_addCompletionWord ),
195 m_includeTwoUpperLetterException( format.m_includeTwoUpperLetterException ),
196 m_includeAbbreviation( format.m_includeAbbreviation ),
197 m_ignoreUpperCase( format.m_ignoreUpperCase ),
198 m_bAutoFormatActive( format.m_bAutoFormatActive ),
199 m_bAutoSuperScript( format.m_bAutoSuperScript ),
200 m_bAutoCorrectionWithFormat( format.m_bAutoCorrectionWithFormat),
201 m_bCapitalizeNameOfDays( format.m_bCapitalizeNameOfDays),
202 m_bulletStyle( format.m_bulletStyle ),
203 m_typographicSimpleQuotes( format.m_typographicSimpleQuotes ),
204 m_typographicDoubleQuotes( format.m_typographicDoubleQuotes ),
205 m_typographicDefaultDoubleQuotes( format.m_typographicDefaultDoubleQuotes),
206 m_typographicDefaultSimpleQuotes( format.m_typographicDefaultSimpleQuotes),
207 m_listCompletion( 0L ),
208 m_entries(17,false ),
209 m_allLanguages(17,false),
210 m_superScriptEntries ( format.m_superScriptEntries ),
211 m_upperCaseExceptions( format.m_upperCaseExceptions ),
212 m_twoUpperLetterException( format.m_twoUpperLetterException ),
213 m_maxFindLength( format.m_maxFindLength ),
214 m_minCompletionWordLength( format.m_minCompletionWordLength ),
215 m_nbMaxCompletionWord( format.m_nbMaxCompletionWord ),
216 m_cacheNameOfDays( format.m_cacheNameOfDays),
218 m_keyCompletionAction( format.m_keyCompletionAction )
225KoAutoFormat::~KoAutoFormat()
227 delete m_listCompletion;
228 m_entries.setAutoDelete(
true );
230 m_allLanguages.setAutoDelete(
true );
231 m_allLanguages.clear();
234void KoAutoFormat::updateMaxWords()
236 TQStringList list = m_listCompletion->items();
237 for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it )
242 for (uint i=0; i < (uint)tmp.length(); i++)
243 if ( tmp.at(i).isSpace() || tmp.at(i).isPunct() )
245 if (maxword > m_countMaxWords )
246 m_countMaxWords = maxword;
248 kdDebug() <<
"m_countMaxWords: " << m_countMaxWords << endl;
251void KoAutoFormat::loadListOfWordCompletion()
253 TDEConfig* config = KoGlobal::kofficeConfig();
254 TDEConfigGroupSaver cgs( config,
"Completion Word" );
255 m_listCompletion->insertItems(config->readListEntry(
"list" ));
258void KoAutoFormat::readConfig(
bool force)
263 if ( m_configRead && !force )
265 TDEConfig* config = KoGlobal::kofficeConfig();
266 TDEConfigGroupSaver cgs( config,
"AutoFormat" );
269 m_autoFormatLanguage = config->readEntry(
"formatLanguage", TQString());
271 m_convertUpperCase = config->readBoolEntry(
"ConvertUpperCase",
false );
272 m_convertUpperUpper = config->readBoolEntry(
"ConvertUpperUpper",
false );
273 m_includeTwoUpperLetterException = config->readBoolEntry(
"includeTwoLetterException",
false );
274 m_includeAbbreviation = config->readBoolEntry(
"includeAbbreviation",
false );
276 m_advancedAutoCorrect = config->readBoolEntry(
"AdvancedAutocorrect",
true );
277 m_bAutoCorrectionWithFormat = config->readBoolEntry(
"AutoCorrectionWithFormat",
false );
278 m_bCapitalizeNameOfDays = config->readBoolEntry(
"CapitalizeNameOfDays",
false );
280 m_autoDetectUrl = config->readBoolEntry(
"AutoDetectUrl",
false);
281 m_ignoreDoubleSpace = config->readBoolEntry(
"IgnoreDoubleSpace",
true);
282 m_removeSpaceBeginEndLine = config->readBoolEntry(
"RemoveSpaceBeginEndLine",
true);
284 m_useBulletStyle = config->readBoolEntry(
"UseBulletStyle",
false);
285 TQString tmp = config->readEntry(
"BulletStyle",
"" );
286 m_bulletStyle = tmp.isEmpty() ? TQChar() : tmp[0];
288 m_autoChangeFormat = config->readBoolEntry(
"AutoChangeFormat",
false );
290 m_autoReplaceNumber = config->readBoolEntry(
"AutoReplaceNumber",
true );
292 m_useAutoNumberStyle = config->readBoolEntry(
"AutoNumberStyle",
false );
295 TQString beginDoubleQuote = config->readEntry(
"TypographicQuotesBegin" );
296 TQString endDoubleQuote = config->readEntry(
"TypographicQuotesEnd" );
298 m_typographicDoubleQuotes.replace = config->readBoolEntry(
"TypographicQuotesEnabled",
false );
300 TQString begin = config->readEntry(
"TypographicSimpleQuotesBegin" );
301 TQString end = config->readEntry(
"TypographicSimpleQuotesEnd" );
302 m_typographicSimpleQuotes.replace = config->readBoolEntry(
"TypographicSimpleQuotesEnabled",
false );
304 m_bAutoSuperScript = config->readBoolEntry(
"AutoSuperScript",
true );
306 config->setGroup(
"completion" );
307 m_completion = config->readBoolEntry(
"completion",
false );
309 m_completionAppendSpace = config->readBoolEntry(
"CompletionAppendSpace",
false );
310 m_minCompletionWordLength = config->readUnsignedNumEntry(
"CompletionMinWordLength", 5 );
311 m_nbMaxCompletionWord = config->readUnsignedNumEntry(
"NbMaxCompletionWord", 100 );
312 m_addCompletionWord = config->readBoolEntry(
"AddCompletionWord",
true );
313 m_toolTipCompletion = config->readBoolEntry(
"ToolTipCompletion",
true );
314 m_keyCompletionAction = ( KoAutoFormat::KeyCompletionAction )config->readUnsignedNumEntry(
"CompletionKeyAction", 0 );
318 m_entries.setAutoDelete(
true);
320 m_entries.setAutoDelete(
false);
321 m_allLanguages.setAutoDelete(
true);
322 m_allLanguages.clear();
323 m_allLanguages.setAutoDelete(
false);
324 m_upperCaseExceptions.clear();
325 m_superScriptEntries.clear();
326 m_twoUpperLetterException.clear();
332 readAutoCorrectConfig();
334 if( beginDoubleQuote.isEmpty())
336 if( m_typographicDefaultDoubleQuotes.begin.isNull())
337 m_typographicDoubleQuotes.begin = TQChar(
'«');
339 m_typographicDoubleQuotes.begin = m_typographicDefaultDoubleQuotes.begin;
342 m_typographicDoubleQuotes.begin = beginDoubleQuote[0];
344 if( endDoubleQuote.isEmpty() )
346 if( m_typographicDefaultDoubleQuotes.end.isNull())
347 m_typographicDoubleQuotes.end = TQChar(
'»');
349 m_typographicDoubleQuotes.end = m_typographicDefaultDoubleQuotes.end;
352 m_typographicDoubleQuotes.end = endDoubleQuote[0];
354 m_typographicDoubleQuotes.replace = m_typographicDoubleQuotes.replace
355 && !m_typographicDoubleQuotes.begin.isNull()
356 && !m_typographicDoubleQuotes.end.isNull();
361 if( m_typographicDefaultSimpleQuotes.begin.isNull())
362 m_typographicSimpleQuotes.begin = TQChar(
'\'');
364 m_typographicSimpleQuotes.begin = m_typographicDefaultSimpleQuotes.begin;
367 m_typographicSimpleQuotes.begin = begin[0];
371 if( m_typographicDefaultSimpleQuotes.end.isNull())
372 m_typographicSimpleQuotes.end = TQChar(
'\'');
374 m_typographicSimpleQuotes.end = m_typographicDefaultSimpleQuotes.end;
377 m_typographicSimpleQuotes.end = end[0];
379 m_typographicSimpleQuotes.replace = m_typographicSimpleQuotes.replace
380 && !m_typographicSimpleQuotes.end.isNull()
381 && !m_typographicSimpleQuotes.begin.isNull();
384 loadAllLanguagesAutoCorrection();
386 autoFormatIsActive();
390void KoAutoFormat::readAutoCorrectConfig()
392 Q_ASSERT( m_entries.isEmpty() );
393 TDELocale tdelocale(m_doc->instance()->instanceName());
394 TQString kdelang = tdelocale.languageList().front();
395 kdelang.remove( TQRegExp(
"@.*" ) );
396 kdDebug(32500) <<
"KoAutoFormat: m_autoFormatLanguage=" << m_autoFormatLanguage <<
" kdelang=" << kdelang << endl;
398 if ( !m_autoFormatLanguage.isEmpty() )
400 fname = locate(
"data",
"koffice/autocorrect/" + m_autoFormatLanguage +
".xml", m_doc->instance() );
402 if ( m_autoFormatLanguage !=
"all_languages" )
404 if ( fname.isEmpty() && !kdelang.isEmpty() )
405 fname = locate(
"data",
"koffice/autocorrect/" + kdelang +
".xml", m_doc->instance() );
406 if ( fname.isEmpty() && kdelang.contains(
"_") )
408 kdelang.remove( TQRegExp(
"_.*" ) );
409 fname = locate(
"data",
"koffice/autocorrect/" + kdelang +
".xml", m_doc->instance() );
411 if ( fname.isEmpty() )
412 fname = locate(
"data",
"koffice/autocorrect/autocorrect.xml", m_doc->instance() );
414 if ( fname.isEmpty() )
416 TQFile xmlFile(fname);
417 if(!xmlFile.open(IO_ReadOnly))
421 if(!doc.setContent(&xmlFile))
424 if(doc.doctype().name() !=
"autocorrection") {
427 TQDomElement de=doc.documentElement();
429 loadAutoCorrection( de );
431 TQDomElement upper = de.namedItem(
"UpperCaseExceptions" ).toElement();
434 TQDomNodeList nl = upper.childNodes();
435 for(uint i = 0; i < nl.count(); i++)
437 m_upperCaseExceptions+= nl.item(i).toElement().attribute(
"exception");
441 TQDomElement twoUpper = de.namedItem(
"TwoUpperLetterExceptions" ).toElement();
442 if(!twoUpper.isNull())
444 TQDomNodeList nl = twoUpper.childNodes();
445 for(uint i = 0; i < nl.count(); i++)
447 m_twoUpperLetterException+= nl.item(i).toElement().attribute(
"exception");
451 TQDomElement superScript = de.namedItem(
"SuperScript" ).toElement();
452 if(!superScript.isNull())
454 TQDomNodeList nl = superScript.childNodes();
455 for(uint i = 0; i < nl.count() ; i++) {
458 m_superScriptEntries.insert( nl.item(i).toElement().attribute(
"find"), KoAutoFormatEntry(nl.item(i).toElement().attribute(
"super")),
false );
462 TQDomElement doubleQuote = de.namedItem(
"DoubleQuote" ).toElement();
463 if(!doubleQuote.isNull())
465 TQDomElement childItem = doubleQuote.namedItem(
"doublequote").toElement();
466 if ( !childItem.isNull() )
468 TQString attr = childItem.attribute(
"begin" );
469 if ( !attr.isEmpty() && attr[0] != 0 )
470 m_typographicDefaultDoubleQuotes.begin = attr[0];
471 attr = childItem.attribute(
"end" );
472 if ( !attr.isEmpty() && attr[0] != 0 )
473 m_typographicDefaultDoubleQuotes.end = attr[0];
476 TQDomElement simpleQuote = de.namedItem(
"SimpleQuote" ).toElement();
477 if(!simpleQuote.isNull())
479 TQDomElement childItem = simpleQuote.namedItem(
"simplequote").toElement();
480 if ( !childItem.isNull() )
482 TQString attr = childItem.attribute(
"begin" );
483 if ( !attr.isEmpty() && attr[0] != 0 )
484 m_typographicDefaultSimpleQuotes.begin = attr[0];
485 attr = childItem.attribute(
"end" );
486 if ( !attr.isEmpty() && attr[0] != 0 )
487 m_typographicDefaultSimpleQuotes.end = attr[0];
492void KoAutoFormat::loadAllLanguagesAutoCorrection()
494 TQString fname = locate(
"data",
"koffice/autocorrect/all_languages.xml", m_doc->instance() );
495 if ( fname.isEmpty() )
497 TQFile xmlFile( fname );
498 if(xmlFile.open(IO_ReadOnly))
501 if(!doc.setContent(&xmlFile)) {
504 if(doc.doctype().name() !=
"autocorrection") {
507 TQDomElement de=doc.documentElement();
509 loadAutoCorrection( de,
true );
514void KoAutoFormat::loadAutoCorrection(
const TQDomElement & _de,
bool _allLanguages )
516 TQDomElement item = _de.namedItem(
"items" ).toElement();
519 TQDomNodeList nl = item.childNodes();
520 m_maxFindLength=nl.count();
521 for(uint i = 0; i < m_maxFindLength; i++) {
522 loadEntry( nl.item(i).toElement(), _allLanguages);
527void KoAutoFormat::loadEntry(
const TQDomElement &nl,
bool _allLanguages)
529 KoAutoFormatEntry *tmp =
new KoAutoFormatEntry(nl.attribute(
"replace"));
530 if ( nl.hasAttribute(
"FONT"))
532 tmp->createNewEntryContext();
533 tmp->formatEntryContext()->m_family=nl.attribute(
"FONT");
534 tmp->formatEntryContext()->m_optionsMask |= KoSearchContext::Family;
536 if ( nl.hasAttribute(
"SIZE" ))
538 tmp->createNewEntryContext();
539 tmp->formatEntryContext()->m_size = nl.attribute(
"SIZE" ).toInt();
540 tmp->formatEntryContext()->m_optionsMask |= KoSearchContext::Size;
542 if (nl.hasAttribute(
"BOLD" ))
544 tmp->createNewEntryContext();
545 tmp->formatEntryContext()->m_optionsMask |= KoSearchContext::Bold;
546 TQString value = nl.attribute(
"BOLD");
547 if ( value.toInt() == 1 )
548 tmp->formatEntryContext()->m_options |= KoSearchContext::Bold;
550 if (nl.hasAttribute(
"ITALIC" ))
552 tmp->createNewEntryContext();
553 tmp->formatEntryContext()->m_optionsMask |= KoSearchContext::Italic;
554 TQString value = nl.attribute(
"ITALIC");
555 if ( value.toInt() == 1 )
556 tmp->formatEntryContext()->m_options |= KoSearchContext::Italic;
558 if (nl.hasAttribute(
"UNDERLINE" ))
560 tmp->createNewEntryContext();
561 tmp->formatEntryContext()->m_optionsMask |= KoSearchContext::Underline;
562 TQString value = nl.attribute(
"UNDERLINE");
563 if ( value ==
"single" )
564 tmp->formatEntryContext()->m_underline = KoTextFormat::U_SIMPLE;
565 else if ( value ==
"double" )
566 tmp->formatEntryContext()->m_underline = KoTextFormat::U_DOUBLE;
567 else if ( value ==
"single-bold" )
568 tmp->formatEntryContext()->m_underline = KoTextFormat::U_SIMPLE_BOLD;
570 tmp->formatEntryContext()->m_underline = KoTextFormat::U_NONE;
572 if (nl.hasAttribute(
"STRIKEOUT" ))
574 tmp->createNewEntryContext();
575 tmp->formatEntryContext()->m_optionsMask |= KoSearchContext::StrikeOut;
576 TQString value = nl.attribute(
"STRIKEOUT");
577 if ( value ==
"single" )
578 tmp->formatEntryContext()->m_strikeOut = KoTextFormat::S_SIMPLE;
579 else if ( value ==
"double" )
580 tmp->formatEntryContext()->m_strikeOut = KoTextFormat::S_DOUBLE;
581 else if ( value ==
"single-bold" )
582 tmp->formatEntryContext()->m_strikeOut = KoTextFormat::S_SIMPLE_BOLD;
584 tmp->formatEntryContext()->m_strikeOut = KoTextFormat::S_NONE;
586 if (nl.hasAttribute(
"VERTALIGN" ))
588 tmp->createNewEntryContext();
589 tmp->formatEntryContext()->m_optionsMask |= KoSearchContext::VertAlign;
590 TQString value = nl.attribute(
"VERTALIGN");
591 tmp->formatEntryContext()->m_vertAlign=
static_cast<KoTextFormat::VerticalAlignment
>( value.toInt() );
594 if ( nl.hasAttribute(
"TEXTCOLOR" ))
596 tmp->createNewEntryContext();
597 tmp->formatEntryContext()->m_optionsMask |= KoSearchContext::Color;
598 TQColor col( nl.attribute(
"TEXTCOLOR" ));
599 tmp->formatEntryContext()->m_color = col;
601 if ( nl.hasAttribute(
"TEXTBGCOLOR" ))
603 tmp->createNewEntryContext();
604 tmp->formatEntryContext()->m_optionsMask |= KoSearchContext::BgColor;
605 TQColor col( nl.attribute(
"TEXTBGCOLOR" ));
606 tmp->formatEntryContext()->m_backGroundColor = col;
608 if ( !_allLanguages )
609 m_entries.insert( nl.attribute(
"find"), tmp );
611 m_allLanguages.insert( nl.attribute(
"find"), tmp );
615void KoAutoFormat::saveConfig()
617 TDEConfig* config = KoGlobal::kofficeConfig();
618 TDELocale tdelocale(m_doc->instance()->instanceName());
620 TDEConfigGroupSaver cgs( config,
"AutoFormat" );
621 config->writeEntry(
"ConvertUpperCase", m_convertUpperCase );
622 config->writeEntry(
"formatLanguage", m_autoFormatLanguage==
"all_languages" ? tdelocale.languageList().front() : m_autoFormatLanguage);
624 config->writeEntry(
"ConvertUpperUpper", m_convertUpperUpper );
625 config->writeEntry(
"includeTwoLetterException", m_includeTwoUpperLetterException );
626 config->writeEntry(
"includeAbbreviation", m_includeAbbreviation );
628 config->writeEntry(
"TypographicQuotesBegin", TQString( m_typographicDoubleQuotes.begin ) );
629 config->writeEntry(
"TypographicQuotesEnd", TQString( m_typographicDoubleQuotes.end ) );
630 config->writeEntry(
"TypographicQuotesEnabled", m_typographicDoubleQuotes.replace );
631 config->writeEntry(
"TypographicSimpleQuotesBegin", TQString( m_typographicSimpleQuotes.begin ) );
632 config->writeEntry(
"TypographicSimpleQuotesEnd", TQString( m_typographicSimpleQuotes.end ) );
633 config->writeEntry(
"TypographicSimpleQuotesEnabled", m_typographicSimpleQuotes.replace );
635 config->writeEntry(
"AdvancedAutocorrect", m_advancedAutoCorrect );
636 config->writeEntry(
"AutoCorrectionWithFormat", m_bAutoCorrectionWithFormat );
637 config->writeEntry(
"CapitalizeNameOfDays", m_bCapitalizeNameOfDays );
639 config->writeEntry(
"AutoDetectUrl",m_autoDetectUrl);
641 config->writeEntry(
"IgnoreDoubleSpace",m_ignoreDoubleSpace );
642 config->writeEntry(
"RemoveSpaceBeginEndLine",m_removeSpaceBeginEndLine );
644 config->writeEntry(
"UseBulletStyle", m_useBulletStyle);
645 config->writeEntry(
"BulletStyle", TQString(m_bulletStyle));
647 config->writeEntry(
"AutoChangeFormat", m_autoChangeFormat);
649 config->writeEntry(
"AutoReplaceNumber", m_autoReplaceNumber);
651 config->writeEntry(
"AutoNumberStyle", m_useAutoNumberStyle );
653 config->writeEntry(
"AutoSuperScript", m_bAutoSuperScript );
655 config->setGroup(
"completion" );
656 config->writeEntry(
"completion", m_completion );
657 config->writeEntry(
"CompletionAppendSpace", m_completionAppendSpace );
658 config->writeEntry(
"CompletionMinWordLength", m_minCompletionWordLength);
659 config->writeEntry(
"NbMaxCompletionWord", m_nbMaxCompletionWord);
660 config->writeEntry(
"AddCompletionWord", m_addCompletionWord );
661 config->writeEntry(
"ToolTipCompletion", m_toolTipCompletion );
662 config->writeEntry(
"CompletionKeyAction", (
int )m_keyCompletionAction );
664 config->setGroup(
"AutoFormatEntries" );
665 TQDictIterator<KoAutoFormatEntry> it( m_entries );
669 TQDomDocument doc(
"autocorrection");
671 TQDomElement begin = doc.createElement(
"Word" );
672 doc.appendChild( begin );
674 items = doc.createElement(
"items");
676 for ( ; it.current() ; ++it )
678 items.appendChild(saveEntry( it, doc));
682 begin.appendChild(items);
685 upper = doc.createElement(
"UpperCaseExceptions");
686 for ( TQStringList::Iterator it = m_upperCaseExceptions.begin(); it != m_upperCaseExceptions.end();++it )
688 data = doc.createElement(
"word");
689 data.setAttribute(
"exception",(*it) );
690 upper.appendChild(data);
692 begin.appendChild(upper);
694 TQDomElement twoUpper;
695 twoUpper = doc.createElement(
"TwoUpperLetterExceptions");
697 for ( TQStringList::Iterator it = m_twoUpperLetterException.begin(); it != m_twoUpperLetterException.end();++it )
699 data = doc.createElement(
"word");
700 data.setAttribute(
"exception",(*it) );
701 twoUpper.appendChild(data);
703 begin.appendChild(twoUpper);
706 super = doc.createElement(
"SuperScript");
707 KoAutoFormatEntryMap::Iterator it2 = m_superScriptEntries.begin();
708 for ( ; it2 != m_superScriptEntries.end() ; ++it2 )
710 data = doc.createElement(
"superscript");
711 data.setAttribute(
"find", it2.key());
712 data.setAttribute(
"super", it2.data().replace());
713 super.appendChild(data);
715 begin.appendChild(super);
717 TQDomElement doubleQuote;
718 doubleQuote = doc.createElement(
"DoubleQuote");
719 data = doc.createElement(
"doublequote");
720 data.setAttribute(
"begin", TQString(m_typographicDefaultDoubleQuotes.begin));
721 data.setAttribute(
"end", TQString(m_typographicDefaultDoubleQuotes.end));
722 doubleQuote.appendChild(data);
723 begin.appendChild(doubleQuote);
726 TQDomElement simpleQuote;
727 simpleQuote = doc.createElement(
"SimpleQuote");
728 data = doc.createElement(
"simplequote");
729 data.setAttribute(
"begin", TQString(m_typographicDefaultSimpleQuotes.begin));
730 data.setAttribute(
"end", TQString(m_typographicDefaultSimpleQuotes.end));
731 simpleQuote.appendChild(data);
732 begin.appendChild(simpleQuote);
734 if ( m_autoFormatLanguage.isEmpty())
735 f.setName(locateLocal(
"data",
"koffice/autocorrect/"+tdelocale.languageList().front() +
".xml",m_doc->instance()));
737 f.setName(locateLocal(
"data",
"koffice/autocorrect/"+m_autoFormatLanguage +
".xml",m_doc->instance()));
738 if(!f.open(IO_WriteOnly)) {
739 kdWarning()<<
"Error during saving autoformat to " << f.name() << endl;
745 autoFormatIsActive();
749TQDomElement KoAutoFormat::saveEntry( TQDictIterator<KoAutoFormatEntry> _entry, TQDomDocument doc)
752 data = doc.createElement(
"item");
753 data.setAttribute(
"find", _entry.currentKey());
754 data.setAttribute(
"replace", _entry.current()->replace());
755 if ( _entry.current()->formatEntryContext() )
757 KoSearchContext *tmp = _entry.current()->formatEntryContext();
758 if ( tmp->m_optionsMask & KoSearchContext::Family )
760 data.setAttribute(
"FONT", tmp->m_family);
762 if ( tmp->m_optionsMask & KoSearchContext::Size )
764 data.setAttribute(
"SIZE", tmp->m_size);
766 if ( tmp->m_optionsMask & KoSearchContext::Italic )
768 data.setAttribute(
"ITALIC",
static_cast<bool>(tmp->m_options & KoSearchContext::Italic));
770 if ( tmp->m_optionsMask & KoSearchContext::Bold )
772 data.setAttribute(
"BOLD",
static_cast<bool>(tmp->m_options & KoSearchContext::Bold));
774 if ( tmp->m_optionsMask & KoSearchContext::Shadow )
776 data.setAttribute(
"SHADOWTEXT",
static_cast<bool>(tmp->m_options & KoSearchContext::Shadow));
778 if ( tmp->m_optionsMask & KoSearchContext::WordByWord )
780 data.setAttribute(
"WORDBYWORD",
static_cast<bool>(tmp->m_options & KoSearchContext::WordByWord));
783 if ( tmp->m_optionsMask & KoSearchContext::Underline )
785 switch( tmp->m_underline )
787 case KoTextFormat::U_SIMPLE:
788 data.setAttribute(
"UNDERLINE",
"single");
790 case KoTextFormat::U_DOUBLE:
791 data.setAttribute(
"UNDERLINE",
"double");
793 case KoTextFormat::U_SIMPLE_BOLD:
794 data.setAttribute(
"UNDERLINE",
"single-bold");
796 case KoTextFormat::U_WAVE:
797 data.setAttribute(
"UNDERLINE",
"wave");
799 case KoTextFormat::U_NONE:
800 data.setAttribute(
"UNDERLINE",
"none");
804 if ( tmp->m_optionsMask & KoSearchContext::StrikeOut )
806 switch( tmp->m_strikeOut )
808 case KoTextFormat::S_SIMPLE:
809 data.setAttribute(
"STRIKEOUT",
"single");
811 case KoTextFormat::S_DOUBLE:
812 data.setAttribute(
"STRIKEOUT",
"double");
814 case KoTextFormat::S_NONE:
815 data.setAttribute(
"STRIKEOUT",
"none");
817 case KoTextFormat::S_SIMPLE_BOLD:
818 data.setAttribute(
"STRIKEOUT",
"single-bold");
822 if ( tmp->m_optionsMask & KoSearchContext::Attribute )
824 data.setAttribute(
"FONTATTRIBUTE", KoTextFormat::attributeFontToString( tmp->m_attribute ) );
827 if ( tmp->m_optionsMask & KoSearchContext::VertAlign)
829 data.setAttribute(
"VERTALIGN",
static_cast<int>(tmp->m_vertAlign) );
831 if ( tmp->m_optionsMask & KoSearchContext::BgColor )
833 data.setAttribute(
"TEXTCOLOR", tmp->m_color.name());
835 if ( tmp->m_optionsMask & KoSearchContext::Color )
837 data.setAttribute(
"TEXTCOLOR", tmp->m_color.name());
839 if ( tmp->m_optionsMask & KoSearchContext::BgColor )
841 data.setAttribute(
"TEXTBGCOLOR", tmp->m_backGroundColor.name());
843 if ( tmp->m_optionsMask & KoSearchContext::Language )
844 data.setAttribute(
"LANGUAGE", tmp->m_language );
849void KoAutoFormat::addAutoFormatEntry(
const TQString &key,
const TQString &replace )
851 KoAutoFormatEntry *findEntry = m_entries.find( key);
854 if ( findEntry->replace().lower() ==
replace.lower() )
858 KoAutoFormatEntry *tmp =
new KoAutoFormatEntry( replace );
859 m_entries.insert( key, tmp );
864TQString KoAutoFormat::getLastWord(KoTextParag *parag,
int const index)
867 KoTextString *s = parag->string();
868 for (
int i = index - 1; i >= 0; --i )
870 TQChar ch = s->at( i ).c;
871 if ( ch.isSpace() || ch.isPunct() )
873 lastWord.prepend( ch );
878TQString KoAutoFormat::getLastWord(
const int max_words, KoTextParag *parag,
int const index)
881 KoTextString
const *s = parag->string();
883 for (
int i = index - 1; i >= 0; --i )
885 TQChar ch = s->at( i ).c;
886 if ( ch.isSpace() || ch.isPunct() )
889 if (words >= max_words)
892 lastWord.prepend( ch );
897TQString KoAutoFormat::getWordAfterSpace(KoTextParag *parag,
int const index)
900 KoTextString *s = parag->string();
901 for (
int i = index - 1; i >= 0; --i )
903 TQChar ch = s->at( i ).c;
912bool KoAutoFormat::doCompletion( KoTextCursor* textEditCursor, KoTextParag *parag,
int const index,
KoTextObject *txtObj )
917 TQString lastWord, word;
918 if (m_completionBox && m_completionBox->isShown() )
920 word = m_completionBox->text();
921 lastWord = m_completionBox->lastWord();
925 TQStringList wordlist, new_wordlist;
926 for (uint i=1; i <= m_countMaxWords; i++ )
928 lastWord = getLastWord(i, parag, index+1);
929 wordlist += m_listCompletion->substringCompletion( lastWord );
932 for ( TQStringList::ConstIterator it = wordlist.begin(); it != wordlist.end(); ++it )
934 if ( (*it).startsWith( lastWord,
false ) && new_wordlist.find(*it) == new_wordlist.end() )
936 if ( (*it).length() > maxlength )
937 maxlength = (*it).length();
938 new_wordlist.append(*it);
942 if ( new_wordlist.isEmpty() )
944 if ( new_wordlist.count() == 1 )
945 word = new_wordlist.first();
949 for (uint i = lastWord.length(); i<maxlength && !part; i++)
951 TQChar ch = new_wordlist.first().at(i);
952 for (TQStringList::ConstIterator it = new_wordlist.begin(); it != new_wordlist.end(); ++it )
954 if ( (*it).at(i).lower() != ch.lower() )
956 word = (*it).left(i);
964 if (word == lastWord)
967 word=lastWord+word.right(word.length()-lastWord.length() );
969 if( !word.isEmpty() )
971 int const lastword_length = lastWord.length();
972 int const start = index+1 - lastword_length;
973 int const length = word.length();
975 KMacroCommand *macro =
new KMacroCommand( i18n(
"Completion Word"));
976 KoTextCursor cursor( parag->document() );
977 cursor.setParag( parag );
978 cursor.setIndex( start );
979 KoTextDocument * textdoc = parag->textDocument();
980 if( m_completionAppendSpace && !part)
982 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
983 cursor.setIndex( start + lastword_length );
984 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
986 macro->
addCommand( txtObj->replaceSelectionCommand( textEditCursor, word,
987 i18n(
"Completion Word"),
988 KoTextDocument::HighlightSelection ));
990 if ( m_completionAppendSpace && !m_ignoreUpperCase && (m_convertUpperUpper || m_convertUpperCase) && !part)
993 for (uint i=1; i < word.length(); i++)
994 if ( word.at(i).isSpace() || word.at(i).isPunct() )
999 int const newPos = start + word.length();
1000 KCommand *cmd = doUpperCase( textEditCursor, parag, newPos, word, txtObj );
1003 txtObj->emitHideCursor();
1004 textEditCursor->setIndex(start+ length+1);
1008 txtObj->emitHideCursor();
1009 textEditCursor->setIndex(start+ length);
1011 txtObj->emitNewCommand( macro );
1016 txtObj->emitShowCursor();
1017 removeToolTipCompletion();
1024bool KoAutoFormat::doToolTipCompletion( KoTextCursor* textEditCursor, KoTextParag *parag,
int index,
KoTextObject *txtObj,
int keyPressed )
1026 if( m_completion && m_toolTipCompletion && m_completionBox && m_completionBox->isShown() )
1028 if ( ( keyPressed == TQt::Key_Return && m_keyCompletionAction==Enter )
1029 || ( keyPressed == TQt::Key_Enter && m_keyCompletionAction==Enter )
1030 || ( keyPressed == TQt::Key_Tab && m_keyCompletionAction==Tab )
1031 || ( keyPressed == TQt::Key_Space && m_keyCompletionAction==Space )
1032 || ( keyPressed == TQt::Key_End && m_keyCompletionAction==End )
1033 || ( keyPressed == TQt::Key_Right && m_keyCompletionAction==Right ))
1035 return doCompletion(textEditCursor, parag, index, txtObj);
1040void KoAutoFormat::showToolTipBox(KoTextParag *parag,
int index, TQWidget *widget,
const TQPoint &pos )
1043 if( m_completion && m_toolTipCompletion)
1045 TQString lastWord, word;
1046 for (uint i=1; i <= m_countMaxWords; i++ )
1048 lastWord = getLastWord(i, parag, index+1);
1049 word=m_listCompletion->makeCompletion( lastWord );
1050 if ( !word.isEmpty())
1053 if( !word.isEmpty() && word!=lastWord )
1055 uint
const length = lastWord.length();
1058 word=lastWord+word.right(word.length()-length);
1059 if (!m_completionBox)
1060 m_completionBox =
new KoCompletionBox(0,0,TQt::WType_Popup);
1061 TQPoint
const show_pos = widget->mapToGlobal(pos);
1062 m_completionBox->setText(word);
1063 m_completionBox->setLastWord(lastWord);
1064 m_completionBox->adjustSize();
1065 int const height = m_completionBox->sizeHint().height();
1066 m_completionBox->move( show_pos.x(), show_pos.y() - height );
1068 if (!m_completionBox->isShown() )
1070 m_completionBox->show();
1075 removeToolTipCompletion();
1078void KoAutoFormat::removeToolTipCompletion()
1080 if (m_completion && m_toolTipCompletion && m_completionBox && m_completionBox->isShown())
1081 m_completionBox->hide();
1084void KoAutoFormat::autoFormatIsActive()
1086 m_bAutoFormatActive = m_useBulletStyle ||
1087 m_removeSpaceBeginEndLine ||
1089 m_convertUpperUpper ||
1090 m_convertUpperCase ||
1091 m_autoReplaceNumber ||
1092 m_autoChangeFormat ||
1094 m_typographicDoubleQuotes.replace ||
1095 m_typographicSimpleQuotes.replace ||
1096 m_entries.count()!=0 ||
1097 m_allLanguages.count()!=0;
1100void KoAutoFormat::doAutoFormat( KoTextCursor* textEditCursor, KoTextParag *parag,
int index, TQChar ch,
KoTextObject *txtObj )
1102 m_ignoreUpperCase =
false;
1104 if ( !m_configRead )
1107 if ( !m_bAutoFormatActive )
1116 TQString word=getWordAfterSpace(parag,index);
1118 if ( m_autoChangeFormat && index > 3)
1120 KCommand *cmd =doAutoChangeFormat( textEditCursor, parag, index, word, txtObj );
1122 txtObj->emitNewCommand( cmd );
1125 if ( m_autoReplaceNumber )
1127 KCommand *cmd = doAutoReplaceNumber( textEditCursor, parag, index, word, txtObj );
1129 txtObj->emitNewCommand( cmd );
1136 if( m_removeSpaceBeginEndLine && index > 1)
1138 KCommand *cmd = doRemoveSpaceBeginEndLine( textEditCursor, parag, txtObj, index );
1140 txtObj->emitNewCommand( cmd );
1142 if( m_useBulletStyle && index > 3)
1144 KCommand *cmd =doUseBulletStyle( textEditCursor, parag, txtObj, index );
1146 txtObj->emitNewCommand( cmd );
1148 if( m_useAutoNumberStyle && index > 3 )
1150 KCommand *cmd =doUseNumberStyle( textEditCursor, parag, txtObj, index );
1152 txtObj->emitNewCommand( cmd );
1154 if( m_convertUpperUpper && m_includeTwoUpperLetterException )
1155 doAutoIncludeUpperUpper(textEditCursor, parag, txtObj );
1156 if( m_convertUpperCase && m_includeAbbreviation )
1157 doAutoIncludeAbbreviation(textEditCursor, parag, txtObj );
1164 if ( (ch.isSpace() || ch==
':' || ch==
'?' || ch==
'!' || ch==
',' || (m_advancedAutoCorrect && ch==
'.') ) && index > 0 )
1167 KMacroCommand *macro = 0L;
1168 TQString lastWord = getWordAfterSpace(parag, index);
1172 detectStartOfLink( parag, index,
true );
1174 detectStartOfLink( parag, index,
false );
1176 if ( !m_wordInserted && m_advancedAutoCorrect && !m_ignoreUpperCase)
1178 int const completionBeginPos = index -lastWord.length();
1180 cmd = doAutoCorrect( textEditCursor, parag, newPos, txtObj );
1185 macro =
new KMacroCommand(i18n(
"Autocorrection"));
1189 int const endPos=textEditCursor->index();
1190 bool was_a_replacement;
1191 if (index == newPos)
1192 was_a_replacement =
false;
1194 was_a_replacement =
true;
1196 if( was_a_replacement)
1198 txtObj->emitHideCursor();
1201 textEditCursor->gotoUp();
1202 textEditCursor->gotoLineEnd();
1203 newPos=textEditCursor->index();
1208 m_wordInserted =
true;
1209 for(
int i=completionBeginPos; i<newPos;i++)
1211 textEditCursor->setIndex(i);
1212 doAutoFormat( textEditCursor, parag, i, parag->toString().at(i),txtObj );
1215 textEditCursor->setIndex(newPos);
1216 doAutoFormat( textEditCursor, parag, newPos, ch,txtObj );
1217 m_wordInserted =
false;
1220 textEditCursor->gotoLineStart();
1221 textEditCursor->gotoDown();
1224 textEditCursor->setIndex(newPos+1);
1225 txtObj->emitShowCursor();
1231 if (!m_ignoreUpperCase && m_bCapitalizeNameOfDays)
1233 KCommand *cmd = doCapitalizeNameOfDays( textEditCursor, parag, index, lastWord, txtObj );
1238 macro =
new KMacroCommand(i18n(
"Autocorrection"));
1240 m_ignoreUpperCase =
true;
1248 if( !m_ignoreUpperCase && m_completion && m_addCompletionWord && m_listCompletion->items().count() < m_nbMaxCompletionWord )
1250 TQString completionWord(
"");
1252 for (uint i=0;i<lastWord.length();i++)
1254 ch = lastWord.at(i);
1255 if (ch.isPunct() && ch!=
'-' && ch!=
'=' )
1257 if (completionWord.at(0) ==
'-')
1258 completionWord.remove(0,1);
1260 if (completionWord.length()>= m_minCompletionWordLength && !completionWord.isEmpty() && m_listCompletion->makeCompletion(completionWord).isEmpty())
1262 kdDebug() <<
"Adding:" << completionWord << endl;
1263 m_listCompletion->addItem( completionWord );
1264 if ( completionWord.length() > m_countMaxWords )
1265 m_countMaxWords = completionWord.length();
1268 completionWord =
"";
1272 completionWord.append(ch);
1273 if (i==lastWord.length()-1)
1275 if (completionWord.at(0) ==
'-')
1276 completionWord.remove(0,1);
1277 if (completionWord.at(completionWord.length()-1) ==
'-')
1278 completionWord.truncate(completionWord.length()-1);
1279 completionWord.remove(
'=');
1280 if (completionWord.length()>= m_minCompletionWordLength && !completionWord.isEmpty() && m_listCompletion->makeCompletion(completionWord).isEmpty())
1282 kdDebug() <<
"Adding:" << completionWord << endl;
1283 m_listCompletion->addItem( completionWord );
1284 if ( completionWord.length() > m_countMaxWords )
1285 m_countMaxWords = completionWord.length();
1292 if( m_autoDetectUrl && m_ignoreUpperCase && (ch!=
'?' || lastWord.at(lastWord.length()-1)==
'?') )
1294 doAutoDetectUrl( textEditCursor, parag, index, lastWord, txtObj );
1298 if (!m_ignoreUpperCase && (m_convertUpperUpper || m_convertUpperCase) )
1300 cmd = doUpperCase( textEditCursor, parag, index, lastWord, txtObj );
1305 macro =
new KMacroCommand(i18n(
"Autocorrection"));
1311 txtObj->emitNewCommand( macro );
1313 if(!m_ignoreUpperCase && m_bAutoSuperScript && m_superScriptEntries.count()>0)
1315 if( lastWord.at(0).isPunct() )
1316 lastWord.remove(0,1);
1317 KCommand * cmd = doAutoSuperScript( textEditCursor, parag, index, lastWord, txtObj );
1319 txtObj->emitNewCommand( cmd );
1325 if ( ch ==
'"' && m_typographicDoubleQuotes.replace )
1327 KCommand *cmd = doTypographicQuotes( textEditCursor, parag, index, txtObj,
true );
1329 txtObj->emitNewCommand( cmd );
1331 else if ( ch ==
'\'' && m_typographicDoubleQuotes.replace )
1333 KCommand *cmd = doTypographicQuotes( textEditCursor, parag, index, txtObj,
false );
1335 txtObj->emitNewCommand( cmd );
1340KCommand *KoAutoFormat::doAutoCorrect( KoTextCursor* textEditCursor, KoTextParag *parag,
int &index,
KoTextObject *txtObj )
1347 TQString * wordArray =
new TQString[m_maxFindLength+1];
1350 KoTextString *s = parag->string();
1351 for (
int i = index - 1; i >= 0; --i )
1353 TQChar ch = s->at( i ).c;
1355 if ( ch.isSpace() || i==0)
1357 if(i==0 && word.length()<m_maxFindLength)
1359 wordArray[word.length()]=word;
1362 if (((index - 1)-i) == (
int)m_maxFindLength)
1367 KCommand *cmd = autoFormatWord( textEditCursor, parag, index, txtObj, wordArray,
false );
1369 cmd = autoFormatWord( textEditCursor, parag, index, txtObj, wordArray,
true );
1370 delete [] wordArray;
1375KCommand *KoAutoFormat::autoFormatWord( KoTextCursor* textEditCursor, KoTextParag *parag,
int &index,
KoTextObject *txtObj, TQString * _wordArray,
bool _allLanguages )
1377 KoTextDocument * textdoc = parag->textDocument();
1382 for(
int i=m_maxFindLength;i>0;--i)
1384 if ( !_wordArray[i].isEmpty())
1386 KoAutoFormatEntry* it = 0L;
1387 if ( _allLanguages )
1388 it = m_allLanguages[ _wordArray[i] ];
1390 it = m_entries[ _wordArray[i] ];
1391 if ( _wordArray[i]!=0 && it )
1393 unsigned int length = _wordArray[i].length();
1394 int const start = index - length;
1395 KoTextCursor cursor( parag->document() );
1396 cursor.setParag( parag );
1397 cursor.setIndex( start );
1398 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1399 cursor.setIndex( start + length );
1400 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1402 kdDebug()<<
"it->replace() :"<<it->replace()<<endl;
1403 if (!it->formatEntryContext() || !m_bAutoCorrectionWithFormat)
1405 cmd = txtObj->replaceSelectionCommand( textEditCursor, it->replace(),
1406 i18n(
"Autocorrect Word"),
1407 KoTextDocument::HighlightSelection );
1412 KoTextFormat * lastFormat = parag->at( start )->format();
1413 KoTextFormat * newFormat =
new KoTextFormat(*lastFormat);
1414 changeTextFormat(it->formatEntryContext(), newFormat, flags );
1415 KMacroCommand *macro =
new KMacroCommand( i18n(
"Autocorrect Word with Format"));
1416 KCommand *cmd2=txtObj->replaceSelectionCommand( textEditCursor, it->replace(),
1417 i18n(
"Autocorrect Word"),
1418 KoTextDocument::HighlightSelection );
1421 KoTextCursor cursor( parag->document() );
1422 cursor.setParag( parag );
1423 cursor.setIndex( start );
1424 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1425 cursor.setIndex( start + it->replace().length() );
1426 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1428 cmd2 =txtObj->
setFormatCommand( textEditCursor, &lastFormat, newFormat, flags,
false, KoTextDocument::HighlightSelection );
1431 index = index - length + it->replace().length();
1432 textEditCursor->setIndex(index+1);
1433 cmd2 =txtObj->
setFormatCommand( textEditCursor, &newFormat, lastFormat, 0 );
1435 parag->at( index+1 )->setFormat(lastFormat);
1438 txtObj->emitHideCursor();
1439 textEditCursor->gotoRight();
1440 txtObj->emitShowCursor();
1447 txtObj->emitHideCursor();
1448 textEditCursor->gotoRight();
1449 txtObj->emitShowCursor();
1450 index = index - length + it->replace().length();
1458KCommand *KoAutoFormat::doTypographicQuotes( KoTextCursor* textEditCursor, KoTextParag *parag,
int index,
KoTextObject *txtObj,
bool doubleQuotes )
1461 KoTextDocument * textdoc = parag->textDocument();
1462 KoTextCursor cursor( parag->document() );
1463 cursor.setParag( parag );
1464 cursor.setIndex( index );
1465 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1466 cursor.setIndex( index + 1 );
1467 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1479 TQString replacement;
1484 TQChar::Category c1 = parag->at( index - 1 )->c.category();
1487 if ( c1 == TQChar::Separator_Space || c1 == TQChar::Separator_Line || c1 == TQChar::Separator_Paragraph ||
1488 c1 == TQChar::Punctuation_Open || c1 == TQChar::Other_Control )
1492 if ( c1 == TQChar::Punctuation_InitialQuote )
1494 TQChar openingQuote;
1497 openingQuote = m_typographicDoubleQuotes.begin;
1499 openingQuote = m_typographicSimpleQuotes.begin;
1502 if( parag->at( index - 1 )->c != openingQuote )
1508 if( index > 1 && !ending )
1510 TQChar::Category c2 = parag->at( index - 2 )->c.category();
1511 ending = (c2 == TQChar::Punctuation_InitialQuote);
1517 replacement = m_typographicDoubleQuotes.end;
1519 replacement = m_typographicSimpleQuotes.end;
1524 replacement = m_typographicDoubleQuotes.begin;
1526 replacement = m_typographicSimpleQuotes.begin;
1528 return txtObj->replaceSelectionCommand( textEditCursor, replacement,
1529 i18n(
"Typographic Quote"),
1530 KoTextDocument::HighlightSelection );
1533KCommand * KoAutoFormat::doUpperCase( KoTextCursor *textEditCursor, KoTextParag *parag,
1534 int index,
const TQString & word,
KoTextObject *txtObj )
1536 KoTextDocument * textdoc = parag->textDocument();
1537 unsigned int length = word.length();
1538 if (word.at(length-1) ==
'.' )
1543 int const start = index - length;
1544 KoTextCursor backCursor( parag->document() );
1545 backCursor.setParag( parag );
1546 backCursor.setIndex( start );
1549 TQChar
const firstChar = backCursor.parag()->at( backCursor.index() )->c;
1551 bool bNeedMove =
false;
1553 if ( m_convertUpperCase && isLower( firstChar ) )
1555 bool beginningOfSentence =
true;
1557 while ( backCursor.index() > 0 || backCursor.parag()->prev() )
1559 beginningOfSentence =
false;
1560 backCursor.gotoLeft();
1561 if ( !backCursor.parag()->at( backCursor.index() )->c.isSpace() )
1565 if ( !beginningOfSentence )
1566 beginningOfSentence = isMark( backCursor.parag()->at( backCursor.index() )->c);
1568 if ( !beginningOfSentence && start==0 )
1569 if ( parag->counter() || backCursor.parag()->at( backCursor.index() )->c.isPunct() )
1570 beginningOfSentence =
true;
1573 if ( beginningOfSentence )
1575 TQChar
const punct = backCursor.parag()->at( backCursor.index() )->c;
1576 TQString
const text = getLastWord( backCursor.parag(), backCursor.index() )
1578 kdDebug() <<
"text: " << text << endl;
1580 beginningOfSentence = (m_upperCaseExceptions.findIndex(text)==-1);
1583 if ( beginningOfSentence )
1585 KoTextCursor cursor( parag->document() );
1586 cursor.setParag( parag );
1587 cursor.setIndex( start );
1588 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1589 cursor.setIndex( start + 1 );
1590 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1591 cmd = txtObj->replaceSelectionCommand( textEditCursor, TQString( firstChar.upper() ),
1592 i18n(
"Autocorrect (capitalize first letter)"),
1593 KoTextDocument::HighlightSelection );
1597 else if ( m_convertUpperUpper && isUpper( firstChar ) && length > 2 )
1599 backCursor.setIndex( backCursor.index() + 1 );
1600 TQChar secondChar = backCursor.parag()->at( backCursor.index() )->c;
1602 if ( isUpper( secondChar ) )
1605 backCursor.setIndex( backCursor.index() + 1 );
1606 TQChar thirdChar = backCursor.parag()->at( backCursor.index() )->c;
1607 if ( isLower( thirdChar ) && (m_twoUpperLetterException.findIndex(word)==-1))
1610 KoTextCursor cursor( parag->document() );
1611 cursor.setParag( parag );
1612 cursor.setIndex( start + 1 );
1613 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1614 cursor.setIndex( start + 2 );
1615 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1617 TQString replacement = word[1].lower();
1618 cmd = txtObj->replaceSelectionCommand( textEditCursor, replacement,
1619 i18n(
"Autocorrect"),
1620 KoTextDocument::HighlightSelection );
1628 if (word.at(word.length()-1) ==
'.' )
1630 txtObj->emitHideCursor();
1631 textEditCursor->setParag( parag );
1632 textEditCursor->setIndex( index );
1633 textEditCursor->gotoRight();
1634 txtObj->emitShowCursor();
1639KCommand * KoAutoFormat::doAutoReplaceNumber( KoTextCursor* textEditCursor, KoTextParag *parag,
int& index,
const TQString & word ,
KoTextObject *txtObj )
1641 unsigned int length = word.length();
1644 KoTextDocument * textdoc = parag->textDocument();
1645 int start = index - length;
1646 if( word == TQString(
"1/2") || word == TQString(
"1/4") || word == TQString(
"3/4") )
1648 KoTextCursor cursor( parag->document() );
1649 cursor.setParag( parag );
1650 cursor.setIndex( start );
1651 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1652 cursor.setIndex( start + length );
1653 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1654 TQString replacement;
1655 if( word == TQString(
"1/2") )
1656 replacement=TQString(
"½");
1657 else if (word == TQString(
"1/4") )
1658 replacement=TQString(
"¼");
1659 else if (word == TQString(
"3/4") )
1660 replacement=TQString(
"¾");
1661 TQString cmdName = i18n(
"Autocorrect for Fraction");
1662 KCommand *cmd =txtObj->replaceSelectionCommand( textEditCursor, replacement,
1664 KoTextDocument::HighlightSelection );
1665 txtObj->emitHideCursor();
1666 textEditCursor->gotoRight();
1667 txtObj->emitShowCursor();
1668 index = index - length + replacement.length();
1674void KoAutoFormat::detectStartOfLink(KoTextParag * parag,
int const index,
bool const insertedDot)
1677 KoTextString *s = parag->string();
1678 for (
int i = 0; i < index; ++i )
1680 word.append( s->at( i ).c );
1683 if (word.find(
"http")!=-1 || word.find(
"https")!=-1 || word.find(
"mailto")!=-1 || word.find(
"ftp")!=-1 || word.find(
"file")!=-1
1684 || word.find(
"news")!=-1 || word.find(
'@')!=-1)
1685 m_ignoreUpperCase=
true;
1688 int const tmp_pos=word.find(
"www.");
1689 if (tmp_pos!=-1 && (word.find(
'.',tmp_pos+4)!=-1 || insertedDot) )
1690 m_ignoreUpperCase=
true;
1694void KoAutoFormat::doAutoDetectUrl( KoTextCursor *textEditCursor, KoTextParag *parag,
int &index, TQString & word,
KoTextObject *txtObj )
1696 kdDebug() <<
"link:" << word << endl;
1698 int pos = word.find(
"http://");
1699 int tmp_pos = word.find(
"https://");
1700 if(tmp_pos<pos && tmp_pos!=-1)
1702 tmp_pos = word.find(
"mailto:/");
1703 if((tmp_pos<pos || pos==-1 ) && tmp_pos!=-1)
1705 tmp_pos = word.find(
"ftp://");
1706 if((tmp_pos<pos || pos==-1 ) && tmp_pos!=-1)
1708 tmp_pos = word.find(
"ftp.");
1709 if((tmp_pos<pos || pos==-1 ) && tmp_pos!=-1)
1714 tmp_pos = word.find(
"file:/");
1715 if((tmp_pos<pos || pos==-1 ) && tmp_pos!=-1)
1717 tmp_pos = word.find(
"news:");
1718 if((tmp_pos<pos || pos==-1 ) && tmp_pos!=-1)
1720 tmp_pos = word.find(
"www.");
1721 if((tmp_pos<pos || pos==-1 ) && tmp_pos!=-1 && word.find(
'.',tmp_pos+4)!=-1 )
1726 tmp_pos = word.find(
'@');
1727 if ( pos == -1 && tmp_pos != -1 )
1734 if ( c.isPunct() && c!=
'.'&& c!=
'_')
break;
1737 if ( pos == tmp_pos-1 )
1739 m_ignoreUpperCase =
false;
1749 while ( !word.at(word.length()-1).isLetter() && !word.at(word.length()-1).isDigit() && word.at(word.length()-1)!=
'/')
1751 word.truncate(word.length()-1);
1755 unsigned int const length = word.length();
1756 int const start = index - length;
1757 KoTextCursor cursor( parag->document() );
1758 KoTextDocument * textdoc = parag->textDocument();
1759 cursor.setParag( parag );
1760 cursor.setIndex( start );
1761 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1762 cursor.setIndex( start + length );
1763 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1764 TQString newWord = word;
1766 newWord = TQString(
"mailto:") + word;
1767 else if(link_type==2)
1768 newWord = TQString(
"http://") + word;
1769 else if(link_type==3)
1770 newWord = TQString(
"ftp://") + word;
1772 KoVariable* var =
new KoLinkVariable( textdoc, word, newWord, m_varFormatCollection->format(
"STRING" ), m_varCollection );
1773 CustomItemsMap customItemsMap;
1774 customItemsMap.insert( 0, var );
1775 KoTextFormat * lastFormat = parag->at( start )->format();
1776 int origCursorIndex = textEditCursor->index();
1777 txtObj->
insert( textEditCursor, lastFormat, KoTextObject::customItemChar(), i18n(
"Insert Variable"),
1778 KoTextDocument::HighlightSelection, KoTextObject::DefaultInsertFlags, customItemsMap );
1780 parag->invalidate(0);
1781 parag->setChanged(
true );
1786 txtObj->emitHideCursor();
1787 textEditCursor->setIndex( origCursorIndex - (length-1) );
1788 txtObj->emitShowCursor();
1791 if ( m_completion && m_addCompletionWord && m_listCompletion->items().count() < m_nbMaxCompletionWord )
1793 if (word.length()>= m_minCompletionWordLength && !word.isEmpty() && m_listCompletion->makeCompletion(word).isEmpty())
1795 kdDebug() <<
"Adding:" << word << endl;
1796 m_listCompletion->addItem( word );
1797 if ( word.length() > m_countMaxWords )
1798 m_countMaxWords = word.length();
1804void KoAutoFormat::doAutoIncludeUpperUpper(KoTextCursor* , KoTextParag *parag,
KoTextObject* )
1806 KoTextString *s = parag->string();
1808 if( s->length() < 2 )
1811 for (
int i=0; i<=(s->length() - 1);i++)
1814 for (
int j = i ; j < s->length() - 1; j++ )
1816 TQChar ch = s->at( j ).c;
1821 if( word.length() > 2 && word.left(2)==word.left(2).upper() && word.at(3)!=word.at(3).upper() )
1823 if ( m_twoUpperLetterException.findIndex(word )==-1)
1824 m_twoUpperLetterException.append( word);
1832void KoAutoFormat::doAutoIncludeAbbreviation(KoTextCursor* , KoTextParag *parag,
KoTextObject* )
1834 KoTextString *s = parag->string();
1835 if( s->length() < 2 )
1837 for (
int i=0; i<=(s->length() - 1);i++)
1842 for (
int j = i ; j < s->length() - 1; j++ )
1844 TQChar ch = s->at( j ).c;
1849 if ( isMark( word.at(word.length()-1)) )
1851 for (
int j = i+word.length()+1 ; j < s->length() - 1; j++ )
1853 TQChar ch = s->at( j ).c;
1856 wordAfter.append( ch );
1858 if( word.length()>1 && !wordAfter.isEmpty() && wordAfter.at(0)==wordAfter.at(0).lower())
1860 if ( m_upperCaseExceptions.findIndex(word )==-1)
1861 m_upperCaseExceptions.append( word );
1865 if( !wordAfter.isEmpty())
1867 i+=wordAfter.length()+1;
1874KCommand * KoAutoFormat::doAutoChangeFormat( KoTextCursor *textEditCursor, KoTextParag *parag,
int index,
const TQString & word,
KoTextObject *txtObj )
1876 bool underline = (word.at(0)==
'_' && word.at(word.length()-1)==
'_');
1877 bool bold = (word.at(0)==
'*' && word.at(word.length()-1)==
'*');
1878 if( bold || underline)
1880 TQString replacement=word.mid(1,word.length()-2);
1881 int start = index - word.length();
1882 KoTextDocument * textdoc = parag->textDocument();
1883 KMacroCommand *macro=
new KMacroCommand(i18n(
"Autocorrection: Change Format"));
1884 KoTextCursor cursor( parag->document() );
1886 cursor.setParag( parag );
1887 cursor.setIndex( start );
1888 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1889 cursor.setIndex( start + word.length() );
1890 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1891 macro->
addCommand(txtObj->replaceSelectionCommand( textEditCursor, replacement,
1892 i18n(
"Autocorrect Word"),
1893 KoTextDocument::HighlightSelection));
1895 KoTextFormat * lastFormat = parag->at( start )->format();
1896 KoTextFormat * newFormat =
new KoTextFormat(*lastFormat);
1897 cursor.setIndex( start );
1898 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1899 cursor.setIndex( start + word.length()-2 );
1900 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1904 newFormat->setBold(
true);
1905 macro->
addCommand(txtObj->
setFormatCommand( textEditCursor, 0L, newFormat, KoTextFormat::Bold ,
false,KoTextDocument::HighlightSelection ));
1907 else if( underline )
1909 newFormat->setUnderline(
true);
1910 macro->
addCommand(txtObj->
setFormatCommand( textEditCursor, 0L, newFormat, KoTextFormat::Underline ,
false,KoTextDocument::HighlightSelection ));
1912 txtObj->emitHideCursor();
1913 textEditCursor->gotoRight();
1914 txtObj->emitShowCursor();
1920KCommand *KoAutoFormat::doUseBulletStyle(KoTextCursor * , KoTextParag *parag,
KoTextObject *txtObj,
int& index )
1922 KoTextDocument * textdoc = parag->textDocument();
1923 KoTextCursor cursor( parag->document() );
1924 KoTextString *s = parag->string();
1925 TQChar ch = s->at( 0 ).c;
1927 if( m_useBulletStyle && (ch ==
'*' || ch ==
'-' || ch ==
'+') && (s->at(1).c).isSpace())
1929 if ( parag->counter() && parag->counter()->
numbering() == KoParagCounter::NUM_FOOTNOTE )
1931 KMacroCommand *macroCmd =
new KMacroCommand( i18n(
"Autocorrect (use bullet style)"));
1932 cursor.setParag( parag );
1933 cursor.setIndex( 0 );
1934 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1935 cursor.setParag( parag );
1936 cursor.setIndex( 2 );
1937 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1938 KCommand *cmd=txtObj->removeSelectedTextCommand( &cursor, KoTextDocument::HighlightSelection );
1944 cursor.setParag( parag );
1945 cursor.setIndex( 0 );
1946 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1948 cursor.setIndex( 2 );
1949 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1953 if( m_bulletStyle.isNull() && (ch ==
'*' || ch ==
'+' || ch ==
'-'))
1957 c.setNumbering( KoParagCounter::NUM_LIST );
1958 c.setStyle( KoParagCounter::STYLE_DISCBULLET );
1960 else if ( ch ==
'+' || ch==
'-')
1962 c.setNumbering( KoParagCounter::NUM_LIST );
1963 c.setStyle( KoParagCounter::STYLE_CUSTOMBULLET );
1965 c.setCustomBulletCharacter(
'-' );
1967 c.setCustomBulletCharacter(
'+' );
1972 c.setNumbering( KoParagCounter::NUM_LIST );
1973 c.setStyle( KoParagCounter::STYLE_CUSTOMBULLET );
1974 c.setCustomBulletCharacter( m_bulletStyle );
1976 c.setSuffix(TQString());
1977 cmd=txtObj->setCounterCommand( &cursor, c ,KoTextDocument::HighlightSelection );
1981 cursor.setParag( parag->next() );
1985 cursor.setIndex( 0 );
1986 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1987 cursor.setIndex( 0 );
1988 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1989 cmd=txtObj->setCounterCommand( &cursor, c ,KoTextDocument::HighlightSelection );
1998KCommand *KoAutoFormat::doUseNumberStyle(KoTextCursor * , KoTextParag *parag,
KoTextObject *txtObj,
int& index )
2000 if ( parag->counter() && parag->counter()->
numbering() == KoParagCounter::NUM_FOOTNOTE )
2002 KoTextDocument * textdoc = parag->textDocument();
2003 KoTextCursor cursor( parag->document() );
2004 KoTextString *s = parag->string();
2006 for (
int i = 0 ; i < s->length() - 1; i++ )
2008 TQChar ch = s->at( i ).c;
2013 TQChar punct=word[word.length()-1];
2014 if( punct.isPunct() )
2016 TQString number=word.mid(0,word.length()-1);
2018 uint val=number.toUInt(&ok);
2021 KMacroCommand *macroCmd =
new KMacroCommand( i18n(
"Autocorrect (use number style)"));
2022 cursor.setParag( parag );
2023 cursor.setIndex( 0 );
2024 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
2025 cursor.setParag( parag );
2026 cursor.setIndex( word.length()+1 );
2027 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
2028 KCommand *cmd=txtObj->removeSelectedTextCommand( &cursor, KoTextDocument::HighlightSelection );
2030 index -= word.length()+1;
2035 cursor.setParag( parag );
2036 cursor.setIndex( 0 );
2037 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
2039 cursor.setIndex( 2 );
2040 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
2043 c.setNumbering( KoParagCounter::NUM_LIST );
2044 c.setStyle( KoParagCounter::STYLE_NUM );
2045 c.setSuffix(TQString( punct ));
2046 c.setStartNumber( (
int)val);
2051 if ( c.number( parag ) != (
int)val )
2052 c.setRestartCounter(
true );
2054 cmd=txtObj->setCounterCommand( &cursor, c, KoTextDocument::HighlightSelection );
2059 c.setRestartCounter(
false );
2060 cursor.setParag( parag->next() );
2061 cursor.setIndex( 0 );
2062 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
2063 cursor.setIndex( 0 );
2064 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
2065 cmd=txtObj->setCounterCommand( &cursor, c, KoTextDocument::HighlightSelection );
2075KCommand * KoAutoFormat::doRemoveSpaceBeginEndLine( KoTextCursor *textEditCursor, KoTextParag *parag,
KoTextObject *txtObj,
int &index )
2077 KoTextString *s = parag->string();
2078 KoTextDocument * textdoc = parag->textDocument();
2079 KoTextCursor cursor( parag->document() );
2081 KMacroCommand *macroCmd = 0L;
2083 for (
int i = parag->lastCharPos(); i >= 0; --i )
2085 TQChar ch = s->at( i ).c;
2088 if( i == parag->lastCharPos() )
2090 cursor.setParag( parag );
2091 cursor.setIndex( i+1 );
2092 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
2093 cursor.setParag( parag );
2094 cursor.setIndex( parag->lastCharPos()+1 );
2095 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
2096 KCommand *cmd=txtObj->replaceSelectionCommand( &cursor,
"", TQString(), KoTextDocument::HighlightSelection );
2103 macroCmd =
new KMacroCommand( i18n(
"Autocorrect (remove start and end line space)"));
2112 for (
int i = 0 ; i <= parag->lastCharPos() ; i++ )
2114 TQChar ch = s->at( i ).c;
2120 cursor.setParag( parag );
2121 cursor.setIndex( 0 );
2122 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
2123 cursor.setParag( parag );
2124 cursor.setIndex( i );
2125 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
2126 KCommand *cmd=txtObj->replaceSelectionCommand( &cursor,
"", TQString(), KoTextDocument::HighlightSelection );
2132 macroCmd =
new KMacroCommand( i18n(
"Autocorrect (remove start and end line space)"));
2141 txtObj->emitHideCursor();
2142 textEditCursor->setParag( parag->next() );
2144 txtObj->emitShowCursor();
2149KCommand *KoAutoFormat::doCapitalizeNameOfDays( KoTextCursor* textEditCursor, KoTextParag *parag,
int index,
const TQString & word ,
KoTextObject *txtObj )
2153 int pos = m_cacheNameOfDays.findIndex( word.lower() );
2156 KoTextDocument * textdoc = parag->textDocument();
2157 TQString replaceStr= m_cacheNameOfDays[pos];
2158 int start = index - replaceStr.length();
2159 int length = replaceStr.length();
2160 if( word.at(0).isLetter() && word.at(0)==word.at(0).lower() )
2162 KoTextCursor cursor( parag->document() );
2163 cursor.setParag( parag );
2164 cursor.setIndex( start );
2165 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
2166 cursor.setIndex( start + length );
2167 TQString replacement = replaceStr.at(0).upper() + replaceStr.right( length-1 );
2168 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
2169 TQString cmdName=i18n(
"Capitalize Name of Days");
2170 KCommand *cmd =txtObj->replaceSelectionCommand( textEditCursor, replacement,
2172 KoTextDocument::HighlightSelection );
2173 txtObj->emitHideCursor();
2174 textEditCursor->gotoRight();
2175 txtObj->emitShowCursor();
2181KCommand *KoAutoFormat::doAutoSuperScript( KoTextCursor* textEditCursor, KoTextParag *parag,
int index,
const TQString & word ,
KoTextObject *txtObj )
2183 KoAutoFormatEntryMap::Iterator it = m_superScriptEntries.begin();
2186 for ( ; it != m_superScriptEntries.end() ; ++it )
2190 replace = it.data().replace();
2194 else if ( it.key()==
"othernb")
2196 TQString tmp = it.data().replace();
2197 int pos = word.find( tmp );
2200 if( pos + tmp.length() == word.length())
2203 word.left( pos ).toInt( &ok);
2216 KoTextDocument * textdoc = parag->textDocument();
2218 int start = index -
replace.length();
2219 KoTextFormat * lastFormat = parag->at( start )->format();
2220 KoTextFormat * newFormat =
new KoTextFormat(*lastFormat);
2221 KoTextCursor cursor( parag->document() );
2223 cursor.setParag( parag );
2224 cursor.setIndex( start );
2225 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
2226 cursor.setIndex( start + word.length() -1 );
2227 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
2228 newFormat->setVAlign(KoTextFormat::AlignSuperScript);
2229 KCommand *cmd =txtObj->
setFormatCommand( textEditCursor, 0L, newFormat, KoTextFormat::VAlign ,
false,KoTextDocument::HighlightSelection );
2230 textdoc->removeSelection( KoTextDocument::HighlightSelection );
2237bool KoAutoFormat::doIgnoreDoubleSpace( KoTextParag *parag,
int index, TQChar ch )
2239 if( m_ignoreDoubleSpace && ch==
' ' && index >= 0 && !parag->hasAnySelection() )
2241 KoTextString *s = parag->string();
2242 TQChar ch = s->at( index ).c;
2249void KoAutoFormat::configTypographicSimpleQuotes( TypographicQuotes _tq )
2251 m_typographicSimpleQuotes = _tq;
2254void KoAutoFormat::configTypographicDoubleQuotes( TypographicQuotes _tq )
2256 m_typographicDoubleQuotes = _tq;
2259void KoAutoFormat::configUpperCase(
bool _uc )
2261 m_convertUpperCase = _uc;
2264void KoAutoFormat::configUpperUpper(
bool _uu )
2266 m_convertUpperUpper = _uu;
2269void KoAutoFormat::configAdvancedAutocorrect(
bool _aa )
2271 m_advancedAutoCorrect = _aa;
2274void KoAutoFormat::configAutoDetectUrl(
bool _au)
2276 m_autoDetectUrl=_au;
2279void KoAutoFormat::configIgnoreDoubleSpace(
bool _ids)
2281 m_ignoreDoubleSpace=_ids;
2284void KoAutoFormat::configRemoveSpaceBeginEndLine(
bool _space)
2286 m_removeSpaceBeginEndLine=_space;
2289void KoAutoFormat::configUseBulletStyle(
bool _ubs)
2291 m_useBulletStyle=_ubs;
2294void KoAutoFormat::configBulletStyle( TQChar b )
2299void KoAutoFormat::configAutoChangeFormat(
bool b)
2301 m_autoChangeFormat = b;
2305void KoAutoFormat::configAutoReplaceNumber(
bool b )
2307 m_autoReplaceNumber = b;
2310void KoAutoFormat::configAutoNumberStyle(
bool b )
2312 m_useAutoNumberStyle = b;
2315void KoAutoFormat::configCompletion(
bool b )
2320void KoAutoFormat::configToolTipCompletion(
bool b )
2322 m_toolTipCompletion = b;
2323 if (!b && m_completionBox)
2325 delete m_completionBox;
2326 m_completionBox = 0;
2330void KoAutoFormat::configKeyCompletionAction( KeyCompletionAction action )
2332 m_keyCompletionAction =
action;
2335void KoAutoFormat::configAppendSpace(
bool b)
2337 m_completionAppendSpace= b;
2340void KoAutoFormat::configMinWordLength( uint val )
2342 m_minCompletionWordLength = val;
2345void KoAutoFormat::configNbMaxCompletionWord( uint val )
2347 m_nbMaxCompletionWord = val;
2351void KoAutoFormat::configAddCompletionWord(
bool b )
2353 m_addCompletionWord= b;
2356bool KoAutoFormat::isUpper(
const TQChar &c )
2358 return c.lower() != c;
2361bool KoAutoFormat::isLower(
const TQChar &c )
2365 return c.upper() != c;
2368bool KoAutoFormat::isMark(
const TQChar &c )
2370 return ( c == TQChar(
'.' ) ||
2371 c == TQChar(
'?' ) ||
2372 c == TQChar(
'!' ) );
2375bool KoAutoFormat::isSeparator(
const TQChar &c )
2377 return ( !c.isLetter() && !c.isNumber() && !c.isDigit() );
2380void KoAutoFormat::buildMaxLen()
2382 m_maxFindLength = 0;
2383 TQDictIterator<KoAutoFormatEntry> it( m_entries );
2384 for( ; it.current(); ++it )
2386 m_maxFindLength = TQMAX( m_maxFindLength, it.currentKey().length() );
2388 TQDictIterator<KoAutoFormatEntry> it2( m_allLanguages );
2389 for( ; it2.current(); ++it2 )
2391 m_maxFindLength = TQMAX( m_maxFindLength, it2.currentKey().length() );
2395TQStringList KoAutoFormat::listCompletion()
const
2397 return m_listCompletion->items();
2401void KoAutoFormat::configIncludeTwoUpperUpperLetterException(
bool b)
2403 m_includeTwoUpperLetterException = b;
2406void KoAutoFormat::configIncludeAbbreviation(
bool b )
2408 m_includeAbbreviation = b;
2411void KoAutoFormat::configAutoSuperScript(
bool b )
2413 m_bAutoSuperScript = b;
2416void KoAutoFormat::configCorrectionWithFormat(
bool b)
2418 m_bAutoCorrectionWithFormat = b;
2421void KoAutoFormat::configCapitalizeNameOfDays(
bool b)
2423 m_bCapitalizeNameOfDays = b;
2426void KoAutoFormat::configAutoFormatLanguage(
const TQString &_lang)
2428 m_autoFormatLanguage=_lang;
2433 KoTextParag * parag = obj->
textDocument()->firstParag();
2434 KoTextCursor *cursor =
new KoTextCursor( obj->
textDocument() );
2435 KMacroCommand *macro = 0L;
2438 cursor->setIndex(0);
2439 for (
int i=0;i<parag->length();i++)
2441 cursor->gotoRight();
2443 if (i == parag->length()-1)
2444 doAutoFormat(cursor,parag,i,
'\n',obj);
2446 doAutoFormat(cursor,parag,i, parag->string()->at(i).c,obj);
2448 parag = parag->next();
2455void KoAutoFormat::changeTextFormat(KoSearchContext *formatOptions,
KoTextFormat * format,
int & flags )
2459 if (formatOptions->m_optionsMask & KoSearchContext::Bold)
2461 format->setBold( formatOptions->m_options & KoSearchContext::Bold);
2462 flags |=KoTextFormat::Bold;
2464 if ( formatOptions->m_optionsMask & KoSearchContext::Size)
2466 format->setPointSize( formatOptions->m_size );
2467 flags |=KoTextFormat::Size;
2469 if ( formatOptions->m_optionsMask & KoSearchContext::Family)
2471 format->setFamily( formatOptions->m_family );
2472 flags |=KoTextFormat::Family;
2474 if ( formatOptions->m_optionsMask & KoSearchContext::Color)
2476 format->setColor(formatOptions->m_color);
2477 flags |=KoTextFormat::Color;
2479 if ( formatOptions->m_optionsMask & KoSearchContext::BgColor)
2481 format->setTextBackgroundColor(formatOptions->m_backGroundColor);
2482 flags |=KoTextFormat::TextBackgroundColor;
2485 if ( formatOptions->m_optionsMask & KoSearchContext::Italic)
2487 format->setItalic( formatOptions->m_options & KoSearchContext::Italic);
2488 flags |=KoTextFormat::Italic;
2490 if ( formatOptions->m_optionsMask & KoSearchContext::WordByWord)
2492 format->setWordByWord( formatOptions->m_options & KoSearchContext::WordByWord );
2493 flags |=KoTextFormat::WordByWord;
2495 if ( formatOptions->m_optionsMask & KoSearchContext::Shadow)
2497 if ( formatOptions->m_options & KoSearchContext::Shadow )
2498 format->setShadow( 1, 1, TQt::gray );
2500 format->setShadow( 0, 0, TQColor() );
2501 flags |=KoTextFormat::ShadowText;
2504 if ( formatOptions->m_optionsMask & KoSearchContext::Underline)
2506 format->setUnderlineType(formatOptions->m_underline);
2507 flags |=KoTextFormat::ExtendUnderLine;
2509 if ( formatOptions->m_optionsMask & KoSearchContext::StrikeOut)
2511 format->setStrikeOutType(formatOptions->m_strikeOut);
2512 flags |= KoTextFormat::StrikeOut;
2514 if ( formatOptions->m_optionsMask & KoSearchContext::VertAlign)
2516 format->setVAlign(formatOptions->m_vertAlign);
2517 flags |=KoTextFormat::VAlign;
2519 if ( formatOptions->m_optionsMask & KoSearchContext::Attribute)
2521 format->setAttributeFont(formatOptions->m_attribute);
2522 flags |= KoTextFormat::Attribute;
2524 if (formatOptions->m_optionsMask & KoSearchContext::Language)
2526 flags |= KoTextFormat::Language;
2527 format->setLanguage( formatOptions->m_language );
2532#include "KoAutoFormat.moc"
void addCommand(KCommand *command)
The KOffice document class.
Numbering numbering() const
Numbering type and style.
virtual void recalc()
Reimplemented by KoVariable to recalculate the value.
Each character (KoTextStringChar) points to a KoTextFormat that defines the formatting of that charac...
The KoTextObject is the high-level object that contains a KoTextDocument (the list of paragraphs),...
void insert(KoTextCursor *cursor, KoTextFormat *currentFormat, const TQString &text, const TQString &commandName, KoTextDocument::SelectionId selectionId=KoTextDocument::Standard, int insertFlags=DefaultInsertFlags, CustomItemsMap customItemsMap=CustomItemsMap())
The main "insert" method, including undo/redo creation/update.
KoTextDocument * textDocument() const
Return the text document contained in this KoTextObject.
KCommand * setFormatCommand(const KoTextFormat *format, int flags, bool zoomFont=false)
Implementation of setFormatCommand from KoTextFormatInterface - apply change to the whole document.
TDEAction * action(StdAction act_enum, const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0L)
TDEAction * replace(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
const char * name(StdAction id)