TerminalDisplay.h 31.4 KB
Newer Older
1
/*
2 3
    Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
    Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301  USA.
*/
20

21 22
#ifndef TERMINALDISPLAY_H
#define TERMINALDISPLAY_H
23

24
// Qt
Dirk Mueller's avatar
Dirk Mueller committed
25
#include <QtGui/QColor>
26
#include <QtCore/QPointer>
27
#include <QWidget>
28

29
// Konsole
30
#include "Character.h"
Laurent Montel's avatar
Laurent Montel committed
31
#include "konsoleprivate_export.h"
32
#include "ScreenWindow.h"
33
#include "ColorScheme.h"
34
#include "Enumeration.h"
35
#include "ScrollState.h"
36

37 38 39
class QDrag;
class QDragEnterEvent;
class QDropEvent;
Laurent Montel's avatar
Laurent Montel committed
40 41
class QLabel;
class QTimer;
42
class QEvent;
43
class QGridLayout;
44 45
class QKeyEvent;
class QScrollBar;
46 47
class QShowEvent;
class QHideEvent;
48
class QTimerEvent;
49

50 51
namespace Konsole
{
52 53 54
class FilterChain;
class TerminalImageFilterChain;
class SessionController;
55 56 57 58
/**
 * A widget which displays output from a terminal emulation and sends input keypresses and mouse activity
 * to the terminal.
 *
Jekyll Wu's avatar
Jekyll Wu committed
59
 * When the terminal emulation receives new output from the program running in the terminal,
60 61 62
 * it will update the display by calling updateImage().
 *
 * TODO More documentation
63
 */
64
class KONSOLEPRIVATE_EXPORT TerminalDisplay : public QWidget
65
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
66
    Q_OBJECT
67 68

public:
69
    /** Constructs a new terminal display widget with the specified parent. */
70
    explicit TerminalDisplay(QWidget* parent = 0);
71
    virtual ~TerminalDisplay();
72

73
    /** Returns the terminal color palette used by the display. */
74
    const ColorEntry* colorTable() const;
75 76
    /** Sets the terminal color palette used by the display. */
    void setColorTable(const ColorEntry table[]);
Constantin Berzan's avatar
APIDOX  
Constantin Berzan committed
77 78 79 80
    /**
     * Sets the seed used to generate random colors for the display
     * (in color schemes that support them).
     */
81
    void setRandomSeed(uint seed);
Constantin Berzan's avatar
APIDOX  
Constantin Berzan committed
82 83 84 85
    /**
     * Returns the seed used to generate random colors for the display
     * (in color schemes that support them).
     */
86 87
    uint randomSeed() const;

88 89
    /** Sets the opacity of the terminal display. */
    void setOpacity(qreal opacity);
90

91 92 93
    /** Sets the background picture */
    void setWallpaper(ColorSchemeWallpaper::Ptr p);

Jekyll Wu's avatar
Jekyll Wu committed
94
    /**
95 96 97
     * Specifies whether the terminal display has a vertical scroll bar, and if so whether it
     * is shown on the left or right side of the display.
     */
98
    void setScrollBarPosition(Enum::ScrollBarPositionEnum position);
99 100 101
    Enum::ScrollBarPositionEnum scrollBarPosition() const {
        return _scrollbarLocation;
    }
102

Jekyll Wu's avatar
Jekyll Wu committed
103
    /**
104 105 106 107 108
     * Sets the current position and range of the display's scroll bar.
     *
     * @param cursor The position of the scroll bar's thumb.
     * @param lines The maximum value of the scroll bar.
     */
109 110
    void setScroll(int cursor, int lines);

111 112 113
    void setScrollFullPage(bool fullPage);
    bool scrollFullPage() const;

114
    /**
115 116 117 118 119 120 121 122 123 124 125
     * Returns the display's filter chain.  When the image for the display is updated,
     * the text is passed through each filter in the chain.  Each filter can define
     * hotspots which correspond to certain strings (such as URLs or particular words).
     * Depending on the type of the hotspots created by the filter ( returned by Filter::Hotspot::type() )
     * the view will draw visual cues such as underlines on mouse-over for links or translucent
     * rectangles for markers.
     *
     * To add a new filter to the view, call:
     *      viewWidget->filterChain()->addFilter( filterObject );
     */
    FilterChain* filterChain() const;
126

Jekyll Wu's avatar
Jekyll Wu committed
127
    /**
128 129
     * Updates the filters in the display's filter chain.  This will cause
     * the hotspots to be updated to match the current image.
130
     *
Jekyll Wu's avatar
Jekyll Wu committed
131
     * WARNING:  This function can be expensive depending on the
132
     * image size and number of filters in the filterChain()
133
     *
134 135 136 137 138 139
     * TODO - This API does not really allow efficient usage.  Revise it so
     * that the processing can be done in a better way.
     *
     * eg:
     *      - Area of interest may be known ( eg. mouse cursor hovering
     *      over an area )
Jekyll Wu's avatar
Jekyll Wu committed
140
     */
141
    void processFilters();
142

Jekyll Wu's avatar
Jekyll Wu committed
143
    /**
144 145 146 147 148
     * Returns a list of menu actions created by the filters for the content
     * at the given @p position.
     */
    QList<QAction*> filterActions(const QPoint& position);

Jekyll Wu's avatar
Jekyll Wu committed
149 150
    /** Specifies whether or not the cursor can blink. */
    void setBlinkingCursorEnabled(bool blink);
151
    /** Returns true if the cursor is allowed to blink or false otherwise. */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
152 153 154
    bool blinkingCursorEnabled() const {
        return _allowBlinkingCursor;
    }
155

156 157 158
    /** Specifies whether or not text can blink. */
    void setBlinkingTextEnabled(bool blink);

159 160
    void setControlDrag(bool enable) {
        _ctrlRequiredForDrag = enable;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
161
    }
162 163
    bool ctrlRequiredForDrag() const {
        return _ctrlRequiredForDrag;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
164
    }
165

166 167 168 169 170 171 172
    void setDropUrlsAsText(bool enable) {
        _dropUrlsAsText = enable;
    }
    bool getDropUrlsAsText() const {
        return _dropUrlsAsText;
    }

Jekyll Wu's avatar
Jekyll Wu committed
173
    /** Sets how the text is selected when the user triple clicks within the display. */
174
    void setTripleClickMode(Enum::TripleClickModeEnum mode) {
Kurt Hindenburg's avatar
Kurt Hindenburg committed
175 176
        _tripleClickMode = mode;
    }
177
    /** See setTripleClickSelectionMode() */
178
    Enum::TripleClickModeEnum tripleClickMode() const {
Kurt Hindenburg's avatar
Kurt Hindenburg committed
179 180
        return _tripleClickMode;
    }
181

182
    /**
Jekyll Wu's avatar
Jekyll Wu committed
183
     * Specifies whether links and email addresses should be underlined when
184 185
     * hovered by the mouse. Defaults to true.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
186 187 188
    void setUnderlineLinks(bool value) {
        _underlineLinks = value;
    }
189
    /**
Jekyll Wu's avatar
Jekyll Wu committed
190
     * Returns true if links and email addresses should be underlined when
191 192
     * hovered by the mouse.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
193 194 195
    bool getUnderlineLinks() const {
        return _underlineLinks;
    }
196

197 198 199 200
    /**
     * Specifies whether links and email addresses should be opened when
     * clicked with the mouse. Defaults to false.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
201 202 203
    void setOpenLinksByDirectClick(bool value) {
        _openLinksByDirectClick = value;
    }
204 205 206 207
    /**
     * Returns true if links and email addresses should be opened when
     * clicked with the mouse.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
208 209 210
    bool getOpenLinksByDirectClick() const {
        return _openLinksByDirectClick;
    }
211

212 213 214 215 216 217 218 219 220 221 222 223 224
    /**
     * Sets whether trailing spaces should be trimmed in selected text.
     */
    void setTrimTrailingSpaces(bool enabled) {
        _trimTrailingSpaces = enabled;
    }

