Example #1
0
/* 
 * Special paste logic.
 * If we are on the first line, and if we have a multi-line paste,
 * then replace the paste with the first line of the paste,
 * do the paste onto the first line, replace the clipboard with the rest,
 * select the entire second line, and paste the rest.
 */
void SBookEdit::paste()
{
    int line,col;
    getCursorPosition(&line,&col);
    if(line!=0 || numLines()<2 ){			  // not on first line or 1 row; 
	QTextEdit::paste();		  // handle normally
	return;
    }
    QClipboard *cb = QApplication::clipboard();
    
    int nl = cb->text().find('\n');
    if(nl==-1 || (int)cb->text().length() == nl+1){
	QTextEdit::paste();
	return;
    }
    QString allText= cb->text();		  // make a copy
    QString line1  = cb->text().mid(0,nl-1);
    QString theRest= cb->text().mid(nl+1);

    /* Paste in the first line */
    cb->setText(line1);
    QTextEdit::paste();			  // paste in the first line

    /* If we haven't edited, select the entire second line.
     * Otherwise, just move to the beginning of the second line
     */
    if(edited==false){
	selectSecondLine();
    }
    else{
	setCursorPosition(1,0);			  // move to the next row
    }

    /* Now paste in the second line */
    cb->setText(theRest);
    QTextEdit::paste();
    cb->setText(allText);			  // restore the clipboard
}
static int panoMenderImageFileNamesReadFromScript(fullPath **ptrImageFileNames, fullPath *scriptFileName)
{
    char *script;
    AlignInfo alignInfo;
    int counter;
    int i;

    // We don't have any images yet. We read the Script and load them from it.
    if (ptDebug) {
	fprintf(stderr, "Loading script [%s]\n", scriptFileName->name);
    }
	
    script = LoadScript(scriptFileName);
    
    if (script == NULL) {
	PrintError("Could not load script [%s]", scriptFileName->name);
	return -1;
    }
    
    // parse input script and set up an array of input file names
    if (ParseScript(script, &alignInfo) != 0) {
	// print error
	
	PrintError("Panorama script parsing error");
	return 0;
    }
    
    // The parser of panotools is really broken. To retrieve each
    // input filename it reads the file,
    // finds the first filename, then removes it, and writes the rest of the file again
    // This is done recursively 
    
    counter = alignInfo.numIm;
    
    if (counter != 0) {
	
	// Try to find filenames in input section
	if (ptDebug) {
	    fprintf(stderr, "Found %d images in script file in INPUT section\n", counter);
	}
	// Allocate their space
	if ((*ptrImageFileNames = malloc(512 * counter)) == NULL) {
	    PrintError("Not enough memory");
	    exit(1);
	}
	
	//Iterate over input images and populate input filename array
	for (i = 0; i < counter; i ++) {
	    //If the image filenames don't appear to have any path information, then 
	    //prepend the path to the script (if any) that was specified on the 
	    //command line (Note: this was the only behavior in the original 
	    //PTStitcher.  It has been moved into this conditional block because
	    //the script path could get prepended to an already fully qualified
	    //filename...not very useful.
	    if (ptDebug) {
		fprintf(stderr, "Processing image [%s] from 'i' line %d\n", alignInfo.im[i].name, i);
	    }

	    panoMenderSetFileName(&((*ptrImageFileNames)[i]), alignInfo.im[i].name, scriptFileName);
	    
	    if (ptDebug) {
		fprintf(stderr, "Reading image filename [%s] from 'i' line %d\n", (*ptrImageFileNames)[i].name, i);
	    }
	    
	    
	}
	DisposeAlignInfo(&alignInfo);
    }	
    if (counter == 0) {
	// Sometimes the names of the images are not in the 'o' line, then assume they are
	// in the 'i' line.
	
	
	// create a temporary copy we can overwrite
	fullPath scriptPathName;
	
	counter = numLines(script, 'o');
	
	if (counter == 0) {
	    PrintError("No images found input file script file (there are no 'o' lines nor 'i' lines");
	    exit(1);
	}
	// Allocate their space
	if ((*ptrImageFileNames = malloc(512 * counter)) == NULL) {
	    PrintError("Not enough memory");
	    exit(1);
	}
	
	
	panoMenderDuplicateScriptFile(scriptFileName->name, script, &scriptPathName);
	
	for (i = 0; i < counter; i++) {
	    aPrefs* preferences;
	    if ( (preferences = readAdjustLine(&scriptPathName)) == NULL) {
		PrintError("No 'i' line for image number %d", i);
		exit(1);
	    }
	    
	    if (ptDebug) {
		fprintf(stderr, "Processing image [%s] from 'o' line %d\n", preferences->im.name, i);
	    }

	    panoMenderSetFileName(&((*ptrImageFileNames)[i]), preferences->im.name, scriptFileName);
	    
	    if (ptDebug) {
		fprintf(stderr, "Reading image filename [%s] from 'i' line %d\n",
			(*ptrImageFileNames)[i].name, i);
	    }
	    if (preferences->td != NULL)
		free(preferences->td);
	    
	    if (preferences->ts != NULL)
		free(preferences->ts);
	    
	    free(preferences);
	    
	} // end of for (i = 0; i < counter; i++) {
	free(script); 
	
	remove(scriptPathName.name);
	
    }
    return counter;
}
Example #3
0
int QMultiLineEdit::lineLength( int row ) const
{
    if ( row < 0 || row > numLines() )
	return -1;
    return document()->paragAt( row )->length() - 1;
}
Example #4
0
void QTextEdit::append( const char *str )
{
    QMultiLineEdit::append( str );
    setCursorPosition( numLines() + 1, 0 );
}
/**
 * Query whether the text contents can fit one one page or needs scrolling.
 *
 * @return true if scrolling is needed to show all the contents.
 */
