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