📄 keditcl2.cpp
字号:
} } else{ //backward search int query = QMessageBox::information( replace_dialog, klocale->translate("Replace"), klocale->translate("Beginning of document reached.\n"\ "Continue from the end?"), klocale->translate("Yes"), klocale->translate("No"), "", 0,1); if (query == 0){ QString string = textLine( numLines() - 1 ); line = numLines() - 1; col = string.length(); last_replace = BACKWARD; goto again; } } } else{ emit CursorPositionChanged(); }}void KEdit::replacedone_slot(){ if (!replace_dialog) return; replace_dialog->hide(); // replace_dialog->clearFocus(); this->setFocus(); last_replace = NONE; can_replace = FALSE;}int KEdit::doReplace(QString s_pattern, bool case_sensitive, bool wildcard, bool forward, int line, int col, bool replace_all){ (void) wildcard; // reserved for possible extension to regex int line_counter, length; int pos = -1; QString string; QString stringnew; QString replacement; replacement = replace_dialog->getReplaceText(); line_counter = line; replace_all_col = col; if(forward){ int num_lines = numLines(); while (line_counter < num_lines){ string = ""; string = textLine(line_counter); if (replace_all){ pos = string.find(s_pattern, replace_all_col, case_sensitive); } else{ pos = string.find(s_pattern, line_counter == line ? col : 0, case_sensitive); } if (pos == -1 ){ line_counter ++; replace_all_col = 0; replace_all_line = line_counter; } if( pos != -1){ length = s_pattern.length(); if(replace_all){ // automatic stringnew = string.copy(); stringnew.replace(pos,length,replacement); removeLine(line_counter); insertLine(stringnew.data(),line_counter); replace_all_col = replace_all_col + replacement.length(); replace_all_line = line_counter; setModified(); } else{ // interactive setCursorPosition( line_counter , pos, FALSE ); for(int l = 0 ; l < length; l++){ cursorRight(TRUE); } setCursorPosition( line_counter , pos + length, TRUE ); pattern = s_pattern; last_replace = FORWARD; can_replace = TRUE; return 1; } } } } else{ // searching backwards while(line_counter >= 0){ string = ""; string = textLine(line_counter); int line_length = string.length(); if( replace_all ){ pos = string.findRev(s_pattern, replace_all_col , case_sensitive); } else{ pos = string.findRev(s_pattern, line == line_counter ? col : line_length , case_sensitive); } if (pos == -1 ){ line_counter --; if(line_counter >= 0){ string = ""; string = textLine(line_counter); replace_all_col = string.length(); } replace_all_line = line_counter; } if (pos != -1){ length = s_pattern.length(); if(replace_all){ // automatic stringnew = string.copy(); stringnew.replace(pos,length,replacement); removeLine(line_counter); insertLine(stringnew.data(),line_counter); replace_all_col = replace_all_col - replacement.length(); replace_all_line = line_counter; setModified(); } else{ // interactive // printf("line_counter %d pos %d col %d\n",line_counter, pos,col); if( ! (line == line_counter && pos > col ) ){ setCursorPosition(line_counter ,pos ,FALSE ); for(int l = 0 ; l < length; l++){ cursorRight(TRUE); } setCursorPosition(line_counter ,pos + length ,TRUE ); pattern = s_pattern; last_replace = BACKWARD; can_replace = TRUE; return 1; } } } } } return 0;}//////////////////////////////////////////////////////////////////////// Find Dialog//KEdSrch::KEdSrch(QWidget *parent, const char *name) : QDialog(parent, name,FALSE){ this->setFocusPolicy(QWidget::StrongFocus); frame1 = new QGroupBox(klocale->translate("Find"), this, "frame1"); value = new QLineEdit( this, "value"); value->setFocus(); connect(value, SIGNAL(returnPressed()), this, SLOT(ok_slot())); sensitive = new QCheckBox(klocale->translate("Case Sensitive"), this, "case"); direction = new QCheckBox(klocale->translate("Find Backwards"), this, "direction"); ok = new QPushButton(klocale->translate("Find"), this, "find"); connect(ok, SIGNAL(clicked()), this, SLOT(ok_slot())); cancel = new QPushButton(klocale->translate("Done"), this, "cancel"); connect(cancel, SIGNAL(clicked()), this, SLOT(done_slot())); // connect(cancel, SIGNAL(clicked()), this, SLOT(reject())); setFixedSize(330, 130);}void KEdSrch::focusInEvent( QFocusEvent *){ value->setFocus(); //value->selectAll();}QString KEdSrch::getText() { return value->text(); }void KEdSrch::setText(QString string){ value->setText(string);}void KEdSrch::done_slot(){ emit search_done_signal();}bool KEdSrch::case_sensitive(){ return sensitive->isChecked();}bool KEdSrch::get_direction(){ return direction->isChecked();}void KEdSrch::ok_slot(){ QString text; text = value->text(); if (!text.isEmpty()) emit search_signal();}void KEdSrch::resizeEvent(QResizeEvent *){ frame1->setGeometry(5, 5, width() - 10, 80); cancel->setGeometry(width() - 80, height() - 30, 70, 25); ok->setGeometry(10, height() - 30, 70, 25); value->setGeometry(20, 25, width() - 40, 25); sensitive->setGeometry(20, 55, 110, 25); direction->setGeometry(width()- 20 - 130, 55, 130, 25);}//////////////////////////////////////////////////////////////////////// Replace Dialog//KEdReplace::KEdReplace(QWidget *parent, const char *name) : QDialog(parent, name,FALSE){ this->setFocusPolicy(QWidget::StrongFocus); frame1 = new QGroupBox(klocale->translate("Find:"), this, "frame1"); value = new QLineEdit( this, "value"); value->setFocus(); connect(value, SIGNAL(returnPressed()), this, SLOT(ok_slot())); replace_value = new QLineEdit( this, "replac_value"); connect(replace_value, SIGNAL(returnPressed()), this, SLOT(ok_slot())); label = new QLabel(this,"Rlabel"); label->setText(klocale->translate("Replace with:")); sensitive = new QCheckBox(klocale->translate("Case Sensitive"), this, "case"); sensitive->setChecked(TRUE); direction = new QCheckBox(klocale->translate("Find Backwards") , this, "direction"); ok = new QPushButton(klocale->translate("Find"), this, "find"); connect(ok, SIGNAL(clicked()), this, SLOT(ok_slot())); replace = new QPushButton(klocale->translate("Replace"), this, "rep"); connect(replace, SIGNAL(clicked()), this, SLOT(replace_slot())); replace_all = new QPushButton(klocale->translate("Replace All"), this, "repall"); connect(replace_all, SIGNAL(clicked()), this, SLOT(replace_all_slot())); cancel = new QPushButton(klocale->translate("Done"), this, "cancel"); connect(cancel, SIGNAL(clicked()), this, SLOT(done_slot())); setFixedSize(330, 180);}void KEdReplace::focusInEvent( QFocusEvent *){ value->setFocus(); // value->selectAll();}QString KEdReplace::getText() { return value->text(); }QString KEdReplace::getReplaceText() { return replace_value->text(); }void KEdReplace::setText(QString string) { value->setText(string); }void KEdReplace::done_slot(){ emit replace_done_signal();}void KEdReplace::replace_slot(){ emit replace_signal();}void KEdReplace::replace_all_slot(){ emit replace_all_signal();}bool KEdReplace::case_sensitive(){ return sensitive->isChecked();}bool KEdReplace::get_direction(){ return direction->isChecked();}void KEdReplace::ok_slot(){ QString text; text = value->text(); if (!text.isEmpty()) emit find_signal();}void KEdReplace::resizeEvent(QResizeEvent *){ frame1->setGeometry(5, 5, width() - 10, 135); cancel->setGeometry(width() - 80, height() - 30, 70, 25); ok->setGeometry(10, height() - 30, 70, 25); replace->setGeometry(85, height() - 30, 70, 25); replace_all->setGeometry(160, height() - 30, 85, 25); value->setGeometry(20, 25, width() - 40, 25); replace_value->setGeometry(20, 80, width() - 40, 25); label->setGeometry(20,55,80,20); sensitive->setGeometry(20, 110, 110, 25); direction->setGeometry(width()- 20 - 130, 110, 130, 25);}KEdGotoLine::KEdGotoLine( QWidget *parent, const char *name) : QDialog( parent, name, TRUE ){ frame = new QGroupBox( klocale->translate("Goto Line"), this ); lineNum = new KIntLineEdit( this ); this->setFocusPolicy( QWidget::StrongFocus ); connect(lineNum, SIGNAL(returnPressed()), this, SLOT(accept())); ok = new QPushButton(klocale->translate("Go"), this ); cancel = new QPushButton(klocale->translate("Cancel"), this ); connect(cancel, SIGNAL(clicked()), this, SLOT(reject())); connect(ok, SIGNAL(clicked()), this, SLOT(accept())); resize(300, 120); }void KEdGotoLine::selected(int){ accept();}void KEdGotoLine::resizeEvent(QResizeEvent *){ frame->setGeometry(5, 5, width() - 10, 80); cancel->setGeometry(width() - 80, height() - 30, 70, 25); ok->setGeometry(10, height() - 30, 70, 25); lineNum->setGeometry(20, 35, width() - 40, 25);}void KEdGotoLine::focusInEvent( QFocusEvent *){ lineNum->setFocus(); lineNum->selectAll();}int KEdGotoLine::getLineNumber(){ return lineNum->getValue();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -