File indexing completed on 2024-12-22 04:17:35

0001 /***************************************************************************
0002  *                                                                         *
0003  *   copyright : (C) 2007 The University of Toronto                        *
0004  *                   netterfield@astro.utoronto.ca                         *
0005  *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  ***************************************************************************/
0012 
0013 #include "logwidget.h"
0014 #include <debug.h>
0015 #include <events.h>
0016 #include <logevents.h>
0017 
0018 
0019 
0020 #include <QDebug>
0021 
0022 namespace Kst {
0023 
0024 
0025 LogWidget::LogWidget(QWidget *parent)
0026   : QTextBrowser(parent) {
0027   _show = Debug::Warning | Debug::Error | Debug::Notice | Debug::Trace;
0028 }
0029 
0030 
0031 LogWidget::~LogWidget() {
0032 }
0033 
0034 
0035 void LogWidget::logAdded(const Debug::LogMessage& msg) {
0036   QString sym;
0037   switch (msg.level) {
0038     case Debug::Warning:
0039       sym = "<img src=\"DebugWarning\"/> ";
0040       break;
0041     case Debug::Error:
0042       sym = "<img src=\"DebugError\"/> ";
0043       break;
0044     case Debug::Notice:
0045       sym = "<img src=\"DebugNotice\"/> ";
0046       break;
0047     case Debug::Trace:
0048         sym = "<img src=\"DebugTrace\"/> ";
0049         break;
0050     default:
0051       return;
0052   }
0053 
0054   if ((_show & int(msg.level)) == 0) {
0055     return;
0056   }
0057 
0058   append(QString("%1<b>%2</b> %3").arg(sym).arg(msg.date.toString()).arg(msg.msg));
0059 }
0060 
0061 
0062 void LogWidget::setShowLevel(Debug::LogLevel level, bool show) {
0063   const int old = _show;
0064   if (show) {
0065     _show |= level;
0066   } else {
0067     _show &= ~level;
0068   }
0069   if (_show != old) {
0070     regenerate();
0071   }
0072 }
0073 
0074 
0075 void LogWidget::setShowError(bool show) {
0076   setShowLevel(Debug::Error, show);
0077 }
0078 
0079 
0080 void LogWidget::setShowWarning(bool show) {
0081   setShowLevel(Debug::Warning, show);
0082 }
0083 
0084 
0085 void LogWidget::setShowNotice(bool show) {
0086   setShowLevel(Debug::Notice, show);
0087 }
0088 
0089 
0090 void LogWidget::setShowTrace(bool show) {
0091   setShowLevel(Debug::Trace, show);
0092 }
0093 
0094 void LogWidget::regenerate() {
0095   clear();
0096   const QList<Debug::LogMessage> messages = Debug::self()->messages();
0097   foreach(const Debug::LogMessage& message, messages) {
0098     logAdded(message);
0099   }
0100 }
0101 
0102 }
0103 
0104 // vim: ts=2 sw=2 et