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 | |
29 | class QVBoxLayout; |
30 | struct TermWidgetImpl; |
31 | class SearchBar; |
32 | class QUrl; |
33 | |
34 | class QTERMWIDGET_EXPORT QTermWidget : public QWidget { |
35 | Q_OBJECT |
36 | public: |
37 | |
38 | /** |
39 | * This enum describes the location where the scroll bar is positioned in the display widget. |
40 | */ |
41 | enum ScrollBarPosition { |
42 | /** Do not show the scroll bar. */ |
43 | NoScrollBar = 0, |
44 | /** Show the scroll bar on the left side of the display. */ |
45 | ScrollBarLeft = 1, |
46 | /** Show the scroll bar on the right side of the display. */ |
47 | ScrollBarRight = 2 |
48 | }; |
49 | |
50 | using KeyboardCursorShape = Konsole::Emulation::KeyboardCursorShape; |
51 | |
52 | //Creation of widget |
53 | QTermWidget(int startnow, // 1 = start shell programm immediatelly |
54 | QWidget * parent = 0); |
55 | // A dummy constructor for Qt Designer. startnow is 1 by default |
56 | QTermWidget(QWidget *parent = 0); |
57 | |
58 | virtual ~QTermWidget(); |
59 | |
60 | //Initial size |
61 | QSize sizeHint() const; |
62 | |
63 | // expose TerminalDisplay::TerminalSizeHint, setTerminalSizeHint |
64 | void setTerminalSizeHint(bool on); |
65 | bool terminalSizeHint(); |
66 | |
67 | //start shell program if it was not started in constructor |
68 | void startShellProgram(); |
69 | |
70 | /** |
71 | * Start terminal teletype as is |
72 | * and redirect data for external recipient. |
73 | * It can be used for display and control a remote terminal. |
74 | */ |
75 | void startTerminalTeletype(); |
76 | |
77 | int getShellPID(); |
78 | |
79 | void changeDir(const QString & dir); |
80 | |
81 | //look-n-feel, if you don`t like defaults |
82 | |
83 | // Terminal font |
84 | // Default is application font with family Monospace, size 10 |
85 | // Beware of a performance penalty and display/alignment issues when using a proportional font. |
86 | void setTerminalFont(const QFont & font); |
87 | QFont getTerminalFont(); |
88 | void setTerminalOpacity(qreal level); |
89 | void setTerminalBackgroundImage(QString backgroundImage); |
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 | // Sets whether flow control is enabled |
129 | void setFlowControlEnabled(bool enabled); |
130 | |
131 | // Returns whether flow control is enabled |
132 | bool flowControlEnabled(void); |
133 | |
134 | /** |
135 | * Sets whether the flow control warning box should be shown |
136 | * when the flow control stop key (Ctrl+S) is pressed. |
137 | */ |
138 | void setFlowControlWarningEnabled(bool enabled); |
139 | |
140 | /*! Get all available keyboard bindings |
141 | */ |
142 | static QStringList availableKeyBindings(); |
143 | |
144 | //! Return current key bindings |
145 | QString keyBindings(); |
146 | |
147 | void setMotionAfterPasting(int); |
148 | |
149 | /** Return the number of lines in the history buffer. */ |
150 | int historyLinesCount(); |
151 | |
152 | int screenColumnsCount(); |
153 | int screenLinesCount(); |
154 | |
155 | void setSelectionStart(int row, int column); |
156 | void setSelectionEnd(int row, int column); |
157 | void getSelectionStart(int& row, int& column); |
158 | void getSelectionEnd(int& row, int& column); |
159 | |
160 | /** |
161 | * Returns the currently selected text. |
162 | * @param preserveLineBreaks Specifies whether new line characters should |
163 | * be inserted into the returned text at the end of each terminal line. |
164 | */ |
165 | QString selectedText(bool preserveLineBreaks = true); |
166 | |
167 | void setMonitorActivity(bool); |
168 | void setMonitorSilence(bool); |
169 | void setSilenceTimeout(int seconds); |
170 | |
171 | /** Returns the available hotspot for the given point \em pos. |
172 | * |
173 | * This method may return a nullptr if no hotspot is available. |
174 | * |
175 | * @param[in] pos The point of interest in the QTermWidget coordinates. |
176 | * @return Hotspot for the given position, or nullptr if no hotspot. |
177 | */ |
178 | Filter::HotSpot* getHotSpotAt(const QPoint& pos) const; |
179 | |
180 | /** Returns the available hotspots for the given row and column. |
181 | * |
182 | * @return Hotspot for the given position, or nullptr if no hotspot. |
183 | */ |
184 | Filter::HotSpot* getHotSpotAt(int row, int column) const; |
185 | |
186 | /* |
187 | * Proxy for TerminalDisplay::filterActions |
188 | * */ |
189 | QList<QAction*> filterActions(const QPoint& position); |
190 | |
191 | /** |
192 | * Returns a pty slave file descriptor. |
193 | * This can be used for display and control |
194 | * a remote terminal. |
195 | */ |
196 | int getPtySlaveFd() const; |
197 | |
198 | /** |
199 | * Sets the shape of the keyboard cursor. This is the cursor drawn |
200 | * at the position in the terminal where keyboard input will appear. |
201 | */ |
202 | void setKeyboardCursorShape(KeyboardCursorShape shape); |
203 | |
204 | void setBlinkingCursor(bool blink); |
205 | |
206 | /** Enables or disables bidi text in the terminal. */ |
207 | void setBidiEnabled(bool enabled); |
208 | bool isBidiEnabled(); |
209 | |
210 | /** |
211 | * Automatically close the terminal session after the shell process exits or |
212 | * keep it running. |
213 | */ |
214 | void setAutoClose(bool); |
215 | |
216 | QString title() const; |
217 | QString icon() const; |
218 | |
219 | /** True if the title() or icon() was (ever) changed by the session. */ |
220 | bool isTitleChanged() const; |
221 | |
222 | /** change and wrap text corresponding to paste mode **/ |
223 | void bracketText(QString& text); |
224 | |
225 | /** Set the empty space outside the terminal */ |
226 | void setMargin(int); |
227 | |
228 | /** Get the empty space outside the terminal */ |
229 | int getMargin() const; |
230 | signals: |
231 | void finished(); |
232 | void copyAvailable(bool); |
233 | |
234 | void termGetFocus(); |
235 | void termLostFocus(); |
236 | |
237 | void termKeyPressed(QKeyEvent *); |
238 | |
239 | void urlActivated(const QUrl&, bool ); |
240 | |
241 | void bell(const QString& message); |
242 | |
243 | void activity(); |
244 | void silence(); |
245 | |
246 | /** |
247 | * Emitted when emulator send data to the terminal process |
248 | * (redirected for external recipient). It can be used for |
249 | * control and display the remote terminal. |
250 | */ |
251 | void sendData(const char *,int); |
252 | |
253 | void profileChanged(const QString & profile); |
254 | |
255 | void titleChanged(); |
256 | |
257 | /** |
258 | * Signals that we received new data from the process running in the |
259 | * terminal emulator |
260 | */ |
261 | void receivedData(const QString &text); |
262 | |
263 | public slots: |
264 | // Copy selection to clipboard |
265 | void copyClipboard(); |
266 | |
267 | // Paste clipboard to terminal |
268 | void pasteClipboard(); |
269 | |
270 | // Paste selection to terminal |
271 | void pasteSelection(); |
272 | |
273 | // Set zoom |
274 | void zoomIn(); |
275 | void zoomOut(); |
276 | |
277 | // Set size |
278 | void setSize(const QSize &); |
279 | |
280 | /*! Set named key binding for given widget |
281 | */ |
282 | void setKeyBindings(const QString & kb); |
283 | |
284 | /*! Clear the terminal content and move to home position |
285 | */ |
286 | void clear(); |
287 | |
288 | void toggleShowSearchBar(); |
289 | |
290 | protected: |
291 | virtual void resizeEvent(QResizeEvent *); |
292 | |
293 | protected slots: |
294 | void sessionFinished(); |
295 | void selectionChanged(bool textSelected); |
296 | |
297 | private slots: |
298 | void find(); |
299 | void findNext(); |
300 | void findPrevious(); |
301 | void matchFound(int startColumn, int startLine, int endColumn, int endLine); |
302 | void noMatchFound(); |
303 | /** |
304 | * Emulation::cursorChanged() signal propogates to here and QTermWidget |
305 | * sends the specified cursor states to the terminal display |
306 | */ |
307 | void cursorChanged(Konsole::Emulation::KeyboardCursorShape cursorShape, bool blinkingCursorEnabled); |
308 | |
309 | private: |
310 | void search(bool forwards, bool next); |
311 | void setZoom(int step); |
312 | void init(int startnow); |
313 | TermWidgetImpl * m_impl; |
314 | SearchBar* m_searchBar; |
315 | QVBoxLayout *m_layout; |
316 | QTranslator *m_translator; |
317 | }; |
318 | |
319 | |
320 | //Maybe useful, maybe not |
321 | |
322 | #ifdef __cplusplus |
323 | extern "C" |
324 | #endif |
325 | void * createTermWidget(int startnow, void * parent); |
326 | |
327 | #endif |
328 | |
329 | |