File indexing completed on 2018-01-16 12:10:23

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