Okular

js_console.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Pino Toscano <pino@kde.org>
3 SPDX-FileCopyrightText: 2008 Harri Porten <porten@kde.org>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6*/
7
8#include "js_console_p.h"
9
10#include <QDebug>
11
12#include "../debug_p.h"
13
14using namespace Okular;
15
16#ifdef OKULAR_JS_CONSOLE
17
18#include <QLayout>
19#include <QPlainTextEdit>
20
21#include <KDialog>
22#include <KStandardGuiItem>
23
24K_GLOBAL_STATIC(KDialog, g_jsConsoleWindow)
25static QPlainTextEdit *g_jsConsoleLog = 0;
26
27static void createConsoleWindow()
28{
29 if (g_jsConsoleWindow.exists())
30 return;
31
32 g_jsConsoleWindow->setButtons(KDialog::Close | KDialog::User1);
33 g_jsConsoleWindow->setButtonGuiItem(KDialog::User1, KStandardGuiItem::clear());
34
35 QVBoxLayout *mainLay = new QVBoxLayout(g_jsConsoleWindow->mainWidget());
36 mainLay->setContentsMargins(0, 0, 0, 0);
37 g_jsConsoleLog = new QPlainTextEdit(g_jsConsoleWindow->mainWidget());
38 g_jsConsoleLog->setReadOnly(true);
39 mainLay->addWidget(g_jsConsoleLog);
40
41 QObject::connect(g_jsConsoleWindow, SIGNAL(closeClicked()), g_jsConsoleWindow, SLOT(close()));
42 QObject::connect(g_jsConsoleWindow, SIGNAL(user1Clicked()), g_jsConsoleLog, SLOT(clear()));
43}
44#endif
45
46void JSConsole::show()
47{
48#ifdef OKULAR_JS_CONSOLE
49 createConsoleWindow();
50 g_jsConsoleWindow->show();
51#endif
52}
53
54void JSConsole::hide()
55{
56#ifdef OKULAR_JS_CONSOLE
57 if (!g_jsConsoleWindow.exists())
58 return;
59
60 g_jsConsoleWindow->hide();
61#endif
62}
63
64void JSConsole::clear()
65{
66#ifdef OKULAR_JS_CONSOLE
67 if (!g_jsConsoleWindow.exists())
68 return;
69
70 g_jsConsoleLog->clear();
71#endif
72}
73
74void JSConsole::println(const QString &cMessage)
75{
76#ifdef OKULAR_JS_CONSOLE
77 showConsole();
78 g_jsConsoleLog->appendPlainText(cMessage);
79#else
80 Q_UNUSED(cMessage);
81#endif
82}
KGuiItem clear()
KGuiItem close()
global.h
Definition action.h:17
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void setContentsMargins(const QMargins &margins)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void appendPlainText(const QString &text)
void setReadOnly(bool ro)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 11:49:40 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.