diff --git a/plugins/dockers/logdocker/LogDocker.cpp b/plugins/dockers/logdocker/LogDocker.cpp index 577c2fce18..e65a9e4a3d 100644 --- a/plugins/dockers/logdocker/LogDocker.cpp +++ b/plugins/dockers/logdocker/LogDocker.cpp @@ -1,80 +1,80 @@ /* * Copyright (c) 2018 Boudewijn Rempt * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "LogDocker.h" #include #include #include #include #include "LogDockerDock.h" K_PLUGIN_FACTORY_WITH_JSON(LogDockerPluginFactory, "krita_logdocker.json", registerPlugin();) class LogDockerDockFactory : public KoDockFactoryBase { public: LogDockerDockFactory() { } virtual ~LogDockerDockFactory() { } QString id() const override { return QString( "LogDocker" ); } virtual Qt::DockWidgetArea defaultDockWidgetArea() const { return Qt::RightDockWidgetArea; } QDockWidget* createDockWidget() override { - LogDockerDock * dockWidget = new LogDockerDock(); + LogDockerDock * dockWidget = new LogDockerDock(); dockWidget->setObjectName(id()); return dockWidget; } DockPosition defaultDockPosition() const override { return DockMinimized; } private: }; LogDockerPlugin::LogDockerPlugin(QObject *parent, const QVariantList &) : QObject(parent) { KoDockRegistry::instance()->add(new LogDockerDockFactory()); } LogDockerPlugin::~LogDockerPlugin() { } #include "LogDocker.moc" diff --git a/plugins/dockers/logdocker/LogDockerDock.cpp b/plugins/dockers/logdocker/LogDockerDock.cpp index 9052878cad..8444883c32 100644 --- a/plugins/dockers/logdocker/LogDockerDock.cpp +++ b/plugins/dockers/logdocker/LogDockerDock.cpp @@ -1,51 +1,166 @@ /* * Copyright (c) 2018 Boudewijn Rempt * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "LogDockerDock.h" #include #include +#include +#include +#include +#include #include +#include #include +#include +#include #include "kis_canvas2.h" #include "KisViewManager.h" +#include "kis_config.h" -#include +QTextEdit *LogDockerDock::s_textEdit {0}; +QTextCharFormat LogDockerDock::s_debug; +QTextCharFormat LogDockerDock::s_info; +QTextCharFormat LogDockerDock::s_warning; +QTextCharFormat LogDockerDock::s_critical; +QTextCharFormat LogDockerDock::s_fatal; LogDockerDock::LogDockerDock( ) : QDockWidget(i18n("Log Viewer")) { QWidget *page = new QWidget(this); setupUi(page); + setWidget(page); + + s_textEdit = txtLogViewer; + bnToggle->setIcon(koIcon("view-list-text")); + connect(bnToggle, SIGNAL(clicked(bool)), SLOT(toggleLogging(bool))); + bnToggle->setChecked(KisConfig().readEntry("logviewer_enabled", false)); + toggleLogging(KisConfig().readEntry("logviewer_enabled", false)); + bnClear->setIcon(koIcon("edit-clear")); - bnSave->setIcon(koIcon("filesave")); + connect(bnClear, SIGNAL(clicked(bool)), SLOT(clearLog())); + + bnSave->setIcon(koIcon("document-save")); + connect(bnSave, SIGNAL(clicked(bool)), SLOT(saveLog())); + bnSettings->setIcon(koIcon("settings")); + connect(bnSettings, SIGNAL(clicked(bool)), SLOT(settings())); + + s_debug.setForeground(Qt::white); + s_info.setForeground(Qt::yellow); + s_warning.setForeground(QColor(255, 80, 0)); + s_critical.setForeground(Qt::red); + s_fatal.setForeground(Qt::red); + s_fatal.setFontWeight(QFont::Bold); } void LogDockerDock::setCanvas(KoCanvasBase *canvas) { Q_UNUSED(canvas); setEnabled(true); } +void LogDockerDock::toggleLogging(bool toggle) +{ + KisConfig().writeEntry("logviewer_enabled", toggle); + if (toggle) { + qInstallMessageHandler(messageHandler); + } + else { + qInstallMessageHandler(0); + } + +} + +void LogDockerDock::clearLog() +{ + txtLogViewer->document()->clear(); +} + +void LogDockerDock::saveLog() +{ + KoFileDialog fileDialog(this, KoFileDialog::SaveFile, "logfile"); + fileDialog.setDefaultDir(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/" + QString("krita_%1.log").arg(QDateTime::currentDateTime().toString())); + QString filename = fileDialog.filename(); + if (!filename.isEmpty()) { + QFile f(filename); + f.open(QFile::WriteOnly); + f.write(txtLogViewer->document()->toPlainText().toUtf8()); + f.close(); + } +} + +void LogDockerDock::settings() +{ + KoDialog dlg(this); + dlg.setButtons(KoDialog::Ok | KoDialog::Cancel); + dlg.setCaption(i18n("Log Settings")); + + QTableWidget *page = new QTableWidget(18, 6, &dlg); + dlg.setMainWidget(page); + + page->setHorizontalHeaderItem(0, new QTableWidgetItem(i18n("Category"))); + page->setHorizontalHeaderItem(1, new QTableWidgetItem(i18n("Debug"))); + page->setHorizontalHeaderItem(2, new QTableWidgetItem(i18n("Info"))); + page->setHorizontalHeaderItem(3, new QTableWidgetItem(i18n("Warning"))); + page->setHorizontalHeaderItem(4, new QTableWidgetItem(i18n("Critical"))); + page->setHorizontalHeaderItem(4, new QTableWidgetItem(i18n("Fatal"))); + + if (dlg.exec()) { + // Apply the new settings + } + +} + +void LogDockerDock::messageHandler(QtMsgType type, const QMessageLogContext &/*context*/, const QString &msg) +{ + QTextDocument *doc = s_textEdit->document(); + QTextCursor cursor(doc); + cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor); + cursor.beginEditBlock(); + + QByteArray localMsg = msg.toLocal8Bit(); + switch (type) { + case QtDebugMsg: + cursor.insertText(msg + "\n", s_debug); + break; + case QtInfoMsg: + cursor.insertText(msg + "\n", s_info); + break; + case QtWarningMsg: + cursor.insertText(msg + "\n", s_warning); + break; + case QtCriticalMsg: + cursor.insertText(msg + "\n", s_critical); + break; + case QtFatalMsg: + cursor.insertText(msg + "\n", s_fatal); + break; + } + + cursor.endEditBlock(); + s_textEdit->verticalScrollBar()->setValue(s_textEdit->verticalScrollBar()->maximum()); +} + diff --git a/plugins/dockers/logdocker/LogDockerDock.h b/plugins/dockers/logdocker/LogDockerDock.h index ef848acf57..fe5c663d13 100644 --- a/plugins/dockers/logdocker/LogDockerDock.h +++ b/plugins/dockers/logdocker/LogDockerDock.h @@ -1,40 +1,54 @@ /* * Copyright (c) 2018 Boudewijn Rempt * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _LOGDOCKER_DOCK_H_ #define _LOGDOCKER_DOCK_H_ #include #include #include "ui_WdgLogDocker.h" class LogDockerDock : public QDockWidget, public KoCanvasObserverBase, public Ui_WdgLogDocker { Q_OBJECT public: LogDockerDock( ); QString observerName() override { return "LogDockerDock"; } void setCanvas(KoCanvasBase *canvas) override; void unsetCanvas() override {} private Q_SLOTS: + + void toggleLogging(bool toggle); + void clearLog(); + void saveLog(); + void settings(); + private: + static QTextEdit *s_textEdit; + static QTextCharFormat s_debug; + static QTextCharFormat s_info; + static QTextCharFormat s_warning; + static QTextCharFormat s_critical; + static QTextCharFormat s_fatal; + static void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg); + }; #endif diff --git a/plugins/dockers/logdocker/WdgLogDocker.ui b/plugins/dockers/logdocker/WdgLogDocker.ui index db1a042c4a..defa50ab39 100644 --- a/plugins/dockers/logdocker/WdgLogDocker.ui +++ b/plugins/dockers/logdocker/WdgLogDocker.ui @@ -1,87 +1,104 @@ WdgLogDocker 0 0 400 260 Form - + + + false + + + QTextEdit::NoWrap + + + true + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Droid Sans'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + - false + true Enable Logging ... true Clear the log ... Save the log ... Qt::Horizontal 40 20 Configure Logging ...