Debian Codegraph @

lib/TerminalDisplay.h

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