    /**
     * Returns true if trailing spaces should be trimmed in selected text.
     */
    bool trimTrailingSpaces() const {
        return _trimTrailingSpaces;
    }
225

226 227 228
    void setLineSpacing(uint);
    uint lineSpacing() const;

229
    void setSessionController(SessionController* controller);
230
    SessionController* sessionController();
231

Jekyll Wu's avatar
Jekyll Wu committed
232 233
    /**
     * Sets the shape of the keyboard cursor.  This is the cursor drawn
234 235
     * at the position in the terminal where keyboard input will appear.
     *
Jekyll Wu's avatar
Jekyll Wu committed
236
     * In addition the terminal display widget also has a cursor for
237 238 239 240 241
     * the mouse pointer, which can be set using the QWidget::setCursor()
     * method.
     *
     * Defaults to BlockCursor
     */
242
    void setKeyboardCursorShape(Enum::CursorShapeEnum shape);
243 244 245
    /**
     * Returns the shape of the keyboard cursor.  See setKeyboardCursorShape()
     */
246
    Enum::CursorShapeEnum keyboardCursorShape() const;
247

248
    /**
Jekyll Wu's avatar
Jekyll Wu committed
249
     * Sets the color used to draw the keyboard cursor.
250 251 252 253
     *
     * The keyboard cursor defaults to using the foreground color of the character
     * underneath it.
     *
254 255 256 257 258 259
     * @param color By default, the widget uses the color of the
     * character under the cursor to draw the cursor, and inverts the
     * color of that character to make sure it is still readable. If @p
     * color is a valid QColor, the widget uses that color to draw the
     * cursor. If @p color is not an valid QColor, the widget falls back
     * to the default behavior.
260
     */
261
    void setKeyboardCursorColor(const QColor& color);
262

Jekyll Wu's avatar
Jekyll Wu committed
263
    /**
264 265
     * Returns the color of the keyboard cursor, or an invalid color if the keyboard
     * cursor color is set to change according to the foreground color of the character
Jekyll Wu's avatar
Jekyll Wu committed
266
     * underneath it.
267 268 269
     */
    QColor keyboardCursorColor() const;

270 271 272 273 274 275
    /**
     * Returns the number of lines of text which can be displayed in the widget.
     *
     * This will depend upon the height of the widget and the current font.
     * See fontHeight()
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
276 277 278
    int  lines() const {
        return _lines;
    }
279 280 281 282 283 284 285
    /**
     * Returns the number of characters of text which can be displayed on
     * each line in the widget.
     *
     * This will depend upon the width of the widget and the current font.
     * See fontWidth()
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
286 287 288
    int  columns() const {
        return _columns;
    }
289

290 291 292
    /**
     * Returns the height of the characters in the font used to draw the text in the display.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
293 294 295
    int  fontHeight() const {
        return _fontHeight;
    }
296
    /**
Jekyll Wu's avatar
Jekyll Wu committed
297
     * Returns the width of the characters in the display.
298 299
     * This assumes the use of a fixed-width font.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
300 301 302
    int  fontWidth() const {
        return _fontWidth;
    }
303

304 305
    void setSize(int columns, int lines);

306
    // reimplemented
307 308
    QSize sizeHint() const;

309
    /**
Jekyll Wu's avatar
Jekyll Wu committed
310
     * Sets which characters, in addition to letters and numbers,
311 312 313 314 315 316 317 318 319
     * are regarded as being part of a word for the purposes
     * of selecting words in the display by double clicking on them.
     *
     * The word boundaries occur at the first and last characters which
     * are either a letter, number, or a character in @p wc
     *
     * @param wc An array of characters which are to be considered parts
     * of a word ( in addition to letters and numbers ).
     */
320
    void setWordCharacters(const QString& wc);
Jekyll Wu's avatar
Jekyll Wu committed
321 322
    /**
     * Returns the characters which are considered part of a word for the
323 324 325 326
     * purpose of selecting words in the display with the mouse.
     *
     * @see setWordCharacters()
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
327 328 329
    QString wordCharacters() const {
        return _wordCharacters;
    }
330

Jekyll Wu's avatar
Jekyll Wu committed
331 332
    /**
     * Sets the type of effect used to alert the user when a 'bell' occurs in the
333 334 335 336 337
     * terminal session.
     *
     * The terminal session can trigger the bell effect by calling bell() with
     * the alert message.
     */
338
    void setBellMode(int mode);
Jekyll Wu's avatar
Jekyll Wu committed
339
    /**
340 341
     * Returns the type of effect used to alert the user when a 'bell' occurs in
     * the terminal session.
Kurt Hindenburg's avatar
Kurt Hindenburg committed
342
     *
343 344
     * See setBellMode()
     */
345 346
    int bellMode() const;

347 348 349
    /** Play a visual bell for prompt or warning. */
    void visualBell();

350
    /**
351
     * Specified whether zoom terminal on Ctrl+mousewheel  is enabled or not.
352 353 354 355 356 357
     * Defaults to enabled.
     */
    void setMouseWheelZoom(bool value) {
        _mouseWheelZoom = value;
    };
    /**
358
     * Returns the whether zoom terminal on Ctrl+mousewheel is enabled.
359 360 361 362 363 364 365
     *
     * See setMouseWheelZoom()
     */
    bool mouseWheelZoom() {
        return _mouseWheelZoom;
    };

Jekyll Wu's avatar
Jekyll Wu committed
366
    /**
367 368 369
     * Reimplemented.  Has no effect.  Use setVTFont() to change the font
     * used to draw characters in the display.
     */
370
    virtual void setFont(const QFont &);
371 372

