From 53716c209b72e3299c6eb5a8afc2f2ea6125158a Mon Sep 17 00:00:00 2001 From: deva Date: Wed, 18 Aug 2010 09:15:52 +0000 Subject: Make debug window more responsive. --- client/debug.cc | 25 ++++++++----------------- client/debug.h | 34 ++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 23 deletions(-) (limited to 'client') diff --git a/client/debug.cc b/client/debug.cc index 6eed1ad..066b0bc 100644 --- a/client/debug.cc +++ b/client/debug.cc @@ -27,8 +27,6 @@ */ #include "debug.h" -#include -#include #include #include #include @@ -37,19 +35,6 @@ static const char * const class_str[] = { "debug", "error", "warn", "log" }; -class DebugWindow : public QDialog { -public: - DebugWindow(); - - void log(const char *func, const char *file, const int line, - debug_class cl, const char *ch, QString &msg); -protected: - void closeEvent(QCloseEvent *event); - -private: - QListWidget *lst; -}; - DebugWindow::DebugWindow() { setLayout(new QVBoxLayout()); @@ -62,6 +47,9 @@ DebugWindow::DebugWindow() resize(settings.value("size", QSize(700, 800)).toSize()); move(settings.value("pos", QPoint(0, 0)).toPoint()); settings.endGroup(); + + timer.setSingleShot(true); + connect(&timer, SIGNAL(timeout()), lst, SLOT(scrollToBottom())); } void DebugWindow::closeEvent(QCloseEvent *event) @@ -77,6 +65,8 @@ void DebugWindow::closeEvent(QCloseEvent *event) void DebugWindow::log(const char *func, const char *file, const int line, debug_class cl, const char *ch, QString &msg) { + timer.stop(); + // Remove trailing newlines. while(msg.endsWith("\n")) msg = msg.left(msg.length() - 1); @@ -92,11 +82,12 @@ void DebugWindow::log(const char *func, const char *file, const int line, if(cl == _warn) item->setBackground(QBrush(QColor(200, 200, 230))); if(cl == _log) item->setBackground(QBrush(QColor(200, 230, 200))); + lst->addItem(item); - lst->scrollToBottom(); + // lst->scrollToBottom(); + timer.start(100); } - static DebugWindow* debugwindow = NULL; void dbg_init() diff --git a/client/debug.h b/client/debug.h index e0de223..ebafce5 100644 --- a/client/debug.h +++ b/client/debug.h @@ -27,6 +27,34 @@ */ #ifndef __PRACRO_DEBUG_H__ +#include +#include +#include +#include + +typedef enum { + _debug, + _error, + _warn, + _log +} debug_class; + +class DebugWindow : public QDialog { + Q_OBJECT +public: + DebugWindow(); + + void log(const char *func, const char *file, const int line, + debug_class cl, const char *ch, QString &msg); + +protected: + void closeEvent(QCloseEvent *event); + +private: + QListWidget *lst; + QTimer timer; +}; + void dbg_init(); void dbg_free(); @@ -36,12 +64,6 @@ void dbg_hide(); bool dbg_enabled(); -typedef enum { - _debug, - _error, - _warn, - _log -} debug_class; void dbg_log(const char *func, const char *file, const int line, debug_class cl, const char *ch, const char *fmt, ...) -- cgit v1.2.3