📄 qmultilineedit.cpp
字号:
if ( cursorY >= line && cursorY > 0 ) cursorY--; bool updt = autoUpdate() && rowIsVisible( line ); QMultiLineEditRow* r = contents->at( line ); ASSERT( r ); bool recalc = r->w == maxLineWidth(); contents->remove( line ); if ( contents->count() == 0 ) { int w = textWidth( QString::fromLatin1("") ); contents->append( new QMultiLineEditRow(QString::fromLatin1(""), w) ); setWidth( w ); dummy = TRUE; } if ( setNumRowsAndTruncate() ) recalc = updt = FALSE; if ( recalc ) updateCellWidth(); makeVisible(); if (updt) update(); textDirty = TRUE; d->edited = TRUE;}/*! Inserts \a s at the current cursor position.*/void QMultiLineEdit::insert( const QString& s ){ insert( s, FALSE );}/*! Inserts \a c at the current cursor position. (this function is provided for backward compatibility - it simply calls insert()).*/void QMultiLineEdit::insertChar( QChar c ){ insert(c);}/*! Inserts \a c at the current cursor position.*/void QMultiLineEdit::insert( const QString& str, bool mark ){ dummy = FALSE; bool wasMarkedText = hasMarkedText(); if ( wasMarkedText ) addUndoCmd( new QBeginCommand ); if ( wasMarkedText ) del(); // ## Will flicker QString *s = getString( cursorY ); if ( cursorX > (int)s->length() ) cursorX = s->length(); else if ( overWrite && !wasMarkedText && cursorX < (int)s->length() ) del(); // ## Will flicker insertAt(str, cursorY, cursorX, mark ); makeVisible(); if ( wasMarkedText ) addUndoCmd( new QEndCommand() );}/*! Makes a line break at the current cursor position.*/void QMultiLineEdit::newLine(){ insert("\n");}/*! Deletes text from the current cursor position to the end of the line.*/void QMultiLineEdit::killLineAux(){ deselect(); // -sanders Don't let del() delete marked region QMultiLineEditRow* r = contents->at( cursorY ); if ( cursorX == (int)r->s.length() ) { // if (r->newline) // -sanders Only del newlines! del(); return; } else { bool recalc = r->w == maxLineWidth(); r->s.remove( cursorX, r->s.length() ); r->w = textWidth( r->s ); updateCell( cursorY, 0, FALSE ); if ( recalc ) updateCellWidth(); rebreakParagraph( cursorY ); // -sanders textDirty = TRUE; d->edited = TRUE; } curXPos = 0; makeVisible(); turnMark( FALSE );}/*! Moves the cursor one character to the left. If \a mark is TRUE, the text is marked. If \a wrap is TRUE, the cursor moves to the end of the previous line if it is placed at the beginning of the current line. \sa cursorRight() cursorUp() cursorDown()*/void QMultiLineEdit::cursorLeft( bool mark, bool wrap ){ cursorLeft(mark,!mark,wrap);}void QMultiLineEdit::cursorLeft( bool mark, bool clear_mark, bool wrap ){ if ( cursorX != 0 || cursorY != 0 && wrap ) { if ( mark && !hasMarkedText() ) { markAnchorX = cursorX; markAnchorY = cursorY; } d->blinkTimer->stop(); int ll = lineLength( cursorY ); if ( cursorX > ll ) cursorX = ll; cursorOn = TRUE; cursorX--; if ( cursorX < 0 ) { int oldY = cursorY; if ( cursorY > 0 ) { cursorY--; cursorX = lineLength( cursorY ); if ( cursorX > 1 && !isEndOfParagraph( cursorY ) ) cursorX--; } else { cursorY = 0; //### ? cursorX = 0; } updateCell( oldY, 0, FALSE ); } if ( mark ) newMark( cursorX, cursorY, FALSE ); d->blinkTimer->start( QApplication::cursorFlashTime() / 2, FALSE ); updateCell( cursorY, 0, FALSE ); } curXPos = 0; makeVisible(); if ( clear_mark ) turnMark( FALSE );}/*! Moves the cursor one character to the right. If \a mark is TRUE, the text is marked. If \a wrap is TRUE, the cursor moves to the beginning of the next line if it is placed at the end of the current line. \sa cursorLeft() cursorUp() cursorDown()*/void QMultiLineEdit::cursorRight( bool mark, bool wrap ){ cursorRight(mark,!mark,wrap);}void QMultiLineEdit::cursorRight( bool mark, bool clear_mark, bool wrap ){ int strl = lineLength( cursorY ); if ( strl > 1 && !isEndOfParagraph( cursorY ) ) strl--; if ( cursorX < strl || cursorY < (int)contents->count() - 1 && wrap ) { if ( mark && !hasMarkedText() ) { markAnchorX = cursorX; markAnchorY = cursorY; } d->blinkTimer->stop(); cursorOn = TRUE; cursorX++; if ( cursorX > strl ) { int oldY = cursorY; if ( cursorY < (int) contents->count() - 1 ) { cursorY++; cursorX = 0; } else { cursorX = lineLength( cursorY ); } updateCell( oldY, 0, FALSE ); } if ( mark ) newMark( cursorX, cursorY, FALSE ); updateCell( cursorY, 0, FALSE ); d->blinkTimer->start( QApplication::cursorFlashTime() / 2, FALSE ); } curXPos = 0; makeVisible(); if ( clear_mark ) turnMark( FALSE );}/*! Moves the cursor up one line. If \a mark is TRUE, the text is marked. \sa cursorDown() cursorLeft() cursorRight()*/void QMultiLineEdit::cursorUp( bool mark ){ cursorUp(mark,!mark);}void QMultiLineEdit::cursorUp( bool mark, bool clear_mark ){ if ( cursorY != 0 ) { if ( mark && !hasMarkedText() ) { markAnchorX = cursorX; markAnchorY = cursorY; } if ( !curXPos ) curXPos = mapToView( cursorX, cursorY ); int oldY = cursorY; d->blinkTimer->stop(); cursorOn = TRUE; cursorY--; if ( cursorY < 0 ) { cursorY = 0; } cursorX = mapFromView( curXPos, cursorY ); if ( mark ) newMark( cursorX, cursorY, FALSE ); updateCell( oldY, 0, FALSE ); updateCell( cursorY, 0, FALSE ); d->blinkTimer->start( QApplication::cursorFlashTime() / 2, FALSE ); } makeVisible(); if ( clear_mark ) turnMark( FALSE );}/*! Moves the cursor one line down. If \a mark is TRUE, the text is marked. \sa cursorUp() cursorLeft() cursorRight()*/void QMultiLineEdit::cursorDown( bool mark ){ cursorDown(mark,!mark);}void QMultiLineEdit::cursorDown( bool mark, bool clear_mark ){ int lastLin = contents->count() - 1; if ( cursorY != lastLin ) { if ( mark && !hasMarkedText() ) { markAnchorX = cursorX; markAnchorY = cursorY; } if ( !curXPos ) curXPos = mapToView( cursorX, cursorY ); int oldY = cursorY; d->blinkTimer->stop(); cursorOn = TRUE; cursorY++; if ( cursorY > lastLin ) { cursorY = lastLin; } cursorX = mapFromView( curXPos, cursorY ); if ( mark ) newMark( cursorX, cursorY, FALSE ); updateCell( oldY, 0, FALSE ); updateCell( cursorY, 0, FALSE ); d->blinkTimer->start( QApplication::cursorFlashTime() / 2, FALSE ); } makeVisible(); if ( clear_mark ) turnMark( FALSE );}/*! Turns off marked text*/void QMultiLineEdit::turnMark( bool on ){ if ( on != markIsOn ) { markIsOn = on; if ( echoMode() == Normal ) emit copyAvailable( on ); update(); }}/*! Deletes the character on the left side of the text cursor and moves the cursor one position to the left. If a text has been marked by the user (e.g. by clicking and dragging) the cursor is put at the beginning of the marked text and the marked text is removed. \sa del()*/void QMultiLineEdit::backspace(){ if ( hasMarkedText() ) { del(); } else { if ( !atBeginning() ) { cursorLeft( FALSE ); del(); } } makeVisible();}void QMultiLineEdit::removeText( int markBeginY, int markBeginX, int markEndY, int markEndX ){ textDirty = TRUE; d->edited = TRUE; if ( markBeginY == markEndY ) { //just one line QMultiLineEditRow *r = contents->at( markBeginY ); ASSERT(r); bool recalc = r->w == maxLineWidth(); r->s.remove( markBeginX, markEndX - markBeginX ); r->w = textWidth( r->s ); cursorX = markBeginX; cursorY = markBeginY; if (autoUpdate() ) updateCell( cursorY, 0, FALSE ); if ( recalc ) updateCellWidth(); } else { //multiline bool oldAuto = autoUpdate(); setAutoUpdate( FALSE ); ASSERT( markBeginY >= 0); ASSERT( markEndY < (int)contents->count() ); QMultiLineEditRow *firstR, *lastR; firstR = contents->at( markBeginY ); lastR = contents->at( markEndY ); ASSERT( firstR != lastR ); firstR->s.remove( markBeginX, firstR->s.length() - markBeginX ); lastR->s.remove( 0, markEndX ); firstR->s.append( lastR->s ); // lastS will be removed in loop below firstR->newline = lastR->newline; // Don't forget this -sanders firstR->w = textWidth( firstR->s ); for( int i = markBeginY + 1 ; i <= markEndY ; i++ ) contents->remove( markBeginY + 1 ); if ( contents->isEmpty() ) insertLine( QString::fromLatin1(""), -1 ); cursorX = markBeginX; cursorY = markBeginY; curXPos = 0; setNumRowsAndTruncate(); updateCellWidth(); setAutoUpdate( oldAuto ); if ( autoUpdate() ) update(); }}void QMultiLineEdit::delAux(){ int markBeginX, markBeginY; 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 stopAutoScroll(); d->dnd_startpos = e->pos(); if ( e->button() == RightButton ) { QPopupMenu *popup = new QPopupMenu( this );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -