Skip to content

Commit

Permalink
view: improve the terminal output view
Browse files Browse the repository at this point in the history
* Use QPlainTextEdit instead of QTextEdit for optimization.
* Set a monospaced font by default
* Use QSyntaxHighlighter to highlight lines starting with "ERROR"
  • Loading branch information
jleben committed Mar 17, 2012
1 parent 6e075dc commit 50093fe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
22 changes: 20 additions & 2 deletions src/ScateView.cpp
Expand Up @@ -34,6 +34,7 @@
#include <QLabel>
#include <QKeyEvent>
#include <QToolBar>
#include <QTextBlock>

using namespace Scate;

Expand Down Expand Up @@ -158,13 +159,19 @@ QWidget * ScateView::createOutputView()
"SC Terminal"
);

scOutView = new QTextEdit;
QFont defaultFont("monospace");
defaultFont.setStyleHint(QFont::TypeWriter);

scOutView = new QPlainTextEdit;
scOutView->setReadOnly( true );
scOutView->document()->setMaximumBlockCount( config.readEntry( "TerminalMaxRows", 500 ) );
scOutView->document()->setDefaultFont( config.readEntry( "TerminalFont", QFont() ) );
scOutView->document()->setDefaultFont( config.readEntry( "TerminalFont", defaultFont ) );
scOutView->setTabStopWidth(20);
connect( plugin, SIGNAL( scSaid( const QString& ) ),
this, SLOT( scSaid( const QString& ) ) );

new PostSyntaxHighlighter(scOutView->document());

cmdLine = new CmdLine( "Code:", 30 );
connect( cmdLine, SIGNAL( invoked( const QString&, bool ) ),
plugin, SLOT( eval( const QString&, bool ) ) );
Expand Down Expand Up @@ -277,3 +284,14 @@ void ScateView::writeSessionConfig( KConfigBase* config, const QString& groupPre
Q_UNUSED( config );
Q_UNUSED( groupPrefix );
}

void PostSyntaxHighlighter::highlightBlock ( const QString & text )
{
if (text.startsWith("ERROR", Qt::CaseInsensitive)) {
QTextBlock b(currentBlock());
QTextBlockFormat fm(b.blockFormat());
fm.setBackground(Qt::red);
QTextCursor c(b);
c.setBlockFormat(fm);
}
}
12 changes: 10 additions & 2 deletions src/ScateView.hpp
Expand Up @@ -28,8 +28,9 @@
#include <kate/plugin.h>
#include <kate/mainwindow.h>

#include <QTextEdit>
#include <QPlainTextEdit>
#include <QLineEdit>
#include <QSyntaxHighlighter>

class ScatePlugin;
class ScateHelpWidget;
Expand Down Expand Up @@ -61,7 +62,7 @@ class ScateView : public Kate::PluginView, public KXMLGUIClient
ScatePlugin *plugin;

QWidget *outputToolView;
QTextEdit *scOutView;
QPlainTextEdit *scOutView;
Scate::CmdLine *cmdLine;

QWidget *helpToolView;
Expand All @@ -73,4 +74,11 @@ class ScateView : public Kate::PluginView, public KXMLGUIClient
QAction *aClearOutput;
};

class PostSyntaxHighlighter : QSyntaxHighlighter
{
public:
PostSyntaxHighlighter(QTextDocument *doc) : QSyntaxHighlighter(doc) {}
void highlightBlock ( const QString & );
};

#endif //SCATE_VIEW_H

0 comments on commit 50093fe

Please sign in to comment.