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