From kde-commits Wed Oct 15 10:19:27 2003 From: Amilcar do Carmo Lucas Date: Wed, 15 Oct 2003 10:19:27 +0000 To: kde-commits Subject: kdevelop/lib/util X-MARC-Message: https://marc.info/?l=kde-commits&m=106621321032467 CVS commit by aclu: To see output of application in the Application Output Tab. This only was possible for the first messages, so I looked in the code of kdevelop to see what was going on. I came up with this changes in processwidget.h/cpp, The qApp->processEvents() is needed because otherwise the listbox is not yet updated before the scroll down. I tried to do the same using a QTimer, but then I would only get good results when the listbox was not yet very big. Added a check to see if we are not somewhere in the midle of the output, meaning the user has scrolled back. Patch by: Pieter Pareit Thanks. M +18 -2 processwidget.cpp 1.13 M +3 -0 processwidget.h 1.7 --- kdevelop/lib/util/processwidget.cpp #1.12:1.13 @@ -19,4 +19,5 @@ #include #include +#include @@ -107,4 +108,5 @@ void ProcessWidget::slotProcessExited(KP { childFinished(childproc->normalExit(), childproc->exitStatus()); + maybeScrollToBottom(); emit processExited(childproc); } @@ -115,4 +117,5 @@ void ProcessWidget::insertStdoutLine(con insertItem(new ProcessListBoxItem(line.stripWhiteSpace(), ProcessListBoxItem::Normal)); + maybeScrollToBottom(); } @@ -122,4 +125,5 @@ void ProcessWidget::insertStderrLine(con insertItem(new ProcessListBoxItem(line.stripWhiteSpace(), ProcessListBoxItem::Error)); + maybeScrollToBottom(); } @@ -154,4 +158,16 @@ QSize ProcessWidget::minimumSizeHint() c return QSize( QListBox::sizeHint().width(), (fontMetrics().lineSpacing()+2)*4 ); +} + +/** Should be called right after an insertItem(), + will automatic scroll the listbox if it is already at the bottom + to prevent automatic scrolling when the user has scrolled up +*/ +void ProcessWidget::maybeScrollToBottom() +{ + if ( verticalScrollBar()->value() == verticalScrollBar()->maxValue() ) { + qApp->processEvents(); + verticalScrollBar()->setValue( verticalScrollBar()->maxValue() ); + } } --- kdevelop/lib/util/processwidget.h #1.6:1.7 @@ -93,4 +93,7 @@ protected slots: private: + void maybeScrollToBottom(); + +private: KProcess *childproc; ProcessLineMaker* procLineMaker;