]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QLog.C
Fix unreported bug related to 3246 by Richard Heck:
[lyx.git] / src / frontends / qt4 / QLog.C
1 /**
2  * \file QLog.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "QLog.h"
14 #include "QLogDialog.h"
15 #include "qt_helpers.h"
16
17 #include "frontends/Application.h"
18
19 #include "controllers/ControlLog.h"
20
21 #include <sstream>
22
23 #include <QTextBrowser>
24 #include <QPushButton>
25
26 namespace lyx {
27 namespace frontend {
28
29 typedef QController<ControlLog, QView<QLogDialog> > log_base_class;
30
31 QLog::QLog(Dialog & parent)
32         : log_base_class(parent, lyx::docstring())
33 {}
34
35
36 logHighlighter::logHighlighter(QTextDocument * parent) :
37         QSyntaxHighlighter(parent)
38 {
39         infoFormat.setForeground(Qt::darkGray);
40         warningFormat.setForeground(Qt::darkBlue);
41         errorFormat.setForeground(Qt::red);
42 }
43
44
45 void logHighlighter::highlightBlock(QString const & text)
46 {
47         // Info
48         QRegExp exprInfo("^(Document Class:|LaTeX Font Info:|File:|Package:|Language:|Underfull|Overfull|\\(|\\\\).*$");
49         int index = text.indexOf(exprInfo);
50         while (index >= 0) {
51                 int length = exprInfo.matchedLength();
52                 setFormat(index, length, infoFormat);
53                 index = text.indexOf(exprInfo, index + length);
54         }
55         // LaTeX Warning:
56         QRegExp exprWarning("^LaTeX Warning.*$");
57         index = text.indexOf(exprWarning);
58         while (index >= 0) {
59                 int length = exprWarning.matchedLength();
60                 setFormat(index, length, warningFormat);
61                 index = text.indexOf(exprWarning, index + length);
62         }
63         // ! error 
64         QRegExp exprError("^!.*$");
65         index = text.indexOf(exprError);
66         while (index >= 0) {
67                 int length = exprError.matchedLength();
68                 setFormat(index, length, errorFormat);
69                 index = text.indexOf(exprError, index + length);
70         }
71 }
72
73
74 void QLog::build_dialog()
75 {
76         dialog_.reset(new QLogDialog(this));
77         // set syntax highlighting
78         highlighter = new logHighlighter(dialog_->logTB->document());
79         //
80         dialog_->logTB->setReadOnly(true);
81         QFont font(toqstr(theApp()->typewriterFontName()));
82         font.setKerning(false);
83         font.setFixedPitch(true);
84         font.setStyleHint(QFont::TypeWriter);
85         dialog_->logTB->setFont(font);
86 }
87
88
89 void QLog::update_contents()
90 {
91         setTitle(controller().title());
92
93         std::ostringstream ss;
94         controller().getContents(ss);
95
96         dialog_->logTB->setPlainText(toqstr(ss.str()));
97 }
98
99 } // namespace frontend
100 } // namespace lyx
101
102 #include "QLog_moc.cpp"