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>
29 using std::istringstream;
37 using support::FileName;
39 /////////////////////////////////////////////////////////////////////
43 ////////////////////////////////////////////////////////////////////
45 class LogHighlighter : public QSyntaxHighlighter
48 LogHighlighter(QTextDocument * parent);
51 void highlightBlock(QString const & text);
54 QTextCharFormat infoFormat;
55 QTextCharFormat warningFormat;
56 QTextCharFormat errorFormat;
61 LogHighlighter::LogHighlighter(QTextDocument * parent)
62 : QSyntaxHighlighter(parent)
64 infoFormat.setForeground(Qt::darkGray);
65 warningFormat.setForeground(Qt::darkBlue);
66 errorFormat.setForeground(Qt::red);
70 void LogHighlighter::highlightBlock(QString const & text)
73 QRegExp exprInfo("^(Document Class:|LaTeX Font Info:|File:|Package:|Language:|Underfull|Overfull|\\(|\\\\).*$");
74 int index = text.indexOf(exprInfo);
76 int length = exprInfo.matchedLength();
77 setFormat(index, length, infoFormat);
78 index = text.indexOf(exprInfo, index + length);
81 QRegExp exprWarning("^LaTeX Warning.*$");
82 index = text.indexOf(exprWarning);
84 int length = exprWarning.matchedLength();
85 setFormat(index, length, warningFormat);
86 index = text.indexOf(exprWarning, index + length);
89 QRegExp exprError("^!.*$");
90 index = text.indexOf(exprError);
92 int length = exprError.matchedLength();
93 setFormat(index, length, errorFormat);
94 index = text.indexOf(exprError, index + length);
99 /////////////////////////////////////////////////////////////////////
103 /////////////////////////////////////////////////////////////////////
105 GuiLog::GuiLog(GuiView & lv)
106 : GuiDialog(lv, "log"), type_(LatexLog)
110 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
111 connect(updatePB, SIGNAL(clicked()), this, SLOT(updateContents()));
113 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
115 // set syntax highlighting
116 highlighter = new LogHighlighter(logTB->document());
118 logTB->setReadOnly(true);
119 QFont font(guiApp->typewriterFontName());
120 font.setKerning(false);
121 font.setFixedPitch(true);
122 font.setStyleHint(QFont::TypeWriter);
123 logTB->setFont(font);
127 void GuiLog::closeEvent(QCloseEvent * e)
134 void GuiLog::updateContents()
136 setViewTitle(title());
138 std::ostringstream ss;
141 logTB->setPlainText(toqstr(ss.str()));
145 bool GuiLog::initialiseParams(string const & data)
147 istringstream is(data);
151 string logtype, logfile;
155 logfile = lex.getString();
158 // Parsing of the data failed.
161 if (logtype == "latex")
163 else if (logtype == "literate")
165 else if (logtype == "lyx2lyx")
167 else if (logtype == "vc")
172 logfile_ = FileName(logfile);
177 void GuiLog::clearParams()
183 docstring GuiLog::title() const
187 return _("LaTeX Log");
189 return _("Literate Programming Build Log");
191 return _("lyx2lyx Error Log");
193 return _("Version Control Log");
200 void GuiLog::getContents(std::ostream & ss) const
202 std::ifstream in(logfile_.toFilesystemEncoding().c_str());
204 bool success = false;
207 // Our caller interprets the file contents as UTF8, but is that
219 ss << to_utf8(_("No LaTeX log file found."));
222 ss << to_utf8(_("No literate programming build log file found."));
225 ss << to_utf8(_("No lyx2lyx error log file found."));
228 ss << to_utf8(_("No version control log file found."));
234 void GuiLog::on_copyPB_clicked()
236 qApp->clipboard()->setText(logTB->toPlainText());
240 Dialog * createGuiLog(GuiView & lv) { return new GuiLog(lv); }
243 } // namespace frontend
246 #include "GuiLog_moc.cpp"