⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qmultilineedit.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    int markEndX, markEndY;    QRect oldContents = contentsRect();    if ( getMarkedRegion( &markBeginY, &markBeginX, &markEndY, &markEndX ) ) {	turnMark( FALSE );	removeText( markBeginY, markBeginX, markEndY, markEndX );	markAnchorY = markDragY = cursorY;	markAnchorX = markDragX = cursorX;    } else {	if ( !atEnd() ) {	    textDirty = TRUE;	    d->edited = TRUE;	    QMultiLineEditRow *r = contents->at( cursorY );	    if ( cursorX == (int) r->s.length() ) { // remove newline		QMultiLineEditRow* other = contents->at( cursorY + 1 );		if ( ! r->newline && cursorX )		    r->s.truncate( r->s.length()-1 );		bool needBreak = !r->s.isEmpty();		r->s += other->s;		r->newline =  other->newline;		contents->remove( cursorY + 1 );		if ( needBreak )		    rebreakParagraph( cursorY, 1 );		else		    wrapLine( cursorY, 1 );	    } else {		bool recalc = r->w == maxLineWidth();		r->s.remove( cursorX, 1 );		rebreakParagraph( cursorY );		if ( recalc )		    updateCellWidth();	    }	}    }    if ( DYNAMIC_WRAP && oldContents != contentsRect() ) {	if ( oldContents.width() != contentsRect().width() ) {	    bool oldAuto = autoUpdate();	    setAutoUpdate( FALSE );	    rebreakAll();	    setAutoUpdate( oldAuto );	}	if ( autoUpdate() )	    update();    }    curXPos  = 0;    makeVisible();}/*!  Moves the text cursor to the left end of the line. If \a mark is  TRUE, text is marked towards the first position. If it is FALSE and  the cursor is moved, all marked text is unmarked.  \sa end()*/void QMultiLineEdit::home( bool mark ){    if ( cursorX != 0 ) {	if ( mark && !hasMarkedText() ) {	    markAnchorX    = cursorX;	    markAnchorY    = cursorY;	}	d->blinkTimer->stop();	cursorX = 0;	cursorOn = TRUE;	if ( mark )	    newMark( cursorX, cursorY, FALSE );	updateCell( cursorY, 0, FALSE );	d->blinkTimer->start( QApplication::cursorFlashTime() / 2, FALSE );    }    curXPos  = 0;    if ( !mark )	turnMark( FALSE );    makeVisible();}/*!  Moves the text cursor to the right end of the line. If mark is TRUE  text is marked towards the last position.  If it is FALSE and the  cursor is moved, all marked text is unmarked.  \sa home()*/void QMultiLineEdit::end( bool mark ){    int tlen = lineLength( cursorY );    if ( cursorX != tlen ) {	if ( mark && !hasMarkedText() ) {	    markAnchorX    = cursorX;	    markAnchorY    = cursorY;	}	d->blinkTimer->stop();	cursorX = tlen;	cursorOn  = TRUE;	if ( mark )	    newMark( cursorX, cursorY, FALSE );	d->blinkTimer->start( QApplication::cursorFlashTime() / 2, FALSE );	updateCell( cursorY, 0, FALSE );    }    curXPos  = 0;    makeVisible();    if ( !mark )	turnMark( FALSE );}#ifndef QT_NO_QWS_IMint  QMultiLineEdit::pixelPosToIMPos( const QPoint &p ) const{    int xPos, yPos;    pixelPosToCursorPos( p, &xPos, &yPos );    //count to find the position    int clickPos = 0;    if ( yPos > d->preeditEndY || 	 yPos == d->preeditEndY && xPos > d->preeditEndX ) {	xPos = d->preeditEndX;	yPos = d->preeditEndY;    }	    int x = d->preeditStartX;    int y = d->preeditStartY;	    while ( y <= yPos ) {	if ( y == yPos ) {	    if ( x < xPos )		clickPos += xPos - x;	} else {	    QString *s = getString( y );	    int lineLen = s ? s->length() : 0;	    clickPos += lineLen - x;	}	x = 0;	y++;    }    return clickPos;    }#endif/*!\reimp*/void QMultiLineEdit::mousePressEvent( QMouseEvent *e ){#ifndef QT_NO_QWS_IM    if ( composeMode() ) {#if defined (_WS_QWS_)	QPaintDevice::qwsDisplay()->sendIMMouseEvent( pixelPosToIMPos( e->pos() ), TRUE ); #endif		return;    }#endif#ifdef QT_KEYPAD_MODE    if( qt_modalEditingEnabled ) {	if ( e->button() == LeftButton && !isModalEditing() )	    setModalEditing( TRUE );    }#endif    stopAutoScroll();    d->dnd_startpos = e->pos();    if ( e->button() == RightButton ) {	QPopupMenu *popup = new QPopupMenu( this );	int id[ (int)IdCount ];	id[ IdUndo ] = popup->insertItem( tr( "Undo" ) );	id[ IdRedo ] = popup->insertItem( tr( "Redo" ) );	popup->insertSeparator();#ifndef QT_NO_CLIPBOARD	id[ IdCut ] = popup->insertItem( tr( "Cut" ) );	id[ IdCopy ] = popup->insertItem( tr( "Copy" ) );	id[ IdPaste ] = popup->insertItem( tr( "Paste" ) );#ifndef QT_NO_MIMECLIPBOARD	id[ IdPasteSpecial ] = popup->insertItem( tr( "Paste special..." ) );#endif#endif	id[ IdClear ] = popup->insertItem( tr( "Clear" ) );	popup->insertSeparator();	id[ IdSelectAll ] = popup->insertItem( tr( "Select All" ) );	popup->setItemEnabled( id[ IdUndo ],				  !this->d->undoList.isEmpty() );	popup->setItemEnabled( id[ IdRedo ],				  !this->d->redoList.isEmpty() );#ifndef QT_NO_CLIPBOARD	popup->setItemEnabled( id[ IdCut ],			          !isReadOnly() && hasMarkedText() );	popup->setItemEnabled( id[ IdCopy ], hasMarkedText() );	popup->setItemEnabled( id[ IdPaste ],	    !isReadOnly() && (bool)QApplication::clipboard()->text().length() );#ifndef QT_NO_MIMECLIPBOARD	// Any non-plain types?	QMimeSource* ms = QApplication::clipboard()->data();	bool ps = FALSE;	if ( ms )  {	    if ( !isReadOnly() ) {		const char* fmt;		for (int i=0; !ps && (fmt=ms->format(i)); i++) {		    ps = qstrnicmp(fmt,"text/",5)==0		      && qstrnicmp(fmt+5,"plain",5)!=0;		}	    }	}	popup->setItemEnabled( id[ IdPasteSpecial ], ps );#endif#endif	popup->setItemEnabled( id[ IdClear ],				  !isReadOnly() && (bool)text().length() );	int allSelected = markIsOn && markAnchorX == 0 && markAnchorY == 0 &&			  markDragY == numLines() - 1 && markDragX == lineLength( markDragY );	popup->setItemEnabled( id[ IdSelectAll ],				  (bool)text().length() && !allSelected );	int r = popup->exec( e->globalPos() );	delete popup;	if ( r == id[ IdUndo ] )	    undo();	else if ( r == id[ IdRedo ] )	    redo();#ifndef QT_NO_CLIPBOARD	else if ( r == id[ IdCut ] )	    cut();	else if ( r == id[ IdCopy ] )	    copy();	else if ( r == id[ IdPaste ] )	    paste();# ifndef QT_NO_MIMECLIPBOARD	else if ( r == id[ IdPasteSpecial ] )	    pasteSpecial(QCursor::pos());# endif#endif	else if ( r == id[ IdClear ] )	    clear();	else if ( r == id[ IdSelectAll ] )	    selectAll();	return;    }    if ( e->button() != MidButton && e->button() != LeftButton)	return;    int newX, newY;    pixelPosToCursorPos( e->pos(), &newX, &newY );    if ( e->state() & ShiftButton ) {	wordMark = FALSE;	dragMarking    = TRUE;	setCursorPosition( newY, newX, TRUE);	return;    }#ifndef QT_NO_DRAGANDDROP    if (	inMark(newX, newY)		// Click on highlighted text	&& echoMode() == Normal		// No DnD of passwords, etc.	&& e->pos().y() < totalHeight() // Click past the end is not dragging	)    {	// The user might be trying to drag	d->dnd_primed = TRUE;	d->dnd_timer->start( QApplication::startDragTime(), FALSE );    } else#endif    {	wordMark = FALSE;	dragMarking    = TRUE;	setCursorPixelPosition(e->pos());    }}void QMultiLineEdit::pixelPosToCursorPos(QPoint p, int* x, int* y) const{    *y = findRow( p.y() );    if ( *y < 0 ) {	if ( p.y() < lineWidth() ) {	    *y = topCell();	} else {	    *y = lastRowVisible();	    p.setX(cellWidth());	}    }    *y = QMIN( (int)contents->count() - 1, *y );    QFontMetrics fm( font() );    *x = xPosToCursorPos( stringShown( *y ), fm,			  p.x() - d->lr_marg + xOffset(),			  cellWidth() - 2 * d->lr_marg - d->marg_extra,			  d->align );    QMultiLineEditRow* r = contents->at( *y );    if (r && !r->newline && ((unsigned int)*x == r->s.length()) && (*x > 0))	--*x;}void QMultiLineEdit::setCursorPixelPosition(QPoint p, bool clear_mark){    int newX, newY;    pixelPosToCursorPos( p, &newX, &newY );#ifdef QT_KEYPAD_MODE    if( qt_modalEditingEnabled ) {	while (d->extraNewLineCount > 0 && cursorY == numLines() - 1	    && lineLength(cursorY) == 0 && cursorX == 0 && cursorY > newY) {	    backspace();	}    }#endif    cursorX = newX;    curXPos        = 0;    if ( clear_mark ) {	markAnchorX    = cursorX;	markAnchorY    = newY;	bool markWasOn = markIsOn;	turnMark( FALSE );	if ( markWasOn ) {	    cursorY = newY;	    update();	    d->isHandlingEvent = FALSE;	    return;	}    }    if ( cursorY != newY ) {	int oldY = cursorY;	cursorY = newY;	updateCell( oldY, 0, FALSE );    }    updateCell( cursorY, 0, FALSE );		// ###}void QMultiLineEdit::startAutoScroll(){    if ( !dragScrolling ) {	d->scrollTime = initialScrollTime;	d->scrollAccel = initialScrollAccel;	d->scrollTimer->start( d->scrollTime, FALSE );	dragScrolling = TRUE;    }}void QMultiLineEdit::stopAutoScroll(){    if ( dragScrolling ) {	d->scrollTimer->stop();	dragScrolling = FALSE;    }}/*!\reimp*/void QMultiLineEdit::mouseMoveEvent( QMouseEvent *e ){#ifndef QT_NO_QWS_IM    if ( composeMode() ) {	return;    }#endif#ifndef QT_NO_DRAGANDDROP    d->dnd_timer->stop();    if ( d->dnd_primed &&	 ( d->dnd_startpos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) {	doDrag();	return;    }#endif    if ( !dragMarking )	return;    if ( rect().contains( e->pos() ) ) {	stopAutoScroll();    } else if ( !dragScrolling ) {	startAutoScroll();    }    int newX, newY;    pixelPosToCursorPos(e->pos(), &newX, &newY);    if ( wordMark ) {	extendSelectionWord( newX, newY);    }    if ( markDragX == newX && markDragY == newY )	return;    int oldY = markDragY;    newMark( newX, newY, FALSE );    for ( int i = QMIN(oldY,newY); i <= QMAX(oldY,newY); i++ )	updateCell( i, 0, FALSE );}void QMultiLineEdit::extendSelectionWord( int &newX, int&newY){    QString s = stringShown( newY );    int lim = s.length();    if ( newX >= 0 && newX < lim ) {	int i = newX;	int startclass = charClass(s.at(i));	if ( markAnchorY < markDragY ||	     ( markAnchorY == markDragY && markAnchorX < markDragX ) ) {	    // going right	    while ( i < lim && charClass(s.at(i)) == startclass )		i++;	} else {	    // going left	    while ( i >= 0 && charClass(s.at(i)) == startclass )		i--;	    i++;	}	newX = i;    }}/*!\reimp*/void QMultiLineEdit::mouseReleaseEvent( QMouseEvent *e ){#ifndef QT_NO_QWS_IM    if ( composeMode() ) {#if defined (_WS_QWS_)	QPaintDevice::qwsDisplay()->sendIMMouseEvent( pixelPosToIMPos( e->pos() ), FALSE ); #endif		return;    }#endif    stopAutoScroll();#ifndef QT_NO_DRAGANDDROP    if ( d->dnd_timer->isActive() ) {	d->dnd_timer->stop();	d->dnd_primed = FALSE;	setCursorPixelPosition(e->pos());    }#endif    wordMark = FALSE;    dragMarking   = FALSE;    textDirty = FALSE;    d->isHandlingEvent = TRUE;    if ( markAnchorY == markDragY && markAnchorX == markDragX )	turnMark( FALSE );#ifndef QT_NO_CLIPBOARD#if defined(_WS_X11_)    else if ( echoMode() == Normal )	copy();#endif    if ( e->button() == MidButton && !readOnly ) {#if defined(_WS_X11_)	paste();		// Will repaint the cursor line.#else	if ( style() == MotifStyle )	    paste();#endif    }#endif    d->isHandlingEvent = FALSE;    if ( !readOnly && textDirty )	emit textChanged();}/*!\reimp*/void QMultiLineEdit::mouseDoubleClickEvent( QMouseEvent *m ){#ifndef QT_NO_QWS_IM    if ( composeMode() ) {	return;    }#endif    if ( m->button() == LeftButton ) {	if ( m->state() & ShiftButton ) {	    int newX = cursorX;	    int newY = cursorY;	    extendSelectionWord( newX, newY);	    newMark( newX, newY, FALSE );	} else {	    markWord( cursorX, cursorY );	}	dragMarking    = TRUE;	wordMark = TRUE;	updateCell( cursorY, 0, FALSE );    }}#ifndef QT_NO_DRAGANDDROP/*!  \reimp*/void QMultiLineEdit::dragEnterEvent( QDragEnterEvent * ){    cursorOn = TRUE;    updateCell( cursorY, 0, FALSE );}/*!\reimp*/void QMultiLineEdit::dragMoveEvent( QDragMoveEvent* event ){    if ( readOnly ) return;    event->accept( QTextDrag::canDecode(event) );    d->dnd_forcecursor = TRUE;    setCursorPixelPosition(event->pos(), FALSE);    d->dnd_forcecursor = FALSE;    QRect inside_margin(scroll_margin, scroll_margin,			width()-scroll_margin*2, height()-scroll_margin*2);    if ( !inside_margin.contains(event->pos()) ) {	startAutoScroll();    }    if ( event->source() == this && event->action() == QDropEvent::Move )	event->acceptAction();}/*!\reimp*/void QMultiLineEdit::dragLeaveEvent( QDragLeaveEvent* ){    if ( cursorOn ) {	cursorOn = FALSE;	updateCell( cursorY, 0, FALSE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -