3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
8 * \author Jürgen Spitzmüller
10 * Full author contact details are available in file CREDITS.
17 #include "GuiApplication.h"
18 #include "qt_helpers.h"
21 #include "support/docstring.h"
22 #include "support/FileName.h"
23 #include "support/gettext.h"
25 #include <QTextBrowser>
26 #include <QSyntaxHighlighter>
33 using namespace lyx::support;
39 // Regular expressions needed at several places
41 QRegExp exprInfo("^(Document Class:|LaTeX Font Info:|File:|Package:|Language:|Underfull|Overfull|\\(|\\\\).*$");
43 QRegExp exprWarning("^(LaTeX Warning|LaTeX Font Warning|Package [\\w\\.]+ Warning|Class \\w+ Warning).*$");
45 QRegExp exprError("^!.*$");
48 /////////////////////////////////////////////////////////////////////
52 ////////////////////////////////////////////////////////////////////
54 class LogHighlighter : public QSyntaxHighlighter
57 LogHighlighter(QTextDocument * parent);
60 void highlightBlock(QString const & text);
63 QTextCharFormat infoFormat;
64 QTextCharFormat warningFormat;
65 QTextCharFormat errorFormat;
70 LogHighlighter::LogHighlighter(QTextDocument * parent)
71 : QSyntaxHighlighter(parent)
73 infoFormat.setForeground(Qt::darkGray);
74 warningFormat.setForeground(Qt::darkBlue);
75 errorFormat.setForeground(Qt::red);
79 void LogHighlighter::highlightBlock(QString const & text)
82 int index = exprInfo.indexIn(text);
84 int length = exprInfo.matchedLength();
85 setFormat(index, length, infoFormat);
86 index = exprInfo.indexIn(text, index + length);
89 index = exprWarning.indexIn(text);
91 int length = exprWarning.matchedLength();
92 setFormat(index, length, warningFormat);
93 index = exprWarning.indexIn(text, index + length);
96 index = exprError.indexIn(text);
98 int length = exprError.matchedLength();
99 setFormat(index, length, errorFormat);
100 index = exprError.indexIn(text, index + length);
105 /////////////////////////////////////////////////////////////////////
109 /////////////////////////////////////////////////////////////////////
111 GuiLog::GuiLog(GuiView & lv)
112 : GuiDialog(lv, "log", qt_("LaTeX Log")), type_(LatexLog)
116 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
117 connect(updatePB, SIGNAL(clicked()), this, SLOT(updateContents()));
118 connect(findPB, SIGNAL(clicked()), this, SLOT(find()));
119 // FIXME: find via returnPressed() does not work!
120 connect(findLE, SIGNAL(returnPressed()), this, SLOT(find()));
121 connect(logTypeCO, SIGNAL(activated(int)),
122 this, SLOT(typeChanged(int)));
124 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
126 // set syntax highlighting
127 highlighter = new LogHighlighter(logTB->document());
129 logTB->setReadOnly(true);
130 QFont font(guiApp->typewriterFontName());
131 font.setKerning(false);
132 font.setFixedPitch(true);
133 font.setStyleHint(QFont::TypeWriter);
134 logTB->setFont(font);
138 void GuiLog::updateContents()
140 setTitle(toqstr(title()));
145 logTB->setPlainText(toqstr(ss.str()));
147 nextErrorPB->setEnabled(contains(exprError));
148 nextWarningPB->setEnabled(contains(exprWarning));
152 void GuiLog::typeChanged(int i)
155 fromqstr(logTypeCO->itemData(i).toString());
159 else if (type == "bibtex")
161 else if (type == "index")
165 logfile_.changeExtension(ext);
173 logTB->find(findLE->text());
177 void GuiLog::on_nextErrorPB_clicked()
183 void GuiLog::on_nextWarningPB_clicked()
189 void GuiLog::goTo(QRegExp const & exp) const
191 QTextCursor const newc =
192 logTB->document()->find(exp, logTB->textCursor());
193 logTB->setTextCursor(newc);
197 bool GuiLog::contains(QRegExp const & exp) const
199 return !logTB->document()->find(exp, logTB->textCursor()).isNull();
203 bool GuiLog::initialiseParams(string const & data)
205 istringstream is(data);
209 string logtype, logfile;
213 logfile = lex.getString();
216 // Parsing of the data failed.
219 logTypeCO->setEnabled(logtype == "latex");
222 FileName log(logfile);
224 if (logtype == "latex") {
226 logTypeCO->addItem(qt_("LaTeX"), toqstr(logtype));
228 tmp.changeExtension("blg");
230 logTypeCO->addItem(qt_("BibTeX"), QString("bibtex"));
231 tmp.changeExtension("ilg");
233 logTypeCO->addItem(qt_("Index"), QString("index"));
234 // FIXME: not sure "literate" still works.
235 } else if (logtype == "literate") {
237 logTypeCO->addItem(qt_("Literate"), toqstr(logtype));
238 } else if (logtype == "lyx2lyx") {
240 logTypeCO->addItem(qt_("LyX2LyX"), toqstr(logtype));
241 } else if (logtype == "vc") {
243 logTypeCO->addItem(qt_("Version Control"), toqstr(logtype));
255 void GuiLog::clearParams()
261 docstring GuiLog::title() const
265 return _("LaTeX Log");
267 return _("Literate Programming Build Log");
269 return _("lyx2lyx Error Log");
271 return _("Version Control Log");
278 void GuiLog::getContents(ostream & ss) const
280 ifstream in(logfile_.toFilesystemEncoding().c_str());
282 bool success = false;
285 // Our caller interprets the file contents as UTF8, but is that
297 ss << to_utf8(_("Log file not found."));
300 ss << to_utf8(_("No literate programming build log file found."));
303 ss << to_utf8(_("No lyx2lyx error log file found."));
306 ss << to_utf8(_("No version control log file found."));
312 void GuiLog::on_copyPB_clicked()
314 qApp->clipboard()->setText(logTB->toPlainText());
318 Dialog * createGuiLog(GuiView & lv) { return new GuiLog(lv); }
321 } // namespace frontend
324 #include "moc_GuiLog.cpp"