source/widget/MTextEdit.cpp
/**
 * Appends the colored Message with the message and color to the end of the TextEdit.
 *
 * @param coloredMessage The message including the color information.
 */
Appends the colored Message with the message and color to the end of the TextEdit.

@param coloredMessage The message including the color information.
Appends the colored Message with the message and color to the end of the TextEdit . @param coloredMessage The message including the color information .
void MTextEdit::appendColoredMessage(const ColoredMessage& coloredMessage)
{
    coloredMessages.append(coloredMessage);
    bool scrollbarOnBottom = false;
    int scrollbarPosition = verticalScrollBar()->value();
    if (scrollbarPosition == verticalScrollBar()->maximum())
    {
        scrollbarOnBottom = true;
    }
    moveCursor(QTextCursor::End);
    setTextColor(getColor(coloredMessage));
    if (doLineBreak)
    {
        insertPlainText("\n");
    }
    QString message = coloredMessage.getMessage();
    if (message.endsWith('\n'))
    {
        doLineBreak = true;
        insertPlainText(message.left(message.length() - 1));
    }
    else
    {
        doLineBreak = false;
        insertPlainText(message);
    }
    if (scrollbarOnBottom)
    {
        verticalScrollBar()->setValue(verticalScrollBar()->maximum());
    }
    else
    {
        verticalScrollBar()->setValue(scrollbarPosition);
    }
}
void MTextEdit :: appendColoredMessage ( const ColoredMessage & coloredMessage ) { coloredMessages . append ( coloredMessage ) ; bool scrollbarOnBottom = false ; int scrollbarPosition = verticalScrollBar ( ) -> value ( ) ; if ( scrollbarPosition == verticalScrollBar ( ) -> maximum ( ) ) { scrollbarOnBottom = true ; } moveCursor ( QTextCursor :: End ) ; setTextColor ( getColor ( coloredMessage ) ) ; if ( doLineBreak ) { insertPlainText ( " \n " ) ; } QString message = coloredMessage . getMessage ( ) ; if ( message . endsWith ( ' \n ' ) ) { doLineBreak = true ; insertPlainText ( message . left ( message . length ( ) - 1 ) ) ; } else { doLineBreak = false ; insertPlainText ( message ) ; } if ( scrollbarOnBottom ) { verticalScrollBar ( ) -> setValue ( verticalScrollBar ( ) -> maximum ( ) ) ; } else { verticalScrollBar ( ) -> setValue ( scrollbarPosition ) ; } }
Appends the colored Message with the message and color to the end of the TextEdit.
Appends the colored Message with the message and color to the end of the TextEdit .