| 1 | /* |
| 2 | Copyright 2007-2008 by Robert Knight <robertknight@gmail.com> |
| 3 | Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de> |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 2 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 18 | 02110-1301 USA. |
| 19 | */ |
| 20 | |
| 21 | #ifndef TERMINALDISPLAY_H |
| 22 | #define TERMINALDISPLAY_H |
| 23 | |
| 24 | // Qt |
| 25 | #include <QColor> |
| 26 | #include <QPointer> |
| 27 | #include <QWidget> |
| 28 | |
| 29 | // Konsole |
| 30 | #include "Filter.h" |
| 31 | #include "Character.h" |
| 32 | #include "qtermwidget.h" |
| 33 | //#include "konsole_export.h" |
| 34 | #define KONSOLEPRIVATE_EXPORT |
| 35 | |
| 36 | class QDrag; |
| 37 | class QDragEnterEvent; |
| 38 | class QDropEvent; |
| 39 | class QLabel; |
| 40 | class QTimer; |
| 41 | class QEvent; |
| 42 | class QGridLayout; |
| 43 | class QKeyEvent; |
| 44 | class QScrollBar; |
| 45 | class QShowEvent; |
| 46 | class QHideEvent; |
| 47 | class QTimerEvent; |
| 48 | class QWidget; |
| 49 | |
| 50 | //class KMenu; |
| 51 | |
| 52 | namespace Konsole |
| 53 | { |
| 54 | |
| 55 | enum MotionAfterPasting |
| 56 | { |
| 57 | // No move screenwindow after pasting |
| 58 | NoMoveScreenWindow = 0, |
| 59 | // Move start of screenwindow after pasting |
| 60 | MoveStartScreenWindow = 1, |
| 61 | // Move end of screenwindow after pasting |
| 62 | MoveEndScreenWindow = 2 |
| 63 | }; |
| 64 | |
| 65 | |
| 66 | extern unsigned short vt100_graphics[32]; |
| 67 | |
| 68 | class ScreenWindow; |
| 69 | |
| 70 | /** |
| 71 | * A widget which displays output from a terminal emulation and sends input keypresses and mouse activity |
| 72 | * to the terminal. |
| 73 | * |
| 74 | * When the terminal emulation receives new output from the program running in the terminal, |
| 75 | * it will update the display by calling updateImage(). |
| 76 | * |
| 77 | * TODO More documentation |
| 78 | */ |
| 79 | class KONSOLEPRIVATE_EXPORT TerminalDisplay : public QWidget |
| 80 | { |
| 81 | Q_OBJECT |
| 82 | |
| 83 | public: |
| 84 | /** Constructs a new terminal display widget with the specified parent. */ |
| 85 | TerminalDisplay(QWidget *parent=0); |
| 86 | virtual ~TerminalDisplay(); |
| 87 | |
| 88 | /** Returns the terminal color palette used by the display. */ |
| 89 | const ColorEntry* colorTable() const; |
| 90 | /** Sets the terminal color palette used by the display. */ |
| 91 | void setColorTable(const ColorEntry table[]); |
| 92 | /** |
| 93 | * Sets the seed used to generate random colors for the display |
| 94 | * (in color schemes that support them). |
| 95 | */ |
| 96 | void setRandomSeed(uint seed); |
| 97 | /** |
| 98 | * Returns the seed used to generate random colors for the display |
| 99 | * (in color schemes that support them). |
| 100 | */ |
| 101 | uint randomSeed() const; |
| 102 | |
| 103 | /** Sets the opacity of the terminal display. */ |
| 104 | void setOpacity(qreal opacity); |
| 105 | |
| 106 | /** Sets the background image of the terminal display. */ |
| 107 | void setBackgroundImage(QString backgroundImage); |
| 108 | |
| 109 | /** |
| 110 | * Specifies whether the terminal display has a vertical scroll bar, and if so whether it |
| 111 | * is shown on the left or right side of the display. |
| 112 | */ |
| 113 | void setScrollBarPosition(QTermWidget::ScrollBarPosition position); |
| 114 | |
| 115 | /** |
| 116 | * Sets the current position and range of the display's scroll bar. |
| 117 | * |
| 118 | * @param cursor The position of the scroll bar's thumb. |
| 119 | * @param lines The maximum value of the scroll bar. |
| 120 | */ |
| 121 | void setScroll(int cursor, int lines); |
| 122 | |
| 123 | /** |
| 124 | * Scroll to the bottom of the terminal (reset scrolling). |
| 125 | */ |
| 126 | void scrollToEnd(); |
| 127 | |
| 128 | /** |
| 129 | * Returns the display's filter chain. When the image for the display is updated, |
| 130 | * the text is passed through each filter in the chain. Each filter can define |
| 131 | * hotspots which correspond to certain strings (such as URLs or particular words). |
| 132 | * Depending on the type of the hotspots created by the filter ( returned by Filter::Hotspot::type() ) |
| 133 | * the view will draw visual cues such as underlines on mouse-over for links or translucent |
| 134 | * rectangles for markers. |
| 135 | * |
| 136 | * To add a new filter to the view, call: |
| 137 | * viewWidget->filterChain()->addFilter( filterObject ); |
| 138 | */ |
| 139 | FilterChain* filterChain() const; |
| 140 | |
| 141 | /** |
| 142 | * Updates the filters in the display's filter chain. This will cause |
| 143 | * the hotspots to be updated to match the current image. |
| 144 | * |
| 145 | * WARNING: This function can be expensive depending on the |
| 146 | * image size and number of filters in the filterChain() |
| 147 | * |
| 148 | * TODO - This API does not really allow efficient usage. Revise it so |
| 149 | * that the processing can be done in a better way. |
| 150 | * |
| 151 | * eg: |
| 152 | * - Area of interest may be known ( eg. mouse cursor hovering |
| 153 | * over an area ) |
| 154 | */ |
| 155 | void processFilters(); |
| 156 | |
| 157 | /** |
| 158 | * Returns a list of menu actions created by the filters for the content |
| 159 | * at the given @p position. |
| 160 | */ |
| 161 | QList<QAction*> filterActions(const QPoint& position); |
| 162 | |
| 163 | /** Returns true if the cursor is set to blink or false otherwise. */ |
| 164 | bool blinkingCursor() { return _hasBlinkingCursor; } |
| 165 | /** Specifies whether or not the cursor blinks. */ |
| 166 | void setBlinkingCursor(bool blink); |
| 167 | |
| 168 | /** Specifies whether or not text can blink. */ |
| 169 | void setBlinkingTextEnabled(bool blink); |
| 170 | |
| 171 | void setCtrlDrag(bool enable) { _ctrlDrag=enable; } |
| 172 | bool ctrlDrag() { return _ctrlDrag; } |
| 173 | |
| 174 | /** |
| 175 | * This enum describes the methods for selecting text when |
| 176 | * the user triple-clicks within the display. |
| 177 | */ |
| 178 | enum TripleClickMode |
| 179 | { |
| 180 | /** Select the whole line underneath the cursor. */ |
| 181 | SelectWholeLine, |
| 182 | /** Select from the current cursor position to the end of the line. */ |
| 183 | SelectForwardsFromCursor |
| 184 | }; |
| 185 | /** Sets how the text is selected when the user triple clicks within the display. */ |
| 186 | void setTripleClickMode(TripleClickMode mode) { _tripleClickMode = mode; } |
| 187 | /** See setTripleClickSelectionMode() */ |
| 188 | TripleClickMode tripleClickMode() { return _tripleClickMode; } |
| 189 | |
| 190 | void setLineSpacing(uint); |
| 191 | void setMargin(int); |
| 192 | |
| 193 | int margin() const; |
| 194 | uint lineSpacing() const; |
| 195 | |
| 196 | void emitSelection(bool useXselection,bool appendReturn); |
| 197 | |
| 198 | /** change and wrap text corresponding to paste mode **/ |
| 199 | void bracketText(QString& text); |
| 200 | |
| 201 | /** |
| 202 | * Sets the shape of the keyboard cursor. This is the cursor drawn |
| 203 | * at the position in the terminal where keyboard input will appear. |
| 204 | * |
| 205 | * In addition the terminal display widget also has a cursor for |
| 206 | * the mouse pointer, which can be set using the QWidget::setCursor() |
| 207 | * method. |
| 208 | * |
| 209 | * Defaults to BlockCursor |
| 210 | */ |
| 211 | void setKeyboardCursorShape(QTermWidget::KeyboardCursorShape shape); |
| 212 | /** |
| 213 | * Returns the shape of the keyboard cursor. See setKeyboardCursorShape() |
| 214 | */ |
| 215 | QTermWidget::KeyboardCursorShape keyboardCursorShape() const; |
| 216 | |
| 217 | /** |
| 218 | * Sets the color used to draw the keyboard cursor. |
| 219 | * |
| 220 | * The keyboard cursor defaults to using the foreground color of the character |
| 221 | * underneath it. |
| 222 | * |
| 223 | * @param useForegroundColor If true, the cursor color will change to match |
| 224 | * the foreground color of the character underneath it as it is moved, in this |
| 225 | * case, the @p color parameter is ignored and the color of the character |
| 226 | * under the cursor is inverted to ensure that it is still readable. |
| 227 | * @param color The color to use to draw the cursor. This is only taken into |
| 228 | * account if @p useForegroundColor is false. |
| 229 | */ |
| 230 | void setKeyboardCursorColor(bool useForegroundColor , const QColor& color); |
| 231 | |
| 232 | /** |
| 233 | * Returns the color of the keyboard cursor, or an invalid color if the keyboard |
| 234 | * cursor color is set to change according to the foreground color of the character |
| 235 | * underneath it. |
| 236 | */ |
| 237 | QColor keyboardCursorColor() const; |
| 238 | |
| 239 | /** |
| 240 | * Returns the number of lines of text which can be displayed in the widget. |
| 241 | * |
| 242 | * This will depend upon the height of the widget and the current font. |
| 243 | * See fontHeight() |
| 244 | */ |
| 245 | int lines() { return _lines; } |
| 246 | /** |
| 247 | * Returns the number of characters of text which can be displayed on |
| 248 | * each line in the widget. |
| 249 | * |
| 250 | * This will depend upon the width of the widget and the current font. |
| 251 | * See fontWidth() |
| 252 | */ |
| 253 | int columns() { return _columns; } |
| 254 | |
| 255 | /** |
| 256 | * Returns the height of the characters in the font used to draw the text in the display. |
| 257 | */ |
| 258 | int fontHeight() { return _fontHeight; } |
| 259 | /** |
| 260 | * Returns the width of the characters in the display. |
| 261 | * This assumes the use of a fixed-width font. |
| 262 | */ |
| 263 | int fontWidth() { return _fontWidth; } |
| 264 | |
| 265 | void setSize(int cols, int lins); |
| 266 | void setFixedSize(int cols, int lins); |
| 267 | |
| 268 | // reimplemented |
| 269 | QSize sizeHint() const; |
| 270 | |
| 271 | /** |
| 272 | * Sets which characters, in addition to letters and numbers, |
| 273 | * are regarded as being part of a word for the purposes |
| 274 | * of selecting words in the display by double clicking on them. |
| 275 | * |
| 276 | * The word boundaries occur at the first and last characters which |
| 277 | * are either a letter, number, or a character in @p wc |
| 278 | * |
| 279 | * @param wc An array of characters which are to be considered parts |
| 280 | * of a word ( in addition to letters and numbers ). |
| 281 | */ |
| 282 | void setWordCharacters(const QString& wc); |
| 283 | /** |
| 284 | * Returns the characters which are considered part of a word for the |
| 285 | * purpose of selecting words in the display with the mouse. |
| 286 | * |
| 287 | * @see setWordCharacters() |
| 288 | */ |
| 289 | QString wordCharacters() { return _wordCharacters; } |
| 290 | |
| 291 | /** |
| 292 | * Sets the type of effect used to alert the user when a 'bell' occurs in the |
| 293 | * terminal session. |
| 294 | * |
| 295 | * The terminal session can trigger the bell effect by calling bell() with |
| 296 | * the alert message. |
| 297 | */ |
| 298 | void setBellMode(int mode); |
| 299 | /** |
| 300 | * Returns the type of effect used to alert the user when a 'bell' occurs in |
| 301 | * the terminal session. |
| 302 | * |
| 303 | * See setBellMode() |
| 304 | */ |
| 305 | int bellMode() { return _bellMode; } |
| 306 | |
| 307 | /** |
| 308 | * This enum describes the different types of sounds and visual effects which |
| 309 | * can be used to alert the user when a 'bell' occurs in the terminal |
| 310 | * session. |
| 311 | */ |
| 312 | enum BellMode |
| 313 | { |
| 314 | /** A system beep. */ |
| 315 | SystemBeepBell=0, |
| 316 | /** |
| 317 | * KDE notification. This may play a sound, show a passive popup |
| 318 | * or perform some other action depending on the user's settings. |
| 319 | */ |
| 320 | NotifyBell=1, |
| 321 | /** A silent, visual bell (eg. inverting the display's colors briefly) */ |
| 322 | VisualBell=2, |
| 323 | /** No bell effects */ |
| 324 | NoBell=3 |
| 325 | }; |
| 326 | |
| 327 | void setSelection(const QString &t); |
| 328 | |
| 329 | /** |
| 330 | * Reimplemented. Has no effect. Use setVTFont() to change the font |
| 331 | * used to draw characters in the display. |
| 332 | */ |
| 333 | virtual void setFont(const QFont &); |
| 334 | |
| 335 | /** Returns the font used to draw characters in the display */ |
| 336 | QFont getVTFont() { return font(); } |
| 337 | |
| 338 | /** |
| 339 | * Sets the font used to draw the display. Has no effect if @p font |
| 340 | * is larger than the size of the display itself. |
| 341 | */ |
| 342 | void setVTFont(const QFont& font); |
| 343 | |
| 344 | /** |
| 345 | * Specified whether anti-aliasing of text in the terminal display |
| 346 | * is enabled or not. Defaults to enabled. |
| 347 | */ |
| 348 | static void setAntialias( bool antialias ) { _antialiasText = antialias; } |
| 349 | /** |
| 350 | * Returns true if anti-aliasing of text in the terminal is enabled. |
| 351 | */ |
| 352 | static bool antialias() { return _antialiasText; } |
| 353 | |
| 354 | /** |
| 355 | * Specifies whether characters with intense colors should be rendered |
| 356 | * as bold. Defaults to true. |
| 357 | */ |
| 358 | void setBoldIntense(bool value) { _boldIntense = value; } |
| 359 | /** |
| 360 | * Returns true if characters with intense colors are rendered in bold. |
| 361 | */ |
| 362 | bool getBoldIntense() { return _boldIntense; } |
| 363 | |
| 364 | /** |
| 365 | * Sets whether or not the current height and width of the |
| 366 | * terminal in lines and columns is displayed whilst the widget |
| 367 | * is being resized. |
| 368 | */ |
| 369 | void setTerminalSizeHint(bool on) { _terminalSizeHint=on; } |
| 370 | /** |
| 371 | * Returns whether or not the current height and width of |
| 372 | * the terminal in lines and columns is displayed whilst the widget |
| 373 | * is being resized. |
| 374 | */ |
| 375 | bool terminalSizeHint() { return _terminalSizeHint; } |
| 376 | /** |
| 377 | * Sets whether the terminal size display is shown briefly |
| 378 | * after the widget is first shown. |
| 379 | * |
| 380 | * See setTerminalSizeHint() , isTerminalSizeHint() |
| 381 | */ |
| 382 | void setTerminalSizeStartup(bool on) { _terminalSizeStartup=on; } |
| 383 | |
| 384 | /** |
| 385 | * Sets the status of the BiDi rendering inside the terminal display. |
| 386 | * Defaults to disabled. |
| 387 | */ |
| 388 | void setBidiEnabled(bool set) { _bidiEnabled=set; } |
| 389 | /** |
| 390 | * Returns the status of the BiDi rendering in this widget. |
| 391 | */ |
| 392 | bool isBidiEnabled() { return _bidiEnabled; } |
| 393 | |
| 394 | /** |
| 395 | * Sets the terminal screen section which is displayed in this widget. |
| 396 | * When updateImage() is called, the display fetches the latest character image from the |
| 397 | * the associated terminal screen window. |
| 398 | * |
| 399 | * In terms of the model-view paradigm, the ScreenWindow is the model which is rendered |
| 400 | * by the TerminalDisplay. |
| 401 | */ |
| 402 | void setScreenWindow( ScreenWindow* window ); |
| 403 | /** Returns the terminal screen section which is displayed in this widget. See setScreenWindow() */ |
| 404 | ScreenWindow* screenWindow() const; |
| 405 | |
| 406 | static bool HAVE_TRANSPARENCY; |
| 407 | |
| 408 | void setMotionAfterPasting(MotionAfterPasting action); |
| 409 | int motionAfterPasting(); |
| 410 | |
| 411 | // maps a point on the widget to the position ( ie. line and column ) |
| 412 | // of the character at that point. |
| 413 | void getCharacterPosition(const QPoint& widgetPoint,int& line,int& column) const; |
| 414 | |
| 415 | public slots: |
| 416 | |
| 417 | /** |
| 418 | * Causes the terminal display to fetch the latest character image from the associated |
| 419 | * terminal screen ( see setScreenWindow() ) and redraw the display. |
| 420 | */ |
| 421 | void updateImage(); |
| 422 | |
| 423 | /** Essentially calles processFilters(). |
| 424 | */ |
| 425 | void updateFilters(); |
| 426 | |
| 427 | /** |
| 428 | * Causes the terminal display to fetch the latest line status flags from the |
| 429 | * associated terminal screen ( see setScreenWindow() ). |
| 430 | */ |
| 431 | void updateLineProperties(); |
| 432 | |
| 433 | /** Copies the selected text to the clipboard. */ |
| 434 | void copyClipboard(); |
| 435 | /** |
| 436 | * Pastes the content of the clipboard into the |
| 437 | * display. |
| 438 | */ |
| 439 | void pasteClipboard(); |
| 440 | /** |
| 441 | * Pastes the content of the selection into the |
| 442 | * display. |
| 443 | */ |
| 444 | void pasteSelection(); |
| 445 | |
| 446 | /** |
| 447 | * Changes whether the flow control warning box should be shown when the flow control |
| 448 | * stop key (Ctrl+S) are pressed. |
| 449 | */ |
| 450 | void setFlowControlWarningEnabled(bool enabled); |
| 451 | /** |
| 452 | * Returns true if the flow control warning box is enabled. |
| 453 | * See outputSuspended() and setFlowControlWarningEnabled() |
| 454 | */ |
| 455 | bool flowControlWarningEnabled() const |
| 456 | { return _flowControlWarningEnabled; } |
| 457 | |
| 458 | /** |
| 459 | * Causes the widget to display or hide a message informing the user that terminal |
| 460 | * output has been suspended (by using the flow control key combination Ctrl+S) |
| 461 | * |
| 462 | * @param suspended True if terminal output has been suspended and the warning message should |
| 463 | * be shown or false to indicate that terminal output has been resumed and that |
| 464 | * the warning message should disappear. |
| 465 | */ |
| 466 | void outputSuspended(bool suspended); |
| 467 | |
| 468 | /** |
| 469 | * Sets whether the program whoose output is being displayed in the view |
| 470 | * is interested in mouse events. |
| 471 | * |
| 472 | * If this is set to true, mouse signals will be emitted by the view when the user clicks, drags |
| 473 | * or otherwise moves the mouse inside the view. |
| 474 | * The user interaction needed to create selections will also change, and the user will be required |
| 475 | * to hold down the shift key to create a selection or perform other mouse activities inside the |
| 476 | * view area - since the program running in the terminal is being allowed to handle normal mouse |
| 477 | * events itself. |
| 478 | * |
| 479 | * @param usesMouse Set to true if the program running in the terminal is interested in mouse events |
| 480 | * or false otherwise. |
| 481 | */ |
| 482 | void setUsesMouse(bool usesMouse); |
| 483 | |
| 484 | /** See setUsesMouse() */ |
| 485 | bool usesMouse() const; |
| 486 | |
| 487 | void setBracketedPasteMode(bool bracketedPasteMode); |
| 488 | bool bracketedPasteMode() const; |
| 489 | |
| 490 | /** |
| 491 | * Shows a notification that a bell event has occurred in the terminal. |
| 492 | * TODO: More documentation here |
| 493 | */ |
| 494 | void bell(const QString& message); |
| 495 | |
| 496 | /** |
| 497 | * Sets the background of the display to the specified color. |
| 498 | * @see setColorTable(), setForegroundColor() |
| 499 | */ |
| 500 | void setBackgroundColor(const QColor& color); |
| 501 | |
| 502 | /** |
| 503 | * Sets the text of the display to the specified color. |
| 504 | * @see setColorTable(), setBackgroundColor() |
| 505 | */ |
| 506 | void setForegroundColor(const QColor& color); |
| 507 | |
| 508 | void selectionChanged(); |
| 509 | |
| 510 | signals: |
| 511 | |
| 512 | /** |
| 513 | * Emitted when the user presses a key whilst the terminal widget has focus. |
| 514 | */ |
| 515 | void keyPressedSignal(QKeyEvent *e); |
| 516 | |
| 517 | /** |
| 518 | * A mouse event occurred. |
| 519 | * @param button The mouse button (0 for left button, 1 for middle button, 2 for right button, 3 for release) |
| 520 | * @param column The character column where the event occurred |
| 521 | * @param line The character row where the event occurred |
| 522 | * @param eventType The type of event. 0 for a mouse press / release or 1 for mouse motion |
| 523 | */ |
| 524 | void mouseSignal(int button, int column, int line, int eventType); |
| 525 | void changedFontMetricSignal(int height, int width); |
| 526 | void changedContentSizeSignal(int height, int width); |
| 527 | |
| 528 | /** |
| 529 | * Emitted when the user right clicks on the display, or right-clicks with the Shift |
| 530 | * key held down if usesMouse() is true. |
| 531 | * |
| 532 | * This can be used to display a context menu. |
| 533 | */ |
| 534 | void configureRequest(const QPoint& position); |
| 535 | |
| 536 | /** |
| 537 | * When a shortcut which is also a valid terminal key sequence is pressed while |
| 538 | * the terminal widget has focus, this signal is emitted to allow the host to decide |
| 539 | * whether the shortcut should be overridden. |
| 540 | * When the shortcut is overridden, the key sequence will be sent to the terminal emulation instead |
| 541 | * and the action associated with the shortcut will not be triggered. |
| 542 | * |
| 543 | * @p override is set to false by default and the shortcut will be triggered as normal. |
| 544 | */ |
| 545 | void overrideShortcutCheck(QKeyEvent* keyEvent,bool& override); |
| 546 | |
| 547 | void isBusySelecting(bool); |
| 548 | void sendStringToEmu(const char*); |
| 549 | |
| 550 | // qtermwidget signals |
| 551 | void copyAvailable(bool); |
| 552 | void termGetFocus(); |
| 553 | void termLostFocus(); |
| 554 | |
| 555 | void notifyBell(const QString&); |
| 556 | void usesMouseChanged(); |
| 557 | |
| 558 | protected: |
| 559 | virtual bool event( QEvent * ); |
| 560 | |
| 561 | virtual void paintEvent( QPaintEvent * ); |
| 562 | |
| 563 | virtual void showEvent(QShowEvent*); |
| 564 | virtual void hideEvent(QHideEvent*); |
| 565 | virtual void resizeEvent(QResizeEvent*); |
| 566 | |
| 567 | virtual void fontChange(const QFont &font); |
| 568 | virtual void focusInEvent(QFocusEvent* event); |
| 569 | virtual void focusOutEvent(QFocusEvent* event); |
| 570 | virtual void keyPressEvent(QKeyEvent* event); |
| 571 | virtual void mouseDoubleClickEvent(QMouseEvent* ev); |
| 572 | virtual void mousePressEvent( QMouseEvent* ); |
| 573 | virtual void mouseReleaseEvent( QMouseEvent* ); |
| 574 | virtual void mouseMoveEvent( QMouseEvent* ); |
| 575 | virtual void extendSelection( const QPoint& pos ); |
| 576 | virtual void wheelEvent( QWheelEvent* ); |
| 577 | |
| 578 | virtual bool focusNextPrevChild( bool next ); |
| 579 | |
| 580 | // drag and drop |
| 581 | virtual void dragEnterEvent(QDragEnterEvent* event); |
| 582 | virtual void dropEvent(QDropEvent* event); |
| 583 | void doDrag(); |
| 584 | enum DragState { diNone, diPending, diDragging }; |
| 585 | |
| 586 | struct _dragInfo { |
| 587 | DragState state; |
| 588 | QPoint start; |
| 589 | QDrag *dragObject; |
| 590 | } dragInfo; |
| 591 | |
| 592 | // classifies the 'ch' into one of three categories |
| 593 | // and returns a character to indicate which category it is in |
| 594 | // |
| 595 | // - A space (returns ' ') |
| 596 | // - Part of a word (returns 'a') |
| 597 | // - Other characters (returns the input character) |
| 598 | QChar charClass(QChar ch) const; |
| 599 | |
| 600 | void clearImage(); |
| 601 | |
| 602 | void mouseTripleClickEvent(QMouseEvent* ev); |
| 603 | |
| 604 | // reimplemented |
| 605 | virtual void inputMethodEvent ( QInputMethodEvent* event ); |
| 606 | virtual QVariant inputMethodQuery( Qt::InputMethodQuery query ) const; |
| 607 | |
| 608 | protected slots: |
| 609 | |
| 610 | void scrollBarPositionChanged(int value); |
| 611 | void blinkEvent(); |
| 612 | void blinkCursorEvent(); |
| 613 | |
| 614 | //Renables bell noises and visuals. Used to disable further bells for a short period of time |
| 615 | //after emitting the first in a sequence of bell events. |
| 616 | void enableBell(); |
| 617 | |
| 618 | private slots: |
| 619 | |
| 620 | void swapColorTable(); |
| 621 | void tripleClickTimeout(); // resets possibleTripleClick |
| 622 | |
| 623 | private: |
| 624 | |
| 625 | // -- Drawing helpers -- |
| 626 | |
| 627 | // determine the width of this text |
| 628 | int textWidth(int startColumn, int length, int line) const; |
| 629 | // determine the area that encloses this series of characters |
| 630 | QRect calculateTextArea(int topLeftX, int topLeftY, int startColumn, int line, int length); |
| 631 | |
| 632 | // divides the part of the display specified by 'rect' into |
| 633 | // fragments according to their colors and styles and calls |
| 634 | // drawTextFragment() to draw the fragments |
| 635 | void drawContents(QPainter &paint, const QRect &rect); |
| 636 | // draws a section of text, all the text in this section |
| 637 | // has a common color and style |
| 638 | void drawTextFragment(QPainter& painter, const QRect& rect, |
| 639 | const std::wstring& text, const Character* style); |
| 640 | // draws the background for a text fragment |
| 641 | // if useOpacitySetting is true then the color's alpha value will be set to |
| 642 | // the display's transparency (set with setOpacity()), otherwise the background |
| 643 | // will be drawn fully opaque |
| 644 | void drawBackground(QPainter& painter, const QRect& rect, const QColor& color, |
| 645 | bool useOpacitySetting); |
| 646 | // draws the cursor character |
| 647 | void drawCursor(QPainter& painter, const QRect& rect , const QColor& foregroundColor, |
| 648 | const QColor& backgroundColor , bool& invertColors); |
| 649 | // draws the characters or line graphics in a text fragment |
| 650 | void drawCharacters(QPainter& painter, const QRect& rect, const std::wstring& text, |
| 651 | const Character* style, bool invertCharacterColor); |
| 652 | // draws a string of line graphics |
| 653 | void drawLineCharString(QPainter& painter, int x, int y, |
| 654 | const std::wstring& str, const Character* attributes); |
| 655 | |
| 656 | // draws the preedit string for input methods |
| 657 | void drawInputMethodPreeditString(QPainter& painter , const QRect& rect); |
| 658 | |
| 659 | // -- |
| 660 | |
| 661 | // maps an area in the character image to an area on the widget |
| 662 | QRect imageToWidget(const QRect& imageArea) const; |
| 663 | |
| 664 | // the area where the preedit string for input methods will be draw |
| 665 | QRect preeditRect() const; |
| 666 | |
| 667 | // shows a notification window in the middle of the widget indicating the terminal's |
| 668 | // current size in columns and lines |
| 669 | void showResizeNotification(); |
| 670 | |
| 671 | // scrolls the image by a number of lines. |
| 672 | // 'lines' may be positive ( to scroll the image down ) |
| 673 | // or negative ( to scroll the image up ) |
| 674 | // 'region' is the part of the image to scroll - currently only |
| 675 | // the top, bottom and height of 'region' are taken into account, |
| 676 | // the left and right are ignored. |
| 677 | void scrollImage(int lines , const QRect& region); |
| 678 | |
| 679 | void calcGeometry(); |
| 680 | void propagateSize(); |
| 681 | void updateImageSize(); |
| 682 | void makeImage(); |
| 683 | |
| 684 | void paintFilters(QPainter& painter); |
| 685 | |
| 686 | void calDrawTextAdditionHeight(QPainter& painter); |
| 687 | |
| 688 | // returns a region covering all of the areas of the widget which contain |
| 689 | // a hotspot |
| 690 | QRegion hotSpotRegion() const; |
| 691 | |
| 692 | // returns the position of the cursor in columns and lines |
| 693 | QPoint cursorPosition() const; |
| 694 | |
| 695 | // redraws the cursor |
| 696 | void updateCursor(); |
| 697 | |
| 698 | bool handleShortcutOverrideEvent(QKeyEvent* event); |
| 699 | |
| 700 | // the window onto the terminal screen which this display |
| 701 | // is currently showing. |
| 702 | QPointer<ScreenWindow> _screenWindow; |
| 703 | |
| 704 | bool _allowBell; |
| 705 | |
| 706 | QGridLayout* _gridLayout; |
| 707 | |
| 708 | bool _fixedFont; // has fixed pitch |
| 709 | int _fontHeight; // height |
| 710 | int _fontWidth; // width |
| 711 | int _fontAscent; // ascend |
| 712 | bool _boldIntense; // Whether intense colors should be rendered with bold font |
| 713 | int _drawTextAdditionHeight; // additional height to prevent font trancation |
| 714 | bool _drawTextTestFlag; // indicate it is a testing or not |
| 715 | |
| 716 | int _leftMargin; // offset |
| 717 | int _topMargin; // offset |
| 718 | |
| 719 | int _lines; // the number of lines that can be displayed in the widget |
| 720 | int _columns; // the number of columns that can be displayed in the widget |
| 721 | |
| 722 | int _usedLines; // the number of lines that are actually being used, this will be less |
| 723 | // than 'lines' if the character image provided with setImage() is smaller |
| 724 | // than the maximum image size which can be displayed |
| 725 | |
| 726 | int _usedColumns; // the number of columns that are actually being used, this will be less |
| 727 | // than 'columns' if the character image provided with setImage() is smaller |
| 728 | // than the maximum image size which can be displayed |
| 729 | |
| 730 | int _contentHeight; |
| 731 | int _contentWidth; |
| 732 | Character* _image; // [lines][columns] |
| 733 | // only the area [usedLines][usedColumns] in the image contains valid data |
| 734 | |
| 735 | int _imageSize; |
| 736 | QVector<LineProperty> _lineProperties; |
| 737 | |
| 738 | ColorEntry _colorTable[TABLE_COLORS]; |
| 739 | uint _randomSeed; |
| 740 | |
| 741 | bool _resizing; |
| 742 | bool _terminalSizeHint; |
| 743 | bool _terminalSizeStartup; |
| 744 | bool _bidiEnabled; |
| 745 | bool _mouseMarks; |
| 746 | bool _bracketedPasteMode; |
| 747 | |
| 748 | QPoint _iPntSel; // initial selection point |
| 749 | QPoint _pntSel; // current selection point |
| 750 | QPoint _tripleSelBegin; // help avoid flicker |
| 751 | int _actSel; // selection state |
| 752 | bool _wordSelectionMode; |
| 753 | bool _lineSelectionMode; |
| 754 | bool _preserveLineBreaks; |
| 755 | bool _columnSelectionMode; |
| 756 | |
| 757 | QClipboard* _clipboard; |
| 758 | QScrollBar* _scrollBar; |
| 759 | QTermWidget::ScrollBarPosition _scrollbarLocation; |
| 760 | QString _wordCharacters; |
| 761 | int _bellMode; |
| 762 | |
| 763 | bool _blinking; // hide text in paintEvent |
| 764 | bool _hasBlinker; // has characters to blink |
| 765 | bool _cursorBlinking; // hide cursor in paintEvent |
| 766 | bool _hasBlinkingCursor; // has blinking cursor enabled |
| 767 | bool _allowBlinkingText; // allow text to blink |
| 768 | bool _ctrlDrag; // require Ctrl key for drag |
| 769 | TripleClickMode _tripleClickMode; |
| 770 | bool _isFixedSize; //Columns / lines are locked. |
| 771 | QTimer* _blinkTimer; // active when hasBlinker |
| 772 | QTimer* _blinkCursorTimer; // active when hasBlinkingCursor |
| 773 | |
| 774 | //QMenu* _drop; |
| 775 | QString _dropText; |
| 776 | int _dndFileCount; |
| 777 | |
| 778 | bool _possibleTripleClick; // is set in mouseDoubleClickEvent and deleted |
| 779 | // after QApplication::doubleClickInterval() delay |
| 780 | |
| 781 | |
| 782 | QLabel* _resizeWidget; |
| 783 | QTimer* _resizeTimer; |
| 784 | |
| 785 | bool _flowControlWarningEnabled; |
| 786 | |
| 787 | //widgets related to the warning message that appears when the user presses Ctrl+S to suspend |
| 788 | //terminal output - informing them what has happened and how to resume output |
| 789 | QLabel* _outputSuspendedLabel; |
| 790 | |
| 791 | uint _lineSpacing; |
| 792 | |
| 793 | bool _colorsInverted; // true during visual bell |
| 794 | |
| 795 | QSize _size; |
| 796 | |
| 797 | QRgb _blendColor; |
| 798 | |
| 799 | QPixmap _backgroundImage; |
| 800 | |
| 801 | // list of filters currently applied to the display. used for links and |
| 802 | // search highlight |
| 803 | TerminalImageFilterChain* _filterChain; |
| 804 | QRegion _mouseOverHotspotArea; |
| 805 | |
| 806 | QTermWidget::KeyboardCursorShape _cursorShape; |
| 807 | |
| 808 | // custom cursor color. if this is invalid then the foreground |
| 809 | // color of the character under the cursor is used |
| 810 | QColor _cursorColor; |
| 811 | |
| 812 | |
| 813 | MotionAfterPasting mMotionAfterPasting; |
| 814 | |
| 815 | struct InputMethodData |
| 816 | { |
| 817 | std::wstring preeditString; |
| 818 | QRect previousPreeditRect; |
| 819 | }; |
| 820 | InputMethodData _inputMethodData; |
| 821 | |
| 822 | static bool _antialiasText; // do we antialias or not |
| 823 | |
| 824 | //the delay in milliseconds between redrawing blinking text |
| 825 | static const int TEXT_BLINK_DELAY = 500; |
| 826 | |
| 827 | int _leftBaseMargin; |
| 828 | int _topBaseMargin; |
| 829 | |
| 830 | public: |
| 831 | static void setTransparencyEnabled(bool enable) |
| 832 | { |
| 833 | HAVE_TRANSPARENCY = enable; |
| 834 | } |
| 835 | }; |
| 836 | |
| 837 | class AutoScrollHandler : public QObject |
| 838 | { |
| 839 | Q_OBJECT |
| 840 | |
| 841 | public: |
| 842 | AutoScrollHandler(QWidget* parent); |
| 843 | protected: |
| 844 | virtual void timerEvent(QTimerEvent* event); |
| 845 | virtual bool eventFilter(QObject* watched,QEvent* event); |
| 846 | private: |
| 847 | QWidget* widget() const { return static_cast<QWidget*>(parent()); } |
| 848 | int _timerId; |
| 849 | }; |
| 850 | |
| 851 | } |
| 852 | |
| 853 | #endif // TERMINALDISPLAY_H |
| 854 | |