File indexing completed on 2024-05-12 04:33:32
0001 /* 0002 SPDX-FileCopyrightText: 2008 Pino Toscano <pino@kde.org> 0003 SPDX-FileCopyrightText: 2008 Harri Porten <porten@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "js_console_p.h" 0009 0010 #include <QDebug> 0011 0012 #include "../debug_p.h" 0013 0014 using namespace Okular; 0015 0016 #ifdef OKULAR_JS_CONSOLE 0017 0018 #include <QLayout> 0019 #include <QPlainTextEdit> 0020 0021 #include <KDialog> 0022 #include <KStandardGuiItem> 0023 0024 K_GLOBAL_STATIC(KDialog, g_jsConsoleWindow) 0025 static QPlainTextEdit *g_jsConsoleLog = 0; 0026 0027 static void createConsoleWindow() 0028 { 0029 if (g_jsConsoleWindow.exists()) 0030 return; 0031 0032 g_jsConsoleWindow->setButtons(KDialog::Close | KDialog::User1); 0033 g_jsConsoleWindow->setButtonGuiItem(KDialog::User1, KStandardGuiItem::clear()); 0034 0035 QVBoxLayout *mainLay = new QVBoxLayout(g_jsConsoleWindow->mainWidget()); 0036 mainLay->setContentsMargins(0, 0, 0, 0); 0037 g_jsConsoleLog = new QPlainTextEdit(g_jsConsoleWindow->mainWidget()); 0038 g_jsConsoleLog->setReadOnly(true); 0039 mainLay->addWidget(g_jsConsoleLog); 0040 0041 QObject::connect(g_jsConsoleWindow, SIGNAL(closeClicked()), g_jsConsoleWindow, SLOT(close())); 0042 QObject::connect(g_jsConsoleWindow, SIGNAL(user1Clicked()), g_jsConsoleLog, SLOT(clear())); 0043 } 0044 #endif 0045 0046 void JSConsole::show() 0047 { 0048 #ifdef OKULAR_JS_CONSOLE 0049 createConsoleWindow(); 0050 g_jsConsoleWindow->show(); 0051 #endif 0052 } 0053 0054 void JSConsole::hide() 0055 { 0056 #ifdef OKULAR_JS_CONSOLE 0057 if (!g_jsConsoleWindow.exists()) 0058 return; 0059 0060 g_jsConsoleWindow->hide(); 0061 #endif 0062 } 0063 0064 void JSConsole::clear() 0065 { 0066 #ifdef OKULAR_JS_CONSOLE 0067 if (!g_jsConsoleWindow.exists()) 0068 return; 0069 0070 g_jsConsoleLog->clear(); 0071 #endif 0072 } 0073 0074 void JSConsole::println(const QString &cMessage) 0075 { 0076 #ifdef OKULAR_JS_CONSOLE 0077 showConsole(); 0078 g_jsConsoleLog->appendPlainText(cMessage); 0079 #else 0080 Q_UNUSED(cMessage); 0081 #endif 0082 }