bool TextViewer::needScrolling() {
    return  lastRowVisible() != numLines() - 1;
}
Example #6
0
/* antlarr: KDE 4: make it const QString & */
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 = 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();
          do 
          {  
	    stringnew.replace(pos,length,replacement);

	    replace_all_col = pos + replacement.length();
	    replace_all_line = line_counter;

            pos = stringnew.find(s_pattern, replace_all_col, case_sensitive);
          }
          while( pos != -1); 

	  removeLine(line_counter);
	  insertLine(stringnew,line_counter);

	  setModified(true);
	}
	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 = textLine(line_counter);

      int line_length = string.length();

      if( replace_all ){
        if (replace_all_col < 0)
          pos = -1;
        else
          pos = string.findRev(s_pattern, replace_all_col , case_sensitive);
      }
      else{
        if ((line == line_counter) && (col < 0))
          pos = -1;
        else
          pos = string.findRev(s_pattern,
			   line == line_counter ? col : line_length , case_sensitive);
      }

      if (pos == -1 ){
	line_counter--;

        replace_all_col = 0;
	if(line_counter >= 0){
	  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,line_counter);

	  replace_all_col = pos-length;
	  replace_all_line = line_counter;
	  if (replace_all_col < 0)
	  {
             line_counter--;

             if(line_counter >= 0){
                string = textLine(line_counter);
                replace_all_col = string.length();
             }
             replace_all_line = line_counter;
	  }

	  setModified(true);
	}
	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 + length ,false );

	    for(int l = 0 ; l < length; l++){
	      cursorLeft(true);
	    }

	    setCursorPosition(line_counter, pos ,true );
	    pattern = s_pattern;

	    last_replace = BACKWARD;
	    can_replace = true;

	    return 1;
	  }
	}
      }
    }
  }

  return 0;

}
Example #7
0
void KEdit::replace_search_slot(){

  int line, col;

  if (!replace_dialog)
    return;

  QString to_find_string = replace_dialog->getText();

  int lineFrom, lineTo, colFrom, colTo;
  getSelection(&lineFrom, &colFrom, &lineTo, &colTo);

  // replace_dialog->get_direction() is true if searching backward
  if (replace_dialog->get_direction())
  {
    if (colFrom != -1)
    {
      col = colFrom - to_find_string.length();
      line = lineFrom;
    }
    else
    {
      getCursorPosition(&line,&col);
      col--;
    }
  }
  else
  {
    if (colTo != -1)
    {
      col = colTo;
      line = lineTo;
    }
    else
    {
      getCursorPosition(&line,&col);
    }
  }

again:

  int  result = doReplace(to_find_string, replace_dialog->case_sensitive(),
			 false, (!replace_dialog->get_direction()), line, col, false );

  if(!result){
    if(!replace_dialog->get_direction()){ // forward search

     int query = KMessageBox::questionYesNo(
			replace_dialog,
                        i18n("End of document reached.\n"\
                             "Continue from the beginning?"),
                        i18n("Replace"),KStdGuiItem::cont(),i18n("Stop"));
     if (query == KMessageBox::Yes){
	line = 0;
	col = 0;
	goto again;
      }
    }
    else{ //backward search

     int query = KMessageBox::questionYesNo(
			replace_dialog,
                        i18n("Beginning of document reached.\n"\
                             "Continue from the end?"),
                        i18n("Replace"),KStdGuiItem::cont(),i18n("Stop"));
      if (query == KMessageBox::Yes){
	QString string = textLine( numLines() - 1 );
	line = numLines() - 1;
	col  = string.length();
	last_replace = BACKWARD;
	goto again;
      }
    }
  }
  else{

    emit CursorPositionChanged();
  }
}
Example #8
0
/* antlarr: KDE 4: make it const QString & */
int KEdit::doSearch(QString s_pattern, bool case_sensitive,
		    bool wildcard, bool forward, int line, int col){

  (void) wildcard; // reserved for possible extension to regex


  int i, length;
  int pos = -1;

  if(forward){

    QString string;

    for(i = line; i < numLines(); i++) {

      string = textLine(i);

      pos = string.find(s_pattern, i == line ? col : 0, case_sensitive);

      if( pos != -1){

	length = s_pattern.length();

	setCursorPosition(i,pos,false);

	for(int l = 0 ; l < length; l++){
	  cursorRight(true);
	}

	setCursorPosition( i , pos + length, true );
	pattern = s_pattern;
	last_search = FORWARD;

	return 1;
      }
    }
  }
  else{ // searching backwards

    QString string;

    for(i = line; i >= 0; i--) {

      string = textLine(i);
      int line_length = string.length();

      pos = string.findRev(s_pattern, line == i ? col : line_length , case_sensitive);

      if (pos != -1){

	length = s_pattern.length();

	if( ! (line == i && pos > col ) ){

	  setCursorPosition(i ,pos ,false );

	  for(int l = 0 ; l < length; l++){
	    cursorRight(true);
	  }

	  setCursorPosition(i ,pos + length ,true );
	  pattern = s_pattern;
	  last_search = BACKWARD;
	  return 1;

	}
      }

    }
  }

  return 0;

}
 /**
  * Change current read line to line.
  */
 void setCurrentLine(int line)
     { if (line >= numLines()) return;
       _current_line = line;
       _current_it_original = _ranges_original[_current_line].begin();
       _current_it_modified = _ranges_modified[_current_line].begin();}