?? qmultilineedit.cpp
字號:
if ( mark && !hasMarkedText() ) { markAnchorX = cursorX; markAnchorY = cursorY; } if ( !curXPos ) curXPos = mapToView( cursorX, cursorY ); int oldY = cursorY; if ( newTopCell != topCell() ) { cursorY = QMIN( newTopCell + delta, numLines() - 1 ); if ( partial ) cursorY--; cursorX = mapFromView( curXPos, cursorY ); if ( mark ) newMark( cursorX, cursorY, FALSE ); setTopCell( newTopCell ); } else { // just move the cursor cursorY = QMAX( cursorY - pageSize, 0 ); cursorX = mapFromView( curXPos, cursorY ); if ( mark ) newMark( cursorX, cursorY, FALSE ); } if ( oldAuto ) if ( mark ) { setAutoUpdate( TRUE ); update(); } else { updateCell( oldY, 0, FALSE ); } if ( !mark ) turnMark( FALSE );}// THE CORE INSERTION FUNCTIONvoid QMultiLineEdit::insertAtAux( const QString &txt, int line, int col, bool mark ){ // don't check for compose end. this is used by compose events as well. dummy = FALSE; d->blinkTimer->stop(); cursorOn = TRUE; int oldw = contentsRect().width(); line = QMAX( QMIN( line, numLines() - 1), 0 ); col = QMAX( QMIN( col, lineLength( line )), 0 ); QString itxt = txt; QMultiLineEditRow *row = contents->at( line ); if ( d->maxlen >= 0 && length() + int(txt.length()) > d->maxlen ) itxt.truncate( d->maxlen - length() ); row->s.insert( uint(col), itxt ); if ( mark ) { markAnchorX = col; markAnchorY = line; } if ( cursorX == col && cursorY == line ) { cursorX += itxt.length(); } QFontMetrics fm( font() ); if ( !WORD_WRAP || ( col == 0 && itxt.contains('\n') == int(itxt.length())) ) wrapLine( line, 0 ); else if ( WORD_WRAP && itxt.find('\n')<0 && itxt.find('\t')<0 && ( ( DYNAMIC_WRAP && fm.width( itxt ) + row->w < contentsRect().width() - 2*d->lr_marg - d->marg_extra ) || ( FIXED_WIDTH_WRAP && ( d->wrapcol < 0 || fm.width( itxt ) + row->w < d->wrapcol ) ) || ( FIXED_COLUMN_WRAP && ( d->wrapcol < 0 || int(row->s.length()) < d->wrapcol ) ) ) && ( itxt.find(' ') < 0 || row->s.find(' ') >= 0 && row->s.find(' ') < col ) ){ row->w = textWidth( row->s ); setWidth( QMAX( maxLineWidth(), row->w) ); updateCell( line, 0, FALSE ); } else { if ( line > 0 && !contents->at( line-1)->newline ) rebreakParagraph( line-1 ); else rebreakParagraph( line ); } if ( mark ) newMark( cursorX, cursorY, FALSE ); setNumRowsAndTruncate(); textDirty = TRUE; d->edited = TRUE; if ( autoUpdate() ) { makeVisible(); d->blinkTimer->start( QApplication::cursorFlashTime() / 2, FALSE ); if ( DYNAMIC_WRAP && oldw != contentsRect().width() ) { setAutoUpdate( FALSE ); rebreakAll(); setAutoUpdate( TRUE ); update(); } }}/*! Inserts \a txt at line number \a line. If \a line is less than zero, or larger than the number of rows, the new text is put at the end. If \a txt contains newline characters, several lines are inserted. The cursor position is not changed.*/void QMultiLineEdit::insertLine( const QString &txt, int line ){ QString s = txt; int oldXPos = cursorX; int oldYPos = cursorY; if ( line < 0 || line >= int( contents->count() ) ) { if ( !dummy ) contents->append( new QMultiLineEditRow(QString::fromLatin1(""), 0) ); insertAt( s, numLines()-1, 0 ); } else { s.append('\n'); insertAt( s, line, 0 ); } cursorX = oldXPos; cursorY = oldYPos;}/*! Deletes the line at line number \a line. If \a line is less than zero, or larger than the number of lines, no line is deleted.*/void QMultiLineEdit::removeLine( int line ){ CLEAR_UNDO if ( line >= numLines() ) return; 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 );#ifdef QT_KEYPAD_MODE if( qt_modalEditingEnabled ) { if (d->extraNewLineCount && cursorY == (int)contents->count() - 2 && lineLength(numLines()-1) == 0) { del(); d->extraNewLineCount--; } }#endif}/*! 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 ){#ifdef QT_KEYPAD_MODE if ( qt_modalEditingEnabled && d->extraNewLineCount && cursorY == numLines() - 1 && lineLength(numLines()-1) == 0 && !mark) { backspace(); // this will decrement d->extraNewLineCount home(FALSE); } else#endif 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;#ifdef QT_KEYPAD_MODE if( qt_modalEditingEnabled ) { if ( cursorY == lastLin ) { // automatically add newlines. insertAt( "\n", numLines()-1, lineLength(numLines()-1), mark ); d->extraNewLineCount++; lastLin = contents->count() - 1; } }#endif 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;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -