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