Debian Codegraph @

src/Gui/ReportView.h

raw
1 /***************************************************************************
2 * Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23 #ifndef GUI_DOCKWND_REPORTVIEW_H
24 #define GUI_DOCKWND_REPORTVIEW_H
25
26 #include <QPointer>
27 #include <QTextEdit>
28 #include <QSyntaxHighlighter>
29
30 #include "Window.h"
31 #include <FCGlobal.h>
32
33
34 class QTabWidget;
35
36 namespace Gui
37 {
38 class PythonConsole;
39 namespace DockWnd
40 {
41
42 class ReportOutput;
43 class ReportHighlighter;
44 class ReportOutputObserver;
45
46 /** Report view containing an output window and a very simple Python console.
47 * @see ReportOutput
48 * @see PythonConsole
49 * \author Werner Mayer
50 */
51 class ReportView: public QWidget
52 {
53 Q_OBJECT
54
55 public:
56 explicit ReportView(QWidget* parent = nullptr);
57 ~ReportView() override;
58
59 protected:
60 void changeEvent(QEvent* e) override;
61
62 private:
63 QTabWidget* tabWidget;
64 ReportOutput* tabOutput; /**< Output 'Report view' window */
65 PythonConsole* tabPython; /**< Python console */
66 };
67
68 /** Syntax highlighter to write log or normal messages, warnings and errors in different colors.
69 * \author Werner Mayer
70 */
71 class GuiExport ReportHighlighter: public QSyntaxHighlighter
72 {
73 public:
74 enum Paragraph
75 {
76 Message = 0, /**< normal text */
77 Warning = 1, /**< Warning */
78 Error = 2, /**< Error text */
79 LogText = 3, /**< Log text */
80 Critical = 4, /**< critical text */
81 };
82
83 public:
84 explicit ReportHighlighter(QTextEdit*);
85 ~ReportHighlighter() override;
86
87 /** Parses the given text and highlight it in the right colors. */
88 void highlightBlock(const QString& text) override;
89 /**
90 * Sets the current paragraph type used in ReportOutput
91 * @see ReportOutput::Message
92 * @see ReportOutput::Warning
93 * @see ReportOutput::Error
94 * @see ReportOutput::Critical
95 */
96 void setParagraphType(Paragraph);
97
98 /**
99 * Sets the text color to \a col.
100 */
101 void setTextColor(const QColor& col);
102
103 /**
104 * Sets the color for log messages to \a col.
105 */
106 void setLogColor(const QColor& col);
107
108 /**
109 * Sets the color for warnings to \a col.
110 */
111 void setWarningColor(const QColor& col);
112
113 /**
114 * Sets the color for error messages to \a col.
115 */
116 void setErrorColor(const QColor& col);
117
118 /**
119 * Sets the text color to \a col.
120 */
121 void setCriticalColor(const QColor& col);
122
123 private:
124 /** @name for internal use only */
125 //@{
126 Paragraph type;
127 QColor txtCol, logCol, warnCol, errCol, criticalCol;
128 //@}
129 };
130
131 /** Output window 'Report view' to show messages.
132 * @see Base::ILogger
133 * @see QTextEdit
134 * \author Werner Mayer
135 */
136 class GuiExport ReportOutput: public QTextEdit, public WindowParameter, public Base::ILogger
137 {
138 Q_OBJECT
139
140 public:
141 explicit ReportOutput(QWidget* parent = nullptr);
142 ~ReportOutput() override;
143
144 /** Observes its parameter group. */
145 void OnChange(Base::Subject<const char*>& rCaller, const char* sReason) override;
146
147 void sendLog(
148 const std::string& notifiername,
149 const std::string& msg,
150 Base::LogStyle level,
151 Base::IntendedRecipient recipient,
152 Base::ContentType content
153 ) override;
154
155 /// returns the name for observer handling
156 const char* name() override
157 {
158 return "ReportOutput";
159 }
160
161 /** Restore the default font settings. */
162 void restoreFont();
163
164 /** Returns true whether errors are reported. */
165 bool isError() const;
166 /** Returns true whether warnings are reported. */
167 bool isWarning() const;
168 /** Returns true whether log messages are reported. */
169 bool isLogMessage() const;
170 /** Returns true whether normal messages are reported. */
171 bool isNormalMessage() const;
172 /** Returns true whether critical messages are reported. */
173 bool isCritical() const;
174
175 protected:
176 /** For internal use only */
177 void customEvent(QEvent* ev) override;
178 /** Handles the change of style sheets */
179 void changeEvent(QEvent*) override;
180 /** Pops up the context menu with some extensions */
181 void contextMenuEvent(QContextMenuEvent* e) override;
182 /** Handle shortcut override events */
183 bool event(QEvent* event) override;
184
185 public Q_SLOTS:
186 /** Save the report messages into a file. */
187 void onSaveAs();
188 /** Toggles the report of errors. */
189 void onToggleError();
190 /** Toggles the report of warnings. */
191 void onToggleWarning();
192 /** Toggles the report of log messages. */
193 void onToggleLogMessage();
194 /** Toggles the report of normal messages. */
195 void onToggleNormalMessage();
196 /** Toggles the report of normal messages. */
197 void onToggleCritical();
198 /** Toggles whether to show report view on warnings*/
199 void onToggleShowReportViewOnWarning();
200 /** Toggles whether to show report view on errors*/
201 void onToggleShowReportViewOnError();
202 /** Toggles whether to show report view on normal messages*/
203 void onToggleShowReportViewOnNormalMessage();
204 /** Toggles whether to show report view on normal messages*/
205 void onToggleShowReportViewOnCritical();
206 /** Toggles whether to show report view on log messages*/
207 void onToggleShowReportViewOnLogMessage();
208 /** Toggles the redirection of Python stdout. */
209 void onToggleRedirectPythonStdout();
210 /** Toggles the redirection of Python stderr. */
211 void onToggleRedirectPythonStderr();
212 /** Toggles the report to go to the end if new messages appear. */
213 void onToggleGoToEnd();
214
215 private:
216 class Data;
217 Data* d;
218 bool gotoEnd;
219 bool blockStart;
220 ReportHighlighter* reportHl; /**< Syntax highlighter */
221 int messageSize;
222 ParameterGrp::handle _prefs;
223 };
224
225 /**
226 * Observer to enable report view on warnings / errors if not already
227 * enabled.
228 */
229
230 class ReportOutputObserver: public QObject
231 {
232 Q_OBJECT
233
234 public:
235 explicit ReportOutputObserver(ReportOutput* view);
236 bool eventFilter(QObject* obj, QEvent* event) override;
237
238 protected:
239 QPointer<ReportOutput> reportView;
240 void showReportView();
241 };
242
243 } // namespace DockWnd
244 } // namespace Gui
245
246 #endif // GUI_DOCKWND_REPORTVIEW_H