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