summaryrefslogtreecommitdiffstats
path: root/kdevdesigner/designer/outputwindow.cpp
blob: 33113ef5faa518e7341db42bdc1fc747817b6ddd (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/**********************************************************************
** Copyright (C) 2001-2002 Trolltech AS.  All rights reserved.
**
** This file is part of TQt Designer.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition
** licenses may use this file in accordance with the TQt Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
**   information about TQt Commercial License Agreements.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/

#include "outputwindow.h"
#include "designerappiface.h"
#include "metadatabase.h"
#include "mainwindow.h"

#include <tqlistview.h>
#include <tqtextedit.h>
#include <tqapplication.h>
#include <tqheader.h>
#include <stdlib.h>
#include <stdio.h>
#include <tqpainter.h>

#include <klocale.h>

static TQTextEdit *debugoutput = 0;
bool debugToStderr = FALSE;

TQtMsgHandler OutputWindow::oldMsgHandler = 0;

OutputWindow::OutputWindow( TQWidget *parent )
    : TQTabWidget( parent, "output_window" ), debugView( 0 ), errorView( 0 )
{
    setupDebug();
    setupError();
    iface = new DesignerOutputDockImpl( this );
}

OutputWindow::~OutputWindow()
{
    debugoutput = debugView = 0;
    errorView = 0;
    if ( !debugToStderr )
	tqInstallMsgHandler( oldMsgHandler );
    delete iface;
}

void OutputWindow::shuttingDown()
{
    if ( !debugToStderr )
	tqInstallMsgHandler( oldMsgHandler );
}

void OutputWindow::setupError()
{
    errorView = new TQListView( this, "OutputWindow::errorView" );
    errorView->setSorting( -1 );
    connect( errorView, TQT_SIGNAL( currentChanged( TQListViewItem* ) ),
	     this, TQT_SLOT( currentErrorChanged( TQListViewItem* ) ) );
    connect( errorView, TQT_SIGNAL( clicked( TQListViewItem* ) ),
	     this, TQT_SLOT( currentErrorChanged( TQListViewItem* ) ) );

    if ( MetaDataBase::languages().count() > 1 )
	addTab( errorView, i18n( "Warnings/Errors" ) );
    else
	errorView->hide();
    errorView->addColumn( i18n( "Type" ) );
    errorView->addColumn( i18n( "Message" ) );
    errorView->addColumn( i18n( "Line" ) );
    errorView->addColumn( i18n( "Location" ) );
    errorView->setResizeMode( TQListView::LastColumn );
    errorView->setColumnWidth( 0, errorView->fontMetrics().width( "WARNING1234" ) );
    errorView->setColumnWidth( 1, errorView->fontMetrics().width( "ABCDEFGHIJKLMNOPTQRSTUVWXYZABCDEFGHIJKLMNOPTQRSTUVWXYZABCDEFGHIJKLMNOP" ) );
    errorView->setColumnWidth( 2, errorView->fontMetrics().width( "9999999" ) );
    errorView->setColumnAlignment( 2, TQt::AlignRight );
    errorView->setAllColumnsShowFocus( TRUE );
}

static void debugMessageOutput( TQtMsgType type, const char *msg )
{
    TQString s( msg );
    s += "\n";

    if ( type != TQtFatalMsg ) {
	if ( debugoutput && debugoutput->isVisible() )
	    debugoutput->append( s );
	else if ( OutputWindow::oldMsgHandler && OutputWindow::oldMsgHandler != debugMessageOutput )
	    (*OutputWindow::oldMsgHandler)( type, msg );
	else
	    fputs( s.latin1(), stderr );
    } else {
	fputs( s.latin1(), stderr );
	abort();
    }

    tqApp->flush();
}

void OutputWindow::setupDebug()
{
    debugoutput = debugView = new TQTextEdit( this, "OutputWindow::debugView" );
    //debugView->setReadOnly( TRUE );
    addTab( debugView, "Debug Output" );

    if ( !debugToStderr )
	oldMsgHandler = tqInstallMsgHandler( debugMessageOutput );
}

void OutputWindow::setErrorMessages( const TQStringList &errors, const TQValueList<uint> &lines,
				     bool clear, const TQStringList &locations,
				     const TQObjectList &locationObjects )
{
    if ( clear )
	errorView->clear();
    TQStringList::ConstIterator mit = errors.begin();
    TQValueList<uint>::ConstIterator lit = lines.begin();
    TQStringList::ConstIterator it = locations.begin();
    TQObjectList objects = (TQObjectList)locationObjects;
    TQObject *o = objects.first();
    TQListViewItem *after = 0;
    for ( ; lit != lines.end() && mit != errors.end(); ++lit, ++mit, ++it, o = objects.next() )
	after = new ErrorItem( errorView, after, *mit, *lit, *it, o );
    setCurrentPage( 1 );
}

DesignerOutputDock *OutputWindow::iFace()
{
    return iface;
}

void OutputWindow::appendDebug( const TQString &text )
{
    debugView->append( text + "\n" );
}

void OutputWindow::clearErrorMessages()
{
    errorView->clear();
}

void OutputWindow::clearDebug()
{
    debugView->clear();
}

void OutputWindow::showDebugTab()
{
    showPage( debugView );
}

void OutputWindow::currentErrorChanged( TQListViewItem *i )
{
    if ( !i )
	return;
    ErrorItem *ei = (ErrorItem*)i;
    ei->setRead( TRUE );
    MainWindow::self->showSourceLine( ei->location(), ei->line() - 1, MainWindow::Error );
}



ErrorItem::ErrorItem( TQListView *parent, TQListViewItem *after, const TQString &message, int line,
		      const TQString &locationString, TQObject *locationObject )
    : TQListViewItem( parent, after )
{
    setMultiLinesEnabled( TRUE );
    TQString m( message );
    type = m.startsWith( "Warning: " ) ? Warning : Error;
    m = m.mid( m.find( ':' ) + 1 );
    setText( 0, type == Error ? "Error" : "Warning" );
    setText( 1, m );
    setText( 2, TQString::number( line ) );
    setText( 3, locationString );
    object = locationObject;
    read = !after;
    if ( !after ) {
	parent->setSelected( this, TRUE );
	parent->setCurrentItem( this );
    }
}

void ErrorItem::paintCell( TQPainter *p, const TQColorGroup & cg,
			   int column, int width, int tqalignment )
{
    TQColorGroup g( cg );
    g.setColor( TQColorGroup::Text, type == Error ? TQt::red : TQt::darkYellow );
    if ( !read ) {
	TQFont f( p->font() );
	f.setBold( TRUE );
	p->setFont( f );
    }
    TQListViewItem::paintCell( p, g, column, width, tqalignment );
}