[libcalamaresui] Simplify log-window

Scrolling explicitly to the bottom isn't needed; leaving it
up to appendPlainText() has the following behavior:

- if the text is scrolled all the way down, follows the text
  and scrolls further down (tailing)
- if it is not scrolled all the way down, keeps current position.
This commit is contained in:
Adriaan de Groot 2022-03-15 14:39:59 +01:00
parent d998c9e24b
commit 28bf8478c4

View File

@ -1,6 +1,8 @@
#include "LogWidget.h"
#include "utils/Logger.h"
#include <QFile>
#include <QScrollBar>
#include <QStackedLayout>
#include <QTextStream>
#include <QThread>
@ -61,6 +63,7 @@ LogWidget::LogWidget( QWidget* parent )
setLayout( layout );
m_text->setReadOnly( true );
m_text->setVerticalScrollBarPolicy( Qt::ScrollBarPolicy::ScrollBarAlwaysOn );
QFont monospaceFont( "monospace" );
monospaceFont.setStyleHint( QFont::Monospace );
@ -77,15 +80,7 @@ LogWidget::LogWidget( QWidget* parent )
void
LogWidget::handleLogChunk( const QString& logChunk )
{
// Scroll to the end of the new chunk, only if we were at the end (tailing
// the log); scrolling up will break the tail-to-end behavior.
const bool isAtEnd = m_text->textCursor().atEnd();
m_text->appendPlainText( logChunk );
if ( isAtEnd )
{
m_text->moveCursor( QTextCursor::End );
}
m_text->ensureCursorVisible();
}
void