You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
210 lines
6.2 KiB
210 lines
6.2 KiB
15 years ago
|
/**********************************************************************
|
||
|
** Copyright (C) 2001-2002 Trolltech AS. All rights reserved.
|
||
|
**
|
||
14 years ago
|
** This file is part of TQt Designer.
|
||
15 years ago
|
**
|
||
|
** 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.
|
||
|
**
|
||
14 years ago
|
** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition
|
||
|
** licenses may use this file in accordance with the TQt Commercial License
|
||
15 years ago
|
** 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
|
||
14 years ago
|
** information about TQt Commercial License Agreements.
|
||
15 years ago
|
**
|
||
|
** 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"
|
||
|
|
||
15 years ago
|
#include <tqlistview.h>
|
||
13 years ago
|
#include <tqtextedit.h>
|
||
15 years ago
|
#include <tqapplication.h>
|
||
|
#include <tqheader.h>
|
||
15 years ago
|
#include <stdlib.h>
|
||
|
#include <stdio.h>
|
||
15 years ago
|
#include <tqpainter.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
|
||
15 years ago
|
static TQTextEdit *debugoutput = 0;
|
||
15 years ago
|
bool debugToStderr = FALSE;
|
||
|
|
||
14 years ago
|
TQtMsgHandler OutputWindow::oldMsgHandler = 0;
|
||
15 years ago
|
|
||
14 years ago
|
OutputWindow::OutputWindow( TQWidget *parent )
|
||
|
: TQTabWidget( parent, "output_window" ), debugView( 0 ), errorView( 0 )
|
||
15 years ago
|
{
|
||
|
setupDebug();
|
||
|
setupError();
|
||
|
iface = new DesignerOutputDockImpl( this );
|
||
|
}
|
||
|
|
||
|
OutputWindow::~OutputWindow()
|
||
|
{
|
||
|
debugoutput = debugView = 0;
|
||
|
errorView = 0;
|
||
|
if ( !debugToStderr )
|
||
14 years ago
|
tqInstallMsgHandler( oldMsgHandler );
|
||
15 years ago
|
delete iface;
|
||
|
}
|
||
|
|
||
|
void OutputWindow::shuttingDown()
|
||
|
{
|
||
|
if ( !debugToStderr )
|
||
14 years ago
|
tqInstallMsgHandler( oldMsgHandler );
|
||
15 years ago
|
}
|
||
|
|
||
|
void OutputWindow::setupError()
|
||
|
{
|
||
15 years ago
|
errorView = new TQListView( this, "OutputWindow::errorView" );
|
||
15 years ago
|
errorView->setSorting( -1 );
|
||
15 years ago
|
connect( errorView, TQT_SIGNAL( currentChanged( TQListViewItem* ) ),
|
||
|
this, TQT_SLOT( currentErrorChanged( TQListViewItem* ) ) );
|
||
|
connect( errorView, TQT_SIGNAL( clicked( TQListViewItem* ) ),
|
||
|
this, TQT_SLOT( currentErrorChanged( TQListViewItem* ) ) );
|
||
15 years ago
|
|
||
|
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" ) );
|
||
15 years ago
|
errorView->setResizeMode( TQListView::LastColumn );
|
||
15 years ago
|
errorView->setColumnWidth( 0, errorView->fontMetrics().width( "WARNING1234" ) );
|
||
13 years ago
|
errorView->setColumnWidth( 1, errorView->fontMetrics().width( "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOP" ) );
|
||
15 years ago
|
errorView->setColumnWidth( 2, errorView->fontMetrics().width( "9999999" ) );
|
||
14 years ago
|
errorView->setColumnAlignment( 2, TQt::AlignRight );
|
||
15 years ago
|
errorView->setAllColumnsShowFocus( TRUE );
|
||
|
}
|
||
|
|
||
14 years ago
|
static void debugMessageOutput( TQtMsgType type, const char *msg )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString s( msg );
|
||
15 years ago
|
s += "\n";
|
||
|
|
||
13 years ago
|
if ( type != TQtFatalMsg ) {
|
||
15 years ago
|
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();
|
||
|
}
|
||
|
|
||
14 years ago
|
tqApp->flush();
|
||
15 years ago
|
}
|
||
|
|
||
|
void OutputWindow::setupDebug()
|
||
|
{
|
||
15 years ago
|
debugoutput = debugView = new TQTextEdit( this, "OutputWindow::debugView" );
|
||
15 years ago
|
//debugView->setReadOnly( TRUE );
|
||
|
addTab( debugView, "Debug Output" );
|
||
|
|
||
|
if ( !debugToStderr )
|
||
14 years ago
|
oldMsgHandler = tqInstallMsgHandler( debugMessageOutput );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void OutputWindow::setErrorMessages( const TQStringList &errors, const TQValueList<uint> &lines,
|
||
|
bool clear, const TQStringList &locations,
|
||
|
const TQObjectList &locationObjects )
|
||
15 years ago
|
{
|
||
|
if ( clear )
|
||
|
errorView->clear();
|
||
15 years ago
|
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;
|
||
15 years ago
|
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;
|
||
|
}
|
||
|
|
||
15 years ago
|
void OutputWindow::appendDebug( const TQString &text )
|
||
15 years ago
|
{
|
||
|
debugView->append( text + "\n" );
|
||
|
}
|
||
|
|
||
|
void OutputWindow::clearErrorMessages()
|
||
|
{
|
||
|
errorView->clear();
|
||
|
}
|
||
|
|
||
|
void OutputWindow::clearDebug()
|
||
|
{
|
||
|
debugView->clear();
|
||
|
}
|
||
|
|
||
|
void OutputWindow::showDebugTab()
|
||
|
{
|
||
|
showPage( debugView );
|
||
|
}
|
||
|
|
||
15 years ago
|
void OutputWindow::currentErrorChanged( TQListViewItem *i )
|
||
15 years ago
|
{
|
||
|
if ( !i )
|
||
|
return;
|
||
|
ErrorItem *ei = (ErrorItem*)i;
|
||
|
ei->setRead( TRUE );
|
||
|
MainWindow::self->showSourceLine( ei->location(), ei->line() - 1, MainWindow::Error );
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
14 years ago
|
ErrorItem::ErrorItem( TQListView *parent, TQListViewItem *after, const TQString &message, int line,
|
||
15 years ago
|
const TQString &locationString, TQObject *locationObject )
|
||
14 years ago
|
: TQListViewItem( parent, after )
|
||
15 years ago
|
{
|
||
|
setMultiLinesEnabled( TRUE );
|
||
15 years ago
|
TQString m( message );
|
||
15 years ago
|
type = m.startsWith( "Warning: " ) ? Warning : Error;
|
||
14 years ago
|
m = m.mid( m.find( ':' ) + 1 );
|
||
15 years ago
|
setText( 0, type == Error ? "Error" : "Warning" );
|
||
|
setText( 1, m );
|
||
15 years ago
|
setText( 2, TQString::number( line ) );
|
||
15 years ago
|
setText( 3, locationString );
|
||
|
object = locationObject;
|
||
|
read = !after;
|
||
|
if ( !after ) {
|
||
14 years ago
|
parent->setSelected( this, TRUE );
|
||
|
parent->setCurrentItem( this );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void ErrorItem::paintCell( TQPainter *p, const TQColorGroup & cg,
|
||
13 years ago
|
int column, int width, int alignment )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQColorGroup g( cg );
|
||
14 years ago
|
g.setColor( TQColorGroup::Text, type == Error ? TQt::red : TQt::darkYellow );
|
||
15 years ago
|
if ( !read ) {
|
||
15 years ago
|
TQFont f( p->font() );
|
||
15 years ago
|
f.setBold( TRUE );
|
||
|
p->setFont( f );
|
||
|
}
|
||
13 years ago
|
TQListViewItem::paintCell( p, g, column, width, alignment );
|
||
15 years ago
|
}
|