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", qt_("LaTeX 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::updateContents()
125 setTitle(toqstr(title()));
130 logTB->setPlainText(toqstr(ss.str()));
134 bool GuiLog::initialiseParams(string const & data)
136 istringstream is(data);
140 string logtype, logfile;
144 logfile = lex.getString();
147 // Parsing of the data failed.
150 if (logtype == "latex")
152 else if (logtype == "literate")
154 else if (logtype == "lyx2lyx")
156 else if (logtype == "vc")
161 logfile_ = FileName(logfile);
166 void GuiLog::clearParams()
172 docstring GuiLog::title() const
176 return _("LaTeX Log");
178 return _("Literate Programming Build Log");
180 return _("lyx2lyx Error Log");
182 return _("Version Control Log");
189 void GuiLog::getContents(ostream & ss) const
191 ifstream in(logfile_.toFilesystemEncoding().c_str());
193 bool success = false;
196 // Our caller interprets the file contents as UTF8, but is that
208 ss << to_utf8(_("No LaTeX log file found."));
211 ss << to_utf8(_("No literate programming build log file found."));
214 ss << to_utf8(_("No lyx2lyx error log file found."));
217 ss << to_utf8(_("No version control log file found."));
223 void GuiLog::on_copyPB_clicked()
225 qApp->clipboard()->setText(logTB->toPlainText());
229 Dialog * createGuiLog(GuiView & lv) { return new GuiLog(lv); }
232 } // namespace frontend
235 #include "GuiLog_moc.cpp"