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>
34 using support::FileName;
36 /////////////////////////////////////////////////////////////////////
40 ////////////////////////////////////////////////////////////////////
42 class LogHighlighter : public QSyntaxHighlighter
45 LogHighlighter(QTextDocument * parent);
48 void highlightBlock(QString const & text);
51 QTextCharFormat infoFormat;
52 QTextCharFormat warningFormat;
53 QTextCharFormat errorFormat;
58 LogHighlighter::LogHighlighter(QTextDocument * parent)
59 : QSyntaxHighlighter(parent)
61 infoFormat.setForeground(Qt::darkGray);
62 warningFormat.setForeground(Qt::darkBlue);
63 errorFormat.setForeground(Qt::red);
67 void LogHighlighter::highlightBlock(QString const & text)
70 QRegExp exprInfo("^(Document Class:|LaTeX Font Info:|File:|Package:|Language:|Underfull|Overfull|\\(|\\\\).*$");
71 int index = text.indexOf(exprInfo);
73 int length = exprInfo.matchedLength();
74 setFormat(index, length, infoFormat);
75 index = text.indexOf(exprInfo, index + length);
78 QRegExp exprWarning("^LaTeX Warning.*$");
79 index = text.indexOf(exprWarning);
81 int length = exprWarning.matchedLength();
82 setFormat(index, length, warningFormat);
83 index = text.indexOf(exprWarning, index + length);
86 QRegExp exprError("^!.*$");
87 index = text.indexOf(exprError);
89 int length = exprError.matchedLength();
90 setFormat(index, length, errorFormat);
91 index = text.indexOf(exprError, index + length);
96 /////////////////////////////////////////////////////////////////////
100 /////////////////////////////////////////////////////////////////////
102 GuiLog::GuiLog(GuiView & lv)
103 : GuiDialog(lv, "log"), type_(LatexLog)
107 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
108 connect(updatePB, SIGNAL(clicked()), this, SLOT(updateContents()));
110 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
112 // set syntax highlighting
113 highlighter = new LogHighlighter(logTB->document());
115 logTB->setReadOnly(true);
116 QFont font(guiApp->typewriterFontName());
117 font.setKerning(false);
118 font.setFixedPitch(true);
119 font.setStyleHint(QFont::TypeWriter);
120 logTB->setFont(font);
124 void GuiLog::closeEvent(QCloseEvent * e)
131 void GuiLog::updateContents()
133 setViewTitle(title());
135 std::ostringstream ss;
138 logTB->setPlainText(toqstr(ss.str()));
142 bool GuiLog::initialiseParams(string const & data)
144 istringstream is(data);
148 string logtype, logfile;
152 logfile = lex.getString();
155 // Parsing of the data failed.
158 if (logtype == "latex")
160 else if (logtype == "literate")
162 else if (logtype == "lyx2lyx")
164 else if (logtype == "vc")
169 logfile_ = FileName(logfile);
174 void GuiLog::clearParams()
180 docstring GuiLog::title() const
184 return _("LaTeX Log");
186 return _("Literate Programming Build Log");
188 return _("lyx2lyx Error Log");
190 return _("Version Control Log");
197 void GuiLog::getContents(std::ostream & ss) const
199 std::ifstream in(logfile_.toFilesystemEncoding().c_str());
201 bool success = false;
204 // Our caller interprets the file contents as UTF8, but is that
216 ss << to_utf8(_("No LaTeX log file found."));
219 ss << to_utf8(_("No literate programming build log file found."));
222 ss << to_utf8(_("No lyx2lyx error log file found."));
225 ss << to_utf8(_("No version control log file found."));
231 void GuiLog::on_copyPB_clicked()
233 qApp->clipboard()->setText(logTB->toPlainText());
237 Dialog * createGuiLog(GuiView & lv) { return new GuiLog(lv); }
240 } // namespace frontend
243 #include "GuiLog_moc.cpp"