File indexing completed on 2018-06-12 20:16:38

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