    /** Returns the font used to draw characters in the display */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
373 374 375
    QFont getVTFont() {
        return font();
    }
376

Jekyll Wu's avatar
Jekyll Wu committed
377
    /**
378
     * Sets the font used to draw the display.  Has no effect if @p font
Jekyll Wu's avatar
Jekyll Wu committed
379
     * is larger than the size of the display itself.
380 381
     */
    void setVTFont(const QFont& font);
382

383 384 385 386 387 388
    /** Increases the font size */
    void increaseFontSize();

    /** Decreases the font size */
    void decreaseFontSize();

389 390 391 392
    /**
     * Specified whether anti-aliasing of text in the terminal display
     * is enabled or not.  Defaults to enabled.
     */
393 394
    void setAntialias(bool value) {
        _antialiasText = value;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
395
    }
Jekyll Wu's avatar
Jekyll Wu committed
396
    /**
397 398
     * Returns true if anti-aliasing of text in the terminal is enabled.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
399 400 401
    bool antialias() const {
        return _antialiasText;
    }
402 403 404 405 406

    /**
     * Specifies whether characters with intense colors should be rendered
     * as bold. Defaults to true.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
407 408 409
    void setBoldIntense(bool value) {
        _boldIntense = value;
    }
410 411 412
    /**
     * Returns true if characters with intense colors are rendered in bold.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
413 414 415
    bool getBoldIntense() const {
        return _boldIntense;
    }
416

417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
    /**
     * Specifies whether line characters will be displayed using font instead
     * of builtin code.
     * as bold. Defaults to false.
     */
    void setUseFontLineCharacters(bool value) {
        _useFontLineCharacters = value;
    }
    /**
     * Returns true if font line characters will be used.
     */
    bool getFontLineCharacters() const {
        return _useFontLineCharacters;
    }

432
    /**
Jekyll Wu's avatar
Jekyll Wu committed
433
     * Sets whether or not the current height and width of the
434 435 436
     * terminal in lines and columns is displayed whilst the widget
     * is being resized.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
437 438 439
    void setShowTerminalSizeHint(bool on) {
        _showTerminalSizeHint = on;
    }
Jekyll Wu's avatar
Jekyll Wu committed
440
    /**
441 442 443 444
     * Returns whether or not the current height and width of
     * the terminal in lines and columns is displayed whilst the widget
     * is being resized.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
445 446 447
    bool showTerminalSizeHint() const {
        return _showTerminalSizeHint;
    }
448

449 450 451 452
    /**
     * Sets the status of the BiDi rendering inside the terminal display.
     * Defaults to disabled.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
453 454 455
    void setBidiEnabled(bool set) {
        _bidiEnabled = set;
    }
456 457 458
    /**
     * Returns the status of the BiDi rendering in this widget.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
459 460 461
    bool isBidiEnabled() const {
        return _bidiEnabled;
    }
462

463 464 465 466 467 468 469 470 471 472 473 474 475 476
    /**
     * Enables or disables showing hints on URLs when ctrl is pressed
     * Defaults to disabled.
     */
    void setEnableUrlHints(bool on) {
        _enableShowUrlHint = on;
    }
    /**
     * Returns the status of the BiDi rendering in this widget.
     */
    bool areUrlHintsEnabled() const {
        return _enableShowUrlHint;
    }

477 478 479 480 481 482 483 484
    /**
     * Sets the terminal screen section which is displayed in this widget.
     * When updateImage() is called, the display fetches the latest character image from the
     * the associated terminal screen window.
     *
     * In terms of the model-view paradigm, the ScreenWindow is the model which is rendered
     * by the TerminalDisplay.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
485
    void setScreenWindow(ScreenWindow* window);
486
    /** Returns the terminal screen section which is displayed in this widget.  See setScreenWindow() */
487 488
    ScreenWindow* screenWindow() const;

489 490 491
    // Select the current line.
    void selectCurrentLine();

492 493
    void printContent(QPainter& painter, bool friendly);

494
public slots:
495 496 497 498 499
    /**
     * Scrolls current ScreenWindow
     *
     * it's needed for proper handling scroll commands in the Vt102Emulation class
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
500
    void scrollScreenWindow(enum ScreenWindow::RelativeScrollMode mode , int amount);
501

Jekyll Wu's avatar
Jekyll Wu committed
502
    /**
503 504 505
     * Causes the terminal display to fetch the latest character image from the associated
     * terminal screen ( see setScreenWindow() ) and redraw the display.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
506
    void updateImage();
507
    /**
Jekyll Wu's avatar
Jekyll Wu committed
508 509 510
     * Causes the terminal display to fetch the latest line status flags from the
     * associated terminal screen ( see setScreenWindow() ).
     */
511
    void updateLineProperties();
512

513 514 515 516 517 518 519 520
    void setAutoCopySelectedText(bool enabled);

