]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiLog.cpp
rename a few view functions from foo() to fooView()
[lyx.git] / src / frontends / qt4 / GuiLog.cpp
1 /**
2  * \file GuiLog.cpp
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 <sstream>
14
15 #include "GuiLog.h"
16 #include "qt_helpers.h"
17
18 #include "frontends/Application.h"
19
20 #include <QCloseEvent>
21 #include <QTextBrowser>
22 #include <QTextBrowser>
23
24 namespace lyx {
25 namespace frontend {
26
27 /////////////////////////////////////////////////////////////////////
28 //
29 // GuiLogDialog
30 //
31 /////////////////////////////////////////////////////////////////////
32
33
34 GuiLogDialog::GuiLogDialog(GuiLog * form)
35         : form_(form)
36 {
37         setupUi(this);
38
39         connect(closePB, SIGNAL(clicked()),
40                 form, SLOT(slotClose()));
41         connect( updatePB, SIGNAL( clicked() ),
42                 this, SLOT( updateClicked() ) );
43 }
44
45
46 void GuiLogDialog::closeEvent(QCloseEvent * e)
47 {
48         form_->slotWMHide();
49         e->accept();
50 }
51
52
53 void GuiLogDialog::updateClicked()
54 {
55         form_->update_contents();
56 }
57
58
59 /////////////////////////////////////////////////////////////////////
60 //
61 // LogHighlighter
62 //
63 /////////////////////////////////////////////////////////////////////
64
65 LogHighlighter::LogHighlighter(QTextDocument * parent)
66         : QSyntaxHighlighter(parent)
67 {
68         infoFormat.setForeground(Qt::darkGray);
69         warningFormat.setForeground(Qt::darkBlue);
70         errorFormat.setForeground(Qt::red);
71 }
72
73
74 void LogHighlighter::highlightBlock(QString const & text)
75 {
76         // Info
77         QRegExp exprInfo("^(Document Class:|LaTeX Font Info:|File:|Package:|Language:|Underfull|Overfull|\\(|\\\\).*$");
78         int index = text.indexOf(exprInfo);
79         while (index >= 0) {
80                 int length = exprInfo.matchedLength();
81                 setFormat(index, length, infoFormat);
82                 index = text.indexOf(exprInfo, index + length);
83         }
84         // LaTeX Warning:
85         QRegExp exprWarning("^LaTeX Warning.*$");
86         index = text.indexOf(exprWarning);
87         while (index >= 0) {
88                 int length = exprWarning.matchedLength();
89                 setFormat(index, length, warningFormat);
90                 index = text.indexOf(exprWarning, index + length);
91         }
92         // ! error
93         QRegExp exprError("^!.*$");
94         index = text.indexOf(exprError);
95         while (index >= 0) {
96                 int length = exprError.matchedLength();
97                 setFormat(index, length, errorFormat);
98                 index = text.indexOf(exprError, index + length);
99         }
100 }
101
102
103 /////////////////////////////////////////////////////////////////////
104 //
105 // GuiLog
106 //
107 /////////////////////////////////////////////////////////////////////
108
109
110 GuiLog::GuiLog(GuiDialog & parent)
111         :  GuiView<GuiLogDialog>(parent, docstring())
112 {}
113
114
115 void GuiLog::build_dialog()
116 {
117         dialog_.reset(new GuiLogDialog(this));
118         // set syntax highlighting
119         highlighter = new LogHighlighter(dialog_->logTB->document());
120         //
121         dialog_->logTB->setReadOnly(true);
122         QFont font(toqstr(theApp()->typewriterFontName()));
123         font.setKerning(false);
124         font.setFixedPitch(true);
125         font.setStyleHint(QFont::TypeWriter);
126         dialog_->logTB->setFont(font);
127 }
128
129
130 void GuiLog::update_contents()
131 {
132         setViewTitle(controller().title());
133
134         std::ostringstream ss;
135         controller().getContents(ss);
136
137         dialog_->logTB->setPlainText(toqstr(ss.str()));
138 }
139
140 } // namespace frontend
141 } // namespace lyx
142
143 #include "GuiLog_moc.cpp"