• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
keditcl2.cpp
1 /* This file is part of the KDE libraries
2 
3  Copyright (C) 1997 Bernd Johannes Wuebben <wuebben@math.cornell.edu>
4  Copyright (C) 2000 Waldo Bastian <bastian@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include <limits.h> // INT_MAX
23 
24 #include <tqframe.h>
25 #include <tqlabel.h>
26 #include <tqlineedit.h>
27 #include <tqvbuttongroup.h>
28 #include <tqcheckbox.h>
29 #include <tqlayout.h>
30 #include <tqpushbutton.h>
31 #include <tqhbox.h>
32 #include <tqpopupmenu.h>
33 
34 #include <tdeapplication.h>
35 #include <kcombobox.h>
36 #include <knuminput.h>
37 #include <tdemessagebox.h>
38 #include <knotifyclient.h>
39 #include <tdelocale.h>
40 #include <kdebug.h>
41 #include <kiconloader.h>
42 
43 #include "keditcl.h"
44 
45 
47 //
48 // Find Methods
49 //
50 
51 void KEdit::search(){
52 
53  if( replace_dialog && replace_dialog->isVisible() )
54  {
55  replace_dialog->hide();
56  }
57 
58  if( !srchdialog )
59  {
60  srchdialog = new KEdFind( this, "searchdialog", false);
61  connect(srchdialog,TQT_SIGNAL(search()),this,TQT_SLOT(search_slot()));
62  connect(srchdialog,TQT_SIGNAL(done()),this,TQT_SLOT(searchdone_slot()));
63  }
64 
65  // If we already searched / replaced something before make sure it shows
66  // up in the find dialog line-edit.
67 
68  TQString string;
69  string = srchdialog->getText();
70  srchdialog->setText(string.isEmpty() ? pattern : string);
71 
72  deselect();
73  last_search = NONE;
74 
75  srchdialog->show();
76  srchdialog->result();
77 }
78 
79 
80 void KEdit::search_slot(){
81 
82  int line, col;
83 
84  if (!srchdialog)
85  return;
86 
87  TQString to_find_string = srchdialog->getText();
88  getCursorPosition(&line,&col);
89 
90  // srchdialog->get_direction() is true if searching backward
91 
92  if (last_search != NONE && srchdialog->get_direction()){
93  col = col - pattern.length() - 1 ;
94  }
95 
96 again:
97  int result = doSearch(to_find_string, srchdialog->case_sensitive(),
98  false, (!srchdialog->get_direction()),line,col);
99 
100  if(!result){
101  if(!srchdialog->get_direction()){ // forward search
102 
103  int query = KMessageBox::questionYesNo(
104  srchdialog,
105  i18n("End of document reached.\n"\
106  "Continue from the beginning?"),
107  i18n("Find"),KStdGuiItem::cont(),i18n("Stop"));
108  if (query == KMessageBox::Yes){
109  line = 0;
110  col = 0;
111  goto again;
112  }
113  }
114  else{ //backward search
115 
116  int query = KMessageBox::questionYesNo(
117  srchdialog,
118  i18n("Beginning of document reached.\n"\
119  "Continue from the end?"),
120  i18n("Find"),KStdGuiItem::cont(),i18n("Stop"));
121  if (query == KMessageBox::Yes){
122  TQString string = textLine( numLines() - 1 );
123  line = numLines() - 1;
124  col = string.length();
125  last_search = BACKWARD;
126  goto again;
127  }
128  }
129  }
130  else{
131  emit CursorPositionChanged();
132  }
133 }
134 
135 
136 
137 void KEdit::searchdone_slot(){
138 
139  if (!srchdialog)
140  return;
141 
142  srchdialog->hide();
143  setFocus();
144  last_search = NONE;
145 }
146 
147 /* antlarr: KDE 4: make it const TQString & */
148 int KEdit::doSearch(TQString s_pattern, bool case_sensitive,
149  bool wildcard, bool forward, int line, int col){
150 
151  (void) wildcard; // reserved for possible extension to regex
152 
153 
154  int i, length;
155  int pos = -1;
156 
157  if(forward){
158 
159  TQString string;
160 
161  for(i = line; i < numLines(); i++) {
162 
163  string = textLine(i);
164 
165  pos = string.find(s_pattern, i == line ? col : 0, case_sensitive);
166 
167  if( pos != -1){
168 
169  length = s_pattern.length();
170 
171  setCursorPosition(i,pos,false);
172 
173  for(int l = 0 ; l < length; l++){
174  cursorRight(true);
175  }
176 
177  setCursorPosition( i , pos + length, true );
178  pattern = s_pattern;
179  last_search = FORWARD;
180 
181  return 1;
182  }
183  }
184  }
185  else{ // searching backwards
186 
187  TQString string;
188 
189  for(i = line; i >= 0; i--) {
190 
191  string = textLine(i);
192  int line_length = string.length();
193 
194  pos = string.findRev(s_pattern, line == i ? col : line_length , case_sensitive);
195 
196  if (pos != -1){
197 
198  length = s_pattern.length();
199 
200  if( ! (line == i && pos > col ) ){
201 
202  setCursorPosition(i ,pos ,false );
203 
204  for(int l = 0 ; l < length; l++){
205  cursorRight(true);
206  }
207 
208  setCursorPosition(i ,pos + length ,true );
209  pattern = s_pattern;
210  last_search = BACKWARD;
211  return 1;
212 
213  }
214  }
215 
216  }
217  }
218 
219  return 0;
220 
221 }
222 
223 
224 
225 bool KEdit::repeatSearch() {
226 
227  if(!srchdialog || pattern.isEmpty())
228  {
229  search();
230  return true;
231  }
232 
233  search_slot();
234 
235  setFocus();
236  return true;
237 
238 }
239 
240 
242 //
243 // Replace Methods
244 //
245 
246 
247 void KEdit::replace()
248 {
249  if( srchdialog && srchdialog->isVisible() )
250  {
251  srchdialog->hide();
252  }
253 
254  if( !replace_dialog )
255  {
256  replace_dialog = new KEdReplace( this, "replace_dialog", false );
257  connect(replace_dialog,TQT_SIGNAL(find()),this,TQT_SLOT(replace_search_slot()));
258  connect(replace_dialog,TQT_SIGNAL(replace()),this,TQT_SLOT(replace_slot()));
259  connect(replace_dialog,TQT_SIGNAL(replaceAll()),this,TQT_SLOT(replace_all_slot()));
260  connect(replace_dialog,TQT_SIGNAL(done()),this,TQT_SLOT(replacedone_slot()));
261  }
262 
263  TQString string = replace_dialog->getText();
264  replace_dialog->setText(string.isEmpty() ? pattern : string);
265 
266 
267  deselect();
268  last_replace = NONE;
269 
270  replace_dialog->show();
271  replace_dialog->result();
272 }
273 
274 
275 void KEdit::replace_slot(){
276 
277  if (!replace_dialog)
278  return;
279 
280  if(!can_replace){
281  KNotifyClient::beep();
282  return;
283  }
284 
285  int line,col, length;
286 
287  TQString string = replace_dialog->getReplaceText();
288  length = string.length();
289 
290  this->cut();
291 
292  getCursorPosition(&line,&col);
293 
294  insertAt(string,line,col);
295  setModified(true);
296  can_replace = false;
297 
298  if (replace_dialog->get_direction())
299  {
300  // Backward
301  setCursorPosition(line,col+length);
302  for( int k = 0; k < length; k++){
303  cursorLeft(true);
304  }
305  }
306  else
307  {
308  // Forward
309  setCursorPosition(line,col);
310  for( int k = 0; k < length; k++){
311  cursorRight(true);
312  }
313  }
314 }
315 
316 void KEdit::replace_all_slot(){
317 
318  if (!replace_dialog)
319  return;
320 
321  TQString to_find_string = replace_dialog->getText();
322 
323  int lineFrom, lineTo, colFrom, colTo;
324  getSelection(&lineFrom, &colFrom, &lineTo, &colTo);
325 
326  // replace_dialog->get_direction() is true if searching backward
327  if (replace_dialog->get_direction())
328  {
329  if (colTo != -1)
330  {
331  replace_all_col = colTo - to_find_string.length();
332  replace_all_line = lineTo;
333  }
334  else
335  {
336  getCursorPosition(&replace_all_line,&replace_all_col);
337  replace_all_col--;
338  }
339  }
340  else
341  {
342  if (colFrom != -1)
343  {
344  replace_all_col = colFrom;
345  replace_all_line = lineFrom;
346  }
347  else
348  {
349  getCursorPosition(&replace_all_line,&replace_all_col);
350  }
351  }
352 
353  deselect();
354 
355 again:
356 
357  setAutoUpdate(false);
358  int result = 1;
359 
360  while(result){
361 
362  result = doReplace(to_find_string, replace_dialog->case_sensitive(),
363  false, (!replace_dialog->get_direction()),
364  replace_all_line,replace_all_col,true);
365 
366  }
367 
368  setAutoUpdate(true);
369  update();
370 
371  if(!replace_dialog->get_direction()){ // forward search
372 
373  int query = KMessageBox::questionYesNo(
374  srchdialog,
375  i18n("End of document reached.\n"\
376  "Continue from the beginning?"),
377  i18n("Find"),KStdGuiItem::cont(),i18n("Stop"));
378  if (query == KMessageBox::Yes){
379  replace_all_line = 0;
380  replace_all_col = 0;
381  goto again;
382  }
383  }
384  else{ //backward search
385 
386  int query = KMessageBox::questionYesNo(
387  srchdialog,
388  i18n("Beginning of document reached.\n"\
389  "Continue from the end?"),
390  i18n("Find"),KStdGuiItem::cont(),i18n("Stop"));
391  if (query == KMessageBox::Yes){
392  TQString string = textLine( numLines() - 1 );
393  replace_all_line = numLines() - 1;
394  replace_all_col = string.length();
395  last_replace = BACKWARD;
396  goto again;
397  }
398  }
399 
400  emit CursorPositionChanged();
401 
402 }
403 
404 
405 void KEdit::replace_search_slot(){
406 
407  int line, col;
408 
409  if (!replace_dialog)
410  return;
411 
412  TQString to_find_string = replace_dialog->getText();
413 
414  int lineFrom, lineTo, colFrom, colTo;
415  getSelection(&lineFrom, &colFrom, &lineTo, &colTo);
416 
417  // replace_dialog->get_direction() is true if searching backward
418  if (replace_dialog->get_direction())
419  {
420  if (colFrom != -1)
421  {
422  col = colFrom - to_find_string.length();
423  line = lineFrom;
424  }
425  else
426  {
427  getCursorPosition(&line,&col);
428  col--;
429  }
430  }
431  else
432  {
433  if (colTo != -1)
434  {
435  col = colTo;
436  line = lineTo;
437  }
438  else
439  {
440  getCursorPosition(&line,&col);
441  }
442  }
443 
444 again:
445 
446  int result = doReplace(to_find_string, replace_dialog->case_sensitive(),
447  false, (!replace_dialog->get_direction()), line, col, false );
448 
449  if(!result){
450  if(!replace_dialog->get_direction()){ // forward search
451 
452  int query = KMessageBox::questionYesNo(
453  replace_dialog,
454  i18n("End of document reached.\n"\
455  "Continue from the beginning?"),
456  i18n("Replace"),KStdGuiItem::cont(),i18n("Stop"));
457  if (query == KMessageBox::Yes){
458  line = 0;
459  col = 0;
460  goto again;
461  }
462  }
463  else{ //backward search
464 
465  int query = KMessageBox::questionYesNo(
466  replace_dialog,
467  i18n("Beginning of document reached.\n"\
468  "Continue from the end?"),
469  i18n("Replace"),KStdGuiItem::cont(),i18n("Stop"));
470  if (query == KMessageBox::Yes){
471  TQString string = textLine( numLines() - 1 );
472  line = numLines() - 1;
473  col = string.length();
474  last_replace = BACKWARD;
475  goto again;
476  }
477  }
478  }
479  else{
480 
481  emit CursorPositionChanged();
482  }
483 }
484 
485 
486 
487 void KEdit::replacedone_slot(){
488 
489  if (!replace_dialog)
490  return;
491 
492  replace_dialog->hide();
493  // replace_dialog->clearFocus();
494 
495  setFocus();
496 
497  last_replace = NONE;
498  can_replace = false;
499 
500 }
501 
502 
503 
504 /* antlarr: KDE 4: make it const TQString & */
505 int KEdit::doReplace(TQString s_pattern, bool case_sensitive,
506  bool wildcard, bool forward, int line, int col, bool replace_all){
507 
508 
509  (void) wildcard; // reserved for possible extension to regex
510 
511  int line_counter, length;
512  int pos = -1;
513 
514  TQString string;
515  TQString stringnew;
516  TQString replacement;
517 
518  replacement = replace_dialog->getReplaceText();
519  line_counter = line;
520  replace_all_col = col;
521 
522  if(forward){
523 
524  int num_lines = numLines();
525 
526  while (line_counter < num_lines){
527 
528  string = textLine(line_counter);
529 
530  if (replace_all){
531  pos = string.find(s_pattern, replace_all_col, case_sensitive);
532  }
533  else{
534  pos = string.find(s_pattern, line_counter == line ? col : 0, case_sensitive);
535  }
536 
537  if (pos == -1 ){
538  line_counter++;
539  replace_all_col = 0;
540  replace_all_line = line_counter;
541  }
542 
543  if( pos != -1){
544 
545  length = s_pattern.length();
546 
547  if(replace_all){ // automatic
548 
549  stringnew = string.copy();
550  do
551  {
552  stringnew.replace(pos,length,replacement);
553 
554  replace_all_col = pos + replacement.length();
555  replace_all_line = line_counter;
556 
557  pos = stringnew.find(s_pattern, replace_all_col, case_sensitive);
558  }
559  while( pos != -1);
560 
561  removeLine(line_counter);
562  insertLine(stringnew,line_counter);
563 
564  setModified(true);
565  }
566  else{ // interactive
567 
568  setCursorPosition( line_counter , pos, false );
569 
570  for(int l = 0 ; l < length; l++){
571  cursorRight(true);
572  }
573 
574  setCursorPosition( line_counter , pos + length, true );
575  pattern = s_pattern;
576  last_replace = FORWARD;
577  can_replace = true;
578 
579  return 1;
580 
581  }
582 
583  }
584  }
585  }
586  else{ // searching backwards
587 
588  while(line_counter >= 0){
589 
590  string = textLine(line_counter);
591 
592  int line_length = string.length();
593 
594  if( replace_all ){
595  if (replace_all_col < 0)
596  pos = -1;
597  else
598  pos = string.findRev(s_pattern, replace_all_col , case_sensitive);
599  }
600  else{
601  if ((line == line_counter) && (col < 0))
602  pos = -1;
603  else
604  pos = string.findRev(s_pattern,
605  line == line_counter ? col : line_length , case_sensitive);
606  }
607 
608  if (pos == -1 ){
609  line_counter--;
610 
611  replace_all_col = 0;
612  if(line_counter >= 0){
613  string = textLine(line_counter);
614  replace_all_col = string.length();
615 
616  }
617  replace_all_line = line_counter;
618  }
619 
620 
621  if (pos != -1){
622  length = s_pattern.length();
623 
624  if(replace_all){ // automatic
625 
626  stringnew = string.copy();
627  stringnew.replace(pos,length,replacement);
628 
629  removeLine(line_counter);
630  insertLine(stringnew,line_counter);
631 
632  replace_all_col = pos-length;
633  replace_all_line = line_counter;
634  if (replace_all_col < 0)
635  {
636  line_counter--;
637 
638  if(line_counter >= 0){
639  string = textLine(line_counter);
640  replace_all_col = string.length();
641  }
642  replace_all_line = line_counter;
643  }
644 
645  setModified(true);
646  }
647  else{ // interactive
648 
649  // printf("line_counter %d pos %d col %d\n",line_counter, pos,col);
650  if( ! (line == line_counter && pos > col ) ){
651 
652  setCursorPosition(line_counter, pos + length ,false );
653 
654  for(int l = 0 ; l < length; l++){
655  cursorLeft(true);
656  }
657 
658  setCursorPosition(line_counter, pos ,true );
659  pattern = s_pattern;
660 
661  last_replace = BACKWARD;
662  can_replace = true;
663 
664  return 1;
665  }
666  }
667  }
668  }
669  }
670 
671  return 0;
672 
673 }
674 
675 
676 
677 
678 
680 //
681 // Find Dialog
682 //
683 
684 class KEdFind::KEdFindPrivate
685 {
686 public:
687  KEdFindPrivate( TQWidget *parent ) {
688  combo = new KHistoryCombo( parent, "value" );
689  combo->setMaxCount( 20 ); // just some default
690  }
691  ~KEdFindPrivate() {
692  delete combo;
693  }
694 
695  KHistoryCombo *combo;
696 };
697 
698 
699 KEdFind::KEdFind( TQWidget *parent, const char *name, bool modal )
700  :KDialogBase( parent, name, modal, i18n("Find"),
701  modal ? User1|Cancel : User1|Close, User1, false, KGuiItem( i18n("&Find"), "edit-find") )
702 {
703  setWFlags( WType_TopLevel );
704 
705  TQWidget *page = new TQWidget( this );
706  setMainWidget(page);
707  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
708 
709  d = new KEdFindPrivate( page );
710 
711  TQString text = i18n("Find:");
712  TQLabel *label = new TQLabel( text, page , "find" );
713  topLayout->addWidget( label );
714 
715  d->combo->setMinimumWidth(fontMetrics().maxWidth()*20);
716  d->combo->setFocus();
717 
718  connect(d->combo, TQT_SIGNAL(textChanged ( const TQString & )),
719  this,TQT_SLOT(textSearchChanged ( const TQString & )));
720 
721  topLayout->addWidget(d->combo);
722 
723  group = new TQVButtonGroup( i18n("Options"), page );
724  topLayout->addWidget( group );
725 
726  TQHBox* row1 = new TQHBox( group );
727 
728  text = i18n("Case &sensitive");
729  sensitive = new TQCheckBox( text, row1, "case");
730  text = i18n("Find &backwards");
731  direction = new TQCheckBox( text, row1, "direction" );
732 
733 
734  enableButton( KDialogBase::User1, !d->combo->currentText().isEmpty() );
735 
736  if ( !modal )
737  connect( this, TQT_SIGNAL( closeClicked() ), this, TQT_SLOT( slotCancel() ) );
738 }
739 
740 KEdFind::~KEdFind()
741 {
742  delete d;
743 }
744 
745 void KEdFind::textSearchChanged ( const TQString &text )
746 {
747  enableButton( KDialogBase::User1, !text.isEmpty() );
748 }
749 
750 void KEdFind::slotCancel( void )
751 {
752  emit done();
753  KDialogBase::slotCancel();
754 }
755 
756 void KEdFind::slotUser1( void )
757 {
758  if( !d->combo->currentText().isEmpty() )
759  {
760  d->combo->addToHistory( d->combo->currentText() );
761  emit search();
762  }
763 }
764 
765 
766 TQString KEdFind::getText() const
767 {
768  return d->combo->currentText();
769 }
770 
771 
772 /* antlarr: KDE 4: make it const TQString & */
773 void KEdFind::setText(TQString string)
774 {
775  d->combo->setEditText(string);
776  d->combo->lineEdit()->selectAll();
777 }
778 
779 void KEdFind::setCaseSensitive( bool b )
780 {
781  sensitive->setChecked( b );
782 }
783 
784 bool KEdFind::case_sensitive() const
785 {
786  return sensitive->isChecked();
787 }
788 
789 void KEdFind::setDirection( bool b )
790 {
791  direction->setChecked( b );
792 }
793 
794 bool KEdFind::get_direction() const
795 {
796  return direction->isChecked();
797 }
798 
799 KHistoryCombo * KEdFind::searchCombo() const
800 {
801  return d->combo;
802 }
803 
804 
805 
807 //
808 // Replace Dialog
809 //
810 
811 class KEdReplace::KEdReplacePrivate
812 {
813 public:
814  KEdReplacePrivate( TQWidget *parent ) {
815  searchCombo = new KHistoryCombo( parent, "value" );
816  replaceCombo = new KHistoryCombo( parent, "replace_value" );
817 
818  searchCombo->setMaxCount( 20 ); // just some defaults
819  replaceCombo->setMaxCount( 20 );
820  }
821  ~KEdReplacePrivate() {
822  delete searchCombo;
823  delete replaceCombo;
824  }
825 
826  KHistoryCombo *searchCombo, *replaceCombo;
827 };
828 
829 KEdReplace::KEdReplace( TQWidget *parent, const char *name, bool modal )
830  :KDialogBase( parent, name, modal, i18n("Replace"),
831  modal ? User3|User2|User1|Cancel : User3|User2|User1|Close,
832  User3, false,
833  i18n("Replace &All"), i18n("&Replace"), KGuiItem( i18n("&Find"), "edit-find") )
834 {
835  setWFlags( WType_TopLevel );
836 
837  setButtonBoxOrientation( Qt::Vertical );
838 
839  TQFrame *page = makeMainWidget();
840  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
841 
842  d = new KEdReplacePrivate( page );
843 
844  TQString text = i18n("Find:");
845  TQLabel *label = new TQLabel( text, page, "find" );
846  topLayout->addWidget( label );
847 
848  d->searchCombo->setMinimumWidth(fontMetrics().maxWidth()*20);
849  d->searchCombo->setFocus();
850  topLayout->addWidget(d->searchCombo);
851 
852  text = i18n("Replace with:");
853  label = new TQLabel( text, page, "replace" );
854  topLayout->addWidget( label );
855 
856  d->replaceCombo->setMinimumWidth(fontMetrics().maxWidth()*20);
857  topLayout->addWidget(d->replaceCombo);
858 
859  connect(d->searchCombo, TQT_SIGNAL(textChanged ( const TQString & )),
860  this,TQT_SLOT(textSearchChanged ( const TQString & )));
861 
862  TQButtonGroup *group = new TQButtonGroup( i18n("Options"), page );
863  topLayout->addWidget( group );
864 
865  TQGridLayout *gbox = new TQGridLayout( group, 3, 2, spacingHint() );
866  gbox->addRowSpacing( 0, fontMetrics().lineSpacing() );
867 
868  text = i18n("Case &sensitive");
869  sensitive = new TQCheckBox( text, group, "case");
870  text = i18n("Find &backwards");
871  direction = new TQCheckBox( text, group, "direction" );
872  gbox->addWidget( sensitive, 1, 0 );
873  gbox->addWidget( direction, 1, 1 );
874  gbox->setRowStretch( 2, 10 );
875 }
876 
877 
878 KEdReplace::~KEdReplace()
879 {
880  delete d;
881 }
882 
883 void KEdReplace::textSearchChanged ( const TQString &text )
884 {
885  bool state=text.isEmpty();
886  enableButton( KDialogBase::User1, !state );
887  enableButton( KDialogBase::User2, !state );
888  enableButton( KDialogBase::User3, !state );
889 }
890 
891 void KEdReplace::slotCancel( void )
892 {
893  emit done();
894  d->searchCombo->clearEdit();
895  d->replaceCombo->clearEdit();
896  KDialogBase::slotCancel();
897 }
898 
899 void KEdReplace::slotClose( void )
900 {
901  slotCancel();
902 }
903 
904 void KEdReplace::slotUser1( void )
905 {
906  if( !d->searchCombo->currentText().isEmpty() )
907  {
908  d->replaceCombo->addToHistory( d->replaceCombo->currentText() );
909  emit replaceAll();
910  }
911 }
912 
913 
914 void KEdReplace::slotUser2( void )
915 {
916  if( !d->searchCombo->currentText().isEmpty() )
917  {
918  d->replaceCombo->addToHistory( d->replaceCombo->currentText() );
919  emit replace();
920  }
921 }
922 
923 void KEdReplace::slotUser3( void )
924 {
925  if( !d->searchCombo->currentText().isEmpty() )
926  {
927  d->searchCombo->addToHistory( d->searchCombo->currentText() );
928  emit find();
929  }
930 }
931 
932 
933 TQString KEdReplace::getText()
934 {
935  return d->searchCombo->currentText();
936 }
937 
938 
939 TQString KEdReplace::getReplaceText()
940 {
941  return d->replaceCombo->currentText();
942 }
943 
944 
945 /* antlarr: KDE 4: make it const TQString & */
946 void KEdReplace::setText(TQString string)
947 {
948  d->searchCombo->setEditText(string);
949  d->searchCombo->lineEdit()->selectAll();
950 }
951 
952 
953 bool KEdReplace::case_sensitive()
954 {
955  return sensitive->isChecked();
956 }
957 
958 
959 bool KEdReplace::get_direction()
960 {
961  return direction->isChecked();
962 }
963 
964 KHistoryCombo * KEdReplace::searchCombo() const
965 {
966  return d->searchCombo;
967 }
968 
969 KHistoryCombo * KEdReplace::replaceCombo() const
970 {
971  return d->replaceCombo;
972 }
973 
974 
975 KEdGotoLine::KEdGotoLine( TQWidget *parent, const char *name, bool modal )
976  :KDialogBase( parent, name, modal, i18n("Go to Line"), modal ? Ok|Cancel : Ok|Close, Ok, false )
977 {
978  TQWidget *page = new TQWidget( this );
979  setMainWidget(page);
980  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
981 
982  lineNum = new KIntNumInput( 1, page);
983  lineNum->setRange(1, 1000000, 1, false);
984  lineNum->setLabel(i18n("Go to line:"), AlignVCenter | AlignLeft);
985 // lineNum->setMinimumWidth(fontMetrics().maxWidth()*20);
986  topLayout->addWidget( lineNum );
987 
988  topLayout->addStretch(10);
989  lineNum->setFocus();
990 }
991 
992 
993 void KEdGotoLine::selected(int)
994 {
995  accept();
996 }
997 
998 
999 int KEdGotoLine::getLineNumber()
1000 {
1001  return lineNum->value();
1002 }
1003 
1004 
1006 //
1007 // Spell Checking
1008 //
1009 
1010 void KEdit::spellcheck_start()
1011 {
1012  saved_readonlystate = isReadOnly();
1013  setReadOnly(true);
1014 }
1015 
1016 void KEdit::misspelling (const TQString &word, const TQStringList &, unsigned int pos)
1017 {
1018 
1019  unsigned int l = 0;
1020  unsigned int cnt = 0;
1021  posToRowCol (pos, l, cnt);
1022  setSelection(l, cnt, l, cnt+word.length());
1023 
1024  /*
1025  if (cursorPoint().y()>height()/2)
1026  tdespell->moveDlg (10, height()/2-tdespell->heightDlg()-15);
1027  else
1028  tdespell->moveDlg (10, height()/2 + 15);
1029  */
1030 
1031 }
1032 
1033 //need to use pos for insert, not cur, so forget cur altogether
1034 void KEdit::corrected (const TQString &originalword, const TQString &newword, unsigned int pos)
1035 {
1036  //we'll reselect the original word in case the user has played with
1037  //the selection in eframe or the word was auto-replaced
1038 
1039  unsigned int l = 0;
1040  unsigned int cnt = 0;
1041 
1042  if( newword != originalword )
1043  {
1044  posToRowCol (pos, l, cnt);
1045  setSelection(l, cnt, l, cnt+originalword.length());
1046 
1047  setReadOnly ( false );
1048  removeSelectedText();
1049  insert(newword);
1050  setReadOnly ( true );
1051  }
1052  else
1053  {
1054  deselect();
1055  }
1056 }
1057 
1058 void KEdit::posToRowCol(unsigned int pos, unsigned int &line, unsigned int &col)
1059 {
1060  for (line = 0; line < static_cast<uint>(numLines()) && col <= pos; line++)
1061  {
1062  col += lineLength(line)+1;
1063  }
1064  line--;
1065  col = pos - col + lineLength(line) + 1;
1066 }
1067 
1068 void KEdit::spellcheck_stop()
1069 {
1070  deselect();
1071 
1072  setReadOnly ( saved_readonlystate);
1073 }
1074 
1075 TQString KEdit::selectWordUnderCursor( )
1076 {
1077  int parag;
1078  int pos;
1079 
1080  getCursorPosition(&parag, &pos);
1081 
1082  TQString txt = text(parag);
1083 
1084  // Find start
1085  int start = pos;
1086  while( start > 0 )
1087  {
1088  const TQChar &ch = txt[start-1];
1089  if (ch.isSpace() || ch.isPunct())
1090  break;
1091  start--;
1092  }
1093 
1094  // Find end
1095  int end = pos;
1096  int len = txt.length();
1097  while( end < len )
1098  {
1099  const TQChar &ch = txt[end];
1100  if (ch.isSpace() || ch.isPunct())
1101  break;
1102  end++;
1103  }
1104  setSelection(parag, start, parag, end);
1105  return txt.mid(start, end-start);
1106 }
1107 
1108 TQPopupMenu *KEdit::createPopupMenu( const TQPoint& pos )
1109 {
1110  enum { IdUndo, IdRedo, IdSep1, IdCut, IdCopy, IdPaste, IdClear, IdSep2, IdSelectAll };
1111 
1112  TQPopupMenu *menu = TQMultiLineEdit::createPopupMenu( pos );
1113 
1114  if ( isReadOnly() )
1115  menu->changeItem( menu->idAt(0), SmallIconSet("edit-copy"), menu->text( menu->idAt(0) ) );
1116  else {
1117  int id = menu->idAt(0);
1118  menu->changeItem( id - IdUndo, SmallIconSet("edit-undo"), menu->text( id - IdUndo) );
1119  menu->changeItem( id - IdRedo, SmallIconSet("edit-redo"), menu->text( id - IdRedo) );
1120  menu->changeItem( id - IdCut, SmallIconSet("edit-cut"), menu->text( id - IdCut) );
1121  menu->changeItem( id - IdCopy, SmallIconSet("edit-copy"), menu->text( id - IdCopy) );
1122  menu->changeItem( id - IdPaste, SmallIconSet("edit-paste"), menu->text( id - IdPaste) );
1123  menu->changeItem( id - IdClear, SmallIconSet("edit-clear"), menu->text( id - IdClear) );
1124  }
1125 
1126  return menu;
1127 }
KMessageBox::questionYesNo
static int questionYesNo(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const KGuiItem &buttonYes=KStdGuiItem::yes(), const KGuiItem &buttonNo=KStdGuiItem::no(), const TQString &dontAskAgainName=TQString::null, int options=Notify)
Display a simple "question" dialog.
Definition: tdemessagebox.cpp:317
KNotifyClient::beep
void beep(const TQString &reason=TQString::null)
KEdit::replace
void replace()
Present a Search and Replace Dialog to the user.
Definition: keditcl2.cpp:247
KStdAction::deselect
TDEAction * deselect(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name)
Deselect any selected elements in the current document.
Definition: kstdaction.cpp:180
Vertical
KEdit::misspelling
void misspelling(const TQString &word, const TQStringList &, unsigned int pos)
Definition: keditcl2.cpp:1016
KEdit::spellcheck_stop
void spellcheck_stop()
Exit spellchecking mode.
Definition: keditcl2.cpp:1068
TDEStdAccel::cut
const TDEShortcut & cut()
KStdGuiItem::cont
static KGuiItem cont()
Returns a "continue" item.
Definition: kstdguiitem.cpp:212
KDialogBase
A dialog base class with standard buttons and predefined layouts.
Definition: kdialogbase.h:191
KEdit::spellcheck_start
void spellcheck_start()
Start spellchecking mode.
Definition: keditcl2.cpp:1010
KEdit::corrected
void corrected(const TQString &originalword, const TQString &newword, unsigned int pos)
Definition: keditcl2.cpp:1034
KDialogBase::User1
Show User defined button 1.
Definition: kdialogbase.h:206
tdelocale.h
KEdit::search
void search()
Present a search dialog to the user.
Definition: keditcl2.cpp:51
TDEStdAccel::end
const TDEShortcut & end()
KGuiItem
An abstract class for GUI data such as ToolTip and Icon.
Definition: kguiitem.h:38
KDialogBase::User2
Show User defined button 2.
Definition: kdialogbase.h:207
TDEStdAccel::find
const TDEShortcut & find()
TDEStdAccel::replace
const TDEShortcut & replace()
KEdit::CursorPositionChanged
void CursorPositionChanged()
This signal is emitted whenever the cursor position changes.
KDialogBase::slotCancel
virtual void slotCancel()
Activated when the Cancel button has been clicked.
Definition: kdialogbase.cpp:1215
KEdit::posToRowCol
void posToRowCol(unsigned int pos, unsigned int &line, unsigned int &col)
Sets line and col to the position pos, considering word wrap.
Definition: keditcl2.cpp:1058
KEdit::createPopupMenu
TQPopupMenu * createPopupMenu(const TQPoint &pos)
Definition: keditcl2.cpp:1108
KEdit::repeatSearch
bool repeatSearch()
Repeat the last search specified on the search dialog.
Definition: keditcl2.cpp:225
KHistoryCombo
A combobox for offering a history and completion.
Definition: kcombobox.h:540
TDEStdAccel::label
TQString label(StdAccel id)
KDialogBase::User3
Show User defined button 3.
Definition: kdialogbase.h:208
KIntNumInput
An input widget for integer numbers, consisting of a spinbox and a slider.
Definition: knuminput.h:188

tdeui

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

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.8.8
This website is maintained by Timothy Pearson.