    void setMiddleClickPasteMode(Enum::MiddleClickPasteModeEnum mode);

    /** Copies the selected text to the X11 Selection. */
    void copyToX11Selection();

    /** Copies the selected text to the system clipboard. */
Jekyll Wu's avatar
Jekyll Wu committed
521
    void copyToClipboard();
522

Jekyll Wu's avatar
Jekyll Wu committed
523 524
    /**
     * Pastes the content of the clipboard into the
525 526
     * display.
     */
527
    void pasteFromClipboard(bool appendEnter = false);
528
    /**
529
     * Pastes the content of the X11 selection into the
530 531
     * display.
     */
532
    void pasteFromX11Selection(bool appendEnter = false);
Robert Knight's avatar
 
Robert Knight committed
533

Jekyll Wu's avatar
Jekyll Wu committed
534
    /**
535 536 537 538
       * Changes whether the flow control warning box should be shown when the flow control
       * stop key (Ctrl+S) are pressed.
       */
    void setFlowControlWarningEnabled(bool enabled);
Jekyll Wu's avatar
Jekyll Wu committed
539 540
    /**
     * Returns true if the flow control warning box is enabled.
Robert Knight's avatar
 
Robert Knight committed
541 542
     * See outputSuspended() and setFlowControlWarningEnabled()
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
543 544 545
    bool flowControlWarningEnabled() const {
        return _flowControlWarningEnabled;
    }
Robert Knight's avatar
 
Robert Knight committed
546

Jekyll Wu's avatar
Jekyll Wu committed
547
    /**
548 549 550 551 552 553
     * Causes the widget to display or hide a message informing the user that terminal
     * output has been suspended (by using the flow control key combination Ctrl+S)
     *
     * @param suspended True if terminal output has been suspended and the warning message should
     *                     be shown or false to indicate that terminal output has been resumed and that
     *                     the warning message should disappear.
Jekyll Wu's avatar
Jekyll Wu committed
554
     */
555
    void outputSuspended(bool suspended);
556

Robert Knight's avatar
 
Robert Knight committed
557
    /**
Jekyll Wu's avatar
Jekyll Wu committed
558
     * Sets whether the program whose output is being displayed in the view
Robert Knight's avatar
 
Robert Knight committed
559 560 561 562 563
     * is interested in mouse events.
     *
     * If this is set to true, mouse signals will be emitted by the view when the user clicks, drags
     * or otherwise moves the mouse inside the view.
     * The user interaction needed to create selections will also change, and the user will be required
Jekyll Wu's avatar
Jekyll Wu committed
564
     * to hold down the shift key to create a selection or perform other mouse activities inside the
Robert Knight's avatar
 
Robert Knight committed
565 566 567 568 569 570 571
     * view area - since the program running in the terminal is being allowed to handle normal mouse
     * events itself.
     *
     * @param usesMouse Set to true if the program running in the terminal is interested in mouse events
     * or false otherwise.
     */
    void setUsesMouse(bool usesMouse);
572

573 574 575
    /** See setUsesMouse() */
    bool usesMouse() const;

576 577 578
    void setBracketedPasteMode(bool bracketedPasteMode);
    bool bracketedPasteMode() const;

579 580 581 582 583 584
    /**
     * Shows a notification that a bell event has occurred in the terminal.
     * TODO: More documentation here
     */
    void bell(const QString& message);

585 586 587 588 589 590
    /**
     * Gets the background of the display
     * @see setBackgroundColor(), setColorTable(), setForegroundColor()
     */
    QColor getBackgroundColor() const;

Jekyll Wu's avatar
Jekyll Wu committed
591 592
    /**
     * Sets the background of the display to the specified color.
593
     * @see setColorTable(), getBackgroundColor(), setForegroundColor()
594 595
     */
    void setBackgroundColor(const QColor& color);
596

Jekyll Wu's avatar
Jekyll Wu committed
597 598
    /**
     * Sets the text of the display to the specified color.
599
     * @see setColorTable(), setBackgroundColor(), getBackgroundColor()
600 601
     */
    void setForegroundColor(const QColor& color);
602

603 604 605 606 607 608 609 610 611 612
    /**
     * Sets the display's contents margins.
     */
    void setMargin(int margin);

