scrollToBottom / auto-scrolling for ProcessWidget diverted classes

Pieter Pareit pieter.pareit at planetinternet.be
Sat Oct 11 14:21:02 UTC 2003


Hello

I needed to see output of my application in the Application Part. 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.

Pieter


------------------------------------------------->8

Index: lib/util/processwidget.cpp
===================================================================
RCS file: /home/kde/kdevelop/lib/util/processwidget.cpp,v
retrieving revision 1.12
diff -u -3 -p -r1.12 processwidget.cpp
--- lib/util/processwidget.cpp  14 Jun 2003 09:36:42 -0000      1.12
+++ lib/util/processwidget.cpp  11 Oct 2003 12:10:26 -0000
@@ -18,6 +18,7 @@
 #include <klocale.h>
 #include <kprocess.h>
 #include <qpainter.h>
+#include <qapplication.h>


@@ -106,6 +108,7 @@ bool ProcessWidget::isRunning()
 void ProcessWidget::slotProcessExited(KProcess *)
 {
     childFinished(childproc->normalExit(), childproc->exitStatus());
+    scrollToBottom();
     emit processExited(childproc);
 }

@@ -113,14 +116,16 @@ void ProcessWidget::slotProcessExited(KP
 void ProcessWidget::insertStdoutLine(const QString &line)
 {
     insertItem(new ProcessListBoxItem(line.stripWhiteSpace(),
-        ProcessListBoxItem::Normal));
+                                      ProcessListBoxItem::Normal));
+    scrollToBottom();
 }


 void ProcessWidget::insertStderrLine(const QString &line)
 {
     insertItem(new ProcessListBoxItem(line.stripWhiteSpace(),
-        ProcessListBoxItem::Error));
+                                      ProcessListBoxItem::Error));
+    scrollToBottom();
 }


@@ -153,6 +158,12 @@ QSize ProcessWidget::minimumSizeHint() c

     return QSize( QListBox::sizeHint().width(),
                   (fontMetrics().lineSpacing()+2)*4 );
+}
+
+void ProcessWidget::scrollToBottom()
+{
+    qApp->processEvents();
+    verticalScrollBar()->setValue( verticalScrollBar()->maxValue() );
 }

 #include "processwidget.moc"
Index: lib/util/processwidget.h
===================================================================
RCS file: /home/kde/kdevelop/lib/util/processwidget.h,v
retrieving revision 1.6
diff -u -3 -p -r1.6 processwidget.h
--- lib/util/processwidget.h    29 Nov 2002 03:07:35 -0000      1.6
+++ lib/util/processwidget.h    11 Oct 2003 12:10:26 -0000
@@ -92,6 +92,9 @@ protected slots:
     void slotProcessExited(KProcess*);

 private:
+    void scrollToBottom();
+
+private:
     KProcess *childproc;
     ProcessLineMaker* procLineMaker;
 };





More information about the KDevelop-devel mailing list