• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kdeui

keditcl2.cpp

Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include <limits.h> // INT_MAX
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 // Find Methods
00049 //
00050 
00051 void KEdit::search(){
00052 
00053   if( replace_dialog && replace_dialog->isVisible() )
00054   {
00055     replace_dialog->hide();
00056   }
00057 
00058   if( !srchdialog )
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   // If we already searched / replaced something before make sure it shows
00066   // up in the find dialog line-edit.
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   // srchdialog->get_direction() is true if searching backward
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){
00101     if(!srchdialog->get_direction()){ // forward search
00102 
00103       int query = KMessageBox::questionYesNo(
00104             srchdialog,
00105                         i18n("End of document reached.\n"\
00106                              "Continue from the beginning?"),
00107                         i18n("Find"),KStdGuiItem::cont(),i18n("Stop"));
00108       if (query == KMessageBox::Yes){
00109     line = 0;
00110     col = 0;
00111     goto again;
00112       }
00113     }
00114     else{ //backward search
00115 
00116       int query = KMessageBox::questionYesNo(
00117             srchdialog,
00118                         i18n("Beginning of document reached.\n"\
00119                              "Continue from the end?"),
00120                         i18n("Find"),KStdGuiItem::cont(),i18n("Stop"));
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 /* antlarr: KDE 4: make it const QString & */
00148 int KEdit::doSearch(QString s_pattern, bool case_sensitive,
00149             bool wildcard, bool forward, int line, int col){
00150 
00151   (void) wildcard; // reserved for possible extension to regex
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{ // searching backwards
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 // Replace Methods
00244 //
00245 
00246 
00247 void KEdit::replace()
00248 {
00249   if( srchdialog && srchdialog->isVisible() )
00250   {
00251     srchdialog->hide();
00252   }
00253 
00254   if( !replace_dialog )
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     // Backward
00301     setCursorPosition(line,col+length);
00302     for( int k = 0; k < length; k++){
00303       cursorLeft(true);
00304     }
00305   }
00306   else
00307   {
00308     // Forward
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   // replace_dialog->get_direction() is true if searching backward
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()){ // forward search
00372 
00373     int query = KMessageBox::questionYesNo(
00374             srchdialog,
00375                         i18n("End of document reached.\n"\
00376                              "Continue from the beginning?"),
00377                         i18n("Find"),KStdGuiItem::cont(),i18n("Stop"));
00378     if (query == KMessageBox::Yes){
00379       replace_all_line = 0;
00380       replace_all_col = 0;
00381       goto again;
00382     }
00383   }
00384   else{ //backward search
00385 
00386     int query = KMessageBox::questionYesNo(
00387             srchdialog,
00388                         i18n("Beginning of document reached.\n"\
00389                              "Continue from the end?"),
00390                         i18n("Find"),KStdGuiItem::cont(),i18n("Stop"));
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   // replace_dialog->get_direction() is true if searching backward
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){
00450     if(!replace_dialog->get_direction()){ // forward search
00451 
00452      int query = KMessageBox::questionYesNo(
00453             replace_dialog,
00454                         i18n("End of document reached.\n"\
00455                              "Continue from the beginning?"),
00456                         i18n("Replace"),KStdGuiItem::cont(),i18n("Stop"));
00457      if (query == KMessageBox::Yes){
00458     line = 0;
00459     col = 0;
00460     goto again;
00461       }
00462     }
00463     else{ //backward search
00464 
00465      int query = KMessageBox::questionYesNo(
00466             replace_dialog,
00467                         i18n("Beginning of document reached.\n"\
00468                              "Continue from the end?"),
00469                         i18n("Replace"),KStdGuiItem::cont(),i18n("Stop"));
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   //  replace_dialog->clearFocus();
00494 
00495   setFocus();
00496 
00497   last_replace = NONE;
00498   can_replace  = false;
00499 
00500 }
00501 
00502 
00503 
00504 /* antlarr: KDE 4: make it const QString & */
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; // reserved for possible extension to regex
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){ // automatic
00548 
00549           stringnew = string.copy();
00550           do 
00551           {  
00552         stringnew.replace(pos,length,replacement);
00553 
00554         replace_all_col = pos + replacement.length();
00555         replace_all_line = line_counter;
00556 
00557             pos = stringnew.find(s_pattern, replace_all_col, case_sensitive);
00558           }
00559           while( pos != -1); 
00560 
00561       removeLine(line_counter);
00562       insertLine(stringnew,line_counter);
00563 
00564       setModified(true);
00565     }
00566     else{ // interactive
00567 
00568       setCursorPosition( line_counter , pos, false );
00569 
00570       for(int l = 0 ; l < length; l++){
00571         cursorRight(true);
00572       }
00573 
00574       setCursorPosition( line_counter , pos + length, true );
00575       pattern = s_pattern;
00576       last_replace = FORWARD;
00577       can_replace = true;
00578 
00579       return 1;
00580 
00581     }
00582 
00583       }
00584     }
00585   }
00586   else{ // searching backwards
00587 
00588     while(line_counter >= 0){
00589 
00590       string = textLine(line_counter);
00591 
00592       int line_length = string.length();
00593 
00594       if( replace_all ){
00595         if (replace_all_col < 0)
00596           pos = -1;
00597         else
00598           pos = string.findRev(s_pattern, replace_all_col , case_sensitive);
00599       }
00600       else{
00601         if ((line == line_counter) && (col < 0))
00602           pos = -1;
00603         else
00604           pos = string.findRev(s_pattern,
00605                line == line_counter ? col : line_length , case_sensitive);
00606       }
00607 
00608       if (pos == -1 ){
00609     line_counter--;
00610 
00611         replace_all_col = 0;
00612     if(line_counter >= 0){
00613       string = textLine(line_counter);
00614       replace_all_col = string.length();
00615 
00616     }
00617     replace_all_line = line_counter;
00618       }
00619 
00620 
00621       if (pos != -1){
00622     length = s_pattern.length();
00623 
00624     if(replace_all){ // automatic
00625 
00626       stringnew = string.copy();
00627       stringnew.replace(pos,length,replacement);
00628 
00629       removeLine(line_counter);
00630       insertLine(stringnew,line_counter);
00631 
00632       replace_all_col = pos-length;
00633       replace_all_line = line_counter;
00634       if (replace_all_col < 0)
00635       {
00636              line_counter--;
00637 
00638              if(line_counter >= 0){
00639                 string = textLine(line_counter);
00640                 replace_all_col = string.length();
00641              }
00642              replace_all_line = line_counter;
00643       }
00644 
00645       setModified(true);
00646     }
00647     else{ // interactive
00648 
00649       //      printf("line_counter %d pos %d col %d\n",line_counter, pos,col);
00650       if( ! (line == line_counter && pos > col ) ){
00651 
00652         setCursorPosition(line_counter, pos + length ,false );
00653 
00654         for(int l = 0 ; l < length; l++){
00655           cursorLeft(true);
00656         }
00657 
00658         setCursorPosition(line_counter, pos ,true );
00659         pattern = s_pattern;
00660 
00661         last_replace = BACKWARD;
00662         can_replace = true;
00663 
00664         return 1;
00665       }
00666     }
00667       }
00668     }
00669   }
00670 
00671   return 0;
00672 
00673 }
00674 
00675 
00676 
00677 
00678 
00680 //
00681 // Find Dialog
00682 //
00683 
00684 class KEdFind::KEdFindPrivate
00685 {
00686 public:
00687     KEdFindPrivate( QWidget *parent ) {
00688     combo = new KHistoryCombo( parent, "value" );
00689     combo->setMaxCount( 20 ); // just some default
00690     }
00691     ~KEdFindPrivate() {
00692     delete combo;
00693     }
00694 
00695     KHistoryCombo *combo;
00696 };
00697 
00698 
00699 KEdFind::KEdFind( QWidget *parent, const char *name, bool modal )
00700   :KDialogBase( parent, name, modal, i18n("Find"),
00701         modal ? User1|Cancel : User1|Close, User1, false, KGuiItem( i18n("&Find"), "find") )
00702 {
00703   setWFlags( WType_TopLevel );
00704 
00705   QWidget *page = new QWidget( this );
00706   setMainWidget(page);
00707   QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() );
00708 
00709   d = new KEdFindPrivate( page );
00710 
00711   QString text = i18n("Find:");
00712   QLabel *label = new QLabel( text, page , "find" );
00713   topLayout->addWidget( label );
00714 
00715   d->combo->setMinimumWidth(fontMetrics().maxWidth()*20);
00716   d->combo->setFocus();
00717 
00718   connect(d->combo, SIGNAL(textChanged ( const QString & )),
00719           this,SLOT(textSearchChanged ( const QString & )));
00720 
00721   topLayout->addWidget(d->combo);
00722 
00723   group = new QVButtonGroup( i18n("Options"), page );
00724   topLayout->addWidget( group );
00725 
00726   QHBox* row1 = new QHBox( group );
00727 
00728   text = i18n("Case &sensitive");
00729   sensitive = new QCheckBox( text, row1, "case");
00730   text = i18n("Find &backwards");
00731   direction = new QCheckBox( text, row1, "direction" );
00732 
00733 
00734   enableButton( KDialogBase::User1, !d->combo->currentText().isEmpty() );
00735 
00736   if ( !modal )
00737     connect( this, SIGNAL( closeClicked() ), this, SLOT( slotCancel() ) );
00738 }
00739 
00740 KEdFind::~KEdFind()
00741 {
00742     delete d;
00743 }
00744 
00745 void KEdFind::textSearchChanged ( const QString &text )
00746 {
00747    enableButton( KDialogBase::User1, !text.isEmpty() );
00748 }
00749 
00750 void KEdFind::slotCancel( void )
00751 {
00752   emit done();
00753   KDialogBase::slotCancel();
00754 }
00755 
00756 void KEdFind::slotUser1( void )
00757 {
00758   if( !d->combo->currentText().isEmpty() )
00759   {
00760     d->combo->addToHistory( d->combo->currentText() );
00761     emit search();
00762   }
00763 }
00764 
00765 
00766 QString KEdFind::getText() const
00767 {
00768     return d->combo->currentText();
00769 }
00770 
00771 
00772 /* antlarr: KDE 4: make it const QString & */
00773 void KEdFind::setText(QString string)
00774 {
00775   d->combo->setEditText(string);
00776   d->combo->lineEdit()->selectAll();
00777 }
00778 
00779 void KEdFind::setCaseSensitive( bool b )
00780 {
00781   sensitive->setChecked( b );
00782 }
00783 
00784 bool KEdFind::case_sensitive() const
00785 {
00786   return sensitive->isChecked();
00787 }
00788 
00789 void KEdFind::setDirection( bool b )
00790 {
00791   direction->setChecked( b );
00792 }
00793 
00794 bool KEdFind::get_direction() const
00795 {
00796   return direction->isChecked();
00797 }
00798 
00799 KHistoryCombo * KEdFind::searchCombo() const
00800 {
00801     return d->combo;
00802 }
00803 
00804 
00805 
00807 //
00808 //  Replace Dialog
00809 //
00810 
00811 class KEdReplace::KEdReplacePrivate
00812 {
00813 public:
00814     KEdReplacePrivate( QWidget *parent ) {
00815     searchCombo = new KHistoryCombo( parent, "value" );
00816     replaceCombo = new KHistoryCombo( parent, "replace_value" );
00817 
00818     searchCombo->setMaxCount( 20 ); // just some defaults
00819     replaceCombo->setMaxCount( 20 );
00820     }
00821     ~KEdReplacePrivate() {
00822     delete searchCombo;
00823     delete replaceCombo;
00824     }
00825 
00826     KHistoryCombo *searchCombo, *replaceCombo;
00827 };
00828 
00829 KEdReplace::KEdReplace( QWidget *parent, const char *name, bool modal )
00830   :KDialogBase( parent, name, modal, i18n("Replace"),
00831         modal ? User3|User2|User1|Cancel : User3|User2|User1|Close,
00832                 User3, false,
00833         i18n("Replace &All"), i18n("&Replace"), KGuiItem( i18n("&Find"), "find") )
00834 {
00835   setWFlags( WType_TopLevel );
00836 
00837   setButtonBoxOrientation( Vertical );
00838 
00839   QFrame *page = makeMainWidget();
00840   QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() );
00841 
00842   d = new KEdReplacePrivate( page );
00843 
00844   QString text = i18n("Find:");
00845   QLabel *label = new QLabel( text, page, "find" );
00846   topLayout->addWidget( label );
00847 
00848   d->searchCombo->setMinimumWidth(fontMetrics().maxWidth()*20);
00849   d->searchCombo->setFocus();
00850   topLayout->addWidget(d->searchCombo);
00851 
00852   text = i18n("Replace with:");
00853   label = new QLabel( text, page, "replace" );
00854   topLayout->addWidget( label );
00855 
00856   d->replaceCombo->setMinimumWidth(fontMetrics().maxWidth()*20);
00857   topLayout->addWidget(d->replaceCombo);
00858 
00859   connect(d->searchCombo, SIGNAL(textChanged ( const QString & )),
00860           this,SLOT(textSearchChanged ( const QString & )));
00861 
00862   QButtonGroup *group = new QButtonGroup( i18n("Options"), page );
00863   topLayout->addWidget( group );
00864 
00865   QGridLayout *gbox = new QGridLayout( group, 3, 2, spacingHint() );
00866   gbox->addRowSpacing( 0, fontMetrics().lineSpacing() );
00867 
00868   text = i18n("Case &sensitive");
00869   sensitive = new QCheckBox( text, group, "case");
00870   text = i18n("Find &backwards");
00871   direction = new QCheckBox( text, group, "direction" );
00872   gbox->addWidget( sensitive, 1, 0 );
00873   gbox->addWidget( direction, 1, 1 );
00874   gbox->setRowStretch( 2, 10 );
00875 }
00876 
00877 
00878 KEdReplace::~KEdReplace()
00879 {
00880     delete d;
00881 }
00882 
00883 void KEdReplace::textSearchChanged ( const QString &text )
00884 {
00885     bool state=text.isEmpty();
00886     enableButton( KDialogBase::User1, !state );
00887     enableButton( KDialogBase::User2, !state );
00888     enableButton( KDialogBase::User3, !state );
00889 }
00890 
00891 void KEdReplace::slotCancel( void )
00892 {
00893   emit done();
00894   d->searchCombo->clearEdit();
00895   d->replaceCombo->clearEdit();
00896   KDialogBase::slotCancel();
00897 }
00898 
00899 void KEdReplace::slotClose( void )
00900 {
00901   slotCancel();
00902 }
00903 
00904 void KEdReplace::slotUser1( void )
00905 {
00906     if( !d->searchCombo->currentText().isEmpty() )
00907     {
00908         d->replaceCombo->addToHistory( d->replaceCombo->currentText() );
00909         emit replaceAll();
00910     }
00911 }
00912 
00913 
00914 void KEdReplace::slotUser2( void )
00915 {
00916     if( !d->searchCombo->currentText().isEmpty() )
00917     {
00918         d->replaceCombo->addToHistory( d->replaceCombo->currentText() );
00919         emit replace();
00920     }
00921 }
00922 
00923 void KEdReplace::slotUser3( void )
00924 {
00925   if( !d->searchCombo->currentText().isEmpty() )
00926   {
00927     d->searchCombo->addToHistory( d->searchCombo->currentText() );
00928     emit find();
00929   }
00930 }
00931 
00932 
00933 QString KEdReplace::getText()
00934 {
00935     return d->searchCombo->currentText();
00936 }
00937 
00938 
00939 QString KEdReplace::getReplaceText()
00940 {
00941     return d->replaceCombo->currentText();
00942 }
00943 
00944 
00945 /* antlarr: KDE 4: make it const QString & */
00946 void KEdReplace::setText(QString string)
00947 {
00948   d->searchCombo->setEditText(string);
00949   d->searchCombo->lineEdit()->selectAll();
00950 }
00951 
00952 
00953 bool KEdReplace::case_sensitive()
00954 {
00955   return sensitive->isChecked();
00956 }
00957 
00958 
00959 bool KEdReplace::get_direction()
00960 {
00961   return direction->isChecked();
00962 }
00963 
00964 KHistoryCombo * KEdReplace::searchCombo() const
00965 {
00966     return d->searchCombo;
00967 }
00968 
00969 KHistoryCombo * KEdReplace::replaceCombo() const
00970 {
00971     return d->replaceCombo;
00972 }
00973 
00974 
00975 KEdGotoLine::KEdGotoLine( QWidget *parent, const char *name, bool modal )
00976   :KDialogBase( parent, name, modal, i18n("Go to Line"), modal ? Ok|Cancel : Ok|Close, Ok, false )
00977 {
00978   QWidget *page = new QWidget( this );
00979   setMainWidget(page);
00980   QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() );
00981 
00982   lineNum = new KIntNumInput( 1, page);
00983   lineNum->setRange(1, 1000000, 1, false);
00984   lineNum->setLabel(i18n("Go to line:"), AlignVCenter | AlignLeft);
00985 //  lineNum->setMinimumWidth(fontMetrics().maxWidth()*20);
00986   topLayout->addWidget( lineNum );
00987 
00988   topLayout->addStretch(10);
00989   lineNum->setFocus();
00990 }
00991 
00992 
00993 void KEdGotoLine::selected(int)
00994 {
00995   accept();
00996 }
00997 
00998 
00999 int KEdGotoLine::getLineNumber()
01000 {
01001   return lineNum->value();
01002 }
01003 
01004 
01006 //
01007 // Spell Checking
01008 //
01009 
01010 void KEdit::spellcheck_start()
01011 {
01012    saved_readonlystate = isReadOnly();
01013    setReadOnly(true);
01014 }
01015 
01016 void KEdit::misspelling (const QString &word, const QStringList &, unsigned int pos)
01017 {
01018 
01019   unsigned int l = 0;
01020   unsigned int cnt = 0;
01021   posToRowCol (pos, l, cnt);
01022   setSelection(l, cnt, l, cnt+word.length());
01023 
01024   /*
01025   if (cursorPoint().y()>height()/2)
01026     kspell->moveDlg (10, height()/2-kspell->heightDlg()-15);
01027   else
01028     kspell->moveDlg (10, height()/2 + 15);
01029   */
01030 
01031 }
01032 
01033 //need to use pos for insert, not cur, so forget cur altogether
01034 void KEdit::corrected (const QString &originalword, const QString &newword, unsigned int pos)
01035 {
01036   //we'll reselect the original word in case the user has played with
01037   //the selection in eframe or the word was auto-replaced
01038 
01039   unsigned int l = 0;
01040   unsigned int cnt = 0;
01041 
01042   if( newword != originalword )
01043   {
01044     posToRowCol (pos, l, cnt);
01045     setSelection(l, cnt, l, cnt+originalword.length());
01046 
01047     setReadOnly ( false );
01048     removeSelectedText();
01049     insert(newword);
01050     setReadOnly ( true );
01051   }
01052   else
01053   {
01054     deselect();
01055   }
01056 }
01057 
01058 void KEdit::posToRowCol(unsigned int pos, unsigned int &line, unsigned int &col)
01059 {
01060   for (line = 0; line < static_cast<uint>(numLines()) && col <= pos; line++)
01061   {
01062     col += lineLength(line)+1;
01063   }
01064   line--;
01065   col = pos - col + lineLength(line) + 1;
01066 }
01067 
01068 void KEdit::spellcheck_stop()
01069 {
01070   deselect();
01071 
01072   setReadOnly ( saved_readonlystate);
01073 }
01074 
01075 QString KEdit::selectWordUnderCursor( )
01076 {
01077     int parag;
01078     int pos;
01079 
01080     getCursorPosition(&parag, &pos);
01081 
01082     QString txt = text(parag);
01083 
01084     // Find start
01085     int start = pos;
01086     while( start > 0 )
01087     {
01088        const QChar &ch = txt[start-1];
01089        if (ch.isSpace() || ch.isPunct())
01090           break;
01091        start--;
01092     }
01093 
01094     // Find end
01095     int end = pos;
01096     int len = txt.length();
01097     while( end < len )
01098     {
01099        const QChar &ch = txt[end];
01100        if (ch.isSpace() || ch.isPunct())
01101           break;
01102        end++;
01103     }
01104     setSelection(parag, start, parag, end);
01105     return txt.mid(start, end-start);
01106 }
01107 
01108 QPopupMenu *KEdit::createPopupMenu( const QPoint& pos )
01109 {
01110     enum { IdUndo, IdRedo, IdSep1, IdCut, IdCopy, IdPaste, IdClear, IdSep2, IdSelectAll };
01111 
01112     QPopupMenu *menu = QMultiLineEdit::createPopupMenu( pos );
01113     
01114     if ( isReadOnly() )
01115       menu->changeItem( menu->idAt(0), SmallIconSet("editcopy"), menu->text( menu->idAt(0) ) );
01116     else {
01117       int id = menu->idAt(0);
01118       menu->changeItem( id - IdUndo, SmallIconSet("undo"), menu->text( id - IdUndo) );
01119       menu->changeItem( id - IdRedo, SmallIconSet("redo"), menu->text( id - IdRedo) );
01120       menu->changeItem( id - IdCut, SmallIconSet("editcut"), menu->text( id - IdCut) );
01121       menu->changeItem( id - IdCopy, SmallIconSet("editcopy"), menu->text( id - IdCopy) );
01122       menu->changeItem( id - IdPaste, SmallIconSet("editpaste"), menu->text( id - IdPaste) );
01123       menu->changeItem( id - IdClear, SmallIconSet("editclear"), menu->text( id - IdClear) );
01124     }
01125 
01126     return menu;
01127 }

kdeui

Skip menu "kdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal