From f05f489d48a42996e4fab455328a928d203d815c Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sun, 18 May 2008 18:42:27 +0000 Subject: [PATCH] add an hidden JS console output window, disabled by default (useful for debugging) svn path=/trunk/KDE/kdegraphics/okular/; revision=809331 --- core/script/kjs_console.cpp | 85 ++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/core/script/kjs_console.cpp b/core/script/kjs_console.cpp index e8bb3a3fc..01a365344 100644 --- a/core/script/kjs_console.cpp +++ b/core/script/kjs_console.cpp @@ -22,13 +22,95 @@ using namespace Okular; static KJSPrototype *g_consoleProto; +#ifdef OKULAR_JS_CONSOLE + +#include +#include + +#include +#include + +K_GLOBAL_STATIC( KDialog, g_jsConsoleWindow ) +static QPlainTextEdit *g_jsConsoleLog = 0; + +static void createConsoleWindow() +{ + if ( g_jsConsoleWindow.exists() ) + return; + + g_jsConsoleWindow->setButtons( KDialog::Close | KDialog::User1 ); + g_jsConsoleWindow->setButtonGuiItem( KDialog::User1, KStandardGuiItem::clear() ); + + QVBoxLayout *mainLay = new QVBoxLayout( g_jsConsoleWindow->mainWidget() ); + mainLay->setMargin( 0 ); + g_jsConsoleLog = new QPlainTextEdit( g_jsConsoleWindow->mainWidget() ); + g_jsConsoleLog->setReadOnly( true ); + mainLay->addWidget( g_jsConsoleLog ); + + QObject::connect( g_jsConsoleWindow, SIGNAL( closeClicked() ), + g_jsConsoleWindow, SLOT( close() ) ); + QObject::connect( g_jsConsoleWindow, SIGNAL( user1Clicked() ), + g_jsConsoleLog, SLOT( clear() ) ); +} + +static void showConsole() +{ + createConsoleWindow(); + g_jsConsoleWindow->show(); +} + +static void hideConsole() +{ + if ( !g_jsConsoleWindow.exists() ) + return; + + g_jsConsoleWindow->hide(); +} + +static void clearConsole() +{ + if ( !g_jsConsoleWindow.exists() ) + return; + + g_jsConsoleLog->clear(); +} + +static void outputToConsole( const QString &message ) +{ + showConsole(); + g_jsConsoleLog->appendPlainText( message ); +} + +#else /* OKULAR_JS_CONSOLE */ + +static void showConsole() +{ +} + +static void hideConsole() +{ +} + +static void clearConsole() +{ +} + +static void outputToConsole( const QString &cMessage ) +{ + kDebug(OkularDebug) << "CONSOLE:" << cMessage; +} + +#endif /* OKULAR_JS_CONSOLE */ + static KJSObject consoleClear( KJSContext *, void *, const KJSArguments & ) { + clearConsole(); return KJSUndefined(); } static KJSObject consoleHide( KJSContext *, void *, const KJSArguments & ) { + hideConsole(); return KJSUndefined(); } @@ -36,13 +118,14 @@ static KJSObject consolePrintln( KJSContext *ctx, void *, const KJSArguments &arguments ) { QString cMessage = arguments.at( 0 ).toString( ctx ); - kDebug(OkularDebug) << "CONSOLE:" << cMessage; + outputToConsole( cMessage ); return KJSUndefined(); } static KJSObject consoleShow( KJSContext *, void *, const KJSArguments & ) { + showConsole(); return KJSUndefined(); }