source: ogBrowser-Git/qtermwidget/lib/qtermwidget.h @ ffbf8ac

jenkinsmain
Last change on this file since ffbf8ac was 64efc22, checked in by Vadim Troshchinskiy <vtroshchinskiy@…>, 19 months ago

Update qtermwidget to modern version

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