    /**
     * Sets whether the contents are centered between the margins.
     */
    void setCenterContents(bool enable);

613
signals:
614

615 616 617
    /**
     * Emitted when the user presses a key whilst the terminal widget has focus.
     */
618
    void keyPressedSignal(QKeyEvent* event);
619

Jekyll Wu's avatar
Jekyll Wu committed
620
    /**
621
     * A mouse event occurred.
622 623 624
     * @param button The mouse button (0 for left button, 1 for middle button, 2 for right button, 3 for release)
     * @param column The character column where the event occurred
     * @param line The character row where the event occurred
625 626
     * @param eventType The type of event.  0 for a mouse press / release or 1 for mouse motion
     */
627
    void mouseSignal(int button, int column, int line, int eventType);
628 629
    void changedFontMetricSignal(int height, int width);
    void changedContentSizeSignal(int height, int width);
630

Jekyll Wu's avatar
Jekyll Wu committed
631
    /**
632 633 634 635 636
     * Emitted when the user right clicks on the display, or right-clicks with the Shift
     * key held down if usesMouse() is true.
     *
     * This can be used to display a context menu.
     */
637
    void configureRequest(const QPoint& position);
638

639
    /**
Jekyll Wu's avatar
Jekyll Wu committed
640 641 642
     * When a shortcut which is also a valid terminal key sequence is pressed while
     * the terminal widget  has focus, this signal is emitted to allow the host to decide
     * whether the shortcut should be overridden.
643 644 645 646 647
     * When the shortcut is overridden, the key sequence will be sent to the terminal emulation instead
     * and the action associated with the shortcut will not be triggered.
     *
     * @p override is set to false by default and the shortcut will be triggered as normal.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
648
    void overrideShortcutCheck(QKeyEvent* keyEvent, bool& override);
649

650
    void sendStringToEmu(const QByteArray& local8BitString);
651

652 653 654
    void focusLost();
    void focusGained();

655
protected:
Kurt Hindenburg's avatar
Kurt Hindenburg committed
656
    virtual bool event(QEvent* event);
657

Kurt Hindenburg's avatar
Kurt Hindenburg committed
658
    virtual void paintEvent(QPaintEvent* event);
659

660 661 662
    virtual void showEvent(QShowEvent* event);
    virtual void hideEvent(QHideEvent* event);
    virtual void resizeEvent(QResizeEvent* event);
663

664 665
    virtual void contextMenuEvent(QContextMenuEvent* event);

Kurt Hindenburg's avatar
Kurt Hindenburg committed
666
    virtual void fontChange(const QFont&);
667 668
    virtual void focusInEvent(QFocusEvent* event);
    virtual void focusOutEvent(QFocusEvent* event);
669
    virtual void keyPressEvent(QKeyEvent* event);
670
    virtual void keyReleaseEvent(QKeyEvent* event);
671
    virtual void leaveEvent(QEvent* event);
672
    virtual void mouseDoubleClickEvent(QMouseEvent* event);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
673 674 675 676 677
    virtual void mousePressEvent(QMouseEvent* event);
    virtual void mouseReleaseEvent(QMouseEvent* event);
    virtual void mouseMoveEvent(QMouseEvent* event);
    virtual void extendSelection(const QPoint& pos);
    virtual void wheelEvent(QWheelEvent* event);
678

Kurt Hindenburg's avatar
Kurt Hindenburg committed
679
    virtual bool focusNextPrevChild(bool next);
680

681 682 683
    // drag and drop
    virtual void dragEnterEvent(QDragEnterEvent* event);
    virtual void dropEvent(QDropEvent* event);
684 685 686
    void doDrag();
    enum DragState { diNone, diPending, diDragging };

687
    struct DragInfo {
Kurt Hindenburg's avatar
Kurt Hindenburg committed
688 689 690
        DragState       state;
        QPoint          start;
        QDrag*          dragObject;
691
    } _dragInfo;
692

693 694 695
    // classifies the 'ch' into one of three categories
    // and returns a character to indicate which category it is in
    //
Jekyll Wu's avatar
Jekyll Wu committed
696
    //     - A space (returns ' ')
697 698
    //     - Part of a word (returns 'a')
    //     - Other characters (returns the input character)
699
    QChar charClass(const Character& ch) const;
700 701 702

    void clearImage();

703
    void mouseTripleClickEvent(QMouseEvent* event);
704
    void selectLine(QPoint pos, bool entireLine);
705

706
    // reimplemented
Kurt Hindenburg's avatar
Kurt Hindenburg committed
707 708
    virtual void inputMethodEvent(QInputMethodEvent* event);
    virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
709

710
protected slots:
711

712
    void scrollBarPositionChanged(int value);
713
    void blinkTextEvent();
Stephan Binner's avatar
Stephan Binner committed
714
    void blinkCursorEvent();
715

716 717
private slots:

718 719
    void unmaskBell();
    void swapFGBGColors();
720
    void tripleClickTimeout();  // resets possibleTripleClick
Harald Hvaal's avatar
Harald Hvaal committed
721
    void viewScrolledByUser();
722

Jekyll Wu's avatar
Jekyll Wu committed
723
    /**
724
     * Called from the drag-and-drop popup. Causes the dropped URLs to be pasted as text.
Jekyll Wu's avatar
Jekyll Wu committed
725 726 727 728 729
     */
    void dropMenuPasteActionTriggered();

