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 "qt_helpers.h"
20 #include "frontends/Application.h"
22 #include <QCloseEvent>
23 #include <QTextBrowser>
24 #include <QSyntaxHighlighter>
30 using std::istringstream;
38 using support::FileName;
40 /////////////////////////////////////////////////////////////////////
44 ////////////////////////////////////////////////////////////////////
46 class LogHighlighter : public QSyntaxHighlighter
49 LogHighlighter(QTextDocument * parent);
52 void highlightBlock(QString const & text);
55 QTextCharFormat infoFormat;
56 QTextCharFormat warningFormat;
57 QTextCharFormat errorFormat;
62 LogHighlighter::LogHighlighter(QTextDocument * parent)
63 : QSyntaxHighlighter(parent)
65 infoFormat.setForeground(Qt::darkGray);
66 warningFormat.setForeground(Qt::darkBlue);
67 errorFormat.setForeground(Qt::red);
71 void LogHighlighter::highlightBlock(QString const & text)
74 QRegExp exprInfo("^(Document Class:|LaTeX Font Info:|File:|Package:|Language:|Underfull|Overfull|\\(|\\\\).*$");
75 int index = text.indexOf(exprInfo);
77 int length = exprInfo.matchedLength();
78 setFormat(index, length, infoFormat);
79 index = text.indexOf(exprInfo, index + length);
82 QRegExp exprWarning("^LaTeX Warning.*$");
83 index = text.indexOf(exprWarning);
85 int length = exprWarning.matchedLength();
86 setFormat(index, length, warningFormat);
87 index = text.indexOf(exprWarning, index + length);
90 QRegExp exprError("^!.*$");
91 index = text.indexOf(exprError);
93 int length = exprError.matchedLength();
94 setFormat(index, length, errorFormat);
95 index = text.indexOf(exprError, index + length);
100 /////////////////////////////////////////////////////////////////////
104 /////////////////////////////////////////////////////////////////////
106 GuiLog::GuiLog(LyXView & lv)
107 : GuiDialog(lv, "log"), type_(LatexLog)
111 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
112 connect(updatePB, SIGNAL(clicked()), this, SLOT(updateContents()));
114 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
116 // set syntax highlighting
117 highlighter = new LogHighlighter(logTB->document());
119 logTB->setReadOnly(true);
120 QFont font(toqstr(theApp()->typewriterFontName()));
121 font.setKerning(false);
122 font.setFixedPitch(true);
123 font.setStyleHint(QFont::TypeWriter);
124 logTB->setFont(font);
128 void GuiLog::closeEvent(QCloseEvent * e)
135 void GuiLog::updateContents()
137 setViewTitle(title());
139 std::ostringstream ss;
142 logTB->setPlainText(toqstr(ss.str()));
146 bool GuiLog::initialiseParams(string const & data)
148 istringstream is(data);
152 string logtype, logfile;
156 logfile = lex.getString();
159 // Parsing of the data failed.
162 if (logtype == "latex")
164 else if (logtype == "literate")
166 else if (logtype == "lyx2lyx")
168 else if (logtype == "vc")
173 logfile_ = FileName(logfile);
178 void GuiLog::clearParams()
184 docstring GuiLog::title() const
188 return _("LaTeX Log");
190 return _("Literate Programming Build Log");
192 return _("lyx2lyx Error Log");
194 return _("Version Control Log");
201 void GuiLog::getContents(std::ostream & ss) const
203 std::ifstream in(logfile_.toFilesystemEncoding().c_str());
205 bool success = false;
208 // Our caller interprets the file contents as UTF8, but is that
220 ss << to_utf8(_("No LaTeX log file found."));
223 ss << to_utf8(_("No literate programming build log file found."));
226 ss << to_utf8(_("No lyx2lyx error log file found."));
229 ss << to_utf8(_("No version control log file found."));
235 void GuiLog::on_copyPB_clicked()
237 qApp->clipboard()->setText(logTB->toPlainText());
241 Dialog * createGuiLog(LyXView & lv) { return new GuiLog(lv); }
244 } // namespace frontend
247 #include "GuiLog_moc.cpp"