00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <limits.h>
00023
00024 #include <qframe.h>
00025 #include <qlabel.h>
00026 #include <qlayout.h>
00027 #include <qlineedit.h>
00028 #include <qvbuttongroup.h>
00029 #include <qcheckbox.h>
00030 #include <qlayout.h>
00031 #include <qpushbutton.h>
00032 #include <qhbox.h>
00033
00034 #include <kapplication.h>
00035 #include <kcombobox.h>
00036 #include <knuminput.h>
00037 #include <kmessagebox.h>
00038 #include <knotifyclient.h>
00039 #include <klocale.h>
00040 #include <kdebug.h>
00041
00042 #include "keditcl.h"
00043
00044
00046
00047
00048
00049
00050 void KEdit::search(){
00051
00052 if( replace_dialog != 0 && replace_dialog->isVisible() == true )
00053 {
00054 replace_dialog->hide();
00055 }
00056
00057 if( srchdialog == 0 )
00058 {
00059 srchdialog = new KEdFind( this, "searchdialog", false);
00060 connect(srchdialog,SIGNAL(search()),this,SLOT(search_slot()));
00061 connect(srchdialog,SIGNAL(done()),this,SLOT(searchdone_slot()));
00062 }
00063
00064
00065
00066
00067 QString string;
00068 string = srchdialog->getText();
00069 srchdialog->setText(string.isEmpty() ? pattern : string);
00070
00071 this->deselect();
00072 last_search = NONE;
00073
00074 srchdialog->show();
00075 srchdialog->result();
00076 }
00077
00078
00079 void KEdit::search_slot(){
00080
00081 int line, col;
00082
00083 if (!srchdialog)
00084 return;
00085
00086 QString to_find_string = srchdialog->getText();
00087 getCursorPosition(&line,&col);
00088
00089
00090
00091 if (last_search != NONE && srchdialog->get_direction()){
00092 col = col - pattern.length() - 1 ;
00093 }
00094
00095 again:
00096 int result = doSearch(to_find_string, srchdialog->case_sensitive(),
00097 FALSE, (!srchdialog->get_direction()),line,col);
00098
00099 if(result == 0){
00100 if(!srchdialog->get_direction()){
00101
00102 int query = KMessageBox::questionYesNo(
00103 srchdialog,
00104 i18n("End of document reached.\n"\
00105 "Continue from the beginning?"),
00106 i18n("Find"));
00107 if (query == KMessageBox::Yes){
00108 line = 0;
00109 col = 0;
00110 goto again;
00111 }
00112 }
00113 else{
00114
00115 int query = KMessageBox::questionYesNo(
00116 srchdialog,
00117 i18n("Beginning of document reached.\n"\
00118 "Continue from the end?"),
00119 i18n("Find"));
00120 if (query == KMessageBox::Yes){
00121 QString string = textLine( numLines() - 1 );
00122 line = numLines() - 1;
00123 col = string.length();
00124 last_search = BACKWARD;
00125 goto again;
00126 }
00127 }
00128 }
00129 else{
00130 emit CursorPositionChanged();
00131 }
00132 }
00133
00134
00135
00136 void KEdit::searchdone_slot(){
00137
00138 if (!srchdialog)
00139 return;
00140
00141 srchdialog->hide();
00142 this->setFocus();
00143 last_search = NONE;
00144
00145 }
00146
00147 int KEdit::doSearch(QString s_pattern, bool case_sensitive,
00148 bool wildcard, bool forward, int line, int col){
00149
00150 (void) wildcard;
00151
00152
00153 int i, length;
00154 int pos = -1;
00155
00156 if(forward){
00157
00158 QString string;
00159
00160 for(i = line; i < numLines(); i++) {
00161
00162 string = textLine(i);
00163
00164 pos = string.find(s_pattern, i == line ? col : 0, case_sensitive);
00165
00166 if( pos != -1){
00167
00168 length = s_pattern.length();
00169
00170 setCursorPosition(i,pos,FALSE);
00171
00172 for(int l = 0 ; l < length; l++){
00173 cursorRight(TRUE);
00174 }
00175
00176 setCursorPosition( i , pos + length, TRUE );
00177 pattern = s_pattern;
00178 last_search = FORWARD;
00179
00180 return 1;
00181 }
00182 }
00183 }
00184 else{
00185
00186 QString string;
00187
00188 for(i = line; i >= 0; i--) {
00189
00190 string = textLine(i);
00191 int line_length = string.length();
00192
00193 pos = string.findRev(s_pattern, line == i ? col : line_length , case_sensitive);
00194
00195 if (pos != -1){
00196
00197 length = s_pattern.length();
00198
00199 if( ! (line == i && pos > col ) ){
00200
00201 setCursorPosition(i ,pos ,FALSE );
00202
00203 for(int l = 0 ; l < length; l++){
00204 cursorRight(TRUE);
00205 }
00206
00207 setCursorPosition(i ,pos + length ,TRUE );
00208 pattern = s_pattern;
00209 last_search = BACKWARD;
00210 return 1;
00211
00212 }
00213 }
00214
00215 }
00216 }
00217
00218 return 0;
00219
00220 }
00221
00222
00223
00224 bool KEdit::repeatSearch() {
00225
00226 if(!srchdialog)
00227 return false;
00228
00229
00230 if(pattern.isEmpty())
00231 return false;
00232
00233 search_slot();
00234
00235 this->setFocus();
00236 return true;
00237
00238 }
00239
00240
00242
00243
00244
00245
00246
00247 void KEdit::replace()
00248 {
00249 if( srchdialog != 0 && srchdialog->isVisible() == true)
00250 {
00251 srchdialog->hide();
00252 }
00253
00254 if( replace_dialog == 0 )
00255 {
00256 replace_dialog = new KEdReplace( this, "replace_dialog", false );
00257 connect(replace_dialog,SIGNAL(find()),this,SLOT(replace_search_slot()));
00258 connect(replace_dialog,SIGNAL(replace()),this,SLOT(replace_slot()));
00259 connect(replace_dialog,SIGNAL(replaceAll()),this,SLOT(replace_all_slot()));
00260 connect(replace_dialog,SIGNAL(done()),this,SLOT(replacedone_slot()));
00261 }
00262
00263 QString string = replace_dialog->getText();
00264 replace_dialog->setText(string.isEmpty() ? pattern : string);
00265
00266
00267 this->deselect();
00268 last_replace = NONE;
00269
00270 replace_dialog->show();
00271 replace_dialog->result();
00272 }
00273
00274
00275 void KEdit::replace_slot(){
00276
00277 if (!replace_dialog)
00278 return;
00279
00280 if(!can_replace){
00281 KNotifyClient::beep();
00282 return;
00283 }
00284
00285 int line,col, length;
00286
00287 QString string = replace_dialog->getReplaceText();
00288 length = string.length();
00289
00290 this->cut();
00291
00292 getCursorPosition(&line,&col);
00293
00294 insertAt(string,line,col);
00295 setModified(true);
00296 can_replace = FALSE;
00297
00298 setCursorPosition(line,col);
00299 for( int k = 0; k < length; k++){
00300 cursorRight(TRUE);
00301 }
00302
00303 }
00304
00305 void KEdit::replace_all_slot(){
00306
00307 if (!replace_dialog)
00308 return;
00309
00310 QString to_find_string = replace_dialog->getText();
00311 getCursorPosition(&replace_all_line,&replace_all_col);
00312
00313
00314
00315 if (last_replace != NONE && replace_dialog->get_direction()){
00316 replace_all_col = replace_all_col - pattern.length() - 1 ;
00317 }
00318
00319 deselect();
00320
00321 again:
00322
00323 setAutoUpdate(FALSE);
00324 int result = 1;
00325
00326 while(result){
00327
00328 result = doReplace(to_find_string, replace_dialog->case_sensitive(),
00329 FALSE, (!replace_dialog->get_direction()),
00330 replace_all_line,replace_all_col,TRUE);
00331
00332 }
00333
00334 setAutoUpdate(TRUE);
00335 update();
00336
00337 if(!replace_dialog->get_direction()){
00338
00339 int query = KMessageBox::questionYesNo(
00340 srchdialog,
00341 i18n("End of document reached.\n"\
00342 "Continue from the beginning?"),
00343 i18n("Find"));
00344 if (query == KMessageBox::Yes){
00345 replace_all_line = 0;
00346 replace_all_col = 0;
00347 goto again;
00348 }
00349 }
00350 else{
00351
00352 int query = KMessageBox::questionYesNo(
00353 srchdialog,
00354 i18n("Beginning of document reached.\n"\
00355 "Continue from the end?"),
00356 i18n("Find"));
00357 if (query == KMessageBox::Yes){
00358 QString string = textLine( numLines() - 1 );
00359 replace_all_line = numLines() - 1;
00360 replace_all_col = string.length();
00361 last_replace = BACKWARD;
00362 goto again;
00363 }
00364 }
00365
00366 emit CursorPositionChanged();
00367
00368 }
00369
00370
00371 void KEdit::replace_search_slot(){
00372
00373 int line, col;
00374
00375 if (!replace_dialog)
00376 return;
00377
00378 QString to_find_string = replace_dialog->getText();
00379 getCursorPosition(&line,&col);
00380
00381
00382
00383
00384
00385 if (last_replace != NONE && replace_dialog->get_direction()){
00386 col = col - pattern.length() -1;
00387 if (col < 0 ) {
00388 if(line !=0){
00389 col = textLine(line - 1).length();
00390 line --;
00391 }
00392 else{
00393
00394 int query = KMessageBox::questionYesNo(
00395 replace_dialog,
00396 i18n("Beginning of document reached.\n"\
00397 "Continue from the end?"),
00398 i18n("Replace"));
00399 if (query == KMessageBox::Yes){
00400 QString string = textLine( numLines() - 1 );
00401 line = numLines() - 1;
00402 col = string.length();
00403 last_replace = BACKWARD;
00404 }
00405 }
00406 }
00407 }
00408
00409 again:
00410
00411
00412
00413 int result = doReplace(to_find_string, replace_dialog->case_sensitive(),
00414 FALSE, (!replace_dialog->get_direction()), line, col, FALSE );
00415
00416 if(result == 0){
00417 if(!replace_dialog->get_direction()){
00418
00419 int query = KMessageBox::questionYesNo(
00420 replace_dialog,
00421 i18n("End of document reached.\n"\
00422 "Continue from the beginning?"),
00423 i18n("Replace"));
00424 if (query == KMessageBox::Yes){
00425 line = 0;
00426 col = 0;
00427 goto again;
00428 }
00429 }
00430 else{
00431
00432 int query = KMessageBox::questionYesNo(
00433 replace_dialog,
00434 i18n("Beginning of document reached.\n"\
00435 "Continue from the end?"),
00436 i18n("Replace"));
00437 if (query == KMessageBox::Yes){
00438 QString string = textLine( numLines() - 1 );
00439 line = numLines() - 1;
00440 col = string.length();
00441 last_replace = BACKWARD;
00442 goto again;
00443 }
00444 }
00445 }
00446 else{
00447
00448 emit CursorPositionChanged();
00449 }
00450 }
00451
00452
00453
00454 void KEdit::replacedone_slot(){
00455
00456 if (!replace_dialog)
00457 return;
00458
00459 replace_dialog->hide();
00460
00461
00462 this->setFocus();
00463
00464 last_replace = NONE;
00465 can_replace = FALSE;
00466
00467 }
00468
00469
00470
00471 int KEdit::doReplace(QString s_pattern, bool case_sensitive,
00472 bool wildcard, bool forward, int line, int col, bool replace_all){
00473
00474
00475 (void) wildcard;
00476
00477 int line_counter, length;
00478 int pos = -1;
00479
00480 QString string;
00481 QString stringnew;
00482 QString replacement;
00483
00484 replacement = replace_dialog->getReplaceText();
00485 line_counter = line;
00486 replace_all_col = col;
00487
00488 if(forward){
00489
00490 int num_lines = numLines();
00491
00492 while (line_counter < num_lines){
00493
00494 string = "";
00495 string = textLine(line_counter);
00496
00497 if (replace_all){
00498 pos = string.find(s_pattern, replace_all_col, case_sensitive);
00499 }
00500 else{
00501 pos = string.find(s_pattern, line_counter == line ? col : 0, case_sensitive);
00502 }
00503
00504 if (pos == -1 ){
00505 line_counter ++;
00506 replace_all_col = 0;
00507 replace_all_line = line_counter;
00508 }
00509
00510 if( pos != -1){
00511
00512 length = s_pattern.length();
00513
00514 if(replace_all){
00515
00516 stringnew = string.copy();
00517 stringnew.replace(pos,length,replacement);
00518
00519 removeLine(line_counter);
00520 insertLine(stringnew,line_counter);
00521
00522 replace_all_col = replace_all_col + replacement.length();
00523 replace_all_line = line_counter;
00524
00525 setModified(true);
00526 }
00527 else{
00528
00529 setCursorPosition( line_counter , pos, FALSE );
00530
00531 for(int l = 0 ; l < length; l++){
00532 cursorRight(TRUE);
00533 }
00534
00535 setCursorPosition( line_counter , pos + length, TRUE );
00536 pattern = s_pattern;
00537 last_replace = FORWARD;
00538 can_replace = TRUE;
00539
00540 return 1;
00541
00542 }
00543
00544 }
00545 }
00546 }
00547 else{
00548
00549 while(line_counter >= 0){
00550
00551 string = "";
00552 string = textLine(line_counter);
00553
00554 int line_length = string.length();
00555
00556 if( replace_all ){
00557 pos = string.findRev(s_pattern, replace_all_col , case_sensitive);
00558 }
00559 else{
00560 pos = string.findRev(s_pattern,
00561 line == line_counter ? col : line_length , case_sensitive);
00562 }
00563
00564 if (pos == -1 ){
00565 line_counter --;
00566
00567 if(line_counter >= 0){
00568 string = "";
00569 string = textLine(line_counter);
00570 replace_all_col = string.length();
00571
00572 }
00573 replace_all_line = line_counter;
00574 }
00575
00576
00577 if (pos != -1){
00578 length = s_pattern.length();
00579
00580 if(replace_all){
00581
00582 stringnew = string.copy();
00583 stringnew.replace(pos,length,replacement);
00584
00585 removeLine(line_counter);
00586 insertLine(stringnew,line_counter);
00587
00588 replace_all_col = replace_all_col - replacement.length();
00589 replace_all_line = line_counter;
00590
00591 setModified(true);
00592
00593 }
00594 else{
00595
00596
00597 if( ! (line == line_counter && pos > col ) ){
00598
00599 setCursorPosition(line_counter ,pos ,FALSE );
00600
00601 for(int l = 0 ; l < length; l++){
00602 cursorRight(TRUE);
00603 }
00604
00605 setCursorPosition(line_counter ,pos + length ,TRUE );
00606 pattern = s_pattern;
00607
00608 last_replace = BACKWARD;
00609 can_replace = TRUE;
00610
00611 return 1;
00612 }
00613 }
00614 }
00615 }
00616 }
00617
00618 return 0;
00619
00620 }
00621
00622
00623
00624
00625
00627
00628
00629
00630
00631 class KEdFind::KEdFindPrivate
00632 {
00633 public:
00634 KEdFindPrivate( QWidget *parent ) {
00635 combo = new KHistoryCombo( parent, "value" );
00636 combo->setMaxCount( 20 );
00637 }
00638 ~KEdFindPrivate() {
00639 delete combo;
00640 }
00641
00642 KHistoryCombo *combo;
00643 };
00644
00645
00646 KEdFind::KEdFind( QWidget *parent, const char *name, bool modal )
00647 :KDialogBase( parent, name, modal, i18n("Find"),
00648 modal ? User1|Cancel : User1|Close, User1, false, i18n("&Find") )
00649 {
00650 setWFlags( WType_TopLevel );
00651
00652 QWidget *page = new QWidget( this );
00653 setMainWidget(page);
00654 QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() );
00655
00656 d = new KEdFindPrivate( page );
00657
00658 QString text = i18n("Find:");
00659 QLabel *label = new QLabel( text, page , "find" );
00660 topLayout->addWidget( label );
00661
00662 d->combo->setMinimumWidth(fontMetrics().maxWidth()*20);
00663 d->combo->setFocus();
00664
00665 connect(d->combo, SIGNAL(textChanged ( const QString & )),
00666 this,SLOT(textSearchChanged ( const QString & )));
00667
00668 topLayout->addWidget(d->combo);
00669
00670 group = new QVButtonGroup( i18n("Options"), page );
00671 topLayout->addWidget( group );
00672
00673 QHBox* row1 = new QHBox( group );
00674
00675 text = i18n("Case &sensitive");
00676 sensitive = new QCheckBox( text, row1, "case");
00677 text = i18n("Find &backwards");
00678 direction = new QCheckBox( text, row1, "direction" );
00679
00680
00681 enableButton( KDialogBase::User1, !d->combo->currentText().isEmpty() );
00682
00683 if ( !modal )
00684 connect( this, SIGNAL( closeClicked() ), this, SLOT( slotCancel() ) );
00685 }
00686
00687 KEdFind::~KEdFind()
00688 {
00689 delete d;
00690 }
00691
00692 void KEdFind::textSearchChanged ( const QString &text )
00693 {
00694 enableButton( KDialogBase::User1, !text.isEmpty() );
00695 }
00696
00697 void KEdFind::slotCancel( void )
00698 {
00699 emit done();
00700 d->combo->clearEdit();
00701 KDialogBase::slotCancel();
00702 }
00703
00704 void KEdFind::slotUser1( void )
00705 {
00706 if( !d->combo->currentText().isEmpty() )
00707 {
00708 d->combo->addToHistory( d->combo->currentText() );
00709 emit search();
00710 }
00711 }
00712
00713
00714 QString KEdFind::getText() const
00715 {
00716 return d->combo->currentText();
00717 }
00718
00719
00720 void KEdFind::setText(QString string)
00721 {
00722 d->combo->setEditText(string);
00723 d->combo->lineEdit()->selectAll();
00724 }
00725
00726 void KEdFind::setCaseSensitive( bool b )
00727 {
00728 sensitive->setChecked( b );
00729 }
00730
00731 bool KEdFind::case_sensitive() const
00732 {
00733 return sensitive->isChecked();
00734 }
00735
00736 void KEdFind::setDirection( bool b )
00737 {
00738 direction->setChecked( b );
00739 }
00740
00741 bool KEdFind::get_direction() const
00742 {
00743 return direction->isChecked();
00744 }
00745
00746 KHistoryCombo * KEdFind::searchCombo() const
00747 {
00748 return d->combo;
00749 }
00750
00751
00752
00754
00755
00756
00757
00758 class KEdReplace::KEdReplacePrivate
00759 {
00760 public:
00761 KEdReplacePrivate( QWidget *parent ) {
00762 searchCombo = new KHistoryCombo( parent, "value" );
00763 replaceCombo = new KHistoryCombo( parent, "replace_value" );
00764
00765 searchCombo->setMaxCount( 20 );
00766 replaceCombo->setMaxCount( 20 );
00767 }
00768 ~KEdReplacePrivate() {
00769 delete searchCombo;
00770 delete replaceCombo;
00771 }
00772
00773 KHistoryCombo *searchCombo, *replaceCombo;
00774 };
00775
00776 KEdReplace::KEdReplace( QWidget *parent, const char *name, bool modal )
00777 :KDialogBase( parent, name, modal, i18n("Replace"),
00778 modal ? User3|User2|User1|Cancel : User3|User2|User1|Close,
00779 User3, false,
00780 i18n("Replace &All"), i18n("&Replace"), i18n("&Find") )
00781 {
00782 setWFlags( WType_TopLevel );
00783
00784 setButtonBoxOrientation( Vertical );
00785
00786 QFrame *page = makeMainWidget();
00787 QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() );
00788
00789 d = new KEdReplacePrivate( page );
00790
00791 QString text = i18n("Find:");
00792 QLabel *label = new QLabel( text, page, "find" );
00793 topLayout->addWidget( label );
00794
00795 d->searchCombo->setMinimumWidth(fontMetrics().maxWidth()*20);
00796 d->searchCombo->setFocus();
00797 topLayout->addWidget(d->searchCombo);
00798
00799 text = i18n("Replace with:");
00800 label = new QLabel( text, page, "replace" );
00801 topLayout->addWidget( label );
00802
00803 d->replaceCombo->setMinimumWidth(fontMetrics().maxWidth()*20);
00804 topLayout->addWidget(d->replaceCombo);
00805
00806 connect(d->searchCombo, SIGNAL(textChanged ( const QString & )),
00807 this,SLOT(textSearchChanged ( const QString & )));
00808
00809 QButtonGroup *group = new QButtonGroup( i18n("Options"), page );
00810 topLayout->addWidget( group );
00811
00812 QGridLayout *gbox = new QGridLayout( group, 3, 2, spacingHint() );
00813 gbox->addRowSpacing( 0, fontMetrics().lineSpacing() );
00814
00815 text = i18n("Case &sensitive");
00816 sensitive = new QCheckBox( text, group, "case");
00817 text = i18n("Find &backwards");
00818 direction = new QCheckBox( text, group, "direction" );
00819 gbox->addWidget( sensitive, 1, 0 );
00820 gbox->addWidget( direction, 1, 1 );
00821 gbox->setRowStretch( 2, 10 );
00822 }
00823
00824
00825 KEdReplace::~KEdReplace()
00826 {
00827 delete d;
00828 }
00829
00830 void KEdReplace::textSearchChanged ( const QString &text )
00831 {
00832 bool state=text.isEmpty();
00833 enableButton( KDialogBase::User1, !state );
00834 enableButton( KDialogBase::User2, !state );
00835 enableButton( KDialogBase::User3, !state );
00836 }
00837
00838 void KEdReplace::slotCancel( void )
00839 {
00840 emit done();
00841 d->searchCombo->clearEdit();
00842 d->replaceCombo->clearEdit();
00843 KDialogBase::slotCancel();
00844 }
00845
00846 void KEdReplace::slotClose( void )
00847 {
00848 slotCancel();
00849 }
00850
00851 void KEdReplace::slotUser1( void )
00852 {
00853 if( !d->searchCombo->currentText().isEmpty() )
00854 {
00855 d->replaceCombo->addToHistory( d->replaceCombo->currentText() );
00856 emit replaceAll();
00857 }
00858 }
00859
00860
00861 void KEdReplace::slotUser2( void )
00862 {
00863 if( !d->searchCombo->currentText().isEmpty() )
00864 {
00865 d->replaceCombo->addToHistory( d->replaceCombo->currentText() );
00866 emit replace();
00867 }
00868 }
00869
00870 void KEdReplace::slotUser3( void )
00871 {
00872 if( !d->searchCombo->currentText().isEmpty() )
00873 {
00874 d->searchCombo->addToHistory( d->searchCombo->currentText() );
00875 emit find();
00876 }
00877 }
00878
00879
00880 QString KEdReplace::getText()
00881 {
00882 return d->searchCombo->currentText();
00883 }
00884
00885
00886 QString KEdReplace::getReplaceText()
00887 {
00888 return d->replaceCombo->currentText();
00889 }
00890
00891
00892 void KEdReplace::setText(QString string)
00893 {
00894 d->searchCombo->setEditText(string);
00895 d->searchCombo->lineEdit()->selectAll();
00896 }
00897
00898
00899 bool KEdReplace::case_sensitive()
00900 {
00901 return sensitive->isChecked();
00902 }
00903
00904
00905 bool KEdReplace::get_direction()
00906 {
00907 return direction->isChecked();
00908 }
00909
00910 KHistoryCombo * KEdReplace::searchCombo() const
00911 {
00912 return d->searchCombo;
00913 }
00914
00915 KHistoryCombo * KEdReplace::replaceCombo() const
00916 {
00917 return d->replaceCombo;
00918 }
00919
00920
00921 KEdGotoLine::KEdGotoLine( QWidget *parent, const char *name, bool modal )
00922 :KDialogBase( parent, name, modal, i18n("Goto Line"), modal ? Ok|Cancel : Ok|Close, Ok, false )
00923 {
00924 QWidget *page = new QWidget( this );
00925 setMainWidget(page);
00926 QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() );
00927
00928 lineNum = new KIntNumInput( 1, page);
00929 lineNum->setRange(1, 1000000, 1, false);
00930 lineNum->setLabel(i18n("Goto line:"), AlignVCenter | AlignLeft);
00931
00932 topLayout->addWidget( lineNum );
00933
00934 topLayout->addStretch(10);
00935 }
00936
00937
00938 void KEdGotoLine::selected(int)
00939 {
00940 accept();
00941 }
00942
00943
00944 int KEdGotoLine::getLineNumber()
00945 {
00946 return lineNum->value();
00947 }
00948
00949
00951
00952
00953
00954
00955 void KEdit::spellcheck_start()
00956 {
00957 saved_readonlystate = isReadOnly();
00958 setReadOnly(true);
00959 }
00960
00961 void KEdit::misspelling (const QString &word, const QStringList &, unsigned int pos)
00962 {
00963
00964 unsigned int l = 0;
00965 unsigned int cnt = 0;
00966 posToRowCol (pos, l, cnt);
00967 setSelection(l, cnt, l, cnt+word.length());
00968
00969
00970
00971
00972
00973
00974
00975
00976 }
00977
00978
00979 void KEdit::corrected (const QString &originalword, const QString &newword, unsigned int pos)
00980 {
00981
00982
00983
00984 unsigned int l = 0;
00985 unsigned int cnt = 0;
00986
00987 if( newword != originalword )
00988 {
00989 posToRowCol (pos, l, cnt);
00990 setSelection(l, cnt, l, cnt+originalword.length());
00991
00992 setReadOnly ( false );
00993 removeSelectedText();
00994 insert(newword);
00995 setReadOnly ( true );
00996 }
00997 else
00998 {
00999 deselect();
01000 }
01001 }
01002
01003 void KEdit::posToRowCol(unsigned int pos, unsigned int &line, unsigned int &col)
01004 {
01005 for (line = 0; line < static_cast<uint>(numLines()) && col <= pos; line++)
01006 {
01007 col += lineLength(line)+1;
01008 }
01009 line--;
01010 col = pos - col + lineLength(line) + 1;
01011 }
01012
01013 void KEdit::spellcheck_stop()
01014 {
01015 deselect();
01016
01017 setReadOnly ( saved_readonlystate);
01018 }
01019
01020
01021