# kdeui Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# keditcl2.cpp

    00001 /* This file is part of the KDE libraries
    00002
    00003    Copyright (C) 1997 Bernd Johannes Wuebben <wuebben@math.cornell.edu>
    00004    Copyright (C) 2000 Waldo Bastian <bastian@kde.org>
    00005
    00006    This library is free software; you can redistribute it and/or
    00007    modify it under the terms of the GNU Library General Public
    00008    License as published by the Free Software Foundation; either
    00009    version 2 of the License, or (at your option) any later version.
    00010
    00011    This library is distributed in the hope that it will be useful,
    00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014    Library General Public License for more details.
    00015
    00016    You should have received a copy of the GNU Library General Public License
    00017    along with this library; see the file COPYING.LIB.  If not, write to
    00018    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00019    Boston, MA 02111-1307, USA.
    00020 */
    00021
    00022 #include <limits.h> // INT_MAX
    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 // Find Methods
    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   // If we already searched / replaced something before make sure it shows
    00065   // up in the find dialog line-edit.
    00066
    00067   QString string;
    00068   string = srchdialog->getText();
    00069   srchdialog->setText(string.isEmpty() ? pattern : string);
    00070
    00071   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   // srchdialog->get_direction() is true if searching backward
    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()){ // forward search
    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{ //backward search
    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   setFocus();
    00143   last_search = NONE;
    00144 }
    00145
    00146 int KEdit::doSearch(QString s_pattern, bool case_sensitive,
    00147                     bool wildcard, bool forward, int line, int col){
    00148
    00149   (void) wildcard; // reserved for possible extension to regex
    00150
    00151
    00152   int i, length;
    00153   int pos = -1;
    00154
    00155   if(forward){
    00156
    00157     QString string;
    00158
    00159     for(i = line; i < numLines(); i++) {
    00160
    00161       string = textLine(i);
    00162
    00163       pos = string.find(s_pattern, i == line ? col : 0, case_sensitive);
    00164
    00165       if( pos != -1){
    00166
    00167         length = s_pattern.length();
    00168
    00169         setCursorPosition(i,pos,FALSE);
    00170
    00171         for(int l = 0 ; l < length; l++){
    00172           cursorRight(TRUE);
    00173         }
    00174
    00175         setCursorPosition( i , pos + length, TRUE );
    00176         pattern = s_pattern;
    00177         last_search = FORWARD;
    00178
    00179         return 1;
    00180       }
    00181     }
    00182   }
    00183   else{ // searching backwards
    00184
    00185     QString string;
    00186
    00187     for(i = line; i >= 0; i--) {
    00188
    00189       string = textLine(i);
    00190       int line_length = string.length();
    00191
    00192       pos = string.findRev(s_pattern, line == i ? col : line_length , case_sensitive);
    00193
    00194       if (pos != -1){
    00195
    00196         length = s_pattern.length();
    00197
    00198         if( ! (line == i && pos > col ) ){
    00199
    00200           setCursorPosition(i ,pos ,FALSE );
    00201
    00202           for(int l = 0 ; l < length; l++){
    00203             cursorRight(TRUE);
    00204           }
    00205
    00206           setCursorPosition(i ,pos + length ,TRUE );
    00207           pattern = s_pattern;
    00208           last_search = BACKWARD;
    00209           return 1;
    00210
    00211         }
    00212       }
    00213
    00214     }
    00215   }
    00216
    00217   return 0;
    00218
    00219 }
    00220
    00221
    00222
    00223 bool KEdit::repeatSearch() {
    00224
    00225   if(!srchdialog || pattern.isEmpty())
    00226   {
    00227       search();
    00228       return true;
    00229   }
    00230
    00231   search_slot();
    00232
    00233   setFocus();
    00234   return true;
    00235
    00236 }
    00237
    00238
    00240 //
    00241 // Replace Methods
    00242 //
    00243
    00244
    00245 void KEdit::replace()
    00246 {
    00247   if( srchdialog != 0 && srchdialog->isVisible() == true)
    00248   {
    00249     srchdialog->hide();
    00250   }
    00251
    00252   if( replace_dialog == 0 )
    00253   {
    00254     replace_dialog = new KEdReplace( this, "replace_dialog", false );
    00255     connect(replace_dialog,SIGNAL(find()),this,SLOT(replace_search_slot()));
    00256     connect(replace_dialog,SIGNAL(replace()),this,SLOT(replace_slot()));
    00257     connect(replace_dialog,SIGNAL(replaceAll()),this,SLOT(replace_all_slot()));
    00258     connect(replace_dialog,SIGNAL(done()),this,SLOT(replacedone_slot()));
    00259   }
    00260
    00261   QString string = replace_dialog->getText();
    00262   replace_dialog->setText(string.isEmpty() ? pattern : string);
    00263
    00264
    00265   deselect();
    00266   last_replace = NONE;
    00267
    00268   replace_dialog->show();
    00269   replace_dialog->result();
    00270 }
    00271
    00272
    00273 void KEdit::replace_slot(){
    00274
    00275   if (!replace_dialog)
    00276     return;
    00277
    00278   if(!can_replace){
    00279     KNotifyClient::beep();
    00280     return;
    00281   }
    00282
    00283   int line,col, length;
    00284
    00285   QString string = replace_dialog->getReplaceText();
    00286   length = string.length();
    00287
    00288   this->cut();
    00289
    00290   getCursorPosition(&line,&col);
    00291
    00292   insertAt(string,line,col);
    00293   setModified(true);
    00294   can_replace = FALSE;
    00295
    00296   if (replace_dialog->get_direction())
    00297   {
    00298     // Backward
    00299     setCursorPosition(line,col+length);
    00300     for( int k = 0; k < length; k++){
    00301       cursorLeft(TRUE);
    00302     }
    00303   }
    00304   else
    00305   {
    00306     // Forward
    00307     setCursorPosition(line,col);
    00308     for( int k = 0; k < length; k++){
    00309       cursorRight(TRUE);
    00310     }
    00311   }
    00312 }
    00313
    00314 void KEdit::replace_all_slot(){
    00315
    00316   if (!replace_dialog)
    00317     return;
    00318
    00319   QString to_find_string = replace_dialog->getText();
    00320
    00321   int lineFrom, lineTo, colFrom, colTo;
    00322   getSelection(&lineFrom, &colFrom, &lineTo, &colTo);
    00323
    00324   // replace_dialog->get_direction() is true if searching backward
    00325   if (replace_dialog->get_direction())
    00326   {
    00327     if (colTo != -1)
    00328     {
    00329       replace_all_col = colTo - to_find_string.length();
    00330       replace_all_line = lineTo;
    00331     }
    00332     else
    00333     {
    00334       getCursorPosition(&replace_all_line,&replace_all_col);
    00335       replace_all_col--;
    00336     }
    00337   }
    00338   else
    00339   {
    00340     if (colFrom != -1)
    00341     {
    00342       replace_all_col = colFrom;
    00343       replace_all_line = lineFrom;
    00344     }
    00345     else
    00346     {
    00347       getCursorPosition(&replace_all_line,&replace_all_col);
    00348     }
    00349   }
    00350
    00351   deselect();
    00352
    00353 again:
    00354
    00355   setAutoUpdate(FALSE);
    00356   int result = 1;
    00357
    00358   while(result){
    00359
    00360     result = doReplace(to_find_string, replace_dialog->case_sensitive(),
    00361                        FALSE, (!replace_dialog->get_direction()),
    00362                        replace_all_line,replace_all_col,TRUE);
    00363
    00364   }
    00365
    00366   setAutoUpdate(TRUE);
    00367   update();
    00368
    00369   if(!replace_dialog->get_direction()){ // forward search
    00370
    00371     int query = KMessageBox::questionYesNo(
    00372                         srchdialog,
    00373                         i18n("End of document reached.\n"\
    00374                              "Continue from the beginning?"),
    00375                         i18n("Find"));
    00376     if (query == KMessageBox::Yes){
    00377       replace_all_line = 0;
    00378       replace_all_col = 0;
    00379       goto again;
    00380     }
    00381   }
    00382   else{ //backward search
    00383
    00384     int query = KMessageBox::questionYesNo(
    00385                         srchdialog,
    00386                         i18n("Beginning of document reached.\n"\
    00387                              "Continue from the end?"),
    00388                         i18n("Find"));
    00389     if (query == KMessageBox::Yes){
    00390       QString string = textLine( numLines() - 1 );
    00391       replace_all_line = numLines() - 1;
    00392       replace_all_col  = string.length();
    00393       last_replace = BACKWARD;
    00394       goto again;
    00395     }
    00396   }
    00397
    00398   emit CursorPositionChanged();
    00399
    00400 }
    00401
    00402
    00403 void KEdit::replace_search_slot(){
    00404
    00405   int line, col;
    00406
    00407   if (!replace_dialog)
    00408     return;
    00409
    00410   QString to_find_string = replace_dialog->getText();
    00411
    00412   int lineFrom, lineTo, colFrom, colTo;
    00413   getSelection(&lineFrom, &colFrom, &lineTo, &colTo);
    00414
    00415   // replace_dialog->get_direction() is true if searching backward
    00416   if (replace_dialog->get_direction())
    00417   {
    00418     if (colFrom != -1)
    00419     {
    00420       col = colFrom - to_find_string.length();
    00421       line = lineFrom;
    00422     }
    00423     else
    00424     {
    00425       getCursorPosition(&line,&col);
    00426       col--;
    00427     }
    00428   }
    00429   else
    00430   {
    00431     if (colTo != -1)
    00432     {
    00433       col = colTo;
    00434       line = lineTo;
    00435     }
    00436     else
    00437     {
    00438       getCursorPosition(&line,&col);
    00439     }
    00440   }
    00441
    00442 again:
    00443
    00444   int  result = doReplace(to_find_string, replace_dialog->case_sensitive(),
    00445                          FALSE, (!replace_dialog->get_direction()), line, col, FALSE );
    00446
    00447   if(result == 0){
    00448     if(!replace_dialog->get_direction()){ // forward search
    00449
    00450      int query = KMessageBox::questionYesNo(
    00451                         replace_dialog,
    00452                         i18n("End of document reached.\n"\
    00453                              "Continue from the beginning?"),
    00454                         i18n("Replace"));
    00455      if (query == KMessageBox::Yes){
    00456         line = 0;
    00457         col = 0;
    00458         goto again;
    00459       }
    00460     }
    00461     else{ //backward search
    00462
    00463      int query = KMessageBox::questionYesNo(
    00464                         replace_dialog,
    00465                         i18n("Beginning of document reached.\n"\
    00466                              "Continue from the end?"),
    00467                         i18n("Replace"));
    00468       if (query == KMessageBox::Yes){
    00469         QString string = textLine( numLines() - 1 );
    00470         line = numLines() - 1;
    00471         col  = string.length();
    00472         last_replace = BACKWARD;
    00473         goto again;
    00474       }
    00475     }
    00476   }
    00477   else{
    00478
    00479     emit CursorPositionChanged();
    00480   }
    00481 }
    00482
    00483
    00484
    00485 void KEdit::replacedone_slot(){
    00486
    00487   if (!replace_dialog)
    00488     return;
    00489
    00490   replace_dialog->hide();
    00491   //  replace_dialog->clearFocus();
    00492
    00493   setFocus();
    00494
    00495   last_replace = NONE;
    00496   can_replace  = FALSE;
    00497
    00498 }
    00499
    00500
    00501
    00502 int KEdit::doReplace(QString s_pattern, bool case_sensitive,
    00503            bool wildcard, bool forward, int line, int col, bool replace_all){
    00504
    00505
    00506   (void) wildcard; // reserved for possible extension to regex
    00507
    00508   int line_counter, length;
    00509   int pos = -1;
    00510
    00511   QString string;
    00512   QString stringnew;
    00513   QString replacement;
    00514
    00515   replacement = replace_dialog->getReplaceText();
    00516   line_counter = line;
    00517   replace_all_col = col;
    00518
    00519   if(forward){
    00520
    00521     int num_lines = numLines();
    00522
    00523     while (line_counter < num_lines){
    00524
    00525       string = textLine(line_counter);
    00526
    00527       if (replace_all){
    00528         pos = string.find(s_pattern, replace_all_col, case_sensitive);
    00529       }
    00530       else{
    00531         pos = string.find(s_pattern, line_counter == line ? col : 0, case_sensitive);
    00532       }
    00533
    00534       if (pos == -1 ){
    00535         line_counter++;
    00536         replace_all_col = 0;
    00537         replace_all_line = line_counter;
    00538       }
    00539
    00540       if( pos != -1){
    00541
    00542         length = s_pattern.length();
    00543
    00544         if(replace_all){ // automatic
    00545
    00546           stringnew = string.copy();
    00547           stringnew.replace(pos,length,replacement);
    00548
    00549           removeLine(line_counter);
    00550           insertLine(stringnew,line_counter);
    00551
    00552           replace_all_col = pos + replacement.length();
    00553           replace_all_line = line_counter;
    00554
    00555           setModified(true);
    00556         }
    00557         else{ // interactive
    00558
    00559           setCursorPosition( line_counter , pos, FALSE );
    00560
    00561           for(int l = 0 ; l < length; l++){
    00562             cursorRight(TRUE);
    00563           }
    00564
    00565           setCursorPosition( line_counter , pos + length, TRUE );
    00566           pattern = s_pattern;
    00567           last_replace = FORWARD;
    00568           can_replace = TRUE;
    00569
    00570           return 1;
    00571
    00572         }
    00573
    00574       }
    00575     }
    00576   }
    00577   else{ // searching backwards
    00578
    00579     while(line_counter >= 0){
    00580
    00581       string = textLine(line_counter);
    00582
    00583       int line_length = string.length();
    00584
    00585       if( replace_all ){
    00586         if (replace_all_col < 0)
    00587           pos = -1;
    00588         else
    00589           pos = string.findRev(s_pattern, replace_all_col , case_sensitive);
    00590       }
    00591       else{
    00592         if ((line == line_counter) && (col < 0))
    00593           pos = -1;
    00594         else
    00595           pos = string.findRev(s_pattern,
    00596                            line == line_counter ? col : line_length , case_sensitive);
    00597       }
    00598
    00599       if (pos == -1 ){
    00600         line_counter--;
    00601
    00602         replace_all_col = 0;
    00603         if(line_counter >= 0){
    00604           string = textLine(line_counter);
    00605           replace_all_col = string.length();
    00606
    00607         }
    00608         replace_all_line = line_counter;
    00609       }
    00610
    00611
    00612       if (pos != -1){
    00613         length = s_pattern.length();
    00614
    00615         if(replace_all){ // automatic
    00616
    00617           stringnew = string.copy();
    00618           stringnew.replace(pos,length,replacement);
    00619
    00620           removeLine(line_counter);
    00621           insertLine(stringnew,line_counter);
    00622
    00623           replace_all_col = pos-length;
    00624           replace_all_line = line_counter;
    00625           if (replace_all_col < 0)
    00626           {
    00627              line_counter--;
    00628
    00629              if(line_counter >= 0){
    00630                 string = textLine(line_counter);
    00631                 replace_all_col = string.length();
    00632              }
    00633              replace_all_line = line_counter;
    00634           }
    00635
    00636           setModified(true);
    00637         }
    00638         else{ // interactive
    00639
    00640           //      printf("line_counter %d pos %d col %d\n",line_counter, pos,col);
    00641           if( ! (line == line_counter && pos > col ) ){
    00642
    00643             setCursorPosition(line_counter, pos + length ,FALSE );
    00644
    00645             for(int l = 0 ; l < length; l++){
    00646               cursorLeft(TRUE);
    00647             }
    00648
    00649             setCursorPosition(line_counter, pos ,TRUE );
    00650             pattern = s_pattern;
    00651
    00652             last_replace = BACKWARD;
    00653             can_replace = TRUE;
    00654
    00655             return 1;
    00656           }
    00657         }
    00658       }
    00659     }
    00660   }
    00661
    00662   return 0;
    00663
    00664 }
    00665
    00666
    00667
    00668
    00669
    00671 //
    00672 // Find Dialog
    00673 //
    00674
    00675 class KEdFind::KEdFindPrivate
    00676 {
    00677 public:
    00678     KEdFindPrivate( QWidget *parent ) {
    00679         combo = new KHistoryCombo( parent, "value" );
    00680         combo->setMaxCount( 20 ); // just some default
    00681     }
    00682     ~KEdFindPrivate() {
    00683         delete combo;
    00684     }
    00685
    00686     KHistoryCombo *combo;
    00687 };
    00688
    00689
    00690 KEdFind::KEdFind( QWidget *parent, const char *name, bool modal )
    00691   :KDialogBase( parent, name, modal, i18n("Find"),
    00692                 modal ? User1|Cancel : User1|Close, User1, false, i18n("&Find") )
    00693 {
    00694   setWFlags( WType_TopLevel );
    00695
    00696   QWidget *page = new QWidget( this );
    00697   setMainWidget(page);
    00698   QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() );
    00699
    00700   d = new KEdFindPrivate( page );
    00701
    00702   QString text = i18n("Find:");
    00703   QLabel *label = new QLabel( text, page , "find" );
    00704   topLayout->addWidget( label );
    00705
    00706   d->combo->setMinimumWidth(fontMetrics().maxWidth()*20);
    00707   d->combo->setFocus();
    00708
    00709   connect(d->combo, SIGNAL(textChanged ( const QString & )),
    00710           this,SLOT(textSearchChanged ( const QString & )));
    00711
    00712   topLayout->addWidget(d->combo);
    00713
    00714   group = new QVButtonGroup( i18n("Options"), page );
    00715   topLayout->addWidget( group );
    00716
    00717   QHBox* row1 = new QHBox( group );
    00718
    00719   text = i18n("Case &sensitive");
    00720   sensitive = new QCheckBox( text, row1, "case");
    00721   text = i18n("Find &backwards");
    00722   direction = new QCheckBox( text, row1, "direction" );
    00723
    00724
    00725   enableButton( KDialogBase::User1, !d->combo->currentText().isEmpty() );
    00726
    00727   if ( !modal )
    00728     connect( this, SIGNAL( closeClicked() ), this, SLOT( slotCancel() ) );
    00729 }
    00730
    00731 KEdFind::~KEdFind()
    00732 {
    00733     delete d;
    00734 }
    00735
    00736 void KEdFind::textSearchChanged ( const QString &text )
    00737 {
    00738    enableButton( KDialogBase::User1, !text.isEmpty() );
    00739 }
    00740
    00741 void KEdFind::slotCancel( void )
    00742 {
    00743   emit done();
    00744   KDialogBase::slotCancel();
    00745 }
    00746
    00747 void KEdFind::slotUser1( void )
    00748 {
    00749   if( !d->combo->currentText().isEmpty() )
    00750   {
    00751     d->combo->addToHistory( d->combo->currentText() );
    00752     emit search();
    00753   }
    00754 }
    00755
    00756
    00757 QString KEdFind::getText() const
    00758 {
    00759     return d->combo->currentText();
    00760 }
    00761
    00762
    00763 void KEdFind::setText(QString string)
    00764 {
    00765   d->combo->setEditText(string);
    00766   d->combo->lineEdit()->selectAll();
    00767 }
    00768
    00769 void KEdFind::setCaseSensitive( bool b )
    00770 {
    00771   sensitive->setChecked( b );
    00772 }
    00773
    00774 bool KEdFind::case_sensitive() const
    00775 {
    00776   return sensitive->isChecked();
    00777 }
    00778
    00779 void KEdFind::setDirection( bool b )
    00780 {
    00781   direction->setChecked( b );
    00782 }
    00783
    00784 bool KEdFind::get_direction() const
    00785 {
    00786   return direction->isChecked();
    00787 }
    00788
    00789 KHistoryCombo * KEdFind::searchCombo() const
    00790 {
    00791     return d->combo;
    00792 }
    00793
    00794
    00795
    00797 //
    00798 //  Replace Dialog
    00799 //
    00800
    00801 class KEdReplace::KEdReplacePrivate
    00802 {
    00803 public:
    00804     KEdReplacePrivate( QWidget *parent ) {
    00805         searchCombo = new KHistoryCombo( parent, "value" );
    00806         replaceCombo = new KHistoryCombo( parent, "replace_value" );
    00807
    00808         searchCombo->setMaxCount( 20 ); // just some defaults
    00809         replaceCombo->setMaxCount( 20 );
    00810     }
    00811     ~KEdReplacePrivate() {
    00812         delete searchCombo;
    00813         delete replaceCombo;
    00814     }
    00815
    00816     KHistoryCombo *searchCombo, *replaceCombo;
    00817 };
    00818
    00819 KEdReplace::KEdReplace( QWidget *parent, const char *name, bool modal )
    00820   :KDialogBase( parent, name, modal, i18n("Replace"),
    00821                 modal ? User3|User2|User1|Cancel : User3|User2|User1|Close,
    00822                 User3, false,
    00823                 i18n("Replace &All"), i18n("&Replace"), i18n("&Find") )
    00824 {
    00825   setWFlags( WType_TopLevel );
    00826
    00827   setButtonBoxOrientation( Vertical );
    00828
    00829   QFrame *page = makeMainWidget();
    00830   QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() );
    00831
    00832   d = new KEdReplacePrivate( page );
    00833
    00834   QString text = i18n("Find:");
    00835   QLabel *label = new QLabel( text, page, "find" );
    00836   topLayout->addWidget( label );
    00837
    00838   d->searchCombo->setMinimumWidth(fontMetrics().maxWidth()*20);
    00839   d->searchCombo->setFocus();
    00840   topLayout->addWidget(d->searchCombo);
    00841
    00842   text = i18n("Replace with:");
    00843   label = new QLabel( text, page, "replace" );
    00844   topLayout->addWidget( label );
    00845
    00846   d->replaceCombo->setMinimumWidth(fontMetrics().maxWidth()*20);
    00847   topLayout->addWidget(d->replaceCombo);
    00848
    00849   connect(d->searchCombo, SIGNAL(textChanged ( const QString & )),
    00850           this,SLOT(textSearchChanged ( const QString & )));
    00851
    00852   QButtonGroup *group = new QButtonGroup( i18n("Options"), page );
    00853   topLayout->addWidget( group );
    00854
    00855   QGridLayout *gbox = new QGridLayout( group, 3, 2, spacingHint() );
    00856   gbox->addRowSpacing( 0, fontMetrics().lineSpacing() );
    00857
    00858   text = i18n("Case &sensitive");
    00859   sensitive = new QCheckBox( text, group, "case");
    00860   text = i18n("Find &backwards");
    00861   direction = new QCheckBox( text, group, "direction" );
    00862   gbox->addWidget( sensitive, 1, 0 );
    00863   gbox->addWidget( direction, 1, 1 );
    00864   gbox->setRowStretch( 2, 10 );
    00865 }
    00866
    00867
    00868 KEdReplace::~KEdReplace()
    00869 {
    00870     delete d;
    00871 }
    00872
    00873 void KEdReplace::textSearchChanged ( const QString &text )
    00874 {
    00875     bool state=text.isEmpty();
    00876     enableButton( KDialogBase::User1, !state );
    00877     enableButton( KDialogBase::User2, !state );
    00878     enableButton( KDialogBase::User3, !state );
    00879 }
    00880
    00881 void KEdReplace::slotCancel( void )
    00882 {
    00883   emit done();
    00884   d->searchCombo->clearEdit();
    00885   d->replaceCombo->clearEdit();
    00886   KDialogBase::slotCancel();
    00887 }
    00888
    00889 void KEdReplace::slotClose( void )
    00890 {
    00891   slotCancel();
    00892 }
    00893
    00894 void KEdReplace::slotUser1( void )
    00895 {
    00896     if( !d->searchCombo->currentText().isEmpty() )
    00897     {
    00898         d->replaceCombo->addToHistory( d->replaceCombo->currentText() );
    00899         emit replaceAll();
    00900     }
    00901 }
    00902
    00903
    00904 void KEdReplace::slotUser2( void )
    00905 {
    00906     if( !d->searchCombo->currentText().isEmpty() )
    00907     {
    00908         d->replaceCombo->addToHistory( d->replaceCombo->currentText() );
    00909         emit replace();
    00910     }
    00911 }
    00912
    00913 void KEdReplace::slotUser3( void )
    00914 {
    00915   if( !d->searchCombo->currentText().isEmpty() )
    00916   {
    00917     d->searchCombo->addToHistory( d->searchCombo->currentText() );
    00918     emit find();
    00919   }
    00920 }
    00921
    00922
    00923 QString KEdReplace::getText()
    00924 {
    00925     return d->searchCombo->currentText();
    00926 }
    00927
    00928
    00929 QString KEdReplace::getReplaceText()
    00930 {
    00931     return d->replaceCombo->currentText();
    00932 }
    00933
    00934
    00935 void KEdReplace::setText(QString string)
    00936 {
    00937   d->searchCombo->setEditText(string);
    00938   d->searchCombo->lineEdit()->selectAll();
    00939 }
    00940
    00941
    00942 bool KEdReplace::case_sensitive()
    00943 {
    00944   return sensitive->isChecked();
    00945 }
    00946
    00947
    00948 bool KEdReplace::get_direction()
    00949 {
    00950   return direction->isChecked();
    00951 }
    00952
    00953 KHistoryCombo * KEdReplace::searchCombo() const
    00954 {
    00955     return d->searchCombo;
    00956 }
    00957
    00958 KHistoryCombo * KEdReplace::replaceCombo() const
    00959 {
    00960     return d->replaceCombo;
    00961 }
    00962
    00963
    00964 KEdGotoLine::KEdGotoLine( QWidget *parent, const char *name, bool modal )
    00965   :KDialogBase( parent, name, modal, i18n("Goto Line"), modal ? Ok|Cancel : Ok|Close, Ok, false )
    00966 {
    00967   QWidget *page = new QWidget( this );
    00968   setMainWidget(page);
    00969   QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() );
    00970
    00971   lineNum = new KIntNumInput( 1, page);
    00972   lineNum->setRange(1, 1000000, 1, false);
    00973   lineNum->setLabel(i18n("Goto line:"), AlignVCenter | AlignLeft);
    00974 //  lineNum->setMinimumWidth(fontMetrics().maxWidth()*20);
    00975   topLayout->addWidget( lineNum );
    00976
    00977   topLayout->addStretch(10);
    00978   lineNum->setFocus();
    00979 }
    00980
    00981
    00982 void KEdGotoLine::selected(int)
    00983 {
    00984   accept();
    00985 }
    00986
    00987
    00988 int KEdGotoLine::getLineNumber()
    00989 {
    00990   return lineNum->value();
    00991 }
    00992
    00993
    00995 //
    00996 // Spell Checking
    00997 //
    00998
    00999 void KEdit::spellcheck_start()
    01000 {
    01001    saved_readonlystate = isReadOnly();
    01002    setReadOnly(true);
    01003 }
    01004
    01005 void KEdit::misspelling (const QString &word, const QStringList &, unsigned int pos)
    01006 {
    01007
    01008   unsigned int l = 0;
    01009   unsigned int cnt = 0;
    01010   posToRowCol (pos, l, cnt);
    01011   setSelection(l, cnt, l, cnt+word.length());
    01012
    01013   /*
    01014   if (cursorPoint().y()>height()/2)
    01015     kspell->moveDlg (10, height()/2-kspell->heightDlg()-15);
    01016   else
    01017     kspell->moveDlg (10, height()/2 + 15);
    01018   */
    01019
    01020 }
    01021
    01022 //need to use pos for insert, not cur, so forget cur altogether
    01023 void KEdit::corrected (const QString &originalword, const QString &newword, unsigned int pos)
    01024 {
    01025   //we'll reselect the original word in case the user has played with
    01026   //the selection in eframe or the word was auto-replaced
    01027
    01028   unsigned int l = 0;
    01029   unsigned int cnt = 0;
    01030
    01031   if( newword != originalword )
    01032   {
    01033     posToRowCol (pos, l, cnt);
    01034     setSelection(l, cnt, l, cnt+originalword.length());
    01035
    01036     setReadOnly ( false );
    01037     removeSelectedText();
    01038     insert(newword);
    01039     setReadOnly ( true );
    01040   }
    01041   else
    01042   {
    01043     deselect();
    01044   }
    01045 }
    01046
    01047 void KEdit::posToRowCol(unsigned int pos, unsigned int &line, unsigned int &col)
    01048 {
    01049   for (line = 0; line < static_cast<uint>(numLines()) && col <= pos; line++)
    01050   {
    01051     col += lineLength(line)+1;
    01052   }
    01053   line--;
    01054   col = pos - col + lineLength(line) + 1;
    01055 }
    01056
    01057 void KEdit::spellcheck_stop()
    01058 {
    01059   deselect();
    01060
    01061   setReadOnly ( saved_readonlystate);
    01062 }
    01063
    01064
    01065

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:56:45 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001