    void dropMenuCdActionTriggered();

730 731
    void dismissOutputSuspendedMessage();

732
private:
733 734 735 736
    // -- Drawing helpers --

    // divides the part of the display specified by 'rect' into
    // fragments according to their colors and styles and calls
737 738
    // drawTextFragment() or drawPrinterFriendlyTextFragment()
    // to draw the fragments
739
    void drawContents(QPainter& painter, const QRect& rect);
Harald Hvaal's avatar
Harald Hvaal committed
740 741
    // draw a transparent rectangle over the line of the current match
    void drawCurrentResultRect(QPainter& painter);
742 743
    // draws a section of text, all the text in this section
    // has a common color and style
Kurt Hindenburg's avatar
Kurt Hindenburg committed
744 745
    void drawTextFragment(QPainter& painter, const QRect& rect,
                          const QString& text, const Character* style);
746 747

    void drawPrinterFriendlyTextFragment(QPainter& painter, const QRect& rect,
748
                                         const QString& text, const Character* style);
749
    // draws the background for a text fragment
Robert Knight's avatar
 
Robert Knight committed
750 751 752 753
    // if useOpacitySetting is true then the color's alpha value will be set to
    // the display's transparency (set with setOpacity()), otherwise the background
    // will be drawn fully opaque
    void drawBackground(QPainter& painter, const QRect& rect, const QColor& color,
754
                        bool useOpacitySetting);
755
    // draws the cursor character
Kurt Hindenburg's avatar
Kurt Hindenburg committed
756 757
    void drawCursor(QPainter& painter, const QRect& rect , const QColor& foregroundColor,
                    const QColor& backgroundColor , bool& invertColors);
758
    // draws the characters or line graphics in a text fragment
Kurt Hindenburg's avatar
Kurt Hindenburg committed
759 760
    void drawCharacters(QPainter& painter, const QRect& rect,  const QString& text,
                        const Character* style, bool invertCharacterColor);
761
    // draws a string of line graphics
Kurt Hindenburg's avatar
Kurt Hindenburg committed
762
    void drawLineCharString(QPainter& painter, int x, int y,
763 764
                            const QString& str, const Character* attributes);

765
    // draws the preedit string for input methods
766 767
    void drawInputMethodPreeditString(QPainter& painter , const QRect& rect);

768 769
    // --

Jekyll Wu's avatar
Jekyll Wu committed
770
    // maps an area in the character image to an area on the widget
771
    QRect imageToWidget(const QRect& imageArea) const;
772

Jekyll Wu's avatar
Jekyll Wu committed
773
    // maps a point on the widget to the position ( ie. line and column )
774
    // of the character at that point.
Kurt Hindenburg's avatar
Kurt Hindenburg committed
775
    void getCharacterPosition(const QPoint& widgetPoint, int& line, int& column) const;
776 777 778

