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