Debian Codegraph @

src/Gui/EditorView.h

raw
1 /***************************************************************************
2 * Copyright (c) 2007 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
24 #ifndef GUI_EDITORVIEW_H
25 #define GUI_EDITORVIEW_H
26
27 #include "MDIView.h"
28 #include "Window.h"
29
30 QT_BEGIN_NAMESPACE
31 class QLineEdit;
32 class QPlainTextEdit;
33 class QPrinter;
34 class QHBoxLayout;
35 class QToolButton;
36 class QCheckBox;
37 class QSpacerItem;
38 QT_END_NAMESPACE
39
40 namespace Gui
41 {
42
43 class EditorViewP;
44 class TextEdit;
45 class PythonTracingWatcher;
46
47 /**
48 * A special view class which sends the messages from the application to
49 * the editor and embeds it in a window.
50 * @author Werner Mayer
51 */
52 class GuiExport EditorView: public MDIView, public WindowParameter
53 {
54 Q_OBJECT
55
56 TYPESYSTEM_HEADER_WITH_OVERRIDE();
57
58 public:
59 enum DisplayName
60 {
61 FullName,
62 FileName,
63 BaseName
64 };
65
66 EditorView(TextEdit* editor, QWidget* parent);
67 ~EditorView() override;
68
69 QPlainTextEdit* getEditor() const;
70 void setDisplayName(DisplayName);
71 void OnChange(Base::Subject<const char*>& rCaller, const char* rcReason) override;
72
73 const char* getName() const override
74 {
75 return "EditorView";
76 }
77 void onUpdate() override
78 {}
79
80 bool onMsg(const char* pMsg, const char** ppReturn) override;
81 bool onHasMsg(const char* pMsg) const override;
82
83 bool canClose() override;
84
85 /** @name Standard actions of the editor */
86 //@{
87 bool open(const QString& f);
88 bool saveAs();
89 void cut();
90 void copy();
91 void paste();
92 void undo();
93 void redo();
94 void print() override;
95 void printPdf() override;
96 void printPreview() override;
97 void print(QPrinter*) override;
98 //@}
99
100 QStringList undoActions() const override;
101 QStringList redoActions() const override;
102 QString fileName() const;
103
104 protected:
105 void focusInEvent(QFocusEvent* e) override;
106 void showEvent(QShowEvent*) override;
107 void hideEvent(QHideEvent*) override;
108 void closeEvent(QCloseEvent*) override;
109
110 private Q_SLOTS:
111 void checkTimestamp();
112 void contentsChange(int position, int charsRemoved, int charsAdded);
113 void undoAvailable(bool);
114 void redoAvailable(bool);
115
116 Q_SIGNALS:
117 void changeFileName(const QString&);
118
119 private:
120 void setCurrentFileName(const QString& fileName);
121 bool saveFile();
122
123 private:
124 EditorViewP* d;
125 QList<QMetaObject::Connection> connectionList;
126 };
127
128 class PythonEditor;
129 class GuiExport PythonEditorView: public EditorView
130 {
131 Q_OBJECT
132
133 TYPESYSTEM_HEADER_WITH_OVERRIDE();
134
135 public:
136 PythonEditorView(PythonEditor* editor, QWidget* parent);
137 ~PythonEditorView() override;
138
139 bool onMsg(const char* pMsg, const char** ppReturn) override;
140 bool onHasMsg(const char* pMsg) const override;
141
142 public Q_SLOTS:
143 void executeScript();
144 void startDebug();
145 void toggleBreakpoint();
146 void showDebugMarker(int line);
147 void hideDebugMarker();
148
149 private:
150 PythonEditor* _pye;
151 PythonTracingWatcher* watcher;
152 };
153
154 class SearchBar: public QWidget
155 {
156 Q_OBJECT
157
158 public:
159 explicit SearchBar(QWidget* parent = nullptr);
160
161 void setEditor(QPlainTextEdit* textEdit);
162
163 protected:
164 void keyPressEvent(QKeyEvent*) override;
165 void changeEvent(QEvent*) override;
166
167 public Q_SLOTS:
168 void activate();
169 void deactivate();
170 void findPrevious();
171 void findNext();
172 void findCurrent();
173
174 private:
175 void retranslateUi();
176 void findText(bool skip, bool next, const QString& str);
177 void updateButtons();
178
179 private:
180 QPlainTextEdit* textEditor;
181 QHBoxLayout* horizontalLayout;
182 QSpacerItem* horizontalSpacer;
183 QToolButton* closeButton;
184 QLineEdit* searchText;
185 QToolButton* prevButton;
186 QToolButton* nextButton;
187 QCheckBox* matchCase;
188 QCheckBox* matchWord;
189 };
190
191 } // namespace Gui
192
193 #endif // GUI_EDITORVIEW_H