summaryrefslogtreecommitdiffstats
path: root/src/libgui/log_view.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 18:42:24 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 18:42:24 +0000
commitf508189682b6fba62e08feeb1596f682bad5fff9 (patch)
tree28aeb0e6c19386c385c1ce5edf8a92c1bca15281 /src/libgui/log_view.cpp
downloadpiklab-f508189682b6fba62e08feeb1596f682bad5fff9.tar.gz
piklab-f508189682b6fba62e08feeb1596f682bad5fff9.zip
Added KDE3 version of PikLab
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/piklab@1095639 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/libgui/log_view.cpp')
-rw-r--r--src/libgui/log_view.cpp135
1 files changed, 135 insertions, 0 deletions
diff --git a/src/libgui/log_view.cpp b/src/libgui/log_view.cpp
new file mode 100644
index 0000000..158c281
--- /dev/null
+++ b/src/libgui/log_view.cpp
@@ -0,0 +1,135 @@
+/***************************************************************************
+ * Copyright (C) 2005 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "log_view.h"
+
+#include <qpopupmenu.h>
+#include <qeventloop.h>
+#include <qapplication.h>
+#include <kiconloader.h>
+
+#include "global_config.h"
+#include "common/gui/purl_gui.h"
+#include "common/gui/misc_gui.h"
+
+Log::Widget::Widget(QWidget *parent, const char *name)
+ : QTextEdit(parent, name)
+{
+ setTextFormat(LogText);
+ setMinimumWidth(300);
+}
+
+void Log::Widget::updateDebugLevel()
+{
+ setDebugLevel(GlobalConfig::debugLevel());
+}
+
+void Log::Widget::logExtra(const QString &text)
+{
+ _text += text;
+ if ( GlobalConfig::logOutputType()==GuiConsole ) fprintf(stdout, "%s", text.latin1());
+}
+
+void Log::Widget::doLog(LineType type, const QString &text, Action action)
+{
+ doLog(text, type.data().color, type.data().bold, action);
+}
+
+void Log::Widget::doLog(DebugLevel level, const QString &text, Action action)
+{
+ doLog(text, level.data().color, false, action);
+}
+
+void Log::Widget::doLog(const QString &text, const QString &color, bool bold, Action action)
+{
+ logExtra(text + "\n");
+ QString s = QString("<font color=%1>").arg(color);
+ if (bold) s += "<b>";
+ s += escapeXml(text);
+ if (bold) s += "</b>";
+ s += "</font>";
+ QTextEdit::append(s);
+ updateContents(); // #### fix bug in Qt (display is messed up)
+ ensureVisible(0, contentsHeight());
+ if ( action==Immediate)
+ QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
+}
+
+void Log::Widget::appendToLastLine(const QString &text)
+{
+ logExtra(text);
+ uint p = paragraphs() - 1;
+ insertAt(escapeXml(text), p, paragraphLength(p));
+ updateContents(); // #### fix bug in Qt (display is messed up)
+ ensureVisible(0, contentsHeight());
+ // immediately visible...
+ QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
+}
+
+QPopupMenu *Log::Widget::createPopupMenu(const QPoint &pos)
+{
+ updateDebugLevel();
+ _popup = QTextEdit::createPopupMenu(pos);
+ KIconLoader loader;
+ QIconSet iset = loader.loadIconSet("filesave", KIcon::Small, 0);
+ _popup->insertItem(iset, "Save As...", this, SLOT(saveAs()));
+ iset = loader.loadIconSet("fileclose", KIcon::Small, 0);
+ _popup->insertItem(iset, "Clear", this, SLOT(clear()));
+ _popup->insertSeparator();
+ FOR_EACH(DebugLevel, level) {
+ _id[level.type()] = _popup->insertItem(level.label());
+ _popup->setItemChecked(_id[level.type()], _debugLevel==level);
+ }
+ _popup->insertSeparator();
+ int id = _popup->insertItem(i18n("Output in console"), this, SLOT(toggleConsoleOutput()));
+ _popup->setItemChecked(id, GlobalConfig::logOutputType()==GuiConsole);
+ connect(_popup, SIGNAL(activated(int)), SLOT(toggleVisible(int)));
+ return _popup;
+}
+
+void Log::Widget::toggleVisible(int id)
+{
+ FOR_EACH(DebugLevel, level) {
+ if ( _id[level.type()]==id ) {
+ _debugLevel = level;
+ GlobalConfig::writeDebugLevel(level);
+ break;
+ }
+ }
+}
+
+void Log::Widget::toggleConsoleOutput()
+{
+ GlobalConfig::writeLogOutputType(GlobalConfig::logOutputType()==GuiOnly ? GuiConsole : GuiOnly);
+}
+
+void Log::Widget::sorry(const QString &message, const QString &details)
+{
+ logExtra(message + " [" + details + "]\n");
+ MessageBox::detailedSorry(message, details, Log::Show);
+}
+
+bool Log::Widget::askContinue(const QString &message)
+{
+ bool ok = MessageBox::askContinue(message);
+ logExtra(message + " [" + (ok ? "continue" : "cancel") + "]\n");
+ return ok;
+}
+
+void Log::Widget::clear()
+{
+ QTextEdit::clear();
+ _text = QString::null;
+}
+
+void Log::Widget::saveAs()
+{
+ PURL::Url url = PURL::getSaveUrl(":save_log", "text/x-log", this, i18n("Save log to file"), PURL::AskOverwrite);
+ if ( url.isEmpty() ) return;
+ url.write(_text, *this);
+}