3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
15 #include "ControlLog.h"
16 #include "qt_helpers.h"
18 #include "frontends/Application.h"
20 #include <QCloseEvent>
21 #include <QTextBrowser>
22 #include <QSyntaxHighlighter>
31 /////////////////////////////////////////////////////////////////////
35 ////////////////////////////////////////////////////////////////////
37 class LogHighlighter : public QSyntaxHighlighter
40 LogHighlighter(QTextDocument * parent);
43 void highlightBlock(QString const & text);
46 QTextCharFormat infoFormat;
47 QTextCharFormat warningFormat;
48 QTextCharFormat errorFormat;
53 LogHighlighter::LogHighlighter(QTextDocument * parent)
54 : QSyntaxHighlighter(parent)
56 infoFormat.setForeground(Qt::darkGray);
57 warningFormat.setForeground(Qt::darkBlue);
58 errorFormat.setForeground(Qt::red);
62 void LogHighlighter::highlightBlock(QString const & text)
65 QRegExp exprInfo("^(Document Class:|LaTeX Font Info:|File:|Package:|Language:|Underfull|Overfull|\\(|\\\\).*$");
66 int index = text.indexOf(exprInfo);
68 int length = exprInfo.matchedLength();
69 setFormat(index, length, infoFormat);
70 index = text.indexOf(exprInfo, index + length);
73 QRegExp exprWarning("^LaTeX Warning.*$");
74 index = text.indexOf(exprWarning);
76 int length = exprWarning.matchedLength();
77 setFormat(index, length, warningFormat);
78 index = text.indexOf(exprWarning, index + length);
81 QRegExp exprError("^!.*$");
82 index = text.indexOf(exprError);
84 int length = exprError.matchedLength();
85 setFormat(index, length, errorFormat);
86 index = text.indexOf(exprError, index + length);
91 /////////////////////////////////////////////////////////////////////
95 /////////////////////////////////////////////////////////////////////
97 GuiLogDialog::GuiLogDialog(LyXView & lv)
98 : GuiDialog(lv, "log")
101 setController(new ControlLog(*this));
103 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
104 connect(updatePB, SIGNAL(clicked()), this, SLOT(updateClicked()));
106 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
108 // set syntax highlighting
109 highlighter = new LogHighlighter(logTB->document());
111 logTB->setReadOnly(true);
112 QFont font(toqstr(theApp()->typewriterFontName()));
113 font.setKerning(false);
114 font.setFixedPitch(true);
115 font.setStyleHint(QFont::TypeWriter);
116 logTB->setFont(font);
120 ControlLog & GuiLogDialog::controller()
122 return static_cast<ControlLog &>(GuiDialog::controller());
126 void GuiLogDialog::closeEvent(QCloseEvent * e)
133 void GuiLogDialog::updateClicked()
139 void GuiLogDialog::updateContents()
141 setViewTitle(controller().title());
143 std::ostringstream ss;
144 controller().getContents(ss);
146 logTB->setPlainText(toqstr(ss.str()));
149 } // namespace frontend
152 #include "GuiLog_moc.cpp"