21#include "KoAutoFormatDia.h"
22#include "KoAutoFormat.h"
23#include "KoCharSelectDia.h"
24#include <KoSearchDia.h>
27#include <tdemessagebox.h>
28#include <tdelistview.h>
29#include <kstandarddirs.h>
32#include <tqwhatsthis.h>
33#include <tqcheckbox.h>
34#include <tqpushbutton.h>
36#include <tqcombobox.h>
38#include <tqapplication.h>
40KoAutoFormatLineEdit::KoAutoFormatLineEdit ( TQWidget * parent,
const char * name )
41 : TQLineEdit(parent,
name)
45void KoAutoFormatLineEdit::keyPressEvent ( TQKeyEvent *ke )
47 if( ke->key() == TQt::Key_Return ||
48 ke->key() == TQt::Key_Enter )
50 emit keyReturnPressed();
53 TQLineEdit::keyPressEvent (ke);
61KoAutoFormatExceptionWidget::KoAutoFormatExceptionWidget(TQWidget *parent,
const TQString &name,
const TQStringList &_list,
bool _autoInclude,
bool _abreviation)
64 m_bAbbreviation=_abreviation;
65 m_listException=_list;
68 TQLabel *lab=
new TQLabel(name,
this);
69 grid->addMultiCellWidget(lab,0,0,0,1);
71 exceptionLine =
new KoAutoFormatLineEdit(
this );
72 grid->addWidget(exceptionLine,1,0);
74 connect(exceptionLine,TQ_SIGNAL(keyReturnPressed()),TQ_SLOT(slotAddException()));
75 connect(exceptionLine ,TQ_SIGNAL(textChanged (
const TQString & )),
76 TQ_SLOT(textChanged (
const TQString & )));
78 pbAddException=
new TQPushButton(i18n(
"Add"),
this);
79 connect(pbAddException, TQ_SIGNAL(clicked()),TQ_SLOT(slotAddException()));
80 grid->addWidget(pbAddException,1,1);
82 pbAddException->setEnabled(
false);
84 pbRemoveException=
new TQPushButton(i18n(
"Remove"),
this);
85 connect(pbRemoveException, TQ_SIGNAL(clicked()),TQ_SLOT(slotRemoveException()));
86 grid->addWidget(pbRemoveException,2,1,TQt::AlignTop);
88 exceptionList=
new TQListBox(
this);
89 exceptionList->insertStringList(m_listException);
90 exceptionList->sort();
91 grid->addWidget(exceptionList,2,0);
93 grid->setRowStretch( 2, 1 );
95 connect( exceptionList , TQ_SIGNAL(selectionChanged () ),
96 this,TQ_SLOT(slotExceptionListSelected()) );
98 pbRemoveException->setEnabled( exceptionList->currentItem()!=-1);
100 cbAutoInclude =
new TQCheckBox( i18n(
"Autoinclude"),
this );
101 grid->addWidget(cbAutoInclude,3,0);
102 cbAutoInclude->setChecked( _autoInclude );
105void KoAutoFormatExceptionWidget::textChanged (
const TQString &_text )
107 pbAddException->setEnabled(!_text.isEmpty());
110void KoAutoFormatExceptionWidget::slotAddException()
112 TQString text=exceptionLine->text().stripWhiteSpace();
115 if(text.at(text.length()-1)!=
'.' && m_bAbbreviation)
117 if( m_listException.findIndex( text )==-1)
119 m_listException<<text;
121 exceptionList->clear();
122 exceptionList->insertStringList(m_listException);
123 exceptionList->sort();
124 pbRemoveException->setEnabled( exceptionList->currentItem()!=-1);
125 pbAddException->setEnabled(
false);
127 exceptionLine->clear();
131void KoAutoFormatExceptionWidget::slotRemoveException()
133 if(!exceptionList->currentText().isEmpty())
135 m_listException.remove(exceptionList->currentText());
136 exceptionList->clear();
137 pbAddException->setEnabled(
false);
138 pbRemoveException->setEnabled( exceptionList->currentItem()!=-1);
139 exceptionList->insertStringList(m_listException);
140 exceptionLine->clear();
144bool KoAutoFormatExceptionWidget::autoInclude()
146 return cbAutoInclude->isChecked();
149void KoAutoFormatExceptionWidget::setListException(
const TQStringList &list)
151 exceptionList->clear();
152 exceptionList->insertStringList(list);
155void KoAutoFormatExceptionWidget::setAutoInclude(
bool b)
157 cbAutoInclude->setChecked( b );
160void KoAutoFormatExceptionWidget::slotExceptionListSelected()
162 pbRemoveException->setEnabled( exceptionList->currentItem()!=-1 );
169KoAutoFormatDia::KoAutoFormatDia( TQWidget *parent,
const char *name,
170 KoAutoFormat * autoFormat )
171 :
KDialogBase( Tabbed, i18n(
"Autocorrection"), Ok | Cancel | User1, Ok,
172 parent,
name, true, true,
KGuiItem( i18n(
"&Reset" ),
"edit-undo" )),
173 oSimpleBegin( autoFormat->getConfigTypographicSimpleQuotes().begin ),
174 oSimpleEnd( autoFormat->getConfigTypographicSimpleQuotes().end ),
175 oDoubleBegin( autoFormat->getConfigTypographicDoubleQuotes().begin ),
176 oDoubleEnd( autoFormat->getConfigTypographicDoubleQuotes().end ),
177 bulletStyle( autoFormat->getConfigBulletStyle()),
178 m_autoFormat( *autoFormat ),
179 m_docAutoFormat( autoFormat )
183 autocorrectionEntryChanged=
false;
184 changeLanguage =
false;
190 setInitialSize( TQSize(500, 300) );
191 connect(
this, TQ_SIGNAL( user1Clicked() ),
this, TQ_SLOT(slotResetConf()));
195KoAutoFormatDia::~KoAutoFormatDia()
200void KoAutoFormatDia::slotResetConf()
220void KoAutoFormatDia::setupTab1()
222 tab1 =
addPage( i18n(
"Simple Autocorrection" ) );
225 cbUpperCase =
new TQCheckBox( tab1 );
226 cbUpperCase->setText( i18n(
227 "Convert &first letter of a sentence automatically to uppercase\n"
228 "(e.g. \"my house. in this town\" to \"my house. In this town\")"
230 TQWhatsThis::add( cbUpperCase, i18n(
231 "Detect when a new sentence is started and always ensure that"
232 " the first character is an uppercase character."));
234 vbox->addWidget(cbUpperCase);
237 cbUpperUpper =
new TQCheckBox( tab1 );
238 cbUpperUpper->setText( i18n(
239 "Convert &two uppercase characters to one uppercase and one"
240 " lowercase character\n (e.g. PErfect to Perfect)" ) );
241 TQWhatsThis::add( cbUpperUpper, i18n(
242 "All words are checked for the common mistake of holding the "
243 "shift key down a bit too long. If some words must have two "
244 "uppercase characters, then those exceptions should be added in "
245 "the 'Exceptions' tab."));
247 vbox->addWidget(cbUpperUpper);
249 cbDetectUrl=
new TQCheckBox( tab1 );
250 cbDetectUrl->setText( i18n(
"Autoformat &URLs" ) );
251 TQWhatsThis::add( cbDetectUrl, i18n(
252 "Detect when a URL (Uniform Resource Locator) is typed and "
253 "provide formatting that matches the way an Internet browser "
254 "would show a URL."));
256 vbox->addWidget(cbDetectUrl);
258 cbIgnoreDoubleSpace=
new TQCheckBox( tab1 );
259 cbIgnoreDoubleSpace->setText( i18n(
"&Suppress double spaces" ) );
260 TQWhatsThis::add( cbIgnoreDoubleSpace, i18n(
261 "Make sure that more than one space cannot be typed, as this is a "
262 "common mistake which is quite hard to find in formatted text."));
264 vbox->addWidget(cbIgnoreDoubleSpace);
266 cbRemoveSpaceBeginEndLine=
new TQCheckBox( tab1 );
267 cbRemoveSpaceBeginEndLine->setText( i18n(
268 "R&emove spaces at the beginning and end of paragraphs" ) );
269 TQWhatsThis::add( cbRemoveSpaceBeginEndLine, i18n(
270 "Keep correct formatting and indenting of sentences by "
271 "automatically removing spaces typed at the beginning and end of "
274 vbox->addWidget(cbRemoveSpaceBeginEndLine);
276 cbAutoChangeFormat=
new TQCheckBox( tab1 );
277 cbAutoChangeFormat->setText( i18n(
278 "Automatically do &bold and underline formatting") );
279 TQWhatsThis::add( cbAutoChangeFormat, i18n(
280 "When you use _underline_ or *bold*, the text between the "
281 "underscores or asterisks will be converted to underlined or "
284 vbox->addWidget(cbAutoChangeFormat);
286 cbAutoReplaceNumber=
new TQCheckBox( tab1 );
287 cbAutoReplaceNumber->setText( i18n(
288 "We add the 1/2 char at the %1",
"Re&place 1/2... with %1..." )
289 .arg( TQString(
"½" ) ) );
290 TQWhatsThis::add( cbAutoReplaceNumber, i18n(
291 "Most standard fraction notations will be converted when available"
294 vbox->addWidget(cbAutoReplaceNumber);
296 cbUseNumberStyle=
new TQCheckBox( tab1 );
297 cbUseNumberStyle->setText( i18n(
298 "Use &autonumbering for numbered paragraphs" ) );
299 TQWhatsThis::add( cbUseNumberStyle, i18n(
300 "When typing '1)' or similar in front of a paragraph, "
301 "automatically convert the paragraph to use that numbering style. "
302 "This has the advantage that further paragraphs will also be "
303 "numbered and the spacing is done correctly.") );
305 vbox->addWidget(cbUseNumberStyle);
307 cbAutoSuperScript =
new TQCheckBox( tab1 );
308 cbAutoSuperScript->setText( i18n(
"Rep&lace 1st... with 1^st..."));
309 cbAutoSuperScript->setEnabled( m_docAutoFormat->nbSuperScriptEntry()>0 );
311 vbox->addWidget(cbAutoSuperScript);
312 cbCapitalizeDaysName =
new TQCheckBox( tab1 );
313 cbCapitalizeDaysName->setText( i18n(
"Capitalize name of days"));
314 vbox->addWidget(cbCapitalizeDaysName);
316 cbUseBulletStyle=
new TQCheckBox( tab1 );
317 cbUseBulletStyle->setText( i18n(
318 "Use l&ist-formatting for bulleted paragraphs" ) );
319 TQWhatsThis::add( cbUseBulletStyle, i18n(
320 "When typing '*' or '-' in front of a paragraph, automatically "
321 "convert the paragraph to use that list-style. Using a list-style "
322 "formatting means that a correct bullet is used to draw the list."
325 connect( cbUseBulletStyle, TQ_SIGNAL( toggled(
bool ) ),
326 TQ_SLOT( slotBulletStyleToggled(
bool ) ) );
328 vbox->addWidget(cbUseBulletStyle);
329 TQHBoxLayout *hbox =
new TQHBoxLayout();
331 hbox->addSpacing( 20 );
333 pbBulletStyle =
new TQPushButton( tab1 );
334 pbBulletStyle->setFixedSize( pbBulletStyle->sizeHint() );
335 hbox->addWidget( pbBulletStyle );
336 pbDefaultBulletStyle =
new TQPushButton( tab1 );
337 pbDefaultBulletStyle->setText(i18n(
"Default"));
338 pbDefaultBulletStyle->setFixedSize( pbDefaultBulletStyle->sizeHint() );
339 hbox->addWidget( pbDefaultBulletStyle );
341 hbox->addStretch( 1 );
344 vbox->addStretch( 1 );
348 connect( pbBulletStyle, TQ_SIGNAL( clicked() ), TQ_SLOT( chooseBulletStyle() ) );
349 connect( pbDefaultBulletStyle, TQ_SIGNAL( clicked()),
350 TQ_SLOT( defaultBulletStyle() ) );
353void KoAutoFormatDia::initTab1()
355 cbUpperCase->setChecked( m_autoFormat.getConfigUpperCase() );
356 cbUpperUpper->setChecked( m_autoFormat.getConfigUpperUpper() );
357 cbDetectUrl->setChecked( m_autoFormat.getConfigAutoDetectUrl());
358 cbIgnoreDoubleSpace->setChecked( m_autoFormat.getConfigIgnoreDoubleSpace());
359 cbRemoveSpaceBeginEndLine->setChecked( m_autoFormat.getConfigRemoveSpaceBeginEndLine());
360 cbAutoChangeFormat->setChecked( m_autoFormat.getConfigAutoChangeFormat());
361 cbAutoReplaceNumber->setChecked( m_autoFormat.getConfigAutoReplaceNumber());
362 cbUseNumberStyle->setChecked( m_autoFormat.getConfigAutoNumberStyle());
363 cbUseBulletStyle->setChecked( m_autoFormat.getConfigUseBulletSyle());
364 cbAutoSuperScript->setChecked( m_docAutoFormat->getConfigAutoSuperScript());
365 pbBulletStyle->setText( bulletStyle );
366 cbCapitalizeDaysName->setChecked( m_autoFormat.getConfigCapitalizeNameOfDays());
368 slotBulletStyleToggled( cbUseBulletStyle->isChecked() );
371void KoAutoFormatDia::slotBulletStyleToggled(
bool b )
373 pbBulletStyle->setEnabled( b );
374 pbDefaultBulletStyle->setEnabled( b );
377void KoAutoFormatDia::setupTab2()
379 tab2 =
addPage( i18n(
"Custom Quotes" ) );
383 cbTypographicDoubleQuotes =
new TQCheckBox( tab2 );
384 cbTypographicDoubleQuotes->setText( i18n(
385 "Replace &double quotes with typographical quotes" ) );
387 connect( cbTypographicDoubleQuotes,TQ_SIGNAL(toggled (
bool)),
388 TQ_SLOT(slotChangeStateDouble(
bool)));
390 vbox->addWidget( cbTypographicDoubleQuotes );
392 TQHBoxLayout *hbox =
new TQHBoxLayout( );
393 hbox->addSpacing( 20 );
395 pbDoubleQuote1 =
new TQPushButton( tab2 );
396 pbDoubleQuote1->setFixedSize( pbDoubleQuote1->sizeHint() );
398 pbDoubleQuote2 =
new TQPushButton( tab2 );
399 pbDoubleQuote2->setFixedSize( pbDoubleQuote2->sizeHint() );
401 if (TQApplication::reverseLayout()) {
402 hbox->addWidget( pbDoubleQuote2 );
403 hbox->addWidget( pbDoubleQuote1 );
405 hbox->addWidget( pbDoubleQuote1 );
406 hbox->addWidget( pbDoubleQuote2 );
411 pbDoubleDefault =
new TQPushButton( tab2 );
412 pbDoubleDefault->setText(i18n(
"Default"));
413 pbDoubleDefault->setFixedSize( pbDoubleDefault->sizeHint() );
414 hbox->addWidget( pbDoubleDefault );
416 hbox->addStretch( 1 );
418 connect(pbDoubleQuote1, TQ_SIGNAL( clicked() ), TQ_SLOT( chooseDoubleQuote1() ));
419 connect(pbDoubleQuote2, TQ_SIGNAL( clicked() ), TQ_SLOT( chooseDoubleQuote2() ));
420 connect(pbDoubleDefault, TQ_SIGNAL( clicked()), TQ_SLOT( defaultDoubleQuote() ));
422 vbox->addItem( hbox );
424 cbTypographicSimpleQuotes =
new TQCheckBox( tab2 );
425 cbTypographicSimpleQuotes->setText( i18n(
426 "Replace &single quotes with typographical quotes" ) );
428 connect( cbTypographicSimpleQuotes,TQ_SIGNAL(toggled (
bool)),
429 TQ_SLOT(slotChangeStateSimple(
bool)));
431 vbox->addWidget( cbTypographicSimpleQuotes );
433 hbox =
new TQHBoxLayout( );
434 hbox->addSpacing( 20 );
436 pbSimpleQuote1 =
new TQPushButton( tab2 );
437 pbSimpleQuote1->setFixedSize( pbSimpleQuote1->sizeHint() );
439 pbSimpleQuote2 =
new TQPushButton( tab2 );
440 pbSimpleQuote2->setFixedSize( pbSimpleQuote2->sizeHint() );
442 if (TQApplication::reverseLayout()) {
443 hbox->addWidget( pbSimpleQuote2 );
444 hbox->addWidget( pbSimpleQuote1 );
446 hbox->addWidget( pbSimpleQuote1 );
447 hbox->addWidget( pbSimpleQuote2 );
452 pbSimpleDefault =
new TQPushButton( tab2 );
453 pbSimpleDefault->setText(i18n(
"Default"));
454 pbSimpleDefault->setFixedSize( pbSimpleDefault->sizeHint() );
455 hbox->addWidget( pbSimpleDefault );
457 hbox->addStretch( 1 );
459 connect(pbSimpleQuote1, TQ_SIGNAL( clicked() ), TQ_SLOT( chooseSimpleQuote1() ));
460 connect(pbSimpleQuote2, TQ_SIGNAL( clicked() ), TQ_SLOT( chooseSimpleQuote2() ));
461 connect(pbSimpleDefault, TQ_SIGNAL( clicked()), TQ_SLOT( defaultSimpleQuote() ));
463 vbox->addItem( hbox );
464 vbox->addStretch( 1 );
469void KoAutoFormatDia::initTab2()
471 bool state=m_autoFormat.getConfigTypographicDoubleQuotes().replace;
472 cbTypographicDoubleQuotes->setChecked( state );
473 pbDoubleQuote1->setText( oDoubleBegin );
474 pbDoubleQuote2->setText(oDoubleEnd );
475 slotChangeStateDouble(state);
477 state=m_autoFormat.getConfigTypographicSimpleQuotes().replace;
478 cbTypographicSimpleQuotes->setChecked( state );
479 pbSimpleQuote1->setText( oSimpleBegin );
480 pbSimpleQuote2->setText(oSimpleEnd );
481 slotChangeStateSimple(state);
485void KoAutoFormatDia::setupTab3()
487 tab3 =
addPage( i18n(
"Advanced Autocorrection" ) );
489 TQLabel *lblFind, *lblReplace;
493 autoFormatLanguage =
new TQComboBox(tab3);
496 lst<<i18n(
"Default");
497 lst<<i18n(
"All Languages");
498 exceptionLanguageName.insert( i18n(
"Default"),
"");
499 exceptionLanguageName.insert( i18n(
"All Languages"),
"all_languages");
501 TDEStandardDirs *standard =
new TDEStandardDirs();
502 TQStringList tmp = standard->findDirs(
"data",
"koffice/autocorrect/");
503 TQString path = *(tmp.end());
504 for ( TQStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it )
510 tmp =dir.entryList (TQDir::Files);
511 for ( TQStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it )
513 if ( !(*it).contains(
"autocorrect"))
515 TQString readableName = TDEGlobal::locale()->twoAlphaToCountryName((*it).left((*it).length()-4));
517 if ( readableName.isEmpty() )
518 tmp =(*it).left((*it).length()-4);
521 exceptionLanguageName.insert( tmp, (*it).left((*it).length()-4));
525 autoFormatLanguage->insertStringList(lst);
527 connect(autoFormatLanguage->listBox(), TQ_SIGNAL(selected (
const TQString & )),
this, TQ_SLOT(changeAutoformatLanguage(
const TQString & )));
529 grid->addMultiCellWidget( autoFormatLanguage, 0, 0, 4, 6 );
530 TQLabel *lblAutoFormatLanguage =
new TQLabel( i18n(
"Replacements and exceptions for language:"), tab3);
531 grid->addMultiCellWidget( lblAutoFormatLanguage, 0, 0, 0, 3 );
533 cbAdvancedAutoCorrection =
new TQCheckBox( tab3 );
534 cbAdvancedAutoCorrection->setText( i18n(
"Enable word replacement") );
535 connect( cbAdvancedAutoCorrection, TQ_SIGNAL(clicked ()),
this, TQ_SLOT( slotChangeAdvancedAutoCorrection()));
536 grid->addMultiCellWidget( cbAdvancedAutoCorrection, 1, 1, 0, 6 );
538 cbAutoCorrectionWithFormat =
new TQCheckBox( tab3 );
539 cbAutoCorrectionWithFormat->setText( i18n(
"Replace text with format") );
540 grid->addMultiCellWidget( cbAutoCorrectionWithFormat, 2, 2, 0, 6 );
542 lblFind =
new TQLabel( i18n(
"&Find:" ), tab3 );
543 grid->addWidget( lblFind, 3, 0 );
545 m_find =
new KoAutoFormatLineEdit( tab3 );
546 grid->addWidget( m_find, 3, 1 );
548 lblFind->setBuddy( m_find );
550 connect( m_find, TQ_SIGNAL( textChanged(
const TQString & ) ),
551 TQ_SLOT( slotfind(
const TQString & ) ) );
552 connect( m_find, TQ_SIGNAL( keyReturnPressed() ),
553 TQ_SLOT( slotAddEntry()));
555 pbSpecialChar1 =
new TQPushButton(
"...", tab3 );
556 TQToolTip::add( pbSpecialChar1, i18n(
"Insert a special character..." ) );
557 pbSpecialChar1->setFixedWidth( 40 );
558 grid->addWidget( pbSpecialChar1, 3, 2 );
560 connect(pbSpecialChar1,TQ_SIGNAL(clicked()), TQ_SLOT(chooseSpecialChar1()));
562 lblReplace =
new TQLabel( i18n(
"&Replace:" ), tab3 );
563 grid->addWidget( lblReplace, 3, 3 );
565 m_replace =
new KoAutoFormatLineEdit( tab3 );
566 grid->addWidget( m_replace, 3, 4 );
568 lblReplace->setBuddy( m_replace );
570 connect( m_replace, TQ_SIGNAL( textChanged(
const TQString & ) ),
571 TQ_SLOT( slotfind2(
const TQString & ) ) );
572 connect( m_replace, TQ_SIGNAL( keyReturnPressed() ),
573 TQ_SLOT( slotAddEntry()));
575 pbSpecialChar2 =
new TQPushButton(
"...", tab3 );
576 TQToolTip::add( pbSpecialChar2, i18n(
"Insert a special character..." ) );
577 pbSpecialChar2->setFixedWidth( 40 );
578 grid->addWidget( pbSpecialChar2, 3, 5 );
580 connect(pbSpecialChar2,TQ_SIGNAL(clicked()), TQ_SLOT(chooseSpecialChar2()));
582 pbAdd =
new TQPushButton( i18n(
"&Add"), tab3 );
583 grid->addWidget( pbAdd, 3, 6 );
585 connect(pbAdd,TQ_SIGNAL(clicked()),
this, TQ_SLOT(slotAddEntry()));
587 m_pListView =
new TDEListView( tab3 );
588 m_pListView->addColumn( i18n(
"Find" ) );
589 m_pListView->addColumn( i18n(
"Replace" ) );
590 m_pListView->setAllColumnsShowFocus(
true );
591 grid->addMultiCellWidget( m_pListView, 4, 10, 0, 5 );
593 connect(m_pListView, TQ_SIGNAL(doubleClicked ( TQListViewItem * )),
594 TQ_SLOT(slotChangeTextFormatEntry()) );
595 connect(m_pListView, TQ_SIGNAL(clicked ( TQListViewItem * ) ),
596 TQ_SLOT(slotEditEntry()) );
598 pbRemove =
new TQPushButton( i18n(
"Remove" ), tab3 );
599 grid->addWidget( pbRemove, 4, 6, TQt::AlignTop );
601 connect(pbRemove,TQ_SIGNAL(clicked()), TQ_SLOT(slotRemoveEntry()));
603 pbChangeFormat=
new TQPushButton( i18n(
"Change Format..." ), tab3 );
604 grid->addWidget( pbChangeFormat, 5, 6, TQt::AlignTop );
606 connect( pbChangeFormat, TQ_SIGNAL(clicked()), TQ_SLOT(slotChangeTextFormatEntry()));
608 pbClearFormat=
new TQPushButton( i18n(
"Clear Format" ), tab3 );
609 grid->addWidget( pbClearFormat, 6, 6, TQt::AlignTop );
611 connect( pbClearFormat, TQ_SIGNAL(clicked()), TQ_SLOT(slotClearTextFormatEntry()));
612 grid->setRowStretch( 10, 1 );
615 slotChangeAdvancedAutoCorrection();
616 pbRemove->setEnabled(
false);
617 pbChangeFormat->setEnabled(
false );
618 pbAdd->setEnabled(
false);
619 pbClearFormat->setEnabled(
false);
623void KoAutoFormatDia::initTab3()
625 if ( !changeLanguage || noSignal)
627 initialLanguage=m_autoFormat.getConfigAutoFormatLanguage( );
628 if ( initialLanguage.isEmpty() )
629 autoFormatLanguage->setCurrentItem(0);
632 KoExceptionLanguageName::Iterator it = exceptionLanguageName.begin();
633 for ( ; it != exceptionLanguageName.end() ; ++it )
635 if ( it.data() == initialLanguage)
637 autoFormatLanguage->setCurrentText(it.key());
645 if ( autocorrectionEntryChanged )
647 if ( !changeLanguage )
648 m_docAutoFormat->configAutoFormatLanguage( initialLanguage);
649 m_docAutoFormat->readConfig(
true );
651 cbAdvancedAutoCorrection->setChecked(m_autoFormat.getConfigAdvancedAutoCorrect());
652 cbAutoCorrectionWithFormat->setChecked( m_autoFormat.getConfigCorrectionWithFormat());
653 m_pListView->clear();
655 TQDictIterator<KoAutoFormatEntry> it( m_docAutoFormat->getAutoFormatEntries());
656 for( ; it.current(); ++it )
658 ( void )
new TQListViewItem( m_pListView, it.currentKey(), it.current()->replace() );
662void KoAutoFormatDia::slotChangeAdvancedAutoCorrection()
664 bool state = cbAdvancedAutoCorrection->isChecked();
665 cbAutoCorrectionWithFormat->setEnabled( state );
666 pbSpecialChar2->setEnabled( state );
667 pbSpecialChar1->setEnabled( state );
668 m_replace->setEnabled( state);
669 m_find->setEnabled( state);
670 m_pListView->setEnabled( state);
672 state = state && !m_replace->text().isEmpty() && !m_find->text().isEmpty();
673 KoAutoFormatEntry * entry=m_docAutoFormat->findFormatEntry(m_find->text());
674 pbRemove->setEnabled(state && entry);
675 pbChangeFormat->setEnabled(state && entry);
676 pbClearFormat->setEnabled(state && entry);
677 pbAdd->setEnabled(state);
681void KoAutoFormatDia::changeAutoformatLanguage(
const TQString & text)
683 if ( text==i18n(
"Default"))
684 m_docAutoFormat->configAutoFormatLanguage( TQString());
687 m_docAutoFormat->configAutoFormatLanguage( exceptionLanguageName.find(text).data());
692 m_docAutoFormat->readConfig(
true );
695 autocorrectionEntryChanged=
true;
696 cbAutoSuperScript->setEnabled( m_docAutoFormat->nbSuperScriptEntry()>0 );
697 oSimpleBegin= m_docAutoFormat->getConfigTypographicSimpleQuotes().begin ;
698 oSimpleEnd= m_docAutoFormat->getConfigTypographicSimpleQuotes().end;
699 oDoubleBegin= m_docAutoFormat->getConfigTypographicDoubleQuotes().begin;
700 oDoubleEnd= m_docAutoFormat->getConfigTypographicDoubleQuotes().end;
701 bulletStyle= m_docAutoFormat->getConfigBulletStyle();
704 changeLanguage=
false;
708void KoAutoFormatDia::setupTab4()
710 tab4 =
addPage( i18n(
"Exceptions" ) );
713 abbreviation=
new KoAutoFormatExceptionWidget(tab4,
714 i18n(
"Do not treat as the end of a sentence:"),
715 m_autoFormat.listException(),
716 m_autoFormat.getConfigIncludeAbbreviation() ,
true);
718 vbox->addWidget( abbreviation );
720 twoUpperLetter=
new KoAutoFormatExceptionWidget(tab4,
721 i18n(
"Accept two uppercase letters in:"),
722 m_autoFormat.listTwoUpperLetterException(),
723 m_autoFormat.getConfigIncludeTwoUpperUpperLetterException());
725 vbox->addWidget( twoUpperLetter );
730void KoAutoFormatDia::initTab4()
732 abbreviation->setListException( !changeLanguage ? m_autoFormat.listException(): m_docAutoFormat->listException() );
733 if ( !changeLanguage )
735 abbreviation->setAutoInclude( m_docAutoFormat->getConfigIncludeAbbreviation() );
736 twoUpperLetter->setAutoInclude( m_docAutoFormat->getConfigIncludeTwoUpperUpperLetterException() );
738 twoUpperLetter->setListException( !changeLanguage ? m_autoFormat.listTwoUpperLetterException():m_docAutoFormat->listTwoUpperLetterException() );
741void KoAutoFormatDia::slotClearTextFormatEntry()
743 bool addNewEntry = (pbAdd->text() == i18n(
"&Add" ));
744 if ( m_pListView->currentItem() || addNewEntry)
749 newEntry->clearFormatEntryContext();
753 KoAutoFormatEntry *entry = m_docAutoFormat->findFormatEntry(m_pListView->currentItem()->text(0));
754 entry->clearFormatEntryContext();
756 autocorrectionEntryChanged=
true;
760void KoAutoFormatDia::slotChangeTextFormatEntry()
762 bool addNewEntry = (pbAdd->text() == i18n(
"&Add" ));
763 if ( m_pListView->currentItem() || addNewEntry)
765 KoAutoFormatEntry *entry = 0L;
768 if ( m_replace->text().isEmpty() )
771 newEntry =
new KoAutoFormatEntry( m_replace->text());
775 entry = m_docAutoFormat->findFormatEntry(m_pListView->currentItem()->text(0));
776 KoSearchContext *tmpFormat = entry->formatEntryContext();
777 bool createNewFormat =
false;
781 tmpFormat =
new KoSearchContext();
782 createNewFormat =
true;
785 KoFormatDia *dia =
new KoFormatDia(
this, i18n(
"Change Text Format"), tmpFormat , 0L);
789 if ( createNewFormat )
790 entry->setFormatEntryContext( tmpFormat );
791 autocorrectionEntryChanged=
true;
796 if ( createNewFormat )
803void KoAutoFormatDia::slotRemoveEntry()
806 if(m_pListView->currentItem())
808 m_docAutoFormat->removeAutoFormatEntry(m_pListView->currentItem()->text(0));
809 pbAdd->setText(i18n(
"&Add"));
811 autocorrectionEntryChanged=
true;
816void KoAutoFormatDia::slotfind(
const TQString & )
818 KoAutoFormatEntry *entry = m_docAutoFormat->findFormatEntry(m_find->text());
821 m_replace->setText(entry->replace().latin1());
822 pbAdd->setText(i18n(
"&Modify"));
823 m_pListView->setCurrentItem(m_pListView->findItem(m_find->text(),0));
827 pbAdd->setText(i18n(
"&Add"));
828 m_pListView->setCurrentItem(0L);
834void KoAutoFormatDia::slotfind2(
const TQString & )
836 bool state = !m_replace->text().isEmpty() && !m_find->text().isEmpty();
837 KoAutoFormatEntry * entry=m_docAutoFormat->findFormatEntry(m_find->text());
838 pbRemove->setEnabled(state && entry);
839 if ( state && entry )
844 pbChangeFormat->setEnabled(state);
845 pbClearFormat->setEnabled(state);
846 pbAdd->setEnabled(state);
850void KoAutoFormatDia::refreshEntryList()
852 m_pListView->clear();
853 TQDictIterator<KoAutoFormatEntry> it( m_docAutoFormat->getAutoFormatEntries());
854 for( ; it.current(); ++it )
856 ( void )
new TQListViewItem( m_pListView, it.currentKey(), it.current()->replace() );
858 m_pListView->setCurrentItem(m_pListView->firstChild ());
859 bool state = !(m_replace->text().isEmpty()) && !(m_find->text().isEmpty());
861 pbRemove->setEnabled(m_pListView->currentItem() && m_pListView->selectedItem()!=0 );
862 pbChangeFormat->setEnabled(state && m_pListView->currentItem() && m_pListView->selectedItem()!=0 );
863 pbClearFormat->setEnabled(state && m_pListView->currentItem() && m_pListView->selectedItem()!=0 );
865 pbAdd->setEnabled(state);
869void KoAutoFormatDia::addEntryList(
const TQString &key, KoAutoFormatEntry *_autoEntry)
871 m_docAutoFormat->addAutoFormatEntry( key, _autoEntry );
876void KoAutoFormatDia::editEntryList(
const TQString &key,
const TQString &newFindString, KoAutoFormatEntry *_autoEntry)
878 if ( m_docAutoFormat->findFormatEntry(key) && m_docAutoFormat->findFormatEntry(key)->formatEntryContext())
879 _autoEntry->setFormatEntryContext(
new KoSearchContext(*(m_docAutoFormat->findFormatEntry(key)->formatEntryContext()) ));
880 m_docAutoFormat->removeAutoFormatEntry( key );
881 m_docAutoFormat->addAutoFormatEntry( newFindString, _autoEntry );
885void KoAutoFormatDia::slotAddEntry()
887 if(!pbAdd->isEnabled())
889 TQString repl = m_replace->text();
891 if(repl.isEmpty() ||
find.isEmpty())
901 KoAutoFormatEntry *tmp =
new KoAutoFormatEntry( repl );
903 if(pbAdd->text() == i18n(
"&Add" ))
907 newEntry->changeReplace( m_replace->text());
908 addEntryList(find, newEntry);
913 addEntryList(find, tmp);
916 editEntryList(find, find, tmp);
921 autocorrectionEntryChanged=
true;
925void KoAutoFormatDia::chooseSpecialChar1()
927 TQString f = font().family();
929 bool const focus = m_find->hasFocus();
930 if ( KoCharSelectDia::selectChar( f, c,
false ) )
932 int const cursorpos = m_find->cursorPosition();
934 m_find->setText( m_find->text().insert( cursorpos, c ) );
936 m_find->setText( m_find->text().append(c) );
937 m_find->setCursorPosition( cursorpos+1 );
942void KoAutoFormatDia::chooseSpecialChar2()
944 TQString f = font().family();
946 bool const focus = m_replace->hasFocus();
947 if ( KoCharSelectDia::selectChar( f, c,
false ) )
949 int const cursorpos = m_replace->cursorPosition();
951 m_replace->setText( m_replace->text().insert(m_replace->cursorPosition(), c ) );
953 m_replace->setText( m_replace->text().append(c) );
954 m_replace->setCursorPosition( cursorpos+1 );
959void KoAutoFormatDia::slotItemRenamed(TQListViewItem *,
const TQString & ,
int )
966void KoAutoFormatDia::slotEditEntry()
968 if(m_pListView->currentItem()==0)
972 m_find->setText(m_pListView->currentItem()->text(0));
973 m_replace->setText(m_pListView->currentItem()->text(1));
974 bool state = !m_replace->text().isEmpty() && !m_find->text().isEmpty();
975 pbRemove->setEnabled(state);
976 pbChangeFormat->setEnabled( state );
977 pbClearFormat->setEnabled(state);
978 pbAdd->setEnabled(state);
982bool KoAutoFormatDia::applyConfig()
985 KoAutoFormat::TypographicQuotes tq = m_autoFormat.getConfigTypographicSimpleQuotes();
986 tq.replace = cbTypographicSimpleQuotes->isChecked();
987 tq.begin = pbSimpleQuote1->text()[ 0 ];
988 tq.end = pbSimpleQuote2->text()[ 0 ];
989 m_docAutoFormat->configTypographicSimpleQuotes( tq );
991 tq = m_autoFormat.getConfigTypographicDoubleQuotes();
992 tq.replace = cbTypographicDoubleQuotes->isChecked();
993 tq.begin = pbDoubleQuote1->text()[ 0 ];
994 tq.end = pbDoubleQuote2->text()[ 0 ];
995 m_docAutoFormat->configTypographicDoubleQuotes( tq );
998 m_docAutoFormat->configUpperCase( cbUpperCase->isChecked() );
999 m_docAutoFormat->configUpperUpper( cbUpperUpper->isChecked() );
1000 m_docAutoFormat->configAutoDetectUrl( cbDetectUrl->isChecked() );
1002 m_docAutoFormat->configIgnoreDoubleSpace( cbIgnoreDoubleSpace->isChecked());
1003 m_docAutoFormat->configRemoveSpaceBeginEndLine( cbRemoveSpaceBeginEndLine->isChecked());
1004 m_docAutoFormat->configUseBulletStyle(cbUseBulletStyle->isChecked());
1006 m_docAutoFormat->configBulletStyle(pbBulletStyle->text()[ 0 ]);
1008 m_docAutoFormat->configAutoChangeFormat( cbAutoChangeFormat->isChecked());
1010 m_docAutoFormat->configAutoReplaceNumber( cbAutoReplaceNumber->isChecked());
1011 m_docAutoFormat->configAutoNumberStyle(cbUseNumberStyle->isChecked());
1013 m_docAutoFormat->configAutoSuperScript ( cbAutoSuperScript->isChecked() );
1014 m_docAutoFormat->configCapitalizeNameOfDays( cbCapitalizeDaysName->isChecked());
1019 m_docAutoFormat->copyListException(abbreviation->getListException());
1020 m_docAutoFormat->copyListTwoUpperCaseException(twoUpperLetter->getListException());
1021 m_docAutoFormat->configAdvancedAutocorrect( cbAdvancedAutoCorrection->isChecked() );
1022 m_docAutoFormat->configCorrectionWithFormat( cbAutoCorrectionWithFormat->isChecked());
1024 m_docAutoFormat->configIncludeTwoUpperUpperLetterException( twoUpperLetter->autoInclude());
1025 m_docAutoFormat->configIncludeAbbreviation( abbreviation->autoInclude());
1027 TQString lang = exceptionLanguageName.find(autoFormatLanguage->currentText()).data();
1028 if ( lang == i18n(
"Default") )
1029 m_docAutoFormat->configAutoFormatLanguage(TQString());
1031 m_docAutoFormat->configAutoFormatLanguage(lang);
1034 m_docAutoFormat->saveConfig();
1049 if ( autocorrectionEntryChanged )
1051 m_docAutoFormat->configAutoFormatLanguage( initialLanguage);
1052 m_docAutoFormat->readConfig(
true );
1057void KoAutoFormatDia::chooseDoubleQuote1()
1059 TQString f = font().family();
1060 TQChar c = oDoubleBegin;
1061 if ( KoCharSelectDia::selectChar( f, c,
false ) )
1063 pbDoubleQuote1->setText( c );
1068void KoAutoFormatDia::chooseDoubleQuote2()
1070 TQString f = font().family();
1071 TQChar c = oDoubleEnd;
1072 if ( KoCharSelectDia::selectChar( f, c,
false ) )
1074 pbDoubleQuote2->setText( c );
1079void KoAutoFormatDia::defaultDoubleQuote()
1081 pbDoubleQuote1->setText(m_docAutoFormat->getDefaultTypographicDoubleQuotes().begin);
1082 pbDoubleQuote2->setText(m_docAutoFormat->getDefaultTypographicDoubleQuotes().end);
1085void KoAutoFormatDia::chooseSimpleQuote1()
1087 TQString f = font().family();
1088 TQChar c = oSimpleBegin;
1089 if ( KoCharSelectDia::selectChar( f, c,
false ) )
1091 pbSimpleQuote1->setText( c );
1095void KoAutoFormatDia::chooseSimpleQuote2()
1097 TQString f = font().family();
1098 TQChar c = oSimpleEnd;
1099 if ( KoCharSelectDia::selectChar( f, c,
false ) )
1101 pbSimpleQuote2->setText( c );
1105void KoAutoFormatDia::defaultSimpleQuote()
1108 pbSimpleQuote1->setText(m_docAutoFormat->getDefaultTypographicSimpleQuotes().begin);
1109 pbSimpleQuote2->setText(m_docAutoFormat->getDefaultTypographicSimpleQuotes().end);
1113void KoAutoFormatDia::chooseBulletStyle()
1115 TQString f = font().family();
1116 TQChar c = bulletStyle;
1117 if ( KoCharSelectDia::selectChar( f, c,
false ) )
1119 pbBulletStyle->setText( c );
1123void KoAutoFormatDia::defaultBulletStyle()
1125 pbBulletStyle->setText(
"" );
1128void KoAutoFormatDia::slotChangeStateSimple(
bool b)
1130 pbSimpleQuote1->setEnabled(b);
1131 pbSimpleQuote2->setEnabled(b);
1132 pbSimpleDefault->setEnabled(b);
1135void KoAutoFormatDia::slotChangeStateDouble(
bool b)
1137 pbDoubleQuote1->setEnabled(b);
1138 pbDoubleQuote2->setEnabled(b);
1139 pbDoubleDefault->setEnabled(b);
1142#include "KoAutoFormatDia.moc"
virtual void slotCancel()
int activePageIndex() const
TQFrame * addPage(const TQString &itemName, const TQString &header=TQString::null, const TQPixmap &pixmap=TQPixmap())
static void sorry(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, int options=Notify)
virtual TQString text() const
TDEAction * find(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
const char * name(StdAction id)