3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
16 #include "GuiApplication.h"
17 #include "qt_helpers.h"
18 #include "support/gettext.h"
21 #include <QCloseEvent>
22 #include <QTextBrowser>
23 #include <QSyntaxHighlighter>
30 using namespace lyx::support;
35 /////////////////////////////////////////////////////////////////////
39 ////////////////////////////////////////////////////////////////////
41 class LogHighlighter : public QSyntaxHighlighter
44 LogHighlighter(QTextDocument * parent);
47 void highlightBlock(QString const & text);
50 QTextCharFormat infoFormat;
51 QTextCharFormat warningFormat;
52 QTextCharFormat errorFormat;
57 LogHighlighter::LogHighlighter(QTextDocument * parent)
58 : QSyntaxHighlighter(parent)
60 infoFormat.setForeground(Qt::darkGray);
61 warningFormat.setForeground(Qt::darkBlue);
62 errorFormat.setForeground(Qt::red);
66 void LogHighlighter::highlightBlock(QString const & text)
69 QRegExp exprInfo("^(Document Class:|LaTeX Font Info:|File:|Package:|Language:|Underfull|Overfull|\\(|\\\\).*$");
70 int index = text.indexOf(exprInfo);
72 int length = exprInfo.matchedLength();
73 setFormat(index, length, infoFormat);
74 index = text.indexOf(exprInfo, index + length);
77 QRegExp exprWarning("^LaTeX Warning.*$");
78 index = text.indexOf(exprWarning);
80 int length = exprWarning.matchedLength();
81 setFormat(index, length, warningFormat);
82 index = text.indexOf(exprWarning, index + length);
85 QRegExp exprError("^!.*$");
86 index = text.indexOf(exprError);
88 int length = exprError.matchedLength();
89 setFormat(index, length, errorFormat);
90 index = text.indexOf(exprError, index + length);
95 /////////////////////////////////////////////////////////////////////
99 /////////////////////////////////////////////////////////////////////
101 GuiLog::GuiLog(GuiView & lv)
102 : GuiDialog(lv, "log"), type_(LatexLog)
106 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
107 connect(updatePB, SIGNAL(clicked()), this, SLOT(updateContents()));
109 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
111 // set syntax highlighting
112 highlighter = new LogHighlighter(logTB->document());
114 logTB->setReadOnly(true);
115 QFont font(guiApp->typewriterFontName());
116 font.setKerning(false);
117 font.setFixedPitch(true);
118 font.setStyleHint(QFont::TypeWriter);
119 logTB->setFont(font);
123 void GuiLog::closeEvent(QCloseEvent * e)
130 void GuiLog::updateContents()
132 setViewTitle(title());
137 logTB->setPlainText(toqstr(ss.str()));
141 bool GuiLog::initialiseParams(string const & data)
143 istringstream is(data);
147 string logtype, logfile;
151 logfile = lex.getString();
154 // Parsing of the data failed.
157 if (logtype == "latex")
159 else if (logtype == "literate")
161 else if (logtype == "lyx2lyx")
163 else if (logtype == "vc")
168 logfile_ = FileName(logfile);
173 void GuiLog::clearParams()
179 docstring GuiLog::title() const
183 return _("LaTeX Log");
185 return _("Literate Programming Build Log");
187 return _("lyx2lyx Error Log");
189 return _("Version Control Log");
196 void GuiLog::getContents(ostream & ss) const
198 ifstream in(logfile_.toFilesystemEncoding().c_str());
200 bool success = false;
203 // Our caller interprets the file contents as UTF8, but is that
215 ss << to_utf8(_("No LaTeX log file found."));
218 ss << to_utf8(_("No literate programming build log file found."));
221 ss << to_utf8(_("No lyx2lyx error log file found."));
224 ss << to_utf8(_("No version control log file found."));
230 void GuiLog::on_copyPB_clicked()
232 qApp->clipboard()->setText(logTB->toPlainText());
236 Dialog * createGuiLog(GuiView & lv) { return new GuiLog(lv); }
239 } // namespace frontend
242 #include "GuiLog_moc.cpp"