00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "KoAutoFormatDia.h"
00022 #include "KoAutoFormat.h"
00023 #include "KoCharSelectDia.h"
00024 #include <KoSearchDia.h>
00025
00026 #include <klocale.h>
00027 #include <kmessagebox.h>
00028 #include <klistview.h>
00029 #include <kstandarddirs.h>
00030
00031 #include <qlayout.h>
00032 #include <qwhatsthis.h>
00033 #include <qcheckbox.h>
00034 #include <qpushbutton.h>
00035 #include <qtooltip.h>
00036 #include <qcombobox.h>
00037 #include <qdir.h>
00038 #include <qapplication.h>
00039
00040 KoAutoFormatLineEdit::KoAutoFormatLineEdit ( QWidget * parent, const char * name )
00041 : QLineEdit(parent,name)
00042 {
00043 }
00044
00045 void KoAutoFormatLineEdit::keyPressEvent ( QKeyEvent *ke )
00046 {
00047 if( ke->key() == QKeyEvent::Key_Return ||
00048 ke->key() == QKeyEvent::Key_Enter )
00049 {
00050 emit keyReturnPressed();
00051 return;
00052 }
00053 QLineEdit::keyPressEvent (ke);
00054 }
00055
00056
00057
00058
00059
00060
00061 KoAutoFormatExceptionWidget::KoAutoFormatExceptionWidget(QWidget *parent, const QString &name,const QStringList &_list, bool _autoInclude, bool _abreviation)
00062 :QWidget( parent )
00063 {
00064 m_bAbbreviation=_abreviation;
00065 m_listException=_list;
00066 QGridLayout *grid = new QGridLayout(this, 4, 2, 0, KDialog::spacingHint());
00067
00068 QLabel *lab=new QLabel(name,this);
00069 grid->addMultiCellWidget(lab,0,0,0,1);
00070
00071 exceptionLine = new KoAutoFormatLineEdit( this );
00072 grid->addWidget(exceptionLine,1,0);
00073
00074 connect(exceptionLine,SIGNAL(keyReturnPressed()),SLOT(slotAddException()));
00075 connect(exceptionLine ,SIGNAL(textChanged ( const QString & )),
00076 SLOT(textChanged ( const QString & )));
00077
00078 pbAddException=new QPushButton(i18n("Add"),this);
00079 connect(pbAddException, SIGNAL(clicked()),SLOT(slotAddException()));
00080 grid->addWidget(pbAddException,1,1);
00081
00082 pbAddException->setEnabled(false);
00083
00084 pbRemoveException=new QPushButton(i18n("Remove"),this);
00085 connect(pbRemoveException, SIGNAL(clicked()),SLOT(slotRemoveException()));
00086 grid->addWidget(pbRemoveException,2,1,Qt::AlignTop);
00087
00088 exceptionList=new QListBox(this);
00089 exceptionList->insertStringList(m_listException);
00090 exceptionList->sort();
00091 grid->addWidget(exceptionList,2,0);
00092
00093 grid->setRowStretch( 2, 1 );
00094
00095 connect( exceptionList , SIGNAL(selectionChanged () ),
00096 this,SLOT(slotExceptionListSelected()) );
00097
00098 pbRemoveException->setEnabled( exceptionList->currentItem()!=-1);
00099
00100 cbAutoInclude = new QCheckBox( i18n("Autoinclude"), this );
00101 grid->addWidget(cbAutoInclude,3,0);
00102 cbAutoInclude->setChecked( _autoInclude );
00103 }
00104
00105 void KoAutoFormatExceptionWidget::textChanged ( const QString &_text )
00106 {
00107 pbAddException->setEnabled(!_text.isEmpty());
00108 }
00109
00110 void KoAutoFormatExceptionWidget::slotAddException()
00111 {
00112 QString text=exceptionLine->text().stripWhiteSpace();
00113 if(!text.isEmpty())
00114 {
00115 if(text.at(text.length()-1)!='.' && m_bAbbreviation)
00116 text=text+".";
00117 if( m_listException.findIndex( text )==-1)
00118 {
00119 m_listException<<text;
00120
00121 exceptionList->clear();
00122 exceptionList->insertStringList(m_listException);
00123 exceptionList->sort();
00124 pbRemoveException->setEnabled( exceptionList->currentItem()!=-1);
00125 pbAddException->setEnabled(false);
00126 }
00127 exceptionLine->clear();
00128 }
00129 }
00130
00131 void KoAutoFormatExceptionWidget::slotRemoveException()
00132 {
00133 if(!exceptionList->currentText().isEmpty())
00134 {
00135 m_listException.remove(exceptionList->currentText());
00136 exceptionList->clear();
00137 pbAddException->setEnabled(false);
00138 pbRemoveException->setEnabled( exceptionList->currentItem()!=-1);
00139 exceptionList->insertStringList(m_listException);
00140 exceptionLine->clear();
00141 }
00142 }
00143
00144 bool KoAutoFormatExceptionWidget::autoInclude()
00145 {
00146 return cbAutoInclude->isChecked();
00147 }
00148
00149 void KoAutoFormatExceptionWidget::setListException( const QStringList &list)
00150 {
00151 exceptionList->clear();
00152 exceptionList->insertStringList(list);
00153 }
00154
00155 void KoAutoFormatExceptionWidget::setAutoInclude(bool b)
00156 {
00157 cbAutoInclude->setChecked( b );
00158 }
00159
00160 void KoAutoFormatExceptionWidget::slotExceptionListSelected()
00161 {
00162 pbRemoveException->setEnabled( exceptionList->currentItem()!=-1 );
00163 }
00164
00165
00166
00167
00168
00169 KoAutoFormatDia::KoAutoFormatDia( QWidget *parent, const char *name,
00170 KoAutoFormat * autoFormat )
00171 : KDialogBase( Tabbed, i18n("Autocorrection"), Ok | Cancel | User1, Ok,
00172 parent, name, true, true, KGuiItem( i18n( "&Reset" ), "undo" )),
00173 oSimpleBegin( autoFormat->getConfigTypographicSimpleQuotes().begin ),
00174 oSimpleEnd( autoFormat->getConfigTypographicSimpleQuotes().end ),
00175 oDoubleBegin( autoFormat->getConfigTypographicDoubleQuotes().begin ),
00176 oDoubleEnd( autoFormat->getConfigTypographicDoubleQuotes().end ),
00177 bulletStyle( autoFormat->getConfigBulletStyle()),
00178 m_autoFormat( *autoFormat ),
00179 m_docAutoFormat( autoFormat )
00180 {
00181 noSignal=true;
00182 newEntry = 0L;
00183 autocorrectionEntryChanged= false;
00184 changeLanguage = false;
00185
00186 setupTab1();
00187 setupTab2();
00188 setupTab3();
00189 setupTab4();
00190 setInitialSize( QSize(500, 300) );
00191 connect( this, SIGNAL( user1Clicked() ), this, SLOT(slotResetConf()));
00192 noSignal=false;
00193 }
00194
00195 KoAutoFormatDia::~KoAutoFormatDia()
00196 {
00197 delete newEntry;
00198 }
00199
00200 void KoAutoFormatDia::slotResetConf()
00201 {
00202 switch( activePageIndex() ) {
00203 case 0:
00204 initTab1();
00205 break;
00206 case 1:
00207 initTab2();
00208 break;
00209 case 2:
00210 initTab3();
00211 break;
00212 case 3:
00213 initTab4();
00214 break;
00215 default:
00216 break;
00217 }
00218 }
00219
00220 void KoAutoFormatDia::setupTab1()
00221 {
00222 tab1 = addPage( i18n( "Simple Autocorrection" ) );
00223 QVBoxLayout *vbox = new QVBoxLayout(tab1, 0, KDialog::spacingHint());
00224
00225 cbUpperCase = new QCheckBox( tab1 );
00226 cbUpperCase->setText( i18n(
00227 "Convert &first letter of a sentence automatically to uppercase\n"
00228 "(e.g. \"my house. in this town\" to \"my house. In this town\")"
00229 ) );
00230 QWhatsThis::add( cbUpperCase, i18n(
00231 "Detect when a new sentence is started and always ensure that"
00232 " the first character is an uppercase character."));
00233
00234 vbox->addWidget(cbUpperCase);
00235
00236
00237 cbUpperUpper = new QCheckBox( tab1 );
00238 cbUpperUpper->setText( i18n(
00239 "Convert &two uppercase characters to one uppercase and one"
00240 " lowercase character\n (e.g. PErfect to Perfect)" ) );
00241 QWhatsThis::add( cbUpperUpper, i18n(
00242 "All words are checked for the common mistake of holding the "
00243 "shift key down a bit too long. If some words must have two "
00244 "uppercase characters, then those exceptions should be added in "
00245 "the 'Exceptions' tab."));
00246
00247 vbox->addWidget(cbUpperUpper);
00248
00249 cbDetectUrl=new QCheckBox( tab1 );
00250 cbDetectUrl->setText( i18n( "Autoformat &URLs" ) );
00251 QWhatsThis::add( cbDetectUrl, i18n(
00252 "Detect when a URL (Uniform Resource Locator) is typed and "
00253 "provide formatting that matches the way an Internet browser "
00254 "would show a URL."));
00255
00256 vbox->addWidget(cbDetectUrl);
00257
00258 cbIgnoreDoubleSpace=new QCheckBox( tab1 );
00259 cbIgnoreDoubleSpace->setText( i18n( "&Suppress double spaces" ) );
00260 QWhatsThis::add( cbIgnoreDoubleSpace, i18n(
00261 "Make sure that more than one space cannot be typed, as this is a "
00262 "common mistake which is quite hard to find in formatted text."));
00263
00264 vbox->addWidget(cbIgnoreDoubleSpace);
00265
00266 cbRemoveSpaceBeginEndLine=new QCheckBox( tab1 );
00267 cbRemoveSpaceBeginEndLine->setText( i18n(
00268 "R&emove spaces at the beginning and end of paragraphs" ) );
00269 QWhatsThis::add( cbRemoveSpaceBeginEndLine, i18n(
00270 "Keep correct formatting and indenting of sentences by "
00271 "automatically removing spaces typed at the beginning and end of "
00272 "a paragraph."));
00273
00274 vbox->addWidget(cbRemoveSpaceBeginEndLine);
00275
00276 cbAutoChangeFormat=new QCheckBox( tab1 );
00277 cbAutoChangeFormat->setText( i18n(
00278 "Automatically do &bold and underline formatting") );
00279 QWhatsThis::add( cbAutoChangeFormat, i18n(
00280 "When you use _underline_ or *bold*, the text between the "
00281 "underscores or asterisks will be converted to underlined or "
00282 "bold text.") );
00283
00284 vbox->addWidget(cbAutoChangeFormat);
00285
00286 cbAutoReplaceNumber=new QCheckBox( tab1 );
00287 cbAutoReplaceNumber->setText( i18n(
00288 "We add the 1/2 char at the %1", "Re&place 1/2... with %1..." )
00289 .arg( QString( "½" ) ) );
00290 QWhatsThis::add( cbAutoReplaceNumber, i18n(
00291 "Most standard fraction notations will be converted when available"
00292 ) );
00293
00294 vbox->addWidget(cbAutoReplaceNumber);
00295
00296 cbUseNumberStyle=new QCheckBox( tab1 );
00297 cbUseNumberStyle->setText( i18n(
00298 "Use &autonumbering for numbered paragraphs" ) );
00299 QWhatsThis::add( cbUseNumberStyle, i18n(
00300 "When typing '1)' or similar in front of a paragraph, "
00301 "automatically convert the paragraph to use that numbering style. "
00302 "This has the advantage that further paragraphs will also be "
00303 "numbered and the spacing is done correctly.") );
00304
00305 vbox->addWidget(cbUseNumberStyle);
00306
00307 cbAutoSuperScript = new QCheckBox( tab1 );
00308 cbAutoSuperScript->setText( i18n("Rep&lace 1st... with 1^st..."));
00309 cbAutoSuperScript->setEnabled( m_docAutoFormat->nbSuperScriptEntry()>0 );
00310
00311 vbox->addWidget(cbAutoSuperScript);
00312 cbCapitalizeDaysName = new QCheckBox( tab1 );
00313 cbCapitalizeDaysName->setText( i18n("Capitalize name of days"));
00314 vbox->addWidget(cbCapitalizeDaysName);
00315
00316 cbUseBulletStyle=new QCheckBox( tab1 );
00317 cbUseBulletStyle->setText( i18n(
00318 "Use l&ist-formatting for bulleted paragraphs" ) );
00319 QWhatsThis::add( cbUseBulletStyle, i18n(
00320 "When typing '*' or '-' in front of a paragraph, automatically "
00321 "convert the paragraph to use that list-style. Using a list-style "
00322 "formatting means that a correct bullet is used to draw the list."
00323 ) );
00324
00325 connect( cbUseBulletStyle, SIGNAL( toggled( bool ) ),
00326 SLOT( slotBulletStyleToggled( bool ) ) );
00327
00328 vbox->addWidget(cbUseBulletStyle);
00329 QHBoxLayout *hbox = new QHBoxLayout();
00330
00331 hbox->addSpacing( 20 );
00332 hbox->setSpacing(KDialog::spacingHint());
00333 pbBulletStyle = new QPushButton( tab1 );
00334 pbBulletStyle->setFixedSize( pbBulletStyle->sizeHint() );
00335 hbox->addWidget( pbBulletStyle );
00336 pbDefaultBulletStyle = new QPushButton( tab1 );
00337 pbDefaultBulletStyle->setText(i18n("Default"));
00338 pbDefaultBulletStyle->setFixedSize( pbDefaultBulletStyle->sizeHint() );
00339 hbox->addWidget( pbDefaultBulletStyle );
00340
00341 hbox->addStretch( 1 );
00342
00343 vbox->addItem(hbox);
00344 vbox->addStretch( 1 );
00345
00346 initTab1();
00347
00348 connect( pbBulletStyle, SIGNAL( clicked() ), SLOT( chooseBulletStyle() ) );
00349 connect( pbDefaultBulletStyle, SIGNAL( clicked()),
00350 SLOT( defaultBulletStyle() ) );
00351 }
00352
00353 void KoAutoFormatDia::initTab1()
00354 {
00355 cbUpperCase->setChecked( m_autoFormat.getConfigUpperCase() );
00356 cbUpperUpper->setChecked( m_autoFormat.getConfigUpperUpper() );
00357 cbDetectUrl->setChecked( m_autoFormat.getConfigAutoDetectUrl());
00358 cbIgnoreDoubleSpace->setChecked( m_autoFormat.getConfigIgnoreDoubleSpace());
00359 cbRemoveSpaceBeginEndLine->setChecked( m_autoFormat.getConfigRemoveSpaceBeginEndLine());
00360 cbAutoChangeFormat->setChecked( m_autoFormat.getConfigAutoChangeFormat());
00361 cbAutoReplaceNumber->setChecked( m_autoFormat.getConfigAutoReplaceNumber());
00362 cbUseNumberStyle->setChecked( m_autoFormat.getConfigAutoNumberStyle());
00363 cbUseBulletStyle->setChecked( m_autoFormat.getConfigUseBulletSyle());
00364 cbAutoSuperScript->setChecked( m_docAutoFormat->getConfigAutoSuperScript());
00365 pbBulletStyle->setText( bulletStyle );
00366 cbCapitalizeDaysName->setChecked( m_autoFormat.getConfigCapitalizeNameOfDays());
00367
00368 slotBulletStyleToggled( cbUseBulletStyle->isChecked() );
00369 }
00370
00371 void KoAutoFormatDia::slotBulletStyleToggled( bool b )
00372 {
00373 pbBulletStyle->setEnabled( b );
00374 pbDefaultBulletStyle->setEnabled( b );
00375 }
00376
00377 void KoAutoFormatDia::setupTab2()
00378 {
00379 tab2 = addPage( i18n( "Custom Quotes" ) );
00380
00381 QVBoxLayout *vbox = new QVBoxLayout(tab2, 0, KDialog::spacingHint());
00382
00383 cbTypographicDoubleQuotes = new QCheckBox( tab2 );
00384 cbTypographicDoubleQuotes->setText( i18n(
00385 "Replace &double quotes with typographical quotes" ) );
00386
00387 connect( cbTypographicDoubleQuotes,SIGNAL(toggled ( bool)),
00388 SLOT(slotChangeStateDouble(bool)));
00389
00390 vbox->addWidget( cbTypographicDoubleQuotes );
00391
00392 QHBoxLayout *hbox = new QHBoxLayout( );
00393 hbox->addSpacing( 20 );
00394
00395 pbDoubleQuote1 = new QPushButton( tab2 );
00396 pbDoubleQuote1->setFixedSize( pbDoubleQuote1->sizeHint() );
00397
00398 pbDoubleQuote2 = new QPushButton( tab2 );
00399 pbDoubleQuote2->setFixedSize( pbDoubleQuote2->sizeHint() );
00400
00401 if (QApplication::reverseLayout()) {
00402 hbox->addWidget( pbDoubleQuote2 );
00403 hbox->addWidget( pbDoubleQuote1 );
00404 } else {
00405 hbox->addWidget( pbDoubleQuote1 );
00406 hbox->addWidget( pbDoubleQuote2 );
00407 }
00408
00409 hbox->addSpacing( KDialog::spacingHint() );
00410
00411 pbDoubleDefault = new QPushButton( tab2 );
00412 pbDoubleDefault->setText(i18n("Default"));
00413 pbDoubleDefault->setFixedSize( pbDoubleDefault->sizeHint() );
00414 hbox->addWidget( pbDoubleDefault );
00415
00416 hbox->addStretch( 1 );
00417
00418 connect(pbDoubleQuote1, SIGNAL( clicked() ), SLOT( chooseDoubleQuote1() ));
00419 connect(pbDoubleQuote2, SIGNAL( clicked() ), SLOT( chooseDoubleQuote2() ));
00420 connect(pbDoubleDefault, SIGNAL( clicked()), SLOT( defaultDoubleQuote() ));
00421
00422 vbox->addItem( hbox );
00423
00424 cbTypographicSimpleQuotes = new QCheckBox( tab2 );
00425 cbTypographicSimpleQuotes->setText( i18n(
00426 "Replace &single quotes with typographical quotes" ) );
00427
00428 connect( cbTypographicSimpleQuotes,SIGNAL(toggled ( bool)),
00429 SLOT(slotChangeStateSimple(bool)));
00430
00431 vbox->addWidget( cbTypographicSimpleQuotes );
00432
00433 hbox = new QHBoxLayout( );
00434 hbox->addSpacing( 20 );
00435
00436 pbSimpleQuote1 = new QPushButton( tab2 );
00437 pbSimpleQuote1->setFixedSize( pbSimpleQuote1->sizeHint() );
00438
00439 pbSimpleQuote2 = new QPushButton( tab2 );
00440 pbSimpleQuote2->setFixedSize( pbSimpleQuote2->sizeHint() );
00441
00442 if (QApplication::reverseLayout()) {
00443 hbox->addWidget( pbSimpleQuote2 );
00444 hbox->addWidget( pbSimpleQuote1 );
00445 } else {
00446 hbox->addWidget( pbSimpleQuote1 );
00447 hbox->addWidget( pbSimpleQuote2 );
00448 }
00449
00450 hbox->addSpacing( KDialog::spacingHint() );
00451
00452 pbSimpleDefault = new QPushButton( tab2 );
00453 pbSimpleDefault->setText(i18n("Default"));
00454 pbSimpleDefault->setFixedSize( pbSimpleDefault->sizeHint() );
00455 hbox->addWidget( pbSimpleDefault );
00456
00457 hbox->addStretch( 1 );
00458
00459 connect(pbSimpleQuote1, SIGNAL( clicked() ), SLOT( chooseSimpleQuote1() ));
00460 connect(pbSimpleQuote2, SIGNAL( clicked() ), SLOT( chooseSimpleQuote2() ));
00461 connect(pbSimpleDefault, SIGNAL( clicked()), SLOT( defaultSimpleQuote() ));
00462
00463 vbox->addItem( hbox );
00464 vbox->addStretch( 1 );
00465
00466 initTab2();
00467 }
00468
00469 void KoAutoFormatDia::initTab2()
00470 {
00471 bool state=m_autoFormat.getConfigTypographicDoubleQuotes().replace;
00472 cbTypographicDoubleQuotes->setChecked( state );
00473 pbDoubleQuote1->setText( oDoubleBegin );
00474 pbDoubleQuote2->setText(oDoubleEnd );
00475 slotChangeStateDouble(state);
00476
00477 state=m_autoFormat.getConfigTypographicSimpleQuotes().replace;
00478 cbTypographicSimpleQuotes->setChecked( state );
00479 pbSimpleQuote1->setText( oSimpleBegin );
00480 pbSimpleQuote2->setText(oSimpleEnd );
00481 slotChangeStateSimple(state);
00482
00483 }
00484
00485 void KoAutoFormatDia::setupTab3()
00486 {
00487 tab3 = addPage( i18n( "Advanced Autocorrection" ) );
00488
00489 QLabel *lblFind, *lblReplace;
00490
00491 QGridLayout *grid = new QGridLayout( tab3, 11, 7, 0, KDialog::spacingHint() );
00492
00493 autoFormatLanguage = new QComboBox(tab3);
00494
00495 QStringList lst;
00496 lst<<i18n("Default");
00497 lst<<i18n("All Languages");
00498 exceptionLanguageName.insert( i18n("Default"), "");
00499 exceptionLanguageName.insert( i18n("All Languages"), "all_languages");
00500
00501 KStandardDirs *standard = new KStandardDirs();
00502 QStringList tmp = standard->findDirs("data", "koffice/autocorrect/");
00503 QString path = *(tmp.end());
00504 for ( QStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it )
00505 {
00506 path =*it;
00507 }
00508 delete standard;
00509 QDir dir( path);
00510 tmp =dir.entryList (QDir::Files);
00511 for ( QStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it )
00512 {
00513 if ( !(*it).contains("autocorrect"))
00514 {
00515 QString readableName = KGlobal::locale()->twoAlphaToCountryName((*it).left((*it).length()-4));
00516 QString tmp;
00517 if ( readableName.isEmpty() )
00518 tmp =(*it).left((*it).length()-4);
00519 else
00520 tmp =readableName;
00521 exceptionLanguageName.insert( tmp, (*it).left((*it).length()-4));
00522 lst<<tmp;
00523 }
00524 }
00525 autoFormatLanguage->insertStringList(lst);
00526
00527 connect(autoFormatLanguage->listBox(), SIGNAL(selected ( const QString & )), this, SLOT(changeAutoformatLanguage(const QString & )));
00528
00529 grid->addMultiCellWidget( autoFormatLanguage, 0, 0, 4, 6 );
00530 QLabel *lblAutoFormatLanguage = new QLabel( i18n("Replacements and exceptions for language:"), tab3);
00531 grid->addMultiCellWidget( lblAutoFormatLanguage, 0, 0, 0, 3 );
00532
00533 cbAdvancedAutoCorrection = new QCheckBox( tab3 );
00534 cbAdvancedAutoCorrection->setText( i18n("Enable word replacement") );
00535 connect( cbAdvancedAutoCorrection, SIGNAL(clicked ()), this, SLOT( slotChangeAdvancedAutoCorrection()));
00536 grid->addMultiCellWidget( cbAdvancedAutoCorrection, 1, 1, 0, 6 );
00537
00538 cbAutoCorrectionWithFormat = new QCheckBox( tab3 );
00539 cbAutoCorrectionWithFormat->setText( i18n("Replace text with format") );
00540 grid->addMultiCellWidget( cbAutoCorrectionWithFormat, 2, 2, 0, 6 );
00541
00542 lblFind = new QLabel( i18n( "&Find:" ), tab3 );
00543 grid->addWidget( lblFind, 3, 0 );
00544
00545 m_find = new KoAutoFormatLineEdit( tab3 );
00546 grid->addWidget( m_find, 3, 1 );
00547
00548 lblFind->setBuddy( m_find );
00549
00550 connect( m_find, SIGNAL( textChanged( const QString & ) ),
00551 SLOT( slotfind( const QString & ) ) );
00552 connect( m_find, SIGNAL( keyReturnPressed() ),
00553 SLOT( slotAddEntry()));
00554
00555 pbSpecialChar1 = new QPushButton( "...", tab3 );
00556 QToolTip::add( pbSpecialChar1, i18n( "Insert a special character..." ) );
00557 pbSpecialChar1->setFixedWidth( 40 );
00558 grid->addWidget( pbSpecialChar1, 3, 2 );
00559
00560 connect(pbSpecialChar1,SIGNAL(clicked()), SLOT(chooseSpecialChar1()));
00561
00562 lblReplace = new QLabel( i18n( "&Replace:" ), tab3 );
00563 grid->addWidget( lblReplace, 3, 3 );
00564
00565 m_replace = new KoAutoFormatLineEdit( tab3 );
00566 grid->addWidget( m_replace, 3, 4 );
00567
00568 lblReplace->setBuddy( m_replace );
00569
00570 connect( m_replace, SIGNAL( textChanged( const QString & ) ),
00571 SLOT( slotfind2( const QString & ) ) );
00572 connect( m_replace, SIGNAL( keyReturnPressed() ),
00573 SLOT( slotAddEntry()));
00574
00575 pbSpecialChar2 = new QPushButton( "...", tab3 );
00576 QToolTip::add( pbSpecialChar2, i18n( "Insert a special character..." ) );
00577 pbSpecialChar2->setFixedWidth( 40 );
00578 grid->addWidget( pbSpecialChar2, 3, 5 );
00579
00580 connect(pbSpecialChar2,SIGNAL(clicked()), SLOT(chooseSpecialChar2()));
00581
00582 pbAdd = new QPushButton( i18n( "&Add"), tab3 );
00583 grid->addWidget( pbAdd, 3, 6 );
00584
00585 connect(pbAdd,SIGNAL(clicked()),this, SLOT(slotAddEntry()));
00586
00587 m_pListView = new KListView( tab3 );
00588 m_pListView->addColumn( i18n( "Find" ) );
00589 m_pListView->addColumn( i18n( "Replace" ) );
00590 m_pListView->setAllColumnsShowFocus( true );
00591 grid->addMultiCellWidget( m_pListView, 4, 10, 0, 5 );
00592
00593 connect(m_pListView, SIGNAL(doubleClicked ( QListViewItem * )),
00594 SLOT(slotChangeTextFormatEntry()) );
00595 connect(m_pListView, SIGNAL(clicked ( QListViewItem * ) ),
00596 SLOT(slotEditEntry()) );
00597
00598 pbRemove = new QPushButton( i18n( "Remove" ), tab3 );
00599 grid->addWidget( pbRemove, 4, 6, Qt::AlignTop );
00600
00601 connect(pbRemove,SIGNAL(clicked()), SLOT(slotRemoveEntry()));
00602
00603 pbChangeFormat= new QPushButton( i18n( "Change Format..." ), tab3 );
00604 grid->addWidget( pbChangeFormat, 5, 6, Qt::AlignTop );
00605
00606 connect( pbChangeFormat, SIGNAL(clicked()), SLOT(slotChangeTextFormatEntry()));
00607
00608 pbClearFormat= new QPushButton( i18n( "Clear Format" ), tab3 );
00609 grid->addWidget( pbClearFormat, 6, 6, Qt::AlignTop );
00610
00611 connect( pbClearFormat, SIGNAL(clicked()), SLOT(slotClearTextFormatEntry()));
00612 grid->setRowStretch( 10, 1 );
00613
00614 initTab3();
00615 slotChangeAdvancedAutoCorrection();
00616 pbRemove->setEnabled(false);
00617 pbChangeFormat->setEnabled( false );
00618 pbAdd->setEnabled(false);
00619 pbClearFormat->setEnabled( false);
00620
00621 }
00622
00623 void KoAutoFormatDia::initTab3()
00624 {
00625 if ( !changeLanguage || noSignal)
00626 {
00627 initialLanguage=m_autoFormat.getConfigAutoFormatLanguage( );
00628 if ( initialLanguage.isEmpty() )
00629 autoFormatLanguage->setCurrentItem(0);
00630 else
00631 {
00632 KoExceptionLanguageName::Iterator it = exceptionLanguageName.begin();
00633 for ( ; it != exceptionLanguageName.end() ; ++it )
00634 {
00635 if ( it.data() == initialLanguage)
00636 {
00637 autoFormatLanguage->setCurrentText(it.key());
00638 break;
00639 }
00640
00641 }
00642 }
00643 }
00644
00645 if ( autocorrectionEntryChanged )
00646 {
00647 if ( !changeLanguage )
00648 m_docAutoFormat->configAutoFormatLanguage( initialLanguage);
00649 m_docAutoFormat->readConfig( true );
00650 }
00651 cbAdvancedAutoCorrection->setChecked(m_autoFormat.getConfigAdvancedAutoCorrect());
00652 cbAutoCorrectionWithFormat->setChecked( m_autoFormat.getConfigCorrectionWithFormat());
00653 m_pListView->clear();
00654
00655 QDictIterator<KoAutoFormatEntry> it( m_docAutoFormat->getAutoFormatEntries());
00656 for( ; it.current(); ++it )
00657 {
00658 ( void )new QListViewItem( m_pListView, it.currentKey(), it.current()->replace() );
00659 }
00660 }
00661
00662 void KoAutoFormatDia::slotChangeAdvancedAutoCorrection()
00663 {
00664 bool state = cbAdvancedAutoCorrection->isChecked();
00665 cbAutoCorrectionWithFormat->setEnabled( state );
00666 pbSpecialChar2->setEnabled( state );
00667 pbSpecialChar1->setEnabled( state );
00668 m_replace->setEnabled( state);
00669 m_find->setEnabled( state);
00670 m_pListView->setEnabled( state);
00671
00672 state = state && !m_replace->text().isEmpty() && !m_find->text().isEmpty();
00673 KoAutoFormatEntry * entry=m_docAutoFormat->findFormatEntry(m_find->text());
00674 pbRemove->setEnabled(state && entry);
00675 pbChangeFormat->setEnabled(state && entry);
00676 pbClearFormat->setEnabled(state && entry);
00677 pbAdd->setEnabled(state);
00678 }
00679
00680
00681 void KoAutoFormatDia::changeAutoformatLanguage(const QString & text)
00682 {
00683 if ( text==i18n("Default"))
00684 m_docAutoFormat->configAutoFormatLanguage( QString::null);
00685 else
00686 {
00687 m_docAutoFormat->configAutoFormatLanguage( exceptionLanguageName.find(text).data());
00688 }
00689 if ( !noSignal )
00690 {
00691 changeLanguage=true;
00692 m_docAutoFormat->readConfig( true );
00693 initTab3();
00694 initTab4();
00695 autocorrectionEntryChanged=true;
00696 cbAutoSuperScript->setEnabled( m_docAutoFormat->nbSuperScriptEntry()>0 );
00697 oSimpleBegin= m_docAutoFormat->getConfigTypographicSimpleQuotes().begin ;
00698 oSimpleEnd= m_docAutoFormat->getConfigTypographicSimpleQuotes().end;
00699 oDoubleBegin= m_docAutoFormat->getConfigTypographicDoubleQuotes().begin;
00700 oDoubleEnd= m_docAutoFormat->getConfigTypographicDoubleQuotes().end;
00701 bulletStyle= m_docAutoFormat->getConfigBulletStyle();
00702 delete newEntry;
00703 newEntry=0L;
00704 changeLanguage=false;
00705 }
00706 }
00707
00708 void KoAutoFormatDia::setupTab4()
00709 {
00710 tab4 = addPage( i18n( "Exceptions" ) );
00711 QVBoxLayout *vbox = new QVBoxLayout(tab4, 0, KDialog::spacingHint());
00712
00713 abbreviation=new KoAutoFormatExceptionWidget(tab4,
00714 i18n("Do not treat as the end of a sentence:"),
00715 m_autoFormat.listException(),
00716 m_autoFormat.getConfigIncludeAbbreviation() , true);
00717
00718 vbox->addWidget( abbreviation );
00719
00720 twoUpperLetter=new KoAutoFormatExceptionWidget(tab4,
00721 i18n("Accept two uppercase letters in:"),
00722 m_autoFormat.listTwoUpperLetterException(),
00723 m_autoFormat.getConfigIncludeTwoUpperUpperLetterException());
00724
00725 vbox->addWidget( twoUpperLetter );
00726
00727 initTab4();
00728 }
00729
00730 void KoAutoFormatDia::initTab4()
00731 {
00732 abbreviation->setListException( !changeLanguage ? m_autoFormat.listException(): m_docAutoFormat->listException() );
00733 if ( !changeLanguage )
00734 {
00735 abbreviation->setAutoInclude( m_docAutoFormat->getConfigIncludeAbbreviation() );
00736 twoUpperLetter->setAutoInclude( m_docAutoFormat->getConfigIncludeTwoUpperUpperLetterException() );
00737 }
00738 twoUpperLetter->setListException( !changeLanguage ? m_autoFormat.listTwoUpperLetterException():m_docAutoFormat->listTwoUpperLetterException() );
00739 }
00740
00741 void KoAutoFormatDia::slotClearTextFormatEntry()
00742 {
00743 bool addNewEntry = (pbAdd->text() == i18n( "&Add" ));
00744 if ( m_pListView->currentItem() || addNewEntry)
00745 {
00746 if ( addNewEntry )
00747 {
00748 if (newEntry)
00749 newEntry->clearFormatEntryContext();
00750 }
00751 else
00752 {
00753 KoAutoFormatEntry *entry = m_docAutoFormat->findFormatEntry(m_pListView->currentItem()->text(0));
00754 entry->clearFormatEntryContext();
00755 }
00756 autocorrectionEntryChanged= true;
00757 }
00758 }
00759
00760 void KoAutoFormatDia::slotChangeTextFormatEntry()
00761 {
00762 bool addNewEntry = (pbAdd->text() == i18n( "&Add" ));
00763 if ( m_pListView->currentItem() || addNewEntry)
00764 {
00765 KoAutoFormatEntry *entry = 0L;
00766 if ( addNewEntry )
00767 {
00768 if ( m_replace->text().isEmpty() )
00769 return;
00770 if ( !newEntry )
00771 newEntry = new KoAutoFormatEntry( m_replace->text());
00772 entry =newEntry;
00773 }
00774 else
00775 entry = m_docAutoFormat->findFormatEntry(m_pListView->currentItem()->text(0));
00776 KoSearchContext *tmpFormat = entry->formatEntryContext();
00777 bool createNewFormat = false;
00778
00779 if ( !tmpFormat )
00780 {
00781 tmpFormat = new KoSearchContext();
00782 createNewFormat = true;
00783 }
00784
00785 KoFormatDia *dia = new KoFormatDia( this, i18n("Change Text Format"), tmpFormat , 0L);
00786 if ( dia->exec())
00787 {
00788 dia->ctxOptions( );
00789 if ( createNewFormat )
00790 entry->setFormatEntryContext( tmpFormat );
00791 autocorrectionEntryChanged= true;
00792
00793 }
00794 else
00795 {
00796 if ( createNewFormat )
00797 delete tmpFormat;
00798 }
00799 delete dia;
00800 }
00801 }
00802
00803 void KoAutoFormatDia::slotRemoveEntry()
00804 {
00805
00806 if(m_pListView->currentItem())
00807 {
00808 m_docAutoFormat->removeAutoFormatEntry(m_pListView->currentItem()->text(0));
00809 pbAdd->setText(i18n("&Add"));
00810 refreshEntryList();
00811 autocorrectionEntryChanged= true;
00812 }
00813 }
00814
00815
00816 void KoAutoFormatDia::slotfind( const QString & )
00817 {
00818 KoAutoFormatEntry *entry = m_docAutoFormat->findFormatEntry(m_find->text());
00819 if ( entry )
00820 {
00821 m_replace->setText(entry->replace().latin1());
00822 pbAdd->setText(i18n("&Modify"));
00823 m_pListView->setCurrentItem(m_pListView->findItem(m_find->text(),0));
00824
00825 } else {
00826 m_replace->clear();
00827 pbAdd->setText(i18n("&Add"));
00828 m_pListView->setCurrentItem(0L);
00829 }
00830 slotfind2("");
00831 }
00832
00833
00834 void KoAutoFormatDia::slotfind2( const QString & )
00835 {
00836 bool state = !m_replace->text().isEmpty() && !m_find->text().isEmpty();
00837 KoAutoFormatEntry * entry=m_docAutoFormat->findFormatEntry(m_find->text());
00838 pbRemove->setEnabled(state && entry);
00839 if ( state && entry )
00840 {
00841 delete newEntry;
00842 newEntry = 0L;
00843 }
00844 pbChangeFormat->setEnabled(state);
00845 pbClearFormat->setEnabled(state);
00846 pbAdd->setEnabled(state);
00847 }
00848
00849
00850 void KoAutoFormatDia::refreshEntryList()
00851 {
00852 m_pListView->clear();
00853 QDictIterator<KoAutoFormatEntry> it( m_docAutoFormat->getAutoFormatEntries());
00854 for( ; it.current(); ++it )
00855 {
00856 ( void )new QListViewItem( m_pListView, it.currentKey(), it.current()->replace() );
00857 }
00858 m_pListView->setCurrentItem(m_pListView->firstChild ());
00859 bool state = !(m_replace->text().isEmpty()) && !(m_find->text().isEmpty());
00860
00861 pbRemove->setEnabled(m_pListView->currentItem() && m_pListView->selectedItem()!=0 );
00862 pbChangeFormat->setEnabled(state && m_pListView->currentItem() && m_pListView->selectedItem()!=0 );
00863 pbClearFormat->setEnabled(state && m_pListView->currentItem() && m_pListView->selectedItem()!=0 );
00864
00865 pbAdd->setEnabled(state);
00866 }
00867
00868
00869 void KoAutoFormatDia::addEntryList(const QString &key, KoAutoFormatEntry *_autoEntry)
00870 {
00871 m_docAutoFormat->addAutoFormatEntry( key, _autoEntry );
00872 }
00873
00874
00875
00876 void KoAutoFormatDia::editEntryList(const QString &key,const QString &newFindString, KoAutoFormatEntry *_autoEntry)
00877 {
00878 if ( m_docAutoFormat->findFormatEntry(key) && m_docAutoFormat->findFormatEntry(key)->formatEntryContext())
00879 _autoEntry->setFormatEntryContext( new KoSearchContext(*(m_docAutoFormat->findFormatEntry(key)->formatEntryContext()) ));
00880 m_docAutoFormat->removeAutoFormatEntry( key );
00881 m_docAutoFormat->addAutoFormatEntry( newFindString, _autoEntry );
00882 }
00883
00884
00885 void KoAutoFormatDia::slotAddEntry()
00886 {
00887 if(!pbAdd->isEnabled())
00888 return;
00889 QString repl = m_replace->text();
00890 QString find = m_find->text();
00891 if(repl.isEmpty() || find.isEmpty())
00892 {
00893 KMessageBox::sorry( 0L, i18n( "An area is empty" ) );
00894 return;
00895 }
00896 if(repl==find)
00897 {
00898 KMessageBox::sorry( 0L, i18n( "Find string is the same as replace string!" ) );
00899 return;
00900 }
00901 KoAutoFormatEntry *tmp = new KoAutoFormatEntry( repl );
00902
00903 if(pbAdd->text() == i18n( "&Add" ))
00904 {
00905 if ( newEntry )
00906 {
00907 newEntry->changeReplace( m_replace->text());
00908 addEntryList(find, newEntry);
00909 delete tmp;
00910 newEntry = 0L;
00911 }
00912 else
00913 addEntryList(find, tmp);
00914 }
00915 else
00916 editEntryList(find, find, tmp);
00917 m_replace->clear();
00918 m_find->clear();
00919
00920 refreshEntryList();
00921 autocorrectionEntryChanged= true;
00922 }
00923
00924
00925 void KoAutoFormatDia::chooseSpecialChar1()
00926 {
00927 QString f = font().family();
00928 QChar c = ' ';
00929 bool const focus = m_find->hasFocus();
00930 if ( KoCharSelectDia::selectChar( f, c, false ) )
00931 {
00932 int const cursorpos = m_find->cursorPosition();
00933 if (focus)
00934 m_find->setText( m_find->text().insert( cursorpos, c ) );
00935 else
00936 m_find->setText( m_find->text().append(c) );
00937 m_find->setCursorPosition( cursorpos+1 );
00938 }
00939 }
00940
00941
00942 void KoAutoFormatDia::chooseSpecialChar2()
00943 {
00944 QString f = font().family();
00945 QChar c = ' ';
00946 bool const focus = m_replace->hasFocus();
00947 if ( KoCharSelectDia::selectChar( f, c, false ) )
00948 {
00949 int const cursorpos = m_replace->cursorPosition();
00950 if (focus)
00951 m_replace->setText( m_replace->text().insert(m_replace->cursorPosition(), c ) );
00952 else
00953 m_replace->setText( m_replace->text().append(c) );
00954 m_replace->setCursorPosition( cursorpos+1 );
00955 }
00956 }
00957
00958
00959 void KoAutoFormatDia::slotItemRenamed(QListViewItem *, const QString & , int )
00960 {
00961
00962
00963 }
00964
00965
00966 void KoAutoFormatDia::slotEditEntry()
00967 {
00968 if(m_pListView->currentItem()==0)
00969 return;
00970 delete newEntry;
00971 newEntry=0L;
00972 m_find->setText(m_pListView->currentItem()->text(0));
00973 m_replace->setText(m_pListView->currentItem()->text(1));
00974 bool state = !m_replace->text().isEmpty() && !m_find->text().isEmpty();
00975 pbRemove->setEnabled(state);
00976 pbChangeFormat->setEnabled( state );
00977 pbClearFormat->setEnabled(state);
00978 pbAdd->setEnabled(state);
00979 }
00980
00981
00982 bool KoAutoFormatDia::applyConfig()
00983 {
00984
00985 KoAutoFormat::TypographicQuotes tq = m_autoFormat.getConfigTypographicSimpleQuotes();
00986 tq.replace = cbTypographicSimpleQuotes->isChecked();
00987 tq.begin = pbSimpleQuote1->text()[ 0 ];
00988 tq.end = pbSimpleQuote2->text()[ 0 ];
00989 m_docAutoFormat->configTypographicSimpleQuotes( tq );
00990
00991 tq = m_autoFormat.getConfigTypographicDoubleQuotes();
00992 tq.replace = cbTypographicDoubleQuotes->isChecked();
00993 tq.begin = pbDoubleQuote1->text()[ 0 ];
00994 tq.end = pbDoubleQuote2->text()[ 0 ];
00995 m_docAutoFormat->configTypographicDoubleQuotes( tq );
00996
00997
00998 m_docAutoFormat->configUpperCase( cbUpperCase->isChecked() );
00999 m_docAutoFormat->configUpperUpper( cbUpperUpper->isChecked() );
01000 m_docAutoFormat->configAutoDetectUrl( cbDetectUrl->isChecked() );
01001
01002 m_docAutoFormat->configIgnoreDoubleSpace( cbIgnoreDoubleSpace->isChecked());
01003 m_docAutoFormat->configRemoveSpaceBeginEndLine( cbRemoveSpaceBeginEndLine->isChecked());
01004 m_docAutoFormat->configUseBulletStyle(cbUseBulletStyle->isChecked());
01005
01006 m_docAutoFormat->configBulletStyle(pbBulletStyle->text()[ 0 ]);
01007
01008 m_docAutoFormat->configAutoChangeFormat( cbAutoChangeFormat->isChecked());
01009
01010 m_docAutoFormat->configAutoReplaceNumber( cbAutoReplaceNumber->isChecked());
01011 m_docAutoFormat->configAutoNumberStyle(cbUseNumberStyle->isChecked());
01012
01013 m_docAutoFormat->configAutoSuperScript ( cbAutoSuperScript->isChecked() );
01014 m_docAutoFormat->configCapitalizeNameOfDays( cbCapitalizeDaysName->isChecked());
01015
01016
01017
01018
01019 m_docAutoFormat->copyListException(abbreviation->getListException());
01020 m_docAutoFormat->copyListTwoUpperCaseException(twoUpperLetter->getListException());
01021 m_docAutoFormat->configAdvancedAutocorrect( cbAdvancedAutoCorrection->isChecked() );
01022 m_docAutoFormat->configCorrectionWithFormat( cbAutoCorrectionWithFormat->isChecked());
01023
01024 m_docAutoFormat->configIncludeTwoUpperUpperLetterException( twoUpperLetter->autoInclude());
01025 m_docAutoFormat->configIncludeAbbreviation( abbreviation->autoInclude());
01026
01027 QString lang = exceptionLanguageName.find(autoFormatLanguage->currentText()).data();
01028 if ( lang == i18n("Default") )
01029 m_docAutoFormat->configAutoFormatLanguage(QString::null);
01030 else
01031 m_docAutoFormat->configAutoFormatLanguage(lang);
01032
01033
01034 m_docAutoFormat->saveConfig();
01035 return true;
01036 }
01037
01038 void KoAutoFormatDia::slotOk()
01039 {
01040 if (applyConfig())
01041 {
01042 KDialogBase::slotOk();
01043 }
01044 }
01045
01046 void KoAutoFormatDia::slotCancel()
01047 {
01048
01049 if ( autocorrectionEntryChanged )
01050 {
01051 m_docAutoFormat->configAutoFormatLanguage( initialLanguage);
01052 m_docAutoFormat->readConfig( true );
01053 }
01054 KDialogBase::slotCancel();
01055 }
01056
01057 void KoAutoFormatDia::chooseDoubleQuote1()
01058 {
01059 QString f = font().family();
01060 QChar c = oDoubleBegin;
01061 if ( KoCharSelectDia::selectChar( f, c, false ) )
01062 {
01063 pbDoubleQuote1->setText( c );
01064 }
01065
01066 }
01067
01068 void KoAutoFormatDia::chooseDoubleQuote2()
01069 {
01070 QString f = font().family();
01071 QChar c = oDoubleEnd;
01072 if ( KoCharSelectDia::selectChar( f, c, false ) )
01073 {
01074 pbDoubleQuote2->setText( c );
01075 }
01076 }
01077
01078
01079 void KoAutoFormatDia::defaultDoubleQuote()
01080 {
01081 pbDoubleQuote1->setText(m_docAutoFormat->getDefaultTypographicDoubleQuotes().begin);
01082 pbDoubleQuote2->setText(m_docAutoFormat->getDefaultTypographicDoubleQuotes().end);
01083 }
01084
01085 void KoAutoFormatDia::chooseSimpleQuote1()
01086 {
01087 QString f = font().family();
01088 QChar c = oSimpleBegin;
01089 if ( KoCharSelectDia::selectChar( f, c, false ) )
01090 {
01091 pbSimpleQuote1->setText( c );
01092 }
01093 }
01094
01095 void KoAutoFormatDia::chooseSimpleQuote2()
01096 {
01097 QString f = font().family();
01098 QChar c = oSimpleEnd;
01099 if ( KoCharSelectDia::selectChar( f, c, false ) )
01100 {
01101 pbSimpleQuote2->setText( c );
01102 }
01103 }
01104
01105 void KoAutoFormatDia::defaultSimpleQuote()
01106 {
01107
01108 pbSimpleQuote1->setText(m_docAutoFormat->getDefaultTypographicSimpleQuotes().begin);
01109 pbSimpleQuote2->setText(m_docAutoFormat->getDefaultTypographicSimpleQuotes().end);
01110 }
01111
01112
01113 void KoAutoFormatDia::chooseBulletStyle()
01114 {
01115 QString f = font().family();
01116 QChar c = bulletStyle;
01117 if ( KoCharSelectDia::selectChar( f, c, false ) )
01118 {
01119 pbBulletStyle->setText( c );
01120 }
01121 }
01122
01123 void KoAutoFormatDia::defaultBulletStyle()
01124 {
01125 pbBulletStyle->setText( "" );
01126 }
01127
01128 void KoAutoFormatDia::slotChangeStateSimple(bool b)
01129 {
01130 pbSimpleQuote1->setEnabled(b);
01131 pbSimpleQuote2->setEnabled(b);
01132 pbSimpleDefault->setEnabled(b);
01133 }
01134
01135 void KoAutoFormatDia::slotChangeStateDouble(bool b)
01136 {
01137 pbDoubleQuote1->setEnabled(b);
01138 pbDoubleQuote2->setEnabled(b);
01139 pbDoubleDefault->setEnabled(b);
01140 }
01141
01142 #include "KoAutoFormatDia.moc"