Beispiel #1
0
void ReplaceWidget::doReplaceAll()
{
QString selectedword="";
if ( !editor )
  {
  startpos=-1; 
  endpos=-1;
  deltacol=0;
  return;
  }
if (ui.checkRegExp->isChecked())
  {
  QRegExp regex(ui.comboFind->currentText());
  if (!regex.isValid()) 
    {
    QMessageBox::warning( this,tr("Error"), tr("Invalid regular expression."));
    return;
    }
  }
bool go=true;
int result=-1;
if (ui.checkSelection->isChecked())
  {
  while (go && (startpos>-1) && (endpos>-1))
    {    
    result=editor->searchInSelection( ui.comboFind->currentText(), ui.checkCase->isChecked(),ui.checkWords->isChecked(), ui.checkRegExp->isChecked(),startpos,endpos); 
     if (result>-1)
	{
	
	startpos=result;
	replaceSelection();
	go=true;
	}
      else 
	{
	go=false;
	ui.checkSelection->setChecked( false );
	}
    }
  }
else
  {
  while ( editor->search( ui.comboFind->currentText(), ui.checkCase->isChecked(),
  ui.checkWords->isChecked(), ui.radioForward->isChecked(), !ui.checkBegin->isChecked(),ui.checkRegExp->isChecked()) )
      {
      editor->replace(ui.comboReplace->currentText(),ui.checkRegExp->isChecked(),ui.comboFind->currentText() );
      ui.checkBegin->setChecked( false );
      }
  ui.checkBegin->setChecked( true );
  }
}
void cTextField::onKeyDown(QKeyEvent *e) {
	int key = e->key();
	Qt::ButtonState state = e->state();

	// Handle special chars
	if (key == Qt::Key_Backspace) {
		// Replace the selection with an empty string
		if (selection_ != 0) {
			replaceSelection("");
		} else if (caret_ > 0) {
			setCaret(caret_ - 1);
			text_.remove(caret_, 1);
			invalidateText();
		}
	} else if (key == Qt::Key_Delete) {
		if (selection_ != 0) {
			replaceSelection("");
		} else if (caret_ < text_.length()) {
 			text_.remove(caret_, 1);
			invalidateText();
		}
	} else if (key == Qt::Key_Left) {
		if (caret_ > 0) {
			setCaret(caret_ - 1);
			if ((state & Qt::ShiftButton) != 0) {
				selection_++;
				invalidateText();
			} else {
				if (selection_ != 0) {
					selection_ = 0;
					invalidateText();
				}
			}
		}
	} else if (key == Qt::Key_Right) {
		if (caret_ < text_.length()) {
			setCaret(caret_ + 1);
			if ((state & Qt::ShiftButton) != 0) {
				selection_--;
				invalidateText();
			} else {
				if (selection_ != 0) {
					selection_ = 0;
					invalidateText();
				}
			}
		}
	} else if (key == Qt::Key_V && (state & Qt::ControlButton) != 0) {
		QClipboard *clipboard = qApp->clipboard();
		QString text = clipboard->text();
		if (!text.isEmpty()) {
			QCString ltext = text.latin1();
			replaceSelection(ltext);
		}
	} else if (key == Qt::Key_C && (state & Qt::ControlButton) != 0) {
		QClipboard *clipboard = qApp->clipboard();
		QCString text = getSelection();
		if (!text.isEmpty()) {
			clipboard->setText(QString(text), QClipboard::Clipboard);
		}
	} else if (key == Qt::Key_X && (state & Qt::ControlButton) != 0) {
		QClipboard *clipboard = qApp->clipboard();
		QCString text = getSelection();
		if (!text.isEmpty()) {
			clipboard->setText(QString(text), QClipboard::Clipboard);
			replaceSelection("");
		}
	} else if (key == Qt::Key_Return) {
		onEnter();
	} else if (key == Qt::Key_Home) {
        int oldCaret = caret_;
		selection_ = 0;
		setCaret(0);
		invalidateText();
		/*if (key.mod & KMOD_SHIFT) {
			selection_--;
			invalidateText();
		} else {
			if (selection_ != 0) {
				selection_ = 0;
				invalidateText();
			}
		}*/
	} else if (key == Qt::Key_End) {
		setCaret(text_.length());
		selection_ = 0;		
		invalidateText();
	} else if (text_.length() < maxLength_) {	
		char ch = e->text().at(0).latin1();

		// Check if the character is supported by the current font.
		if (ch != 0) {
			cSurface *chs = AsciiFonts->getCharacter(font_, ch);
			if (chs) {
				QCString replacement;
				replacement.insert(0, ch);
				replaceSelection(replacement);
			}
		}
	}
}
void QFEHelpEditorWidget::toChars()
{
    QString txt=getSelection();
    replaceSelection(deescapeHTML(txt));
}
void QFEHelpEditorWidget::toEntity()
{
    QString txt=getSelection();
    replaceSelection(escapeHTML(txt));
}
Beispiel #5
0
void ReplaceWidget::doReplace()
{
//doHide();

if ( !editor )
  {
  startpos=-1; 
  endpos=-1;
  deltacol=0;
  return;
  }
if (ui.checkRegExp->isChecked())
  {
  QRegExp regex(ui.comboFind->currentText());
  if (!regex.isValid()) 
    {
    QMessageBox::warning( this,tr("Error"), tr("Invalid regular expression."));
    return;
    }
  }
bool go=true;
int result=-1; 

if (ui.checkSelection->isChecked())
  {
  while (go && (startpos>-1) && (endpos>-1))
    {
     result=editor->searchInSelection( ui.comboFind->currentText(), ui.checkCase->isChecked(),ui.checkWords->isChecked(), ui.checkRegExp->isChecked(),startpos,endpos); 
     if (result>-1)
      {
      startpos=result;
      switch(  QMessageBox::warning(this, "Texmaker",tr("Replace this occurence ? "),tr("Yes"), tr("No"), tr("Cancel"), 0,2 ) )
	{
	case 0:
	replaceSelection();  
	ui.checkBegin->setChecked( false );
	  break;
	case 1:
	ui.checkBegin->setChecked( false );
	  break;
	case 2:
	go=false;
	ui.checkSelection->setChecked( false );
	  break;
	}
      }
     else ui.checkSelection->setChecked( false );  
    }
  }
else
  {
  while (go && editor->search( ui.comboFind->currentText(), ui.checkCase->isChecked(),
	  ui.checkWords->isChecked(), ui.radioForward->isChecked(), !ui.checkBegin->isChecked(),ui.checkRegExp->isChecked()) )
	{
	switch(  QMessageBox::warning(this, "Texmaker",tr("Replace this occurence ? "),tr("Yes"), tr("No"), tr("Cancel"), 0,2 ) )
	  {
	  case 0:
	  editor->replace(ui.comboReplace->currentText(),ui.checkRegExp->isChecked(),ui.comboFind->currentText() );
	  ui.checkBegin->setChecked( false );
	    break;
	  case 1:
	  ui.checkBegin->setChecked( false );
	    break;
	  case 2:
	  go=false;
	    break;
	  }
	}
  if (go) ui.checkBegin->setChecked( true );
  }
}