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 <qtooltip.h>
00039 #include <kdebug.h>
00040 #include <knuminput.h>
00041 #include <kcompletion.h>
00042 #include <kconfig.h>
00043 #include <kinputdialog.h>
00044 #include <qcombobox.h>
00045 #include <qdir.h>
00046 #include <koSearchDia.h>
00047 
00048 KoAutoFormatLineEdit::KoAutoFormatLineEdit ( QWidget * parent, const char * name )
00049     : QLineEdit(parent,name)
00050 {
00051 }
00052 
00053 void KoAutoFormatLineEdit::keyPressEvent ( QKeyEvent *ke )
00054 {
00055     if( ke->key()  == QKeyEvent::Key_Return ||
00056         ke->key()  == QKeyEvent::Key_Enter )
00057     {
00058         emit keyReturnPressed();
00059         return;
00060     }
00061     QLineEdit::keyPressEvent (ke);
00062 }
00063 
00064 
00065 /******************************************************************/
00066 /* Class: KoAutoFormatExceptionWidget                             */
00067 /******************************************************************/
00068 
00069 KoAutoFormatExceptionWidget::KoAutoFormatExceptionWidget(QWidget *parent, const QString &name,const QStringList &_list, bool _autoInclude, bool _abreviation)
00070     :QWidget( parent )
00071 {
00072     m_bAbbreviation=_abreviation;
00073     m_listException=_list;
00074     QGridLayout *grid = new QGridLayout(this, 4, 2, KDialog::marginHint(), KDialog::spacingHint());
00075 
00076     QLabel *lab=new QLabel(name,this);
00077     grid->addMultiCellWidget(lab,0,0,0,1);
00078 
00079     exceptionLine = new KoAutoFormatLineEdit( this );
00080     grid->addWidget(exceptionLine,1,0);
00081 
00082     connect(exceptionLine,SIGNAL(keyReturnPressed()),SLOT(slotAddException()));
00083     connect(exceptionLine ,SIGNAL(textChanged ( const QString & )),
00084             SLOT(textChanged ( const QString & )));
00085 
00086     pbAddException=new QPushButton(i18n("Add"),this);
00087     connect(pbAddException, SIGNAL(clicked()),SLOT(slotAddException()));
00088     grid->addWidget(pbAddException,1,1);
00089 
00090     pbAddException->setEnabled(false);
00091 
00092     pbRemoveException=new QPushButton(i18n("Remove"),this);
00093     connect(pbRemoveException, SIGNAL(clicked()),SLOT(slotRemoveException()));
00094     grid->addWidget(pbRemoveException,2,1,Qt::AlignTop);
00095 
00096     exceptionList=new QListBox(this);
00097     exceptionList->insertStringList(m_listException);
00098     exceptionList->sort();
00099     grid->addWidget(exceptionList,2,0);
00100 
00101     grid->setRowStretch( 2, 1 );
00102 
00103     connect( exceptionList , SIGNAL(selectionChanged () ),
00104             this,SLOT(slotExceptionListSelected()) );
00105 
00106     pbRemoveException->setEnabled( exceptionList->currentItem()!=-1);
00107 
00108     cbAutoInclude = new QCheckBox( i18n("Autoinclude"), this );
00109     grid->addWidget(cbAutoInclude,3,0);
00110     cbAutoInclude->setChecked( _autoInclude );
00111 }
00112 
00113 void KoAutoFormatExceptionWidget::textChanged ( const QString &_text )
00114 {
00115     pbAddException->setEnabled(!_text.isEmpty());
00116 }
00117 
00118 void KoAutoFormatExceptionWidget::slotAddException()
00119 {
00120     QString text=exceptionLine->text().stripWhiteSpace();
00121     if(!text.isEmpty())
00122     {
00123         if(text.at(text.length()-1)!='.' && m_bAbbreviation)
00124             text=text+".";
00125         if( m_listException.findIndex( text )==-1)
00126         {
00127             m_listException<<text;
00128 
00129             exceptionList->clear();
00130             exceptionList->insertStringList(m_listException);
00131             exceptionList->sort();
00132             pbRemoveException->setEnabled( exceptionList->currentItem()!=-1);
00133             pbAddException->setEnabled(false);
00134         }
00135         exceptionLine->clear();
00136     }
00137 }
00138 
00139 void KoAutoFormatExceptionWidget::slotRemoveException()
00140 {
00141     if(!exceptionList->currentText().isEmpty())
00142     {
00143         m_listException.remove(exceptionList->currentText());
00144         exceptionList->clear();
00145         pbAddException->setEnabled(false);
00146         pbRemoveException->setEnabled( exceptionList->currentItem()!=-1);
00147         exceptionList->insertStringList(m_listException);
00148         exceptionLine->clear();
00149     }
00150 }
00151 
00152 bool KoAutoFormatExceptionWidget::autoInclude()
00153 {
00154     return cbAutoInclude->isChecked();
00155 }
00156 
00157 void KoAutoFormatExceptionWidget::setListException( const QStringList &list)
00158 {
00159     exceptionList->clear();
00160     exceptionList->insertStringList(list);
00161 }
00162 
00163 void KoAutoFormatExceptionWidget::setAutoInclude(bool b)
00164 {
00165     cbAutoInclude->setChecked( b );
00166 }
00167 
00168 void KoAutoFormatExceptionWidget::slotExceptionListSelected()
00169 {
00170     pbRemoveException->setEnabled( exceptionList->currentItem()!=-1 );
00171 }
00172 
00173 /******************************************************************/
00174 /* Class: KoAutoFormatDia                                         */
00175 /******************************************************************/
00176 
00177 KoAutoFormatDia::KoAutoFormatDia( QWidget *parent, const char *name,
00178       KoAutoFormat * autoFormat )
00179     : KDialogBase( Tabbed, i18n("Autocorrection"), Ok | Cancel | User1, Ok,
00180       parent, name, true, true, KGuiItem( i18n( "&Reset" ), "undo" )),
00181       oSimpleBegin( autoFormat->getConfigTypographicSimpleQuotes().begin ),
00182       oSimpleEnd( autoFormat->getConfigTypographicSimpleQuotes().end ),
00183       oDoubleBegin( autoFormat->getConfigTypographicDoubleQuotes().begin ),
00184       oDoubleEnd( autoFormat->getConfigTypographicDoubleQuotes().end ),
00185       bulletStyle( autoFormat->getConfigBulletStyle()),
00186       m_autoFormat( *autoFormat ),
00187       m_docAutoFormat( autoFormat )
00188 {
00189     noSignal=true;
00190     newEntry = 0L;
00191     autocorrectionEntryChanged= false;
00192     changeLanguage = false;
00193 
00194     setupTab1();
00195     setupTab2();
00196     setupTab3();
00197     setupTab4();
00198     setInitialSize( QSize(500, 300) );
00199     connect( this, SIGNAL( user1Clicked() ), this, SLOT(slotResetConf()));
00200     noSignal=false;
00201 }
00202 
00203 KoAutoFormatDia::~KoAutoFormatDia()
00204 {
00205     delete newEntry;
00206 }
00207 
00208 void KoAutoFormatDia::slotResetConf()
00209 {
00210     switch( activePageIndex() ) {
00211     case 0:
00212         initTab1();
00213         break;
00214     case 1:
00215         initTab2();
00216         break;
00217     case 2:
00218         initTab3();
00219         break;
00220     case 3:
00221         initTab4();
00222         break;
00223     default:
00224         break;
00225     }
00226 }
00227 
00228 void KoAutoFormatDia::setupTab1()
00229 {
00230     tab1 = addPage( i18n( "Simple Autocorrection" ) );
00231     QVBoxLayout *vbox = new QVBoxLayout(tab1, KDialog::marginHint(),
00232             KDialog::spacingHint());
00233 
00234     cbUpperCase = new QCheckBox( tab1 );
00235     cbUpperCase->setText( i18n(
00236             "Convert &first letter of a sentence automatically to uppercase\n"
00237             "(e.g. \"my house. in this town\" to \"my house. In this town\")"
00238             ) );
00239     QWhatsThis::add( cbUpperCase, i18n(
00240             "Detect when a new sentence is started and always ensure that"
00241             " the first character is an uppercase character."));
00242 
00243     vbox->addWidget(cbUpperCase);
00244 
00245 
00246     cbUpperUpper = new QCheckBox( tab1 );
00247     cbUpperUpper->setText( i18n(
00248             "Convert &two uppercase characters to one uppercase and one"
00249             " lowercase character\n (e.g. PErfect to Perfect)" ) );
00250     QWhatsThis::add( cbUpperUpper, i18n(
00251             "All words are checked for the common mistake of holding the "
00252             "shift key down a bit too long. If some words must have two "
00253             "uppercase characters, then those exceptions should be added in "
00254             "the 'Exceptions' tab."));
00255 
00256     vbox->addWidget(cbUpperUpper);
00257 
00258     cbDetectUrl=new QCheckBox( tab1 );
00259     cbDetectUrl->setText( i18n( "Autoformat &URLs" ) );
00260     QWhatsThis::add( cbDetectUrl, i18n(
00261             "Detect when a URL (Uniform Resource Locator) is typed and "
00262             "provide formatting that matches the way an Internet browser "
00263             "would show a URL."));
00264 
00265     vbox->addWidget(cbDetectUrl);
00266 
00267     cbIgnoreDoubleSpace=new QCheckBox( tab1 );
00268     cbIgnoreDoubleSpace->setText( i18n( "&Suppress double spaces" ) );
00269     QWhatsThis::add( cbIgnoreDoubleSpace, i18n(
00270             "Make sure that more than one space cannot be typed, as this is a "
00271             "common mistake which is quite hard to find in formatted text."));
00272 
00273     vbox->addWidget(cbIgnoreDoubleSpace);
00274 
00275     cbRemoveSpaceBeginEndLine=new QCheckBox( tab1 );
00276     cbRemoveSpaceBeginEndLine->setText( i18n(
00277             "R&emove spaces at the beginning and end of paragraphs" ) );
00278     QWhatsThis::add( cbRemoveSpaceBeginEndLine, i18n(
00279             "Keep correct formatting and indenting of sentences by "
00280             "automatically removing spaces typed at the beginning and end of "
00281             "a paragraph."));
00282 
00283     vbox->addWidget(cbRemoveSpaceBeginEndLine);
00284 
00285     cbAutoChangeFormat=new QCheckBox( tab1 );
00286     cbAutoChangeFormat->setText( i18n(
00287             "Automatically do &bold and underline formatting") );
00288     QWhatsThis::add( cbAutoChangeFormat, i18n(
00289             "When you use _underline_ or *bold*, the text between the "
00290             "underscores or asterisks will be converted to underlined or "
00291             "bold text.") );
00292 
00293     vbox->addWidget(cbAutoChangeFormat);
00294 
00295     cbAutoReplaceNumber=new QCheckBox( tab1 );
00296     cbAutoReplaceNumber->setText( i18n(
00297             "We add the 1/2 char at the %1", "Re&place 1/2... with %1..." )
00298             .arg( QString( "½" ) ) );
00299     QWhatsThis::add( cbAutoReplaceNumber, i18n(
00300             "Most standard fraction notations will be converted when available"
00301             ) );
00302 
00303     vbox->addWidget(cbAutoReplaceNumber);
00304 
00305     cbUseNumberStyle=new QCheckBox( tab1 );
00306     cbUseNumberStyle->setText( i18n(
00307             "Use &autonumbering for numbered paragraphs" ) );
00308     QWhatsThis::add( cbUseNumberStyle, i18n(
00309             "When typing '1)' or similar in front of a paragraph, "
00310             "automatically convert the paragraph to use that numbering style. "
00311             "This has the advantage that further paragraphs will also be "
00312             "numbered and the spacing is done correctly.") );
00313 
00314     vbox->addWidget(cbUseNumberStyle);
00315 
00316     cbAutoSuperScript = new QCheckBox( tab1 );
00317     cbAutoSuperScript->setText( i18n("Rep&lace 1st... with 1^st..."));
00318     cbAutoSuperScript->setEnabled( m_docAutoFormat->nbSuperScriptEntry()>0 );
00319 
00320     vbox->addWidget(cbAutoSuperScript);
00321     cbCapitalizeDaysName = new QCheckBox( tab1 );
00322     cbCapitalizeDaysName->setText( i18n("Capitalize name of days"));
00323     vbox->addWidget(cbCapitalizeDaysName);
00324 
00325     cbUseBulletStyle=new QCheckBox( tab1 );
00326     cbUseBulletStyle->setText( i18n(
00327             "Use l&ist-formatting for bulleted paragraphs" ) );
00328     QWhatsThis::add( cbUseBulletStyle, i18n(
00329             "When typing '*' or '-' in front of a paragraph, automatically "
00330             "convert the paragraph to use that list-style. Using a list-style "
00331             "formatting means that a correct bullet is used to draw the list."
00332             ) );
00333 
00334     connect( cbUseBulletStyle, SIGNAL( toggled( bool ) ),
00335             SLOT( slotBulletStyleToggled( bool ) ) );
00336 
00337     vbox->addWidget(cbUseBulletStyle);
00338     QHBoxLayout *hbox = new QHBoxLayout( );
00339 
00340     hbox->addSpacing( 20 );
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 = addPage( i18n( "Custom Quotes" ) );
00388 
00389     QVBoxLayout *vbox = new QVBoxLayout(tab2, KDialog::marginHint(),
00390             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     QHBoxLayout *hbox = new QHBoxLayout( );
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::reverseLayout()) {
00411         hbox->addWidget( pbDoubleQuote2 );
00412         hbox->addWidget( pbDoubleQuote1 );
00413     } else {
00414         hbox->addWidget( pbDoubleQuote1 );
00415         hbox->addWidget( pbDoubleQuote2 );
00416     }
00417 
00418     hbox->addSpacing( 20 );
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 QHBoxLayout( );
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::reverseLayout()) {
00452         hbox->addWidget( pbSimpleQuote2 );
00453         hbox->addWidget( pbSimpleQuote1 );
00454     } else {
00455         hbox->addWidget( pbSimpleQuote1 );
00456         hbox->addWidget( pbSimpleQuote2 );
00457     }
00458 
00459     hbox->addSpacing( 20 );
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 = addPage( i18n( "Advanced Autocorrection" ) );
00497 
00498     QLabel *lblFind, *lblReplace;
00499 
00500     QGridLayout *grid = new QGridLayout( tab3, 3, 7, KDialog::marginHint(),
00501             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->insertStringList(lst);
00536 
00537     connect(autoFormatLanguage->listBox(), SIGNAL(selected ( const QString & )), this, SLOT(changeAutoformatLanguage(const QString & )));
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     QToolTip::add( pbSpecialChar1, 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     QToolTip::add( pbSpecialChar2, 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 KListView( 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 ( QListViewItem * )),
00604              SLOT(slotChangeTextFormatEntry()) );
00605     connect(m_pListView, SIGNAL(clicked ( QListViewItem * ) ),
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     grid->setRowStretch( 2, 1 );
00618 
00619     pbClearFormat= new QPushButton( i18n( "Clear Format" ), tab3 );
00620     grid->addWidget( pbClearFormat, 6, 6, Qt::AlignTop );
00621 
00622     connect( pbClearFormat, SIGNAL(clicked()), SLOT(slotClearTextFormatEntry()));
00623     grid->setRowStretch( 2, 1 );
00624 
00625     initTab3();
00626     slotChangeAdvancedAutoCorrection();
00627     pbRemove->setEnabled(false);
00628     pbChangeFormat->setEnabled( false );
00629     pbAdd->setEnabled(false);
00630     pbClearFormat->setEnabled( false);
00631 
00632 }
00633 
00634 void KoAutoFormatDia::initTab3()
00635 {
00636     if ( !changeLanguage || noSignal)
00637     {
00638         initialLanguage=m_autoFormat.getConfigAutoFormatLanguage( );
00639         if ( initialLanguage.isEmpty() )
00640             autoFormatLanguage->setCurrentItem(0);
00641         else
00642         {
00643             KoExceptionLanguageName::Iterator it = exceptionLanguageName.begin();
00644             for ( ; it != exceptionLanguageName.end() ; ++it )
00645             {
00646                 if ( it.data() == initialLanguage)
00647                 {
00648                     autoFormatLanguage->setCurrentText(it.key());
00649                     break;
00650                 }
00651 
00652             }
00653         }
00654     }
00655     //force to re-readconfig when we reset config and we change a entry
00656     if ( autocorrectionEntryChanged )
00657     {
00658         if ( !changeLanguage )
00659             m_docAutoFormat->configAutoFormatLanguage( initialLanguage);
00660         m_docAutoFormat->readConfig( true );
00661     }
00662     cbAdvancedAutoCorrection->setChecked(m_autoFormat.getConfigAdvancedAutoCorrect());
00663     cbAutoCorrectionWithFormat->setChecked( m_autoFormat.getConfigCorrectionWithFormat());
00664     m_pListView->clear();
00665 
00666     QDictIterator<KoAutoFormatEntry> it( m_docAutoFormat->getAutoFormatEntries());
00667     for( ; it.current(); ++it )
00668     {
00669         ( void )new QListViewItem( m_pListView, it.currentKey(), it.current()->replace() );
00670     }
00671 }
00672 
00673 void KoAutoFormatDia::slotChangeAdvancedAutoCorrection()
00674 {
00675     bool state = cbAdvancedAutoCorrection->isChecked();
00676     cbAutoCorrectionWithFormat->setEnabled( state );
00677     pbSpecialChar2->setEnabled( state );
00678     pbSpecialChar1->setEnabled( state );
00679     m_replace->setEnabled( state);
00680     m_find->setEnabled( state);
00681     m_pListView->setEnabled( state);
00682 
00683     state = state && !m_replace->text().isEmpty() && !m_find->text().isEmpty();
00684     KoAutoFormatEntry * entry=m_docAutoFormat->findFormatEntry(m_find->text());
00685     pbRemove->setEnabled(state && entry);
00686     pbChangeFormat->setEnabled(state && entry);
00687     pbClearFormat->setEnabled(state && entry);
00688     pbAdd->setEnabled(state);
00689 }
00690 
00691 
00692 void KoAutoFormatDia::changeAutoformatLanguage(const QString & text)
00693 {
00694     if ( text==i18n("Default"))
00695         m_docAutoFormat->configAutoFormatLanguage( QString::null);
00696     else
00697     {
00698         m_docAutoFormat->configAutoFormatLanguage( exceptionLanguageName.find(text).data());
00699     }
00700     if ( !noSignal )
00701     {
00702         changeLanguage=true;
00703         m_docAutoFormat->readConfig( true );
00704         initTab3();
00705         initTab4();
00706         autocorrectionEntryChanged=true;
00707         cbAutoSuperScript->setEnabled( m_docAutoFormat->nbSuperScriptEntry()>0 );
00708         oSimpleBegin= m_docAutoFormat->getConfigTypographicSimpleQuotes().begin ;
00709         oSimpleEnd= m_docAutoFormat->getConfigTypographicSimpleQuotes().end;
00710         oDoubleBegin= m_docAutoFormat->getConfigTypographicDoubleQuotes().begin;
00711         oDoubleEnd= m_docAutoFormat->getConfigTypographicDoubleQuotes().end;
00712         bulletStyle= m_docAutoFormat->getConfigBulletStyle();
00713         delete newEntry;
00714         newEntry=0L;
00715         changeLanguage=false;
00716     }
00717 }
00718 
00719 void KoAutoFormatDia::setupTab4()
00720 {
00721     tab4 = addPage( i18n( "Exceptions" ) );
00722     QVBoxLayout *vbox = new QVBoxLayout(tab4, KDialog::marginHint(),
00723             KDialog::spacingHint());
00724 
00725     abbreviation=new KoAutoFormatExceptionWidget(tab4,
00726             i18n("Do not treat as the end of a sentence:"),
00727             m_autoFormat.listException(),
00728             m_autoFormat.getConfigIncludeAbbreviation() , true);
00729 
00730     vbox->addWidget( abbreviation );
00731 
00732     twoUpperLetter=new KoAutoFormatExceptionWidget(tab4,
00733             i18n("Accept two uppercase letters in:"),
00734             m_autoFormat.listTwoUpperLetterException(),
00735             m_autoFormat.getConfigIncludeTwoUpperUpperLetterException());
00736 
00737     vbox->addWidget( twoUpperLetter );
00738 
00739     initTab4();
00740 }
00741 
00742 void KoAutoFormatDia::initTab4()
00743 {
00744     abbreviation->setListException( !changeLanguage ? m_autoFormat.listException(): m_docAutoFormat->listException() );
00745     if ( !changeLanguage )
00746     {
00747         abbreviation->setAutoInclude( m_docAutoFormat->getConfigIncludeAbbreviation() );
00748         twoUpperLetter->setAutoInclude( m_docAutoFormat->getConfigIncludeTwoUpperUpperLetterException() );
00749     }
00750     twoUpperLetter->setListException( !changeLanguage ? m_autoFormat.listTwoUpperLetterException():m_docAutoFormat->listTwoUpperLetterException() );
00751 }
00752 
00753 void KoAutoFormatDia::slotClearTextFormatEntry()
00754 {
00755     bool addNewEntry = (pbAdd->text() == i18n( "&Add" ));
00756     if ( m_pListView->currentItem() || addNewEntry)
00757     {
00758         if ( addNewEntry )
00759         {
00760             if (newEntry)
00761                 newEntry->clearFormatEntryContext();
00762         }
00763         else
00764         {
00765             KoAutoFormatEntry *entry = m_docAutoFormat->findFormatEntry(m_pListView->currentItem()->text(0));
00766             entry->clearFormatEntryContext();
00767         }
00768         autocorrectionEntryChanged= true;
00769     }
00770 }
00771 
00772 void KoAutoFormatDia::slotChangeTextFormatEntry()
00773 {
00774     bool addNewEntry = (pbAdd->text() == i18n( "&Add" ));
00775     if ( m_pListView->currentItem() || addNewEntry)
00776     {
00777         KoAutoFormatEntry *entry = 0L;
00778         if ( addNewEntry )
00779         {
00780             if ( m_replace->text().isEmpty() )
00781                 return;
00782             if ( !newEntry )
00783                 newEntry = new KoAutoFormatEntry( m_replace->text());
00784             entry =newEntry;
00785         }
00786         else
00787             entry = m_docAutoFormat->findFormatEntry(m_pListView->currentItem()->text(0));
00788         KoSearchContext *tmpFormat = entry->formatEntryContext();
00789         bool createNewFormat = false;
00790 
00791         if ( !tmpFormat )
00792         {
00793             tmpFormat = new KoSearchContext();
00794             createNewFormat = true;
00795         }
00796 
00797         KoFormatDia *dia = new KoFormatDia( this, i18n("Change Text Format"), tmpFormat ,  0L);
00798         if ( dia->exec())
00799         {
00800             dia->ctxOptions( );
00801             if ( createNewFormat )
00802                 entry->setFormatEntryContext( tmpFormat );
00803             autocorrectionEntryChanged= true;
00804 
00805         }
00806         else
00807         {
00808             if ( createNewFormat )
00809                 delete tmpFormat;
00810         }
00811         delete dia;
00812     }
00813 }
00814 
00815 void KoAutoFormatDia::slotRemoveEntry()
00816 {
00817     //find entry in listbox
00818    if(m_pListView->currentItem())
00819     {
00820         m_docAutoFormat->removeAutoFormatEntry(m_pListView->currentItem()->text(0));
00821         pbAdd->setText(i18n("&Add"));
00822         refreshEntryList();
00823         autocorrectionEntryChanged= true;
00824     }
00825 }
00826 
00827 
00828 void KoAutoFormatDia::slotfind( const QString & )
00829 {
00830     KoAutoFormatEntry *entry = m_docAutoFormat->findFormatEntry(m_find->text());
00831     if ( entry )
00832     {
00833         m_replace->setText(entry->replace().latin1());
00834         pbAdd->setText(i18n("&Modify"));
00835         m_pListView->setCurrentItem(m_pListView->findItem(m_find->text(),0));
00836 
00837     } else {
00838         m_replace->clear();
00839         pbAdd->setText(i18n("&Add"));
00840         m_pListView->setCurrentItem(0L);
00841     }
00842     slotfind2("");
00843 }
00844 
00845 
00846 void KoAutoFormatDia::slotfind2( const QString & )
00847 {
00848     bool state = !m_replace->text().isEmpty() && !m_find->text().isEmpty();
00849     KoAutoFormatEntry * entry=m_docAutoFormat->findFormatEntry(m_find->text());
00850     pbRemove->setEnabled(state && entry);
00851     if ( state && entry )
00852     {
00853         delete newEntry;
00854         newEntry = 0L;
00855     }
00856     pbChangeFormat->setEnabled(state);
00857     pbClearFormat->setEnabled(state);
00858     pbAdd->setEnabled(state);
00859 }
00860 
00861 
00862 void KoAutoFormatDia::refreshEntryList()
00863 {
00864     m_pListView->clear();
00865     QDictIterator<KoAutoFormatEntry> it( m_docAutoFormat->getAutoFormatEntries());
00866     for( ; it.current(); ++it )
00867     {
00868         ( void )new QListViewItem( m_pListView, it.currentKey(), it.current()->replace() );
00869     }
00870     m_pListView->setCurrentItem(m_pListView->firstChild ());
00871     bool state = !(m_replace->text().isEmpty()) && !(m_find->text().isEmpty());
00872     //we can delete item, as we search now in listbox and not in m_find lineedit
00873     pbRemove->setEnabled(m_pListView->currentItem() && m_pListView->selectedItem()!=0 );
00874     pbChangeFormat->setEnabled(state && m_pListView->currentItem() && m_pListView->selectedItem()!=0 );
00875     pbClearFormat->setEnabled(state && m_pListView->currentItem() && m_pListView->selectedItem()!=0 );
00876 
00877     pbAdd->setEnabled(state);
00878 }
00879 
00880 
00881 void KoAutoFormatDia::addEntryList(const QString &key, KoAutoFormatEntry *_autoEntry)
00882 {
00883     m_docAutoFormat->addAutoFormatEntry( key, _autoEntry );
00884 }
00885 
00886 
00887 
00888 void KoAutoFormatDia::editEntryList(const QString &key,const QString &newFindString, KoAutoFormatEntry *_autoEntry)
00889 {
00890     if ( m_docAutoFormat->findFormatEntry(key) && m_docAutoFormat->findFormatEntry(key)->formatEntryContext())
00891         _autoEntry->setFormatEntryContext( new KoSearchContext(*(m_docAutoFormat->findFormatEntry(key)->formatEntryContext()) ));
00892     m_docAutoFormat->removeAutoFormatEntry( key );
00893     m_docAutoFormat->addAutoFormatEntry( newFindString, _autoEntry );
00894 }
00895 
00896 
00897 void KoAutoFormatDia::slotAddEntry()
00898 {
00899     if(!pbAdd->isEnabled())
00900         return;
00901     QString repl = m_replace->text();
00902     QString find = m_find->text();
00903     if(repl.isEmpty() || find.isEmpty())
00904     {
00905         KMessageBox::sorry( 0L, i18n( "An area is empty" ) );
00906         return;
00907     }
00908     if(repl==find)
00909     {
00910         KMessageBox::sorry( 0L, i18n( "Find string is the same as replace string!" ) );
00911     return;
00912     }
00913     KoAutoFormatEntry *tmp = new KoAutoFormatEntry( repl );
00914 
00915     if(pbAdd->text() == i18n( "&Add" ))
00916     {
00917         if ( newEntry )
00918         {
00919             newEntry->changeReplace( m_replace->text());
00920             addEntryList(find, newEntry);
00921             delete tmp;
00922             newEntry = 0L;
00923         }
00924         else
00925             addEntryList(find, tmp);
00926     }
00927     else
00928         editEntryList(find, find, tmp);
00929     m_replace->clear();
00930     m_find->clear();
00931 
00932     refreshEntryList();
00933     autocorrectionEntryChanged= true;
00934 }
00935 
00936 
00937 void KoAutoFormatDia::chooseSpecialChar1()
00938 {
00939     QString f = font().family();
00940     QChar c = ' ';
00941     bool const focus = m_find->hasFocus();
00942     if ( KoCharSelectDia::selectChar( f, c, false ) )
00943     {
00944         int const cursorpos = m_find->cursorPosition();
00945         if (focus)
00946             m_find->setText( m_find->text().insert( cursorpos, c ) );
00947         else
00948             m_find->setText( m_find->text().append(c) );
00949         m_find->setCursorPosition( cursorpos+1 );
00950     }
00951 }
00952 
00953 
00954 void KoAutoFormatDia::chooseSpecialChar2()
00955 {
00956     QString f = font().family();
00957     QChar c = ' ';
00958     bool const focus = m_replace->hasFocus();
00959     if ( KoCharSelectDia::selectChar( f, c, false ) )
00960     {
00961         int const cursorpos = m_replace->cursorPosition();
00962         if (focus)
00963             m_replace->setText( m_replace->text().insert(m_replace->cursorPosition(),  c ) );
00964         else
00965         m_replace->setText( m_replace->text().append(c) );
00966         m_replace->setCursorPosition( cursorpos+1 );
00967     }
00968 }
00969 
00970 
00971 void KoAutoFormatDia::slotItemRenamed(QListViewItem *, const QString & , int )
00972 {
00973     // Wow. This need a redesign (we don't have the old key anymore at this point !)
00974     // -> inherit QListViewItem and store the KoAutoFormatEntry pointer in it.
00975 }
00976 
00977 
00978 void KoAutoFormatDia::slotEditEntry()
00979 {
00980     if(m_pListView->currentItem()==0)
00981         return;
00982     delete newEntry;
00983     newEntry=0L;
00984     m_find->setText(m_pListView->currentItem()->text(0));
00985     m_replace->setText(m_pListView->currentItem()->text(1));
00986     bool state = !m_replace->text().isEmpty() && !m_find->text().isEmpty();
00987     pbRemove->setEnabled(state);
00988     pbChangeFormat->setEnabled( state );
00989     pbClearFormat->setEnabled(state);
00990     pbAdd->setEnabled(state);
00991 }
00992 
00993 
00994 bool KoAutoFormatDia::applyConfig()
00995 {
00996     // First tab
00997     KoAutoFormat::TypographicQuotes tq = m_autoFormat.getConfigTypographicSimpleQuotes();
00998     tq.replace = cbTypographicSimpleQuotes->isChecked();
00999     tq.begin = pbSimpleQuote1->text()[ 0 ];
01000     tq.end = pbSimpleQuote2->text()[ 0 ];
01001     m_docAutoFormat->configTypographicSimpleQuotes( tq );
01002 
01003     tq = m_autoFormat.getConfigTypographicDoubleQuotes();
01004     tq.replace = cbTypographicDoubleQuotes->isChecked();
01005     tq.begin = pbDoubleQuote1->text()[ 0 ];
01006     tq.end = pbDoubleQuote2->text()[ 0 ];
01007     m_docAutoFormat->configTypographicDoubleQuotes( tq );
01008 
01009 
01010     m_docAutoFormat->configUpperCase( cbUpperCase->isChecked() );
01011     m_docAutoFormat->configUpperUpper( cbUpperUpper->isChecked() );
01012     m_docAutoFormat->configAutoDetectUrl( cbDetectUrl->isChecked() );
01013 
01014     m_docAutoFormat->configIgnoreDoubleSpace( cbIgnoreDoubleSpace->isChecked());
01015     m_docAutoFormat->configRemoveSpaceBeginEndLine( cbRemoveSpaceBeginEndLine->isChecked());
01016     m_docAutoFormat->configUseBulletStyle(cbUseBulletStyle->isChecked());
01017 
01018     m_docAutoFormat->configBulletStyle(pbBulletStyle->text()[ 0 ]);
01019 
01020     m_docAutoFormat->configAutoChangeFormat( cbAutoChangeFormat->isChecked());
01021 
01022     m_docAutoFormat->configAutoReplaceNumber( cbAutoReplaceNumber->isChecked());
01023     m_docAutoFormat->configAutoNumberStyle(cbUseNumberStyle->isChecked());
01024 
01025     m_docAutoFormat->configAutoSuperScript ( cbAutoSuperScript->isChecked() );
01026     m_docAutoFormat->configCapitalizeNameOfDays( cbCapitalizeDaysName->isChecked());
01027 
01028 
01029     // Second tab
01030     //m_docAutoFormat->copyAutoFormatEntries( m_autoFormat );
01031     m_docAutoFormat->copyListException(abbreviation->getListException());
01032     m_docAutoFormat->copyListTwoUpperCaseException(twoUpperLetter->getListException());
01033     m_docAutoFormat->configAdvancedAutocorrect( cbAdvancedAutoCorrection->isChecked() );
01034     m_docAutoFormat->configCorrectionWithFormat( cbAutoCorrectionWithFormat->isChecked());
01035 
01036     m_docAutoFormat->configIncludeTwoUpperUpperLetterException( twoUpperLetter->autoInclude());
01037     m_docAutoFormat->configIncludeAbbreviation( abbreviation->autoInclude());
01038 
01039     QString lang = exceptionLanguageName.find(autoFormatLanguage->currentText()).data();
01040     if ( lang == i18n("Default") )
01041         m_docAutoFormat->configAutoFormatLanguage(QString::null);
01042     else
01043         m_docAutoFormat->configAutoFormatLanguage(lang);
01044 
01045     // Save to config file
01046     m_docAutoFormat->saveConfig();
01047     return true;
01048 }
01049 
01050 void KoAutoFormatDia::slotOk()
01051 {
01052     if (applyConfig())
01053     {
01054        KDialogBase::slotOk();
01055     }
01056 }
01057 
01058 void KoAutoFormatDia::slotCancel()
01059 {
01060     //force to reload
01061     if ( autocorrectionEntryChanged )
01062     {
01063         m_docAutoFormat->configAutoFormatLanguage( initialLanguage);
01064         m_docAutoFormat->readConfig( true );
01065     }
01066     KDialogBase::slotCancel();
01067 }
01068 
01069 void KoAutoFormatDia::chooseDoubleQuote1()
01070 {
01071     QString f = font().family();
01072     QChar c = oDoubleBegin;
01073     if ( KoCharSelectDia::selectChar( f, c, false ) )
01074     {
01075         pbDoubleQuote1->setText( c );
01076     }
01077 
01078 }
01079 
01080 void KoAutoFormatDia::chooseDoubleQuote2()
01081 {
01082     QString f = font().family();
01083     QChar c = oDoubleEnd;
01084     if ( KoCharSelectDia::selectChar( f, c, false ) )
01085     {
01086         pbDoubleQuote2->setText( c );
01087     }
01088 }
01089 
01090 
01091 void KoAutoFormatDia::defaultDoubleQuote()
01092 {
01093     pbDoubleQuote1->setText(m_docAutoFormat->getDefaultTypographicDoubleQuotes().begin);
01094     pbDoubleQuote2->setText(m_docAutoFormat->getDefaultTypographicDoubleQuotes().end);
01095 }
01096 
01097 void KoAutoFormatDia::chooseSimpleQuote1()
01098 {
01099     QString f = font().family();
01100     QChar c = oSimpleBegin;
01101     if ( KoCharSelectDia::selectChar( f, c, false ) )
01102     {
01103         pbSimpleQuote1->setText( c );
01104     }
01105 }
01106 
01107 void KoAutoFormatDia::chooseSimpleQuote2()
01108 {
01109     QString f = font().family();
01110     QChar c = oSimpleEnd;
01111     if ( KoCharSelectDia::selectChar( f, c, false ) )
01112     {
01113         pbSimpleQuote2->setText( c );
01114     }
01115 }
01116 
01117 void KoAutoFormatDia::defaultSimpleQuote()
01118 {
01119 
01120     pbSimpleQuote1->setText(m_docAutoFormat->getDefaultTypographicSimpleQuotes().begin);
01121     pbSimpleQuote2->setText(m_docAutoFormat->getDefaultTypographicSimpleQuotes().end);
01122 }
01123 
01124 
01125 void KoAutoFormatDia::chooseBulletStyle()
01126 {
01127     QString f = font().family();
01128     QChar c = bulletStyle;
01129     if ( KoCharSelectDia::selectChar( f, c, false ) )
01130     {
01131         pbBulletStyle->setText( c );
01132     }
01133 }
01134 
01135 void KoAutoFormatDia::defaultBulletStyle()
01136 {
01137     pbBulletStyle->setText( "" );
01138 }
01139 
01140 void KoAutoFormatDia::slotChangeStateSimple(bool b)
01141 {
01142     pbSimpleQuote1->setEnabled(b);
01143     pbSimpleQuote2->setEnabled(b);
01144     pbSimpleDefault->setEnabled(b);
01145 }
01146 
01147 void KoAutoFormatDia::slotChangeStateDouble(bool b)
01148 {
01149     pbDoubleQuote1->setEnabled(b);
01150     pbDoubleQuote2->setEnabled(b);
01151     pbDoubleDefault->setEnabled(b);
01152 }
01153 
01154 
01155 /******************************************************************/
01156 /* Class: KoCompletionDia                                         */
01157 /******************************************************************/
01158 
01159 KoCompletionDia::KoCompletionDia( QWidget *parent, const char *name,
01160       KoAutoFormat * autoFormat )
01161     : KDialogBase( parent, name , true, i18n( "Completion" ), Ok|Cancel|User1,
01162       Ok, true, KGuiItem( i18n( "&Reset" ), "undo" ) ),
01163       m_autoFormat( *autoFormat ),
01164       m_docAutoFormat( autoFormat )
01165 {
01166     setup();
01167     slotResetConf();
01168     setInitialSize( QSize( 500, 500 ) );
01169     connect( this, SIGNAL( user1Clicked() ), this, SLOT(slotResetConf()));
01170     changeButtonStatus();
01171 }
01172 
01173 void KoCompletionDia::changeButtonStatus()
01174 {
01175     bool state = cbAllowCompletion->isChecked();
01176     cbAppendSpace->setEnabled( state );
01177     cbShowToolTip->setEnabled( state );
01178     cbAddCompletionWord->setEnabled( state );
01179     pbRemoveCompletionEntry->setEnabled( state );
01180     pbSaveCompletionEntry->setEnabled( state );
01181     pbAddCompletionEntry->setEnabled( state );
01182     m_lbListCompletion->setEnabled( state );
01183     m_minWordLength->setEnabled( state );
01184     m_maxNbWordCompletion->setEnabled( state );
01185     m_completionKeyActionLabel->setEnabled( state );
01186     m_completionKeyAction->setEnabled( state );
01187     state = state && (m_lbListCompletion->count()!=0 && !m_lbListCompletion->currentText().isEmpty());
01188     pbRemoveCompletionEntry->setEnabled( state );
01189 }
01190 
01191 void KoCompletionDia::setup()
01192 {
01193     QVBox *page = makeVBoxMainWidget();
01194     cbAllowCompletion = new QCheckBox( page );
01195     cbAllowCompletion->setText( i18n( "E&nable completion" ) );
01196     connect(cbAllowCompletion, SIGNAL(toggled ( bool )), this, SLOT( changeButtonStatus()));
01197     // TODO whatsthis or text, to tell about the key to use for autocompletion....
01198 
01199     cbShowToolTip = new QCheckBox( page );
01200     cbShowToolTip->setText( i18n( "&Enable tool tip completion" ) );
01201     QWhatsThis::add( cbShowToolTip, i18n("If this option is enabled, a tool tip box will appear when you type the beginning of a word that exists in the completion list. To complete the word, press the TAB or ENTER key." ) );
01202     cbAddCompletionWord = new QCheckBox( page );
01203     cbAddCompletionWord->setText( i18n( "&Automatically add new words to completion list" ) );
01204     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." ) );
01205 
01206     m_lbListCompletion = new QListBox( page );
01207     connect( m_lbListCompletion, SIGNAL( selected ( const QString & ) ), this, SLOT( slotCompletionWordSelected( const QString & )));
01208     connect( m_lbListCompletion, SIGNAL( highlighted ( const QString & ) ), this, SLOT( slotCompletionWordSelected( const QString & )));
01209 
01210     pbAddCompletionEntry = new QPushButton( i18n("Add Completion Entry..."), page);
01211     connect( pbAddCompletionEntry, SIGNAL( clicked() ), this, SLOT( slotAddCompletionEntry()));
01212 
01213     pbRemoveCompletionEntry = new QPushButton(i18n( "R&emove Completion Entry"), page  );
01214     connect( pbRemoveCompletionEntry, SIGNAL( clicked() ), this, SLOT( slotRemoveCompletionEntry()));
01215 
01216     pbSaveCompletionEntry= new QPushButton(i18n( "&Save Completion List"), page );
01217     connect( pbSaveCompletionEntry, SIGNAL( clicked() ), this, SLOT( slotSaveCompletionEntry()));
01218 
01219 
01220     m_minWordLength = new KIntNumInput( page );
01221     m_minWordLength->setRange ( 5, 100,1,true );
01222     m_minWordLength->setLabel( i18n( "&Minimum word length:" ) );
01223 
01224     m_maxNbWordCompletion = new KIntNumInput( page );
01225     m_maxNbWordCompletion->setRange( 1, 500, 1, true);
01226     m_maxNbWordCompletion->setLabel( i18n( "Ma&ximum number of completion words:" ) );
01227 
01228     cbAppendSpace = new QCheckBox( page );
01229     cbAppendSpace->setText( i18n( "A&ppend space" ) );
01230 
01231     m_completionKeyActionLabel = new QLabel(i18n( "Key used for completion:" ),page );
01232 
01233     m_completionKeyAction = new QComboBox( page );
01234     QStringList lst;
01235     lst << i18n( "Enter" );
01236     lst << i18n( "Tab" );
01237     lst << i18n( "Space" );
01238     lst << i18n( "End" );
01239     lst << i18n( "Right" );
01240     m_completionKeyAction->insertStringList( lst );
01241     m_listCompletion = m_docAutoFormat->listCompletion();
01242 }
01243 
01244 void KoCompletionDia::slotResetConf()
01245 {
01246     cbAllowCompletion->setChecked( m_autoFormat.getConfigCompletion());
01247     cbShowToolTip->setChecked( m_autoFormat.getConfigToolTipCompletion());
01248     cbAddCompletionWord->setChecked( m_autoFormat.getConfigAddCompletionWord());
01249     m_lbListCompletion->clear();
01250     QStringList lst = m_docAutoFormat->listCompletion();
01251     m_lbListCompletion->insertStringList( lst );
01252     m_lbListCompletion->sort();
01253     if( lst.isEmpty() || m_lbListCompletion->currentText().isEmpty())
01254         pbRemoveCompletionEntry->setEnabled( false );
01255     m_minWordLength->setValue ( m_docAutoFormat->getConfigMinWordLength() );
01256     m_maxNbWordCompletion->setValue ( m_docAutoFormat->getConfigNbMaxCompletionWord() );
01257     cbAppendSpace->setChecked( m_autoFormat.getConfigAppendSpace() );
01258 
01259     switch( m_docAutoFormat->getConfigKeyAction() )
01260     {
01261     case KoAutoFormat::Enter:
01262         m_completionKeyAction->setCurrentItem( 0 );
01263         break;
01264     case KoAutoFormat::Tab:
01265         m_completionKeyAction->setCurrentItem( 1 );
01266         break;
01267     case KoAutoFormat::Space:
01268         m_completionKeyAction->setCurrentItem( 2 );
01269         break;
01270     case KoAutoFormat::End:
01271         m_completionKeyAction->setCurrentItem( 3 );
01272         break;
01273     case KoAutoFormat::Right:
01274         m_completionKeyAction->setCurrentItem( 4 );
01275         break;
01276     default:
01277         m_completionKeyAction->setCurrentItem( 0 );
01278     }
01279     changeButtonStatus();
01280 }
01281 
01282 void KoCompletionDia::slotSaveCompletionEntry()
01283 {
01284 
01285     KConfig config("kofficerc");
01286     KConfigGroupSaver cgs( &config, "Completion Word" );
01287     config.writeEntry( "list", m_listCompletion );
01288     config.sync();
01289     KMessageBox::information( this, i18n(
01290             "Completion list saved.\nIt will be used for all documents "
01291             "from now on."), i18n("Completion List Saved") );
01292 }
01293 
01294 void KoCompletionDia::slotAddCompletionEntry()
01295 {
01296     bool ok;
01297     QString const newWord = KInputDialog::getText( i18n("Add Completion Entry"), i18n("Enter entry:"), QString::null, &ok, this ).lower();
01298     if ( ok )
01299     {
01300         if ( !m_listCompletion.contains( newWord ))
01301         {
01302             m_listCompletion.append( newWord );
01303             m_lbListCompletion->insertItem( newWord );
01304             pbRemoveCompletionEntry->setEnabled( !m_lbListCompletion->currentText().isEmpty() );
01305             m_lbListCompletion->sort();
01306         }
01307 
01308     }
01309 }
01310 
01311 void KoCompletionDia::slotOk()
01312 {
01313     if (applyConfig())
01314     {
01315        KDialogBase::slotOk();
01316     }
01317 }
01318 
01319 bool KoCompletionDia::applyConfig()
01320 {
01321     m_docAutoFormat->configCompletion( cbAllowCompletion->isChecked());
01322     m_docAutoFormat->configToolTipCompletion( cbShowToolTip->isChecked());
01323     m_docAutoFormat->configAppendSpace( cbAppendSpace->isChecked() );
01324     m_docAutoFormat->configMinWordLength( m_minWordLength->value() );
01325     m_docAutoFormat->configNbMaxCompletionWord( m_maxNbWordCompletion->value () );
01326     m_docAutoFormat->configAddCompletionWord( cbAddCompletionWord->isChecked());
01327 
01328     m_docAutoFormat->getCompletion()->setItems( m_listCompletion );
01329     m_docAutoFormat->updateMaxWords();
01330     switch( m_completionKeyAction->currentItem() )
01331     {
01332     case 0:
01333         m_docAutoFormat->configKeyCompletionAction( KoAutoFormat::Enter );
01334         break;
01335     case 1:
01336         m_docAutoFormat->configKeyCompletionAction( KoAutoFormat::Tab );
01337         break;
01338     case 2:
01339         m_docAutoFormat->configKeyCompletionAction( KoAutoFormat::Space );
01340         break;
01341     case 3:
01342         m_docAutoFormat->configKeyCompletionAction( KoAutoFormat::End );
01343         break;
01344     case 4:
01345         m_docAutoFormat->configKeyCompletionAction( KoAutoFormat::Right );
01346         break;
01347     default:
01348         m_docAutoFormat->configKeyCompletionAction( KoAutoFormat::Enter );
01349     }
01350     // Save to config file
01351     m_docAutoFormat->saveConfig();
01352     return true;
01353 }
01354 
01355 void KoCompletionDia::slotRemoveCompletionEntry()
01356 {
01357     QString text = m_lbListCompletion->currentText();
01358     if( !text.isEmpty() )
01359     {
01360         m_listCompletion.remove( text );
01361         m_lbListCompletion->removeItem( m_lbListCompletion->currentItem () );
01362         if( m_lbListCompletion->count()==0 )
01363             pbRemoveCompletionEntry->setEnabled( false );
01364     }
01365 }
01366 
01367 void KoCompletionDia::slotCompletionWordSelected( const QString & word)
01368 {
01369     pbRemoveCompletionEntry->setEnabled( !word.isEmpty() );
01370 }
KDE Logo
This file is part of the documentation for lib Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:39:59 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003