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>
31#include <tdeversion.h>
34#include <tdeinstance.h>
36#include <kstandarddirs.h>
40#include <kcompletion.h>
41#include <kcalendarsystem.h>
46#include <tqwhatsthis.h>
51KoCompletionBox::KoCompletionBox( TQWidget * parent,
const char * name, WFlags f)
52 : TQLabel(parent,
name,f)
54 setBackgroundColor(TQColor(
"#FFFFE6"));
55 setFocusPolicy(TQWidget::NoFocus);
56 setFrameShape(TQFrame::Box);
59KoCompletionBox::~KoCompletionBox()
63void KoCompletionBox::mousePressEvent( TQMouseEvent *)
68TQString& KoCompletionBox::lastWord()
73void KoCompletionBox::setLastWord( TQString
const &lastword)
75 m_lastWord = lastword;
78KoAutoFormatEntry::KoAutoFormatEntry(
const TQString& replace)
84KoAutoFormatEntry::~KoAutoFormatEntry()
86 delete m_formatOptions;
90KoSearchContext *KoAutoFormatEntry::formatEntryContext()
const
92 return m_formatOptions;
95void KoAutoFormatEntry::createNewEntryContext()
97 if ( !m_formatOptions )
99 m_formatOptions =
new KoSearchContext();
103void KoAutoFormatEntry::setFormatEntryContext( KoSearchContext *_cont )
105 delete m_formatOptions;
106 m_formatOptions=_cont;
109void KoAutoFormatEntry::clearFormatEntryContext( )
111 delete m_formatOptions;
112 m_formatOptions = 0L;
121 m_varCollection(_varCollection),
122 m_varFormatCollection(_varFormatCollection),
123 m_autoFormatLanguage( TQString()),
124 m_configRead( false ),
125 m_convertUpperCase( false ), m_convertUpperUpper( false ),
126 m_advancedAutoCorrect( true ),
127 m_autoDetectUrl( false ),
128 m_ignoreDoubleSpace( false ),
129 m_removeSpaceBeginEndLine( false ),
130 m_useBulletStyle(false),
131 m_autoChangeFormat(false),
132 m_autoReplaceNumber(false),
133 m_useAutoNumberStyle(false),
135 m_toolTipCompletion(false),
136 m_completionAppendSpace(false),
137 m_addCompletionWord(true),
138 m_includeTwoUpperLetterException(false),
139 m_includeAbbreviation(false),
140 m_ignoreUpperCase(false),
141 m_bAutoFormatActive(true),
142 m_bAutoSuperScript( false ),
143 m_bAutoCorrectionWithFormat( false ),
144 m_bCapitalizeNameOfDays( false ),
145 m_wordInserted( false ),
147 m_typographicSimpleQuotes(),
148 m_typographicDoubleQuotes(),
149 m_typographicDefaultDoubleQuotes(),
150 m_typographicDefaultSimpleQuotes(),
151 m_listCompletion( new TDECompletion ),
153 m_allLanguages(17,false),
154 m_superScriptEntries(),
155 m_upperCaseExceptions(),
156 m_twoUpperLetterException(),
157 m_maxFindLength( 0 ),
158 m_minCompletionWordLength( 5 ),
159 m_nbMaxCompletionWord( 500 ),
162 m_keyCompletionAction( Enter )
166 loadListOfWordCompletion();
167 m_listCompletion->setIgnoreCase(
true );
169 TDELocale tdelocale(m_doc->instance()->instanceName());
170 for (
int i = 1; i <=7; i++)
172 m_cacheNameOfDays.append(tdelocale.calendar()->weekDayName( i ).lower());
176KoAutoFormat::KoAutoFormat(
const KoAutoFormat& format )
177 : m_doc( format.m_doc ),
178 m_varCollection( format.m_varCollection ),
179 m_varFormatCollection( format.m_varFormatCollection ),
180 m_autoFormatLanguage( format.m_autoFormatLanguage),
181 m_configRead( format.m_configRead ),
182 m_convertUpperCase( format.m_convertUpperCase ),
183 m_convertUpperUpper( format.m_convertUpperUpper ),
184 m_advancedAutoCorrect( format.m_advancedAutoCorrect ),
185 m_autoDetectUrl( format.m_autoDetectUrl ),
186 m_ignoreDoubleSpace( format.m_ignoreDoubleSpace ),
187 m_removeSpaceBeginEndLine( format.m_removeSpaceBeginEndLine ),
188 m_useBulletStyle( format.m_useBulletStyle ),
189 m_autoChangeFormat( format.m_autoChangeFormat ),
190 m_autoReplaceNumber( format.m_autoReplaceNumber ),
191 m_useAutoNumberStyle( format.m_useAutoNumberStyle ),
192 m_completion( format.m_completion ),
193 m_toolTipCompletion( format.m_toolTipCompletion),
194 m_completionAppendSpace( format.m_completionAppendSpace ),
195 m_addCompletionWord( format.m_addCompletionWord ),
196 m_includeTwoUpperLetterException( format.m_includeTwoUpperLetterException ),
197 m_includeAbbreviation( format.m_includeAbbreviation ),
198 m_ignoreUpperCase( format.m_ignoreUpperCase ),
199 m_bAutoFormatActive( format.m_bAutoFormatActive ),
200 m_bAutoSuperScript( format.m_bAutoSuperScript ),
201 m_bAutoCorrectionWithFormat( format.m_bAutoCorrectionWithFormat),
202 m_bCapitalizeNameOfDays( format.m_bCapitalizeNameOfDays),
203 m_bulletStyle( format.m_bulletStyle ),
204 m_typographicSimpleQuotes( format.m_typographicSimpleQuotes ),
205 m_typographicDoubleQuotes( format.m_typographicDoubleQuotes ),
206 m_typographicDefaultDoubleQuotes( format.m_typographicDefaultDoubleQuotes),
207 m_typographicDefaultSimpleQuotes( format.m_typographicDefaultSimpleQuotes),
208 m_listCompletion( 0L ),
209 m_entries(17,false ),
210 m_allLanguages(17,false),
211 m_superScriptEntries ( format.m_superScriptEntries ),
212 m_upperCaseExceptions( format.m_upperCaseExceptions ),
213 m_twoUpperLetterException( format.m_twoUpperLetterException ),
214 m_maxFindLength( format.m_maxFindLength ),
215 m_minCompletionWordLength( format.m_minCompletionWordLength ),
216 m_nbMaxCompletionWord( format.m_nbMaxCompletionWord ),
217 m_cacheNameOfDays( format.m_cacheNameOfDays),
219 m_keyCompletionAction( format.m_keyCompletionAction )
226KoAutoFormat::~KoAutoFormat()
228 delete m_listCompletion;
229 m_entries.setAutoDelete(
true );
231 m_allLanguages.setAutoDelete(
true );
232 m_allLanguages.clear();
235void KoAutoFormat::updateMaxWords()
237 TQStringList list = m_listCompletion->items();
238 for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it )
243 for (uint i=0; i < (uint)tmp.length(); i++)
244 if ( tmp.at(i).isSpace() || tmp.at(i).isPunct() )
246 if (maxword > m_countMaxWords )
247 m_countMaxWords = maxword;
249 kdDebug() <<
"m_countMaxWords: " << m_countMaxWords << endl;
252void KoAutoFormat::loadListOfWordCompletion()
254 TDEConfig* config = KoGlobal::kofficeConfig();
255 TDEConfigGroupSaver cgs( config,
"Completion Word" );
256 m_listCompletion->insertItems(config->readListEntry(
"list" ));
259void KoAutoFormat::readConfig(
bool force)
264 if ( m_configRead && !force )
266 TDEConfig* config = KoGlobal::kofficeConfig();
267 TDEConfigGroupSaver cgs( config,
"AutoFormat" );
270 m_autoFormatLanguage = config->readEntry(
"formatLanguage", TQString());
272 m_convertUpperCase = config->readBoolEntry(
"ConvertUpperCase",
false );
273 m_convertUpperUpper = config->readBoolEntry(
"ConvertUpperUpper",
false );
274 m_includeTwoUpperLetterException = config->readBoolEntry(
"includeTwoLetterException",
false );
275 m_includeAbbreviation = config->readBoolEntry(
"includeAbbreviation",
false );
277 m_advancedAutoCorrect = config->readBoolEntry(
"AdvancedAutocorrect",
true );
278 m_bAutoCorrectionWithFormat = config->readBoolEntry(
"AutoCorrectionWithFormat",
false );
279 m_bCapitalizeNameOfDays = config->readBoolEntry(
"CapitalizeNameOfDays",
false );
281 m_autoDetectUrl = config->readBoolEntry(
"AutoDetectUrl",
false);
282 m_ignoreDoubleSpace = config->readBoolEntry(
"IgnoreDoubleSpace",
true);
283 m_removeSpaceBeginEndLine = config->readBoolEntry(
"RemoveSpaceBeginEndLine",
true);
285 m_useBulletStyle = config->readBoolEntry(
"UseBulletStyle",
false);
286 TQString tmp = config->readEntry(
"BulletStyle",
"" );
287 m_bulletStyle = tmp.isEmpty() ? TQChar() : tmp[0];
289 m_autoChangeFormat = config->readBoolEntry(
"AutoChangeFormat",
false );
291 m_autoReplaceNumber = config->readBoolEntry(
"AutoReplaceNumber",
true );
293 m_useAutoNumberStyle = config->readBoolEntry(
"AutoNumberStyle",
false );
296 TQString beginDoubleQuote = config->readEntry(
"TypographicQuotesBegin" );
297 TQString endDoubleQuote = config->readEntry(
"TypographicQuotesEnd" );
299 m_typographicDoubleQuotes.replace = config->readBoolEntry(
"TypographicQuotesEnabled",
false );
301 TQString begin = config->readEntry(
"TypographicSimpleQuotesBegin" );
302 TQString end = config->readEntry(
"TypographicSimpleQuotesEnd" );
303 m_typographicSimpleQuotes.replace = config->readBoolEntry(
"TypographicSimpleQuotesEnabled",
false );
305 m_bAutoSuperScript = config->readBoolEntry(
"AutoSuperScript",
true );
307 config->setGroup(
"completion" );
308 m_completion = config->readBoolEntry(
"completion",
false );
310 m_completionAppendSpace = config->readBoolEntry(
"CompletionAppendSpace",
false );
311 m_minCompletionWordLength = config->readUnsignedNumEntry(
"CompletionMinWordLength", 5 );
312 m_nbMaxCompletionWord = config->readUnsignedNumEntry(
"NbMaxCompletionWord", 100 );
313 m_addCompletionWord = config->readBoolEntry(
"AddCompletionWord",
true );
314 m_toolTipCompletion = config->readBoolEntry(
"ToolTipCompletion",
true );
315 m_keyCompletionAction = ( KoAutoFormat::KeyCompletionAction )config->readUnsignedNumEntry(
"CompletionKeyAction", 0 );
319 m_entries.setAutoDelete(
true);
321 m_entries.setAutoDelete(
false);
322 m_allLanguages.setAutoDelete(
true);
323 m_allLanguages.clear();
324 m_allLanguages.setAutoDelete(
false);
325 m_upperCaseExceptions.clear();
326 m_superScriptEntries.clear();
327 m_twoUpperLetterException.clear();
333 readAutoCorrectConfig();
335 if( beginDoubleQuote.isEmpty())
337 if( m_typographicDefaultDoubleQuotes.begin.isNull())
338 m_typographicDoubleQuotes.begin = TQChar(
'«');
340 m_typographicDoubleQuotes.begin = m_typographicDefaultDoubleQuotes.begin;
343 m_typographicDoubleQuotes.begin = beginDoubleQuote[0];
345 if( endDoubleQuote.isEmpty() )
347 if( m_typographicDefaultDoubleQuotes.end.isNull())
348 m_typographicDoubleQuotes.end = TQChar(
'»');
350 m_typographicDoubleQuotes.end = m_typographicDefaultDoubleQuotes.end;
353 m_typographicDoubleQuotes.end = endDoubleQuote[0];
355 m_typographicDoubleQuotes.replace = m_typographicDoubleQuotes.replace
356 && !m_typographicDoubleQuotes.begin.isNull()
357 && !m_typographicDoubleQuotes.end.isNull();
362 if( m_typographicDefaultSimpleQuotes.begin.isNull())
363 m_typographicSimpleQuotes.begin = TQChar(
'\'');
365 m_typographicSimpleQuotes.begin = m_typographicDefaultSimpleQuotes.begin;
368 m_typographicSimpleQuotes.begin = begin[0];
372 if( m_typographicDefaultSimpleQuotes.end.isNull())
373 m_typographicSimpleQuotes.end = TQChar(
'\'');
375 m_typographicSimpleQuotes.end = m_typographicDefaultSimpleQuotes.end;
378 m_typographicSimpleQuotes.end = end[0];
380 m_typographicSimpleQuotes.replace = m_typographicSimpleQuotes.replace
381 && !m_typographicSimpleQuotes.end.isNull()
382 && !m_typographicSimpleQuotes.begin.isNull();
385 loadAllLanguagesAutoCorrection();
387 autoFormatIsActive();
391void KoAutoFormat::readAutoCorrectConfig()
393 Q_ASSERT( m_entries.isEmpty() );
394 TDELocale tdelocale(m_doc->instance()->instanceName());
395 TQString kdelang = tdelocale.languageList().front();
396 kdelang.remove( TQRegExp(
"@.*" ) );
397 kdDebug(32500) <<
"KoAutoFormat: m_autoFormatLanguage=" << m_autoFormatLanguage <<
" kdelang=" << kdelang << endl;
399 if ( !m_autoFormatLanguage.isEmpty() )
401 fname = locate(
"data",
"koffice/autocorrect/" + m_autoFormatLanguage +
".xml", m_doc->instance() );
403 if ( m_autoFormatLanguage !=
"all_languages" )
405 if ( fname.isEmpty() && !kdelang.isEmpty() )
406 fname = locate(
"data",
"koffice/autocorrect/" + kdelang +
".xml", m_doc->instance() );
407 if ( fname.isEmpty() && kdelang.contains(
"_") )
409 kdelang.remove( TQRegExp(
"_.*" ) );
410 fname = locate(
"data",
"koffice/autocorrect/" + kdelang +
".xml", m_doc->instance() );
412 if ( fname.isEmpty() )
413 fname = locate(
"data",
"koffice/autocorrect/autocorrect.xml", m_doc->instance() );
415 if ( fname.isEmpty() )
417 TQFile xmlFile(fname);
418 if(!xmlFile.open(IO_ReadOnly))
422 if(!doc.setContent(&xmlFile))
425 if(doc.doctype().name() !=
"autocorrection") {
428 TQDomElement de=doc.documentElement();
430 loadAutoCorrection( de );
432 TQDomElement upper = de.namedItem(
"UpperCaseExceptions" ).toElement();
435 TQDomNodeList nl = upper.childNodes();
436 for(uint i = 0; i < nl.count(); i++)
438 m_upperCaseExceptions+= nl.item(i).toElement().attribute(
"exception");
442 TQDomElement twoUpper = de.namedItem(
"TwoUpperLetterExceptions" ).toElement();
443 if(!twoUpper.isNull())
445 TQDomNodeList nl = twoUpper.childNodes();
446 for(uint i = 0; i < nl.count(); i++)
448 m_twoUpperLetterException+= nl.item(i).toElement().attribute(
"exception");
452 TQDomElement superScript = de.namedItem(
"SuperScript" ).toElement();
453 if(!superScript.isNull())
455 TQDomNodeList nl = superScript.childNodes();
456 for(uint i = 0; i < nl.count() ; i++) {
459 m_superScriptEntries.insert( nl.item(i).toElement().attribute(
"find"), KoAutoFormatEntry(nl.item(i).toElement().attribute(
"super")),
false );
463 TQDomElement doubleQuote = de.namedItem(
"DoubleQuote" ).toElement();
464 if(!doubleQuote.isNull())
466 TQDomElement childItem = doubleQuote.namedItem(
"doublequote").toElement();
467 if ( !childItem.isNull() )
469 TQString attr = childItem.attribute(
"begin" );
470 if ( !attr.isEmpty() && attr[0] != 0 )
471 m_typographicDefaultDoubleQuotes.begin = attr[0];
472 attr = childItem.attribute(
"end" );
473 if ( !attr.isEmpty() && attr[0] != 0 )
474 m_typographicDefaultDoubleQuotes.end = attr[0];
477 TQDomElement simpleQuote = de.namedItem(
"SimpleQuote" ).toElement();
478 if(!simpleQuote.isNull())
480 TQDomElement childItem = simpleQuote.namedItem(
"simplequote").toElement();
481 if ( !childItem.isNull() )
483 TQString attr = childItem.attribute(
"begin" );
484 if ( !attr.isEmpty() && attr[0] != 0 )
485 m_typographicDefaultSimpleQuotes.begin = attr[0];
486 attr = childItem.attribute(
"end" );
487 if ( !attr.isEmpty() && attr[0] != 0 )
488 m_typographicDefaultSimpleQuotes.end = attr[0];
493void KoAutoFormat::loadAllLanguagesAutoCorrection()
495 TQString fname = locate(
"data",
"koffice/autocorrect/all_languages.xml", m_doc->instance() );
496 if ( fname.isEmpty() )
498 TQFile xmlFile( fname );
499 if(xmlFile.open(IO_ReadOnly))
502 if(!doc.setContent(&xmlFile)) {
505 if(doc.doctype().name() !=
"autocorrection") {
508 TQDomElement de=doc.documentElement();
510 loadAutoCorrection( de,
true );
515void KoAutoFormat::loadAutoCorrection(
const TQDomElement & _de,
bool _allLanguages )
517 TQDomElement item = _de.namedItem(
"items" ).toElement();
520 TQDomNodeList nl = item.childNodes();
521 m_maxFindLength=nl.count();
522 for(uint i = 0; i < m_maxFindLength; i++) {
523 loadEntry( nl.item(i).toElement(), _allLanguages);
528void KoAutoFormat::loadEntry(
const TQDomElement &nl,
bool _allLanguages)
530 KoAutoFormatEntry *tmp =
new KoAutoFormatEntry(nl.attribute(
"replace"));
531 if ( nl.hasAttribute(
"FONT"))
533 tmp->createNewEntryContext();
534 tmp->formatEntryContext()->m_family=nl.attribute(
"FONT");
535 tmp->formatEntryContext()->m_optionsMask |= KoSearchContext::Family;
537 if ( nl.hasAttribute(
"SIZE" ))
539 tmp->createNewEntryContext();
540 tmp->formatEntryContext()->m_size = nl.attribute(
"SIZE" ).toInt();
541 tmp->formatEntryContext()->m_optionsMask |= KoSearchContext::Size;
543 if (nl.hasAttribute(
"BOLD" ))
545 tmp->createNewEntryContext();
546 tmp->formatEntryContext()->m_optionsMask |= KoSearchContext::Bold;
547 TQString value = nl.attribute(
"BOLD");
548 if ( value.toInt() == 1 )
549 tmp->formatEntryContext()->m_options |= KoSearchContext::Bold;
551 if (nl.hasAttribute(
"ITALIC" ))
553 tmp->createNewEntryContext();
554 tmp->formatEntryContext()->m_optionsMask |= KoSearchContext::Italic;
555 TQString value = nl.attribute(
"ITALIC");
556 if ( value.toInt() == 1 )
557 tmp->formatEntryContext()->m_options |= KoSearchContext::Italic;
559 if (nl.hasAttribute(
"UNDERLINE" ))
561 tmp->createNewEntryContext();
562 tmp->formatEntryContext()->m_optionsMask |= KoSearchContext::Underline;
563 TQString value = nl.attribute(
"UNDERLINE");
564 if ( value ==
"single" )
565 tmp->formatEntryContext()->m_underline = KoTextFormat::U_SIMPLE;
566 else if ( value ==
"double" )
567 tmp->formatEntryContext()->m_underline = KoTextFormat::U_DOUBLE;
568 else if ( value ==
"single-bold" )
569 tmp->formatEntryContext()->m_underline = KoTextFormat::U_SIMPLE_BOLD;
571 tmp->formatEntryContext()->m_underline = KoTextFormat::U_NONE;
573 if (nl.hasAttribute(
"STRIKEOUT" ))
575 tmp->createNewEntryContext();
576 tmp->formatEntryContext()->m_optionsMask |= KoSearchContext::StrikeOut;
577 TQString value = nl.attribute(
"STRIKEOUT");
578 if ( value ==
"single" )
579 tmp->formatEntryContext()->m_strikeOut = KoTextFormat::S_SIMPLE;
580 else if ( value ==
"double" )
581 tmp->formatEntryContext()->m_strikeOut = KoTextFormat::S_DOUBLE;
582 else if ( value ==
"single-bold" )
583 tmp->formatEntryContext()->m_strikeOut = KoTextFormat::S_SIMPLE_BOLD;
585 tmp->formatEntryContext()->m_strikeOut = KoTextFormat::S_NONE;
587 if (nl.hasAttribute(
"VERTALIGN" ))
589 tmp->createNewEntryContext();
590 tmp->formatEntryContext()->m_optionsMask |= KoSearchContext::VertAlign;
591 TQString value = nl.attribute(
"VERTALIGN");
592 tmp->formatEntryContext()->m_vertAlign=
static_cast<KoTextFormat::VerticalAlignment
>( value.toInt() );
595 if ( nl.hasAttribute(
"TEXTCOLOR" ))
597 tmp->createNewEntryContext();
598 tmp->formatEntryContext()->m_optionsMask |= KoSearchContext::Color;
599 TQColor col( nl.attribute(
"TEXTCOLOR" ));
600 tmp->formatEntryContext()->m_color = col;
602 if ( nl.hasAttribute(
"TEXTBGCOLOR" ))
604 tmp->createNewEntryContext();
605 tmp->formatEntryContext()->m_optionsMask |= KoSearchContext::BgColor;
606 TQColor col( nl.attribute(
"TEXTBGCOLOR" ));
607 tmp->formatEntryContext()->m_backGroundColor = col;
609 if ( !_allLanguages )
610 m_entries.insert( nl.attribute(
"find"), tmp );
612 m_allLanguages.insert( nl.attribute(
"find"), tmp );
616void KoAutoFormat::saveConfig()
618 TDEConfig* config = KoGlobal::kofficeConfig();
619 TDELocale tdelocale(m_doc->instance()->instanceName());
621 TDEConfigGroupSaver cgs( config,
"AutoFormat" );
622 config->writeEntry(
"ConvertUpperCase", m_convertUpperCase );
623 config->writeEntry(
"formatLanguage", m_autoFormatLanguage==
"all_languages" ? tdelocale.languageList().front() : m_autoFormatLanguage);
625 config->writeEntry(
"ConvertUpperUpper", m_convertUpperUpper );
626 config->writeEntry(
"includeTwoLetterException", m_includeTwoUpperLetterException );
627 config->writeEntry(
"includeAbbreviation", m_includeAbbreviation );
629 config->writeEntry(
"TypographicQuotesBegin", TQString( m_typographicDoubleQuotes.begin ) );
630 config->writeEntry(
"TypographicQuotesEnd", TQString( m_typographicDoubleQuotes.end ) );
631 config->writeEntry(
"TypographicQuotesEnabled", m_typographicDoubleQuotes.replace );
632 config->writeEntry(
"TypographicSimpleQuotesBegin", TQString( m_typographicSimpleQuotes.begin ) );
633 config->writeEntry(
"TypographicSimpleQuotesEnd", TQString( m_typographicSimpleQuotes.end ) );
634 config->writeEntry(
"TypographicSimpleQuotesEnabled", m_typographicSimpleQuotes.replace );
636 config->writeEntry(
"AdvancedAutocorrect", m_advancedAutoCorrect );
637 config->writeEntry(
"AutoCorrectionWithFormat", m_bAutoCorrectionWithFormat );
638 config->writeEntry(
"CapitalizeNameOfDays", m_bCapitalizeNameOfDays );
640 config->writeEntry(
"AutoDetectUrl",m_autoDetectUrl);
642 config->writeEntry(
"IgnoreDoubleSpace",m_ignoreDoubleSpace );
643 config->writeEntry(
"RemoveSpaceBeginEndLine",m_removeSpaceBeginEndLine );
645 config->writeEntry(
"UseBulletStyle", m_useBulletStyle);
646 config->writeEntry(
"BulletStyle", TQString(m_bulletStyle));
648 config->writeEntry(
"AutoChangeFormat", m_autoChangeFormat);
650 config->writeEntry(
"AutoReplaceNumber", m_autoReplaceNumber);
652 config->writeEntry(
"AutoNumberStyle", m_useAutoNumberStyle );
654 config->writeEntry(
"AutoSuperScript", m_bAutoSuperScript );
656 config->setGroup(
"completion" );
657 config->writeEntry(
"completion", m_completion );
658 config->writeEntry(
"CompletionAppendSpace", m_completionAppendSpace );
659 config->writeEntry(
"CompletionMinWordLength", m_minCompletionWordLength);
660 config->writeEntry(
"NbMaxCompletionWord", m_nbMaxCompletionWord);
661 config->writeEntry(
"AddCompletionWord", m_addCompletionWord );
662 config->writeEntry(
"ToolTipCompletion", m_toolTipCompletion );
663 config->writeEntry(
"CompletionKeyAction", (
int )m_keyCompletionAction );
665 config->setGroup(
"AutoFormatEntries" );
666 TQDictIterator<KoAutoFormatEntry> it( m_entries );
670 TQDomDocument doc(
"autocorrection");
672 TQDomElement begin = doc.createElement(
"Word" );
673 doc.appendChild( begin );
675 items = doc.createElement(
"items");
677 for ( ; it.current() ; ++it )
679 items.appendChild(saveEntry( it, doc));
683 begin.appendChild(items);
686 upper = doc.createElement(
"UpperCaseExceptions");
687 for ( TQStringList::Iterator it = m_upperCaseExceptions.begin(); it != m_upperCaseExceptions.end();++it )
689 data = doc.createElement(
"word");
690 data.setAttribute(
"exception",(*it) );
691 upper.appendChild(data);
693 begin.appendChild(upper);
695 TQDomElement twoUpper;
696 twoUpper = doc.createElement(
"TwoUpperLetterExceptions");
698 for ( TQStringList::Iterator it = m_twoUpperLetterException.begin(); it != m_twoUpperLetterException.end();++it )
700 data = doc.createElement(
"word");
701 data.setAttribute(
"exception",(*it) );
702 twoUpper.appendChild(data);
704 begin.appendChild(twoUpper);
707 super = doc.createElement(
"SuperScript");
708 KoAutoFormatEntryMap::Iterator it2 = m_superScriptEntries.begin();
709 for ( ; it2 != m_superScriptEntries.end() ; ++it2 )
711 data = doc.createElement(
"superscript");
712 data.setAttribute(
"find", it2.key());
713 data.setAttribute(
"super", it2.data().replace());
714 super.appendChild(data);
716 begin.appendChild(super);
718 TQDomElement doubleQuote;
719 doubleQuote = doc.createElement(
"DoubleQuote");
720 data = doc.createElement(
"doublequote");
721 data.setAttribute(
"begin", TQString(m_typographicDefaultDoubleQuotes.begin));
722 data.setAttribute(
"end", TQString(m_typographicDefaultDoubleQuotes.end));
723 doubleQuote.appendChild(data);
724 begin.appendChild(doubleQuote);
727 TQDomElement simpleQuote;
728 simpleQuote = doc.createElement(
"SimpleQuote");
729 data = doc.createElement(
"simplequote");
730 data.setAttribute(
"begin", TQString(m_typographicDefaultSimpleQuotes.begin));
731 data.setAttribute(
"end", TQString(m_typographicDefaultSimpleQuotes.end));
732 simpleQuote.appendChild(data);
733 begin.appendChild(simpleQuote);
735 if ( m_autoFormatLanguage.isEmpty())
736 f.setName(locateLocal(
"data",
"koffice/autocorrect/"+tdelocale.languageList().front() +
".xml",m_doc->instance()));
738 f.setName(locateLocal(
"data",
"koffice/autocorrect/"+m_autoFormatLanguage +
".xml",m_doc->instance()));
739 if(!f.open(IO_WriteOnly)) {
740 kdWarning()<<
"Error during saving autoformat to " << f.name() << endl;
746 autoFormatIsActive();
750TQDomElement KoAutoFormat::saveEntry( TQDictIterator<KoAutoFormatEntry> _entry, TQDomDocument doc)
753 data = doc.createElement(
"item");
754 data.setAttribute(
"find", _entry.currentKey());
755 data.setAttribute(
"replace", _entry.current()->replace());
756 if ( _entry.current()->formatEntryContext() )
758 KoSearchContext *tmp = _entry.current()->formatEntryContext();
759 if ( tmp->m_optionsMask & KoSearchContext::Family )
761 data.setAttribute(
"FONT", tmp->m_family);
763 if ( tmp->m_optionsMask & KoSearchContext::Size )
765 data.setAttribute(
"SIZE", tmp->m_size);
767 if ( tmp->m_optionsMask & KoSearchContext::Italic )
769 data.setAttribute(
"ITALIC",
static_cast<bool>(tmp->m_options & KoSearchContext::Italic));
771 if ( tmp->m_optionsMask & KoSearchContext::Bold )
773 data.setAttribute(
"BOLD",
static_cast<bool>(tmp->m_options & KoSearchContext::Bold));
775 if ( tmp->m_optionsMask & KoSearchContext::Shadow )
777 data.setAttribute(
"SHADOWTEXT",
static_cast<bool>(tmp->m_options & KoSearchContext::Shadow));
779 if ( tmp->m_optionsMask & KoSearchContext::WordByWord )
781 data.setAttribute(
"WORDBYWORD",
static_cast<bool>(tmp->m_options & KoSearchContext::WordByWord));
784 if ( tmp->m_optionsMask & KoSearchContext::Underline )
786 switch( tmp->m_underline )
788 case KoTextFormat::U_SIMPLE:
789 data.setAttribute(
"UNDERLINE",
"single");
791 case KoTextFormat::U_DOUBLE:
792 data.setAttribute(
"UNDERLINE",
"double");
794 case KoTextFormat::U_SIMPLE_BOLD:
795 data.setAttribute(
"UNDERLINE",
"single-bold");
797 case KoTextFormat::U_WAVE:
798 data.setAttribute(
"UNDERLINE",
"wave");
800 case KoTextFormat::U_NONE:
801 data.setAttribute(
"UNDERLINE",
"none");
805 if ( tmp->m_optionsMask & KoSearchContext::StrikeOut )
807 switch( tmp->m_strikeOut )
809 case KoTextFormat::S_SIMPLE:
810 data.setAttribute(
"STRIKEOUT",
"single");
812 case KoTextFormat::S_DOUBLE:
813 data.setAttribute(
"STRIKEOUT",
"double");
815 case KoTextFormat::S_NONE:
816 data.setAttribute(
"STRIKEOUT",
"none");
818 case KoTextFormat::S_SIMPLE_BOLD:
819 data.setAttribute(
"STRIKEOUT",
"single-bold");
823 if ( tmp->m_optionsMask & KoSearchContext::Attribute )
825 data.setAttribute(
"FONTATTRIBUTE", KoTextFormat::attributeFontToString( tmp->m_attribute ) );
828 if ( tmp->m_optionsMask & KoSearchContext::VertAlign)
830 data.setAttribute(
"VERTALIGN",
static_cast<int>(tmp->m_vertAlign) );
832 if ( tmp->m_optionsMask & KoSearchContext::BgColor )
834 data.setAttribute(
"TEXTCOLOR", tmp->m_color.name());
836 if ( tmp->m_optionsMask & KoSearchContext::Color )
838 data.setAttribute(
"TEXTCOLOR", tmp->m_color.name());
840 if ( tmp->m_optionsMask & KoSearchContext::BgColor )
842 data.setAttribute(
"TEXTBGCOLOR", tmp->m_backGroundColor.name());
844 if ( tmp->m_optionsMask & KoSearchContext::Language )
845 data.setAttribute(
"LANGUAGE", tmp->m_language );
850void KoAutoFormat::addAutoFormatEntry(
const TQString &key,
const TQString &replace )
852 KoAutoFormatEntry *findEntry = m_entries.find( key);
855 if ( findEntry->replace().lower() ==
replace.lower() )
859 KoAutoFormatEntry *tmp =
new KoAutoFormatEntry( replace );
860 m_entries.insert( key, tmp );
865TQString KoAutoFormat::getLastWord(KoTextParag *parag,
int const index)
868 KoTextString *s = parag->string();
869 for (
int i = index - 1; i >= 0; --i )
871 TQChar ch = s->at( i ).c;
872 if ( ch.isSpace() || ch.isPunct() )
874 lastWord.prepend( ch );
879TQString KoAutoFormat::getLastWord(
const int max_words, KoTextParag *parag,
int const index)
882 KoTextString
const *s = parag->string();
884 for (
int i = index - 1; i >= 0; --i )
886 TQChar ch = s->at( i ).c;
887 if ( ch.isSpace() || ch.isPunct() )
890 if (words >= max_words)
893 lastWord.prepend( ch );
898TQString KoAutoFormat::getWordAfterSpace(KoTextParag *parag,
int const index)
901 KoTextString *s = parag->string();
902 for (
int i = index - 1; i >= 0; --i )
904 TQChar ch = s->at( i ).c;
913bool KoAutoFormat::doCompletion( KoTextCursor* textEditCursor, KoTextParag *parag,
int const index,
KoTextObject *txtObj )
918 TQString lastWord, word;
919 if (m_completionBox && m_completionBox->isShown() )
921 word = m_completionBox->text();
922 lastWord = m_completionBox->lastWord();
926 TQStringList wordlist, new_wordlist;
927 for (uint i=1; i <= m_countMaxWords; i++ )
929 lastWord = getLastWord(i, parag, index+1);
930 wordlist += m_listCompletion->substringCompletion( lastWord );
933 for ( TQStringList::ConstIterator it = wordlist.begin(); it != wordlist.end(); ++it )
935 if ( (*it).startsWith( lastWord,
false ) && new_wordlist.find(*it) == new_wordlist.end() )
937 if ( (*it).length() > maxlength )
938 maxlength = (*it).length();
939 new_wordlist.append(*it);
943 if ( new_wordlist.isEmpty() )
945 if ( new_wordlist.count() == 1 )
946 word = new_wordlist.first();
950 for (uint i = lastWord.length(); i<maxlength && !part; i++)
952 TQChar ch = new_wordlist.first().at(i);
953 for (TQStringList::ConstIterator it = new_wordlist.begin(); it != new_wordlist.end(); ++it )
955 if ( (*it).at(i).lower() != ch.lower() )
957 word = (*it).left(i);
965 if (word == lastWord)
968 word=lastWord+word.right(word.length()-lastWord.length() );
970 if( !word.isEmpty() )
972 int const lastword_length = lastWord.length();
973 int const start = index+1 - lastword_length;
974 int const length = word.length();
977 KoTextCursor cursor( parag->document() );
978 cursor.setParag( parag );
979 cursor.setIndex( start );
980 KoTextDocument * textdoc = parag->textDocument();
981 if( m_completionAppendSpace && !part)
983 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
984 cursor.setIndex( start + lastword_length );
985 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
987 macro->
addCommand( txtObj->replaceSelectionCommand( textEditCursor, word,
988 i18n(
"Completion Word"),
989 KoTextDocument::HighlightSelection ));
991 if ( m_completionAppendSpace && !m_ignoreUpperCase && (m_convertUpperUpper || m_convertUpperCase) && !part)
994 for (uint i=1; i < word.length(); i++)
995 if ( word.at(i).isSpace() || word.at(i).isPunct() )
1000 int const newPos = start + word.length();
1001 KCommand *cmd = doUpperCase( textEditCursor, parag, newPos, word, txtObj );
1004 txtObj->emitHideCursor();
1005 textEditCursor->setIndex(start+ length+1);
1009 txtObj->emitHideCursor();
1010 textEditCursor->setIndex(start+ length);
1012 txtObj->emitNewCommand( macro );
1017 txtObj->emitShowCursor();
1018 removeToolTipCompletion();
1025bool KoAutoFormat::doToolTipCompletion( KoTextCursor* textEditCursor, KoTextParag *parag,
int index,
KoTextObject *txtObj,
int keyPressed )
1027 if( m_completion && m_toolTipCompletion && m_completionBox && m_completionBox->isShown() )
1029 if ( ( keyPressed == TQt::Key_Return && m_keyCompletionAction==Enter )
1030 || ( keyPressed == TQt::Key_Enter && m_keyCompletionAction==Enter )
1031 || ( keyPressed == TQt::Key_Tab && m_keyCompletionAction==Tab )
1032 || ( keyPressed == TQt::Key_Space && m_keyCompletionAction==Space )
1033 || ( keyPressed == TQt::Key_End && m_keyCompletionAction==End )
1034 || ( keyPressed == TQt::Key_Right && m_keyCompletionAction==Right ))
1036 return doCompletion(textEditCursor, parag, index, txtObj);
1041void KoAutoFormat::showToolTipBox(KoTextParag *parag,
int index, TQWidget *widget,
const TQPoint &pos )
1044 if( m_completion && m_toolTipCompletion)
1046 TQString lastWord, word;
1047 for (uint i=1; i <= m_countMaxWords; i++ )
1049 lastWord = getLastWord(i, parag, index+1);
1050 word=m_listCompletion->makeCompletion( lastWord );
1051 if ( !word.isEmpty())
1054 if( !word.isEmpty() && word!=lastWord )
1056 uint
const length = lastWord.length();
1059 word=lastWord+word.right(word.length()-length);
1060 if (!m_completionBox)
1061 m_completionBox =
new KoCompletionBox(0,0,TQt::WType_Popup);
1062 TQPoint
const show_pos = widget->mapToGlobal(pos);
1063 m_completionBox->setText(word);
1064 m_completionBox->setLastWord(lastWord);
1065 m_completionBox->adjustSize();
1066 int const height = m_completionBox->sizeHint().height();
1067 m_completionBox->move( show_pos.x(), show_pos.y() - height );
1069 if (!m_completionBox->isShown() )
1071 m_completionBox->show();
1076 removeToolTipCompletion();
1079void KoAutoFormat::removeToolTipCompletion()
1081 if (m_completion && m_toolTipCompletion && m_completionBox && m_completionBox->isShown())
1082 m_completionBox->hide();
1085void KoAutoFormat::autoFormatIsActive()
1087 m_bAutoFormatActive = m_useBulletStyle ||
1088 m_removeSpaceBeginEndLine ||
1090 m_convertUpperUpper ||
1091 m_convertUpperCase ||
1092 m_autoReplaceNumber ||
1093 m_autoChangeFormat ||
1095 m_typographicDoubleQuotes.replace ||
1096 m_typographicSimpleQuotes.replace ||
1097 m_entries.count()!=0 ||
1098 m_allLanguages.count()!=0;
1101void KoAutoFormat::doAutoFormat( KoTextCursor* textEditCursor, KoTextParag *parag,
int index, TQChar ch,
KoTextObject *txtObj )
1103 m_ignoreUpperCase =
false;
1105 if ( !m_configRead )
1108 if ( !m_bAutoFormatActive )
1117 TQString word=getWordAfterSpace(parag,index);
1119 if ( m_autoChangeFormat && index > 3)
1121 KCommand *cmd =doAutoChangeFormat( textEditCursor, parag, index, word, txtObj );
1123 txtObj->emitNewCommand( cmd );
1126 if ( m_autoReplaceNumber )
1128 KCommand *cmd = doAutoReplaceNumber( textEditCursor, parag, index, word, txtObj );
1130 txtObj->emitNewCommand( cmd );
1137 if( m_removeSpaceBeginEndLine && index > 1)
1139 KCommand *cmd = doRemoveSpaceBeginEndLine( textEditCursor, parag, txtObj, index );
1141 txtObj->emitNewCommand( cmd );
1143 if( m_useBulletStyle && index > 3)
1145 KCommand *cmd =doUseBulletStyle( textEditCursor, parag, txtObj, index );
1147 txtObj->emitNewCommand( cmd );
1149 if( m_useAutoNumberStyle && index > 3 )
1151 KCommand *cmd =doUseNumberStyle( textEditCursor, parag, txtObj, index );
1153 txtObj->emitNewCommand( cmd );
1155 if( m_convertUpperUpper && m_includeTwoUpperLetterException )
1156 doAutoIncludeUpperUpper(textEditCursor, parag, txtObj );
1157 if( m_convertUpperCase && m_includeAbbreviation )
1158 doAutoIncludeAbbreviation(textEditCursor, parag, txtObj );
1165 if ( (ch.isSpace() || ch==
':' || ch==
'?' || ch==
'!' || ch==
',' || (m_advancedAutoCorrect && ch==
'.') ) && index > 0 )
1169 TQString lastWord = getWordAfterSpace(parag, index);
1173 detectStartOfLink( parag, index,
true );
1175 detectStartOfLink( parag, index,
false );
1177 if ( !m_wordInserted && m_advancedAutoCorrect && !m_ignoreUpperCase)
1179 int const completionBeginPos = index -lastWord.length();
1181 cmd = doAutoCorrect( textEditCursor, parag, newPos, txtObj );
1190 int const endPos=textEditCursor->index();
1191 bool was_a_replacement;
1192 if (index == newPos)
1193 was_a_replacement =
false;
1195 was_a_replacement =
true;
1197 if( was_a_replacement)
1199 txtObj->emitHideCursor();
1202 textEditCursor->gotoUp();
1203 textEditCursor->gotoLineEnd();
1204 newPos=textEditCursor->index();
1209 m_wordInserted =
true;
1210 for(
int i=completionBeginPos; i<newPos;i++)
1212 textEditCursor->setIndex(i);
1213 doAutoFormat( textEditCursor, parag, i, parag->toString().at(i),txtObj );
1216 textEditCursor->setIndex(newPos);
1217 doAutoFormat( textEditCursor, parag, newPos, ch,txtObj );
1218 m_wordInserted =
false;
1221 textEditCursor->gotoLineStart();
1222 textEditCursor->gotoDown();
1225 textEditCursor->setIndex(newPos+1);
1226 txtObj->emitShowCursor();
1232 if (!m_ignoreUpperCase && m_bCapitalizeNameOfDays)
1234 KCommand *cmd = doCapitalizeNameOfDays( textEditCursor, parag, index, lastWord, txtObj );
1241 m_ignoreUpperCase =
true;
1249 if( !m_ignoreUpperCase && m_completion && m_addCompletionWord && m_listCompletion->items().count() < m_nbMaxCompletionWord )
1251 TQString completionWord(
"");
1253 for (uint i=0;i<lastWord.length();i++)
1255 ch = lastWord.at(i);
1256 if (ch.isPunct() && ch!=
'-' && ch!=
'=' )
1258 if (completionWord.at(0) ==
'-')
1259 completionWord.remove(0,1);
1261 if (completionWord.length()>= m_minCompletionWordLength && !completionWord.isEmpty() && m_listCompletion->makeCompletion(completionWord).isEmpty())
1263 kdDebug() <<
"Adding:" << completionWord << endl;
1264 m_listCompletion->addItem( completionWord );
1265 if ( completionWord.length() > m_countMaxWords )
1266 m_countMaxWords = completionWord.length();
1269 completionWord =
"";
1273 completionWord.append(ch);
1274 if (i==lastWord.length()-1)
1276 if (completionWord.at(0) ==
'-')
1277 completionWord.remove(0,1);
1278 if (completionWord.at(completionWord.length()-1) ==
'-')
1279 completionWord.truncate(completionWord.length()-1);
1280 completionWord.remove(
'=');
1281 if (completionWord.length()>= m_minCompletionWordLength && !completionWord.isEmpty() && m_listCompletion->makeCompletion(completionWord).isEmpty())
1283 kdDebug() <<
"Adding:" << completionWord << endl;
1284 m_listCompletion->addItem( completionWord );
1285 if ( completionWord.length() > m_countMaxWords )
1286 m_countMaxWords = completionWord.length();
1293 if( m_autoDetectUrl && m_ignoreUpperCase && (ch!=
'?' || lastWord.at(lastWord.length()-1)==
'?') )
1295 doAutoDetectUrl( textEditCursor, parag, index, lastWord, txtObj );
1299 if (!m_ignoreUpperCase && (m_convertUpperUpper || m_convertUpperCase) )
1301 cmd = doUpperCase( textEditCursor, parag, index, lastWord, txtObj );
1312 txtObj->emitNewCommand( macro );
1314 if(!m_ignoreUpperCase && m_bAutoSuperScript && m_superScriptEntries.count()>0)
1316 if( lastWord.at(0).isPunct() )
1317 lastWord.remove(0,1);
1318 KCommand * cmd = doAutoSuperScript( textEditCursor, parag, index, lastWord, txtObj );
1320 txtObj->emitNewCommand( cmd );
1326 if ( ch ==
'"' && m_typographicDoubleQuotes.replace )
1328 KCommand *cmd = doTypographicQuotes( textEditCursor, parag, index, txtObj,
true );
1330 txtObj->emitNewCommand( cmd );
1332 else if ( ch ==
'\'' && m_typographicDoubleQuotes.replace )
1334 KCommand *cmd = doTypographicQuotes( textEditCursor, parag, index, txtObj,
false );
1336 txtObj->emitNewCommand( cmd );
1341KCommand *KoAutoFormat::doAutoCorrect( KoTextCursor* textEditCursor, KoTextParag *parag,
int &index,
KoTextObject *txtObj )
1348 TQString * wordArray =
new TQString[m_maxFindLength+1];
1351 KoTextString *s = parag->string();
1352 for (
int i = index - 1; i >= 0; --i )
1354 TQChar ch = s->at( i ).c;
1356 if ( ch.isSpace() || i==0)
1358 if(i==0 && word.length()<m_maxFindLength)
1360 wordArray[word.length()]=word;
1363 if (((index - 1)-i) == (
int)m_maxFindLength)
1368 KCommand *cmd = autoFormatWord( textEditCursor, parag, index, txtObj, wordArray,
false );
1370 cmd = autoFormatWord( textEditCursor, parag, index, txtObj, wordArray,
true );
1371 delete [] wordArray;
1376KCommand *KoAutoFormat::autoFormatWord( KoTextCursor* textEditCursor, KoTextParag *parag,
int &index,
KoTextObject *txtObj, TQString * _wordArray,
bool _allLanguages )
1378 KoTextDocument * textdoc = parag->textDocument();
1383 for(
int i=m_maxFindLength;i>0;--i)
1385 if ( !_wordArray[i].isEmpty())
1387 KoAutoFormatEntry* it = 0L;
1388 if ( _allLanguages )
1389 it = m_allLanguages[ _wordArray[i] ];
1391 it = m_entries[ _wordArray[i] ];
1392 if ( _wordArray[i]!=0 && it )
1394 unsigned int length = _wordArray[i].length();
1395 int const start = index - length;
1396 KoTextCursor cursor( parag->document() );
1397 cursor.setParag( parag );
1398 cursor.setIndex( start );
1399 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1400 cursor.setIndex( start + length );
1401 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1403 kdDebug()<<
"it->replace() :"<<it->replace()<<endl;
1404 if (!it->formatEntryContext() || !m_bAutoCorrectionWithFormat)
1406 cmd = txtObj->replaceSelectionCommand( textEditCursor, it->replace(),
1407 i18n(
"Autocorrect Word"),
1408 KoTextDocument::HighlightSelection );
1413 KoTextFormat * lastFormat = parag->at( start )->format();
1415 changeTextFormat(it->formatEntryContext(), newFormat, flags );
1417 KCommand *cmd2=txtObj->replaceSelectionCommand( textEditCursor, it->replace(),
1418 i18n(
"Autocorrect Word"),
1419 KoTextDocument::HighlightSelection );
1422 KoTextCursor cursor( parag->document() );
1423 cursor.setParag( parag );
1424 cursor.setIndex( start );
1425 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1426 cursor.setIndex( start + it->replace().length() );
1427 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1429 cmd2 =txtObj->
setFormatCommand( textEditCursor, &lastFormat, newFormat, flags,
false, KoTextDocument::HighlightSelection );
1432 index = index - length + it->replace().length();
1433 textEditCursor->setIndex(index+1);
1434 cmd2 =txtObj->
setFormatCommand( textEditCursor, &newFormat, lastFormat, 0 );
1436 parag->at( index+1 )->setFormat(lastFormat);
1439 txtObj->emitHideCursor();
1440 textEditCursor->gotoRight();
1441 txtObj->emitShowCursor();
1448 txtObj->emitHideCursor();
1449 textEditCursor->gotoRight();
1450 txtObj->emitShowCursor();
1451 index = index - length + it->replace().length();
1459KCommand *KoAutoFormat::doTypographicQuotes( KoTextCursor* textEditCursor, KoTextParag *parag,
int index,
KoTextObject *txtObj,
bool doubleQuotes )
1462 KoTextDocument * textdoc = parag->textDocument();
1463 KoTextCursor cursor( parag->document() );
1464 cursor.setParag( parag );
1465 cursor.setIndex( index );
1466 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1467 cursor.setIndex( index + 1 );
1468 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1480 TQString replacement;
1485 TQChar::Category c1 = parag->at( index - 1 )->c.category();
1488 if ( c1 == TQChar::Separator_Space || c1 == TQChar::Separator_Line || c1 == TQChar::Separator_Paragraph ||
1489 c1 == TQChar::Punctuation_Open || c1 == TQChar::Other_Control )
1493 if ( c1 == TQChar::Punctuation_InitialQuote )
1495 TQChar openingQuote;
1498 openingQuote = m_typographicDoubleQuotes.begin;
1500 openingQuote = m_typographicSimpleQuotes.begin;
1503 if( parag->at( index - 1 )->c != openingQuote )
1509 if( index > 1 && !ending )
1511 TQChar::Category c2 = parag->at( index - 2 )->c.category();
1512 ending = (c2 == TQChar::Punctuation_InitialQuote);
1518 replacement = m_typographicDoubleQuotes.end;
1520 replacement = m_typographicSimpleQuotes.end;
1525 replacement = m_typographicDoubleQuotes.begin;
1527 replacement = m_typographicSimpleQuotes.begin;
1529 return txtObj->replaceSelectionCommand( textEditCursor, replacement,
1530 i18n(
"Typographic Quote"),
1531 KoTextDocument::HighlightSelection );
1534KCommand * KoAutoFormat::doUpperCase( KoTextCursor *textEditCursor, KoTextParag *parag,
1535 int index,
const TQString & word,
KoTextObject *txtObj )
1537 KoTextDocument * textdoc = parag->textDocument();
1538 unsigned int length = word.length();
1539 if (word.at(length-1) ==
'.' )
1544 int const start = index - length;
1545 KoTextCursor backCursor( parag->document() );
1546 backCursor.setParag( parag );
1547 backCursor.setIndex( start );
1550 TQChar
const firstChar = backCursor.parag()->at( backCursor.index() )->c;
1552 bool bNeedMove =
false;
1554 if ( m_convertUpperCase && isLower( firstChar ) )
1556 bool beginningOfSentence =
true;
1558 while ( backCursor.index() > 0 || backCursor.parag()->prev() )
1560 beginningOfSentence =
false;
1561 backCursor.gotoLeft();
1562 if ( !backCursor.parag()->at( backCursor.index() )->c.isSpace() )
1566 if ( !beginningOfSentence )
1567 beginningOfSentence = isMark( backCursor.parag()->at( backCursor.index() )->c);
1569 if ( !beginningOfSentence && start==0 )
1570 if ( parag->counter() || backCursor.parag()->at( backCursor.index() )->c.isPunct() )
1571 beginningOfSentence =
true;
1574 if ( beginningOfSentence )
1576 TQChar
const punct = backCursor.parag()->at( backCursor.index() )->c;
1577 TQString
const text = getLastWord( backCursor.parag(), backCursor.index() )
1579 kdDebug() <<
"text: " << text << endl;
1581 beginningOfSentence = (m_upperCaseExceptions.findIndex(text)==-1);
1584 if ( beginningOfSentence )
1586 KoTextCursor cursor( parag->document() );
1587 cursor.setParag( parag );
1588 cursor.setIndex( start );
1589 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1590 cursor.setIndex( start + 1 );
1591 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1592 cmd = txtObj->replaceSelectionCommand( textEditCursor, TQString( firstChar.upper() ),
1593 i18n(
"Autocorrect (capitalize first letter)"),
1594 KoTextDocument::HighlightSelection );
1598 else if ( m_convertUpperUpper && isUpper( firstChar ) && length > 2 )
1600 backCursor.setIndex( backCursor.index() + 1 );
1601 TQChar secondChar = backCursor.parag()->at( backCursor.index() )->c;
1603 if ( isUpper( secondChar ) )
1606 backCursor.setIndex( backCursor.index() + 1 );
1607 TQChar thirdChar = backCursor.parag()->at( backCursor.index() )->c;
1608 if ( isLower( thirdChar ) && (m_twoUpperLetterException.findIndex(word)==-1))
1611 KoTextCursor cursor( parag->document() );
1612 cursor.setParag( parag );
1613 cursor.setIndex( start + 1 );
1614 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1615 cursor.setIndex( start + 2 );
1616 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1618 TQString replacement = word[1].lower();
1619 cmd = txtObj->replaceSelectionCommand( textEditCursor, replacement,
1620 i18n(
"Autocorrect"),
1621 KoTextDocument::HighlightSelection );
1629 if (word.at(word.length()-1) ==
'.' )
1631 txtObj->emitHideCursor();
1632 textEditCursor->setParag( parag );
1633 textEditCursor->setIndex( index );
1634 textEditCursor->gotoRight();
1635 txtObj->emitShowCursor();
1640KCommand * KoAutoFormat::doAutoReplaceNumber( KoTextCursor* textEditCursor, KoTextParag *parag,
int& index,
const TQString & word ,
KoTextObject *txtObj )
1642 unsigned int length = word.length();
1645 KoTextDocument * textdoc = parag->textDocument();
1646 int start = index - length;
1647 if( word == TQString(
"1/2") || word == TQString(
"1/4") || word == TQString(
"3/4") )
1649 KoTextCursor cursor( parag->document() );
1650 cursor.setParag( parag );
1651 cursor.setIndex( start );
1652 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1653 cursor.setIndex( start + length );
1654 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1655 TQString replacement;
1656 if( word == TQString(
"1/2") )
1657 replacement=TQString(
"½");
1658 else if (word == TQString(
"1/4") )
1659 replacement=TQString(
"¼");
1660 else if (word == TQString(
"3/4") )
1661 replacement=TQString(
"¾");
1662 TQString cmdName = i18n(
"Autocorrect for Fraction");
1663 KCommand *cmd =txtObj->replaceSelectionCommand( textEditCursor, replacement,
1665 KoTextDocument::HighlightSelection );
1666 txtObj->emitHideCursor();
1667 textEditCursor->gotoRight();
1668 txtObj->emitShowCursor();
1669 index = index - length + replacement.length();
1675void KoAutoFormat::detectStartOfLink(KoTextParag * parag,
int const index,
bool const insertedDot)
1678 KoTextString *s = parag->string();
1679 for (
int i = 0; i < index; ++i )
1681 word.append( s->at( i ).c );
1684 if (word.find(
"http")!=-1 || word.find(
"https")!=-1 || word.find(
"mailto")!=-1 || word.find(
"ftp")!=-1 || word.find(
"file")!=-1
1685 || word.find(
"news")!=-1 || word.find(
'@')!=-1)
1686 m_ignoreUpperCase=
true;
1689 int const tmp_pos=word.find(
"www.");
1690 if (tmp_pos!=-1 && (word.find(
'.',tmp_pos+4)!=-1 || insertedDot) )
1691 m_ignoreUpperCase=
true;
1695void KoAutoFormat::doAutoDetectUrl( KoTextCursor *textEditCursor, KoTextParag *parag,
int &index, TQString & word,
KoTextObject *txtObj )
1697 kdDebug() <<
"link:" << word << endl;
1699 int pos = word.find(
"http://");
1700 int tmp_pos = word.find(
"https://");
1701 if(tmp_pos<pos && tmp_pos!=-1)
1703 tmp_pos = word.find(
"mailto:/");
1704 if((tmp_pos<pos || pos==-1 ) && tmp_pos!=-1)
1706 tmp_pos = word.find(
"ftp://");
1707 if((tmp_pos<pos || pos==-1 ) && tmp_pos!=-1)
1709 tmp_pos = word.find(
"ftp.");
1710 if((tmp_pos<pos || pos==-1 ) && tmp_pos!=-1)
1715 tmp_pos = word.find(
"file:/");
1716 if((tmp_pos<pos || pos==-1 ) && tmp_pos!=-1)
1718 tmp_pos = word.find(
"news:");
1719 if((tmp_pos<pos || pos==-1 ) && tmp_pos!=-1)
1721 tmp_pos = word.find(
"www.");
1722 if((tmp_pos<pos || pos==-1 ) && tmp_pos!=-1 && word.find(
'.',tmp_pos+4)!=-1 )
1727 tmp_pos = word.find(
'@');
1728 if ( pos == -1 && tmp_pos != -1 )
1735 if ( c.isPunct() && c!=
'.'&& c!=
'_')
break;
1738 if ( pos == tmp_pos-1 )
1740 m_ignoreUpperCase =
false;
1750 while ( !word.at(word.length()-1).isLetter() && !word.at(word.length()-1).isDigit() && word.at(word.length()-1)!=
'/')
1752 word.truncate(word.length()-1);
1756 unsigned int const length = word.length();
1757 int const start = index - length;
1758 KoTextCursor cursor( parag->document() );
1759 KoTextDocument * textdoc = parag->textDocument();
1760 cursor.setParag( parag );
1761 cursor.setIndex( start );
1762 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1763 cursor.setIndex( start + length );
1764 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1765 TQString newWord = word;
1767 newWord = TQString(
"mailto:") + word;
1768 else if(link_type==2)
1769 newWord = TQString(
"http://") + word;
1770 else if(link_type==3)
1771 newWord = TQString(
"ftp://") + word;
1773 KoVariable* var =
new KoLinkVariable( textdoc, word, newWord, m_varFormatCollection->format(
"STRING" ), m_varCollection );
1775 customItemsMap.insert( 0, var );
1776 KoTextFormat * lastFormat = parag->at( start )->format();
1777 int origCursorIndex = textEditCursor->index();
1778 txtObj->
insert( textEditCursor, lastFormat, KoTextObject::customItemChar(), i18n(
"Insert Variable"),
1779 KoTextDocument::HighlightSelection, KoTextObject::DefaultInsertFlags, customItemsMap );
1781 parag->invalidate(0);
1782 parag->setChanged(
true );
1787 txtObj->emitHideCursor();
1788 textEditCursor->setIndex( origCursorIndex - (length-1) );
1789 txtObj->emitShowCursor();
1792 if ( m_completion && m_addCompletionWord && m_listCompletion->items().count() < m_nbMaxCompletionWord )
1794 if (word.length()>= m_minCompletionWordLength && !word.isEmpty() && m_listCompletion->makeCompletion(word).isEmpty())
1796 kdDebug() <<
"Adding:" << word << endl;
1797 m_listCompletion->addItem( word );
1798 if ( word.length() > m_countMaxWords )
1799 m_countMaxWords = word.length();
1805void KoAutoFormat::doAutoIncludeUpperUpper(KoTextCursor* , KoTextParag *parag,
KoTextObject* )
1807 KoTextString *s = parag->string();
1809 if( s->length() < 2 )
1812 for (
int i=0; i<=(s->length() - 1);i++)
1815 for (
int j = i ; j < s->length() - 1; j++ )
1817 TQChar ch = s->at( j ).c;
1822 if( word.length() > 2 && word.left(2)==word.left(2).upper() && word.at(3)!=word.at(3).upper() )
1824 if ( m_twoUpperLetterException.findIndex(word )==-1)
1825 m_twoUpperLetterException.append( word);
1833void KoAutoFormat::doAutoIncludeAbbreviation(KoTextCursor* , KoTextParag *parag,
KoTextObject* )
1835 KoTextString *s = parag->string();
1836 if( s->length() < 2 )
1838 for (
int i=0; i<=(s->length() - 1);i++)
1843 for (
int j = i ; j < s->length() - 1; j++ )
1845 TQChar ch = s->at( j ).c;
1850 if ( isMark( word.at(word.length()-1)) )
1852 for (
int j = i+word.length()+1 ; j < s->length() - 1; j++ )
1854 TQChar ch = s->at( j ).c;
1857 wordAfter.append( ch );
1859 if( word.length()>1 && !wordAfter.isEmpty() && wordAfter.at(0)==wordAfter.at(0).lower())
1861 if ( m_upperCaseExceptions.findIndex(word )==-1)
1862 m_upperCaseExceptions.append( word );
1866 if( !wordAfter.isEmpty())
1868 i+=wordAfter.length()+1;
1875KCommand * KoAutoFormat::doAutoChangeFormat( KoTextCursor *textEditCursor, KoTextParag *parag,
int index,
const TQString & word,
KoTextObject *txtObj )
1877 bool underline = (word.at(0)==
'_' && word.at(word.length()-1)==
'_');
1878 bool bold = (word.at(0)==
'*' && word.at(word.length()-1)==
'*');
1879 if( bold || underline)
1881 TQString replacement=word.mid(1,word.length()-2);
1882 int start = index - word.length();
1883 KoTextDocument * textdoc = parag->textDocument();
1885 KoTextCursor cursor( parag->document() );
1887 cursor.setParag( parag );
1888 cursor.setIndex( start );
1889 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1890 cursor.setIndex( start + word.length() );
1891 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1892 macro->
addCommand(txtObj->replaceSelectionCommand( textEditCursor, replacement,
1893 i18n(
"Autocorrect Word"),
1894 KoTextDocument::HighlightSelection));
1896 KoTextFormat * lastFormat = parag->at( start )->format();
1898 cursor.setIndex( start );
1899 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1900 cursor.setIndex( start + word.length()-2 );
1901 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1905 newFormat->setBold(
true);
1906 macro->
addCommand(txtObj->
setFormatCommand( textEditCursor, 0L, newFormat, KoTextFormat::Bold ,
false,KoTextDocument::HighlightSelection ));
1908 else if( underline )
1910 newFormat->setUnderline(
true);
1911 macro->
addCommand(txtObj->
setFormatCommand( textEditCursor, 0L, newFormat, KoTextFormat::Underline ,
false,KoTextDocument::HighlightSelection ));
1913 txtObj->emitHideCursor();
1914 textEditCursor->gotoRight();
1915 txtObj->emitShowCursor();
1921KCommand *KoAutoFormat::doUseBulletStyle(KoTextCursor * , KoTextParag *parag,
KoTextObject *txtObj,
int& index )
1923 KoTextDocument * textdoc = parag->textDocument();
1924 KoTextCursor cursor( parag->document() );
1925 KoTextString *s = parag->string();
1926 TQChar ch = s->at( 0 ).c;
1928 if( m_useBulletStyle && (ch ==
'*' || ch ==
'-' || ch ==
'+') && (s->at(1).c).isSpace())
1930 if ( parag->counter() && parag->counter()->numbering() == KoParagCounter::NUM_FOOTNOTE )
1933 cursor.setParag( parag );
1934 cursor.setIndex( 0 );
1935 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1936 cursor.setParag( parag );
1937 cursor.setIndex( 2 );
1938 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1939 KCommand *cmd=txtObj->removeSelectedTextCommand( &cursor, KoTextDocument::HighlightSelection );
1945 cursor.setParag( parag );
1946 cursor.setIndex( 0 );
1947 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1949 cursor.setIndex( 2 );
1950 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1954 if( m_bulletStyle.isNull() && (ch ==
'*' || ch ==
'+' || ch ==
'-'))
1958 c.setNumbering( KoParagCounter::NUM_LIST );
1959 c.setStyle( KoParagCounter::STYLE_DISCBULLET );
1961 else if ( ch ==
'+' || ch==
'-')
1963 c.setNumbering( KoParagCounter::NUM_LIST );
1964 c.setStyle( KoParagCounter::STYLE_CUSTOMBULLET );
1966 c.setCustomBulletCharacter(
'-' );
1968 c.setCustomBulletCharacter(
'+' );
1973 c.setNumbering( KoParagCounter::NUM_LIST );
1974 c.setStyle( KoParagCounter::STYLE_CUSTOMBULLET );
1975 c.setCustomBulletCharacter( m_bulletStyle );
1977 c.setSuffix(TQString());
1978 cmd=txtObj->setCounterCommand( &cursor, c ,KoTextDocument::HighlightSelection );
1982 cursor.setParag( parag->next() );
1986 cursor.setIndex( 0 );
1987 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1988 cursor.setIndex( 0 );
1989 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1990 cmd=txtObj->setCounterCommand( &cursor, c ,KoTextDocument::HighlightSelection );
1999KCommand *KoAutoFormat::doUseNumberStyle(KoTextCursor * , KoTextParag *parag,
KoTextObject *txtObj,
int& index )
2001 if ( parag->counter() && parag->counter()->numbering() == KoParagCounter::NUM_FOOTNOTE )
2003 KoTextDocument * textdoc = parag->textDocument();
2004 KoTextCursor cursor( parag->document() );
2005 KoTextString *s = parag->string();
2007 for (
int i = 0 ; i < s->length() - 1; i++ )
2009 TQChar ch = s->at( i ).c;
2014 TQChar punct=word[word.length()-1];
2015 if( punct.isPunct() )
2017 TQString number=word.mid(0,word.length()-1);
2019 uint val=number.toUInt(&ok);
2023 cursor.setParag( parag );
2024 cursor.setIndex( 0 );
2025 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
2026 cursor.setParag( parag );
2027 cursor.setIndex( word.length()+1 );
2028 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
2029 KCommand *cmd=txtObj->removeSelectedTextCommand( &cursor, KoTextDocument::HighlightSelection );
2031 index -= word.length()+1;
2036 cursor.setParag( parag );
2037 cursor.setIndex( 0 );
2038 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
2040 cursor.setIndex( 2 );
2041 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
2044 c.setNumbering( KoParagCounter::NUM_LIST );
2045 c.setStyle( KoParagCounter::STYLE_NUM );
2046 c.setSuffix(TQString( punct ));
2047 c.setStartNumber( (
int)val);
2052 if ( c.number( parag ) != (
int)val )
2053 c.setRestartCounter(
true );
2055 cmd=txtObj->setCounterCommand( &cursor, c, KoTextDocument::HighlightSelection );
2060 c.setRestartCounter(
false );
2061 cursor.setParag( parag->next() );
2062 cursor.setIndex( 0 );
2063 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
2064 cursor.setIndex( 0 );
2065 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
2066 cmd=txtObj->setCounterCommand( &cursor, c, KoTextDocument::HighlightSelection );
2076KCommand * KoAutoFormat::doRemoveSpaceBeginEndLine( KoTextCursor *textEditCursor, KoTextParag *parag,
KoTextObject *txtObj,
int &index )
2078 KoTextString *s = parag->string();
2079 KoTextDocument * textdoc = parag->textDocument();
2080 KoTextCursor cursor( parag->document() );
2084 for (
int i = parag->lastCharPos(); i >= 0; --i )
2086 TQChar ch = s->at( i ).c;
2089 if( i == parag->lastCharPos() )
2091 cursor.setParag( parag );
2092 cursor.setIndex( i+1 );
2093 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
2094 cursor.setParag( parag );
2095 cursor.setIndex( parag->lastCharPos()+1 );
2096 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
2097 KCommand *cmd=txtObj->replaceSelectionCommand( &cursor,
"", TQString(), KoTextDocument::HighlightSelection );
2104 macroCmd =
new KMacroCommand( i18n(
"Autocorrect (remove start and end line space)"));
2113 for (
int i = 0 ; i <= parag->lastCharPos() ; i++ )
2115 TQChar ch = s->at( i ).c;
2121 cursor.setParag( parag );
2122 cursor.setIndex( 0 );
2123 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
2124 cursor.setParag( parag );
2125 cursor.setIndex( i );
2126 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
2127 KCommand *cmd=txtObj->replaceSelectionCommand( &cursor,
"", TQString(), KoTextDocument::HighlightSelection );
2133 macroCmd =
new KMacroCommand( i18n(
"Autocorrect (remove start and end line space)"));
2142 txtObj->emitHideCursor();
2143 textEditCursor->setParag( parag->next() );
2145 txtObj->emitShowCursor();
2150KCommand *KoAutoFormat::doCapitalizeNameOfDays( KoTextCursor* textEditCursor, KoTextParag *parag,
int index,
const TQString & word ,
KoTextObject *txtObj )
2154 int pos = m_cacheNameOfDays.findIndex( word.lower() );
2157 KoTextDocument * textdoc = parag->textDocument();
2158 TQString replaceStr= m_cacheNameOfDays[pos];
2159 int start = index - replaceStr.length();
2160 int length = replaceStr.length();
2161 if( word.at(0).isLetter() && word.at(0)==word.at(0).lower() )
2163 KoTextCursor cursor( parag->document() );
2164 cursor.setParag( parag );
2165 cursor.setIndex( start );
2166 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
2167 cursor.setIndex( start + length );
2168 TQString replacement = replaceStr.at(0).upper() + replaceStr.right( length-1 );
2169 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
2170 TQString cmdName=i18n(
"Capitalize Name of Days");
2171 KCommand *cmd =txtObj->replaceSelectionCommand( textEditCursor, replacement,
2173 KoTextDocument::HighlightSelection );
2174 txtObj->emitHideCursor();
2175 textEditCursor->gotoRight();
2176 txtObj->emitShowCursor();
2182KCommand *KoAutoFormat::doAutoSuperScript( KoTextCursor* textEditCursor, KoTextParag *parag,
int index,
const TQString & word ,
KoTextObject *txtObj )
2184 KoAutoFormatEntryMap::Iterator it = m_superScriptEntries.begin();
2187 for ( ; it != m_superScriptEntries.end() ; ++it )
2191 replace = it.data().replace();
2195 else if ( it.key()==
"othernb")
2197 TQString tmp = it.data().replace();
2198 int pos = word.find( tmp );
2201 if( pos + tmp.length() == word.length())
2204 word.left( pos ).toInt( &ok);
2217 KoTextDocument * textdoc = parag->textDocument();
2219 int start = index -
replace.length();
2220 KoTextFormat * lastFormat = parag->at( start )->format();
2222 KoTextCursor cursor( parag->document() );
2224 cursor.setParag( parag );
2225 cursor.setIndex( start );
2226 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
2227 cursor.setIndex( start + word.length() -1 );
2228 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
2229 newFormat->setVAlign(KoTextFormat::AlignSuperScript);
2230 KCommand *cmd =txtObj->
setFormatCommand( textEditCursor, 0L, newFormat, KoTextFormat::VAlign ,
false,KoTextDocument::HighlightSelection );
2231 textdoc->removeSelection( KoTextDocument::HighlightSelection );
2238bool KoAutoFormat::doIgnoreDoubleSpace( KoTextParag *parag,
int index, TQChar ch )
2240 if( m_ignoreDoubleSpace && ch==
' ' && index >= 0 && !parag->hasAnySelection() )
2242 KoTextString *s = parag->string();
2243 TQChar ch = s->at( index ).c;
2250void KoAutoFormat::configTypographicSimpleQuotes( TypographicQuotes _tq )
2252 m_typographicSimpleQuotes = _tq;
2255void KoAutoFormat::configTypographicDoubleQuotes( TypographicQuotes _tq )
2257 m_typographicDoubleQuotes = _tq;
2260void KoAutoFormat::configUpperCase(
bool _uc )
2262 m_convertUpperCase = _uc;
2265void KoAutoFormat::configUpperUpper(
bool _uu )
2267 m_convertUpperUpper = _uu;
2270void KoAutoFormat::configAdvancedAutocorrect(
bool _aa )
2272 m_advancedAutoCorrect = _aa;
2275void KoAutoFormat::configAutoDetectUrl(
bool _au)
2277 m_autoDetectUrl=_au;
2280void KoAutoFormat::configIgnoreDoubleSpace(
bool _ids)
2282 m_ignoreDoubleSpace=_ids;
2285void KoAutoFormat::configRemoveSpaceBeginEndLine(
bool _space)
2287 m_removeSpaceBeginEndLine=_space;
2290void KoAutoFormat::configUseBulletStyle(
bool _ubs)
2292 m_useBulletStyle=_ubs;
2295void KoAutoFormat::configBulletStyle( TQChar b )
2300void KoAutoFormat::configAutoChangeFormat(
bool b)
2302 m_autoChangeFormat = b;
2306void KoAutoFormat::configAutoReplaceNumber(
bool b )
2308 m_autoReplaceNumber = b;
2311void KoAutoFormat::configAutoNumberStyle(
bool b )
2313 m_useAutoNumberStyle = b;
2316void KoAutoFormat::configCompletion(
bool b )
2321void KoAutoFormat::configToolTipCompletion(
bool b )
2323 m_toolTipCompletion = b;
2324 if (!b && m_completionBox)
2326 delete m_completionBox;
2327 m_completionBox = 0;
2331void KoAutoFormat::configKeyCompletionAction( KeyCompletionAction action )
2333 m_keyCompletionAction =
action;
2336void KoAutoFormat::configAppendSpace(
bool b)
2338 m_completionAppendSpace= b;
2341void KoAutoFormat::configMinWordLength( uint val )
2343 m_minCompletionWordLength = val;
2346void KoAutoFormat::configNbMaxCompletionWord( uint val )
2348 m_nbMaxCompletionWord = val;
2352void KoAutoFormat::configAddCompletionWord(
bool b )
2354 m_addCompletionWord= b;
2357bool KoAutoFormat::isUpper(
const TQChar &c )
2359 return c.lower() != c;
2362bool KoAutoFormat::isLower(
const TQChar &c )
2366 return c.upper() != c;
2369bool KoAutoFormat::isMark(
const TQChar &c )
2371 return ( c == TQChar(
'.' ) ||
2372 c == TQChar(
'?' ) ||
2373 c == TQChar(
'!' ) );
2376bool KoAutoFormat::isSeparator(
const TQChar &c )
2378 return ( !c.isLetter() && !c.isNumber() && !c.isDigit() );
2381void KoAutoFormat::buildMaxLen()
2383 m_maxFindLength = 0;
2384 TQDictIterator<KoAutoFormatEntry> it( m_entries );
2385 for( ; it.current(); ++it )
2387 m_maxFindLength = TQMAX( m_maxFindLength, it.currentKey().length() );
2389 TQDictIterator<KoAutoFormatEntry> it2( m_allLanguages );
2390 for( ; it2.current(); ++it2 )
2392 m_maxFindLength = TQMAX( m_maxFindLength, it2.currentKey().length() );
2396TQStringList KoAutoFormat::listCompletion()
const
2398 return m_listCompletion->items();
2402void KoAutoFormat::configIncludeTwoUpperUpperLetterException(
bool b)
2404 m_includeTwoUpperLetterException = b;
2407void KoAutoFormat::configIncludeAbbreviation(
bool b )
2409 m_includeAbbreviation = b;
2412void KoAutoFormat::configAutoSuperScript(
bool b )
2414 m_bAutoSuperScript = b;
2417void KoAutoFormat::configCorrectionWithFormat(
bool b)
2419 m_bAutoCorrectionWithFormat = b;
2422void KoAutoFormat::configCapitalizeNameOfDays(
bool b)
2424 m_bCapitalizeNameOfDays = b;
2427void KoAutoFormat::configAutoFormatLanguage(
const TQString &_lang)
2429 m_autoFormatLanguage=_lang;
2434 KoTextParag * parag = obj->
textDocument()->firstParag();
2435 KoTextCursor *cursor =
new KoTextCursor( obj->
textDocument() );
2439 cursor->setIndex(0);
2440 for (
int i=0;i<parag->length();i++)
2442 cursor->gotoRight();
2444 if (i == parag->length()-1)
2445 doAutoFormat(cursor,parag,i,
'\n',obj);
2447 doAutoFormat(cursor,parag,i, parag->string()->at(i).c,obj);
2449 parag = parag->next();
2456void KoAutoFormat::changeTextFormat(KoSearchContext *formatOptions,
KoTextFormat * format,
int & flags )
2460 if (formatOptions->m_optionsMask & KoSearchContext::Bold)
2462 format->setBold( formatOptions->m_options & KoSearchContext::Bold);
2463 flags |=KoTextFormat::Bold;
2465 if ( formatOptions->m_optionsMask & KoSearchContext::Size)
2467 format->setPointSize( formatOptions->m_size );
2468 flags |=KoTextFormat::Size;
2470 if ( formatOptions->m_optionsMask & KoSearchContext::Family)
2472 format->setFamily( formatOptions->m_family );
2473 flags |=KoTextFormat::Family;
2475 if ( formatOptions->m_optionsMask & KoSearchContext::Color)
2477 format->setColor(formatOptions->m_color);
2478 flags |=KoTextFormat::Color;
2480 if ( formatOptions->m_optionsMask & KoSearchContext::BgColor)
2482 format->setTextBackgroundColor(formatOptions->m_backGroundColor);
2483 flags |=KoTextFormat::TextBackgroundColor;
2486 if ( formatOptions->m_optionsMask & KoSearchContext::Italic)
2488 format->setItalic( formatOptions->m_options & KoSearchContext::Italic);
2489 flags |=KoTextFormat::Italic;
2491 if ( formatOptions->m_optionsMask & KoSearchContext::WordByWord)
2493 format->setWordByWord( formatOptions->m_options & KoSearchContext::WordByWord );
2494 flags |=KoTextFormat::WordByWord;
2496 if ( formatOptions->m_optionsMask & KoSearchContext::Shadow)
2498 if ( formatOptions->m_options & KoSearchContext::Shadow )
2499 format->setShadow( 1, 1, TQt::gray );
2501 format->setShadow( 0, 0, TQColor() );
2502 flags |=KoTextFormat::ShadowText;
2505 if ( formatOptions->m_optionsMask & KoSearchContext::Underline)
2507 format->setUnderlineType(formatOptions->m_underline);
2508 flags |=KoTextFormat::ExtendUnderLine;
2510 if ( formatOptions->m_optionsMask & KoSearchContext::StrikeOut)
2512 format->setStrikeOutType(formatOptions->m_strikeOut);
2513 flags |= KoTextFormat::StrikeOut;
2515 if ( formatOptions->m_optionsMask & KoSearchContext::VertAlign)
2517 format->setVAlign(formatOptions->m_vertAlign);
2518 flags |=KoTextFormat::VAlign;
2520 if ( formatOptions->m_optionsMask & KoSearchContext::Attribute)
2522 format->setAttributeFont(formatOptions->m_attribute);
2523 flags |= KoTextFormat::Attribute;
2525 if (formatOptions->m_optionsMask & KoSearchContext::Language)
2527 flags |= KoTextFormat::Language;
2528 format->setLanguage( formatOptions->m_language );
2533#include "KoAutoFormat.moc"
A CustomItemsMap associates a custom item to an index Used in the undo/redo info for insert/delete te...
void addCommand(KCommand *command)
The KOffice document class.
This is the structure associated with a paragraph (KoTextParag), to define the bullet or numbering of...
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.
A KoVariable is a custom item, i.e.
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)