    // the area where the preedit string for input methods will be draw
    QRect preeditRect() const;
779

780 781 782 783
    // shows a notification window in the middle of the widget indicating the terminal's
    // current size in columns and lines
    void showResizeNotification();

Jekyll Wu's avatar
Jekyll Wu committed
784 785
    // scrolls the image by a number of lines.
    // 'lines' may be positive ( to scroll the image down )
786
    // or negative ( to scroll the image up )
787 788 789 790
    // 'region' is the part of the image to scroll - currently only
    // the top, bottom and height of 'region' are taken into account,
    // the left and right are ignored.
    void scrollImage(int lines , const QRect& region);
791

792 793 794
    void calcGeometry();
    void propagateSize();
    void updateImageSize();
795
    void makeImage();
796

797
    void paintFilters(QPainter& painter);
798

799 800 801
    // returns a region covering all of the areas of the widget which contain
    // a hotspot
    QRegion hotSpotRegion() const;
802

803 804
    // returns the position of the cursor in columns and lines
    QPoint cursorPosition() const;
805

806 807
    // redraws the cursor
    void updateCursor();
808

809 810
    bool handleShortcutOverrideEvent(QKeyEvent* event);

811
    void doPaste(QString text, bool appendReturn);
Jekyll Wu's avatar
Jekyll Wu committed
812

813 814
    void processMidButtonClick(QMouseEvent* event);

815 816
    QPoint findLineStart(const QPoint &pnt);
    QPoint findLineEnd(const QPoint &pnt);
817 818
    QPoint findWordStart(const QPoint &pnt);
    QPoint findWordEnd(const QPoint &pnt);
819

820
    // the window onto the terminal screen which this display
Jekyll Wu's avatar
Jekyll Wu committed
821
    // is currently showing.
822
    QPointer<ScreenWindow> _screenWindow;
823

824
    bool _bellMasked;
825

826
    QGridLayout* _gridLayout;
827

828 829 830 831
    bool _fixedFont; // has fixed pitch
    int  _fontHeight;     // height
    int  _fontWidth;     // width
    int  _fontAscent;     // ascend
832
    bool _boldIntense;   // Whether intense colors should be rendered with bold font
833

Robert Knight's avatar
 
Robert Knight committed
834 835
    int _leftMargin;    // offset
    int _topMargin;    // offset
836

837 838
    int _lines;      // the number of lines that can be displayed in the widget
    int _columns;    // the number of columns that can be displayed in the widget
839

840
    int _usedLines;  // the number of lines that are actually being used, this will be less
Kurt Hindenburg's avatar
Kurt Hindenburg committed
841 842
    // than 'lines' if the character image provided with setImage() is smaller
    // than the maximum image size which can be displayed
843

844
    int _usedColumns; // the number of columns that are actually being used, this will be less
Kurt Hindenburg's avatar
Kurt Hindenburg committed
845 846
    // than 'columns' if the character image provided with setImage() is smaller
    // than the maximum image size which can be displayed
847