lib Library API Documentation

koAutoFormatDia.cc

00001 /* This file is part of the KDE project 00002 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org> 00003 2001, 2002 Sven Leiber <s.leiber@web.de> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, USA. 00019 */ 00020 00021 #include "koAutoFormatDia.h" 00022 #include "koAutoFormatDia.moc" 00023 #include "koAutoFormat.h" 00024 #include "koCharSelectDia.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 <qvbox.h> 00034 #include <qcheckbox.h> 00035 #include <qpushbutton.h> 00036 #include <qlabel.h> 00037 #include <qspinbox.h> 00038 #include <kdebug.h> 00039 #include <knuminput.h> 00040 #include <kcompletion.h> 00041 #include <kconfig.h> 00042 #include <klineeditdlg.h> 00043 #include <qcombobox.h> 00044 #include <qdir.h> 00045 #include <koSearchDia.h> 00046 00047 KoAutoFormatLineEdit::KoAutoFormatLineEdit ( QWidget * parent, const char * name ) 00048 : QLineEdit(parent,name) 00049 { 00050 } 00051 00052 void KoAutoFormatLineEdit::keyPressEvent ( QKeyEvent *ke ) 00053 { 00054 if( ke->key() == QKeyEvent::Key_Return || 00055 ke->key() == QKeyEvent::Key_Enter ) 00056 { 00057 emit keyReturnPressed(); 00058 return; 00059 } 00060 QLineEdit::keyPressEvent (ke); 00061 } 00062 00063 00064 /******************************************************************/ 00065 /* Class: KoAutoFormatExceptionWidget */ 00066 /******************************************************************/ 00067 00068 KoAutoFormatExceptionWidget::KoAutoFormatExceptionWidget(QWidget *parent, const QString &name,const QStringList &_list, bool _autoInclude, bool _abreviation) 00069 :QWidget( parent ) 00070 { 00071 m_bAbbreviation=_abreviation; 00072 m_listException=_list; 00073 QGridLayout *grid = new QGridLayout(this, 4, 2, KDialog::marginHint(), KDialog::spacingHint()); 00074 00075 QLabel *lab=new QLabel(name,this); 00076 grid->addMultiCellWidget(lab,0,0,0,1); 00077 00078 exceptionLine = new KoAutoFormatLineEdit( this ); 00079 grid->addWidget(exceptionLine,1,0); 00080 00081 connect(exceptionLine,SIGNAL(keyReturnPressed()),SLOT(slotAddException())); 00082 connect(exceptionLine ,SIGNAL(textChanged ( const QString & )), 00083 SLOT(textChanged ( const QString & ))); 00084 00085 pbAddException=new QPushButton(i18n("Add"),this); 00086 connect(pbAddException, SIGNAL(clicked()),SLOT(slotAddException())); 00087 grid->addWidget(pbAddException,1,1); 00088 00089 pbAddException->setEnabled(false); 00090 00091 pbRemoveException=new QPushButton(i18n("Remove"),this); 00092 connect(pbRemoveException, SIGNAL(clicked()),SLOT(slotRemoveException())); 00093 grid->addWidget(pbRemoveException,2,1,Qt::AlignTop); 00094 00095 exceptionList=new QListBox(this); 00096 exceptionList->insertStringList(m_listException); 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().stripWhiteSpace(); 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 pbRemoveException->setEnabled( exceptionList->currentItem()!=-1); 00130 pbAddException->setEnabled(false); 00131 } 00132 exceptionLine->clear(); 00133 } 00134 } 00135 00136 void KoAutoFormatExceptionWidget::slotRemoveException() 00137 { 00138 if(!exceptionList->currentText().isEmpty()) 00139 { 00140 m_listException.remove(exceptionList->currentText()); 00141 exceptionList->clear(); 00142 pbAddException->setEnabled(false); 00143 pbRemoveException->setEnabled( exceptionList->currentItem()!=-1); 00144 exceptionList->insertStringList(m_listException); 00145 exceptionLine->clear(); 00146 } 00147 } 00148 00149 bool KoAutoFormatExceptionWidget::autoInclude() 00150 { 00151 return cbAutoInclude->isChecked(); 00152 } 00153 00154 void KoAutoFormatExceptionWidget::setListException( const QStringList &list) 00155 { 00156 exceptionList->clear(); 00157 exceptionList->insertStringList(list); 00158 } 00159 00160 void KoAutoFormatExceptionWidget::setAutoInclude(bool b) 00161 { 00162 cbAutoInclude->setChecked( b ); 00163 } 00164 00165 void KoAutoFormatExceptionWidget::slotExceptionListSelected() 00166 { 00167 pbRemoveException->setEnabled( exceptionList->currentItem()!=-1 ); 00168 } 00169 00170 /******************************************************************/ 00171 /* Class: KoAutoFormatDia */ 00172 /******************************************************************/ 00173 00174 KoAutoFormatDia::KoAutoFormatDia( QWidget *parent, const char *name, 00175 KoAutoFormat * autoFormat ) 00176 : KDialogBase( Tabbed, i18n("Autocorrection"), Ok | Cancel | User1, Ok, 00177 parent, name, true, true, KGuiItem( i18n( "&Reset" ), "undo" )), 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 noSignal=true; 00187 newEntry = 0L; 00188 autocorrectionEntryChanged= false; 00189 changeLanguage = false; 00190 00191 setupTab1(); 00192 setupTab2(); 00193 setupTab3(); 00194 setupTab4(); 00195 setInitialSize( QSize(500, 300) ); 00196 connect( this, SIGNAL( user1Clicked() ), this, SLOT(slotResetConf())); 00197 noSignal=false; 00198 } 00199 00200 KoAutoFormatDia::~KoAutoFormatDia() 00201 { 00202 delete newEntry; 00203 } 00204 00205 void KoAutoFormatDia::slotResetConf() 00206 { 00207 switch( activePageIndex() ) { 00208 case 0: 00209 initTab1(); 00210 break; 00211 case 1: 00212 initTab2(); 00213 break; 00214 case 2: 00215 initTab3(); 00216 break; 00217 case 3: 00218 initTab4(); 00219 break; 00220 default: 00221 break; 00222 } 00223 } 00224 00225 void KoAutoFormatDia::setupTab1() 00226 { 00227 tab1 = addPage( i18n( "Simple Autocorrection" ) ); 00228 QVBoxLayout *vbox = new QVBoxLayout(tab1, KDialog::marginHint(), 00229 KDialog::spacingHint()); 00230 00231 cbUpperCase = new QCheckBox( tab1 ); 00232 cbUpperCase->setText( i18n( 00233 "Convert &first letter of a sentence automatically to uppercase\n" 00234 "(e.g. \"my house. in this town\" to \"my house. In this town\")" 00235 ) ); 00236 QWhatsThis::add( cbUpperCase, i18n( 00237 "Detect when a new sentence is started and always ensure that" 00238 " the first character is an uppercase character.")); 00239 00240 vbox->addWidget(cbUpperCase); 00241 00242 00243 cbUpperUpper = new QCheckBox( tab1 ); 00244 cbUpperUpper->setText( i18n( 00245 "Convert &two uppercase characters to one uppercase and one" 00246 " lowercase character\n (e.g. PErfect to Perfect)" ) ); 00247 QWhatsThis::add( cbUpperUpper, i18n( 00248 "All words are checked for the common mistake of holding the " 00249 "shift key down a bit too long. If some words must have two " 00250 "uppercase characters, then those exceptions should be added in " 00251 "the 'Exceptions' tab.")); 00252 00253 vbox->addWidget(cbUpperUpper); 00254 00255 cbDetectUrl=new QCheckBox( tab1 ); 00256 cbDetectUrl->setText( i18n( "Autoformat &URLs" ) ); 00257 QWhatsThis::add( cbDetectUrl, i18n( 00258 "Detect when a URL (Uniform Resource Locator) is typed and " 00259 "provide formatting that matches the way an Internet browser " 00260 "would show a URL.")); 00261 00262 vbox->addWidget(cbDetectUrl); 00263 00264 cbIgnoreDoubleSpace=new QCheckBox( tab1 ); 00265 cbIgnoreDoubleSpace->setText( i18n( "&Suppress double spaces" ) ); 00266 QWhatsThis::add( cbIgnoreDoubleSpace, i18n( 00267 "Make sure that more than one space cannot be typed, as this is a " 00268 "common mistake which is quite hard to find in formatted text.")); 00269 00270 vbox->addWidget(cbIgnoreDoubleSpace); 00271 00272 cbRemoveSpaceBeginEndLine=new QCheckBox( tab1 ); 00273 cbRemoveSpaceBeginEndLine->setText( i18n( 00274 "R&emove spaces at the beginning and end of paragraphs" ) ); 00275 QWhatsThis::add( cbRemoveSpaceBeginEndLine, i18n( 00276 "Keep correct formatting and indenting of sentences by " 00277 "automatically removing spaces typed at the beginning and end of " 00278 "a paragraph.")); 00279 00280 vbox->addWidget(cbRemoveSpaceBeginEndLine); 00281 00282 cbAutoChangeFormat=new QCheckBox( tab1 ); 00283 cbAutoChangeFormat->setText( i18n( 00284 "Automatically do &bold and underline formatting") ); 00285 QWhatsThis::add( cbAutoChangeFormat, i18n( 00286 "When you use _underline_ or *bold*, the text between the " 00287 "underscores or asterisks will be converted to underlined or " 00288 "bold text.") ); 00289 00290 vbox->addWidget(cbAutoChangeFormat); 00291 00292 cbAutoReplaceNumber=new QCheckBox( tab1 ); 00293 cbAutoReplaceNumber->setText( i18n( 00294 "We add the 1/2 char at the %1", "Re&place 1/2... with %1..." ) 00295 .arg( QString( "½" ) ) ); 00296 QWhatsThis::add( cbAutoReplaceNumber, i18n( 00297 "Most standard fraction notations will be converted when available" 00298 ) ); 00299 00300 vbox->addWidget(cbAutoReplaceNumber); 00301 00302 cbUseNumberStyle=new QCheckBox( tab1 ); 00303 cbUseNumberStyle->setText( i18n( 00304 "Use &autonumbering for numbered paragraphs" ) ); 00305 QWhatsThis::add( cbUseNumberStyle, i18n( 00306 "When typing '1)' or similar in front of a paragraph, " 00307 "automatically convert the paragraph to use that numbering style. " 00308 "This has the advantage that further paragraphs will also be " 00309 "numbered and the spacing is done correctly.") ); 00310 00311 vbox->addWidget(cbUseNumberStyle); 00312 00313 cbAutoSuperScript = new QCheckBox( tab1 ); 00314 cbAutoSuperScript->setText( i18n("Rep&lace 1st... with 1^st...")); 00315 cbAutoSuperScript->setEnabled( m_docAutoFormat->nbSuperScriptEntry()>0 ); 00316 00317 vbox->addWidget(cbAutoSuperScript); 00318 cbCapitalizeDaysName = new QCheckBox( tab1 ); 00319 cbCapitalizeDaysName->setText( i18n("Capitalize name of days")); 00320 vbox->addWidget(cbCapitalizeDaysName); 00321 00322 cbUseBulletStyle=new QCheckBox( tab1 ); 00323 cbUseBulletStyle->setText( i18n( 00324 "Use l&ist-formatting for bulleted paragraphs" ) ); 00325 QWhatsThis::add( cbUseBulletStyle, i18n( 00326 "When typing '*' or '-' in front of a paragraph, automatically " 00327 "convert the paragraph to use that list-style. Using a list-style " 00328 "formatting means that a correct bullet is used to draw the list." 00329 ) ); 00330 00331 connect( cbUseBulletStyle, SIGNAL( toggled( bool ) ), 00332 SLOT( slotBulletStyleToggled( bool ) ) ); 00333 00334 vbox->addWidget(cbUseBulletStyle); 00335 QHBoxLayout *hbox = new QHBoxLayout( ); 00336 00337 hbox->addSpacing( 20 ); 00338 pbBulletStyle = new QPushButton( tab1 ); 00339 pbBulletStyle->setFixedSize( pbBulletStyle->sizeHint() ); 00340 hbox->addWidget( pbBulletStyle ); 00341 pbDefaultBulletStyle = new QPushButton( tab1 ); 00342 pbDefaultBulletStyle->setText(i18n("Default")); 00343 pbDefaultBulletStyle->setFixedSize( pbDefaultBulletStyle->sizeHint() ); 00344 hbox->addWidget( pbDefaultBulletStyle ); 00345 00346 hbox->addStretch( 1 ); 00347 00348 vbox->addItem(hbox); 00349 vbox->addStretch( 1 ); 00350 00351 initTab1(); 00352 00353 connect( pbBulletStyle, SIGNAL( clicked() ), SLOT( chooseBulletStyle() ) ); 00354 connect( pbDefaultBulletStyle, SIGNAL( clicked()), 00355 SLOT( defaultBulletStyle() ) ); 00356 } 00357 00358 void KoAutoFormatDia::initTab1() 00359 { 00360 cbUpperCase->setChecked( m_autoFormat.getConfigUpperCase() ); 00361 cbUpperUpper->setChecked( m_autoFormat.getConfigUpperUpper() ); 00362 cbDetectUrl->setChecked( m_autoFormat.getConfigAutoDetectUrl()); 00363 cbIgnoreDoubleSpace->setChecked( m_autoFormat.getConfigIgnoreDoubleSpace()); 00364 cbRemoveSpaceBeginEndLine->setChecked( m_autoFormat.getConfigRemoveSpaceBeginEndLine()); 00365 cbAutoChangeFormat->setChecked( m_autoFormat.getConfigAutoChangeFormat()); 00366 cbAutoReplaceNumber->setChecked( m_autoFormat.getConfigAutoReplaceNumber()); 00367 cbUseNumberStyle->setChecked( m_autoFormat.getConfigAutoNumberStyle()); 00368 cbUseBulletStyle->setChecked( m_autoFormat.getConfigUseBulletSyle()); 00369 cbAutoSuperScript->setChecked( m_docAutoFormat->getConfigAutoSuperScript()); 00370 pbBulletStyle->setText( bulletStyle ); 00371 cbCapitalizeDaysName->setChecked( m_autoFormat.getConfigCapitalizeNameOfDays()); 00372 00373 slotBulletStyleToggled( cbUseBulletStyle->isChecked() ); 00374 } 00375 00376 void KoAutoFormatDia::slotBulletStyleToggled( bool b ) 00377 { 00378 pbBulletStyle->setEnabled( b ); 00379 pbDefaultBulletStyle->setEnabled( b ); 00380 } 00381 00382 void KoAutoFormatDia::setupTab2() 00383 { 00384 tab2 = addPage( i18n( "Custom Quotes" ) ); 00385 00386 QVBoxLayout *vbox = new QVBoxLayout(tab2, KDialog::marginHint(), 00387 KDialog::spacingHint()); 00388 00389 cbTypographicDoubleQuotes = new QCheckBox( tab2 ); 00390 cbTypographicDoubleQuotes->setText( i18n( 00391 "Replace &double quotes with typographical quotes" ) ); 00392 00393 connect( cbTypographicDoubleQuotes,SIGNAL(toggled ( bool)), 00394 SLOT(slotChangeStateDouble(bool))); 00395 00396 vbox->addWidget( cbTypographicDoubleQuotes ); 00397 00398 QHBoxLayout *hbox = new QHBoxLayout( ); 00399 hbox->addSpacing( 20 ); 00400 00401 pbDoubleQuote1 = new QPushButton( tab2 ); 00402 pbDoubleQuote1->setFixedSize( pbDoubleQuote1->sizeHint() ); 00403 00404 pbDoubleQuote2 = new QPushButton( tab2 ); 00405 pbDoubleQuote2->setFixedSize( pbDoubleQuote2->sizeHint() ); 00406 00407 if (QApplication::reverseLayout()) { 00408 hbox->addWidget( pbDoubleQuote2 ); 00409 hbox->addWidget( pbDoubleQuote1 ); 00410 } else { 00411 hbox->addWidget( pbDoubleQuote1 ); 00412 hbox->addWidget( pbDoubleQuote2 ); 00413 } 00414 00415 hbox->addSpacing( 20 ); 00416 00417 pbDoubleDefault = new QPushButton( tab2 ); 00418 pbDoubleDefault->setText(i18n("Default")); 00419 pbDoubleDefault->setFixedSize( pbDoubleDefault->sizeHint() ); 00420 hbox->addWidget( pbDoubleDefault ); 00421 00422 hbox->addStretch( 1 ); 00423 00424 connect(pbDoubleQuote1, SIGNAL( clicked() ), SLOT( chooseDoubleQuote1() )); 00425 connect(pbDoubleQuote2, SIGNAL( clicked() ), SLOT( chooseDoubleQuote2() )); 00426 connect(pbDoubleDefault, SIGNAL( clicked()), SLOT( defaultDoubleQuote() )); 00427 00428 vbox->addItem( hbox ); 00429 00430 cbTypographicSimpleQuotes = new QCheckBox( tab2 ); 00431 cbTypographicSimpleQuotes->setText( i18n( 00432 "Replace &single quotes with typographical quotes" ) ); 00433 00434 connect( cbTypographicSimpleQuotes,SIGNAL(toggled ( bool)), 00435 SLOT(slotChangeStateSimple(bool))); 00436 00437 vbox->addWidget( cbTypographicSimpleQuotes ); 00438 00439 hbox = new QHBoxLayout( ); 00440 hbox->addSpacing( 20 ); 00441 00442 pbSimpleQuote1 = new QPushButton( tab2 ); 00443 pbSimpleQuote1->setFixedSize( pbSimpleQuote1->sizeHint() ); 00444 00445 pbSimpleQuote2 = new QPushButton( tab2 ); 00446 pbSimpleQuote2->setFixedSize( pbSimpleQuote2->sizeHint() ); 00447 00448 if (QApplication::reverseLayout()) { 00449 hbox->addWidget( pbSimpleQuote2 ); 00450 hbox->addWidget( pbSimpleQuote1 ); 00451 } else { 00452 hbox->addWidget( pbSimpleQuote1 ); 00453 hbox->addWidget( pbSimpleQuote2 ); 00454 } 00455 00456 hbox->addSpacing( 20 ); 00457 00458 pbSimpleDefault = new QPushButton( tab2 ); 00459 pbSimpleDefault->setText(i18n("Default")); 00460 pbSimpleDefault->setFixedSize( pbSimpleDefault->sizeHint() ); 00461 hbox->addWidget( pbSimpleDefault ); 00462 00463 hbox->addStretch( 1 ); 00464 00465 connect(pbSimpleQuote1, SIGNAL( clicked() ), SLOT( chooseSimpleQuote1() )); 00466 connect(pbSimpleQuote2, SIGNAL( clicked() ), SLOT( chooseSimpleQuote2() )); 00467 connect(pbSimpleDefault, SIGNAL( clicked()), SLOT( defaultSimpleQuote() )); 00468 00469 vbox->addItem( hbox ); 00470 vbox->addStretch( 1 ); 00471 00472 initTab2(); 00473 } 00474 00475 void KoAutoFormatDia::initTab2() 00476 { 00477 bool state=m_autoFormat.getConfigTypographicDoubleQuotes().replace; 00478 cbTypographicDoubleQuotes->setChecked( state ); 00479 pbDoubleQuote1->setText( oDoubleBegin ); 00480 pbDoubleQuote2->setText(oDoubleEnd ); 00481 slotChangeStateDouble(state); 00482 00483 state=m_autoFormat.getConfigTypographicSimpleQuotes().replace; 00484 cbTypographicSimpleQuotes->setChecked( state ); 00485 pbSimpleQuote1->setText( oSimpleBegin ); 00486 pbSimpleQuote2->setText(oSimpleEnd ); 00487 slotChangeStateSimple(state); 00488 00489 } 00490 00491 void KoAutoFormatDia::setupTab3() 00492 { 00493 tab3 = addPage( i18n( "Advanced Autocorrection" ) ); 00494 00495 QLabel *lblFind, *lblReplace; 00496 00497 QGridLayout *grid = new QGridLayout( tab3, 3, 7, KDialog::marginHint(), 00498 KDialog::spacingHint() ); 00499 00500 autoFormatLanguage = new QComboBox(tab3); 00501 00502 QStringList lst; 00503 lst<<i18n("Default"); 00504 exceptionLanguageName.insert( i18n("Default"), ""); 00505 00506 KStandardDirs *standard = new KStandardDirs(); 00507 QStringList tmp = standard->findDirs("data", "koffice/autocorrect/"); 00508 QString path = *(tmp.end()); 00509 for ( QStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it ) 00510 { 00511 path =*it; 00512 } 00513 delete standard; 00514 QDir dir( path); 00515 tmp =dir.entryList (QDir::Files); 00516 for ( QStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it ) 00517 { 00518 if ( !(*it).contains("autocorrect")) 00519 { 00520 QString readableName = KGlobal::locale()->twoAlphaToCountryName((*it).left((*it).length()-4)); 00521 QString tmp; 00522 if ( readableName.isEmpty() ) 00523 tmp =(*it).left((*it).length()-4); 00524 else 00525 tmp =readableName; 00526 exceptionLanguageName.insert( tmp, (*it).left((*it).length()-4)); 00527 lst<<tmp; 00528 } 00529 } 00530 autoFormatLanguage->insertStringList(lst); 00531 00532 connect(autoFormatLanguage->listBox(), SIGNAL(selected ( const QString & )), this, SLOT(changeAutoformatLanguage(const QString & ))); 00533 00534 grid->addMultiCellWidget( autoFormatLanguage, 0, 0, 4, 6 ); 00535 QLabel *lblAutoFormatLanguage = new QLabel( i18n("Replacements and exceptions for language:"), tab3); 00536 grid->addMultiCellWidget( lblAutoFormatLanguage, 0, 0, 0, 3 ); 00537 00538 cbAdvancedAutoCorrection = new QCheckBox( tab3 ); 00539 cbAdvancedAutoCorrection->setText( i18n("Enable word replacement") ); 00540 connect( cbAdvancedAutoCorrection, SIGNAL(clicked ()), this, SLOT( slotChangeAdvancedAutoCorrection())); 00541 grid->addMultiCellWidget( cbAdvancedAutoCorrection, 1, 1, 0, 6 ); 00542 00543 cbAutoCorrectionWithFormat = new QCheckBox( tab3 ); 00544 cbAutoCorrectionWithFormat->setText( i18n("Replace text with format") ); 00545 grid->addMultiCellWidget( cbAutoCorrectionWithFormat, 2, 2, 0, 6 ); 00546 00547 lblFind = new QLabel( i18n( "&Find:" ), tab3 ); 00548 grid->addWidget( lblFind, 3, 0 ); 00549 00550 m_find = new KoAutoFormatLineEdit( tab3 ); 00551 grid->addWidget( m_find, 3, 1 ); 00552 00553 lblFind->setBuddy( m_find ); 00554 00555 connect( m_find, SIGNAL( textChanged( const QString & ) ), 00556 SLOT( slotfind( const QString & ) ) ); 00557 connect( m_find, SIGNAL( keyReturnPressed() ), 00558 SLOT( slotAddEntry())); 00559 00560 pbSpecialChar1 = new QPushButton( "...", tab3 ); 00561 pbSpecialChar1->setFixedWidth( 40 ); 00562 grid->addWidget( pbSpecialChar1, 3, 2 ); 00563 00564 connect(pbSpecialChar1,SIGNAL(clicked()), SLOT(chooseSpecialChar1())); 00565 00566 lblReplace = new QLabel( i18n( "&Replace:" ), tab3 ); 00567 grid->addWidget( lblReplace, 3, 3 ); 00568 00569 m_replace = new KoAutoFormatLineEdit( tab3 ); 00570 grid->addWidget( m_replace, 3, 4 ); 00571 00572 lblReplace->setBuddy( m_replace ); 00573 00574 connect( m_replace, SIGNAL( textChanged( const QString & ) ), 00575 SLOT( slotfind2( const QString & ) ) ); 00576 connect( m_replace, SIGNAL( keyReturnPressed() ), 00577 SLOT( slotAddEntry())); 00578 00579 pbSpecialChar2 = new QPushButton( "...", tab3 ); 00580 pbSpecialChar2->setFixedWidth( 40 ); 00581 grid->addWidget( pbSpecialChar2, 3, 5 ); 00582 00583 connect(pbSpecialChar2,SIGNAL(clicked()), SLOT(chooseSpecialChar2())); 00584 00585 pbAdd = new QPushButton( i18n( "&Add"), tab3 ); 00586 grid->addWidget( pbAdd, 3, 6 ); 00587 00588 connect(pbAdd,SIGNAL(clicked()),this, SLOT(slotAddEntry())); 00589 00590 m_pListView = new KListView( tab3 ); 00591 m_pListView->addColumn( i18n( "Find" ) ); 00592 m_pListView->addColumn( i18n( "Replace" ) ); 00593 m_pListView->setAllColumnsShowFocus( true ); 00594 grid->addMultiCellWidget( m_pListView, 4, 10, 0, 5 ); 00595 00596 connect(m_pListView, SIGNAL(doubleClicked ( QListViewItem * )), 00597 SLOT(slotChangeTextFormatEntry()) ); 00598 connect(m_pListView, SIGNAL(clicked ( QListViewItem * ) ), 00599 SLOT(slotEditEntry()) ); 00600 00601 pbRemove = new QPushButton( i18n( "Remove" ), tab3 ); 00602 grid->addWidget( pbRemove, 4, 6, Qt::AlignTop ); 00603 00604 connect(pbRemove,SIGNAL(clicked()), SLOT(slotRemoveEntry())); 00605 00606 pbChangeFormat= new QPushButton( i18n( "Change Format..." ), tab3 ); 00607 grid->addWidget( pbChangeFormat, 5, 6, Qt::AlignTop ); 00608 00609 connect( pbChangeFormat, SIGNAL(clicked()), SLOT(slotChangeTextFormatEntry())); 00610 grid->setRowStretch( 2, 1 ); 00611 00612 pbClearFormat= new QPushButton( i18n( "Clear Format" ), tab3 ); 00613 grid->addWidget( pbClearFormat, 6, 6, Qt::AlignTop ); 00614 00615 connect( pbClearFormat, SIGNAL(clicked()), SLOT(slotClearTextFormatEntry())); 00616 grid->setRowStretch( 2, 1 ); 00617 00618 initTab3(); 00619 slotChangeAdvancedAutoCorrection(); 00620 pbRemove->setEnabled(false); 00621 pbChangeFormat->setEnabled( false ); 00622 pbAdd->setEnabled(false); 00623 pbClearFormat->setEnabled( false); 00624 00625 } 00626 00627 void KoAutoFormatDia::initTab3() 00628 { 00629 if ( !changeLanguage || noSignal) 00630 { 00631 initialLanguage=m_autoFormat.getConfigAutoFormatLanguage( ); 00632 if ( initialLanguage.isEmpty() ) 00633 autoFormatLanguage->setCurrentItem(0); 00634 else 00635 { 00636 KoExceptionLanguageName::Iterator it = exceptionLanguageName.begin(); 00637 for ( ; it != exceptionLanguageName.end() ; ++it ) 00638 { 00639 if ( it.data() == initialLanguage) 00640 { 00641 autoFormatLanguage->setCurrentText(it.key()); 00642 break; 00643 } 00644 00645 } 00646 } 00647 } 00648 //force to re-readconfig when we reset config and we change a entry 00649 if ( autocorrectionEntryChanged ) 00650 { 00651 if ( !changeLanguage ) 00652 m_docAutoFormat->configAutoFormatLanguage( initialLanguage); 00653 m_docAutoFormat->readConfig( true ); 00654 } 00655 cbAdvancedAutoCorrection->setChecked(m_autoFormat.getConfigAdvancedAutoCorrect()); 00656 cbAutoCorrectionWithFormat->setChecked( m_autoFormat.getConfigCorrectionWithFormat()); 00657 m_pListView->clear(); 00658 00659 QDictIterator<KoAutoFormatEntry> it( m_docAutoFormat->getAutoFormatEntries()); 00660 for( ; it.current(); ++it ) 00661 { 00662 ( void )new QListViewItem( m_pListView, it.currentKey(), it.current()->replace() ); 00663 } 00664 } 00665 00666 void KoAutoFormatDia::slotChangeAdvancedAutoCorrection() 00667 { 00668 bool state = cbAdvancedAutoCorrection->isChecked(); 00669 cbAutoCorrectionWithFormat->setEnabled( state ); 00670 pbSpecialChar2->setEnabled( state ); 00671 pbSpecialChar1->setEnabled( state ); 00672 m_replace->setEnabled( state); 00673 m_find->setEnabled( state); 00674 m_pListView->setEnabled( state); 00675 00676 state = state && !m_replace->text().isEmpty() && !m_find->text().isEmpty(); 00677 KoAutoFormatEntry * entry=m_docAutoFormat->findFormatEntry(m_find->text()); 00678 pbRemove->setEnabled(state && entry); 00679 pbChangeFormat->setEnabled(state && entry); 00680 pbClearFormat->setEnabled(state && entry); 00681 pbAdd->setEnabled(state); 00682 } 00683 00684 00685 void KoAutoFormatDia::changeAutoformatLanguage(const QString & text) 00686 { 00687 if ( text==i18n("Default")) 00688 m_docAutoFormat->configAutoFormatLanguage( QString::null); 00689 else 00690 { 00691 m_docAutoFormat->configAutoFormatLanguage( exceptionLanguageName.find(text).data()); 00692 } 00693 00694 if ( !noSignal ) 00695 { 00696 changeLanguage=true; 00697 m_docAutoFormat->readConfig( true ); 00698 initTab3(); 00699 initTab4(); 00700 autocorrectionEntryChanged=true; 00701 cbAutoSuperScript->setEnabled( m_docAutoFormat->nbSuperScriptEntry()>0 ); 00702 oSimpleBegin= m_docAutoFormat->getConfigTypographicSimpleQuotes().begin ; 00703 oSimpleEnd= m_docAutoFormat->getConfigTypographicSimpleQuotes().end; 00704 oDoubleBegin= m_docAutoFormat->getConfigTypographicDoubleQuotes().begin; 00705 oDoubleEnd= m_docAutoFormat->getConfigTypographicDoubleQuotes().end; 00706 bulletStyle= m_docAutoFormat->getConfigBulletStyle(); 00707 delete newEntry; 00708 newEntry=0L; 00709 changeLanguage=false; 00710 } 00711 } 00712 00713 void KoAutoFormatDia::setupTab4() 00714 { 00715 tab4 = addPage( i18n( "Exceptions" ) ); 00716 QVBoxLayout *vbox = new QVBoxLayout(tab4, KDialog::marginHint(), 00717 KDialog::spacingHint()); 00718 00719 abbreviation=new KoAutoFormatExceptionWidget(tab4, 00720 i18n("Do not treat as the end of a sentence:"), 00721 m_autoFormat.listException(), 00722 m_autoFormat.getConfigIncludeAbbreviation() , true); 00723 00724 vbox->addWidget( abbreviation ); 00725 00726 twoUpperLetter=new KoAutoFormatExceptionWidget(tab4, 00727 i18n("Accept two uppercase letters in:"), 00728 m_autoFormat.listTwoUpperLetterException(), 00729 m_autoFormat.getConfigIncludeTwoUpperUpperLetterException()); 00730 00731 vbox->addWidget( twoUpperLetter ); 00732 00733 initTab4(); 00734 } 00735 00736 void KoAutoFormatDia::initTab4() 00737 { 00738 abbreviation->setListException( !changeLanguage ? m_autoFormat.listException(): m_docAutoFormat->listException() ); 00739 if ( !changeLanguage ) 00740 { 00741 abbreviation->setAutoInclude( m_docAutoFormat->getConfigIncludeAbbreviation() ); 00742 twoUpperLetter->setAutoInclude( m_docAutoFormat->getConfigIncludeTwoUpperUpperLetterException() ); 00743 } 00744 twoUpperLetter->setListException( !changeLanguage ? m_autoFormat.listTwoUpperLetterException():m_docAutoFormat->listTwoUpperLetterException() ); 00745 } 00746 00747 void KoAutoFormatDia::slotClearTextFormatEntry() 00748 { 00749 bool addNewEntry = (pbAdd->text() == i18n( "&Add" )); 00750 if ( m_pListView->currentItem() || addNewEntry) 00751 { 00752 if ( addNewEntry ) 00753 { 00754 if (newEntry) 00755 newEntry->clearFormatEntryContext(); 00756 } 00757 else 00758 { 00759 KoAutoFormatEntry *entry = m_docAutoFormat->findFormatEntry(m_pListView->currentItem()->text(0)); 00760 entry->clearFormatEntryContext(); 00761 } 00762 autocorrectionEntryChanged= true; 00763 } 00764 } 00765 00766 void KoAutoFormatDia::slotChangeTextFormatEntry() 00767 { 00768 bool addNewEntry = (pbAdd->text() == i18n( "&Add" )); 00769 if ( m_pListView->currentItem() || addNewEntry) 00770 { 00771 KoAutoFormatEntry *entry = 0L; 00772 if ( addNewEntry ) 00773 { 00774 if ( m_replace->text().isEmpty() ) 00775 return; 00776 if ( !newEntry ) 00777 newEntry = new KoAutoFormatEntry( m_replace->text()); 00778 entry =newEntry; 00779 } 00780 else 00781 entry = m_docAutoFormat->findFormatEntry(m_pListView->currentItem()->text(0)); 00782 KoSearchContext *tmpFormat = entry->formatEntryContext(); 00783 bool createNewFormat = false; 00784 00785 if ( !tmpFormat ) 00786 { 00787 tmpFormat = new KoSearchContext(); 00788 createNewFormat = true; 00789 } 00790 00791 KoFormatDia *dia = new KoFormatDia( this, i18n("Change Text Format"), tmpFormat , 0L); 00792 if ( dia->exec()) 00793 { 00794 dia->ctxOptions( ); 00795 if ( createNewFormat ) 00796 entry->setFormatEntryContext( tmpFormat ); 00797 autocorrectionEntryChanged= true; 00798 00799 } 00800 else 00801 { 00802 if ( createNewFormat ) 00803 delete tmpFormat; 00804 } 00805 delete dia; 00806 } 00807 } 00808 00809 void KoAutoFormatDia::slotRemoveEntry() 00810 { 00811 //find entry in listbox 00812 if(m_pListView->currentItem()) 00813 { 00814 m_docAutoFormat->removeAutoFormatEntry(m_pListView->currentItem()->text(0)); 00815 pbAdd->setText(i18n("&Add")); 00816 refreshEntryList(); 00817 autocorrectionEntryChanged= true; 00818 } 00819 } 00820 00821 00822 void KoAutoFormatDia::slotfind( const QString & ) 00823 { 00824 KoAutoFormatEntry *entry = m_docAutoFormat->findFormatEntry(m_find->text()); 00825 if ( entry ) 00826 { 00827 m_replace->setText(entry->replace().latin1()); 00828 pbAdd->setText(i18n("&Modify")); 00829 m_pListView->setCurrentItem(m_pListView->findItem(m_find->text(),0)); 00830 00831 } else { 00832 m_replace->clear(); 00833 pbAdd->setText(i18n("&Add")); 00834 m_pListView->setCurrentItem(0L); 00835 } 00836 slotfind2(""); 00837 } 00838 00839 00840 void KoAutoFormatDia::slotfind2( const QString & ) 00841 { 00842 bool state = !m_replace->text().isEmpty() && !m_find->text().isEmpty(); 00843 KoAutoFormatEntry * entry=m_docAutoFormat->findFormatEntry(m_find->text()); 00844 pbRemove->setEnabled(state && entry); 00845 if ( state && entry ) 00846 { 00847 delete newEntry; 00848 newEntry = 0L; 00849 } 00850 pbChangeFormat->setEnabled(state); 00851 pbClearFormat->setEnabled(state); 00852 pbAdd->setEnabled(state); 00853 } 00854 00855 00856 void KoAutoFormatDia::refreshEntryList() 00857 { 00858 m_pListView->clear(); 00859 QDictIterator<KoAutoFormatEntry> it( m_docAutoFormat->getAutoFormatEntries()); 00860 for( ; it.current(); ++it ) 00861 { 00862 ( void )new QListViewItem( m_pListView, it.currentKey(), it.current()->replace() ); 00863 } 00864 m_pListView->setCurrentItem(m_pListView->firstChild ()); 00865 bool state = !(m_replace->text().isEmpty()) && !(m_find->text().isEmpty()); 00866 //we can delete item, as we search now in listbox and not in m_find lineedit 00867 pbRemove->setEnabled(m_pListView->currentItem() && m_pListView->selectedItem()!=0 ); 00868 pbChangeFormat->setEnabled(state && m_pListView->currentItem() && m_pListView->selectedItem()!=0 ); 00869 pbClearFormat->setEnabled(state && m_pListView->currentItem() && m_pListView->selectedItem()!=0 ); 00870 00871 pbAdd->setEnabled(state); 00872 } 00873 00874 00875 void KoAutoFormatDia::addEntryList(const QString &key, KoAutoFormatEntry *_autoEntry) 00876 { 00877 m_docAutoFormat->addAutoFormatEntry( key, _autoEntry ); 00878 } 00879 00880 00881 00882 void KoAutoFormatDia::editEntryList(const QString &key,const QString &newFindString, KoAutoFormatEntry *_autoEntry) 00883 { 00884 if ( m_docAutoFormat->findFormatEntry(key) && m_docAutoFormat->findFormatEntry(key)->formatEntryContext()) 00885 _autoEntry->setFormatEntryContext( new KoSearchContext(*(m_docAutoFormat->findFormatEntry(key)->formatEntryContext()) )); 00886 m_docAutoFormat->removeAutoFormatEntry( key ); 00887 m_docAutoFormat->addAutoFormatEntry( newFindString, _autoEntry ); 00888 } 00889 00890 00891 void KoAutoFormatDia::slotAddEntry() 00892 { 00893 if(!pbAdd->isEnabled()) 00894 return; 00895 QString repl = m_replace->text(); 00896 QString find = m_find->text(); 00897 if(repl.isEmpty() || find.isEmpty()) 00898 { 00899 KMessageBox::sorry( 0L, i18n( "An area is empty" ) ); 00900 return; 00901 } 00902 if(repl==find) 00903 { 00904 KMessageBox::sorry( 0L, i18n( "Find string is the same as replace string!" ) ); 00905 return; 00906 } 00907 KoAutoFormatEntry *tmp = new KoAutoFormatEntry( repl ); 00908 00909 if(pbAdd->text() == i18n( "&Add" )) 00910 { 00911 if ( newEntry ) 00912 { 00913 newEntry->changeReplace( m_replace->text()); 00914 addEntryList(find, newEntry); 00915 delete tmp; 00916 newEntry = 0L; 00917 } 00918 else 00919 addEntryList(find, tmp); 00920 } 00921 else 00922 editEntryList(find, find, tmp); 00923 m_replace->clear(); 00924 m_find->clear(); 00925 00926 refreshEntryList(); 00927 autocorrectionEntryChanged= true; 00928 } 00929 00930 00931 void KoAutoFormatDia::chooseSpecialChar1() 00932 { 00933 QString f = font().family(); 00934 QChar c = ' '; 00935 if ( KoCharSelectDia::selectChar( f, c, false ) ) 00936 m_find->setText( c ); 00937 } 00938 00939 00940 void KoAutoFormatDia::chooseSpecialChar2() 00941 { 00942 QString f = font().family(); 00943 QChar c = ' '; 00944 if ( KoCharSelectDia::selectChar( f, c, false ) ) 00945 m_replace->setText( c ); 00946 } 00947 00948 00949 void KoAutoFormatDia::slotItemRenamed(QListViewItem *, const QString & , int ) 00950 { 00951 // Wow. This need a redesign (we don't have the old key anymore at this point !) 00952 // -> inherit QListViewItem and store the KoAutoFormatEntry pointer in it. 00953 } 00954 00955 00956 void KoAutoFormatDia::slotEditEntry() 00957 { 00958 if(m_pListView->currentItem()==0) 00959 return; 00960 delete newEntry; 00961 newEntry=0L; 00962 m_find->setText(m_pListView->currentItem()->text(0)); 00963 m_replace->setText(m_pListView->currentItem()->text(1)); 00964 bool state = !m_replace->text().isEmpty() && !m_find->text().isEmpty(); 00965 pbRemove->setEnabled(state); 00966 pbChangeFormat->setEnabled( state ); 00967 pbClearFormat->setEnabled(state); 00968 pbAdd->setEnabled(state); 00969 } 00970 00971 00972 bool KoAutoFormatDia::applyConfig() 00973 { 00974 // First tab 00975 KoAutoFormat::TypographicQuotes tq = m_autoFormat.getConfigTypographicSimpleQuotes(); 00976 tq.replace = cbTypographicSimpleQuotes->isChecked(); 00977 tq.begin = pbSimpleQuote1->text()[ 0 ]; 00978 tq.end = pbSimpleQuote2->text()[ 0 ]; 00979 m_docAutoFormat->configTypographicSimpleQuotes( tq ); 00980 00981 tq = m_autoFormat.getConfigTypographicDoubleQuotes(); 00982 tq.replace = cbTypographicDoubleQuotes->isChecked(); 00983 tq.begin = pbDoubleQuote1->text()[ 0 ]; 00984 tq.end = pbDoubleQuote2->text()[ 0 ]; 00985 m_docAutoFormat->configTypographicDoubleQuotes( tq ); 00986 00987 00988 m_docAutoFormat->configUpperCase( cbUpperCase->isChecked() ); 00989 m_docAutoFormat->configUpperUpper( cbUpperUpper->isChecked() ); 00990 m_docAutoFormat->configAutoDetectUrl( cbDetectUrl->isChecked() ); 00991 00992 m_docAutoFormat->configIgnoreDoubleSpace( cbIgnoreDoubleSpace->isChecked()); 00993 m_docAutoFormat->configRemoveSpaceBeginEndLine( cbRemoveSpaceBeginEndLine->isChecked()); 00994 m_docAutoFormat->configUseBulletStyle(cbUseBulletStyle->isChecked()); 00995 00996 m_docAutoFormat->configBulletStyle(pbBulletStyle->text()[ 0 ]); 00997 00998 m_docAutoFormat->configAutoChangeFormat( cbAutoChangeFormat->isChecked()); 00999 01000 m_docAutoFormat->configAutoReplaceNumber( cbAutoReplaceNumber->isChecked()); 01001 m_docAutoFormat->configAutoNumberStyle(cbUseNumberStyle->isChecked()); 01002 01003 m_docAutoFormat->configAutoSuperScript ( cbAutoSuperScript->isChecked() ); 01004 m_docAutoFormat->configCapitalizeNameOfDays( cbCapitalizeDaysName->isChecked()); 01005 01006 01007 // Second tab 01008 //m_docAutoFormat->copyAutoFormatEntries( m_autoFormat ); 01009 m_docAutoFormat->copyListException(abbreviation->getListException()); 01010 m_docAutoFormat->copyListTwoUpperCaseException(twoUpperLetter->getListException()); 01011 m_docAutoFormat->configAdvancedAutocorrect( cbAdvancedAutoCorrection->isChecked() ); 01012 m_docAutoFormat->configCorrectionWithFormat( cbAutoCorrectionWithFormat->isChecked()); 01013 01014 m_docAutoFormat->configIncludeTwoUpperUpperLetterException( twoUpperLetter->autoInclude()); 01015 m_docAutoFormat->configIncludeAbbreviation( abbreviation->autoInclude()); 01016 01017 QString lang = exceptionLanguageName.find(autoFormatLanguage->currentText()).data(); 01018 if ( lang == i18n("Default") ) 01019 m_docAutoFormat->configAutoFormatLanguage(QString::null); 01020 else 01021 m_docAutoFormat->configAutoFormatLanguage(lang); 01022 01023 // Save to config file 01024 m_docAutoFormat->saveConfig(); 01025 return true; 01026 } 01027 01028 void KoAutoFormatDia::slotOk() 01029 { 01030 if (applyConfig()) 01031 { 01032 KDialogBase::slotOk(); 01033 } 01034 } 01035 01036 void KoAutoFormatDia::slotCancel() 01037 { 01038 //force to reload 01039 if ( autocorrectionEntryChanged ) 01040 { 01041 m_docAutoFormat->configAutoFormatLanguage( initialLanguage); 01042 m_docAutoFormat->readConfig( true ); 01043 } 01044 KDialogBase::slotCancel(); 01045 } 01046 01047 void KoAutoFormatDia::chooseDoubleQuote1() 01048 { 01049 QString f = font().family(); 01050 QChar c = oDoubleBegin; 01051 if ( KoCharSelectDia::selectChar( f, c, false ) ) 01052 { 01053 pbDoubleQuote1->setText( c ); 01054 } 01055 01056 } 01057 01058 void KoAutoFormatDia::chooseDoubleQuote2() 01059 { 01060 QString f = font().family(); 01061 QChar c = oDoubleEnd; 01062 if ( KoCharSelectDia::selectChar( f, c, false ) ) 01063 { 01064 pbDoubleQuote2->setText( c ); 01065 } 01066 } 01067 01068 01069 void KoAutoFormatDia::defaultDoubleQuote() 01070 { 01071 pbDoubleQuote1->setText(m_docAutoFormat->getDefaultTypographicDoubleQuotes().begin); 01072 pbDoubleQuote2->setText(m_docAutoFormat->getDefaultTypographicDoubleQuotes().end); 01073 } 01074 01075 void KoAutoFormatDia::chooseSimpleQuote1() 01076 { 01077 QString f = font().family(); 01078 QChar c = oSimpleBegin; 01079 if ( KoCharSelectDia::selectChar( f, c, false ) ) 01080 { 01081 pbSimpleQuote1->setText( c ); 01082 } 01083 } 01084 01085 void KoAutoFormatDia::chooseSimpleQuote2() 01086 { 01087 QString f = font().family(); 01088 QChar c = oSimpleEnd; 01089 if ( KoCharSelectDia::selectChar( f, c, false ) ) 01090 { 01091 pbSimpleQuote2->setText( c ); 01092 } 01093 } 01094 01095 void KoAutoFormatDia::defaultSimpleQuote() 01096 { 01097 01098 pbSimpleQuote1->setText(m_docAutoFormat->getDefaultTypographicSimpleQuotes().begin); 01099 pbSimpleQuote2->setText(m_docAutoFormat->getDefaultTypographicSimpleQuotes().end); 01100 } 01101 01102 01103 void KoAutoFormatDia::chooseBulletStyle() 01104 { 01105 QString f = font().family(); 01106 QChar c = bulletStyle; 01107 if ( KoCharSelectDia::selectChar( f, c, false ) ) 01108 { 01109 pbBulletStyle->setText( c ); 01110 } 01111 } 01112 01113 void KoAutoFormatDia::defaultBulletStyle() 01114 { 01115 pbBulletStyle->setText( "" ); 01116 } 01117 01118 void KoAutoFormatDia::slotChangeStateSimple(bool b) 01119 { 01120 pbSimpleQuote1->setEnabled(b); 01121 pbSimpleQuote2->setEnabled(b); 01122 pbSimpleDefault->setEnabled(b); 01123 } 01124 01125 void KoAutoFormatDia::slotChangeStateDouble(bool b) 01126 { 01127 pbDoubleQuote1->setEnabled(b); 01128 pbDoubleQuote2->setEnabled(b); 01129 pbDoubleDefault->setEnabled(b); 01130 } 01131 01132 01133 /******************************************************************/ 01134 /* Class: KoCompletionDia */ 01135 /******************************************************************/ 01136 01137 KoCompletionDia::KoCompletionDia( QWidget *parent, const char *name, 01138 KoAutoFormat * autoFormat ) 01139 : KDialogBase( parent, name , true, i18n( "Completion" ), Ok|Cancel|User1, 01140 Ok, true, KGuiItem( i18n( "&Reset" ), "undo" ) ), 01141 m_autoFormat( *autoFormat ), 01142 m_docAutoFormat( autoFormat ) 01143 { 01144 setup(); 01145 slotResetConf(); 01146 setInitialSize( QSize( 500, 500 ) ); 01147 connect( this, SIGNAL( user1Clicked() ), this, SLOT(slotResetConf())); 01148 changeButtonStatus(); 01149 } 01150 01151 void KoCompletionDia::changeButtonStatus() 01152 { 01153 bool state = cbAllowCompletion->isChecked(); 01154 cbAppendSpace->setEnabled( state ); 01155 cbAddCompletionWord->setEnabled( state ); 01156 pbRemoveCompletionEntry->setEnabled( state ); 01157 pbSaveCompletionEntry->setEnabled( state ); 01158 pbAddCompletionEntry->setEnabled( state ); 01159 m_lbListCompletion->setEnabled( state ); 01160 m_minWordLength->setEnabled( state ); 01161 m_maxNbWordCompletion->setEnabled( state ); 01162 01163 state = state && (m_lbListCompletion->count()!=0 && !m_lbListCompletion->currentText().isEmpty()); 01164 pbRemoveCompletionEntry->setEnabled( state ); 01165 } 01166 01167 void KoCompletionDia::setup() 01168 { 01169 QVBox *page = makeVBoxMainWidget(); 01170 cbAllowCompletion = new QCheckBox( page ); 01171 cbAllowCompletion->setText( i18n( "E&nable completion" ) ); 01172 connect(cbAllowCompletion, SIGNAL(toggled ( bool )), this, SLOT( changeButtonStatus())); 01173 // TODO whatsthis or text, to tell about the key to use for autocompletion.... 01174 cbAddCompletionWord = new QCheckBox( page ); 01175 cbAddCompletionWord->setText( i18n( "&Automatically add new words to completion list" ) ); 01176 QWhatsThis::add( cbAddCompletionWord, i18n("If this option is enabled, any word typed in this document will automatically be added to the list of words used by the completion." ) ); 01177 01178 m_lbListCompletion = new QListBox( page ); 01179 connect( m_lbListCompletion, SIGNAL( selected ( const QString & ) ), this, SLOT( slotCompletionWordSelected( const QString & ))); 01180 connect( m_lbListCompletion, SIGNAL( highlighted ( const QString & ) ), this, SLOT( slotCompletionWordSelected( const QString & ))); 01181 01182 pbAddCompletionEntry = new QPushButton( i18n("Add Completion Entry..."), page); 01183 connect( pbAddCompletionEntry, SIGNAL( clicked() ), this, SLOT( slotAddCompletionEntry())); 01184 01185 pbRemoveCompletionEntry = new QPushButton(i18n( "R&emove Completion Entry"), page ); 01186 connect( pbRemoveCompletionEntry, SIGNAL( clicked() ), this, SLOT( slotRemoveCompletionEntry())); 01187 01188 pbSaveCompletionEntry= new QPushButton(i18n( "&Save Completion List"), page ); 01189 connect( pbSaveCompletionEntry, SIGNAL( clicked() ), this, SLOT( slotSaveCompletionEntry())); 01190 01191 01192 m_minWordLength = new KIntNumInput( page ); 01193 m_minWordLength->setRange ( 5, 100,1,true ); 01194 m_minWordLength->setLabel( i18n( "&Minimum word length:" ) ); 01195 01196 m_maxNbWordCompletion = new KIntNumInput( page ); 01197 m_maxNbWordCompletion->setRange( 1, 500, 1, true); 01198 m_maxNbWordCompletion->setLabel( i18n( "Ma&ximum number of completion words:" ) ); 01199 01200 cbAppendSpace = new QCheckBox( page ); 01201 cbAppendSpace->setText( i18n( "A&ppend space" ) ); 01202 01203 m_listCompletion = m_docAutoFormat->listCompletion(); 01204 } 01205 01206 void KoCompletionDia::slotResetConf() 01207 { 01208 cbAllowCompletion->setChecked( m_autoFormat.getConfigCompletion()); 01209 cbAddCompletionWord->setChecked( m_autoFormat.getConfigAddCompletionWord()); 01210 m_lbListCompletion->clear(); 01211 QStringList lst = m_docAutoFormat->listCompletion(); 01212 m_lbListCompletion->insertStringList( lst ); 01213 if( lst.isEmpty() || m_lbListCompletion->currentText().isEmpty()) 01214 pbRemoveCompletionEntry->setEnabled( false ); 01215 m_minWordLength->setValue ( m_docAutoFormat->getConfigMinWordLength() ); 01216 m_maxNbWordCompletion->setValue ( m_docAutoFormat->getConfigNbMaxCompletionWord() ); 01217 cbAppendSpace->setChecked( m_autoFormat.getConfigAppendSpace() ); 01218 changeButtonStatus(); 01219 } 01220 01221 void KoCompletionDia::slotSaveCompletionEntry() 01222 { 01223 01224 KConfig config("kofficerc"); 01225 KConfigGroupSaver cgs( &config, "Completion Word" ); 01226 config.writeEntry( "list", m_listCompletion ); 01227 config.sync(); 01228 KMessageBox::information( this, i18n( 01229 "Completion list saved.\nIt will be used for all documents " 01230 "from now on."), i18n("Completion List Saved") ); 01231 } 01232 01233 void KoCompletionDia::slotAddCompletionEntry() 01234 { 01235 bool ok; 01236 QString newWord = KLineEditDlg::getText( i18n("Add Completion Entry"),i18n("Enter entry:"),QString::null, &ok, this ); 01237 if ( ok ) 01238 { 01239 if ( !m_listCompletion.contains( newWord )) 01240 { 01241 m_listCompletion.append( newWord ); 01242 m_lbListCompletion->insertItem( newWord ); 01243 pbRemoveCompletionEntry->setEnabled( !m_lbListCompletion->currentText().isEmpty() ); 01244 } 01245 01246 } 01247 } 01248 01249 void KoCompletionDia::slotOk() 01250 { 01251 if (applyConfig()) 01252 { 01253 KDialogBase::slotOk(); 01254 } 01255 } 01256 01257 bool KoCompletionDia::applyConfig() 01258 { 01259 01260 m_docAutoFormat->configCompletion( cbAllowCompletion->isChecked()); 01261 m_docAutoFormat->configAppendSpace( cbAppendSpace->isChecked() ); 01262 m_docAutoFormat->configMinWordLength( m_minWordLength->value() ); 01263 m_docAutoFormat->configNbMaxCompletionWord( m_maxNbWordCompletion->value () ); 01264 m_docAutoFormat->configAddCompletionWord( cbAddCompletionWord->isChecked()); 01265 01266 m_docAutoFormat->getCompletion()->setItems( m_listCompletion ); 01267 // Save to config file 01268 m_docAutoFormat->saveConfig(); 01269 return true; 01270 } 01271 01272 void KoCompletionDia::slotRemoveCompletionEntry() 01273 { 01274 QString text = m_lbListCompletion->currentText(); 01275 if( !text.isEmpty() ) 01276 { 01277 m_listCompletion.remove( text ); 01278 m_lbListCompletion->removeItem( m_lbListCompletion->currentItem () ); 01279 if( m_lbListCompletion->count()==0 ) 01280 pbRemoveCompletionEntry->setEnabled( false ); 01281 } 01282 } 01283 01284 void KoCompletionDia::slotCompletionWordSelected( const QString & word) 01285 { 01286 pbRemoveCompletionEntry->setEnabled( !word.isEmpty() ); 01287 }
KDE Logo
This file is part of the documentation for lib Library Version 1.3.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Sep 24 18:22:23 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003