summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorMichal Kubecek <mkubecek@suse.cz>2015-04-17 10:42:36 +0200
committerMichal Kubecek <mkubecek@suse.cz>2015-04-17 10:59:51 +0200
commit7b011f71ac046d0e533fe8663f23a431d3df4dba (patch)
tree239970136d772c54b92ffa7169d11e005a5b30ba /src/gui
parent60fb764bd8c1bac1c178bd470aa1bf5fa6d3851e (diff)
downloadtwinkle-7b011f71ac046d0e533fe8663f23a431d3df4dba.tar
twinkle-7b011f71ac046d0e533fe8663f23a431d3df4dba.tar.gz
twinkle-7b011f71ac046d0e533fe8663f23a431d3df4dba.tar.lz
twinkle-7b011f71ac046d0e533fe8663f23a431d3df4dba.tar.xz
twinkle-7b011f71ac046d0e533fe8663f23a431d3df4dba.zip
LogViewForm: follow bottom of the log
Minor improvement of log viewer form: if vertical scrollbar is on the bottom and new text is appended, scroll to bottom after appending it so that we can still see the newest entries. If the scrollbar is not on the bottom, preserve its position so that we can still see the same entry (as it used to be).
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/logviewform.cpp9
-rw-r--r--src/gui/logviewform.h1
2 files changed, 10 insertions, 0 deletions
diff --git a/src/gui/logviewform.cpp b/src/gui/logviewform.cpp
index fdf0f71..834496b 100644
--- a/src/gui/logviewform.cpp
+++ b/src/gui/logviewform.cpp
@@ -25,6 +25,12 @@ LogViewForm::~LogViewForm()
// no need to delete child widgets, Qt does it all for us
}
+bool LogViewForm::isOnBottom() const
+{
+ const QScrollBar* vsb = logTextEdit->verticalScrollBar();
+ return (vsb->value() == vsb->maximum());
+}
+
void LogViewForm::scrollToBottom()
{
QScrollBar* vsb = logTextEdit->verticalScrollBar();
@@ -86,7 +92,10 @@ void LogViewForm::update(bool log_zapped)
if (logstream) {
QString s = logstream->read();
if (!s.isNull() && !s.isEmpty()) {
+ bool bottom = isOnBottom();
logTextEdit->appendPlainText(s);
+ if (bottom)
+ scrollToBottom();
}
}
}
diff --git a/src/gui/logviewform.h b/src/gui/logviewform.h
index d91f7c6..ab4ec0b 100644
--- a/src/gui/logviewform.h
+++ b/src/gui/logviewform.h
@@ -15,6 +15,7 @@ private:
QFile* logfile;
QTextStream* logstream;
+ bool isOnBottom() const;
void scrollToBottom();
public: