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/gettext.h"
24 #include <QTextBrowser>
25 #include <QSyntaxHighlighter>
32 using namespace lyx::support;
38 // Regular expressions needed at several places
40 QRegExp exprInfo("^(Document Class:|LaTeX Font Info:|File:|Package:|Language:|Underfull|Overfull|\\(|\\\\).*$");
42 QRegExp exprWarning("^LaTeX Warning.*$");
44 QRegExp exprError("^!.*$");
47 /////////////////////////////////////////////////////////////////////
51 ////////////////////////////////////////////////////////////////////
53 class LogHighlighter : public QSyntaxHighlighter
56 LogHighlighter(QTextDocument * parent);
59 void highlightBlock(QString const & text);
62 QTextCharFormat infoFormat;
63 QTextCharFormat warningFormat;
64 QTextCharFormat errorFormat;
69 LogHighlighter::LogHighlighter(QTextDocument * parent)
70 : QSyntaxHighlighter(parent)
72 infoFormat.setForeground(Qt::darkGray);
73 warningFormat.setForeground(Qt::darkBlue);
74 errorFormat.setForeground(Qt::red);
78 void LogHighlighter::highlightBlock(QString const & text)
81 int index = exprInfo.indexIn(text);
83 int length = exprInfo.matchedLength();
84 setFormat(index, length, infoFormat);
85 index = exprInfo.indexIn(text, index + length);
88 index = exprWarning.indexIn(text);
90 int length = exprWarning.matchedLength();
91 setFormat(index, length, warningFormat);
92 index = exprWarning.indexIn(text, index + length);
95 index = exprError.indexIn(text);
97 int length = exprError.matchedLength();
98 setFormat(index, length, errorFormat);
99 index = exprError.indexIn(text, index + length);
104 /////////////////////////////////////////////////////////////////////
108 /////////////////////////////////////////////////////////////////////
110 GuiLog::GuiLog(GuiView & lv)
111 : GuiDialog(lv, "log", qt_("LaTeX Log")), type_(LatexLog)
115 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
116 connect(updatePB, SIGNAL(clicked()), this, SLOT(updateContents()));
117 connect(findPB, SIGNAL(clicked()), this, SLOT(find()));
118 // FIXME: find via returnPressed() does not work!
119 connect(findLE, SIGNAL(returnPressed()), this, SLOT(find()));
121 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
123 // set syntax highlighting
124 highlighter = new LogHighlighter(logTB->document());
126 logTB->setReadOnly(true);
127 QFont font(guiApp->typewriterFontName());
128 font.setKerning(false);
129 font.setFixedPitch(true);
130 font.setStyleHint(QFont::TypeWriter);
131 logTB->setFont(font);
135 void GuiLog::updateContents()
137 setTitle(toqstr(title()));
142 logTB->setPlainText(toqstr(ss.str()));
144 nextErrorPB->setEnabled(contains(exprError));
145 nextWarningPB->setEnabled(contains(exprWarning));
151 logTB->find(findLE->text());
155 void GuiLog::on_nextErrorPB_clicked()
161 void GuiLog::on_nextWarningPB_clicked()
167 void GuiLog::goTo(QRegExp const & exp) const
169 QTextCursor const newc =
170 logTB->document()->find(exp, logTB->textCursor());
171 logTB->setTextCursor(newc);
175 bool GuiLog::contains(QRegExp const & exp) const
177 return !logTB->document()->find(exp, logTB->textCursor()).isNull();
181 bool GuiLog::initialiseParams(string const & data)
183 istringstream is(data);
187 string logtype, logfile;
191 logfile = lex.getString();
194 // Parsing of the data failed.
197 if (logtype == "latex")
199 // FIXME: not sure "literate" still works.
200 else if (logtype == "literate")
202 else if (logtype == "lyx2lyx")
204 else if (logtype == "vc")
209 logfile_ = FileName(logfile);
217 void GuiLog::clearParams()
223 docstring GuiLog::title() const
227 return _("LaTeX Log");
229 return _("Literate Programming Build Log");
231 return _("lyx2lyx Error Log");
233 return _("Version Control Log");
240 void GuiLog::getContents(ostream & ss) const
242 ifstream in(logfile_.toFilesystemEncoding().c_str());
244 bool success = false;
247 // Our caller interprets the file contents as UTF8, but is that
259 ss << to_utf8(_("No LaTeX log file found."));
262 ss << to_utf8(_("No literate programming build log file found."));
265 ss << to_utf8(_("No lyx2lyx error log file found."));
268 ss << to_utf8(_("No version control log file found."));
274 void GuiLog::on_copyPB_clicked()
276 qApp->clipboard()->setText(logTB->toPlainText());
280 Dialog * createGuiLog(GuiView & lv) { return new GuiLog(lv); }
283 } // namespace frontend
286 #include "moc_GuiLog.cpp"