Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

Commit

Permalink
Install custom message handler on UIMain.
Browse files Browse the repository at this point in the history
  • Loading branch information
pasnox committed Aug 1, 2012
1 parent e269b25 commit 63f9fdc
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 17 deletions.
40 changes: 38 additions & 2 deletions src/example/UIMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "SyntaxHighlighter.h"
#include "TextDocument.h"

UIMain* UIMain::qMain = 0;

// QodeEditor

QodeEditor::QodeEditor( QWidget* parent )
Expand Down Expand Up @@ -67,14 +69,20 @@ class SpacerWidget : public QWidget {
UIMain::UIMain( QWidget* parent )
: QMainWindow( parent ), ui( new Ui_UIMain )
{
if ( !UIMain::qMain ) {
UIMain::qMain = this;
}

ui->setupUi( this );
ui->toolBar->addWidget( new SpacerWidget( this ) );
ui->toolBar->addWidget( ui->cbSyntax );

qInstallMsgHandler( UIMain::messageHandler );

QString error;

if ( Syntax::Factory::load( &error ) ) {
error = "Syntaxes loaded correctly";
qWarning() << Q_FUNC_INFO << "Syntaxes loaded correctly";
}

//qWarning() << Syntax::Factory::availableSyntaxes();
Expand Down Expand Up @@ -117,7 +125,7 @@ UIMain::UIMain( QWidget* parent )
editor->textDocument()->setSyntaxHighlighter( highlighter );

QListWidgetItem* item = new QListWidgetItem( ui->lwEditors );
item->setText( highlighter->syntaxDocument().name );
item->setText( QString( "%1 (%2)" ).arg( file.fileName() ).arg( highlighter->syntaxDocument().name ) );
item->setData( Qt::UserRole, QVariant::fromValue( editor ) );
ui->swEditors->addWidget( editor );
}
Expand All @@ -131,10 +139,38 @@ UIMain::UIMain( QWidget* parent )

UIMain::~UIMain()
{
if ( UIMain::qMain == this ) {
UIMain::qMain = 0;
}

delete ui;
Syntax::Factory::free();
}

void UIMain::appendDebugMessage( const QString& message )
{
ui->pteDebug->appendPlainText( message );
}

void UIMain::messageHandler( QtMsgType type, const char* msg )
{
switch ( type ) {
case QtDebugMsg:
UIMain::qMain->appendDebugMessage( QString( "Debug: %1" ).arg( msg ) );
break;
case QtWarningMsg:
UIMain::qMain->appendDebugMessage( QString( "Warning: %1" ).arg( msg ) );
break;
case QtCriticalMsg:
UIMain::qMain->appendDebugMessage( QString( "Critical: %1" ).arg( msg ) );
break;
case QtFatalMsg:
UIMain::qMain->appendDebugMessage( QString( "Fatal: %1" ).arg( msg ) );
//abort();
break;
}
}

QodeEditor* UIMain::editor( int row ) const
{
QListWidgetItem* item = ui->lwEditors->item( row );
Expand Down
5 changes: 5 additions & 0 deletions src/example/UIMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class UIMain : public QMainWindow
UIMain( QWidget* parent = 0 );
virtual ~UIMain();

void appendDebugMessage( const QString& message );

static void messageHandler( QtMsgType type, const char* msg );
static UIMain* qMain;

protected:
Ui_UIMain* ui;
QHash<QString, QodeEditor*> mEditors;
Expand Down
80 changes: 65 additions & 15 deletions src/example/UIMain.ui
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,77 @@
</rect>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<widget class="QStackedWidget" name="swEditors"/>
</item>
<item row="1" column="0">
<widget class="QListWidget" name="lwEditors">
<property name="maximumSize">
<size>
<width>120</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="Syntax::ComboBox" name="cbSyntax">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item>
<widget class="QSplitter" name="splitter_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QListWidget" name="lwEditors">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>240</width>
<height>16777215</height>
</size>
</property>
</widget>
<widget class="QStackedWidget" name="swEditors">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</widget>
<widget class="QPlainTextEdit" name="pteDebug">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>140</height>
</size>
</property>
<property name="tabChangesFocus">
<bool>true</bool>
</property>
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="tabStopWidth">
<number>40</number>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QToolBar" name="toolBar">
Expand Down

0 comments on commit 63f9fdc

Please sign in to comment.