MauiKit Terminal

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

KDE's Doxygen guidelines are available online.