3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
14 #include "qt_helpers.h"
16 #include "frontends/Application.h"
18 #include "controllers/ControlLog.h"
22 #include <QTextBrowser>
23 #include <QPushButton>
28 /////////////////////////////////////////////////////////////////////
32 /////////////////////////////////////////////////////////////////////
35 QLogDialog::QLogDialog(QLog * form)
40 connect(closePB, SIGNAL(clicked()),
41 form, SLOT(slotClose()));
42 connect( updatePB, SIGNAL( clicked() ),
43 this, SLOT( updateClicked() ) );
47 void QLogDialog::closeEvent(QCloseEvent * e)
54 void QLogDialog::updateClicked()
56 form_->update_contents();
60 /////////////////////////////////////////////////////////////////////
64 /////////////////////////////////////////////////////////////////////
66 LogHighlighter::LogHighlighter(QTextDocument * parent)
67 : QSyntaxHighlighter(parent)
69 infoFormat.setForeground(Qt::darkGray);
70 warningFormat.setForeground(Qt::darkBlue);
71 errorFormat.setForeground(Qt::red);
75 void LogHighlighter::highlightBlock(QString const & text)
78 QRegExp exprInfo("^(Document Class:|LaTeX Font Info:|File:|Package:|Language:|Underfull|Overfull|\\(|\\\\).*$");
79 int index = text.indexOf(exprInfo);
81 int length = exprInfo.matchedLength();
82 setFormat(index, length, infoFormat);
83 index = text.indexOf(exprInfo, index + length);
86 QRegExp exprWarning("^LaTeX Warning.*$");
87 index = text.indexOf(exprWarning);
89 int length = exprWarning.matchedLength();
90 setFormat(index, length, warningFormat);
91 index = text.indexOf(exprWarning, index + length);
94 QRegExp exprError("^!.*$");
95 index = text.indexOf(exprError);
97 int length = exprError.matchedLength();
98 setFormat(index, length, errorFormat);
99 index = text.indexOf(exprError, index + length);
104 /////////////////////////////////////////////////////////////////////
108 /////////////////////////////////////////////////////////////////////
110 typedef QController<ControlLog, QView<QLogDialog> > LogBase;
112 QLog::QLog(Dialog & parent)
113 : LogBase(parent, docstring())
117 void QLog::build_dialog()
119 dialog_.reset(new QLogDialog(this));
120 // set syntax highlighting
121 highlighter = new LogHighlighter(dialog_->logTB->document());
123 dialog_->logTB->setReadOnly(true);
124 QFont font(toqstr(theApp()->typewriterFontName()));
125 font.setKerning(false);
126 font.setFixedPitch(true);
127 font.setStyleHint(QFont::TypeWriter);
128 dialog_->logTB->setFont(font);
132 void QLog::update_contents()
134 setTitle(controller().title());
136 std::ostringstream ss;
137 controller().getContents(ss);
139 dialog_->logTB->setPlainText(toqstr(ss.str()));
142 } // namespace frontend
145 #include "QLog_moc.cpp"