Debian Codegraph @

lib/TerminalDisplay.h

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 4 — not the installed (fully patched) source.
4 Debian patches touch this file
1 /*
2 Copyright 2007-2008 by Robert Knight <[email protected]>
3 Copyright 1997,1998 by Lars Doelle <[email protected]>
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 <QColor>
26 #include <QPointer>
27 //#include <QWidget>
28 #include <QQuickPaintedItem>
29
30 // Konsole
31 #include "Filter.h"
32 #include "Character.h"
33 #include "qtermwidget.h"
34 //#include "konsole_export.h"
35 #define KONSOLEPRIVATE_EXPORT
36
37 // QMLTermWidget
38 #include "ksession.h"
39 #include "ColorScheme.h"
40
41 class QDrag;
42 class QDragEnterEvent;
43 class QDropEvent;
44 class QLabel;
45 class QTimer;
46 class QEvent;
47 class QGridLayout;
48 class QKeyEvent;
49 class QScrollBar;
50 class QShowEvent;
51 class QHideEvent;
52 class QTimerEvent;
53 class QWidget;
54
55 //class KMenu;
56
57 namespace Konsole
58 {
59
60 enum MotionAfterPasting
61 {
62 // No move screenwindow after pasting
63 NoMoveScreenWindow = 0,
64 // Move start of screenwindow after pasting
65 MoveStartScreenWindow = 1,
66 // Move end of screenwindow after pasting
67 MoveEndScreenWindow = 2
68 };
69
70 enum BackgroundMode {
71 None,
72 Stretch,
73 Zoom,
74 Fit,
75 Center
76 };
77
78 extern unsigned short vt100_graphics[32];
79
80 class ScreenWindow;
81
82 /**
83 * A widget which displays output from a terminal emulation and sends input keypresses and mouse activity
84 * to the terminal.
85 *
86 * When the terminal emulation receives new output from the program running in the terminal,
87 * it will update the display by calling updateImage().
88 *
89 * TODO More documentation
90 */
91 class KONSOLEPRIVATE_EXPORT TerminalDisplay : public QQuickPaintedItem
92 {
93 Q_OBJECT
94 Q_PROPERTY(KSession* session READ getSession WRITE setSession NOTIFY sessionChanged )
95 Q_PROPERTY(QFont font READ getVTFont WRITE setVTFont NOTIFY vtFontChanged )
96 Q_PROPERTY(QString colorScheme READ colorScheme WRITE setColorScheme NOTIFY colorSchemeChanged )
97 Q_PROPERTY(QSize terminalSize READ getTerminalSize NOTIFY changedContentSizeSignal)
98 Q_PROPERTY(int lineSpacing READ lineSpacing WRITE setLineSpacing NOTIFY lineSpacingChanged )
99 Q_PROPERTY(bool terminalUsesMouse READ getUsesMouse NOTIFY usesMouseChanged )
100 Q_PROPERTY(int lines READ lines NOTIFY changedContentSizeSignal)
101 Q_PROPERTY(int columns READ columns NOTIFY changedContentSizeSignal)
102 Q_PROPERTY(int scrollbarCurrentValue READ getScrollbarValue NOTIFY scrollbarParamsChanged )
103 Q_PROPERTY(int scrollbarMaximum READ getScrollbarMaximum NOTIFY scrollbarParamsChanged )
104 Q_PROPERTY(int scrollbarMinimum READ getScrollbarMinimum NOTIFY scrollbarParamsChanged )
105 Q_PROPERTY(QSize fontMetrics READ getFontMetrics NOTIFY changedFontMetricSignal )
106
107 Q_PROPERTY(bool enableBold READ getBoldIntense WRITE setBoldIntense NOTIFY boldIntenseChanged )
108 Q_PROPERTY(bool fullCursorHeight READ fullCursorHeight WRITE setFullCursorHeight NOTIFY fullCursorHeightChanged)
109 Q_PROPERTY(bool blinkingCursor READ blinkingCursor WRITE setBlinkingCursor NOTIFY blinkingCursorStateChanged)
110 Q_PROPERTY(bool antialiasText READ antialias WRITE setAntialias)
111 Q_PROPERTY(QStringList availableColorSchemes READ availableColorSchemes NOTIFY availableColorSchemesChanged)
112
113 public:
114 /** Constructs a new terminal display widget with the specified parent. */
115 TerminalDisplay(QQuickItem *parent=0);
116 virtual ~TerminalDisplay();
117
118 /** Returns the terminal color palette used by the display. */
119 const ColorEntry* colorTable() const;
120 /** Sets the terminal color palette used by the display. */
121 void setColorTable(const ColorEntry table[]);
122 /**
123 * Sets the seed used to generate random colors for the display
124 * (in color schemes that support them).
125 */
126 void setRandomSeed(uint seed);
127 /**
128 * Returns the seed used to generate random colors for the display
129 * (in color schemes that support them).
130 */
131 uint randomSeed() const;
132
133 /** Sets the opacity of the terminal display. */
134 void setOpacity(qreal opacity);
135
136 /**
137 * This enum describes the location where the scroll bar is positioned in the display widget.
138 */
139 enum ScrollBarPosition
140 {
141 /** Do not show the scroll bar. */
142 NoScrollBar=0,
143 /** Show the scroll bar on the left side of the display. */
144 ScrollBarLeft=1,
145 /** Show the scroll bar on the right side of the display. */
146 ScrollBarRight=2
147 };
148 /**
149
150 /** Sets the background image of the terminal display. */
151 void setBackgroundImage(const QString& backgroundImage);
152
153 /** Sets the background image mode of the terminal display. */
154 void setBackgroundMode(BackgroundMode mode);
155
156 /**
157 * Specifies whether the terminal display has a vertical scroll bar, and if so whether it
158 * is shown on the left or right side of the display.
159 */
160 void setScrollBarPosition(QTermWidget::ScrollBarPosition position);
161
162 /**
163 * Sets the current position and range of the display's scroll bar.
164 *
165 * @param cursor The position of the scroll bar's thumb.
166 * @param lines The maximum value of the scroll bar.
167 */
168 void setScroll(int cursor, int lines);
169
170 /**
171 * Scroll to the bottom of the terminal (reset scrolling).
172 */
173 void scrollToEnd();
174
175 /**
176 * Returns the display's filter chain. When the image for the display is updated,
177 * the text is passed through each filter in the chain. Each filter can define
178 * hotspots which correspond to certain strings (such as URLs or particular words).
179 * Depending on the type of the hotspots created by the filter ( returned by Filter::Hotspot::type() )
180 * the view will draw visual cues such as underlines on mouse-over for links or translucent
181 * rectangles for markers.
182 *
183 * To add a new filter to the view, call:
184 * viewWidget->filterChain()->addFilter( filterObject );
185 */
186 FilterChain* filterChain() const;
187
188 /**
189 * Updates the filters in the display's filter chain. This will cause
190 * the hotspots to be updated to match the current image.
191 *
192 * WARNING: This function can be expensive depending on the
193 * image size and number of filters in the filterChain()
194 *
195 * TODO - This API does not really allow efficient usage. Revise it so
196 * that the processing can be done in a better way.
197 *
198 * eg:
199 * - Area of interest may be known ( eg. mouse cursor hovering
200 * over an area )
201 */
202 void processFilters();
203
204 /**
205 * Returns a list of menu actions created by the filters for the content
206 * at the given @p position.
207 */
208 QList<QAction*> filterActions(const QPoint& position);
209
210 /** Returns true if the cursor is set to blink or false otherwise. */
211 bool blinkingCursor() { return _hasBlinkingCursor; }
212 /** Specifies whether or not the cursor blinks. */
213 void setBlinkingCursor(bool blink);
214
215 /** Specifies whether or not text can blink. */
216 void setBlinkingTextEnabled(bool blink);
217
218 void setCtrlDrag(bool enable) { _ctrlDrag=enable; }
219 bool ctrlDrag() { return _ctrlDrag; }
220
221 /**
222 * This enum describes the methods for selecting text when
223 * the user triple-clicks within the display.
224 */
225 enum TripleClickMode
226 {
227 /** Select the whole line underneath the cursor. */
228 SelectWholeLine,
229 /** Select from the current cursor position to the end of the line. */
230 SelectForwardsFromCursor
231 };
232 /** Sets how the text is selected when the user triple clicks within the display. */
233 void setTripleClickMode(TripleClickMode mode) { _tripleClickMode = mode; }
234 /** See setTripleClickSelectionMode() */
235 TripleClickMode tripleClickMode() { return _tripleClickMode; }
236
237 void setLineSpacing(uint);
238 void setMargin(int);
239
240 int margin() const;
241 uint lineSpacing() const;
242
243 void emitSelection(bool useXselection,bool appendReturn);
244
245 /** change and wrap text corresponding to paste mode **/
246 void bracketText(QString& text) const;
247
248 /**
249 * Sets the shape of the keyboard cursor. This is the cursor drawn
250 * at the position in the terminal where keyboard input will appear.
251 *
252 * In addition the terminal display widget also has a cursor for
253 * the mouse pointer, which can be set using the QWidget::setCursor()
254 * method.
255 *
256 * Defaults to BlockCursor
257 */
258 void setKeyboardCursorShape(QTermWidget::KeyboardCursorShape shape);
259 /**
260 * Returns the shape of the keyboard cursor. See setKeyboardCursorShape()
261 */
262 QTermWidget::KeyboardCursorShape keyboardCursorShape() const;
263
264 /**
265 * Sets the color used to draw the keyboard cursor.
266 *
267 * The keyboard cursor defaults to using the foreground color of the character
268 * underneath it.
269 *
270 * @param useForegroundColor If true, the cursor color will change to match
271 * the foreground color of the character underneath it as it is moved, in this
272 * case, the @p color parameter is ignored and the color of the character
273 * under the cursor is inverted to ensure that it is still readable.
274 * @param color The color to use to draw the cursor. This is only taken into
275 * account if @p useForegroundColor is false.
276 */
277 void setKeyboardCursorColor(bool useForegroundColor , const QColor& color);
278
279 /**
280 * Returns the color of the keyboard cursor, or an invalid color if the keyboard
281 * cursor color is set to change according to the foreground color of the character
282 * underneath it.
283 */
284 QColor keyboardCursorColor() const;
285
286 /**
287 * Returns the number of lines of text which can be displayed in the widget.
288 *
289 * This will depend upon the height of the widget and the current font.
290 * See fontHeight()
291 */
292 int lines() { return _lines; }
293 /**
294 * Returns the number of characters of text which can be displayed on
295 * each line in the widget.
296 *
297 * This will depend upon the width of the widget and the current font.
298 * See fontWidth()
299 */
300 int columns() { return _columns; }
301
302 /**
303 * Returns the height of the characters in the font used to draw the text in the display.
304 */
305 int fontHeight() { return _fontHeight; }
306 /**
307 * Returns the width of the characters in the display.
308 * This assumes the use of a fixed-width font.
309 */
310 int fontWidth() { return _fontWidth; }
311
312 void setSize(int cols, int lins);
313 void setFixedSize(int cols, int lins);
314
315 // reimplemented
316 QSize sizeHint() const;
317
318 /**
319 * Sets which characters, in addition to letters and numbers,
320 * are regarded as being part of a word for the purposes
321 * of selecting words in the display by double clicking on them.
322 *
323 * The word boundaries occur at the first and last characters which
324 * are either a letter, number, or a character in @p wc
325 *
326 * @param wc An array of characters which are to be considered parts
327 * of a word ( in addition to letters and numbers ).
328 */
329 void setWordCharacters(const QString& wc);
330 /**
331 * Returns the characters which are considered part of a word for the
332 * purpose of selecting words in the display with the mouse.
333 *
334 * @see setWordCharacters()
335 */
336 QString wordCharacters() { return _wordCharacters; }
337
338 /**
339 * Sets the type of effect used to alert the user when a 'bell' occurs in the
340 * terminal session.
341 *
342 * The terminal session can trigger the bell effect by calling bell() with
343 * the alert message.
344 */
345 void setBellMode(int mode);
346 /**
347 * Returns the type of effect used to alert the user when a 'bell' occurs in
348 * the terminal session.
349 *
350 * See setBellMode()
351 */
352 int bellMode() { return _bellMode; }
353
354 /**
355 * This enum describes the different types of sounds and visual effects which
356 * can be used to alert the user when a 'bell' occurs in the terminal
357 * session.
358 */
359 enum BellMode
360 {
361 /** A system beep. */
362 SystemBeepBell=0,
363 /**
364 * KDE notification. This may play a sound, show a passive popup
365 * or perform some other action depending on the user's settings.
366 */
367 NotifyBell=1,
368 /** A silent, visual bell (eg. inverting the display's colors briefly) */
369 VisualBell=2,
370 /** No bell effects */
371 NoBell=3
372 };
373
374 void setSelection(const QString &t);
375
376 /**
377 * Reimplemented. Has no effect. Use setVTFont() to change the font
378 * used to draw characters in the display.
379 */
380 virtual void setFont(const QFont &);
381
382 /** Returns the font used to draw characters in the display */
383 QFont getVTFont() { return font(); }
384
385 /**
386 * Sets the font used to draw the display. Has no effect if @p font
387 * is larger than the size of the display itself.
388 */
389 void setVTFont(const QFont& font);
390
391 /**
392 * Specified whether anti-aliasing of text in the terminal display
393 * is enabled or not. Defaults to enabled.
394 */
395 static void setAntialias( bool antialias ) { _antialiasText = antialias; }
396 /**
397 * Returns true if anti-aliasing of text in the terminal is enabled.
398 */
399 static bool antialias() { return _antialiasText; }
400
401 /**
402 * Specify whether line chars should be drawn by ourselves or left to
403 * underlying font rendering libraries.
404 */
405 void setDrawLineChars(bool drawLineChars) { _drawLineChars = drawLineChars; }
406
407 /**
408 * Specifies whether characters with intense colors should be rendered
409 * as bold. Defaults to true.
410 */
411 void setBoldIntense(bool value);
412 /**
413 * Returns true if characters with intense colors are rendered in bold.
414 */
415 bool getBoldIntense() { return _boldIntense; }
416
417 /**
418 * Sets whether or not the current height and width of the
419 * terminal in lines and columns is displayed whilst the widget
420 * is being resized.
421 */
422 void setTerminalSizeHint(bool on) { _terminalSizeHint=on; }
423 /**
424 * Returns whether or not the current height and width of
425 * the terminal in lines and columns is displayed whilst the widget
426 * is being resized.
427 */
428 bool terminalSizeHint() { return _terminalSizeHint; }
429 /**
430 * Sets whether the terminal size display is shown briefly
431 * after the widget is first shown.
432 *
433 * See setTerminalSizeHint() , isTerminalSizeHint()
434 */
435 void setTerminalSizeStartup(bool on) { _terminalSizeStartup=on; }
436
437 /**
438 * Sets the status of the BiDi rendering inside the terminal display.
439 * Defaults to disabled.
440 */
441 void setBidiEnabled(bool set) { _bidiEnabled=set; }
442 /**
443 * Returns the status of the BiDi rendering in this widget.
444 */
445 bool isBidiEnabled() { return _bidiEnabled; }
446
447 /**
448 * Sets the terminal screen section which is displayed in this widget.
449 * When updateImage() is called, the display fetches the latest character image from the
450 * the associated terminal screen window.
451 *
452 * In terms of the model-view paradigm, the ScreenWindow is the model which is rendered
453 * by the TerminalDisplay.
454 */
455 void setScreenWindow( ScreenWindow* window );
456 /** Returns the terminal screen section which is displayed in this widget. See setScreenWindow() */
457 ScreenWindow* screenWindow() const;
458
459 static bool HAVE_TRANSPARENCY;
460
461 void setMotionAfterPasting(MotionAfterPasting action);
462 int motionAfterPasting();
463 void setConfirmMultilinePaste(bool confirmMultilinePaste);
464 void setTrimPastedTrailingNewlines(bool trimPastedTrailingNewlines);
465
466 // maps a point on the widget to the position ( ie. line and column )
467 // of the character at that point.
468
469 void getCharacterPosition(const QPoint& widgetPoint,int& line,int& column) const;
470
471 void disableBracketedPasteMode(bool disable) { _disabledBracketedPasteMode = disable; }
472 bool bracketedPasteModeIsDisabled() const { return _disabledBracketedPasteMode; }
473
474 public slots:
475
476 /**
477 * Causes the terminal display to fetch the latest character image from the associated
478 * terminal screen ( see setScreenWindow() ) and redraw the display.
479 */
480 void updateImage();
481
482 /** Essentially calles processFilters().
483 */
484 void updateFilters();
485
486 /**
487 * Causes the terminal display to fetch the latest line status flags from the
488 * associated terminal screen ( see setScreenWindow() ).
489 */
490 void updateLineProperties();
491
492 /** Copies the selected text to the clipboard. */
493 void copyClipboard();
494 /**
495 * Pastes the content of the clipboard into the
496 * display.
497 */
498 void pasteClipboard();
499 /**
500 * Pastes the content of the selection into the
501 * display.
502 */
503 void pasteSelection();
504
505 /**
506 * Changes whether the flow control warning box should be shown when the flow control
507 * stop key (Ctrl+S) are pressed.
508 */
509 void setFlowControlWarningEnabled(bool enabled);
510 /**
511 * Returns true if the flow control warning box is enabled.
512 * See outputSuspended() and setFlowControlWarningEnabled()
513 */
514 bool flowControlWarningEnabled() const
515 { return _flowControlWarningEnabled; }
516
517 /**
518 * Causes the widget to display or hide a message informing the user that terminal
519 * output has been suspended (by using the flow control key combination Ctrl+S)
520 *
521 * @param suspended True if terminal output has been suspended and the warning message should
522 * be shown or false to indicate that terminal output has been resumed and that
523 * the warning message should disappear.
524 */
525 void outputSuspended(bool suspended);
526
527 /**
528 * Sets whether the program whoose output is being displayed in the view
529 * is interested in mouse events.
530 *
531 * If this is set to true, mouse signals will be emitted by the view when the user clicks, drags
532 * or otherwise moves the mouse inside the view.
533 * The user interaction needed to create selections will also change, and the user will be required
534 * to hold down the shift key to create a selection or perform other mouse activities inside the
535 * view area - since the program running in the terminal is being allowed to handle normal mouse
536 * events itself.
537 *
538 * @param usesMouse Set to true if the program running in the terminal is interested in mouse events
539 * or false otherwise.
540 */
541 void setUsesMouse(bool usesMouse);
542
543 /** See setUsesMouse() */
544 bool usesMouse() const;
545
546 void setBracketedPasteMode(bool bracketedPasteMode);
547 bool bracketedPasteMode() const;
548
549 /**
550 * Shows a notification that a bell event has occurred in the terminal.
551 * TODO: More documentation here
552 */
553 void bell(const QString& message);
554
555 /**
556 * Sets the background of the display to the specified color.
557 * @see setColorTable(), setForegroundColor()
558 */
559 void setBackgroundColor(const QColor& color);
560
561 /**
562 * Sets the text of the display to the specified color.
563 * @see setColorTable(), setBackgroundColor()
564 */
565 void setForegroundColor(const QColor& color);
566
567 void selectionChanged();
568
569 // QMLTermWidget
570 void setColorScheme(const QString &name);
571 QString colorScheme() const;
572 QStringList availableColorSchemes();
573
574 void simulateKeyPress(int key, int modifiers, bool pressed, quint32 nativeScanCode, const QString &text);
575 void simulateKeySequence(const QKeySequence &sequence);
576 void simulateWheel(int x, int y, int buttons, int modifiers, QPointF angleDelta);
577 void simulateMouseMove(int x, int y, int button, int buttons, int modifiers);
578 void simulateMousePress(int x, int y, int button, int buttons, int modifiers);
579 void simulateMouseRelease(int x, int y, int button, int buttons, int modifiers);
580 void simulateMouseDoubleClick(int x, int y, int button, int buttons, int modifiers);
581
582 signals:
583
584 /**
585 * Emitted when the user presses a key whilst the terminal widget has focus.
586 */
587 void keyPressedSignal(QKeyEvent *e, bool fromPaste);
588
589 /**
590 * A mouse event occurred.
591 * @param button The mouse button (0 for left button, 1 for middle button, 2 for right button, 3 for release)
592 * @param column The character column where the event occurred
593 * @param line The character row where the event occurred
594 * @param eventType The type of event. 0 for a mouse press / release or 1 for mouse motion
595 */
596 void mouseSignal(int button, int column, int line, int eventType);
597 void changedFontMetricSignal(int height, int width);
598 void changedContentSizeSignal(int height, int width);
599
600 /**
601 * Emitted when the user right clicks on the display, or right-clicks with the Shift
602 * key held down if usesMouse() is true.
603 *
604 * This can be used to display a context menu.
605 */
606 void configureRequest(const QPoint& position);
607
608 /**
609 * When a shortcut which is also a valid terminal key sequence is pressed while
610 * the terminal widget has focus, this signal is emitted to allow the host to decide
611 * whether the shortcut should be overridden.
612 * When the shortcut is overridden, the key sequence will be sent to the terminal emulation instead
613 * and the action associated with the shortcut will not be triggered.
614 *
615 * @p override is set to false by default and the shortcut will be triggered as normal.
616 */
617 void overrideShortcutCheck(QKeyEvent* keyEvent,bool& override);
618
619 void isBusySelecting(bool busy);
620 void sendStringToEmu(const char*);
621
622 // qtermwidget signals
623 void copyAvailable(bool available);
624 void termGetFocus();
625 void termLostFocus();
626
627 void notifyBell(const QString& bell);
628 void usesMouseChanged();
629
630 // QMLTermWidget
631 void sessionChanged();
632 void sizeChanged();
633 void imagePainted();
634 void scrollbarValueChanged();
635 void scrollbarParamsChanged(int value);
636 void vtFontChanged();
637 void lineSpacingChanged();
638 void availableColorSchemesChanged();
639 void colorSchemeChanged();
640 void fullCursorHeightChanged();
641 void blinkingCursorStateChanged();
642 void boldIntenseChanged();
643
644 protected:
645 bool event( QEvent * ) override;
646
647 void showEvent(QShowEvent*);
648 void hideEvent(QHideEvent*);
649 void resizeEvent(QResizeEvent*);
650
651 virtual void fontChange(const QFont &font);
652 void focusInEvent(QFocusEvent* event) override;
653 void focusOutEvent(QFocusEvent* event) override;
654 void keyPressEvent(QKeyEvent* event) override;
655 void mouseDoubleClickEvent(QMouseEvent* ev) override;
656 void mousePressEvent( QMouseEvent* ) override;
657 void mouseReleaseEvent( QMouseEvent* ) override;
658 void mouseMoveEvent( QMouseEvent* ) override;
659 virtual void extendSelection( const QPoint& pos );
660 void wheelEvent( QWheelEvent* ) override;
661
662 bool focusNextPrevChild( bool next );
663
664 // drag and drop
665 void dragEnterEvent(QDragEnterEvent* event) override;
666 void dropEvent(QDropEvent* event) override;
667 void doDrag();
668 enum DragState { diNone, diPending, diDragging };
669
670 struct _dragInfo {
671 DragState state;
672 QPoint start;
673 QDrag *dragObject;
674 } dragInfo;
675
676 // classifies the 'ch' into one of three categories
677 // and returns a character to indicate which category it is in
678 //
679 // - A space (returns ' ')
680 // - Part of a word (returns 'a')
681 // - Other characters (returns the input character)
682 QChar charClass(QChar ch) const;
683
684 void clearImage();
685
686 void mouseTripleClickEvent(QMouseEvent* ev);
687
688 // reimplemented
689 void inputMethodEvent ( QInputMethodEvent* event ) override;
690 QVariant inputMethodQuery( Qt::InputMethodQuery query ) const override;
691
692 // QMLTermWidget
693 void paint(QPainter * painter);
694 virtual void geometryChanged(const QRectF & newGeometry, const QRectF & oldGeometry);
695 void inputMethodQuery(QInputMethodQueryEvent *event);
696 void itemChange(ItemChange change, const ItemChangeData & value);
697
698 protected slots:
699
700 void scrollBarPositionChanged(int value);
701 void blinkEvent();
702 void blinkCursorEvent();
703
704 //Renables bell noises and visuals. Used to disable further bells for a short period of time
705 //after emitting the first in a sequence of bell events.
706 void enableBell();
707
708 private slots:
709
710 void swapColorTable();
711 void tripleClickTimeout(); // resets possibleTripleClick
712
713 private:
714
715 // -- Drawing helpers --
716
717 // determine the width of this text
718 int textWidth(int startColumn, int length, int line) const;
719 // determine the area that encloses this series of characters
720 QRect calculateTextArea(int topLeftX, int topLeftY, int startColumn, int line, int length);
721
722 // divides the part of the display specified by 'rect' into
723 // fragments according to their colors and styles and calls
724 // drawTextFragment() to draw the fragments
725 void drawContents(QPainter &paint, const QRect &rect);
726 // draws a section of text, all the text in this section
727 // has a common color and style
728 void drawTextFragment(QPainter& painter, const QRect& rect,
729 const std::wstring& text, const Character* style);
730 // draws the background for a text fragment
731 // if useOpacitySetting is true then the color's alpha value will be set to
732 // the display's transparency (set with setOpacity()), otherwise the background
733 // will be drawn fully opaque
734 void drawBackground(QPainter& painter, const QRect& rect, const QColor& color,
735 bool useOpacitySetting);
736 // draws the cursor character
737 void drawCursor(QPainter& painter, const QRect& rect , const QColor& foregroundColor,
738 const QColor& backgroundColor , bool& invertColors);
739 // draws the characters or line graphics in a text fragment
740 void drawCharacters(QPainter& painter, const QRect& rect, const std::wstring& text,
741 const Character* style, bool invertCharacterColor);
742 // draws a string of line graphics
743 void drawLineCharString(QPainter& painter, int x, int y,
744 const std::wstring& str, const Character* attributes) const;
745
746 // draws the preedit string for input methods
747 void drawInputMethodPreeditString(QPainter& painter , const QRect& rect);
748
749 // --
750
751 // maps an area in the character image to an area on the widget
752 QRect imageToWidget(const QRect& imageArea) const;
753
754 // the area where the preedit string for input methods will be draw
755 QRect preeditRect() const;
756
757 // shows a notification window in the middle of the widget indicating the terminal's
758 // current size in columns and lines
759 void showResizeNotification();
760
761 // scrolls the image by a number of lines.
762 // 'lines' may be positive ( to scroll the image down )
763 // or negative ( to scroll the image up )
764 // 'region' is the part of the image to scroll - currently only
765 // the top, bottom and height of 'region' are taken into account,
766 // the left and right are ignored.
767 void scrollImage(int lines , const QRect& region);
768
769 void calcGeometry();
770 void propagateSize();
771 void updateImageSize();
772 void makeImage();
773
774 void paintFilters(QPainter& painter);
775
776 // returns a region covering all of the areas of the widget which contain
777 // a hotspot
778 QRegion hotSpotRegion() const;
779
780 // returns the position of the cursor in columns and lines
781 QPoint cursorPosition() const;
782
783 // redraws the cursor
784 void updateCursor();
785
786 bool handleShortcutOverrideEvent(QKeyEvent* event);
787
788 bool isLineChar(wchar_t c) const;
789 bool isLineCharString(const std::wstring& string) const;
790
791 // the window onto the terminal screen which this display
792 // is currently showing.
793 QPointer<ScreenWindow> _screenWindow;
794
795 bool _allowBell;
796
797 QGridLayout* _gridLayout;
798
799 bool _fixedFont; // has fixed pitch
800 int _fontHeight; // height
801 int _fontWidth; // width
802 int _fontAscent; // ascend
803 bool _boldIntense; // Whether intense colors should be rendered with bold font
804
805 int _leftMargin; // offset
806 int _topMargin; // offset
807
808 int _lines; // the number of lines that can be displayed in the widget
809 int _columns; // the number of columns that can be displayed in the widget
810
811 int _usedLines; // the number of lines that are actually being used, this will be less
812 // than 'lines' if the character image provided with setImage() is smaller
813 // than the maximum image size which can be displayed
814
815 int _usedColumns; // the number of columns that are actually being used, this will be less
816 // than 'columns' if the character image provided with setImage() is smaller
817 // than the maximum image size which can be displayed
818
819 int _contentHeight;
820 int _contentWidth;
821 Character* _image; // [lines][columns]
822 // only the area [usedLines][usedColumns] in the image contains valid data
823
824 int _imageSize;
825 QVector<LineProperty> _lineProperties;
826
827 ColorEntry _colorTable[TABLE_COLORS];
828 uint _randomSeed;
829
830 bool _resizing;
831 bool _terminalSizeHint;
832 bool _terminalSizeStartup;
833 bool _bidiEnabled;
834 bool _mouseMarks;
835 bool _bracketedPasteMode;
836 bool _disabledBracketedPasteMode;
837
838 QPoint _iPntSel; // initial selection point
839 QPoint _pntSel; // current selection point
840 QPoint _tripleSelBegin; // help avoid flicker
841 int _actSel; // selection state
842 bool _wordSelectionMode;
843 bool _lineSelectionMode;
844 bool _preserveLineBreaks;
845 bool _columnSelectionMode;
846
847 QClipboard* _clipboard;
848 QScrollBar* _scrollBar;
849 QTermWidget::ScrollBarPosition _scrollbarLocation;
850 QString _wordCharacters;
851 int _bellMode;
852
853 bool _blinking; // hide text in paintEvent
854 bool _hasBlinker; // has characters to blink
855 bool _cursorBlinking; // hide cursor in paintEvent
856 bool _hasBlinkingCursor; // has blinking cursor enabled
857 bool _allowBlinkingText; // allow text to blink
858 bool _ctrlDrag; // require Ctrl key for drag
859 TripleClickMode _tripleClickMode;
860 bool _isFixedSize; //Columns / lines are locked.
861 QTimer* _blinkTimer; // active when hasBlinker
862 QTimer* _blinkCursorTimer; // active when hasBlinkingCursor
863
864 //QMenu* _drop;
865 QString _dropText;
866 int _dndFileCount;
867
868 bool _possibleTripleClick; // is set in mouseDoubleClickEvent and deleted
869 // after QApplication::doubleClickInterval() delay
870
871
872 QLabel* _resizeWidget;
873 QTimer* _resizeTimer;
874
875 bool _flowControlWarningEnabled;
876
877 //widgets related to the warning message that appears when the user presses Ctrl+S to suspend
878 //terminal output - informing them what has happened and how to resume output
879 QLabel* _outputSuspendedLabel;
880
881 uint _lineSpacing;
882 QString _colorScheme;
883 bool _colorsInverted; // true during visual bell
884
885 QSize _size;
886
887 qreal _opacity;
888
889 QPixmap _backgroundImage;
890 BackgroundMode _backgroundMode;
891
892 // list of filters currently applied to the display. used for links and
893 // search highlight
894 TerminalImageFilterChain* _filterChain;
895 QRegion _mouseOverHotspotArea;
896
897 QTermWidget::KeyboardCursorShape _cursorShape;
898
899 // custom cursor color. if this is invalid then the foreground
900 // color of the character under the cursor is used
901 QColor _cursorColor;
902
903
904 MotionAfterPasting mMotionAfterPasting;
905 bool _confirmMultilinePaste;
906 bool _trimPastedTrailingNewlines;
907
908 struct InputMethodData
909 {
910 std::wstring preeditString;
911 QRect previousPreeditRect;
912 };
913 InputMethodData _inputMethodData;
914
915 static bool _antialiasText; // do we antialias or not
916
917 //the delay in milliseconds between redrawing blinking text
918 static const int TEXT_BLINK_DELAY = 500;
919
920 int _leftBaseMargin;
921 int _topBaseMargin;
922
923 // QMLTermWidget port functions
924 QFont m_font;
925 QPalette m_palette;
926 QPalette::ColorRole m_color_role;
927 KSession *m_session;
928 bool m_full_cursor_height;
929
930 QFont font() const { return m_font; }
931
932 const QPalette palette() { return m_palette; }
933 void setPalette(const QPalette &p){ m_palette = p; }
934
935 QPalette::ColorRole backgroundRole() { return m_color_role; }
936 void setBackgroundRole(QPalette::ColorRole role) { m_color_role = role; }
937
938 void update(const QRegion &region);
939 void update();
940
941 QRect contentsRect() const;
942 QSize size() const;
943
944 void setSession(KSession *session);
945 KSession* getSession();
946
947 QSize getTerminalSize();
948
949 bool getUsesMouse();
950
951 int getScrollbarValue();
952 int getScrollbarMaximum();
953 int getScrollbarMinimum();
954
955 QSize getFontMetrics();
956
957 void setFullCursorHeight(bool val);
958
959 bool _drawLineChars;
960
961 public:
962 static void setTransparencyEnabled(bool enable)
963 {
964 HAVE_TRANSPARENCY = enable;
965 }
966 bool fullCursorHeight() const;
967 };
968
969 class AutoScrollHandler : public QObject
970 {
971 Q_OBJECT
972
973 public:
974 AutoScrollHandler(QWidget* parent);
975 protected:
976 void timerEvent(QTimerEvent* event) override;
977 bool eventFilter(QObject* watched,QEvent* event) override;
978 private:
979 QWidget* widget() const { return static_cast<QWidget*>(parent()); }
980 int _timerId;
981 };
982
983 }
984
985 #endif // TERMINALDISPLAY_H