Warning, file /kde/applications/konsole/src/TerminalDisplay.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
0003     Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
0004 
0005     This program is free software; you can redistribute it and/or modify
0006     it under the terms of the GNU General Public License as published by
0007     the Free Software Foundation; either version 2 of the License, or
0008     (at your option) any later version.
0009 
0010     This program is distributed in the hope that it will be useful,
0011     but WITHOUT ANY WARRANTY; without even the implied warranty of
0012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013     GNU General Public License for more details.
0014 
0015     You should have received a copy of the GNU General Public License
0016     along with this program; if not, write to the Free Software
0017     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0018     02110-1301  USA.
0019 */
0020 
0021 #ifndef TERMINALDISPLAY_H
0022 #define TERMINALDISPLAY_H
0023 
0024 // Qt
0025 #include <QColor>
0026 #include <QPointer>
0027 #include <QWidget>
0028 
0029 // Konsole
0030 #include "Character.h"
0031 #include "konsoleprivate_export.h"
0032 #include "ScreenWindow.h"
0033 #include "ColorScheme.h"
0034 #include "Enumeration.h"
0035 #include "ScrollState.h"
0036 
0037 class QDrag;
0038 class QDragEnterEvent;
0039 class QDropEvent;
0040 class QLabel;
0041 class QTimer;
0042 class QEvent;
0043 class QVBoxLayout;
0044 class QKeyEvent;
0045 class QScrollBar;
0046 class QShowEvent;
0047 class QHideEvent;
0048 class QTimerEvent;
0049 class KMessageWidget;
0050 
0051 namespace Konsole {
0052 class FilterChain;
0053 class TerminalImageFilterChain;
0054 class SessionController;
0055 class IncrementalSearchBar;
0056 /**
0057  * A widget which displays output from a terminal emulation and sends input keypresses and mouse activity
0058  * to the terminal.
0059  *
0060  * When the terminal emulation receives new output from the program running in the terminal,
0061  * it will update the display by calling updateImage().
0062  *
0063  * TODO More documentation
0064  */
0065 class KONSOLEPRIVATE_EXPORT TerminalDisplay : public QWidget
0066 {
0067     Q_OBJECT
0068 
0069 public:
0070     /** Constructs a new terminal display widget with the specified parent. */
0071     explicit TerminalDisplay(QWidget *parent = nullptr);
0072     ~TerminalDisplay() Q_DECL_OVERRIDE;
0073 
0074     /** Returns the terminal color palette used by the display. */
0075     const ColorEntry *colorTable() const;
0076     /** Sets the terminal color palette used by the display. */
0077     void setColorTable(const ColorEntry table[]);
0078     /**
0079      * Sets the seed used to generate random colors for the display
0080      * (in color schemes that support them).
0081      */
0082     void setRandomSeed(uint randomSeed);
0083     /**
0084      * Returns the seed used to generate random colors for the display
0085      * (in color schemes that support them).
0086      */
0087     uint randomSeed() const;
0088 
0089     /** Sets the opacity of the terminal display. */
0090     void setOpacity(qreal opacity);
0091 
0092     /** Sets the background picture */
0093     void setWallpaper(ColorSchemeWallpaper::Ptr p);
0094 
0095     /**
0096      * Specifies whether the terminal display has a vertical scroll bar, and if so whether it
0097      * is shown on the left or right side of the display.
0098      */
0099     void setScrollBarPosition(Enum::ScrollBarPositionEnum position);
0100     Enum::ScrollBarPositionEnum scrollBarPosition() const
0101     {
0102         return _scrollbarLocation;
0103     }
0104 
0105     /**
0106      * Sets the current position and range of the display's scroll bar.
0107      *
0108      * @param cursor The position of the scroll bar's thumb.
0109      * @param slines The maximum value of the scroll bar.
0110      */
0111     void setScroll(int cursor, int slines);
0112 
0113     void setScrollFullPage(bool fullPage);
0114     bool scrollFullPage() const;
0115 
0116     /**
0117      * Returns the display's filter chain.  When the image for the display is updated,
0118      * the text is passed through each filter in the chain.  Each filter can define
0119      * hotspots which correspond to certain strings (such as URLs or particular words).
0120      * Depending on the type of the hotspots created by the filter ( returned by Filter::Hotspot::type() )
0121      * the view will draw visual cues such as underlines on mouse-over for links or translucent
0122      * rectangles for markers.
0123      *
0124      * To add a new filter to the view, call:
0125      *      viewWidget->filterChain()->addFilter( filterObject );
0126      */
0127     FilterChain *filterChain() const;
0128 
0129     /**
0130      * Updates the filters in the display's filter chain.  This will cause
0131      * the hotspots to be updated to match the current image.
0132      *
0133      * WARNING:  This function can be expensive depending on the
0134      * image size and number of filters in the filterChain()
0135      *
0136      * TODO - This API does not really allow efficient usage.  Revise it so
0137      * that the processing can be done in a better way.
0138      *
0139      * eg:
0140      *      - Area of interest may be known ( eg. mouse cursor hovering
0141      *      over an area )
0142      */
0143     void processFilters();
0144 
0145     /**
0146      * Returns a list of menu actions created by the filters for the content
0147      * at the given @p position.
0148      */
0149     QList<QAction *> filterActions(const QPoint &position);
0150 
0151     /** Specifies whether or not the cursor can blink. */
0152     void setBlinkingCursorEnabled(bool blink);
0153     /** Returns true if the cursor is allowed to blink or false otherwise. */
0154     bool blinkingCursorEnabled() const
0155     {
0156         return _allowBlinkingCursor;
0157     }
0158 
0159     /** Specifies whether or not text can blink. */
0160     void setBlinkingTextEnabled(bool blink);
0161 
0162     void setControlDrag(bool enable)
0163     {
0164         _ctrlRequiredForDrag = enable;
0165     }
0166 
0167     bool ctrlRequiredForDrag() const
0168     {
0169         return _ctrlRequiredForDrag;
0170     }
0171 
0172     void setDropUrlsAsText(bool enable)
0173     {
0174         _dropUrlsAsText = enable;
0175     }
0176 
0177     bool getDropUrlsAsText() const
0178     {
0179         return _dropUrlsAsText;
0180     }
0181 
0182     /** Sets how the text is selected when the user triple clicks within the display. */
0183     void setTripleClickMode(Enum::TripleClickModeEnum mode)
0184     {
0185         _tripleClickMode = mode;
0186     }
0187 
0188     /** See setTripleClickSelectionMode() */
0189     Enum::TripleClickModeEnum tripleClickMode() const
0190     {
0191         return _tripleClickMode;
0192     }
0193 
0194     /**
0195      * Specifies whether links and email addresses should be opened when
0196      * clicked with the mouse. Defaults to false.
0197      */
0198     void setOpenLinksByDirectClick(bool value)
0199     {
0200         _openLinksByDirectClick = value;
0201     }
0202 
0203     /**
0204      * Returns true if links and email addresses should be opened when
0205      * clicked with the mouse.
0206      */
0207     bool getOpenLinksByDirectClick() const
0208     {
0209         return _openLinksByDirectClick;
0210     }
0211 
0212     /**
0213      * Sets whether leading spaces should be trimmed in selected text.
0214      */
0215     void setTrimLeadingSpaces(bool enabled)
0216     {
0217         _trimLeadingSpaces = enabled;
0218     }
0219 
0220     /**
0221      * Returns true if leading spaces should be trimmed in selected text.
0222      */
0223     bool trimLeadingSpaces() const
0224     {
0225         return _trimLeadingSpaces;
0226     }
0227 
0228     /**
0229      * Sets whether trailing spaces should be trimmed in selected text.
0230      */
0231     void setTrimTrailingSpaces(bool enabled)
0232     {
0233         _trimTrailingSpaces = enabled;
0234     }
0235 
0236     /**
0237      * Returns true if trailing spaces should be trimmed in selected text.
0238      */
0239     bool trimTrailingSpaces() const
0240     {
0241         return _trimTrailingSpaces;
0242     }
0243 
0244     void setLineSpacing(uint);
0245     uint lineSpacing() const;
0246 
0247     void setSessionController(SessionController *controller);
0248     SessionController *sessionController();
0249 
0250     /**
0251      * Sets the shape of the keyboard cursor.  This is the cursor drawn
0252      * at the position in the terminal where keyboard input will appear.
0253      *
0254      * In addition the terminal display widget also has a cursor for
0255      * the mouse pointer, which can be set using the QWidget::setCursor()
0256      * method.
0257      *
0258      * Defaults to BlockCursor
0259      */
0260     void setKeyboardCursorShape(Enum::CursorShapeEnum shape);
0261     /**
0262      * Returns the shape of the keyboard cursor.  See setKeyboardCursorShape()
0263      */
0264     Enum::CursorShapeEnum keyboardCursorShape() const;
0265 
0266     /**
0267      * Sets the Cursor Style (DECSCUSR) via escape sequences
0268      * @p shape cursor shape
0269      * @p isBlinking if true, the cursor will be set to blink
0270     */
0271     void setCursorStyle(Enum::CursorShapeEnum shape, bool isBlinking);
0272     /**
0273      * Resets the cursor style to the current profile cursor shape and
0274      * blinking settings
0275     */
0276     void resetCursorStyle();
0277 
0278     /**
0279      * Sets the color used to draw the keyboard cursor.
0280      *
0281      * The keyboard cursor defaults to using the foreground color of the character
0282      * underneath it.
0283      *
0284      * @param color By default, the widget uses the color of the
0285      * character under the cursor to draw the cursor, and inverts the
0286      * color of that character to make sure it is still readable. If @p
0287      * color is a valid QColor, the widget uses that color to draw the
0288      * cursor. If @p color is not an valid QColor, the widget falls back
0289      * to the default behavior.
0290      */
0291     void setKeyboardCursorColor(const QColor &color);
0292 
0293     /**
0294      * Returns the color of the keyboard cursor, or an invalid color if the keyboard
0295      * cursor color is set to change according to the foreground color of the character
0296      * underneath it.
0297      */
0298     QColor keyboardCursorColor() const;
0299 
0300     /**
0301      * Returns the number of lines of text which can be displayed in the widget.
0302      *
0303      * This will depend upon the height of the widget and the current font.
0304      * See fontHeight()
0305      */
0306     int  lines() const
0307     {
0308         return _lines;
0309     }
0310 
0311     /**
0312      * Returns the number of characters of text which can be displayed on
0313      * each line in the widget.
0314      *
0315      * This will depend upon the width of the widget and the current font.
0316      * See fontWidth()
0317      */
0318     int  columns() const
0319     {
0320         return _columns;
0321     }
0322 
0323     /**
0324      * Returns the height of the characters in the font used to draw the text in the display.
0325      */
0326     int  fontHeight() const
0327     {
0328         return _fontHeight;
0329     }
0330 
0331     /**
0332      * Returns the width of the characters in the display.
0333      * This assumes the use of a fixed-width font.
0334      */
0335     int  fontWidth() const
0336     {
0337         return _fontWidth;
0338     }
0339 
0340     void setSize(int columns, int lines);
0341 
0342     // reimplemented
0343     QSize sizeHint() const Q_DECL_OVERRIDE;
0344 
0345     /**
0346      * Sets which characters, in addition to letters and numbers,
0347      * are regarded as being part of a word for the purposes
0348      * of selecting words in the display by double clicking on them.
0349      *
0350      * The word boundaries occur at the first and last characters which
0351      * are either a letter, number, or a character in @p wc
0352      *
0353      * @param wc An array of characters which are to be considered parts
0354      * of a word ( in addition to letters and numbers ).
0355      */
0356     void setWordCharacters(const QString &wc);
0357     /**
0358      * Returns the characters which are considered part of a word for the
0359      * purpose of selecting words in the display with the mouse.
0360      *
0361      * @see setWordCharacters()
0362      */
0363     QString wordCharacters() const
0364     {
0365         return _wordCharacters;
0366     }
0367 
0368     /**
0369      * Sets the type of effect used to alert the user when a 'bell' occurs in the
0370      * terminal session.
0371      *
0372      * The terminal session can trigger the bell effect by calling bell() with
0373      * the alert message.
0374      */
0375     void setBellMode(int mode);
0376     /**
0377      * Returns the type of effect used to alert the user when a 'bell' occurs in
0378      * the terminal session.
0379      *
0380      * See setBellMode()
0381      */
0382     int bellMode() const;
0383 
0384     /** Play a visual bell for prompt or warning. */
0385     void visualBell();
0386 
0387     /**
0388      * Specified whether zoom terminal on Ctrl+mousewheel  is enabled or not.
0389      * Defaults to enabled.
0390      */
0391     void setMouseWheelZoom(bool value)
0392     {
0393         _mouseWheelZoom = value;
0394     }
0395 
0396     /**
0397      * Returns the whether zoom terminal on Ctrl+mousewheel is enabled.
0398      *
0399      * See setMouseWheelZoom()
0400      */
0401     bool mouseWheelZoom()
0402     {
0403         return _mouseWheelZoom;
0404     }
0405 
0406     /**
0407      * Reimplemented.  Has no effect.  Use setVTFont() to change the font
0408      * used to draw characters in the display.
0409      */
0410     virtual void setFont(const QFont &);
0411 
0412     /** Returns the font used to draw characters in the display */
0413     QFont getVTFont()
0414     {
0415         return font();
0416     }
0417 
0418     /**
0419      * Sets the font used to draw the display.  Has no effect if @p font
0420      * is larger than the size of the display itself.
0421      */
0422     void setVTFont(const QFont &f);
0423 
0424     /** Increases the font size */
0425     void increaseFontSize();
0426 
0427     /** Decreases the font size */
0428     void decreaseFontSize();
0429 
0430     /** Reset the font size */
0431     void resetFontSize();
0432 
0433     /**
0434      * Specified whether anti-aliasing of text in the terminal display
0435      * is enabled or not.  Defaults to enabled.
0436      */
0437     void setAntialias(bool value)
0438     {
0439         _antialiasText = value;
0440     }
0441 
0442     /**
0443      * Returns true if anti-aliasing of text in the terminal is enabled.
0444      */
0445     bool antialias() const
0446     {
0447         return _antialiasText;
0448     }
0449 
0450     /**
0451      * Specifies whether characters with intense colors should be rendered
0452      * as bold. Defaults to true.
0453      */
0454     void setBoldIntense(bool value)
0455     {
0456         _boldIntense = value;
0457     }
0458 
0459     /**
0460      * Returns true if characters with intense colors are rendered in bold.
0461      */
0462     bool getBoldIntense() const
0463     {
0464         return _boldIntense;
0465     }
0466 
0467     /**
0468      * Specifies whether line characters will be displayed using font instead
0469      * of builtin code.
0470      * as bold. Defaults to false.
0471      */
0472     void setUseFontLineCharacters(bool value)
0473     {
0474         _useFontLineCharacters = value;
0475     }
0476 
0477     /**
0478      * Returns true if font line characters will be used.
0479      */
0480     bool getFontLineCharacters() const
0481     {
0482         return _useFontLineCharacters;
0483     }
0484 
0485     /**
0486      * Sets whether or not the current height and width of the
0487      * terminal in lines and columns is displayed whilst the widget
0488      * is being resized.
0489      */
0490     void setShowTerminalSizeHint(bool on)
0491     {
0492         _showTerminalSizeHint = on;
0493     }
0494 
0495     /**
0496      * Returns whether or not the current height and width of
0497      * the terminal in lines and columns is displayed whilst the widget
0498      * is being resized.
0499      */
0500     bool showTerminalSizeHint() const
0501     {
0502         return _showTerminalSizeHint;
0503     }
0504 
0505     /**
0506      * Sets the status of the BiDi rendering inside the terminal display.
0507      * Defaults to disabled.
0508      */
0509     void setBidiEnabled(bool set)
0510     {
0511         _bidiEnabled = set;
0512     }
0513 
0514     /**
0515      * Returns the status of the BiDi rendering in this widget.
0516      */
0517     bool isBidiEnabled() const
0518     {
0519         return _bidiEnabled;
0520     }
0521 
0522     /**
0523      * Sets the modifiers that shows URL hints when they are pressed
0524      * Defaults to disabled.
0525      */
0526     void setUrlHintsModifiers(int modifiers)
0527     {
0528         _urlHintsModifiers = Qt::KeyboardModifiers(modifiers);
0529     }
0530 
0531     void setReverseUrlHintsEnabled(bool set)
0532     {
0533         _reverseUrlHints = set;
0534     }
0535 
0536     bool isReverseUrlHintsEnabled() const
0537     {
0538         return _reverseUrlHints;
0539     }
0540 
0541     /**
0542      * Sets the terminal screen section which is displayed in this widget.
0543      * When updateImage() is called, the display fetches the latest character image from the
0544      * the associated terminal screen window.
0545      *
0546      * In terms of the model-view paradigm, the ScreenWindow is the model which is rendered
0547      * by the TerminalDisplay.
0548      */
0549     void setScreenWindow(ScreenWindow *window);
0550     /** Returns the terminal screen section which is displayed in this widget.  See setScreenWindow() */
0551     ScreenWindow *screenWindow() const;
0552 
0553     // Select the current line.
0554     void selectCurrentLine();
0555 
0556     /**
0557      * Selects everything in the terminal
0558      */
0559     void selectAll();
0560 
0561     void printContent(QPainter &painter, bool friendly);
0562 
0563     /**
0564      * Gets the background of the display
0565      * @see setBackgroundColor(), setColorTable(), setForegroundColor()
0566      */
0567     QColor getBackgroundColor() const;
0568 
0569     bool bracketedPasteMode() const;
0570 
0571     /**
0572      * Returns true if the flow control warning box is enabled.
0573      * See outputSuspended() and setFlowControlWarningEnabled()
0574      */
0575     bool flowControlWarningEnabled() const
0576     {
0577         return _flowControlWarningEnabled;
0578     }
0579 
0580     /** See setUsesMouseTracking() */
0581     bool usesMouseTracking() const;
0582 
0583     /** See setAlternateScrolling() */
0584     bool alternateScrolling() const;
0585 
0586 public Q_SLOTS:
0587     /**
0588      * Scrolls current ScreenWindow
0589      *
0590      * it's needed for proper handling scroll commands in the Vt102Emulation class
0591      */
0592     void scrollScreenWindow(enum ScreenWindow::RelativeScrollMode mode, int amount);
0593 
0594     /**
0595      * Causes the terminal display to fetch the latest character image from the associated
0596      * terminal screen ( see setScreenWindow() ) and redraw the display.
0597      */
0598     void updateImage();
0599     /**
0600      * Causes the terminal display to fetch the latest line status flags from the
0601      * associated terminal screen ( see setScreenWindow() ).
0602      */
0603     void updateLineProperties();
0604 
0605     void setAutoCopySelectedText(bool enabled);
0606 
0607     void setCopyTextAsHTML(bool enabled);
0608 
0609     void setMiddleClickPasteMode(Enum::MiddleClickPasteModeEnum mode);
0610 
0611     /** Copies the selected text to the X11 Selection. */
0612     void copyToX11Selection();
0613 
0614     /** Copies the selected text to the system clipboard. */
0615     void copyToClipboard();
0616 
0617     /**
0618      * Pastes the content of the clipboard into the
0619      * display.
0620      */
0621     void pasteFromClipboard(bool appendEnter = false);
0622     /**
0623      * Pastes the content of the X11 selection into the
0624      * display.
0625      */
0626     void pasteFromX11Selection(bool appendEnter = false);
0627 
0628     /**
0629        * Changes whether the flow control warning box should be shown when the flow control
0630        * stop key (Ctrl+S) are pressed.
0631        */
0632     void setFlowControlWarningEnabled(bool enable);
0633     /**
0634      * Causes the widget to display or hide a message informing the user that terminal
0635      * output has been suspended (by using the flow control key combination Ctrl+S)
0636      *
0637      * @param suspended True if terminal output has been suspended and the warning message should
0638      *                     be shown or false to indicate that terminal output has been resumed and that
0639      *                     the warning message should disappear.
0640      */
0641     void outputSuspended(bool suspended);
0642 
0643     /**
0644      * Sets whether the program currently running in the terminal is interested
0645      * in Mouse Tracking events.
0646      *
0647      * When set to true, Konsole will send Mouse Tracking events.
0648      *
0649      * The user interaction needed to create text selections will change
0650      * also, and the user will be required to hold down the Shift key to
0651      * create a selection or perform other mouse activities inside the view
0652      * area, since the program running in the terminal is being allowed
0653      * to handle normal mouse events itself.
0654      *
0655      * @param on Set to true if the program running in the terminal is
0656      * interested in Mouse Tracking events or false otherwise.
0657      */
0658     void setUsesMouseTracking(bool on);
0659 
0660     /**
0661      * Sets the AlternateScrolling profile property which controls whether
0662      * to emulate up/down key presses for mouse scroll wheel events.
0663      * For more details, check the documentation of that property in the
0664      * Profile header.
0665      * Enabled by default.
0666      */
0667     void setAlternateScrolling(bool enable);
0668 
0669     void setBracketedPasteMode(bool on);
0670 
0671     /**
0672      * Shows a notification that a bell event has occurred in the terminal.
0673      * TODO: More documentation here
0674      */
0675     void bell(const QString &message);
0676 
0677     /**
0678      * Sets the background of the display to the specified color.
0679      * @see setColorTable(), getBackgroundColor(), setForegroundColor()
0680      */
0681     void setBackgroundColor(const QColor &color);
0682 
0683     /**
0684      * Sets the text of the display to the specified color.
0685      * @see setColorTable(), setBackgroundColor(), getBackgroundColor()
0686      */
0687     void setForegroundColor(const QColor &color);
0688 
0689     /**
0690      * Sets the display's contents margins.
0691      */
0692     void setMargin(int margin);
0693 
0694     /**
0695      * Sets whether the contents are centered between the margins.
0696      */
0697     void setCenterContents(bool enable);
0698 
0699     // Used to show/hide the message widget
0700     void updateReadOnlyState(bool readonly);
0701     IncrementalSearchBar *searchBar() const;
0702 Q_SIGNALS:
0703 
0704     /**
0705      * Emitted when the user presses a key whilst the terminal widget has focus.
0706      */
0707     void keyPressedSignal(QKeyEvent *event);
0708 
0709     /**
0710      * A mouse event occurred.
0711      * @param button The mouse button (0 for left button, 1 for middle button, 2 for right button, 3 for release)
0712      * @param column The character column where the event occurred
0713      * @param line The character row where the event occurred
0714      * @param eventType The type of event.  0 for a mouse press / release or 1 for mouse motion
0715      */
0716     void mouseSignal(int button, int column, int line, int eventType);
0717     void changedFontMetricSignal(int height, int width);
0718     void changedContentSizeSignal(int height, int width);
0719 
0720     /**
0721      * Emitted when the user right clicks on the display, or right-clicks
0722      * with the Shift key held down if usesMouseTracking() is true.
0723      *
0724      * This can be used to display a context menu.
0725      */
0726     void configureRequest(const QPoint &position);
0727 
0728     /**
0729      * When a shortcut which is also a valid terminal key sequence is pressed while
0730      * the terminal widget  has focus, this signal is emitted to allow the host to decide
0731      * whether the shortcut should be overridden.
0732      * When the shortcut is overridden, the key sequence will be sent to the terminal emulation instead
0733      * and the action associated with the shortcut will not be triggered.
0734      *
0735      * @p override is set to false by default and the shortcut will be triggered as normal.
0736      */
0737     void overrideShortcutCheck(QKeyEvent *keyEvent, bool &override);
0738 
0739     void sendStringToEmu(const QByteArray &local8BitString);
0740 
0741     void focusLost();
0742     void focusGained();
0743 
0744 protected:
0745     bool event(QEvent *event) Q_DECL_OVERRIDE;
0746 
0747     void paintEvent(QPaintEvent *pe) Q_DECL_OVERRIDE;
0748 
0749     void showEvent(QShowEvent *event) Q_DECL_OVERRIDE;
0750     void hideEvent(QHideEvent *event) Q_DECL_OVERRIDE;
0751     void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
0752 
0753     void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE;
0754 
0755     virtual void fontChange(const QFont &);
0756     void focusInEvent(QFocusEvent *event) Q_DECL_OVERRIDE;
0757     void focusOutEvent(QFocusEvent *event) Q_DECL_OVERRIDE;
0758     void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
0759     void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
0760     void leaveEvent(QEvent *event) Q_DECL_OVERRIDE;
0761     void mouseDoubleClickEvent(QMouseEvent *ev) Q_DECL_OVERRIDE;
0762     void mousePressEvent(QMouseEvent *ev) Q_DECL_OVERRIDE;
0763     void mouseReleaseEvent(QMouseEvent *ev) Q_DECL_OVERRIDE;
0764     void mouseMoveEvent(QMouseEvent *ev) Q_DECL_OVERRIDE;
0765     virtual void extendSelection(const QPoint &position);
0766     void wheelEvent(QWheelEvent *ev) Q_DECL_OVERRIDE;
0767 
0768     bool focusNextPrevChild(bool next) Q_DECL_OVERRIDE;
0769 
0770     // drag and drop
0771     void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
0772     void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE;
0773     void doDrag();
0774     enum DragState {
0775         diNone, diPending, diDragging
0776     };
0777 
0778     struct DragInfo {
0779         DragState state;
0780         QPoint start;
0781         QDrag *dragObject;
0782     } _dragInfo;
0783 
0784     // classifies the 'ch' into one of three categories
0785     // and returns a character to indicate which category it is in
0786     //
0787     //     - A space (returns ' ')
0788     //     - Part of a word (returns 'a')
0789     //     - Other characters (returns the input character)
0790     QChar charClass(const Character &ch) const;
0791 
0792     void clearImage();
0793 
0794     void mouseTripleClickEvent(QMouseEvent *ev);
0795     void selectLine(QPoint pos, bool entireLine);
0796 
0797     // reimplemented
0798     void inputMethodEvent(QInputMethodEvent *event) Q_DECL_OVERRIDE;
0799     QVariant inputMethodQuery(Qt::InputMethodQuery query) const Q_DECL_OVERRIDE;
0800 
0801     void updateScrollBarPalette();
0802 protected Q_SLOTS:
0803 
0804     void scrollBarPositionChanged(int value);
0805     void blinkTextEvent();
0806     void blinkCursorEvent();
0807 
0808 private Q_SLOTS:
0809 
0810     void swapFGBGColors();
0811     void viewScrolledByUser();
0812 
0813     /**
0814      * Called from the drag-and-drop popup. Causes the dropped URLs to be pasted as text.
0815      */
0816     void dropMenuPasteActionTriggered();
0817 
0818     void dropMenuCdActionTriggered();
0819 
0820     void dismissOutputSuspendedMessage();
0821 
0822 private:
0823     Q_DISABLE_COPY(TerminalDisplay)
0824 
0825     // -- Drawing helpers --
0826 
0827     // divides the part of the display specified by 'rect' into
0828     // fragments according to their colors and styles and calls
0829     // drawTextFragment() or drawPrinterFriendlyTextFragment()
0830     // to draw the fragments
0831     void drawContents(QPainter &painter, const QRect &rect);
0832     // draw a transparent rectangle over the line of the current match
0833     void drawCurrentResultRect(QPainter &painter);
0834     // draws a section of text, all the text in this section
0835     // has a common color and style
0836     void drawTextFragment(QPainter &painter, const QRect &rect, const QString &text,
0837                           const Character *style);
0838 
0839     void drawPrinterFriendlyTextFragment(QPainter &painter, const QRect &rect, const QString &text,
0840                                          const Character *style);
0841     // draws the background for a text fragment
0842     // if useOpacitySetting is true then the color's alpha value will be set to
0843     // the display's transparency (set with setOpacity()), otherwise the background
0844     // will be drawn fully opaque
0845     void drawBackground(QPainter &painter, const QRect &rect, const QColor &backgroundColor,
0846                         bool useOpacitySetting);
0847     // draws the cursor character
0848     void drawCursor(QPainter &painter, const QRect &rect, const QColor &foregroundColor,
0849                     const QColor &backgroundColor, bool &invertCharacterColor);
0850     // draws the characters or line graphics in a text fragment
0851     void drawCharacters(QPainter &painter, const QRect &rect, const QString &text,
0852                         const Character *style, bool invertCharacterColor);
0853     // draws a string of line graphics
0854     void drawLineCharString(QPainter &painter, int x, int y, const QString &str,
0855                             const Character *attributes);
0856 
0857     // draws the preedit string for input methods
0858     void drawInputMethodPreeditString(QPainter &painter, const QRect &rect);
0859 
0860     // --
0861 
0862     // maps an area in the character image to an area on the widget
0863     QRect imageToWidget(const QRect &imageArea) const;
0864 
0865     // maps a point on the widget to the position ( ie. line and column )
0866     // of the character at that point. When the edge is true, it maps to
0867     // a character which left edge is closest to the point.
0868     void getCharacterPosition(const QPoint &widgetPoint, int &line, int &column, bool edge) const;
0869 
0870     // the area where the preedit string for input methods will be draw
0871     QRect preeditRect() const;
0872 
0873     // shows a notification window in the middle of the widget indicating the terminal's
0874     // current size in columns and lines
0875     void showResizeNotification();
0876 
0877     // scrolls the image by a number of lines.
0878     // 'lines' may be positive ( to scroll the image down )
0879     // or negative ( to scroll the image up )
0880     // 'region' is the part of the image to scroll - currently only
0881     // the top, bottom and height of 'region' are taken into account,
0882     // the left and right are ignored.
0883     void scrollImage(int lines, const QRect &screenWindowRegion);
0884 
0885     void calcGeometry();
0886     void propagateSize();
0887     void updateImageSize();
0888     void makeImage();
0889 
0890     void paintFilters(QPainter &painter);
0891 
0892     // returns a region covering all of the areas of the widget which contain
0893     // a hotspot
0894     QRegion hotSpotRegion() const;
0895 
0896     // returns the position of the cursor in columns and lines
0897     QPoint cursorPosition() const;
0898 
0899     // returns true if the cursor's position is on display.
0900     bool isCursorOnDisplay() const;
0901 
0902     // redraws the cursor
0903     void updateCursor();
0904 
0905     bool handleShortcutOverrideEvent(QKeyEvent *keyEvent);
0906 
0907     void doPaste(QString text, bool appendReturn);
0908 
0909     void processMidButtonClick(QMouseEvent *ev);
0910 
0911     QPoint findLineStart(const QPoint &pnt);
0912     QPoint findLineEnd(const QPoint &pnt);
0913     QPoint findWordStart(const QPoint &pnt);
0914     QPoint findWordEnd(const QPoint &pnt);
0915 
0916     // Uses the current settings for trimming whitespace and preserving linebreaks to create a proper flag value for Screen
0917     Screen::DecodingOptions currentDecodingOptions();
0918 
0919     // Boilerplate setup for MessageWidget
0920     KMessageWidget* createMessageWidget(const QString &text);
0921 
0922     int loc(int x, int y) const;
0923 
0924     // the window onto the terminal screen which this display
0925     // is currently showing.
0926     QPointer<ScreenWindow> _screenWindow;
0927 
0928     bool _bellMasked;
0929 
0930     QVBoxLayout *_verticalLayout;
0931 
0932     bool _fixedFont; // has fixed pitch
0933     int _fontHeight;      // height
0934     int _fontWidth;      // width
0935     int _fontAscent;      // ascend
0936     bool _boldIntense;   // Whether intense colors should be rendered with bold font
0937 
0938     int _lines;      // the number of lines that can be displayed in the widget
0939     int _columns;    // the number of columns that can be displayed in the widget
0940 
0941     int _usedLines;  // the number of lines that are actually being used, this will be less
0942     // than 'lines' if the character image provided with setImage() is smaller
0943     // than the maximum image size which can be displayed
0944 
0945     int _usedColumns; // the number of columns that are actually being used, this will be less
0946     // than 'columns' if the character image provided with setImage() is smaller
0947     // than the maximum image size which can be displayed
0948 
0949     QRect _contentRect;
0950     Character *_image; // [lines][columns]
0951     // only the area [usedLines][usedColumns] in the image contains valid data
0952 
0953     int _imageSize;
0954     QVector<LineProperty> _lineProperties;
0955 
0956     ColorEntry _colorTable[TABLE_COLORS];
0957     uint _randomSeed;
0958 
0959     bool _resizing;
0960     bool _showTerminalSizeHint;
0961     bool _bidiEnabled;
0962     bool _usesMouseTracking;
0963     bool _alternateScrolling;
0964     bool _bracketedPasteMode;
0965 
0966     QPoint _iPntSel;  // initial selection point
0967     QPoint _pntSel;  // current selection point
0968     QPoint _tripleSelBegin;  // help avoid flicker
0969     int _actSel;     // selection state
0970     bool _wordSelectionMode;
0971     bool _lineSelectionMode;
0972     bool _preserveLineBreaks;
0973     bool _columnSelectionMode;
0974 
0975     bool _autoCopySelectedText;
0976     bool _copyTextAsHTML;
0977     Enum::MiddleClickPasteModeEnum _middleClickPasteMode;
0978 
0979     QScrollBar *_scrollBar;
0980     Enum::ScrollBarPositionEnum _scrollbarLocation;
0981     bool _scrollFullPage;
0982     QString _wordCharacters;
0983     int _bellMode;
0984 
0985     bool _allowBlinkingText;  // allow text to blink
0986     bool _allowBlinkingCursor;  // allow cursor to blink
0987     bool _textBlinking;   // text is blinking, hide it when drawing
0988     bool _cursorBlinking;     // cursor is blinking, hide it when drawing
0989     bool _hasTextBlinker; // has characters to blink
0990     QTimer *_blinkTextTimer;
0991     QTimer *_blinkCursorTimer;
0992 
0993     Qt::KeyboardModifiers _urlHintsModifiers;
0994     bool _showUrlHint;
0995     bool _reverseUrlHints;
0996     bool _openLinksByDirectClick;     // Open URL and hosts by single mouse click
0997 
0998     bool _ctrlRequiredForDrag; // require Ctrl key for drag selected text
0999     bool _dropUrlsAsText; // always paste URLs as text without showing copy/move menu
1000 
1001     Enum::TripleClickModeEnum _tripleClickMode;
1002     bool _possibleTripleClick;  // is set in mouseDoubleClickEvent and deleted
1003     // after QApplication::doubleClickInterval() delay
1004 
1005     QLabel *_resizeWidget;
1006     QTimer *_resizeTimer;
1007 
1008     bool _flowControlWarningEnabled;
1009 
1010     //widgets related to the warning message that appears when the user presses Ctrl+S to suspend
1011     //terminal output - informing them what has happened and how to resume output
1012     KMessageWidget *_outputSuspendedMessageWidget;
1013 
1014     uint _lineSpacing;
1015 
1016     QSize _size;
1017 
1018     QRgb _blendColor;
1019 
1020     ColorSchemeWallpaper::Ptr _wallpaper;
1021 
1022     // list of filters currently applied to the display.  used for links and
1023     // search highlight
1024     TerminalImageFilterChain *_filterChain;
1025     QRegion _mouseOverHotspotArea;
1026     bool _filterUpdateRequired;
1027 
1028     Enum::CursorShapeEnum _cursorShape;
1029 
1030     // cursor color. If it is invalid (by default) then the foreground
1031     // color of the character under the cursor is used
1032     QColor _cursorColor;
1033 
1034     struct InputMethodData {
1035         QString preeditString;
1036         QRect previousPreeditRect;
1037     };
1038     InputMethodData _inputMethodData;
1039 
1040     bool _antialiasText;   // do we anti-alias or not
1041     bool _useFontLineCharacters;
1042 
1043     bool _printerFriendly; // are we currently painting to a printer in black/white mode
1044 
1045     //the delay in milliseconds between redrawing blinking text
1046     static const int TEXT_BLINK_DELAY = 500;
1047 
1048     //the duration of the size hint in milliseconds
1049     static const int SIZE_HINT_DURATION = 1000;
1050 
1051     SessionController *_sessionController;
1052 
1053     bool _trimLeadingSpaces;   // trim leading spaces in selected text
1054     bool _trimTrailingSpaces;   // trim trailing spaces in selected text
1055     bool _mouseWheelZoom;   // enable mouse wheel zooming or not
1056 
1057     int _margin;      // the contents margin
1058     bool _centerContents;   // center the contents between margins
1059 
1060     KMessageWidget *_readOnlyMessageWidget; // Message shown at the top when read-only mode gets activated
1061 
1062     // Needed to know whether the mode really changed between update calls
1063     bool _readOnly;
1064 
1065     qreal _opacity;
1066 
1067     ScrollState _scrollWheelState;
1068     IncrementalSearchBar *_searchBar;
1069 
1070     friend class TerminalDisplayAccessible;
1071 };
1072 
1073 class AutoScrollHandler : public QObject
1074 {
1075     Q_OBJECT
1076 
1077 public:
1078     explicit AutoScrollHandler(QWidget *parent);
1079 protected:
1080     void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
1081     bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE;
1082 private:
1083     QWidget *widget() const
1084     {
1085         return static_cast<QWidget *>(parent());
1086     }
1087 
1088     int _timerId;
1089 };
1090 }
1091 
1092 #endif // TERMINALDISPLAY_H