summaryrefslogtreecommitdiffstats
path: root/src/gui/logview.cpp
blob: a1580497b8584409a7a2b4072cacf68ca642f330 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/***************************************************************************
 *   Copyright (C) 2003-2005 by David Saxton                               *
 *   david@bluehaze.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 "logview.h"

#include <kdebug.h>
#include <kiconloader.h>
#include <katemdi.h>
#include <klocale.h>
#include <tqpopupmenu.h>


//BEGIN class LogView
LogView::LogView( KateMDI::ToolView * tqparent, const char *name )
	: KTextEdit( tqparent, name )
{
	setReadOnly(true);
	setPaper( TQt::white );
	setTextFormat( LogText );
	setWordWrap( WidgetWidth );
	
	// Connect up signal emitted when the user doubleclicks on a paragraph in the log view
	connect( this, TQT_SIGNAL(clicked(int,int)), this, TQT_SLOT(slotParaClicked(int,int)) );
}


LogView::~LogView()
{
}


void LogView::clear()
{
	m_messageInfoMap.clear();
	KTextEdit::clear();
}


void LogView::addOutput( TQString text, OutputType outputType, MessageInfo messageInfo )
{
	tidyText(text);
	switch(outputType)
	{
		case LogView::ot_important:
			append( TQString("<font color=\"#000000\"><b>%1</b></font>").tqarg(text) );
			break;
			
		case LogView::ot_info:
			append( TQString("<font color=\"#000000\"><i>%1</i></font>").tqarg(text) );
			break;
			
		case LogView::ot_message:
			append( TQString("<font color=\"#000000\">%1</font>").tqarg(text) );
			break;
			
		case LogView::ot_warning:
			append( TQString("<font color=\"#666666\">%1</font>").tqarg(text) );
			break;
			
		case LogView::ot_error:
			append( TQString("<font color=\"#800000\">%1</font>").tqarg(text) );
			break;
	}
	
	m_messageInfoMap[ paragraphs()-1 ] = messageInfo;
}


void LogView::slotParaClicked( int para, int /*pos*/ )
{
	TQString t = text(para);
	untidyText(t);
	emit paraClicked( t, m_messageInfoMap[para] );
}


void LogView::tidyText( TQString &t )
{
	t.replace( "&", "&amp;" );
	t.replace( "<", "&lt;" );
	t.replace( ">", "&gt;" );
}


void LogView::untidyText( TQString &t )
{
	t.replace( "&lt;", "<" );
	t.replace( "&gt;", ">" );
	t.replace( "&amp;", "&" );
}


TQPopupMenu * LogView::createPopupMenu( const TQPoint & pos )
{
	TQPopupMenu * menu = KTextEdit::createPopupMenu( pos );
	
	menu->insertSeparator();
	int id = menu->insertItem( i18n("Clear All"), this, TQT_SLOT(clear()) );
	
	// "an empty textedit is always considered to have one paragraph" - qt documentation
	// although this does not always seem to be the case, so I don't know...
	menu->setItemEnabled( id, paragraphs() > 1 );
	
	return menu;
}
//END class LogView



//BEGIN class MessageInfo
MessageInfo::MessageInfo()
{
	m_fileLine = -1;
}


MessageInfo::MessageInfo( TQString fileURL, int fileLine )
{
	m_fileURL = fileURL;
	m_fileLine = fileLine;
}
//END class MessageInfo


#include "logview.moc"