1 | /* |
2 | Copyright 2007-2008 by Robert Knight <robertknight@gmail.com> |
3 | Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de> |
4 | |
5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
9 | |
10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | 02110-1301 USA. |
19 | */ |
20 | |
21 | #ifndef TERMINALDISPLAY_H |
22 | #define TERMINALDISPLAY_H |
23 | |
24 | // Qt |
25 | #include <QtGui/QColor> |
26 | #include <QtCore/QPointer> |
27 | #include <QWidget> |
28 | |
29 | // Konsole |
30 | #include "Character.h" |
31 | #include "konsole_export.h" |
32 | #include "ScreenWindow.h" |
33 | #include "ColorScheme.h" |
34 | #include "Enumeration.h" |
35 | |
36 | class QDrag; |
37 | class QDragEnterEvent; |
38 | class QDropEvent; |
39 | class QLabel; |
40 | class QTimer; |
41 | class QEvent; |
42 | class QGridLayout; |
43 | class QKeyEvent; |
44 | class QScrollBar; |
45 | class QShowEvent; |
46 | class QHideEvent; |
47 | class QTimerEvent; |
48 | |
49 | namespace Konsole |
50 | { |
51 | class FilterChain; |
52 | class TerminalImageFilterChain; |
53 | class SessionController; |
54 | /** |
55 | * A widget which displays output from a terminal emulation and sends input keypresses and mouse activity |
56 | * to the terminal. |
57 | * |
58 | * When the terminal emulation receives new output from the program running in the terminal, |
59 | * it will update the display by calling updateImage(). |
60 | * |
61 | * TODO More documentation |
62 | */ |
63 | class KONSOLEPRIVATE_EXPORT TerminalDisplay : public QWidget |
64 | { |
65 | Q_OBJECT |
66 | |
67 | public: |
68 | /** Constructs a new terminal display widget with the specified parent. */ |
69 | explicit TerminalDisplay(QWidget* parent = 0); |
70 | virtual ~TerminalDisplay(); |
71 | |
72 | /** Returns the terminal color palette used by the display. */ |
73 | const ColorEntry* colorTable() const; |
74 | /** Sets the terminal color palette used by the display. */ |
75 | void setColorTable(const ColorEntry table[]); |
76 | /** |
77 | * Sets the seed used to generate random colors for the display |
78 | * (in color schemes that support them). |
79 | */ |
80 | void setRandomSeed(uint seed); |
81 | /** |
82 | * Returns the seed used to generate random colors for the display |
83 | * (in color schemes that support them). |
84 | */ |
85 | uint randomSeed() const; |
86 | |
87 | /** Sets the opacity of the terminal display. */ |
88 | void setOpacity(qreal opacity); |
89 | |
90 | /** Sets the background picture */ |
91 | void setWallpaper(ColorSchemeWallpaper::Ptr p); |
92 | |
93 | /** |
94 | * Specifies whether the terminal display has a vertical scroll bar, and if so whether it |
95 | * is shown on the left or right side of the display. |
96 | */ |
97 | void setScrollBarPosition(Enum::ScrollBarPositionEnum position); |
98 | Enum::ScrollBarPositionEnum scrollBarPosition() const { |
99 | return _scrollbarLocation; |
100 | } |
101 | |
102 | /** |
103 | * Sets the current position and range of the display's scroll bar. |
104 | * |
105 | * @param cursor The position of the scroll bar's thumb. |
106 | * @param lines The maximum value of the scroll bar. |
107 | */ |
108 | void setScroll(int cursor, int lines); |
109 | |
110 | void setScrollFullPage(bool fullPage); |
111 | bool scrollFullPage() const; |
112 | |
113 | /** |
114 | * Returns the display's filter chain. When the image for the display is updated, |
115 | * the text is passed through each filter in the chain. Each filter can define |
116 | * hotspots which correspond to certain strings (such as URLs or particular words). |
117 | * Depending on the type of the hotspots created by the filter ( returned by Filter::Hotspot::type() ) |
118 | * the view will draw visual cues such as underlines on mouse-over for links or translucent |
119 | * rectangles for markers. |
120 | * |
121 | * To add a new filter to the view, call: |
122 | * viewWidget->filterChain()->addFilter( filterObject ); |
123 | */ |
124 | FilterChain* filterChain() const; |
125 | |
126 | /** |
127 | * Updates the filters in the display's filter chain. This will cause |
128 | * the hotspots to be updated to match the current image. |
129 | * |
130 | * WARNING: This function can be expensive depending on the |
131 | * image size and number of filters in the filterChain() |
132 | * |
133 | * TODO - This API does not really allow efficient usage. Revise it so |
134 | * that the processing can be done in a better way. |
135 | * |
136 | * eg: |
137 | * - Area of interest may be known ( eg. mouse cursor hovering |
138 | * over an area ) |
139 | */ |
140 | void processFilters(); |
141 | |
142 | /** |
143 | * Returns a list of menu actions created by the filters for the content |
144 | * at the given @p position. |
145 | */ |
146 | QList<QAction*> filterActions(const QPoint& position); |
147 | |
148 | /** Specifies whether or not the cursor can blink. */ |
149 | void setBlinkingCursorEnabled(bool blink); |
150 | /** Returns true if the cursor is allowed to blink or false otherwise. */ |
151 | bool blinkingCursorEnabled() const { |
152 | return _allowBlinkingCursor; |
153 | } |
154 | |
155 | /** Specifies whether or not text can blink. */ |
156 | void setBlinkingTextEnabled(bool blink); |
157 | |
158 | void setControlDrag(bool enable) { |
159 | _ctrlRequiredForDrag = enable; |
160 | } |
161 | bool ctrlRequiredForDrag() const { |
162 | return _ctrlRequiredForDrag; |
163 | } |
164 | |
165 | /** Sets how the text is selected when the user triple clicks within the display. */ |
166 | void setTripleClickMode(Enum::TripleClickModeEnum mode) { |
167 | _tripleClickMode = mode; |
168 | } |
169 | /** See setTripleClickSelectionMode() */ |
170 | Enum::TripleClickModeEnum tripleClickMode() const { |
171 | return _tripleClickMode; |
172 | } |
173 | |
174 | /** |
175 | * Specifies whether links and email addresses should be underlined when |
176 | * hovered by the mouse. Defaults to true. |
177 | */ |
178 | void setUnderlineLinks(bool value) { |
179 | _underlineLinks = value; |
180 | } |
181 | /** |
182 | * Returns true if links and email addresses should be underlined when |
183 | * hovered by the mouse. |
184 | */ |
185 | bool getUnderlineLinks() const { |
186 | return _underlineLinks; |
187 | } |
188 | |
189 | /** |
190 | * Specifies whether links and email addresses should be opened when |
191 | * clicked with the mouse. Defaults to false. |
192 | */ |
193 | void setOpenLinksByDirectClick(bool value) { |
194 | _openLinksByDirectClick = value; |
195 | } |
196 | /** |
197 | * Returns true if links and email addresses should be opened when |
198 | * clicked with the mouse. |
199 | */ |
200 | bool getOpenLinksByDirectClick() const { |
201 | return _openLinksByDirectClick; |
202 | } |
203 | |
204 | /** |
205 | * Sets whether trailing spaces should be trimmed in selected text. |
206 | */ |
207 | void setTrimTrailingSpaces(bool enabled) { |
208 | _trimTrailingSpaces = enabled; |
209 | } |
210 | |
211 | /** |
212 | * Returns true if trailing spaces should be trimmed in selected text. |
213 | */ |
214 | bool trimTrailingSpaces() const { |
215 | return _trimTrailingSpaces; |
216 | } |
217 | |
218 | void setLineSpacing(uint); |
219 | uint lineSpacing() const; |
220 | |
221 | void setSessionController(SessionController* controller); |
222 | SessionController* sessionController(); |
223 | |
224 | /** |
225 | * Sets the shape of the keyboard cursor. This is the cursor drawn |
226 | * at the position in the terminal where keyboard input will appear. |
227 | * |
228 | * In addition the terminal display widget also has a cursor for |
229 | * the mouse pointer, which can be set using the QWidget::setCursor() |
230 | * method. |
231 | * |
232 | * Defaults to BlockCursor |
233 | */ |
234 | void setKeyboardCursorShape(Enum::CursorShapeEnum shape); |
235 | /** |
236 | * Returns the shape of the keyboard cursor. See setKeyboardCursorShape() |
237 | */ |
238 | Enum::CursorShapeEnum keyboardCursorShape() const; |
239 | |
240 | /** |
241 | * Sets the color used to draw the keyboard cursor. |
242 | * |
243 | * The keyboard cursor defaults to using the foreground color of the character |
244 | * underneath it. |
245 | * |
246 | * @param color By default, the widget uses the color of the |
247 | * character under the cursor to draw the cursor, and inverts the |
248 | * color of that character to make sure it is still readable. If @p |
249 | * color is a valid QColor, the widget uses that color to draw the |
250 | * cursor. If @p color is not an valid QColor, the widget falls back |
251 | * to the default behavior. |
252 | */ |
253 | void setKeyboardCursorColor(const QColor& color); |
254 | |
255 | /** |
256 | * Returns the color of the keyboard cursor, or an invalid color if the keyboard |
257 | * cursor color is set to change according to the foreground color of the character |
258 | * underneath it. |
259 | */ |
260 | QColor keyboardCursorColor() const; |
261 | |
262 | /** |
263 | * Returns the number of lines of text which can be displayed in the widget. |
264 | * |
265 | * This will depend upon the height of the widget and the current font. |
266 | * See fontHeight() |
267 | */ |
268 | int lines() const { |
269 | return _lines; |
270 | } |
271 | /** |
272 | * Returns the number of characters of text which can be displayed on |
273 | * each line in the widget. |
274 | * |
275 | * This will depend upon the width of the widget and the current font. |
276 | * See fontWidth() |
277 | */ |
278 | int columns() const { |
279 | return _columns; |
280 | } |
281 | |
282 | /** |
283 | * Returns the height of the characters in the font used to draw the text in the display. |
284 | */ |
285 | int fontHeight() const { |
286 | return _fontHeight; |
287 | } |
288 | /** |
289 | * Returns the width of the characters in the display. |
290 | * This assumes the use of a fixed-width font. |
291 | */ |
292 | int fontWidth() const { |
293 | return _fontWidth; |
294 | } |
295 | |
296 | void setSize(int columns, int lines); |
297 | |
298 | // reimplemented |
299 | QSize sizeHint() const; |
300 | |
301 | /** |
302 | * Sets which characters, in addition to letters and numbers, |
303 | * are regarded as being part of a word for the purposes |
304 | * of selecting words in the display by double clicking on them. |
305 | * |
306 | * The word boundaries occur at the first and last characters which |
307 | * are either a letter, number, or a character in @p wc |
308 | * |
309 | * @param wc An array of characters which are to be considered parts |
310 | * of a word ( in addition to letters and numbers ). |
311 | */ |
312 | void setWordCharacters(const QString& wc); |
313 | /** |
314 | * Returns the characters which are considered part of a word for the |
315 | * purpose of selecting words in the display with the mouse. |
316 | * |
317 | * @see setWordCharacters() |
318 | */ |
319 | QString wordCharacters() const { |
320 | return _wordCharacters; |
321 | } |
322 | |
323 | /** |
324 | * Sets the type of effect used to alert the user when a 'bell' occurs in the |
325 | * terminal session. |
326 | * |
327 | * The terminal session can trigger the bell effect by calling bell() with |
328 | * the alert message. |
329 | */ |
330 | void setBellMode(int mode); |
331 | /** |
332 | * Returns the type of effect used to alert the user when a 'bell' occurs in |
333 | * the terminal session. |
334 | * |
335 | * See setBellMode() |
336 | */ |
337 | int bellMode() const; |
338 | |
339 | /** Play a visual bell for prompt or warning. */ |
340 | void visualBell(); |
341 | |
342 | /** |
343 | * Specified whether zoom terminal on Ctrl+mousewheel is enabled or not. |
344 | * Defaults to enabled. |
345 | */ |
346 | void setMouseWheelZoom(bool value) { |
347 | _mouseWheelZoom = value; |
348 | }; |
349 | /** |
350 | * Returns the whether zoom terminal on Ctrl+mousewheel is enabled. |
351 | * |
352 | * See setMouseWheelZoom() |
353 | */ |
354 | bool mouseWheelZoom() { |
355 | return _mouseWheelZoom; |
356 | }; |
357 | |
358 | /** |
359 | * Reimplemented. Has no effect. Use setVTFont() to change the font |
360 | * used to draw characters in the display. |
361 | */ |
362 | virtual void setFont(const QFont &); |
363 | |
364 | /** Returns the font used to draw characters in the display */ |
365 | QFont getVTFont() { |
366 | return font(); |
367 | } |
368 | |
369 | /** |
370 | * Sets the font used to draw the display. Has no effect if @p font |
371 | * is larger than the size of the display itself. |
372 | */ |
373 | void setVTFont(const QFont& font); |
374 | |
375 | /** Increases the font size */ |
376 | void increaseFontSize(); |
377 | |
378 | /** Decreases the font size */ |
379 | void decreaseFontSize(); |
380 | |
381 | /** |
382 | * Specified whether anti-aliasing of text in the terminal display |
383 | * is enabled or not. Defaults to enabled. |
384 | */ |
385 | void setAntialias(bool value) { |
386 | _antialiasText = value; |
387 | } |
388 | /** |
389 | * Returns true if anti-aliasing of text in the terminal is enabled. |
390 | */ |
391 | bool antialias() const { |
392 | return _antialiasText; |
393 | } |
394 | |
395 | /** |
396 | * Specifies whether characters with intense colors should be rendered |
397 | * as bold. Defaults to true. |
398 | */ |
399 | void setBoldIntense(bool value) { |
400 | _boldIntense = value; |
401 | } |
402 | /** |
403 | * Returns true if characters with intense colors are rendered in bold. |
404 | */ |
405 | bool getBoldIntense() const { |
406 | return _boldIntense; |
407 | } |
408 | |
409 | /** |
410 | * Sets whether or not the current height and width of the |
411 | * terminal in lines and columns is displayed whilst the widget |
412 | * is being resized. |
413 | */ |
414 | void setShowTerminalSizeHint(bool on) { |
415 | _showTerminalSizeHint = on; |
416 | } |
417 | /** |
418 | * Returns whether or not the current height and width of |
419 | * the terminal in lines and columns is displayed whilst the widget |
420 | * is being resized. |
421 | */ |
422 | bool showTerminalSizeHint() const { |
423 | return _showTerminalSizeHint; |
424 | } |
425 | |
426 | /** |
427 | * Sets the status of the BiDi rendering inside the terminal display. |
428 | * Defaults to disabled. |
429 | */ |
430 | void setBidiEnabled(bool set) { |
431 | _bidiEnabled = set; |
432 | } |
433 | /** |
434 | * Returns the status of the BiDi rendering in this widget. |
435 | */ |
436 | bool isBidiEnabled() const { |
437 | return _bidiEnabled; |
438 | } |
439 | |
440 | /** |
441 | * Sets the terminal screen section which is displayed in this widget. |
442 | * When updateImage() is called, the display fetches the latest character image from the |
443 | * the associated terminal screen window. |
444 | * |
445 | * In terms of the model-view paradigm, the ScreenWindow is the model which is rendered |
446 | * by the TerminalDisplay. |
447 | */ |
448 | void setScreenWindow(ScreenWindow* window); |
449 | /** Returns the terminal screen section which is displayed in this widget. See setScreenWindow() */ |
450 | ScreenWindow* screenWindow() const; |
451 | |
452 | // Select the current line. |
453 | void selectCurrentLine(); |
454 | |
455 | void printContent(QPainter& painter, bool friendly); |
456 | |
457 | public slots: |
458 | /** |
459 | * Scrolls current ScreenWindow |
460 | * |
461 | * it's needed for proper handling scroll commands in the Vt102Emulation class |
462 | */ |
463 | void scrollScreenWindow(enum ScreenWindow::RelativeScrollMode mode , int amount); |
464 | |
465 | /** |
466 | * Causes the terminal display to fetch the latest character image from the associated |
467 | * terminal screen ( see setScreenWindow() ) and redraw the display. |
468 | */ |
469 | void updateImage(); |
470 | /** |
471 | * Causes the terminal display to fetch the latest line status flags from the |
472 | * associated terminal screen ( see setScreenWindow() ). |
473 | */ |
474 | void updateLineProperties(); |
475 | |
476 | void setAutoCopySelectedText(bool enabled); |
477 | |
478 | void setMiddleClickPasteMode(Enum::MiddleClickPasteModeEnum mode); |
479 | |
480 | /** Copies the selected text to the X11 Selection. */ |
481 | void copyToX11Selection(); |
482 | |
483 | /** Copies the selected text to the system clipboard. */ |
484 | void copyToClipboard(); |
485 | |
486 | /** |
487 | * Pastes the content of the clipboard into the |
488 | * display. |
489 | */ |
490 | void pasteFromClipboard(bool appendEnter = false); |
491 | /** |
492 | * Pastes the content of the X11 selection into the |
493 | * display. |
494 | */ |
495 | void pasteFromX11Selection(bool appendEnter = false); |
496 | |
497 | /** |
498 | * Changes whether the flow control warning box should be shown when the flow control |
499 | * stop key (Ctrl+S) are pressed. |
500 | */ |
501 | void setFlowControlWarningEnabled(bool enabled); |
502 | /** |
503 | * Returns true if the flow control warning box is enabled. |
504 | * See outputSuspended() and setFlowControlWarningEnabled() |
505 | */ |
506 | bool flowControlWarningEnabled() const { |
507 | return _flowControlWarningEnabled; |
508 | } |
509 | |
510 | /** |
511 | * Causes the widget to display or hide a message informing the user that terminal |
512 | * output has been suspended (by using the flow control key combination Ctrl+S) |
513 | * |
514 | * @param suspended True if terminal output has been suspended and the warning message should |
515 | * be shown or false to indicate that terminal output has been resumed and that |
516 | * the warning message should disappear. |
517 | */ |
518 | void outputSuspended(bool suspended); |
519 | |
520 | /** |
521 | * Sets whether the program whose output is being displayed in the view |
522 | * is interested in mouse events. |
523 | * |
524 | * If this is set to true, mouse signals will be emitted by the view when the user clicks, drags |
525 | * or otherwise moves the mouse inside the view. |
526 | * The user interaction needed to create selections will also change, and the user will be required |
527 | * to hold down the shift key to create a selection or perform other mouse activities inside the |
528 | * view area - since the program running in the terminal is being allowed to handle normal mouse |
529 | * events itself. |
530 | * |
531 | * @param usesMouse Set to true if the program running in the terminal is interested in mouse events |
532 | * or false otherwise. |
533 | */ |
534 | void setUsesMouse(bool usesMouse); |
535 | |
536 | /** See setUsesMouse() */ |
537 | bool usesMouse() const; |
538 | |
539 | void setBracketedPasteMode(bool bracketedPasteMode); |
540 | bool bracketedPasteMode() const; |
541 | |
542 | /** |
543 | * Shows a notification that a bell event has occurred in the terminal. |
544 | * TODO: More documentation here |
545 | */ |
546 | void bell(const QString& message); |
547 | |
548 | /** |
549 | * Gets the background of the display |
550 | * @see setBackgroundColor(), setColorTable(), setForegroundColor() |
551 | */ |
552 | QColor getBackgroundColor() const; |
553 | |
554 | /** |
555 | * Sets the background of the display to the specified color. |
556 | * @see setColorTable(), getBackgroundColor(), setForegroundColor() |
557 | */ |
558 | void setBackgroundColor(const QColor& color); |
559 | |
560 | /** |
561 | * Sets the text of the display to the specified color. |
562 | * @see setColorTable(), setBackgroundColor(), getBackgroundColor() |
563 | */ |
564 | void setForegroundColor(const QColor& color); |
565 | |
566 | /** |
567 | * Sets the display's contents margins. |
568 | */ |
569 | void setMargin(int margin); |
570 | |
571 | /** |
572 | * Sets whether the contents are centered between the margins. |
573 | */ |
574 | void setCenterContents(bool enable); |
575 | |
576 | signals: |
577 | |
578 | /** |
579 | * Emitted when the user presses a key whilst the terminal widget has focus. |
580 | */ |
581 | void keyPressedSignal(QKeyEvent* event); |
582 | |
583 | /** |
584 | * A mouse event occurred. |
585 | * @param button The mouse button (0 for left button, 1 for middle button, 2 for right button, 3 for release) |
586 | * @param column The character column where the event occurred |
587 | * @param line The character row where the event occurred |
588 | * @param eventType The type of event. 0 for a mouse press / release or 1 for mouse motion |
589 | */ |
590 | void mouseSignal(int button, int column, int line, int eventType); |
591 | void changedFontMetricSignal(int height, int width); |
592 | void changedContentSizeSignal(int height, int width); |
593 | |
594 | /** |
595 | * Emitted when the user right clicks on the display, or right-clicks with the Shift |
596 | * key held down if usesMouse() is true. |
597 | * |
598 | * This can be used to display a context menu. |
599 | */ |
600 | void configureRequest(const QPoint& position); |
601 | |
602 | /** |
603 | * When a shortcut which is also a valid terminal key sequence is pressed while |
604 | * the terminal widget has focus, this signal is emitted to allow the host to decide |
605 | * whether the shortcut should be overridden. |
606 | * When the shortcut is overridden, the key sequence will be sent to the terminal emulation instead |
607 | * and the action associated with the shortcut will not be triggered. |
608 | * |
609 | * @p override is set to false by default and the shortcut will be triggered as normal. |
610 | */ |
611 | void overrideShortcutCheck(QKeyEvent* keyEvent, bool& override); |
612 | |
613 | void sendStringToEmu(const char*); |
614 | |
615 | protected: |
616 | virtual bool event(QEvent* event); |
617 | |
618 | virtual void paintEvent(QPaintEvent* event); |
619 | |
620 | virtual void showEvent(QShowEvent* event); |
621 | virtual void hideEvent(QHideEvent* event); |
622 | virtual void resizeEvent(QResizeEvent* event); |
623 | |
624 | virtual void (QContextMenuEvent* event); |
625 | |
626 | virtual void fontChange(const QFont&); |
627 | virtual void focusInEvent(QFocusEvent* event); |
628 | virtual void focusOutEvent(QFocusEvent* event); |
629 | virtual void keyPressEvent(QKeyEvent* event); |
630 | virtual void leaveEvent(QEvent* event); |
631 | virtual void mouseDoubleClickEvent(QMouseEvent* event); |
632 | virtual void mousePressEvent(QMouseEvent* event); |
633 | virtual void mouseReleaseEvent(QMouseEvent* event); |
634 | virtual void mouseMoveEvent(QMouseEvent* event); |
635 | virtual void extendSelection(const QPoint& pos); |
636 | virtual void wheelEvent(QWheelEvent* event); |
637 | |
638 | virtual bool focusNextPrevChild(bool next); |
639 | |
640 | // drag and drop |
641 | virtual void dragEnterEvent(QDragEnterEvent* event); |
642 | virtual void dropEvent(QDropEvent* event); |
643 | void doDrag(); |
644 | enum DragState { diNone, diPending, diDragging }; |
645 | |
646 | struct DragInfo { |
647 | DragState state; |
648 | QPoint start; |
649 | QDrag* dragObject; |
650 | } _dragInfo; |
651 | |
652 | // classifies the 'ch' into one of three categories |
653 | // and returns a character to indicate which category it is in |
654 | // |
655 | // - A space (returns ' ') |
656 | // - Part of a word (returns 'a') |
657 | // - Other characters (returns the input character) |
658 | QChar charClass(const Character& ch) const; |
659 | |
660 | void clearImage(); |
661 | |
662 | void mouseTripleClickEvent(QMouseEvent* event); |
663 | void selectLine(QPoint pos, bool entireLine); |
664 | |
665 | // reimplemented |
666 | virtual void inputMethodEvent(QInputMethodEvent* event); |
667 | virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const; |
668 | |
669 | protected slots: |
670 | |
671 | void scrollBarPositionChanged(int value); |
672 | void blinkTextEvent(); |
673 | void blinkCursorEvent(); |
674 | |
675 | private slots: |
676 | |
677 | void unmaskBell(); |
678 | void swapFGBGColors(); |
679 | void tripleClickTimeout(); // resets possibleTripleClick |
680 | void viewScrolledByUser(); |
681 | |
682 | /** |
683 | * Called from the drag-and-drop popup. Causes the dropped URLs to be pasted as text. |
684 | */ |
685 | void (); |
686 | |
687 | void (); |
688 | |
689 | void dismissOutputSuspendedMessage(); |
690 | |
691 | private: |
692 | // -- Drawing helpers -- |
693 | |
694 | // divides the part of the display specified by 'rect' into |
695 | // fragments according to their colors and styles and calls |
696 | // drawTextFragment() or drawPrinterFriendlyTextFragment() |
697 | // to draw the fragments |
698 | void drawContents(QPainter& painter, const QRect& rect); |
699 | // draw a transparent rectangle over the line of the current match |
700 | void drawCurrentResultRect(QPainter& painter); |
701 | // draws a section of text, all the text in this section |
702 | // has a common color and style |
703 | void drawTextFragment(QPainter& painter, const QRect& rect, |
704 | const QString& text, const Character* style); |
705 | |
706 | void drawPrinterFriendlyTextFragment(QPainter& painter, const QRect& rect, |
707 | const QString& text, const Character* style); |
708 | // draws the background for a text fragment |
709 | // if useOpacitySetting is true then the color's alpha value will be set to |
710 | // the display's transparency (set with setOpacity()), otherwise the background |
711 | // will be drawn fully opaque |
712 | void drawBackground(QPainter& painter, const QRect& rect, const QColor& color, |
713 | bool useOpacitySetting); |
714 | // draws the cursor character |
715 | void drawCursor(QPainter& painter, const QRect& rect , const QColor& foregroundColor, |
716 | const QColor& backgroundColor , bool& invertColors); |
717 | // draws the characters or line graphics in a text fragment |
718 | void drawCharacters(QPainter& painter, const QRect& rect, const QString& text, |
719 | const Character* style, bool invertCharacterColor); |
720 | // draws a string of line graphics |
721 | void drawLineCharString(QPainter& painter, int x, int y, |
722 | const QString& str, const Character* attributes); |
723 | |
724 | // draws the preedit string for input methods |
725 | void drawInputMethodPreeditString(QPainter& painter , const QRect& rect); |
726 | |
727 | // -- |
728 | |
729 | // maps an area in the character image to an area on the widget |
730 | QRect imageToWidget(const QRect& imageArea) const; |
731 | |
732 | // maps a point on the widget to the position ( ie. line and column ) |
733 | // of the character at that point. |
734 | void getCharacterPosition(const QPoint& widgetPoint, int& line, int& column) const; |
735 | |
736 | // the area where the preedit string for input methods will be draw |
737 | QRect preeditRect() const; |
738 | |
739 | // shows a notification window in the middle of the widget indicating the terminal's |
740 | // current size in columns and lines |
741 | void showResizeNotification(); |
742 | |
743 | // scrolls the image by a number of lines. |
744 | // 'lines' may be positive ( to scroll the image down ) |
745 | // or negative ( to scroll the image up ) |
746 | // 'region' is the part of the image to scroll - currently only |
747 | // the top, bottom and height of 'region' are taken into account, |
748 | // the left and right are ignored. |
749 | void scrollImage(int lines , const QRect& region); |
750 | |
751 | void calcGeometry(); |
752 | void propagateSize(); |
753 | void updateImageSize(); |
754 | void makeImage(); |
755 | |
756 | void paintFilters(QPainter& painter); |
757 | |
758 | // returns a region covering all of the areas of the widget which contain |
759 | // a hotspot |
760 | QRegion hotSpotRegion() const; |
761 | |
762 | // returns the position of the cursor in columns and lines |
763 | QPoint cursorPosition() const; |
764 | |
765 | // redraws the cursor |
766 | void updateCursor(); |
767 | |
768 | bool handleShortcutOverrideEvent(QKeyEvent* event); |
769 | |
770 | void doPaste(QString text, bool appendReturn); |
771 | |
772 | void processMidButtonClick(QMouseEvent* event); |
773 | |
774 | QPoint findLineStart(const QPoint &pnt); |
775 | QPoint findLineEnd(const QPoint &pnt); |
776 | QPoint findWordStart(const QPoint &pnt); |
777 | QPoint findWordEnd(const QPoint &pnt); |
778 | |
779 | // the window onto the terminal screen which this display |
780 | // is currently showing. |
781 | QPointer<ScreenWindow> _screenWindow; |
782 | |
783 | bool _bellMasked; |
784 | |
785 | QGridLayout* _gridLayout; |
786 | |
787 | bool _fixedFont; // has fixed pitch |
788 | int _fontHeight; // height |
789 | int _fontWidth; // width |
790 | int _fontAscent; // ascend |
791 | bool _boldIntense; // Whether intense colors should be rendered with bold font |
792 | |
793 | int _leftMargin; // offset |
794 | int _topMargin; // offset |
795 | |
796 | int _lines; // the number of lines that can be displayed in the widget |
797 | int _columns; // the number of columns that can be displayed in the widget |
798 | |
799 | int _usedLines; // the number of lines that are actually being used, this will be less |
800 | // than 'lines' if the character image provided with setImage() is smaller |
801 | // than the maximum image size which can be displayed |
802 | |
803 | int _usedColumns; // the number of columns that are actually being used, this will be less |
804 | // than 'columns' if the character image provided with setImage() is smaller |
805 | // than the maximum image size which can be displayed |
806 | |
807 | QRect _contentRect; |
808 | Character* _image; // [lines][columns] |
809 | // only the area [usedLines][usedColumns] in the image contains valid data |
810 | |
811 | int _imageSize; |
812 | QVector<LineProperty> _lineProperties; |
813 | |
814 | ColorEntry _colorTable[TABLE_COLORS]; |
815 | uint _randomSeed; |
816 | |
817 | bool _resizing; |
818 | bool _showTerminalSizeHint; |
819 | bool _bidiEnabled; |
820 | bool _mouseMarks; |
821 | bool _bracketedPasteMode; |
822 | |
823 | QPoint _iPntSel; // initial selection point |
824 | QPoint _pntSel; // current selection point |
825 | QPoint _tripleSelBegin; // help avoid flicker |
826 | int _actSel; // selection state |
827 | bool _wordSelectionMode; |
828 | bool _lineSelectionMode; |
829 | bool _preserveLineBreaks; |
830 | bool _columnSelectionMode; |
831 | |
832 | bool _autoCopySelectedText; |
833 | Enum::MiddleClickPasteModeEnum _middleClickPasteMode; |
834 | |
835 | QScrollBar* _scrollBar; |
836 | Enum::ScrollBarPositionEnum _scrollbarLocation; |
837 | bool _scrollFullPage; |
838 | QString _wordCharacters; |
839 | int _bellMode; |
840 | |
841 | bool _allowBlinkingText; // allow text to blink |
842 | bool _allowBlinkingCursor; // allow cursor to blink |
843 | bool _textBlinking; // text is blinking, hide it when drawing |
844 | bool _cursorBlinking; // cursor is blinking, hide it when drawing |
845 | bool _hasTextBlinker; // has characters to blink |
846 | QTimer* _blinkTextTimer; |
847 | QTimer* _blinkCursorTimer; |
848 | |
849 | bool _underlineLinks; // Underline URL and hosts on mouse hover |
850 | bool _openLinksByDirectClick; // Open URL and hosts by single mouse click |
851 | |
852 | bool _ctrlRequiredForDrag; // require Ctrl key for drag selected text |
853 | |
854 | Enum::TripleClickModeEnum _tripleClickMode; |
855 | bool _possibleTripleClick; // is set in mouseDoubleClickEvent and deleted |
856 | // after QApplication::doubleClickInterval() delay |
857 | |
858 | QLabel* _resizeWidget; |
859 | QTimer* _resizeTimer; |
860 | |
861 | bool _flowControlWarningEnabled; |
862 | |
863 | //widgets related to the warning message that appears when the user presses Ctrl+S to suspend |
864 | //terminal output - informing them what has happened and how to resume output |
865 | QLabel* _outputSuspendedLabel; |
866 | |
867 | uint _lineSpacing; |
868 | |
869 | QSize _size; |
870 | |
871 | QRgb _blendColor; |
872 | |
873 | ColorSchemeWallpaper::Ptr _wallpaper; |
874 | |
875 | // list of filters currently applied to the display. used for links and |
876 | // search highlight |
877 | TerminalImageFilterChain* _filterChain; |
878 | QRegion _mouseOverHotspotArea; |
879 | |
880 | Enum::CursorShapeEnum _cursorShape; |
881 | |
882 | // cursor color. If it is invalid (by default) then the foreground |
883 | // color of the character under the cursor is used |
884 | QColor _cursorColor; |
885 | |
886 | struct InputMethodData { |
887 | QString preeditString; |
888 | QRect previousPreeditRect; |
889 | }; |
890 | InputMethodData _inputMethodData; |
891 | |
892 | bool _antialiasText; // do we anti-alias or not |
893 | |
894 | bool _printerFriendly; // are we currently painting to a printer in black/white mode |
895 | |
896 | //the delay in milliseconds between redrawing blinking text |
897 | static const int TEXT_BLINK_DELAY = 500; |
898 | |
899 | //the duration of the size hint in milliseconds |
900 | static const int SIZE_HINT_DURATION = 1000; |
901 | |
902 | SessionController* _sessionController; |
903 | |
904 | bool _trimTrailingSpaces; // trim trailing spaces in selected text |
905 | bool _mouseWheelZoom; // enable mouse wheel zooming or not |
906 | |
907 | int _margin; // the contents margin |
908 | bool _centerContents; // center the contents between margins |
909 | |
910 | qreal _opacity; |
911 | |
912 | friend class TerminalDisplayAccessible; |
913 | }; |
914 | |
915 | class AutoScrollHandler : public QObject |
916 | { |
917 | Q_OBJECT |
918 | |
919 | public: |
920 | explicit AutoScrollHandler(QWidget* parent); |
921 | protected: |
922 | virtual void timerEvent(QTimerEvent* event); |
923 | virtual bool eventFilter(QObject* watched, QEvent* event); |
924 | private: |
925 | QWidget* widget() const { |
926 | return static_cast<QWidget*>(parent()); |
927 | } |
928 | int _timerId; |
929 | }; |
930 | } |
931 | |
932 | #endif // TERMINALDISPLAY_H |
933 | |