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