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 selectedText READ selectedText CONSTANT)
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
700 /**
701 * Sets the text of the display to the specified color.
702 * @see setColorTable(), setBackgroundColor()
703 */
704 void setForegroundColor(const QColor &color);
705
706 void selectionChanged();
707
708 // QMLTermWidget
709 void setColorScheme(const QString &name);
710 QString colorScheme() const;
711 QStringList availableColorSchemes();
712
713 void simulateKeyPress(int key, int modifiers, bool pressed, quint32 nativeScanCode, const QString &text);
714 void simulateKeySequence(const QKeySequence &sequence);
715 void simulateWheel(int x, int y, int buttons, int modifiers, QPoint angleDelta);
716 void simulateMouseMove(int x, int y, int button, int buttons, int modifiers);
717 void simulateMousePress(int x, int y, int button, int buttons, int modifiers);
718 void simulateMouseRelease(int x, int y, int button, int buttons, int modifiers);
719 void simulateMouseDoubleClick(int x, int y, int button, int buttons, int modifiers);
720
721 /** Sets the backgroundOpacity of the terminal display. */
722 void setBackgroundOpacity(qreal backgroundOpacity);
723 qreal backgroundOpacity() const;
724
725 void findNext(const QString &regexp);
726 void findPrevious(const QString &regexp);
727 void matchFound(int startColumn, int startLine, int endColumn, int endLine);
728 void noMatchFound();
729
730Q_SIGNALS:
731
732 /**
733 * Emitted when the user presses a key whilst the terminal widget has focus.
734 */
735 void keyPressedSignal(QKeyEvent *e, bool fromPaste);
736
737 /**
738 * A mouse event occurred.
739 * @param button The mouse button (0 for left button, 1 for middle button, 2 for right button, 3 for release)
740 * @param column The character column where the event occurred
741 * @param line The character row where the event occurred
742 * @param eventType The type of event. 0 for a mouse press / release or 1 for mouse motion
743 */
744 void mouseSignal(int button, int column, int line, int eventType);
745 void changedFontMetricSignal(qreal height, qreal width);
746 void changedContentSizeSignal(int height, int width);
747
748 /**
749 * Emitted when the user right clicks on the display, or right-clicks with the Shift
750 * key held down if usesMouse() is true.
751 *
752 * This can be used to display a context menu.
753 */
754 void configureRequest(const QPoint &position);
755
756 /**
757 * When a shortcut which is also a valid terminal key sequence is pressed while
758 * the terminal widget has focus, this signal is emitted to allow the host to decide
759 * whether the shortcut should be overridden.
760 * When the shortcut is overridden, the key sequence will be sent to the terminal emulation instead
761 * and the action associated with the shortcut will not be triggered.
762 *
763 * @p override is set to false by default and the shortcut will be triggered as normal.
764 */
765 void overrideShortcutCheck(QKeyEvent *keyEvent, bool &override);
766
767 void isBusySelecting(bool busy);
768 void sendStringToEmu(const char *);
769
770 // qtermwidget signals
771 void copyAvailable(bool available);
772 void termGetFocus();
773 void termLostFocus();
774
775 void notifyBell(const QString &bell);
776 void usesMouseChanged();
777
778 // QMLTermWidget
779 void sessionChanged();
780 void sizeChanged();
781 void imagePainted();
782 void scrollbarValueChanged();
783 void scrollbarParamsChanged(int value);
784 void vtFontChanged();
785 void lineSpacingChanged();
786 void availableColorSchemesChanged();
787 void colorSchemeChanged();
788 void fullCursorHeightChanged();
789 void blinkingCursorStateChanged();
790 void boldIntenseChanged();
791 void backgroundOpacityChanged();
792
793 void readOnlyChanged();
794
795protected:
796 bool event(QEvent *) override;
797
798 void showEvent(QShowEvent *);
799 void hideEvent(QHideEvent *);
800 void resizeEvent(QResizeEvent *);
801
802 virtual void fontChange(const QFont &font);
803 void focusInEvent(QFocusEvent *event) override;
804 void focusOutEvent(QFocusEvent *event) override;
805 void keyPressEvent(QKeyEvent *event) override;
806 void mouseDoubleClickEvent(QMouseEvent *ev) override;
807 void mousePressEvent(QMouseEvent *) override;
808 void mouseReleaseEvent(QMouseEvent *) override;
809 void mouseMoveEvent(QMouseEvent *) override;
810 virtual void extendSelection(const QPoint &pos);
811 void wheelEvent(QWheelEvent *) override;
812
813 bool focusNextPrevChild(bool next);
814
815 // drag and drop
816 void dragEnterEvent(QDragEnterEvent *event) override;
817 void dropEvent(QDropEvent *event) override;
818 void doDrag();
819 enum DragState { diNone, diPending, diDragging };
820
821 struct _dragInfo {
822 DragState state;
824 QDrag *dragObject;
825 } dragInfo;
826
827 // classifies the 'ch' into one of three categories
828 // and returns a character to indicate which category it is in
829 //
830 // - A space (returns ' ')
831 // - Part of a word (returns 'a')
832 // - Other characters (returns the input character)
833 QChar charClass(QChar ch) const;
834
835 void clearImage();
836
837 void mouseTripleClickEvent(QMouseEvent *ev);
838
839 // reimplemented
840 void inputMethodEvent(QInputMethodEvent *event) override;
841 QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
842
843 // QMLTermWidget
844 void paint(QPainter *painter) override;
845#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
846 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
847#else
848 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
849#endif
850 void inputMethodQuery(QInputMethodQueryEvent *event);
851 void itemChange(ItemChange change, const ItemChangeData &value) override;
852
853 constexpr int loc(int x, int y) const
854 {
855 return y * _columns + x;
856 }
857
858protected Q_SLOTS:
859
860 void scrollBarPositionChanged(int value);
861 void blinkEvent();
862 void blinkCursorEvent();
863
864 // Renables bell noises and visuals. Used to disable further bells for a short period of time
865 // after emitting the first in a sequence of bell events.
866 void enableBell();
867
868private Q_SLOTS:
869
870 void swapColorTable();
871 void tripleClickTimeout(); // resets possibleTripleClick
872
873 void applyColorScheme();
874
875private:
876 // -- Drawing helpers --
877
878 // determine the width of this text
879 int textWidth(int startColumn, int length, int line) const;
880 // determine the area that encloses this series of characters
881 QRect calculateTextArea(int topLeftX, int topLeftY, int startColumn, int line, int length);
882
883 // divides the part of the display specified by 'rect' into
884 // fragments according to their colors and styles and calls
885 // drawTextFragment() to draw the fragments
886 void drawContents(QPainter &paint, const QRect &rect);
887 // draws a section of text, all the text in this section
888 // has a common color and style
889 void drawTextFragment(QPainter &painter, const QRect &rect, const QString &text, const Character *style);
890 // draws the background for a text fragment
891 // if useOpacitySetting is true then the color's alpha value will be set to
892 // the display's transparency (set with setOpacity()), otherwise the background
893 // will be drawn fully opaque
894 void drawBackground(QPainter &painter, const QRect &rect, const QColor &color, bool useOpacitySetting);
895 // draws the cursor character
896 void drawCursor(QPainter &painter, const QRect &rect, const QColor &foregroundColor, const QColor &backgroundColor, bool &invertColors);
897 // draws the characters or line graphics in a text fragment
898 void drawCharacters(QPainter &painter, const QRect &rect, const QString &text, const Character *style, bool invertCharacterColor);
899 // draws a string of line graphics
900 void drawLineCharString(QPainter &painter, int x, int y, QStringView str, const Character *attributes) const;
901
902 // draws the preedit string for input methods
903 void drawInputMethodPreeditString(QPainter &painter, const QRect &rect);
904
905 // --
906
907 // maps an area in the character image to an area on the widget
908 QRect imageToWidget(const QRect &imageArea) const;
909
910 // the area where the preedit string for input methods will be draw
911 QRect preeditRect() const;
912
913 // shows a notification window in the middle of the widget indicating the terminal's
914 // current size in columns and lines
915 void showResizeNotification();
916
917 // scrolls the image by a number of lines.
918 // 'lines' may be positive ( to scroll the image down )
919 // or negative ( to scroll the image up )
920 // 'region' is the part of the image to scroll - currently only
921 // the top, bottom and height of 'region' are taken into account,
922 // the left and right are ignored.
923 void scrollImage(int lines, const QRect &region);
924
925 void calcGeometry();
926 void propagateSize();
927 void updateImageSize();
928 void makeImage();
929
930 void paintFilters(QPainter &painter);
931
932 // returns a region covering all of the areas of the widget which contain
933 // a hotspot
934 QRegion hotSpotRegion() const;
935
936 // returns the position of the cursor in columns and lines
937 QPoint cursorPosition() const;
938
939 // redraws the cursor
940 void updateCursor();
941
942 bool handleShortcutOverrideEvent(QKeyEvent *event);
943
944 constexpr bool isLineChar(QChar c) const;
945 constexpr bool isLineCharString(QStringView string) const;
946
947 // the window onto the terminal screen which this display
948 // is currently showing.
949 QPointer<ScreenWindow> _screenWindow;
950
951 bool _allowBell;
952
953 QGridLayout *_gridLayout;
954
955 bool _fixedFont; // has fixed pitch
956 qreal _fontHeight; // height
957 qreal _fontWidth; // width
958 int _fontAscent; // ascend
959 bool _boldIntense; // Whether intense colors should be rendered with bold font
960
961 int _leftMargin; // offset
962 int _topMargin; // offset
963
964 int _lines; // the number of lines that can be displayed in the widget
965 int _columns; // the number of columns that can be displayed in the widget
966
967 int _usedLines; // the number of lines that are actually being used, this will be less
968 // than 'lines' if the character image provided with setImage() is smaller
969 // than the maximum image size which can be displayed
970
971 int _usedColumns; // the number of columns that are actually being used, this will be less
972 // than 'columns' if the character image provided with setImage() is smaller
973 // than the maximum image size which can be displayed
974
975 int _contentHeight;
976 int _contentWidth;
977 std::vector<Character> _image; // [lines][columns]
978 // only the area [usedLines][usedColumns] in the image contains valid data
979
980 int _imageSize;
981 QVector<LineProperty> _lineProperties;
982
983 std::array<ColorEntry, TABLE_COLORS> _colorTable;
984 uint _randomSeed;
985
986 bool _resizing;
987 bool _terminalSizeHint;
988 bool _terminalSizeStartup;
989 bool _bidiEnabled;
990 bool _mouseMarks;
991 bool _bracketedPasteMode;
992 bool _disabledBracketedPasteMode;
993
994 QPoint _iPntSel; // initial selection point
995 QPoint _pntSel; // current selection point
996 QPoint _tripleSelBegin; // help avoid flicker
997 int _actSel; // selection state
998 bool _wordSelectionMode;
999 bool _lineSelectionMode;
1000 bool _preserveLineBreaks;
1001 bool _columnSelectionMode;
1002
1003 QClipboard *_clipboard;
1004 QScrollBar *_scrollBar;
1005 QTermWidget::ScrollBarPosition _scrollbarLocation;
1006 QString _wordCharacters;
1007 int _bellMode;
1008
1009 bool _blinking; // hide text in paintEvent
1010 bool _hasBlinker; // has characters to blink
1011 bool _cursorBlinking; // hide cursor in paintEvent
1012 bool _hasBlinkingCursor; // has blinking cursor enabled
1013 bool _allowBlinkingText; // allow text to blink
1014 bool _ctrlDrag; // require Ctrl key for drag
1015 TripleClickMode _tripleClickMode;
1016 bool _isFixedSize; // Columns / lines are locked.
1017 QTimer *_blinkTimer; // active when hasBlinker
1018 QTimer *_blinkCursorTimer; // active when hasBlinkingCursor
1019
1020 // QMenu* _drop;
1021 QString _dropText;
1022 int _dndFileCount;
1023
1024 bool _possibleTripleClick; // is set in mouseDoubleClickEvent and deleted
1025 // after QApplication::doubleClickInterval() delay
1026
1027 QLabel *_resizeWidget;
1028 QTimer *_resizeTimer;
1029
1030 bool _flowControlWarningEnabled;
1031
1032 // widgets related to the warning message that appears when the user presses Ctrl+S to suspend
1033 // terminal output - informing them what has happened and how to resume output
1034 QLabel *_outputSuspendedLabel;
1035
1036 uint _lineSpacing;
1037 QString _colorScheme;
1038 bool _colorsInverted; // true during visual bell
1039
1040 QSize _size;
1041
1042 qreal _opacity;
1043
1044 // list of filters currently applied to the display. used for links and
1045 // search highlight
1046 std::unique_ptr<TerminalImageFilterChain> _filterChain;
1047 QRegion _mouseOverHotspotArea;
1048
1049 Emulation::KeyboardCursorShape _cursorShape;
1050
1051 // custom cursor color. if this is invalid then the foreground
1052 // color of the character under the cursor is used
1053 QColor _cursorColor;
1054
1055 MotionAfterPasting mMotionAfterPasting;
1056 bool _confirmMultilinePaste;
1057 bool _trimPastedTrailingNewlines;
1058
1059 struct InputMethodData {
1060 QString preeditString;
1061 QRect previousPreeditRect;
1062 };
1063 InputMethodData _inputMethodData;
1064
1065 static bool _antialiasText; // do we antialias or not
1066
1067 // the delay in milliseconds between redrawing blinking text
1068 static const int TEXT_BLINK_DELAY = 500;
1069
1070 int _leftBaseMargin;
1071 int _topBaseMargin;
1072
1073 // QMLTermWidget port functions
1074 QFont m_font;
1075 QPalette m_palette;
1076 QPalette::ColorRole m_color_role;
1077 KSession *m_session = nullptr;
1078 bool m_full_cursor_height;
1079
1080 QFont font() const
1081 {
1082 return m_font;
1083 }
1084
1085 const QPalette palette()
1086 {
1087 return m_palette;
1088 }
1089 void setPalette(const QPalette &p)
1090 {
1091 m_palette = p;
1092 }
1093
1094 QPalette::ColorRole backgroundRole()
1095 {
1096 return m_color_role;
1097 }
1098 void setBackgroundRole(QPalette::ColorRole role)
1099 {
1100 m_color_role = role;
1101 }
1102
1103 void update(const QRegion &region);
1104 void update();
1105
1106 QRect contentsRect() const;
1107 QSize size() const;
1108
1109 void setSession(KSession *session);
1110 KSession *getSession();
1111
1112 QSize getTerminalSize();
1113
1114 bool getUsesMouse();
1115
1116 int getScrollbarValue();
1117 void setScrollbarValue(int value);
1118
1119 int getScrollbarMaximum();
1120 int getScrollbarMinimum();
1121
1122 QSize getFontMetrics();
1123
1124 void setFullCursorHeight(bool val);
1125
1126 bool _drawLineChars;
1127
1128 qreal m_backgroundOpacity;
1129
1130 CustomColorScheme *m_customColorScheme = nullptr;
1131 const Konsole::ColorScheme *m_scheme = nullptr;
1132 bool m_readOnly = false;
1133
1134public:
1135 bool fullCursorHeight() const;
1136 CustomColorScheme *customColorScheme() const;
1137 bool readOnly() const;
1138 void setReadOnly(bool newReadOnly);
1139 bool selectedText() const;
1140};
1141
1142}
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 Jul 26 2024 11:57:30 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.