diff options
author | kh1 <karsten.heimrich@digia.com> | 2014-07-18 11:22:31 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@digia.com> | 2014-07-18 13:12:17 +0200 |
commit | 5ca8f4d7a4171a1dae355899fb4fa457d34489b1 (patch) | |
tree | e31dca31c6d4f99563a886ed155f117e8e2b3d56 /src/libs/installer | |
parent | e7925974802829339ebe351a5bb5a5d143933745 (diff) |
Show Details widget doesn't follow content during install.
Now also keeps the position if we have scrolled somewhere.
Task-number: QTIFW-353
Change-Id: I58e90592df3d8d4589b5e577366c251e501900d9
Reviewed-by: Niels Weber <niels.weber@digia.com>
Diffstat (limited to 'src/libs/installer')
-rw-r--r-- | src/libs/installer/lazyplaintextedit.cpp | 26 | ||||
-rw-r--r-- | src/libs/installer/lazyplaintextedit.h | 5 | ||||
-rw-r--r-- | src/libs/installer/performinstallationform.cpp | 9 |
3 files changed, 29 insertions, 11 deletions
diff --git a/src/libs/installer/lazyplaintextedit.cpp b/src/libs/installer/lazyplaintextedit.cpp index c0857458a..93a090e96 100644 --- a/src/libs/installer/lazyplaintextedit.cpp +++ b/src/libs/installer/lazyplaintextedit.cpp @@ -57,10 +57,12 @@ void LazyPlainTextEdit::timerEvent(QTimerEvent *event) killTimer(m_timerId); m_timerId = 0; m_cachedOutput.chop(1); //removes the last \n - if (!m_cachedOutput.isEmpty()) + if (!m_cachedOutput.isEmpty()) { appendPlainText(m_cachedOutput); - horizontalScrollBar()->setValue( 0 ); - m_cachedOutput.clear(); + updateCursor(TextCursorPosition::Keep); + horizontalScrollBar()->setValue(0); + m_cachedOutput.clear(); + } } } @@ -81,7 +83,6 @@ void LazyPlainTextEdit::clear() QPlainTextEdit::clear(); } - void LazyPlainTextEdit::setVisible(bool visible) { if (m_timerId) { @@ -93,4 +94,21 @@ void LazyPlainTextEdit::setVisible(bool visible) m_timerId = startTimer(INTERVAL); QPlainTextEdit::setVisible(visible); + updateCursor(TextCursorPosition::Keep); +} + +void LazyPlainTextEdit::updateCursor(TextCursorPosition position) +{ + QTextCursor cursor = textCursor(); + if ((position == TextCursorPosition::ForceEnd) || cursor.atEnd()) { + // Workaround for height calculation issue if scrollbar is set to Qt::ScrollBarAsNeeded. + Qt::ScrollBarPolicy policy = horizontalScrollBarPolicy(); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); // enforce always on + + cursor.movePosition(QTextCursor::End); + setTextCursor(cursor); + ensureCursorVisible(); + + setHorizontalScrollBarPolicy(policy); // but reset once we updated the cursor position + } } diff --git a/src/libs/installer/lazyplaintextedit.h b/src/libs/installer/lazyplaintextedit.h index 34651a36b..06cf45f0a 100644 --- a/src/libs/installer/lazyplaintextedit.h +++ b/src/libs/installer/lazyplaintextedit.h @@ -48,7 +48,12 @@ class LazyPlainTextEdit : public QPlainTextEdit { Q_OBJECT public: + enum struct TextCursorPosition { + Keep, + ForceEnd + }; explicit LazyPlainTextEdit(QWidget *parent = 0); + void updateCursor(TextCursorPosition position); public slots: void append(const QString &text); diff --git a/src/libs/installer/performinstallationform.cpp b/src/libs/installer/performinstallationform.cpp index 211d8176e..5480b397a 100644 --- a/src/libs/installer/performinstallationform.cpp +++ b/src/libs/installer/performinstallationform.cpp @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2012-2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2012-2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Qt Installer Framework. @@ -149,10 +149,6 @@ void PerformInstallationForm::toggleDetails() { const bool willShow = !isShowingDetails(); m_detailsButton->setText(willShow ? tr("&Hide Details") : tr("&Show Details")); - - if (willShow) - scrollDetailsToTheEnd(); - m_detailsBrowser->setVisible(willShow); emit showDetailsChanged(); } @@ -188,8 +184,7 @@ void PerformInstallationForm::setDetailsButtonEnabled(bool enable) void PerformInstallationForm::scrollDetailsToTheEnd() { - m_detailsBrowser->horizontalScrollBar()->setValue(0); - m_detailsBrowser->verticalScrollBar()->setValue(m_detailsBrowser->verticalScrollBar()->maximum()); + m_detailsBrowser->updateCursor(LazyPlainTextEdit::TextCursorPosition::ForceEnd); } bool PerformInstallationForm::isShowingDetails() const |