File indexing completed on 2024-03-24 17:24:30

0001 /**
0002  * SPDX-FileCopyrightText: (C) 2003 by Sébastien Laoût <slaout@linux62.org>
0003  * SPDX-License-Identifier: GPL-2.0-or-later
0004  */
0005 
0006 #include "debugwindow.h"
0007 
0008 #include <QVBoxLayout>
0009 #include <QtCore/QString>
0010 #include <QtGui/QCloseEvent>
0011 
0012 #include <QLocale>
0013 #include <QTextBrowser>
0014 
0015 #include <KLocalizedString>
0016 
0017 #include "global.h"
0018 
0019 DebugWindow::DebugWindow(QWidget *parent)
0020     : QWidget(parent)
0021 {
0022     Global::debugWindow = this;
0023     setWindowTitle(i18n("Debug Window"));
0024 
0025     layout = new QVBoxLayout(this);
0026     textBrowser = new QTextBrowser(this);
0027 
0028     textBrowser->setWordWrapMode(QTextOption::NoWrap);
0029 
0030     layout->addWidget(textBrowser);
0031     textBrowser->show();
0032 }
0033 
0034 DebugWindow::~DebugWindow()
0035 {
0036     delete textBrowser;
0037     delete layout;
0038 }
0039 
0040 void DebugWindow::postMessage(const QString msg)
0041 {
0042     textBrowser->append(msg);
0043 }
0044 
0045 DebugWindow &DebugWindow::operator<<(const QString msg)
0046 {
0047     // This can be used from a different thread
0048     QMetaObject::invokeMethod(this, "postMessage", Qt::QueuedConnection, Q_ARG(QString, msg));
0049     return *this;
0050 }
0051 
0052 void DebugWindow::insertHLine()
0053 {
0054     textBrowser->append("<hr>");
0055 }
0056 
0057 void DebugWindow::closeEvent(QCloseEvent *event)
0058 {
0059     Global::debugWindow = nullptr;
0060     QWidget::closeEvent(event);
0061 }
0062 
0063 #include "moc_debugwindow.cpp"