diff --git a/src/SeerCaretAsteriskLogWidget.cpp b/src/SeerCaretAsteriskLogWidget.cpp index 4f36ead..de73c5c 100644 --- a/src/SeerCaretAsteriskLogWidget.cpp +++ b/src/SeerCaretAsteriskLogWidget.cpp @@ -26,6 +26,7 @@ void SeerCaretAsteriskLogWidget::processText (const QString& text) { // Write the string to the log. textEdit->append(str); - textEdit->verticalScrollBar()->setValue(textEdit->verticalScrollBar()->maximum()); + + moveToEnd(); } diff --git a/src/SeerLogWidget.cpp b/src/SeerLogWidget.cpp index 70cd400..5c4f241 100644 --- a/src/SeerLogWidget.cpp +++ b/src/SeerLogWidget.cpp @@ -35,7 +35,26 @@ SeerLogWidget::~SeerLogWidget () { } void SeerLogWidget::processText (const QString& text) { + + // Add text to the end of the document. textEdit->append(text); + + moveToEnd(); +} + +void SeerLogWidget::moveToEnd () { + + // Move cursor to start of the last line. + // Move scrollbars to the last line. + int nlines = textEdit->document()->lineCount(); + + QTextCursor cursor = textEdit->textCursor(); + + cursor.setPosition(nlines-1); + + textEdit->setTextCursor(cursor); + textEdit->moveCursor(QTextCursor::StartOfLine); + textEdit->verticalScrollBar()->setValue(textEdit->verticalScrollBar()->maximum()); } diff --git a/src/SeerLogWidget.h b/src/SeerLogWidget.h index 5135139..cdc01be 100644 --- a/src/SeerLogWidget.h +++ b/src/SeerLogWidget.h @@ -13,6 +13,7 @@ class SeerLogWidget : public QWidget, protected Ui::SeerLogWidgetForm { ~SeerLogWidget (); virtual void processText (const QString& text); + virtual void moveToEnd (); public slots: void handleText (const QString& text); diff --git a/src/SeerTildeEqualAmpersandLogWidget.cpp b/src/SeerTildeEqualAmpersandLogWidget.cpp index 213d90d..fa43feb 100644 --- a/src/SeerTildeEqualAmpersandLogWidget.cpp +++ b/src/SeerTildeEqualAmpersandLogWidget.cpp @@ -85,6 +85,7 @@ void SeerTildeEqualAmpersandLogWidget::processText (const QString& text) { // Write the string to the log. textEdit->append(str); - textEdit->verticalScrollBar()->setValue(textEdit->verticalScrollBar()->maximum()); + + moveToEnd(); } diff --git a/src/SeerTildeLogWidget.cpp b/src/SeerTildeLogWidget.cpp index 390fd8c..3878617 100644 --- a/src/SeerTildeLogWidget.cpp +++ b/src/SeerTildeLogWidget.cpp @@ -31,6 +31,7 @@ void SeerTildeLogWidget::processText (const QString& text) { } textEdit->append(str); - textEdit->verticalScrollBar()->setValue(textEdit->verticalScrollBar()->maximum()); + + moveToEnd(); }