示例#1
0
void QLineEdit::mouseReleaseEvent( QMouseEvent * e )
{
    if ( d->inDoubleClick ) {
	d->inDoubleClick = FALSE;
	return;
    }

#if defined(_WS_X11_)
    if ( hasMarkedText() && echoMode() == Normal )
	copyText();
#else
    if ( style() == MotifStyle && hasMarkedText() && echoMode() == Normal )
	copyText();
#endif
    if ( dragScrolling )
	dragScrolling = FALSE;
    if ( e->button() != LeftButton )
	return;

    int margin = frame() ? 4 : 2;
    if ( !QRect( margin, margin,
		 width() - 2*margin,
		 height() - 2*margin ).contains( e->pos() ) )
	return;

    int mousePos = offset + xPosToCursorPos( &tbuf[(int)offset],
					     fontMetrics(),
					     e->pos().x() - margin,
					     width() - margin - margin );
    int m1 = markDrag;
    newMark( mousePos, FALSE );
    repaintArea( m1, mousePos );
}
示例#2
0
void QLineEdit::end( bool mark )
{
    int tlen = strlen( tbuf );
    if ( cursorPos != tlen || (!mark && hasMarkedText()) ) {
	int mo = showLastPartOffset( &tbuf[offset], fontMetrics(),
				     width() - (frame() ? 8 : 4) );
	int markStart = cursorPos;
	cursorPos = tlen;
	cursorOn = FALSE;
	blinkSlot();
	if ( mark ) {
	    markStart = QMIN( markStart, markDrag );
	    newMark( cursorPos );
	} else {
	    markStart = QMIN( markStart, minMark() );
	    markAnchor = markDrag = cursorPos;
	}
	d->pmDirty = TRUE;
	if ( mo > 0 ) {
	    offset += mo;
	    repaint( FALSE );
	} else {
	    repaintArea( markStart, tlen );
	}
    }
}
示例#3
0
void QLineEdit::insert( const char * newText )
{
    QString t( newText );
    if ( t.isEmpty() )
	return;

    uchar *p = (uchar *) t.data();
    while ( *p ) {		// unprintable/nl becomes space
	if ( *p < 32 )
	    *p = 32;
	p++;
    }

    QString test( tbuf.copy() );
    int cp = cursorPos;
    if ( hasMarkedText() ) {
	test.remove( minMark(), maxMark() - minMark() );
	cp = minMark();
    }
    test.insert( cp, t );
    cp = QMIN( cp+t.length(), (uint)maxLength() );
    cursorOn = FALSE;
    blinkSlot();
    validateAndSet( test, cp, cp, cp );
}
示例#4
0
bool QLineEdit::event( QEvent * e )
{
#if 0 // it works, but we'll wait with enabling it.
    if ( !e )
	return QWidget::event( e );

    if ( e->type() == Event_DragEnter ) {
	if ( ((QDragEnterEvent *) e)->provides( "text/plain" ) ) {
	    ((QDragEnterEvent *) e)->accept( rect() );
	    return TRUE;
	}
    } else if ( e->type() == Event_DragLeave ) {
	return TRUE;
    } else if ( e->type() == Event_Drop ) {
	QDropEvent * de = (QDropEvent *) e;
	QString str;
	if ( QTextDrag::decode( de, str ) ) {
	    if ( !hasMarkedText() ) {
		int margin = frame() ? 2 : 0;
		setCursorPosition( xPosToCursorPos( &tbuf[(int)offset],
						    fontMetrics(),
						    de->pos().x() - margin,
						    width() - 2*margin ) );
	    }
	    insert( str );
	    de->accept();
	} else {
	    de->ignore();
	}
	return TRUE;
    }
#endif
    return QWidget::event( e );
}
示例#5
0
void QLineEdit::backspace()
{
    if ( hasMarkedText() ) {
	del();
    } else {
	if ( cursorPos > 0 ) {
	    cursorLeft( FALSE );
	    del();
	}
    }
}
示例#6
0
void QLineEdit::del()
{
    QString test( tbuf.copy() );

    if ( hasMarkedText() ) {
	test.remove( minMark(), maxMark() - minMark() );
	validateAndSet( test, minMark(), minMark(), minMark() );
    } else if ( cursorPos != (int)strlen(tbuf) ) {
	test.remove( cursorPos, 1 );
	validateAndSet( test, minMark(), minMark(), minMark() );
    }
}
示例#7
0
QPopupMenu *MultiLineEdit::createPopupMenu()
{
#if COMPAT_QT_VERSION < 0x030000
    QPopupMenu *popup = new QPopupMenu( this );
#ifndef QT_NO_CLIPBOARD
    popup->insertItem(i18n("Cut"), IdCut);
    popup->insertItem(i18n("Copy"), IdCopy);
    popup->insertItem(i18n("Paste"), IdPaste);
#endif
    popup->insertItem(i18n("Clear"), IdClear);
#ifndef QT_NO_CLIPBOARD
    popup->setItemEnabled(IdCut,
                          !isReadOnly() && hasMarkedText() );
    popup->setItemEnabled(IdCopy, hasMarkedText() );
    popup->setItemEnabled(IdPaste,
                          !isReadOnly() && (bool)QApplication::clipboard()->text().length() );
#endif
    popup->setItemEnabled(IdClear,
                          !isReadOnly() && (bool)text().length() );
#else
    QPopupMenu *popup = QMultiLineEdit::createPopupMenu();
    connect(popup, SIGNAL(activated(int)), this, SLOT(menuActivated(int)));
#endif
    if (helpList){
        popup->insertSeparator();
        int id = IdBase;
        for (const char **p = helpList; *p;){
            QString s = *p++;
            s = s.replace(QRegExp("\\&"), "&&");
            QString text = unquoteText(i18n(*p++));
            text += " (";
            text += s;
            text += ")";
            popup->insertItem(text, id++);
        }
    }
    return popup;
}
示例#8
0
void MyMultiEdit::mousePressEvent( QMouseEvent *e )
{
  if( e->button() == RightButton )
    {
      if( hasMarkedText() )
	{
	  QString marked = markedText();
	  if( marked.left(7) == "http://" || marked.left(6) == "ftp://" )
	    {
	      web_menu->popup(QCursor::pos());
	      web_menu->grabMouse();
	    }
	}
      return;
    }
  QMultiLineEdit::mousePressEvent(e);
  return;
}
示例#9
0
void MyMultiEdit::openUrl()
{
  QString command;
  int pos;
  if( hasMarkedText() )
    {
      QString marked = markedText();
      if( marked.left(7) == "http://" )
	{
	  command = exec_http;
	  command.detach();
	  if( (pos = exec_http.find("%u")) == -1 )
	    {
	      command += " " + marked + " &";
	    }
	  else
	    {
	      command.remove(pos, 2);
	      command = command.insert(pos, marked);
	      command += " &";
	    }
	  system((const char *) command);
	  //debug("exec: %s", (const char *) command );
	}
      else if( marked.left(6) == "ftp://" )
	{
	  command = exec_ftp;
	  command.detach();
	  if( (pos = exec_ftp.find("%u")) == -1 )
	    {
	      command += " " + marked + " &";
	    }
	  else
	    {
	      command.remove(pos, 2);
	      command = command.insert(pos, marked);
	      command += " &";
	    }
	  system((const char *) command);
	  //debug("exec: %s", (const char *) command );
	}
    }
}
示例#10
0
void QLineEdit::mousePressEvent( QMouseEvent *e )
{
    killTimers();
    d->inDoubleClick = FALSE;
    int margin = frame() ? 4 : 2;
    cursorPos = offset + xPosToCursorPos( &tbuf[(int)offset], fontMetrics(),
					  e->pos().x() - margin,
					  width() - 2*margin );
    if ( e->button() == MidButton ) {
#if defined(_WS_X11_)
	insert( QApplication::clipboard()->text() );
#else
	if ( style() == MotifStyle )
	    insert( QApplication::clipboard()->text() );
#endif
	return;
#if 0 // it works, but it's wait until we have an API
    } else if ( hasMarkedText() &&
		e->button() == LeftButton &&
		( (markAnchor > cursorPos && markDrag < cursorPos) ||
		  (markAnchor < cursorPos && markDrag > cursorPos) ) ) {
	QTextDrag * tdo = new QTextDrag( this );
	tdo->setText( markedText() );
	tdo->dragCopy();
	delete tdo;
	return;
#endif
    }

    int m1 = minMark();
    int m2 = maxMark();
    markAnchor = cursorPos;
    newMark( markAnchor, FALSE );
    if ( cursorPos > m2 )
	m2 = cursorPos;
    else if ( cursorPos < m1 )
	m1 = cursorPos;
    repaintArea( m1, m2 );
    dragScrolling = FALSE;
}
示例#11
0
void QLineEdit::cursorLeft( bool mark, int steps )
{
    if ( steps < 0 ) {
	cursorRight( mark, -steps );
	return;
    }
    if ( cursorPos > 0 || (!mark && hasMarkedText()) ) {
	cursorPos -= steps;
	if ( cursorPos < 0 )
	    cursorPos = 0;
	cursorOn = FALSE;
	blinkSlot();
	int minP = QMIN( minMark(), cursorPos );
	int maxP = QMAX( maxMark(), cursorPos );
	if ( mark )
	    newMark( cursorPos );
	else
	    markAnchor = markDrag = cursorPos;
	d->pmDirty = TRUE;
	repaintArea( minP, maxP );
    }
}
示例#12
0
void QLineEdit::home( bool mark )
{
    if ( cursorPos != 0 || (!mark && hasMarkedText()) ) {
	int m = cursorPos;
	cursorPos = 0;
	cursorOn = FALSE;
	blinkSlot();
	if ( mark ) {
	    m = QMAX( minMark(), m );
	    newMark( cursorPos );
	} else {
	    m = QMAX( maxMark(), m );
	    markDrag = markAnchor = 0;
	}
	d->pmDirty = TRUE;
	if ( offset ) {
	    offset = 0;
	    repaint( FALSE );
	} else {
	    repaintArea( 0, m );
	}
    }
}
示例#13
0
void QLineEdit::cursorRight( bool mark, int steps )
{
    if ( steps < 0 ) {
	cursorLeft( mark, -steps );
	return;
    }
    int len = (int)strlen( tbuf );
    if ( cursorPos < len || (!mark && hasMarkedText()) ) {
	int minP = QMIN( cursorPos, minMark() );
	cursorPos += steps;
	if ( cursorPos > len )
	    cursorPos = len;
	cursorOn = FALSE;
	blinkSlot();
	int maxP = QMAX( cursorPos, maxMark() );
	if ( mark )
	    newMark( cursorPos );
	else
	    markAnchor = markDrag = cursorPos;
	d->pmDirty = TRUE;
	repaintArea( minP, maxP );
    }
}
示例#14
0
void QLineEdit::keyPressEvent( QKeyEvent *e )
{
    if ( e->key() == Key_Enter || e->key() == Key_Return ) {
	QValidator * v = validator();
	if ( !v || v->validate( tbuf, cursorPos ) == QValidator::Acceptable ) {
	    emit returnPressed();
	} else if ( v ) {
	    v->fixup( tbuf );
	    if ( v->validate( tbuf, cursorPos ) == QValidator::Acceptable )
		emit returnPressed();
	}
	// ### 2.0 must fix this
	e->ignore();
	return;
    }
    if ( e->ascii() >= 32 &&
	 e->key() != Key_Delete &&
	 e->key() != Key_Backspace ) {
	QString t( 2 );
	t[0] = e->ascii();
	t[1] = '\0';
	insert( t );
	return;
    }
    int unknown = 0;
    if ( e->state() & ControlButton ) {
	switch ( e->key() ) {
	case Key_A:
	case Key_Left:
	    home( e->state() & ShiftButton );
	    break;
	case Key_B:
	    cursorLeft( e->state() & ShiftButton );
	    break;
	case Key_C:
	    if ( hasMarkedText() && echoMode() == Normal )
		copyText();
	    break;
	case Key_D:
	    del();
	    break;
	case Key_E:
	case Key_Right:
	    end( e->state() & ShiftButton );
	    break;
	case Key_F:
	    cursorRight( e->state() & ShiftButton );
	    break;
	case Key_H:
	    backspace();
	    break;
	case Key_K:
	    if ( cursorPos < (int)tbuf.length() ) {
		QString t( tbuf );
		t.detach(); // ### 2.0
		t.truncate( cursorPos );
		validateAndSet( t, cursorPos, cursorPos, cursorPos );
	    }
	    break;
	case Key_V:
	    insert( QApplication::clipboard()->text() );
	case Key_X:
	    if ( hasMarkedText() && echoMode() == Normal ) {
		copyText();
		del();
	    }
	    break;
	default:
	    unknown++;
	}
    } else {
	switch ( e->key() ) {
	case Key_Left:
	    cursorLeft( e->state() & ShiftButton );
	    break;
	case Key_Right:
	    cursorRight( e->state() & ShiftButton );
	    break;
	case Key_Backspace:
	    backspace();
	    break;
	case Key_Home:
	    home( e->state() & ShiftButton );
	    break;
	case Key_End:
	    end( e->state() & ShiftButton );
	    break;
	case Key_Delete:
	    del();
	    break;
	default:
	    unknown++;
	}
    }

    if ( unknown ) {				// unknown key
	e->ignore();
	return;
    }
}