Debian Codegraph @

lib/qtermwidget.h

raw symbols SCIP
1 /* Copyright (C) 2008 e_k ([email protected])
2
3 This library is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Library General Public
5 License as published by the Free Software Foundation; either
6 version 2 of the License, or (at your option) any later version.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17 */
18
19
20 #ifndef _Q_TERM_WIDGET
21 #define _Q_TERM_WIDGET
22
23 #include <QTranslator>
24 #include <QWidget>
25 #include "Emulation.h"
26 #include "Filter.h"
27
28 class QVBoxLayout;
29 class TermWidgetImpl;
30 class SearchBar;
31 class QUrl;
32
33 class QTermWidget : public QWidget {
34 Q_OBJECT
35 public:
36
37 /**
38 * This enum describes the location where the scroll bar is positioned in the display widget.
39 */
40 enum ScrollBarPosition {
41 /** Do not show the scroll bar. */
42 NoScrollBar = 0,
43 /** Show the scroll bar on the left side of the display. */
44 ScrollBarLeft = 1,
45 /** Show the scroll bar on the right side of the display. */
46 ScrollBarRight = 2
47 };
48
49 using KeyboardCursorShape = Konsole::Emulation::KeyboardCursorShape;
50
51 //Creation of widget
52 QTermWidget(int startnow, // 1 = start shell programm immediatelly
53 QWidget * parent = nullptr);
54 // A dummy constructor for Qt Designer. startnow is 1 by default
55 QTermWidget(QWidget *parent = nullptr);
56
57 ~QTermWidget() override;
58
59 //Initial size
60 QSize sizeHint() const override;
61
62 // expose TerminalDisplay::TerminalSizeHint, setTerminalSizeHint
63 void setTerminalSizeHint(bool on);
64 bool terminalSizeHint();
65
66 //start shell program if it was not started in constructor
67 void startShellProgram();
68
69 /**
70 * Start terminal teletype as is
71 * and redirect data for external recipient.
72 * It can be used for display and control a remote terminal.
73 */
74 void startTerminalTeletype();
75
76 int getShellPID();
77
78 void changeDir(const QString & dir);
79
80 //look-n-feel, if you don`t like defaults
81
82 // Terminal font
83 // Default is application font with family Monospace, size 10
84 // Beware of a performance penalty and display/alignment issues when using a proportional font.
85 void setTerminalFont(const QFont & font);
86 QFont getTerminalFont();
87 void setTerminalOpacity(qreal level);
88 void setTerminalBackgroundImage(const QString& backgroundImage);
89 void setTerminalBackgroundMode(int mode);
90
91 //environment
92 void setEnvironment(const QStringList & environment);
93
94 // Shell program, default is /bin/bash
95 void setShellProgram(const QString & progname);
96
97 //working directory
98 void setWorkingDirectory(const QString & dir);
99 QString workingDirectory();
100
101 // Shell program args, default is none
102 void setArgs(const QStringList & args);
103
104 //Text codec, default is UTF-8
105 void setTextCodec(QTextCodec * codec);
106
107 /** @brief Sets the color scheme, default is white on black
108 *
109 * @param[in] name The name of the color scheme, either returned from
110 * availableColorSchemes() or a full path to a color scheme.
111 */
112 void setColorScheme(const QString & name);
113 static QStringList availableColorSchemes();
114 static void addCustomColorSchemeDir(const QString& custom_dir);
115
116 // History size for scrolling
117 void setHistorySize(int lines); //infinite if lines < 0
118
119 // Presence of scrollbar
120 void setScrollBarPosition(ScrollBarPosition);
121
122 // Wrapped, scroll to end.
123 void scrollToEnd();
124
125 // Send some text to terminal
126 void sendText(const QString & text);
127
128 // Send key event to terminal
129 void sendKeyEvent(QKeyEvent* e);
130
131 // Sets whether flow control is enabled
132 void setFlowControlEnabled(bool enabled);
133
134 // Returns whether flow control is enabled
135 bool flowControlEnabled(void);
136
137 /**
138 * Sets whether the flow control warning box should be shown
139 * when the flow control stop key (Ctrl+S) is pressed.
140 */
141 void setFlowControlWarningEnabled(bool enabled);
142
143 /*! Get all available keyboard bindings
144 */
145 static QStringList availableKeyBindings();
146
147 //! Return current key bindings
148 QString keyBindings();
149
150 void setMotionAfterPasting(int);
151
152 /** Return the number of lines in the history buffer. */
153 int historyLinesCount();
154
155 int screenColumnsCount();
156 int screenLinesCount();
157
158 void setSelectionStart(int row, int column);
159 void setSelectionEnd(int row, int column);
160 void getSelectionStart(int& row, int& column);
161 void getSelectionEnd(int& row, int& column);
162
163 /**
164 * Returns the currently selected text.
165 * @param preserveLineBreaks Specifies whether new line characters should
166 * be inserted into the returned text at the end of each terminal line.
167 */
168 QString selectedText(bool preserveLineBreaks = true);
169
170 void setMonitorActivity(bool);
171 void setMonitorSilence(bool);
172 void setSilenceTimeout(int seconds);
173
174 /** Returns the available hotspot for the given point \em pos.
175 *
176 * This method may return a nullptr if no hotspot is available.
177 *
178 * @param[in] pos The point of interest in the QTermWidget coordinates.
179 * @return Hotspot for the given position, or nullptr if no hotspot.
180 */
181 Filter::HotSpot* getHotSpotAt(const QPoint& pos) const;
182
183 /** Returns the available hotspots for the given row and column.
184 *
185 * @return Hotspot for the given position, or nullptr if no hotspot.
186 */
187 Filter::HotSpot* getHotSpotAt(int row, int column) const;
188
189 /*
190 * Proxy for TerminalDisplay::filterActions
191 * */
192 QList<QAction*> filterActions(const QPoint& position);
193
194 /**
195 * Returns a pty slave file descriptor.
196 * This can be used for display and control
197 * a remote terminal.
198 */
199 int getPtySlaveFd() const;
200
201 /**
202 * Sets the shape of the keyboard cursor. This is the cursor drawn
203 * at the position in the terminal where keyboard input will appear.
204 */
205 void setKeyboardCursorShape(KeyboardCursorShape shape);
206
207 void setBlinkingCursor(bool blink);
208
209 /** Enables or disables bidi text in the terminal. */
210 void setBidiEnabled(bool enabled);
211 bool isBidiEnabled();
212
213 /**
214 * Automatically close the terminal session after the shell process exits or
215 * keep it running.
216 */
217 void setAutoClose(bool);
218
219 QString title() const;
220 QString icon() const;
221
222 /** True if the title() or icon() was (ever) changed by the session. */
223 bool isTitleChanged() const;
224
225 /** change and wrap text corresponding to paste mode **/
226 void bracketText(QString& text);
227
228 /** forcefully disable bracketed paste mode **/
229 void disableBracketedPasteMode(bool disable);
230 bool bracketedPasteModeIsDisabled() const;
231
232 /** Set the empty space outside the terminal */
233 void setMargin(int);
234
235 /** Get the empty space outside the terminal */
236 int getMargin() const;
237
238 void setDrawLineChars(bool drawLineChars);
239
240 void setBoldIntense(bool boldIntense);
241
242 void setConfirmMultilinePaste(bool confirmMultilinePaste);
243 void setTrimPastedTrailingNewlines(bool trimPastedTrailingNewlines);
244 signals:
245 void finished();
246 void copyAvailable(bool);
247
248 void termGetFocus();
249 void termLostFocus();
250
251 void termKeyPressed(QKeyEvent *);
252
253 void urlActivated(const QUrl&, bool fromContextMenu);
254
255 void bell(const QString& message);
256
257 void activity();
258 void silence();
259
260 /**
261 * Emitted when emulator send data to the terminal process
262 * (redirected for external recipient). It can be used for
263 * control and display the remote terminal.
264 */
265 void sendData(const char *,int);
266
267 void profileChanged(const QString & profile);
268
269 void titleChanged();
270
271 /**
272 * Signals that we received new data from the process running in the
273 * terminal emulator
274 */
275 void receivedData(const QString &text);
276
277 public slots:
278 // Copy selection to clipboard
279 void copyClipboard();
280
281 // Paste clipboard to terminal
282 void pasteClipboard();
283
284 // Paste selection to terminal
285 void pasteSelection();
286
287 // Set zoom
288 void zoomIn();
289 void zoomOut();
290
291 // Set size
292 void setSize(const QSize &);
293
294 /*! Set named key binding for given widget
295 */
296 void setKeyBindings(const QString & kb);
297
298 /*! Clear the terminal content and move to home position
299 */
300 void clear();
301
302 void toggleShowSearchBar();
303
304 void saveHistory(QIODevice *device);
305 protected:
306 void resizeEvent(QResizeEvent *) override;
307
308 protected slots:
309 void sessionFinished();
310 void selectionChanged(bool textSelected);
311
312 private slots:
313 void find();
314 void findNext();
315 void findPrevious();
316 void matchFound(int startColumn, int startLine, int endColumn, int endLine);
317 void noMatchFound();
318 /**
319 * Emulation::cursorChanged() signal propogates to here and QTermWidget
320 * sends the specified cursor states to the terminal display
321 */
322 void cursorChanged(Konsole::Emulation::KeyboardCursorShape cursorShape, bool blinkingCursorEnabled);
323
324 private:
325 void search(bool forwards, bool next);
326 void setZoom(int step);
327 void init(int startnow);
328 TermWidgetImpl * m_impl;
329 SearchBar* m_searchBar;
330 QVBoxLayout *m_layout;
331 QTranslator *m_translator;
332 };
333
334
335 //Maybe useful, maybe not
336
337 #ifdef __cplusplus
338 extern "C"
339 #endif
340 void * createTermWidget(int startnow, void * parent);
341
342 #endif
343