File indexing completed on 2018-12-11 17:32:26

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     /** Returns the font used to draw characters in the display */
0407     QFont getVTFont()
0408     {
0409         return font();
0410     }
0411 
0412     /**
0413      * Sets the font used to draw the display.  Has no effect if @p font
0414      * is larger than the size of the display itself.
0415      */
0416     void setVTFont(const QFont &f);
0417 
0418     /** Increases the font size */
0419     void increaseFontSize();
0420 
0421     /** Decreases the font size */
0422     void decreaseFontSize();
0423 
0424     /** Reset the font size */
0425     void resetFontSize();
0426 
0427     /**
0428      * Specified whether anti-aliasing of text in the terminal display
0429      * is enabled or not.  Defaults to enabled.
0430      */
0431     void setAntialias(bool value)
0432     {
0433         _antialiasText = value;
0434     }
0435 
0436     /**
0437      * Returns true if anti-aliasing of text in the terminal is enabled.
0438      */
0439     bool antialias() const
0440     {
0441         return _antialiasText;
0442     }
0443 
0444     /**
0445      * Specifies whether characters with intense colors should be rendered
0446      * as bold. Defaults to true.
0447      */
0448     void setBoldIntense(bool value)
0449     {
0450         _boldIntense = value;
0451     }
0452 
0453     /**
0454      * Returns true if characters with intense colors are rendered in bold.
0455      */
0456     bool getBoldIntense() const
0457     {
0458         return _boldIntense;
0459     }
0460 
0461     /**
0462      * Specifies whether line characters will be displayed using font instead
0463      * of builtin code.
0464      * as bold. Defaults to false.
0465      */
0466     void setUseFontLineCharacters(bool value)
0467     {
0468         _useFontLineCharacters = value;
0469     }
0470 
0471     /**
0472      * Returns true if font line characters will be used.
0473      */
0474     bool getFontLineCharacters() const
0475     {
0476         return _useFontLineCharacters;
0477     }
0478 
0479     /**
0480      * Sets whether or not the current height and width of the
0481      * terminal in lines and columns is displayed whilst the widget
0482      * is being resized.
0483      */
0484     void setShowTerminalSizeHint(bool on)
0485     {
0486         _showTerminalSizeHint = on;
0487     }
0488 
0489     /**
0490      * Returns whether or not the current height and width of
0491      * the terminal in lines and columns is displayed whilst the widget
0492      * is being resized.
0493      */
0494     bool showTerminalSizeHint() const
0495     {
0496         return _showTerminalSizeHint;
0497     }
0498 
0499     /**
0500      * Sets the status of the BiDi rendering inside the terminal display.
0501      * Defaults to disabled.
0502      */
0503     void setBidiEnabled(bool set)
0504     {
0505         _bidiEnabled = set;
0506     }
0507 
0508     /**
0509      * Returns the status of the BiDi rendering in this widget.
0510      */
0511     bool isBidiEnabled() const
0512     {
0513         return _bidiEnabled;
0514     }
0515 
0516     /**
0517      * Sets the modifiers that shows URL hints when they are pressed
0518      * Defaults to disabled.
0519      */
0520     void setUrlHintsModifiers(int modifiers)
0521     {
0522         _urlHintsModifiers = Qt::KeyboardModifiers(modifiers);
0523     }
0524 
0525     void setReverseUrlHintsEnabled(bool set)
0526     {
0527         _reverseUrlHints = set;
0528     }
0529 
0530     bool isReverseUrlHintsEnabled() const
0531     {
0532         return _reverseUrlHints;
0533     }
0534 
0535     /**
0536      * Sets the terminal screen section which is displayed in this widget.
0537      * When updateImage() is called, the display fetches the latest character image from the
0538      * the associated terminal screen window.
0539      *
0540      * In terms of the model-view paradigm, the ScreenWindow is the model which is rendered
0541      * by the TerminalDisplay.
0542      */
0543     void setScreenWindow(ScreenWindow *window);
0544     /** Returns the terminal screen section which is displayed in this widget.  See setScreenWindow() */
0545     ScreenWindow *screenWindow() const;
0546 
0547     // Select the current line.
0548     void selectCurrentLine();
0549 
0550     /**
0551      * Selects everything in the terminal
0552      */
0553     void selectAll();
0554 
0555     void printContent(QPainter &painter, bool friendly);
0556 
0557     /**
0558      * Gets the background of the display
0559      * @see setBackgroundColor(), setColorTable(), setForegroundColor()
0560      */
0561     QColor getBackgroundColor() const;
0562 
0563     bool bracketedPasteMode() const;
0564 
0565     /**
0566      * Returns true if the flow control warning box is enabled.
0567      * See outputSuspended() and setFlowControlWarningEnabled()
0568      */
0569     bool flowControlWarningEnabled() const
0570     {
0571         return _flowControlWarningEnabled;
0572     }
0573 
0574     /** See setUsesMouseTracking() */
0575     bool usesMouseTracking() const;
0576 
0577     /** See setAlternateScrolling() */
0578     bool alternateScrolling() const;
0579 
0580 public Q_SLOTS:
0581     /**
0582      * Scrolls current ScreenWindow
0583      *
0584      * it's needed for proper handling scroll commands in the Vt102Emulation class
0585      */
0586     void scrollScreenWindow(enum ScreenWindow::RelativeScrollMode mode, int amount);
0587 
0588     /**
0589      * Causes the terminal display to fetch the latest character image from the associated
0590      * terminal screen ( see setScreenWindow() ) and redraw the display.
0591      */
0592     void updateImage();
0593     /**
0594      * Causes the terminal display to fetch the latest line status flags from the
0595      * associated terminal screen ( see setScreenWindow() ).
0596      */
0597     void updateLineProperties();
0598 
0599     void setAutoCopySelectedText(bool enabled);
0600 
0601     void setCopyTextAsHTML(bool enabled);
0602 
0603     void setMiddleClickPasteMode(Enum::MiddleClickPasteModeEnum mode);
0604 
0605     /** Copies the selected text to the X11 Selection. */
0606     void copyToX11Selection();
0607 
0608     /** Copies the selected text to the system clipboard. */
0609     void copyToClipboard();
0610 
0611     /**
0612      * Pastes the content of the clipboard into the
0613      * display.
0614      */
0615     void pasteFromClipboard(bool appendEnter = false);
0616     /**
0617      * Pastes the content of the X11 selection into the
0618      * display.
0619      */
0620     void pasteFromX11Selection(bool appendEnter = false);
0621 
0622     /**
0623        * Changes whether the flow control warning box should be shown when the flow control
0624        * stop key (Ctrl+S) are pressed.
0625        */
0626     void setFlowControlWarningEnabled(bool enable);
0627     /**
0628      * Causes the widget to display or hide a message informing the user that terminal
0629      * output has been suspended (by using the flow control key combination Ctrl+S)
0630      *
0631      * @param suspended True if terminal output has been suspended and the warning message should
0632      *                     be shown or false to indicate that terminal output has been resumed and that
0633      *                     the warning message should disappear.
0634      */
0635     void outputSuspended(bool suspended);
0636 
0637     /**
0638      * Sets whether the program currently running in the terminal is interested
0639      * in Mouse Tracking events.
0640      *
0641      * When set to true, Konsole will send Mouse Tracking events.
0642      *
0643      * The user interaction needed to create text selections will change
0644      * also, and the user will be required to hold down the Shift key to
0645      * create a selection or perform other mouse activities inside the view
0646      * area, since the program running in the terminal is being allowed
0647      * to handle normal mouse events itself.
0648      *
0649      * @param on Set to true if the program running in the terminal is
0650      * interested in Mouse Tracking events or false otherwise.
0651      */
0652     void setUsesMouseTracking(bool on);
0653 
0654     /**
0655      * Sets the AlternateScrolling profile property which controls whether
0656      * to emulate up/down key presses for mouse scroll wheel events.
0657      * For more details, check the documentation of that property in the
0658      * Profile header.
0659      * Enabled by default.
0660      */
0661     void setAlternateScrolling(bool enable);
0662 
0663     void setBracketedPasteMode(bool on);
0664 
0665     /**
0666      * Shows a notification that a bell event has occurred in the terminal.
0667      * TODO: More documentation here
0668      */
0669     void bell(const QString &message);
0670 
0671     /**
0672      * Sets the background of the display to the specified color.
0673      * @see setColorTable(), getBackgroundColor(), setForegroundColor()
0674      */
0675     void setBackgroundColor(const QColor &color);
0676 
0677     /**
0678      * Sets the text of the display to the specified color.
0679      * @see setColorTable(), setBackgroundColor(), getBackgroundColor()
0680      */
0681     void setForegroundColor(const QColor &color);
0682 
0683     /**
0684      * Sets the display's contents margins.
0685      */
0686     void setMargin(int margin);
0687 
0688     /**
0689      * Sets whether the contents are centered between the margins.
0690      */
0691     void setCenterContents(bool enable);
0692 
0693     /**
0694      * Sets whether the background should change when the window loses focus
0695      */
0696     void setDimWhenInactive(bool shouldDim) {
0697         _dimWhenInactive = shouldDim;
0698     }
0699 
0700     // Used to show/hide the message widget
0701     void updateReadOnlyState(bool readonly);
0702     IncrementalSearchBar *searchBar() const;
0703 Q_SIGNALS:
0704 
0705     /**
0706      * Emitted when the user presses a key whilst the terminal widget has focus.
0707      */
0708     void keyPressedSignal(QKeyEvent *event);
0709 
0710     /**
0711      * A mouse event occurred.
0712      * @param button The mouse button (0 for left button, 1 for middle button, 2 for right button, 3 for release)
0713      * @param column The character column where the event occurred
0714      * @param line The character row where the event occurred
0715      * @param eventType The type of event.  0 for a mouse press / release or 1 for mouse motion
0716      */
0717     void mouseSignal(int button, int column, int line, int eventType);
0718     void changedFontMetricSignal(int height, int width);
0719     void changedContentSizeSignal(int height, int width);
0720 
0721     /**
0722      * Emitted when the user right clicks on the display, or right-clicks
0723      * with the Shift key held down if usesMouseTracking() is true.
0724      *
0725      * This can be used to display a context menu.
0726      */
0727     void configureRequest(const QPoint &position);
0728 
0729     /**
0730      * When a shortcut which is also a valid terminal key sequence is pressed while
0731      * the terminal widget  has focus, this signal is emitted to allow the host to decide
0732      * whether the shortcut should be overridden.
0733      * When the shortcut is overridden, the key sequence will be sent to the terminal emulation instead
0734      * and the action associated with the shortcut will not be triggered.
0735      *
0736      * @p override is set to false by default and the shortcut will be triggered as normal.
0737      */
0738     void overrideShortcutCheck(QKeyEvent *keyEvent, bool &override);
0739 
0740     void sendStringToEmu(const QByteArray &local8BitString);
0741 
0742     void focusLost();
0743     void focusGained();
0744 
0745 protected:
0746     // events
0747     bool event(QEvent *event) Q_DECL_OVERRIDE;
0748     void paintEvent(QPaintEvent *pe) Q_DECL_OVERRIDE;
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     void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE;
0753     void focusInEvent(QFocusEvent *event) Q_DECL_OVERRIDE;
0754     void focusOutEvent(QFocusEvent *event) Q_DECL_OVERRIDE;
0755     void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
0756     void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
0757     void leaveEvent(QEvent *event) Q_DECL_OVERRIDE;
0758     void mouseDoubleClickEvent(QMouseEvent *ev) Q_DECL_OVERRIDE;
0759     void mousePressEvent(QMouseEvent *ev) Q_DECL_OVERRIDE;
0760     void mouseReleaseEvent(QMouseEvent *ev) Q_DECL_OVERRIDE;
0761     void mouseMoveEvent(QMouseEvent *ev) Q_DECL_OVERRIDE;
0762     void wheelEvent(QWheelEvent *ev) Q_DECL_OVERRIDE;
0763     bool focusNextPrevChild(bool next) Q_DECL_OVERRIDE;
0764 
0765     void fontChange(const QFont &);
0766     void extendSelection(const QPoint &position);
0767 
0768     // drag and drop
0769     void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
0770     void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE;
0771     void doDrag();
0772     enum DragState {
0773         diNone, diPending, diDragging
0774     };
0775 
0776     struct DragInfo {
0777         DragState state;
0778         QPoint start;
0779         QDrag *dragObject;
0780     } _dragInfo;
0781 
0782     // classifies the 'ch' into one of three categories
0783     // and returns a character to indicate which category it is in
0784     //
0785     //     - A space (returns ' ')
0786     //     - Part of a word (returns 'a')
0787     //     - Other characters (returns the input character)
0788     QChar charClass(const Character &ch) const;
0789 
0790     void clearImage();
0791 
0792     void mouseTripleClickEvent(QMouseEvent *ev);
0793     void selectLine(QPoint pos, bool entireLine);
0794 
0795     // reimplemented
0796     void inputMethodEvent(QInputMethodEvent *event) Q_DECL_OVERRIDE;
0797     QVariant inputMethodQuery(Qt::InputMethodQuery query) const Q_DECL_OVERRIDE;
0798 
0799     void onColorsChanged();
0800 
0801 protected Q_SLOTS:
0802 
0803     void scrollBarPositionChanged(int value);
0804     void blinkTextEvent();
0805     void blinkCursorEvent();
0806 
0807 private Q_SLOTS:
0808 
0809     void swapFGBGColors();
0810     void viewScrolledByUser();
0811 
0812     /**
0813      * Called from the drag-and-drop popup. Causes the dropped URLs to be pasted as text.
0814      */
0815     void dropMenuPasteActionTriggered();
0816 
0817     void dropMenuCdActionTriggered();
0818 
0819     void dismissOutputSuspendedMessage();
0820 
0821 private:
0822     Q_DISABLE_COPY(TerminalDisplay)
0823 
0824     // -- Drawing helpers --
0825 
0826     // divides the part of the display specified by 'rect' into
0827     // fragments according to their colors and styles and calls
0828     // drawTextFragment() or drawPrinterFriendlyTextFragment()
0829     // to draw the fragments
0830     void drawContents(QPainter &painter, const QRect &rect);
0831     // draw a transparent rectangle over the line of the current match
0832     void drawCurrentResultRect(QPainter &painter);
0833     // draws a section of text, all the text in this section
0834     // has a common color and style
0835     void drawTextFragment(QPainter &painter, const QRect &rect, const QString &text,
0836                           const Character *style);
0837 
0838     void drawPrinterFriendlyTextFragment(QPainter &painter, const QRect &rect, const QString &text,
0839                                          const Character *style);
0840     // draws the background for a text fragment
0841     // if useOpacitySetting is true then the color's alpha value will be set to
0842     // the display's transparency (set with setOpacity()), otherwise the background
0843     // will be drawn fully opaque
0844     void drawBackground(QPainter &painter, const QRect &rect, const QColor &backgroundColor,
0845                         bool useOpacitySetting);
0846     // draws the cursor character
0847     void drawCursor(QPainter &painter, const QRect &rect, const QColor &foregroundColor,
0848                     const QColor &backgroundColor, bool &invertCharacterColor);
0849     // draws the characters or line graphics in a text fragment
0850     void drawCharacters(QPainter &painter, const QRect &rect, const QString &text,
0851                         const Character *style, bool invertCharacterColor);
0852     // draws a string of line graphics
0853     void drawLineCharString(QPainter &painter, int x, int y, const QString &str,
0854                             const Character *attributes);
0855 
0856     // draws the preedit string for input methods
0857     void drawInputMethodPreeditString(QPainter &painter, const QRect &rect);
0858 
0859     // --
0860 
0861     // maps an area in the character image to an area on the widget
0862     QRect imageToWidget(const QRect &imageArea) const;
0863     QRect widgetToImage(const QRect &widgetArea) 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 
0958     uint _randomSeed;
0959 
0960     bool _resizing;
0961     bool _showTerminalSizeHint;
0962     bool _bidiEnabled;
0963     bool _usesMouseTracking;
0964     bool _alternateScrolling;
0965     bool _bracketedPasteMode;
0966 
0967     QPoint _iPntSel;  // initial selection point
0968     QPoint _pntSel;  // current selection point
0969     QPoint _tripleSelBegin;  // help avoid flicker
0970     int _actSel;     // selection state
0971     bool _wordSelectionMode;
0972     bool _lineSelectionMode;
0973     bool _preserveLineBreaks;
0974     bool _columnSelectionMode;
0975 
0976     bool _autoCopySelectedText;
0977     bool _copyTextAsHTML;
0978     Enum::MiddleClickPasteModeEnum _middleClickPasteMode;
0979 
0980     QScrollBar *_scrollBar;
0981     Enum::ScrollBarPositionEnum _scrollbarLocation;
0982     bool _scrollFullPage;
0983     QString _wordCharacters;
0984     int _bellMode;
0985 
0986     bool _allowBlinkingText;  // allow text to blink
0987     bool _allowBlinkingCursor;  // allow cursor to blink
0988     bool _textBlinking;   // text is blinking, hide it when drawing
0989     bool _cursorBlinking;     // cursor is blinking, hide it when drawing
0990     bool _hasTextBlinker; // has characters to blink
0991     QTimer *_blinkTextTimer;
0992     QTimer *_blinkCursorTimer;
0993 
0994     Qt::KeyboardModifiers _urlHintsModifiers;
0995     bool _showUrlHint;
0996     bool _reverseUrlHints;
0997     bool _openLinksByDirectClick;     // Open URL and hosts by single mouse click
0998 
0999     bool _ctrlRequiredForDrag; // require Ctrl key for drag selected text
1000     bool _dropUrlsAsText; // always paste URLs as text without showing copy/move menu
1001 
1002     Enum::TripleClickModeEnum _tripleClickMode;
1003     bool _possibleTripleClick;  // is set in mouseDoubleClickEvent and deleted
1004     // after QApplication::doubleClickInterval() delay
1005 
1006     QLabel *_resizeWidget;
1007     QTimer *_resizeTimer;
1008 
1009     bool _flowControlWarningEnabled;
1010 
1011     //widgets related to the warning message that appears when the user presses Ctrl+S to suspend
1012     //terminal output - informing them what has happened and how to resume output
1013     KMessageWidget *_outputSuspendedMessageWidget;
1014 
1015     uint _lineSpacing;
1016 
1017     QSize _size;
1018 
1019     QRgb _blendColor;
1020 
1021     ColorSchemeWallpaper::Ptr _wallpaper;
1022 
1023     // list of filters currently applied to the display.  used for links and
1024     // search highlight
1025     TerminalImageFilterChain *_filterChain;
1026     QRegion _mouseOverHotspotArea;
1027     bool _filterUpdateRequired;
1028 
1029     Enum::CursorShapeEnum _cursorShape;
1030 
1031     // cursor color. If it is invalid (by default) then the foreground
1032     // color of the character under the cursor is used
1033     QColor _cursorColor;
1034 
1035     struct InputMethodData {
1036         QString preeditString;
1037         QRect previousPreeditRect;
1038     };
1039     InputMethodData _inputMethodData;
1040 
1041     bool _antialiasText;   // do we anti-alias or not
1042     bool _useFontLineCharacters;
1043 
1044     bool _printerFriendly; // are we currently painting to a printer in black/white mode
1045 
1046     //the delay in milliseconds between redrawing blinking text
1047     static const int TEXT_BLINK_DELAY = 500;
1048 
1049     //the duration of the size hint in milliseconds
1050     static const int SIZE_HINT_DURATION = 1000;
1051 
1052     SessionController *_sessionController;
1053 
1054     bool _trimLeadingSpaces;   // trim leading spaces in selected text
1055     bool _trimTrailingSpaces;   // trim trailing spaces in selected text
1056     bool _mouseWheelZoom;   // enable mouse wheel zooming or not
1057 
1058     int _margin;      // the contents margin
1059     bool _centerContents;   // center the contents between margins
1060 
1061     KMessageWidget *_readOnlyMessageWidget; // Message shown at the top when read-only mode gets activated
1062 
1063     // Needed to know whether the mode really changed between update calls
1064     bool _readOnly;
1065 
1066     qreal _opacity;
1067 
1068     bool _dimWhenInactive;
1069 
1070     ScrollState _scrollWheelState;
1071     IncrementalSearchBar *_searchBar;
1072 
1073     QRect _searchResultRect;
1074     friend class TerminalDisplayAccessible;
1075 };
1076 
1077 class AutoScrollHandler : public QObject
1078 {
1079     Q_OBJECT
1080 
1081 public:
1082     explicit AutoScrollHandler(QWidget *parent);
1083 protected:
1084     void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
1085     bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE;
1086 private:
1087     QWidget *widget() const
1088     {
1089         return static_cast<QWidget *>(parent());
1090     }
1091 
1092     int _timerId;
1093 };
1094 }
1095 
1096 #endif // TERMINALDISPLAY_H