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 <QTextBrowser>
22 #include <QSyntaxHighlighter>
29 using namespace lyx::support;
34 /////////////////////////////////////////////////////////////////////
38 ////////////////////////////////////////////////////////////////////
40 class LogHighlighter : public QSyntaxHighlighter
43 LogHighlighter(QTextDocument * parent);
46 void highlightBlock(QString const & text);
49 QTextCharFormat infoFormat;
50 QTextCharFormat warningFormat;
51 QTextCharFormat errorFormat;
56 LogHighlighter::LogHighlighter(QTextDocument * parent)
57 : QSyntaxHighlighter(parent)
59 infoFormat.setForeground(Qt::darkGray);
60 warningFormat.setForeground(Qt::darkBlue);
61 errorFormat.setForeground(Qt::red);
65 void LogHighlighter::highlightBlock(QString const & text)
68 QRegExp exprInfo("^(Document Class:|LaTeX Font Info:|File:|Package:|Language:|Underfull|Overfull|\\(|\\\\).*$");
69 int index = text.indexOf(exprInfo);
71 int length = exprInfo.matchedLength();
72 setFormat(index, length, infoFormat);
73 index = text.indexOf(exprInfo, index + length);
76 QRegExp exprWarning("^LaTeX Warning.*$");
77 index = text.indexOf(exprWarning);
79 int length = exprWarning.matchedLength();
80 setFormat(index, length, warningFormat);
81 index = text.indexOf(exprWarning, index + length);
84 QRegExp exprError("^!.*$");
85 index = text.indexOf(exprError);
87 int length = exprError.matchedLength();
88 setFormat(index, length, errorFormat);
89 index = text.indexOf(exprError, index + length);
94 /////////////////////////////////////////////////////////////////////
98 /////////////////////////////////////////////////////////////////////
100 GuiLog::GuiLog(GuiView & lv)
101 : GuiDialog(lv, "log", qt_("LaTeX Log")), type_(LatexLog)
105 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
106 connect(updatePB, SIGNAL(clicked()), this, SLOT(updateContents()));
108 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
110 // set syntax highlighting
111 highlighter = new LogHighlighter(logTB->document());
113 logTB->setReadOnly(true);
114 QFont font(guiApp->typewriterFontName());
115 font.setKerning(false);
116 font.setFixedPitch(true);
117 font.setStyleHint(QFont::TypeWriter);
118 logTB->setFont(font);
122 void GuiLog::updateContents()
124 setTitle(toqstr(title()));
129 logTB->setPlainText(toqstr(ss.str()));
133 bool GuiLog::initialiseParams(string const & data)
135 istringstream is(data);
139 string logtype, logfile;
143 logfile = lex.getString();
146 // Parsing of the data failed.
149 if (logtype == "latex")
151 else if (logtype == "literate")
153 else if (logtype == "lyx2lyx")
155 else if (logtype == "vc")
160 logfile_ = FileName(logfile);
165 void GuiLog::clearParams()
171 docstring GuiLog::title() const
175 return _("LaTeX Log");
177 return _("Literate Programming Build Log");
179 return _("lyx2lyx Error Log");
181 return _("Version Control Log");
188 void GuiLog::getContents(ostream & ss) const
190 ifstream in(logfile_.toFilesystemEncoding().c_str());
192 bool success = false;
195 // Our caller interprets the file contents as UTF8, but is that
207 ss << to_utf8(_("No LaTeX log file found."));
210 ss << to_utf8(_("No literate programming build log file found."));
213 ss << to_utf8(_("No lyx2lyx error log file found."));
216 ss << to_utf8(_("No version control log file found."));
222 void GuiLog::on_copyPB_clicked()
224 qApp->clipboard()->setText(logTB->toPlainText());
228 Dialog * createGuiLog(GuiView & lv) { return new GuiLog(lv); }
231 } // namespace frontend
234 #include "GuiLog_moc.cpp"