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