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

KDE's Doxygen guidelines are available online.