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"
20 #include "support/docstring.h"
21 #include "support/gettext.h"
23 #include <QTextBrowser>
24 #include <QSyntaxHighlighter>
31 using namespace lyx::support;
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", qt_("LaTeX 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::updateContents()
126 setTitle(toqstr(title()));
131 logTB->setPlainText(toqstr(ss.str()));
135 bool GuiLog::initialiseParams(string const & data)
137 istringstream is(data);
141 string logtype, logfile;
145 logfile = lex.getString();
148 // Parsing of the data failed.
151 if (logtype == "latex")
153 else if (logtype == "literate")
155 else if (logtype == "lyx2lyx")
157 else if (logtype == "vc")
162 logfile_ = FileName(logfile);
167 void GuiLog::clearParams()
173 docstring GuiLog::title() const
177 return _("LaTeX Log");
179 return _("Literate Programming Build Log");
181 return _("lyx2lyx Error Log");
183 return _("Version Control Log");
190 void GuiLog::getContents(ostream & ss) const
192 ifstream in(logfile_.toFilesystemEncoding().c_str());
194 bool success = false;
197 // Our caller interprets the file contents as UTF8, but is that
209 ss << to_utf8(_("No LaTeX log file found."));
212 ss << to_utf8(_("No literate programming build log file found."));
215 ss << to_utf8(_("No lyx2lyx error log file found."));
218 ss << to_utf8(_("No version control log file found."));
224 void GuiLog::on_copyPB_clicked()
226 qApp->clipboard()->setText(logTB->toPlainText());
230 Dialog * createGuiLog(GuiView & lv) { return new GuiLog(lv); }
233 } // namespace frontend
236 #include "GuiLog_moc.cpp"