void QtSupportPlugin::testQtOutputFormatter_appendMixedAssertAndAnsi() { QPlainTextEdit edit; TestQtOutputFormatter formatter; formatter.setPlainTextEdit(&edit); const QString inputText = QString::fromLatin1( "\x1b[38;2;0;0;127mHello\n" "Object::Test in test.cpp:123\n" "\x1b[38;2;0;0;127mHello\n"); const QString outputText = QString::fromLatin1( "Hello\n" "Object::Test in test.cpp:123\n" "Hello\n"); formatter.appendMessage(inputText, QTextCharFormat()); QCOMPARE(edit.toPlainText(), outputText); edit.moveCursor(QTextCursor::Start); QCOMPARE(edit.currentCharFormat(), blueFormat()); edit.moveCursor(QTextCursor::Down); edit.moveCursor(QTextCursor::EndOfLine); QCOMPARE(edit.currentCharFormat(), linkFormat(QTextCharFormat(), QLatin1String("test.cpp:123"))); edit.moveCursor(QTextCursor::End); QCOMPARE(edit.currentCharFormat(), blueFormat()); }
void MessagesDialog::sinkMessage( const MsgEvent *msg ) { QMutexLocker locker( &messageLocker ); QPlainTextEdit *messages = ui.messages; /* Only scroll if the viewport is at the end. Don't bug user by auto-changing/losing viewport on insert(). */ bool b_autoscroll = ( messages->verticalScrollBar()->value() + messages->verticalScrollBar()->pageStep() >= messages->verticalScrollBar()->maximum() ); /* Copy selected text to the clipboard */ if( messages->textCursor().hasSelection() ) messages->copy(); /* Fix selected text bug */ if( !messages->textCursor().atEnd() || messages->textCursor().anchor() != messages->textCursor().position() ) messages->moveCursor( QTextCursor::End ); /* Start a new logic block so we can hide it on-demand */ messages->textCursor().insertBlock(); QString buf = QString( "<i><font color='darkblue'>%1</font>" ).arg( msg->module ); switch ( msg->priority ) { case VLC_MSG_INFO: buf += "<font color='blue'> info: </font>"; break; case VLC_MSG_ERR: buf += "<font color='red'> error: </font>"; break; case VLC_MSG_WARN: buf += "<font color='green'> warning: </font>"; break; case VLC_MSG_DBG: default: buf += "<font color='grey'> debug: </font>"; break; } /* Insert the prefix */ messages->textCursor().insertHtml( buf /* + "</i>" */ ); /* Insert the message */ messages->textCursor().insertHtml( msg->text ); /* Pass the new message thru the filter */ QTextBlock b = messages->document()->lastBlock(); b.setVisible( matchFilter( b.text() ) ); /* Tell the QTextDocument to recompute the size of the given area */ messages->document()->markContentsDirty( b.position(), b.length() ); if ( b_autoscroll ) messages->ensureCursorVisible(); }
//------------------------------------------------------------------------- void MainWindow::insertTextAtLine(int lineNr, const char* pText) { QPlainTextEdit *sourceCode = getCurrentSourceCode(); if (lineNr >= 0) { QTextCursor sourceCursor = sourceCode->textCursor(); sourceCursor.setPosition(sourceCode->document()->findBlockByLineNumber(lineNr).position()); sourceCode->setTextCursor(sourceCursor); } else { sourceCode->moveCursor(QTextCursor::StartOfLine); } sourceCode->insertPlainText(QString::fromUtf8(pText)); }