?? qmultilineedit.cpp
return QString::null;}/*! Returns a copy of the whole text. If the multi line edit contains no text, a \link QString::operator!() null string\endlink is returned.*/QString QMultiLineEdit::text() const{ QString tmp; for( int i = 0 ; i < (int)contents->count() ; i++ ) { tmp += *getString(i); if ( i+1 < (int)contents->count() && contents->at(i)->newline ) tmp += '\n'; } return tmp;}/*! Selects all text without moving the cursor.*/void QMultiLineEdit::selectAll(){ markAnchorX = 0; markAnchorY = 0; markDragY = numLines() - 1; markDragX = lineLength( markDragY ); turnMark( markDragX != markAnchorX || markDragY != markAnchorY ); if ( autoUpdate() ) update();}/*! Deselects all text (i.e. removes marking) and leaves the cursor at the current position.*/void QMultiLineEdit::deselect(){ turnMark( FALSE );}/*! Sets the text to \a s, removing old text, if any.*/void QMultiLineEdit::setText( const QString &s ){ bool oldUndo = isUndoEnabled(); setUndoEnabled( FALSE ); bool oldAuto = autoUpdate(); setAutoUpdate( FALSE ); bool b = signalsBlocked(); blockSignals( TRUE ); clear(); CLEAR_UNDO blockSignals( b ); insertLine( s, -1 ); emit textChanged(); setAutoUpdate(oldAuto); if ( autoUpdate() ) update(); setUndoEnabled( oldUndo );#ifdef QT_KEYPAD_MODE if( qt_modalEditingEnabled ) { d->orgTxt = text(); }#endif}/*! Appends \a s to the text.*/void QMultiLineEdit::append( const QString &s ){ bool oldUndo = isUndoEnabled(); setUndoEnabled( FALSE ); insertLine( s, -1 ); setUndoEnabled( oldUndo ); emit textChanged();#ifdef QT_KEYPAD_MODE if( qt_modalEditingEnabled ) { d->orgTxt = text(); }#endif}/*! \reimpPasses wheel events to the vertical scrollbar.*/void QMultiLineEdit::wheelEvent( QWheelEvent *e ){ QApplication::sendEvent( verticalScrollBar(), e);}/*! The key press event handler converts a key press to some line editor action. Here are the default key bindings when isReadOnly() is FALSE: <ul> <li><i> Left Arrow </i> Move the cursor one character leftwards <li><i> Right Arrow </i> Move the cursor one character rightwards <li><i> Up Arrow </i> Move the cursor one line upwards <li><i> Down Arrow </i> Move the cursor one line downwards <li><i> Page Up </i> Move the cursor one page upwards <li><i> Page Down </i> Move the cursor one page downwards <li><i> Backspace </i> Delete the character to the left of the cursor <li><i> Home </i> Move the cursor to the beginning of the line <li><i> End </i> Move the cursor to the end of the line <li><i> Delete </i> Delete the character to the right of the cursor <li><i> Shift - Left Arrow </i> Mark text one character leftwards <li><i> Shift - Right Arrow </i> Mark text one character rightwards <li><i> Control-A </i> Move the cursor to the beginning of the line <li><i> Control-B </i> Move the cursor one character leftwards <li><i> Control-C </i> Copy the marked text to the clipboard <li><i> Control-D </i> Delete the character to the right of the cursor <li><i> Control-E </i> Move the cursor to the end of the line <li><i> Control-F </i> Move the cursor one character rightwards <li><i> Control-H </i> Delete the character to the left of the cursor <li><i> Control-K </i> Delete to end of line <li><i> Control-N </i> Move the cursor one line downwards <li><i> Control-P </i> Move the cursor one line upwards <li><i> Control-V </i> Paste the clipboard text into line edit <li><i> Control-X </i> Cut the marked text, copy to clipboard <li><i> Control-Z </i> Undo the last operation <li><i> Control-Y </i> Redo the last operation <li><i> Control - Left Arrow </i> Move the cursor one word leftwards <li><i> Control - Right Arrow </i> Move the cursor one word rightwards <li><i> Control - Up Arrow </i> Move the cursor one word upwards <li><i> Control - Down Arrow </i> Move the cursor one word downwards <li><i> Control - Home Arrow </i> Move the cursor to the beginning of the text <li><i> Control - End Arrow </i> Move the cursor to the end of the text </ul> In addition, the following key bindings are used on Windows: <ul> <li><i> Shift - Delete </i> Cut the marked text, copy to clipboard <li><i> Shift - Insert </i> Paste the clipboard text into line edit <li><i> Control - Insert </i> Copy the marked text to the clipboard </ul> All other keys with valid ASCII codes insert themselves into the line. Here are the default key bindings when isReadOnly() is TRUE: <ul> <li><i> Left Arrow </i> Scrolls the table rightwards <li><i> Right Arrow </i> Scrolls the table rightwards <li><i> Up Arrow </i> Scrolls the table one line downwards <li><i> Down Arrow </i> Scrolls the table one line upwards <li><i> Page Up </i> Scrolls the table one page downwards <li><i> Page Down </i> Scrolls the table one page upwards <li><i> Control-C </i> Copy the marked text to the clipboard </ul>*/void QMultiLineEdit::keyPressEvent( QKeyEvent *e ){#ifdef QT_KEYPAD_MODE if( qt_modalEditingEnabled ) { switch( e->key() ) { // two enters in a row to insert a return, one enter followed by any // other key to escape from modal mode case Key_Select: setModalEditing( !isModalEditing() ); return; case Key_Back: case Key_No: if ( !isModalEditing() ) { e->ignore(); return; } break; default: if ( e->text()[0].isPrint() ) { setModalEditing( TRUE ); clear(); } else { e->ignore(); return; } } } }#endif textDirty = FALSE; d->isHandlingEvent = TRUE; int unknown = 0; if ( readOnly ) { int pageSize = viewHeight() / cellHeight(); switch ( e->key() ) { case Key_Left: setXOffset( xOffset() - viewWidth()/10 ); break; case Key_Right: setXOffset( xOffset() + viewWidth()/10 ); break; case Key_Up: setTopCell( topCell() - 1 ); break; case Key_Down: setTopCell( topCell() + 1 ); break; case Key_Home: setCursorPosition(0,0, e->state() & ShiftButton ); break; case Key_End: setCursorPosition( numLines()-1, lineLength( numLines()-1 ), e->state() & ShiftButton ); break; case Key_Next: setTopCell( topCell() + pageSize ); break; case Key_Prior: setTopCell( QMAX( topCell() - pageSize, 0 ) ); break;#ifndef QT_NO_CLIPBOARD case Key_C: if ( echoMode() == Normal && (e->state()&ControlButton) ) copy(); else unknown++; break; case Key_F16: // Copy key on Sun keyboards if ( echoMode() == Normal ) copy(); else unknown++; break;#endif default: unknown++; } if ( unknown ) e->ignore(); d->isHandlingEvent = FALSE; return; } if ( e->text().length() && e->key() != Key_Return && e->key() != Key_Enter && e->key() != Key_Delete && e->key() != Key_Backspace &&#ifdef QT_KEYPAD_MODE e->key() != Key_Back && e->key() != Key_No &&#endif (!e->ascii() || e->ascii()>=32) ) { insert( e->text() ); //QApplication::sendPostedEvents( this, QEvent::Paint ); if ( textDirty ) emit textChanged(); d->isHandlingEvent = FALSE; return; } if ( e->state() & ControlButton ) { switch ( e->key() ) { case Key_A: home( e->state() & ShiftButton ); break; case Key_B: cursorLeft( e->state() & ShiftButton ); break;#ifndef QT_NO_CLIPBOARD case Key_C: if ( echoMode() == Normal ) copy(); break;#endif case Key_D: del(); break; case Key_E: end( e->state() & ShiftButton ); break; case Key_Left: cursorWordBackward( e->state() & ShiftButton ); break; case Key_Right: cursorWordForward( e->state() & ShiftButton ); break; case Key_Up: cursorUp( e->state() & ShiftButton ); break; case Key_Down: cursorDown( e->state() & ShiftButton ); break; case Key_Home: setCursorPosition(0,0, e->state() & ShiftButton ); break; case Key_End: setCursorPosition( numLines()-1, lineLength( numLines()-1 ), e->state() & ShiftButton ); break; case Key_F: cursorRight( e->state() & ShiftButton ); break; case Key_H: backspace(); break; case Key_K: killLine(); break; case Key_N: cursorDown( e->state() & ShiftButton ); break; case Key_P: cursorUp( e->state() & ShiftButton ); break;#ifndef QT_NO_CLIPBOARD case Key_V: paste(); break; case Key_X: cut(); break;#endif case Key_Z: undo(); break; case Key_Y: redo(); break;#if defined (_WS_WIN_) case Key_Insert: copy();#endif default: unknown++; } } else { switch ( e->key() ) { case Key_Left: cursorLeft( e->state() & ShiftButton ); break; case Key_Right: cursorRight( e->state() & ShiftButton ); break; case Key_Up: cursorUp( e->state() & ShiftButton ); break; case Key_Down: cursorDown( e->state() & ShiftButton ); break;#ifdef QT_KEYPAD_MODE case Key_No: if( qt_modalEditingEnabled ) { setText(d->orgTxt); setModalEditing( FALSE ); setEdited(FALSE); } else { unknown++; } break;#endif#ifdef QT_KEYPAD_MODE case Key_Back: if (!e->isAutoRepeat()) { if ( qt_modalEditingEnabled && !length() ) { setText(d->orgTxt); setEdited(FALSE); setModalEditing( FALSE ); } else if ( qt_modalEditingEnabled && d->deleteAllTimerId < 0) { d->deleteAllTimerId = startTimer(750); } else if (!qt_modalEditingEnabled) { ++unknown; } } break;#endif case Key_Backspace: backspace(); break; case Key_Home: home( e->state() & ShiftButton ); break; case Key_End: end( e->state() & ShiftButton ); break; case Key_Delete:#if defined (_WS_WIN_) if ( e->state() & ShiftButton ) { cut(); break; }#endif del(); break; case Key_Next: pageDown( e->state() & ShiftButton ); break; case Key_Prior: pageUp( e->state() & ShiftButton ); break; case Key_Enter: case Key_Return: newLine(); emit returnPressed(); break; case Key_Tab: insert( e->text() ); break;#if defined (_WS_WIN_) case Key_Insert: if ( e->state() & ShiftButton ) paste(); else unknown++; break;#endif case Key_F14: // Undo key on Sun keyboards undo(); break;#ifndef QT_NO_CLIPBOARD case Key_F16: // Copy key on Sun keyboards if ( echoMode() == Normal ) copy(); break; case Key_F18: // Paste key on Sun keyboards paste(); break; case Key_F20: // Paste key on Sun keyboards cut(); break;#endif default: unknown++; } } if ( textDirty ) emit textChanged(); if ( unknown ) // unknown key e->ignore();#ifdef QT_KEYPAD_MODE if( qt_modalEditingEnabled ) { if (cursorY == numLines()-1 && lineLength(numLines()-1) != 0) d->extraNewLineCount = 0; }#endif d->isHandlingEvent = FALSE;}/*! Moves the cursor one page down. If \a mark is TRUE, the text is marked.*/void QMultiLineEdit::pageDown( bool mark ){ bool oldAuto = autoUpdate(); if ( mark ) setAutoUpdate( FALSE ); if ( partiallyInvisible( cursorY ) ) cursorY = topCell(); int delta = cursorY - topCell(); int pageSize = viewHeight() / cellHeight(); int newTopCell = QMIN( topCell() + pageSize, numLines() - 1 - pageSize ); if ( pageSize >= numLines() ) { // quick fix to handle small texts newTopCell = topCell(); } if ( !curXPos ) curXPos = mapToView( cursorX, cursorY ); int oldY = cursorY; if ( mark && !hasMarkedText() ) { markAnchorX = cursorX; markAnchorY = cursorY; } if ( newTopCell != topCell() ) { cursorY = newTopCell + delta; cursorX = mapFromView( curXPos, cursorY ); if ( mark ) newMark( cursorX, cursorY, FALSE ); setTopCell( newTopCell ); } else if ( cursorY != (int)contents->count() - 1) { // just move the cursor cursorY = QMIN( cursorY + pageSize, numLines() - 1); cursorX = mapFromView( curXPos, cursorY ); if ( mark ) newMark( cursorX, cursorY, FALSE ); makeVisible(); } if ( oldAuto ) if ( mark ) { setAutoUpdate( TRUE ); update(); } else { updateCell( oldY, 0, FALSE ); } if ( !mark ) turnMark( FALSE );}/*! Moves the cursor one page up. If \a mark is TRUE, the text is marked.*/void QMultiLineEdit::pageUp( bool mark ){ bool oldAuto = autoUpdate(); if ( mark ) setAutoUpdate( FALSE ); if ( partiallyInvisible( cursorY ) ) cursorY = topCell(); int delta = cursorY - topCell(); int pageSize = viewHeight() / cellHeight(); bool partial = delta == pageSize && viewHeight() != pageSize * cellHeight(); int newTopCell = QMAX( topCell() - pageSize, 0 ); if ( pageSize > numLines() ) { // quick fix to handle small texts newTopCell = 0; delta = 0; }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -