]> git.lyx.org Git - features.git/commitdiff
Present to Abdel: Syntax highlighting for LaTeX Log. (I know I should have been readi...
authorBo Peng <bpeng@lyx.org>
Mon, 26 Mar 2007 04:25:49 +0000 (04:25 +0000)
committerBo Peng <bpeng@lyx.org>
Mon, 26 Mar 2007 04:25:49 +0000 (04:25 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17561 a592a061-630c-0410-9148-cb99ea01b6c8

development/scons/scons_manifest.py
src/frontends/qt4/QLog.C
src/frontends/qt4/QLog.h

index 6ed4e79a42554dc306988a002b92d381ceca698f..e80974d754ea80b5e7a13c055d6ddd825b5717ae 100644 (file)
@@ -701,6 +701,7 @@ src_frontends_qt4_moc_files = Split('''
     QIncludeDialog.C
     QIndexDialog.C
     Action.C
+    QLog.C
     QLogDialog.C
     QViewSourceDialog.C
     QViewSource.C
index c8f04e45b7db17bf11aebb395d7ff9d4d20987fe..6d6cc8556abdda34f80fd2d2c8e49e717e269375 100644 (file)
@@ -14,6 +14,8 @@
 #include "QLogDialog.h"
 #include "qt_helpers.h"
 
+#include "frontends/Application.h"
+
 #include "controllers/ControlLog.h"
 
 #include <sstream>
@@ -31,9 +33,56 @@ QLog::QLog(Dialog & parent)
 {}
 
 
+logHighlighter::logHighlighter(QTextDocument * parent) :
+       QSyntaxHighlighter(parent)
+{
+       infoFormat.setForeground(Qt::gray);
+       warningFormat.setForeground(Qt::darkBlue);
+       errorFormat.setForeground(Qt::red);
+}
+
+
+void logHighlighter::highlightBlock(QString const & text)
+{
+       // Info
+       QRegExp exprInfo("^(Document Class:|LaTeX Font Info:|File:|Package:|Language:|Underfull|Overfull|\\(|\\\\).*$");
+       int index = text.indexOf(exprInfo);
+       while (index >= 0) {
+               int length = exprInfo.matchedLength();
+               setFormat(index, length, infoFormat);
+               index = text.indexOf(exprInfo, index + length);
+       }
+       // LaTeX Warning:
+       QRegExp exprWarning("^LaTeX Warning.*$");
+       index = text.indexOf(exprWarning);
+       while (index >= 0) {
+               int length = exprWarning.matchedLength();
+               setFormat(index, length, warningFormat);
+               index = text.indexOf(exprWarning, index + length);
+       }
+       // ! error 
+       QRegExp exprError("^!.*$");
+       index = text.indexOf(exprError);
+       while (index >= 0) {
+               int length = exprError.matchedLength();
+               setFormat(index, length, errorFormat);
+               index = text.indexOf(exprError, index + length);
+       }
+}
+
+
 void QLog::build_dialog()
 {
        dialog_.reset(new QLogDialog(this));
+       // set syntax highlighting
+       highlighter = new logHighlighter(dialog_->logTB->document());
+       //
+       dialog_->logTB->setReadOnly(true);
+       QFont font(toqstr(theApp()->typewriterFontName()));
+       font.setKerning(false);
+       font.setFixedPitch(true);
+       font.setStyleHint(QFont::TypeWriter);
+       dialog_->logTB->setFont(font);
 }
 
 
@@ -49,3 +98,5 @@ void QLog::update_contents()
 
 } // namespace frontend
 } // namespace lyx
+
+#include "QLog_moc.cpp"
index 0ef101c43325b6a85cc4bc15c6be0001bcd21e82..0ed6170a0a47c3968f67be85f271ed8f3c8d36f9 100644 (file)
 #include "QDialogView.h"
 #include "QLogDialog.h"
 
+#include <QSyntaxHighlighter>
+
 namespace lyx {
 namespace frontend {
 
 class ControlLog;
+class logHighlighter;
 
 ///
 class QLog
@@ -36,8 +39,30 @@ private:
        virtual void update_contents();
        /// build the dialog
        virtual void build_dialog();
+       /// log syntax highlighter
+       logHighlighter * highlighter;
+
+};
+
+
+///
+class logHighlighter : public QSyntaxHighlighter
+{
+       Q_OBJECT
+       
+public:
+       logHighlighter(QTextDocument * parent);
+
+protected:
+       void highlightBlock(QString const & text);
+
+private:
+       QTextCharFormat infoFormat;
+       QTextCharFormat warningFormat;
+       QTextCharFormat errorFormat;
 };
 
+
 } // namespace frontend
 } // namespace lyx