lib

KoAutoFormatDia.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3 2001, 2002 Sven Leiber <s.leiber@web.de>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "KoAutoFormatDia.h"
22#include "KoAutoFormat.h"
23#include "KoCharSelectDia.h"
24#include <KoSearchDia.h>
25
26#include <tdelocale.h>
27#include <tdemessagebox.h>
28#include <tdelistview.h>
29#include <kstandarddirs.h>
30
31#include <tqlayout.h>
32#include <tqwhatsthis.h>
33#include <tqcheckbox.h>
34#include <tqpushbutton.h>
35#include <tqtooltip.h>
36#include <tqcombobox.h>
37#include <tqdir.h>
38#include <tqapplication.h>
39
40KoAutoFormatLineEdit::KoAutoFormatLineEdit ( TQWidget * parent, const char * name )
41 : TQLineEdit(parent,name)
42{
43}
44
45void KoAutoFormatLineEdit::keyPressEvent ( TQKeyEvent *ke )
46{
47 if( ke->key() == TQt::Key_Return ||
48 ke->key() == TQt::Key_Enter )
49 {
50 emit keyReturnPressed();
51 return;
52 }
53 TQLineEdit::keyPressEvent (ke);
54}
55
56
57/******************************************************************/
58/* Class: KoAutoFormatExceptionWidget */
59/******************************************************************/
60
61KoAutoFormatExceptionWidget::KoAutoFormatExceptionWidget(TQWidget *parent, const TQString &name,const TQStringList &_list, bool _autoInclude, bool _abreviation)
62 :TQWidget( parent )
63{
64 m_bAbbreviation=_abreviation;
65 m_listException=_list;
66 TQGridLayout *grid = new TQGridLayout(this, 4, 2, 0, KDialog::spacingHint());
67
68 TQLabel *lab=new TQLabel(name,this);
69 grid->addMultiCellWidget(lab,0,0,0,1);
70
71 exceptionLine = new KoAutoFormatLineEdit( this );
72 grid->addWidget(exceptionLine,1,0);
73
74 connect(exceptionLine,TQ_SIGNAL(keyReturnPressed()),TQ_SLOT(slotAddException()));
75 connect(exceptionLine ,TQ_SIGNAL(textChanged ( const TQString & )),
76 TQ_SLOT(textChanged ( const TQString & )));
77
78 pbAddException=new TQPushButton(i18n("Add"),this);
79 connect(pbAddException, TQ_SIGNAL(clicked()),TQ_SLOT(slotAddException()));
80 grid->addWidget(pbAddException,1,1);
81
82 pbAddException->setEnabled(false);
83
84 pbRemoveException=new TQPushButton(i18n("Remove"),this);
85 connect(pbRemoveException, TQ_SIGNAL(clicked()),TQ_SLOT(slotRemoveException()));
86 grid->addWidget(pbRemoveException,2,1,TQt::AlignTop);
87
88 exceptionList=new TQListBox(this);
89 exceptionList->insertStringList(m_listException);
90 exceptionList->sort();
91 grid->addWidget(exceptionList,2,0);
92
93 grid->setRowStretch( 2, 1 );
94
95 connect( exceptionList , TQ_SIGNAL(selectionChanged () ),
96 this,TQ_SLOT(slotExceptionListSelected()) );
97
98 pbRemoveException->setEnabled( exceptionList->currentItem()!=-1);
99
100 cbAutoInclude = new TQCheckBox( i18n("Autoinclude"), this );
101 grid->addWidget(cbAutoInclude,3,0);
102 cbAutoInclude->setChecked( _autoInclude );
103}
104
105void KoAutoFormatExceptionWidget::textChanged ( const TQString &_text )
106{
107 pbAddException->setEnabled(!_text.isEmpty());
108}
109
110void KoAutoFormatExceptionWidget::slotAddException()
111{
112 TQString text=exceptionLine->text().stripWhiteSpace();
113 if(!text.isEmpty())
114 {
115 if(text.at(text.length()-1)!='.' && m_bAbbreviation)
116 text=text+".";
117 if( m_listException.findIndex( text )==-1)
118 {
119 m_listException<<text;
120
121 exceptionList->clear();
122 exceptionList->insertStringList(m_listException);
123 exceptionList->sort();
124 pbRemoveException->setEnabled( exceptionList->currentItem()!=-1);
125 pbAddException->setEnabled(false);
126 }
127 exceptionLine->clear();
128 }
129}
130
131void KoAutoFormatExceptionWidget::slotRemoveException()
132{
133 if(!exceptionList->currentText().isEmpty())
134 {
135 m_listException.remove(exceptionList->currentText());
136 exceptionList->clear();
137 pbAddException->setEnabled(false);
138 pbRemoveException->setEnabled( exceptionList->currentItem()!=-1);
139 exceptionList->insertStringList(m_listException);
140 exceptionLine->clear();
141 }
142}
143
144bool KoAutoFormatExceptionWidget::autoInclude()
145{
146 return cbAutoInclude->isChecked();
147}
148
149void KoAutoFormatExceptionWidget::setListException( const TQStringList &list)
150{
151 exceptionList->clear();
152 exceptionList->insertStringList(list);
153}
154
155void KoAutoFormatExceptionWidget::setAutoInclude(bool b)
156{
157 cbAutoInclude->setChecked( b );
158}
159
160void KoAutoFormatExceptionWidget::slotExceptionListSelected()
161{
162 pbRemoveException->setEnabled( exceptionList->currentItem()!=-1 );
163}
164
165/******************************************************************/
166/* Class: KoAutoFormatDia */
167/******************************************************************/
168
169KoAutoFormatDia::KoAutoFormatDia( TQWidget *parent, const char *name,
170 KoAutoFormat * autoFormat )
171 : KDialogBase( Tabbed, i18n("Autocorrection"), Ok | Cancel | User1, Ok,
172 parent, name, true, true, KGuiItem( i18n( "&Reset" ), "edit-undo" )),
173 oSimpleBegin( autoFormat->getConfigTypographicSimpleQuotes().begin ),
174 oSimpleEnd( autoFormat->getConfigTypographicSimpleQuotes().end ),
175 oDoubleBegin( autoFormat->getConfigTypographicDoubleQuotes().begin ),
176 oDoubleEnd( autoFormat->getConfigTypographicDoubleQuotes().end ),
177 bulletStyle( autoFormat->getConfigBulletStyle()),
178 m_autoFormat( *autoFormat ),
179 m_docAutoFormat( autoFormat )
180{
181 noSignal=true;
182 newEntry = 0L;
183 autocorrectionEntryChanged= false;
184 changeLanguage = false;
185
186 setupTab1();
187 setupTab2();
188 setupTab3();
189 setupTab4();
190 setInitialSize( TQSize(500, 300) );
191 connect( this, TQ_SIGNAL( user1Clicked() ), this, TQ_SLOT(slotResetConf()));
192 noSignal=false;
193}
194
195KoAutoFormatDia::~KoAutoFormatDia()
196{
197 delete newEntry;
198}
199
200void KoAutoFormatDia::slotResetConf()
201{
202 switch( activePageIndex() ) {
203 case 0:
204 initTab1();
205 break;
206 case 1:
207 initTab2();
208 break;
209 case 2:
210 initTab3();
211 break;
212 case 3:
213 initTab4();
214 break;
215 default:
216 break;
217 }
218}
219
220void KoAutoFormatDia::setupTab1()
221{
222 tab1 = addPage( i18n( "Simple Autocorrection" ) );
223 TQVBoxLayout *vbox = new TQVBoxLayout(tab1, 0, KDialog::spacingHint());
224
225 cbUpperCase = new TQCheckBox( tab1 );
226 cbUpperCase->setText( i18n(
227 "Convert &first letter of a sentence automatically to uppercase\n"
228 "(e.g. \"my house. in this town\" to \"my house. In this town\")"
229 ) );
230 TQWhatsThis::add( cbUpperCase, i18n(
231 "Detect when a new sentence is started and always ensure that"
232 " the first character is an uppercase character."));
233
234 vbox->addWidget(cbUpperCase);
235
236
237 cbUpperUpper = new TQCheckBox( tab1 );
238 cbUpperUpper->setText( i18n(
239 "Convert &two uppercase characters to one uppercase and one"
240 " lowercase character\n (e.g. PErfect to Perfect)" ) );
241 TQWhatsThis::add( cbUpperUpper, i18n(
242 "All words are checked for the common mistake of holding the "
243 "shift key down a bit too long. If some words must have two "
244 "uppercase characters, then those exceptions should be added in "
245 "the 'Exceptions' tab."));
246
247 vbox->addWidget(cbUpperUpper);
248
249 cbDetectUrl=new TQCheckBox( tab1 );
250 cbDetectUrl->setText( i18n( "Autoformat &URLs" ) );
251 TQWhatsThis::add( cbDetectUrl, i18n(
252 "Detect when a URL (Uniform Resource Locator) is typed and "
253 "provide formatting that matches the way an Internet browser "
254 "would show a URL."));
255
256 vbox->addWidget(cbDetectUrl);
257
258 cbIgnoreDoubleSpace=new TQCheckBox( tab1 );
259 cbIgnoreDoubleSpace->setText( i18n( "&Suppress double spaces" ) );
260 TQWhatsThis::add( cbIgnoreDoubleSpace, i18n(
261 "Make sure that more than one space cannot be typed, as this is a "
262 "common mistake which is quite hard to find in formatted text."));
263
264 vbox->addWidget(cbIgnoreDoubleSpace);
265
266 cbRemoveSpaceBeginEndLine=new TQCheckBox( tab1 );
267 cbRemoveSpaceBeginEndLine->setText( i18n(
268 "R&emove spaces at the beginning and end of paragraphs" ) );
269 TQWhatsThis::add( cbRemoveSpaceBeginEndLine, i18n(
270 "Keep correct formatting and indenting of sentences by "
271 "automatically removing spaces typed at the beginning and end of "
272 "a paragraph."));
273
274 vbox->addWidget(cbRemoveSpaceBeginEndLine);
275
276 cbAutoChangeFormat=new TQCheckBox( tab1 );
277 cbAutoChangeFormat->setText( i18n(
278 "Automatically do &bold and underline formatting") );
279 TQWhatsThis::add( cbAutoChangeFormat, i18n(
280 "When you use _underline_ or *bold*, the text between the "
281 "underscores or asterisks will be converted to underlined or "
282 "bold text.") );
283
284 vbox->addWidget(cbAutoChangeFormat);
285
286 cbAutoReplaceNumber=new TQCheckBox( tab1 );
287 cbAutoReplaceNumber->setText( i18n(
288 "We add the 1/2 char at the %1", "Re&place 1/2... with %1..." )
289 .arg( TQString( "½" ) ) );
290 TQWhatsThis::add( cbAutoReplaceNumber, i18n(
291 "Most standard fraction notations will be converted when available"
292 ) );
293
294 vbox->addWidget(cbAutoReplaceNumber);
295
296 cbUseNumberStyle=new TQCheckBox( tab1 );
297 cbUseNumberStyle->setText( i18n(
298 "Use &autonumbering for numbered paragraphs" ) );
299 TQWhatsThis::add( cbUseNumberStyle, i18n(
300 "When typing '1)' or similar in front of a paragraph, "
301 "automatically convert the paragraph to use that numbering style. "
302 "This has the advantage that further paragraphs will also be "
303 "numbered and the spacing is done correctly.") );
304
305 vbox->addWidget(cbUseNumberStyle);
306
307 cbAutoSuperScript = new TQCheckBox( tab1 );
308 cbAutoSuperScript->setText( i18n("Rep&lace 1st... with 1^st..."));
309 cbAutoSuperScript->setEnabled( m_docAutoFormat->nbSuperScriptEntry()>0 );
310
311 vbox->addWidget(cbAutoSuperScript);
312 cbCapitalizeDaysName = new TQCheckBox( tab1 );
313 cbCapitalizeDaysName->setText( i18n("Capitalize name of days"));
314 vbox->addWidget(cbCapitalizeDaysName);
315
316 cbUseBulletStyle=new TQCheckBox( tab1 );
317 cbUseBulletStyle->setText( i18n(
318 "Use l&ist-formatting for bulleted paragraphs" ) );
319 TQWhatsThis::add( cbUseBulletStyle, i18n(
320 "When typing '*' or '-' in front of a paragraph, automatically "
321 "convert the paragraph to use that list-style. Using a list-style "
322 "formatting means that a correct bullet is used to draw the list."
323 ) );
324
325 connect( cbUseBulletStyle, TQ_SIGNAL( toggled( bool ) ),
326 TQ_SLOT( slotBulletStyleToggled( bool ) ) );
327
328 vbox->addWidget(cbUseBulletStyle);
329 TQHBoxLayout *hbox = new TQHBoxLayout();
330
331 hbox->addSpacing( 20 );
332 hbox->setSpacing(KDialog::spacingHint());
333 pbBulletStyle = new TQPushButton( tab1 );
334 pbBulletStyle->setFixedSize( pbBulletStyle->sizeHint() );
335 hbox->addWidget( pbBulletStyle );
336 pbDefaultBulletStyle = new TQPushButton( tab1 );
337 pbDefaultBulletStyle->setText(i18n("Default"));
338 pbDefaultBulletStyle->setFixedSize( pbDefaultBulletStyle->sizeHint() );
339 hbox->addWidget( pbDefaultBulletStyle );
340
341 hbox->addStretch( 1 );
342
343 vbox->addItem(hbox);
344 vbox->addStretch( 1 );
345
346 initTab1();
347
348 connect( pbBulletStyle, TQ_SIGNAL( clicked() ), TQ_SLOT( chooseBulletStyle() ) );
349 connect( pbDefaultBulletStyle, TQ_SIGNAL( clicked()),
350 TQ_SLOT( defaultBulletStyle() ) );
351}
352
353void KoAutoFormatDia::initTab1()
354{
355 cbUpperCase->setChecked( m_autoFormat.getConfigUpperCase() );
356 cbUpperUpper->setChecked( m_autoFormat.getConfigUpperUpper() );
357 cbDetectUrl->setChecked( m_autoFormat.getConfigAutoDetectUrl());
358 cbIgnoreDoubleSpace->setChecked( m_autoFormat.getConfigIgnoreDoubleSpace());
359 cbRemoveSpaceBeginEndLine->setChecked( m_autoFormat.getConfigRemoveSpaceBeginEndLine());
360 cbAutoChangeFormat->setChecked( m_autoFormat.getConfigAutoChangeFormat());
361 cbAutoReplaceNumber->setChecked( m_autoFormat.getConfigAutoReplaceNumber());
362 cbUseNumberStyle->setChecked( m_autoFormat.getConfigAutoNumberStyle());
363 cbUseBulletStyle->setChecked( m_autoFormat.getConfigUseBulletSyle());
364 cbAutoSuperScript->setChecked( m_docAutoFormat->getConfigAutoSuperScript());
365 pbBulletStyle->setText( bulletStyle );
366 cbCapitalizeDaysName->setChecked( m_autoFormat.getConfigCapitalizeNameOfDays());
367
368 slotBulletStyleToggled( cbUseBulletStyle->isChecked() );
369}
370
371void KoAutoFormatDia::slotBulletStyleToggled( bool b )
372{
373 pbBulletStyle->setEnabled( b );
374 pbDefaultBulletStyle->setEnabled( b );
375}
376
377void KoAutoFormatDia::setupTab2()
378{
379 tab2 = addPage( i18n( "Custom Quotes" ) );
380
381 TQVBoxLayout *vbox = new TQVBoxLayout(tab2, 0, KDialog::spacingHint());
382
383 cbTypographicDoubleQuotes = new TQCheckBox( tab2 );
384 cbTypographicDoubleQuotes->setText( i18n(
385 "Replace &double quotes with typographical quotes" ) );
386
387 connect( cbTypographicDoubleQuotes,TQ_SIGNAL(toggled ( bool)),
388 TQ_SLOT(slotChangeStateDouble(bool)));
389
390 vbox->addWidget( cbTypographicDoubleQuotes );
391
392 TQHBoxLayout *hbox = new TQHBoxLayout( );
393 hbox->addSpacing( 20 );
394
395 pbDoubleQuote1 = new TQPushButton( tab2 );
396 pbDoubleQuote1->setFixedSize( pbDoubleQuote1->sizeHint() );
397
398 pbDoubleQuote2 = new TQPushButton( tab2 );
399 pbDoubleQuote2->setFixedSize( pbDoubleQuote2->sizeHint() );
400
401 if (TQApplication::reverseLayout()) {
402 hbox->addWidget( pbDoubleQuote2 );
403 hbox->addWidget( pbDoubleQuote1 );
404 } else {
405 hbox->addWidget( pbDoubleQuote1 );
406 hbox->addWidget( pbDoubleQuote2 );
407 }
408
409 hbox->addSpacing( KDialog::spacingHint() );
410
411 pbDoubleDefault = new TQPushButton( tab2 );
412 pbDoubleDefault->setText(i18n("Default"));
413 pbDoubleDefault->setFixedSize( pbDoubleDefault->sizeHint() );
414 hbox->addWidget( pbDoubleDefault );
415
416 hbox->addStretch( 1 );
417
418 connect(pbDoubleQuote1, TQ_SIGNAL( clicked() ), TQ_SLOT( chooseDoubleQuote1() ));
419 connect(pbDoubleQuote2, TQ_SIGNAL( clicked() ), TQ_SLOT( chooseDoubleQuote2() ));
420 connect(pbDoubleDefault, TQ_SIGNAL( clicked()), TQ_SLOT( defaultDoubleQuote() ));
421
422 vbox->addItem( hbox );
423
424 cbTypographicSimpleQuotes = new TQCheckBox( tab2 );
425 cbTypographicSimpleQuotes->setText( i18n(
426 "Replace &single quotes with typographical quotes" ) );
427
428 connect( cbTypographicSimpleQuotes,TQ_SIGNAL(toggled ( bool)),
429 TQ_SLOT(slotChangeStateSimple(bool)));
430
431 vbox->addWidget( cbTypographicSimpleQuotes );
432
433 hbox = new TQHBoxLayout( );
434 hbox->addSpacing( 20 );
435
436 pbSimpleQuote1 = new TQPushButton( tab2 );
437 pbSimpleQuote1->setFixedSize( pbSimpleQuote1->sizeHint() );
438
439 pbSimpleQuote2 = new TQPushButton( tab2 );
440 pbSimpleQuote2->setFixedSize( pbSimpleQuote2->sizeHint() );
441
442 if (TQApplication::reverseLayout()) {
443 hbox->addWidget( pbSimpleQuote2 );
444 hbox->addWidget( pbSimpleQuote1 );
445 } else {
446 hbox->addWidget( pbSimpleQuote1 );
447 hbox->addWidget( pbSimpleQuote2 );
448 }
449
450 hbox->addSpacing( KDialog::spacingHint() );
451
452 pbSimpleDefault = new TQPushButton( tab2 );
453 pbSimpleDefault->setText(i18n("Default"));
454 pbSimpleDefault->setFixedSize( pbSimpleDefault->sizeHint() );
455 hbox->addWidget( pbSimpleDefault );
456
457 hbox->addStretch( 1 );
458
459 connect(pbSimpleQuote1, TQ_SIGNAL( clicked() ), TQ_SLOT( chooseSimpleQuote1() ));
460 connect(pbSimpleQuote2, TQ_SIGNAL( clicked() ), TQ_SLOT( chooseSimpleQuote2() ));
461 connect(pbSimpleDefault, TQ_SIGNAL( clicked()), TQ_SLOT( defaultSimpleQuote() ));
462
463 vbox->addItem( hbox );
464 vbox->addStretch( 1 );
465
466 initTab2();
467}
468
469void KoAutoFormatDia::initTab2()
470{
471 bool state=m_autoFormat.getConfigTypographicDoubleQuotes().replace;
472 cbTypographicDoubleQuotes->setChecked( state );
473 pbDoubleQuote1->setText( oDoubleBegin );
474 pbDoubleQuote2->setText(oDoubleEnd );
475 slotChangeStateDouble(state);
476
477 state=m_autoFormat.getConfigTypographicSimpleQuotes().replace;
478 cbTypographicSimpleQuotes->setChecked( state );
479 pbSimpleQuote1->setText( oSimpleBegin );
480 pbSimpleQuote2->setText(oSimpleEnd );
481 slotChangeStateSimple(state);
482
483}
484
485void KoAutoFormatDia::setupTab3()
486{
487 tab3 = addPage( i18n( "Advanced Autocorrection" ) );
488
489 TQLabel *lblFind, *lblReplace;
490
491 TQGridLayout *grid = new TQGridLayout( tab3, 11, 7, 0, KDialog::spacingHint() );
492
493 autoFormatLanguage = new TQComboBox(tab3);
494
495 TQStringList lst;
496 lst<<i18n("Default");
497 lst<<i18n("All Languages");
498 exceptionLanguageName.insert( i18n("Default"), "");
499 exceptionLanguageName.insert( i18n("All Languages"), "all_languages");
500
501 TDEStandardDirs *standard = new TDEStandardDirs();
502 TQStringList tmp = standard->findDirs("data", "koffice/autocorrect/");
503 TQString path = *(tmp.end());
504 for ( TQStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it )
505 {
506 path =*it;
507 }
508 delete standard;
509 TQDir dir( path);
510 tmp =dir.entryList (TQDir::Files);
511 for ( TQStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it )
512 {
513 if ( !(*it).contains("autocorrect"))
514 {
515 TQString readableName = TDEGlobal::locale()->twoAlphaToCountryName((*it).left((*it).length()-4));
516 TQString tmp;
517 if ( readableName.isEmpty() )
518 tmp =(*it).left((*it).length()-4);
519 else
520 tmp =readableName;
521 exceptionLanguageName.insert( tmp, (*it).left((*it).length()-4));
522 lst<<tmp;
523 }
524 }
525 autoFormatLanguage->insertStringList(lst);
526
527 connect(autoFormatLanguage->listBox(), TQ_SIGNAL(selected ( const TQString & )), this, TQ_SLOT(changeAutoformatLanguage(const TQString & )));
528
529 grid->addMultiCellWidget( autoFormatLanguage, 0, 0, 4, 6 );
530 TQLabel *lblAutoFormatLanguage = new TQLabel( i18n("Replacements and exceptions for language:"), tab3);
531 grid->addMultiCellWidget( lblAutoFormatLanguage, 0, 0, 0, 3 );
532
533 cbAdvancedAutoCorrection = new TQCheckBox( tab3 );
534 cbAdvancedAutoCorrection->setText( i18n("Enable word replacement") );
535 connect( cbAdvancedAutoCorrection, TQ_SIGNAL(clicked ()), this, TQ_SLOT( slotChangeAdvancedAutoCorrection()));
536 grid->addMultiCellWidget( cbAdvancedAutoCorrection, 1, 1, 0, 6 );
537
538 cbAutoCorrectionWithFormat = new TQCheckBox( tab3 );
539 cbAutoCorrectionWithFormat->setText( i18n("Replace text with format") );
540 grid->addMultiCellWidget( cbAutoCorrectionWithFormat, 2, 2, 0, 6 );
541
542 lblFind = new TQLabel( i18n( "&Find:" ), tab3 );
543 grid->addWidget( lblFind, 3, 0 );
544
545 m_find = new KoAutoFormatLineEdit( tab3 );
546 grid->addWidget( m_find, 3, 1 );
547
548 lblFind->setBuddy( m_find );
549
550 connect( m_find, TQ_SIGNAL( textChanged( const TQString & ) ),
551 TQ_SLOT( slotfind( const TQString & ) ) );
552 connect( m_find, TQ_SIGNAL( keyReturnPressed() ),
553 TQ_SLOT( slotAddEntry()));
554
555 pbSpecialChar1 = new TQPushButton( "...", tab3 );
556 TQToolTip::add( pbSpecialChar1, i18n( "Insert a special character..." ) );
557 pbSpecialChar1->setFixedWidth( 40 );
558 grid->addWidget( pbSpecialChar1, 3, 2 );
559
560 connect(pbSpecialChar1,TQ_SIGNAL(clicked()), TQ_SLOT(chooseSpecialChar1()));
561
562 lblReplace = new TQLabel( i18n( "&Replace:" ), tab3 );
563 grid->addWidget( lblReplace, 3, 3 );
564
565 m_replace = new KoAutoFormatLineEdit( tab3 );
566 grid->addWidget( m_replace, 3, 4 );
567
568 lblReplace->setBuddy( m_replace );
569
570 connect( m_replace, TQ_SIGNAL( textChanged( const TQString & ) ),
571 TQ_SLOT( slotfind2( const TQString & ) ) );
572 connect( m_replace, TQ_SIGNAL( keyReturnPressed() ),
573 TQ_SLOT( slotAddEntry()));
574
575 pbSpecialChar2 = new TQPushButton( "...", tab3 );
576 TQToolTip::add( pbSpecialChar2, i18n( "Insert a special character..." ) );
577 pbSpecialChar2->setFixedWidth( 40 );
578 grid->addWidget( pbSpecialChar2, 3, 5 );
579
580 connect(pbSpecialChar2,TQ_SIGNAL(clicked()), TQ_SLOT(chooseSpecialChar2()));
581
582 pbAdd = new TQPushButton( i18n( "&Add"), tab3 );
583 grid->addWidget( pbAdd, 3, 6 );
584
585 connect(pbAdd,TQ_SIGNAL(clicked()),this, TQ_SLOT(slotAddEntry()));
586
587 m_pListView = new TDEListView( tab3 );
588 m_pListView->addColumn( i18n( "Find" ) );
589 m_pListView->addColumn( i18n( "Replace" ) );
590 m_pListView->setAllColumnsShowFocus( true );
591 grid->addMultiCellWidget( m_pListView, 4, 10, 0, 5 );
592
593 connect(m_pListView, TQ_SIGNAL(doubleClicked ( TQListViewItem * )),
594 TQ_SLOT(slotChangeTextFormatEntry()) );
595 connect(m_pListView, TQ_SIGNAL(clicked ( TQListViewItem * ) ),
596 TQ_SLOT(slotEditEntry()) );
597
598 pbRemove = new TQPushButton( i18n( "Remove" ), tab3 );
599 grid->addWidget( pbRemove, 4, 6, TQt::AlignTop );
600
601 connect(pbRemove,TQ_SIGNAL(clicked()), TQ_SLOT(slotRemoveEntry()));
602
603 pbChangeFormat= new TQPushButton( i18n( "Change Format..." ), tab3 );
604 grid->addWidget( pbChangeFormat, 5, 6, TQt::AlignTop );
605
606 connect( pbChangeFormat, TQ_SIGNAL(clicked()), TQ_SLOT(slotChangeTextFormatEntry()));
607
608 pbClearFormat= new TQPushButton( i18n( "Clear Format" ), tab3 );
609 grid->addWidget( pbClearFormat, 6, 6, TQt::AlignTop );
610
611 connect( pbClearFormat, TQ_SIGNAL(clicked()), TQ_SLOT(slotClearTextFormatEntry()));
612 grid->setRowStretch( 10, 1 );
613
614 initTab3();
615 slotChangeAdvancedAutoCorrection();
616 pbRemove->setEnabled(false);
617 pbChangeFormat->setEnabled( false );
618 pbAdd->setEnabled(false);
619 pbClearFormat->setEnabled( false);
620
621}
622
623void KoAutoFormatDia::initTab3()
624{
625 if ( !changeLanguage || noSignal)
626 {
627 initialLanguage=m_autoFormat.getConfigAutoFormatLanguage( );
628 if ( initialLanguage.isEmpty() )
629 autoFormatLanguage->setCurrentItem(0);
630 else
631 {
632 KoExceptionLanguageName::Iterator it = exceptionLanguageName.begin();
633 for ( ; it != exceptionLanguageName.end() ; ++it )
634 {
635 if ( it.data() == initialLanguage)
636 {
637 autoFormatLanguage->setCurrentText(it.key());
638 break;
639 }
640
641 }
642 }
643 }
644 //force to re-readconfig when we reset config and we change a entry
645 if ( autocorrectionEntryChanged )
646 {
647 if ( !changeLanguage )
648 m_docAutoFormat->configAutoFormatLanguage( initialLanguage);
649 m_docAutoFormat->readConfig( true );
650 }
651 cbAdvancedAutoCorrection->setChecked(m_autoFormat.getConfigAdvancedAutoCorrect());
652 cbAutoCorrectionWithFormat->setChecked( m_autoFormat.getConfigCorrectionWithFormat());
653 m_pListView->clear();
654
655 TQDictIterator<KoAutoFormatEntry> it( m_docAutoFormat->getAutoFormatEntries());
656 for( ; it.current(); ++it )
657 {
658 ( void )new TQListViewItem( m_pListView, it.currentKey(), it.current()->replace() );
659 }
660}
661
662void KoAutoFormatDia::slotChangeAdvancedAutoCorrection()
663{
664 bool state = cbAdvancedAutoCorrection->isChecked();
665 cbAutoCorrectionWithFormat->setEnabled( state );
666 pbSpecialChar2->setEnabled( state );
667 pbSpecialChar1->setEnabled( state );
668 m_replace->setEnabled( state);
669 m_find->setEnabled( state);
670 m_pListView->setEnabled( state);
671
672 state = state && !m_replace->text().isEmpty() && !m_find->text().isEmpty();
673 KoAutoFormatEntry * entry=m_docAutoFormat->findFormatEntry(m_find->text());
674 pbRemove->setEnabled(state && entry);
675 pbChangeFormat->setEnabled(state && entry);
676 pbClearFormat->setEnabled(state && entry);
677 pbAdd->setEnabled(state);
678}
679
680
681void KoAutoFormatDia::changeAutoformatLanguage(const TQString & text)
682{
683 if ( text==i18n("Default"))
684 m_docAutoFormat->configAutoFormatLanguage( TQString());
685 else
686 {
687 m_docAutoFormat->configAutoFormatLanguage( exceptionLanguageName.find(text).data());
688 }
689 if ( !noSignal )
690 {
691 changeLanguage=true;
692 m_docAutoFormat->readConfig( true );
693 initTab3();
694 initTab4();
695 autocorrectionEntryChanged=true;
696 cbAutoSuperScript->setEnabled( m_docAutoFormat->nbSuperScriptEntry()>0 );
697 oSimpleBegin= m_docAutoFormat->getConfigTypographicSimpleQuotes().begin ;
698 oSimpleEnd= m_docAutoFormat->getConfigTypographicSimpleQuotes().end;
699 oDoubleBegin= m_docAutoFormat->getConfigTypographicDoubleQuotes().begin;
700 oDoubleEnd= m_docAutoFormat->getConfigTypographicDoubleQuotes().end;
701 bulletStyle= m_docAutoFormat->getConfigBulletStyle();
702 delete newEntry;
703 newEntry=0L;
704 changeLanguage=false;
705 }
706}
707
708void KoAutoFormatDia::setupTab4()
709{
710 tab4 = addPage( i18n( "Exceptions" ) );
711 TQVBoxLayout *vbox = new TQVBoxLayout(tab4, 0, KDialog::spacingHint());
712
713 abbreviation=new KoAutoFormatExceptionWidget(tab4,
714 i18n("Do not treat as the end of a sentence:"),
715 m_autoFormat.listException(),
716 m_autoFormat.getConfigIncludeAbbreviation() , true);
717
718 vbox->addWidget( abbreviation );
719
720 twoUpperLetter=new KoAutoFormatExceptionWidget(tab4,
721 i18n("Accept two uppercase letters in:"),
722 m_autoFormat.listTwoUpperLetterException(),
723 m_autoFormat.getConfigIncludeTwoUpperUpperLetterException());
724
725 vbox->addWidget( twoUpperLetter );
726
727 initTab4();
728}
729
730void KoAutoFormatDia::initTab4()
731{
732 abbreviation->setListException( !changeLanguage ? m_autoFormat.listException(): m_docAutoFormat->listException() );
733 if ( !changeLanguage )
734 {
735 abbreviation->setAutoInclude( m_docAutoFormat->getConfigIncludeAbbreviation() );
736 twoUpperLetter->setAutoInclude( m_docAutoFormat->getConfigIncludeTwoUpperUpperLetterException() );
737 }
738 twoUpperLetter->setListException( !changeLanguage ? m_autoFormat.listTwoUpperLetterException():m_docAutoFormat->listTwoUpperLetterException() );
739}
740
741void KoAutoFormatDia::slotClearTextFormatEntry()
742{
743 bool addNewEntry = (pbAdd->text() == i18n( "&Add" ));
744 if ( m_pListView->currentItem() || addNewEntry)
745 {
746 if ( addNewEntry )
747 {
748 if (newEntry)
749 newEntry->clearFormatEntryContext();
750 }
751 else
752 {
753 KoAutoFormatEntry *entry = m_docAutoFormat->findFormatEntry(m_pListView->currentItem()->text(0));
754 entry->clearFormatEntryContext();
755 }
756 autocorrectionEntryChanged= true;
757 }
758}
759
760void KoAutoFormatDia::slotChangeTextFormatEntry()
761{
762 bool addNewEntry = (pbAdd->text() == i18n( "&Add" ));
763 if ( m_pListView->currentItem() || addNewEntry)
764 {
765 KoAutoFormatEntry *entry = 0L;
766 if ( addNewEntry )
767 {
768 if ( m_replace->text().isEmpty() )
769 return;
770 if ( !newEntry )
771 newEntry = new KoAutoFormatEntry( m_replace->text());
772 entry =newEntry;
773 }
774 else
775 entry = m_docAutoFormat->findFormatEntry(m_pListView->currentItem()->text(0));
776 KoSearchContext *tmpFormat = entry->formatEntryContext();
777 bool createNewFormat = false;
778
779 if ( !tmpFormat )
780 {
781 tmpFormat = new KoSearchContext();
782 createNewFormat = true;
783 }
784
785 KoFormatDia *dia = new KoFormatDia( this, i18n("Change Text Format"), tmpFormat , 0L);
786 if ( dia->exec())
787 {
788 dia->ctxOptions( );
789 if ( createNewFormat )
790 entry->setFormatEntryContext( tmpFormat );
791 autocorrectionEntryChanged= true;
792
793 }
794 else
795 {
796 if ( createNewFormat )
797 delete tmpFormat;
798 }
799 delete dia;
800 }
801}
802
803void KoAutoFormatDia::slotRemoveEntry()
804{
805 //find entry in listbox
806 if(m_pListView->currentItem())
807 {
808 m_docAutoFormat->removeAutoFormatEntry(m_pListView->currentItem()->text(0));
809 pbAdd->setText(i18n("&Add"));
810 refreshEntryList();
811 autocorrectionEntryChanged= true;
812 }
813}
814
815
816void KoAutoFormatDia::slotfind( const TQString & )
817{
818 KoAutoFormatEntry *entry = m_docAutoFormat->findFormatEntry(m_find->text());
819 if ( entry )
820 {
821 m_replace->setText(entry->replace().latin1());
822 pbAdd->setText(i18n("&Modify"));
823 m_pListView->setCurrentItem(m_pListView->findItem(m_find->text(),0));
824
825 } else {
826 m_replace->clear();
827 pbAdd->setText(i18n("&Add"));
828 m_pListView->setCurrentItem(0L);
829 }
830 slotfind2("");
831}
832
833
834void KoAutoFormatDia::slotfind2( const TQString & )
835{
836 bool state = !m_replace->text().isEmpty() && !m_find->text().isEmpty();
837 KoAutoFormatEntry * entry=m_docAutoFormat->findFormatEntry(m_find->text());
838 pbRemove->setEnabled(state && entry);
839 if ( state && entry )
840 {
841 delete newEntry;
842 newEntry = 0L;
843 }
844 pbChangeFormat->setEnabled(state);
845 pbClearFormat->setEnabled(state);
846 pbAdd->setEnabled(state);
847}
848
849
850void KoAutoFormatDia::refreshEntryList()
851{
852 m_pListView->clear();
853 TQDictIterator<KoAutoFormatEntry> it( m_docAutoFormat->getAutoFormatEntries());
854 for( ; it.current(); ++it )
855 {
856 ( void )new TQListViewItem( m_pListView, it.currentKey(), it.current()->replace() );
857 }
858 m_pListView->setCurrentItem(m_pListView->firstChild ());
859 bool state = !(m_replace->text().isEmpty()) && !(m_find->text().isEmpty());
860 //we can delete item, as we search now in listbox and not in m_find lineedit
861 pbRemove->setEnabled(m_pListView->currentItem() && m_pListView->selectedItem()!=0 );
862 pbChangeFormat->setEnabled(state && m_pListView->currentItem() && m_pListView->selectedItem()!=0 );
863 pbClearFormat->setEnabled(state && m_pListView->currentItem() && m_pListView->selectedItem()!=0 );
864
865 pbAdd->setEnabled(state);
866}
867
868
869void KoAutoFormatDia::addEntryList(const TQString &key, KoAutoFormatEntry *_autoEntry)
870{
871 m_docAutoFormat->addAutoFormatEntry( key, _autoEntry );
872}
873
874
875
876void KoAutoFormatDia::editEntryList(const TQString &key,const TQString &newFindString, KoAutoFormatEntry *_autoEntry)
877{
878 if ( m_docAutoFormat->findFormatEntry(key) && m_docAutoFormat->findFormatEntry(key)->formatEntryContext())
879 _autoEntry->setFormatEntryContext( new KoSearchContext(*(m_docAutoFormat->findFormatEntry(key)->formatEntryContext()) ));
880 m_docAutoFormat->removeAutoFormatEntry( key );
881 m_docAutoFormat->addAutoFormatEntry( newFindString, _autoEntry );
882}
883
884
885void KoAutoFormatDia::slotAddEntry()
886{
887 if(!pbAdd->isEnabled())
888 return;
889 TQString repl = m_replace->text();
890 TQString find = m_find->text();
891 if(repl.isEmpty() || find.isEmpty())
892 {
893 KMessageBox::sorry( 0L, i18n( "An area is empty" ) );
894 return;
895 }
896 if(repl==find)
897 {
898 KMessageBox::sorry( 0L, i18n( "Find string is the same as replace string!" ) );
899 return;
900 }
901 KoAutoFormatEntry *tmp = new KoAutoFormatEntry( repl );
902
903 if(pbAdd->text() == i18n( "&Add" ))
904 {
905 if ( newEntry )
906 {
907 newEntry->changeReplace( m_replace->text());
908 addEntryList(find, newEntry);
909 delete tmp;
910 newEntry = 0L;
911 }
912 else
913 addEntryList(find, tmp);
914 }
915 else
916 editEntryList(find, find, tmp);
917 m_replace->clear();
918 m_find->clear();
919
920 refreshEntryList();
921 autocorrectionEntryChanged= true;
922}
923
924
925void KoAutoFormatDia::chooseSpecialChar1()
926{
927 TQString f = font().family();
928 TQChar c = ' ';
929 bool const focus = m_find->hasFocus();
930 if ( KoCharSelectDia::selectChar( f, c, false ) )
931 {
932 int const cursorpos = m_find->cursorPosition();
933 if (focus)
934 m_find->setText( m_find->text().insert( cursorpos, c ) );
935 else
936 m_find->setText( m_find->text().append(c) );
937 m_find->setCursorPosition( cursorpos+1 );
938 }
939}
940
941
942void KoAutoFormatDia::chooseSpecialChar2()
943{
944 TQString f = font().family();
945 TQChar c = ' ';
946 bool const focus = m_replace->hasFocus();
947 if ( KoCharSelectDia::selectChar( f, c, false ) )
948 {
949 int const cursorpos = m_replace->cursorPosition();
950 if (focus)
951 m_replace->setText( m_replace->text().insert(m_replace->cursorPosition(), c ) );
952 else
953 m_replace->setText( m_replace->text().append(c) );
954 m_replace->setCursorPosition( cursorpos+1 );
955 }
956}
957
958
959void KoAutoFormatDia::slotItemRenamed(TQListViewItem *, const TQString & , int )
960{
961 // Wow. This need a redesign (we don't have the old key anymore at this point !)
962 // -> inherit TQListViewItem and store the KoAutoFormatEntry pointer in it.
963}
964
965
966void KoAutoFormatDia::slotEditEntry()
967{
968 if(m_pListView->currentItem()==0)
969 return;
970 delete newEntry;
971 newEntry=0L;
972 m_find->setText(m_pListView->currentItem()->text(0));
973 m_replace->setText(m_pListView->currentItem()->text(1));
974 bool state = !m_replace->text().isEmpty() && !m_find->text().isEmpty();
975 pbRemove->setEnabled(state);
976 pbChangeFormat->setEnabled( state );
977 pbClearFormat->setEnabled(state);
978 pbAdd->setEnabled(state);
979}
980
981
982bool KoAutoFormatDia::applyConfig()
983{
984 // First tab
985 KoAutoFormat::TypographicQuotes tq = m_autoFormat.getConfigTypographicSimpleQuotes();
986 tq.replace = cbTypographicSimpleQuotes->isChecked();
987 tq.begin = pbSimpleQuote1->text()[ 0 ];
988 tq.end = pbSimpleQuote2->text()[ 0 ];
989 m_docAutoFormat->configTypographicSimpleQuotes( tq );
990
991 tq = m_autoFormat.getConfigTypographicDoubleQuotes();
992 tq.replace = cbTypographicDoubleQuotes->isChecked();
993 tq.begin = pbDoubleQuote1->text()[ 0 ];
994 tq.end = pbDoubleQuote2->text()[ 0 ];
995 m_docAutoFormat->configTypographicDoubleQuotes( tq );
996
997
998 m_docAutoFormat->configUpperCase( cbUpperCase->isChecked() );
999 m_docAutoFormat->configUpperUpper( cbUpperUpper->isChecked() );
1000 m_docAutoFormat->configAutoDetectUrl( cbDetectUrl->isChecked() );
1001
1002 m_docAutoFormat->configIgnoreDoubleSpace( cbIgnoreDoubleSpace->isChecked());
1003 m_docAutoFormat->configRemoveSpaceBeginEndLine( cbRemoveSpaceBeginEndLine->isChecked());
1004 m_docAutoFormat->configUseBulletStyle(cbUseBulletStyle->isChecked());
1005
1006 m_docAutoFormat->configBulletStyle(pbBulletStyle->text()[ 0 ]);
1007
1008 m_docAutoFormat->configAutoChangeFormat( cbAutoChangeFormat->isChecked());
1009
1010 m_docAutoFormat->configAutoReplaceNumber( cbAutoReplaceNumber->isChecked());
1011 m_docAutoFormat->configAutoNumberStyle(cbUseNumberStyle->isChecked());
1012
1013 m_docAutoFormat->configAutoSuperScript ( cbAutoSuperScript->isChecked() );
1014 m_docAutoFormat->configCapitalizeNameOfDays( cbCapitalizeDaysName->isChecked());
1015
1016
1017 // Second tab
1018 //m_docAutoFormat->copyAutoFormatEntries( m_autoFormat );
1019 m_docAutoFormat->copyListException(abbreviation->getListException());
1020 m_docAutoFormat->copyListTwoUpperCaseException(twoUpperLetter->getListException());
1021 m_docAutoFormat->configAdvancedAutocorrect( cbAdvancedAutoCorrection->isChecked() );
1022 m_docAutoFormat->configCorrectionWithFormat( cbAutoCorrectionWithFormat->isChecked());
1023
1024 m_docAutoFormat->configIncludeTwoUpperUpperLetterException( twoUpperLetter->autoInclude());
1025 m_docAutoFormat->configIncludeAbbreviation( abbreviation->autoInclude());
1026
1027 TQString lang = exceptionLanguageName.find(autoFormatLanguage->currentText()).data();
1028 if ( lang == i18n("Default") )
1029 m_docAutoFormat->configAutoFormatLanguage(TQString());
1030 else
1031 m_docAutoFormat->configAutoFormatLanguage(lang);
1032
1033 // Save to config file
1034 m_docAutoFormat->saveConfig();
1035 return true;
1036}
1037
1038void KoAutoFormatDia::slotOk()
1039{
1040 if (applyConfig())
1041 {
1043 }
1044}
1045
1046void KoAutoFormatDia::slotCancel()
1047{
1048 //force to reload
1049 if ( autocorrectionEntryChanged )
1050 {
1051 m_docAutoFormat->configAutoFormatLanguage( initialLanguage);
1052 m_docAutoFormat->readConfig( true );
1053 }
1055}
1056
1057void KoAutoFormatDia::chooseDoubleQuote1()
1058{
1059 TQString f = font().family();
1060 TQChar c = oDoubleBegin;
1061 if ( KoCharSelectDia::selectChar( f, c, false ) )
1062 {
1063 pbDoubleQuote1->setText( c );
1064 }
1065
1066}
1067
1068void KoAutoFormatDia::chooseDoubleQuote2()
1069{
1070 TQString f = font().family();
1071 TQChar c = oDoubleEnd;
1072 if ( KoCharSelectDia::selectChar( f, c, false ) )
1073 {
1074 pbDoubleQuote2->setText( c );
1075 }
1076}
1077
1078
1079void KoAutoFormatDia::defaultDoubleQuote()
1080{
1081 pbDoubleQuote1->setText(m_docAutoFormat->getDefaultTypographicDoubleQuotes().begin);
1082 pbDoubleQuote2->setText(m_docAutoFormat->getDefaultTypographicDoubleQuotes().end);
1083}
1084
1085void KoAutoFormatDia::chooseSimpleQuote1()
1086{
1087 TQString f = font().family();
1088 TQChar c = oSimpleBegin;
1089 if ( KoCharSelectDia::selectChar( f, c, false ) )
1090 {
1091 pbSimpleQuote1->setText( c );
1092 }
1093}
1094
1095void KoAutoFormatDia::chooseSimpleQuote2()
1096{
1097 TQString f = font().family();
1098 TQChar c = oSimpleEnd;
1099 if ( KoCharSelectDia::selectChar( f, c, false ) )
1100 {
1101 pbSimpleQuote2->setText( c );
1102 }
1103}
1104
1105void KoAutoFormatDia::defaultSimpleQuote()
1106{
1107
1108 pbSimpleQuote1->setText(m_docAutoFormat->getDefaultTypographicSimpleQuotes().begin);
1109 pbSimpleQuote2->setText(m_docAutoFormat->getDefaultTypographicSimpleQuotes().end);
1110}
1111
1112
1113void KoAutoFormatDia::chooseBulletStyle()
1114{
1115 TQString f = font().family();
1116 TQChar c = bulletStyle;
1117 if ( KoCharSelectDia::selectChar( f, c, false ) )
1118 {
1119 pbBulletStyle->setText( c );
1120 }
1121}
1122
1123void KoAutoFormatDia::defaultBulletStyle()
1124{
1125 pbBulletStyle->setText( "" );
1126}
1127
1128void KoAutoFormatDia::slotChangeStateSimple(bool b)
1129{
1130 pbSimpleQuote1->setEnabled(b);
1131 pbSimpleQuote2->setEnabled(b);
1132 pbSimpleDefault->setEnabled(b);
1133}
1134
1135void KoAutoFormatDia::slotChangeStateDouble(bool b)
1136{
1137 pbDoubleQuote1->setEnabled(b);
1138 pbDoubleQuote2->setEnabled(b);
1139 pbDoubleDefault->setEnabled(b);
1140}
1141
1142#include "KoAutoFormatDia.moc"
virtual void slotCancel()
virtual void slotOk()
static int spacingHint()
static void sorry(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, int options=Notify)
The separate dialog that pops up to ask for which formatting options should be used to match text,...
virtual TQString text() const
TDEAction * find(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
const char * name(StdAction id)