1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
|
/*
Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
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.
*/
#ifndef TERMINALDISPLAY_H
#define TERMINALDISPLAY_H
// Qt
#include <QColor>
#include <QPointer>
#include <QWidget>
// Konsole
#include "Filter.h"
#include "Character.h"
#include "qtermwidget.h"
//#include "konsole_export.h"
#include "tools.h"
#include <QGesture>
#include <QPanGesture>
#include <QSwipeGesture>
#include <QPinchGesture>
#include <QTapAndHoldGesture>
#include <QGestureEvent>
#include <math.h>
#define CELL_TIME 15
#define TAP_MOVE_DELAY 300
//#include "konsole_export.h"
#define KONSOLEPRIVATE_EXPORT
class QDrag;
class QDragEnterEvent;
class QDropEvent;
class QLabel;
class QTimer;
class QEvent;
class QGridLayout;
class QKeyEvent;
class QScrollBar;
class QShowEvent;
class QHideEvent;
class QTimerEvent;
class QWidget;
//class KMenu;
namespace Konsole
{
enum MotionAfterPasting
{
// No move screenwindow after pasting
NoMoveScreenWindow = 0,
// Move start of screenwindow after pasting
MoveStartScreenWindow = 1,
// Move end of screenwindow after pasting
MoveEndScreenWindow = 2
};
/***add begin by ut001121 zhangmeng 20200912 声明字号限制 修复42250***/
extern __attribute__((visibility("default"))) int __minFontSize;
extern __attribute__((visibility("default"))) int __maxFontSize;
/***add end by ut001121***/
extern unsigned short vt100_graphics[32];
class ScreenWindow;
/**
* A widget which displays output from a terminal emulation and sends input keypresses and mouse activity
* to the terminal.
*
* When the terminal emulation receives new output from the program running in the terminal,
* it will update the display by calling updateImage().
*
* TODO More documentation
*/
class KONSOLEPRIVATE_EXPORT TerminalDisplay : public QWidget
{
Q_OBJECT
public:
/** Constructs a new terminal display widget with the specified parent. */
explicit TerminalDisplay(QWidget *parent=nullptr);
~TerminalDisplay() override;
/** Returns the terminal color palette used by the display. */
const ColorEntry* colorTable() const;
/** Sets the terminal color palette used by the display. */
void setColorTable(const ColorEntry table[]);
/**
* Sets the seed used to generate random colors for the display
* (in color schemes that support them).
*/
void setRandomSeed(uint seed);
/**
* Returns the seed used to generate random colors for the display
* (in color schemes that support them).
*/
uint randomSeed() const;
/** Sets the opacity of the terminal display. */
void setOpacity(qreal opacity);
/** Sets the background image of the terminal display. */
void setBackgroundImage(QString backgroundImage);
/**
* 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.
*/
void setScrollBarPosition(QTermWidget::ScrollBarPosition position);
/**
* 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.
*/
void setScroll(int cursor, int lines);
/**
* Scroll to the bottom of the terminal (reset scrolling).
*/
void scrollToEnd();
/**
* 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;
/**
* Updates the filters in the display's filter chain. This will cause
* the hotspots to be updated to match the current image.
*
* WARNING: This function can be expensive depending on the
* image size and number of filters in the filterChain()
*
* 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 )
*/
void processFilters();
/**
* Returns a list of menu actions created by the filters for the content
* at the given @p position.
*/
QList<QAction*> filterActions(const QPoint& position);
/** Returns true if the cursor is set to blink or false otherwise. */
bool blinkingCursor() { return _hasBlinkingCursor; }
/** Specifies whether or not the cursor blinks. */
void setBlinkingCursor(bool blink);
/** Specifies whether or not text can blink. */
void setBlinkingTextEnabled(bool blink);
void setCtrlDrag(bool enable) { _ctrlDrag=enable; }
bool ctrlDrag() { return _ctrlDrag; }
/**
* This enum describes the methods for selecting text when
* the user triple-clicks within the display.
*/
enum TripleClickMode
{
/** Select the whole line underneath the cursor. */
SelectWholeLine,
/** Select from the current cursor position to the end of the line. */
SelectForwardsFromCursor
};
/** Sets how the text is selected when the user triple clicks within the display. */
void setTripleClickMode(TripleClickMode mode) { _tripleClickMode = mode; }
/** See setTripleClickSelectionMode() */
TripleClickMode tripleClickMode() { return _tripleClickMode; }
void setLineSpacing(uint);
void setMargin(int);
int margin() const;
uint lineSpacing() const;
void emitSelection(bool useXselection,bool appendReturn);
/** change and wrap text corresponding to paste mode **/
void bracketText(QString& text);
/**
* Sets the shape of the keyboard cursor. This is the cursor drawn
* at the position in the terminal where keyboard input will appear.
*
* In addition the terminal display widget also has a cursor for
* the mouse pointer, which can be set using the QWidget::setCursor()
* method.
*
* Defaults to BlockCursor
*/
void setKeyboardCursorShape(QTermWidget::KeyboardCursorShape shape);
/**
* Returns the shape of the keyboard cursor. See setKeyboardCursorShape()
*/
QTermWidget::KeyboardCursorShape keyboardCursorShape() const;
/**
* Sets the color used to draw the keyboard cursor.
*
* The keyboard cursor defaults to using the foreground color of the character
* underneath it.
*
* @param useForegroundColor If true, the cursor color will change to match
* the foreground color of the character underneath it as it is moved, in this
* case, the @p color parameter is ignored and the color of the character
* under the cursor is inverted to ensure that it is still readable.
* @param color The color to use to draw the cursor. This is only taken into
* account if @p useForegroundColor is false.
*/
void setKeyboardCursorColor(bool useForegroundColor , const QColor& color);
/**
* 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
* underneath it.
*/
QColor keyboardCursorColor() const;
/**
* 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()
*/
int lines() { return _lines; }
/**
* 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()
*/
int columns() { return _columns; }
/**
* Returns the height of the characters in the font used to draw the text in the display.
*/
int fontHeight() { return _fontHeight; }
/**
* Returns the width of the characters in the display.
* This assumes the use of a fixed-width font.
*/
int fontWidth() { return _fontWidth; }
void setSize(int cols, int lins);
void setFixedSize(int cols, int lins);
// reimplemented
QSize sizeHint() const override;
/**
* Sets which characters, in addition to letters and numbers,
* 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 ).
*/
void setWordCharacters(const QString& wc);
/**
* Returns the characters which are considered part of a word for the
* purpose of selecting words in the display with the mouse.
*
* @see setWordCharacters()
*/
QString wordCharacters() { return _wordCharacters; }
/**
* Sets the type of effect used to alert the user when a 'bell' occurs in the
* terminal session.
*
* The terminal session can trigger the bell effect by calling bell() with
* the alert message.
*/
void setBellMode(int mode);
/**
* Returns the type of effect used to alert the user when a 'bell' occurs in
* the terminal session.
*
* See setBellMode()
*/
int bellMode() { return _bellMode; }
/**
* This enum describes the different types of sounds and visual effects which
* can be used to alert the user when a 'bell' occurs in the terminal
* session.
*/
enum BellMode
{
/** A system beep. */
SystemBeepBell=0,
/**
* KDE notification. This may play a sound, show a passive popup
* or perform some other action depending on the user's settings.
*/
NotifyBell=1,
/** A silent, visual bell (eg. inverting the display's colors briefly) */
VisualBell=2,
/** No bell effects */
NoBell=3
};
void setSelection(const QString &t);
void setSelectionAll();
/**
* Reimplemented. Has no effect. Use setVTFont() to change the font
* used to draw characters in the display.
*/
virtual void setFont(const QFont &);
/** Returns the font used to draw characters in the display */
QFont getVTFont() { return font(); }
/**
* Sets the font used to draw the display. Has no effect if @p font
* is larger than the size of the display itself.
*/
void setVTFont(const QFont& font);
/**
* Specified whether anti-aliasing of text in the terminal display
* is enabled or not. Defaults to enabled.
*/
static void setAntialias( bool antialias ) { _antialiasText = antialias; }
/**
* Returns true if anti-aliasing of text in the terminal is enabled.
*/
static bool antialias() { return _antialiasText; }
/**
* Specify whether line chars should be drawn by ourselves or left to
* underlying font rendering libraries.
*/
void setDrawLineChars(bool drawLineChars) { _drawLineChars = drawLineChars; }
/**
* Specifies whether characters with intense colors should be rendered
* as bold. Defaults to true.
*/
void setBoldIntense(bool value) { _boldIntense = value; }
/**
* Returns true if characters with intense colors are rendered in bold.
*/
bool getBoldIntense() { return _boldIntense; }
/**
* Sets whether or not the current height and width of the
* terminal in lines and columns is displayed whilst the widget
* is being resized.
*/
void setTerminalSizeHint(bool on) { _terminalSizeHint=on; }
/**
* Returns whether or not the current height and width of
* the terminal in lines and columns is displayed whilst the widget
* is being resized.
*/
bool terminalSizeHint() { return _terminalSizeHint; }
/**
* Sets whether the terminal size display is shown briefly
* after the widget is first shown.
*
* See setTerminalSizeHint() , isTerminalSizeHint()
*/
void setTerminalSizeStartup(bool on) { _terminalSizeStartup=on; }
/**
* Sets the status of the BiDi rendering inside the terminal display.
* Defaults to disabled.
*/
void setBidiEnabled(bool set) { _bidiEnabled=set; }
/**
* Returns the status of the BiDi rendering in this widget.
*/
bool isBidiEnabled() { return _bidiEnabled; }
/**
* 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.
*/
void setScreenWindow( ScreenWindow* window );
/** Returns the terminal screen section which is displayed in this widget. See setScreenWindow() */
ScreenWindow* screenWindow() const;
static bool HAVE_TRANSPARENCY;
void setMotionAfterPasting(MotionAfterPasting action);
int motionAfterPasting();
// maps a point on the widget to the position ( ie. line and column )
// of the character at that point.
void getCharacterPosition(const QPoint& widgetPoint,int& line,int& column) const;
void setHideCursor(bool hideCursor);
void setSessionId(int sessionId);
// 获取是否允许输出时滚动
bool getIsAllowScroll() const;
// 设置是否允许输出时滚动
void setIsAllowScroll(bool isAllowScroll);
public slots:
/**
* Causes the terminal display to fetch the latest character image from the associated
* terminal screen ( see setScreenWindow() ) and redraw the display.
*/
void updateImage();
/** Essentially calles processFilters().
*/
void updateFilters();
/**
* Causes the terminal display to fetch the latest line status flags from the
* associated terminal screen ( see setScreenWindow() ).
*/
void updateLineProperties();
/** Copies the selected text to the clipboard. */
void copyClipboard();
/**
* Pastes the content of the clipboard into the
* display.
*/
void pasteClipboard();
/**
* Pastes the content of the selection into the
* display.
*/
void pasteSelection();
/**
* Changes whether the flow control warning box should be shown when the flow control
* stop key (Ctrl+S) are pressed.
*/
void setFlowControlWarningEnabled(bool enabled);
/**
* Returns true if the flow control warning box is enabled.
* See outputSuspended() and setFlowControlWarningEnabled()
*/
bool flowControlWarningEnabled() const
{ return _flowControlWarningEnabled; }
/**
* 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.
*/
void outputSuspended(bool suspended);
/**
* Sets whether the program whoose output is being displayed in the view
* 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
* to hold down the shift key to create a selection or perform other mouse activities inside the
* 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);
/**
* Sets the AlternateScrolling profile property which controls whether
* to emulate up/down key presses for mouse scroll wheel events.
* For more details, check the documentation of that property in the
* Profile header.
* Enabled by default.
*/
void setAlternateScrolling(bool enable);
/** See setUsesMouse() */
bool usesMouse() const;
void setBracketedPasteMode(bool bracketedPasteMode);
bool bracketedPasteMode() const;
/**
* Shows a notification that a bell event has occurred in the terminal.
* TODO: More documentation here
*/
void bell(const QString& message);
/**
* Sets the background of the display to the specified color.
* @see setColorTable(), setForegroundColor()
*/
void setBackgroundColor(const QColor& color);
/**
* Sets the text of the display to the specified color.
* @see setColorTable(), setBackgroundColor()
*/
void setForegroundColor(const QColor& color);
void selectionChanged();
void selectionCleared();
// 隐藏QScrollBar默认的右键菜单
void hideQScrollBarRightMenu();
signals:
/**
* Emitted when the user presses a key whilst the terminal widget has focus.
*/
void keyPressedSignal(QKeyEvent *e);
/**
* A mouse event occurred.
* @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
* @param eventType The type of event. 0 for a mouse press / release or 1 for mouse motion
*/
void mouseSignal(int button, int column, int line, int eventType);
void changedFontMetricSignal(int height, int width);
void changedContentSizeSignal(int height, int width);
/**
* 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.
*/
void configureRequest(const QPoint& position);
/**
* 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.
* 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.
*/
void overrideShortcutCheck(QKeyEvent* keyEvent,bool& override);
void isBusySelecting(bool);
void sendStringToEmu(const char*);
// qtermwidget signals
void copyAvailable(bool);
void termGetFocus();
void termLostFocus();
void leftMouseClick();
void notifyBell(const QString&);
void usesMouseChanged();
protected:
bool event( QEvent * ) override;
void paintEvent( QPaintEvent * ) override;
void showEvent(QShowEvent*) override;
void hideEvent(QHideEvent*) override;
void resizeEvent(QResizeEvent*) override;
virtual void fontChange(const QFont &font);
void focusInEvent(QFocusEvent* event) override;
void focusOutEvent(QFocusEvent* event) override;
void keyPressEvent(QKeyEvent* event) override;
void keyReleaseEvent(QKeyEvent *event) override;
void mouseDoubleClickEvent(QMouseEvent* ev) override;
void mousePressEvent( QMouseEvent* ) override;
void mouseReleaseEvent( QMouseEvent* ) override;
void mouseMoveEvent( QMouseEvent* ) override;
virtual void extendSelection( const QPoint& pos );
void wheelEvent( QWheelEvent* ) override;
bool focusNextPrevChild( bool next ) override;
// drag and drop
void dragEnterEvent(QDragEnterEvent* event) override;
void dropEvent(QDropEvent* event) override;
void doDrag();
void initSelectionStates();
void initKeyBoardSelection();
void checkAndInitSelectionState();
enum DragState { diNone, diPending, diDragging };
struct _dragInfo {
DragState state;
QPoint start;
QDrag *dragObject;
} dragInfo;
// classifies the 'ch' into one of three categories
// and returns a character to indicate which category it is in
//
// - A space (returns ' ')
// - Part of a word (returns 'a')
// - Other characters (returns the input character)
QChar charClass(QChar ch) const;
void clearImage();
Screen::DecodingOptions currentDecodingOptions();
void mouseTripleClickEvent(QMouseEvent* ev);
// reimplemented
void inputMethodEvent ( QInputMethodEvent* event ) override;
QVariant inputMethodQuery( Qt::InputMethodQuery query ) const override;
protected slots:
void scrollBarPositionChanged(int value);
void blinkEvent();
void blinkCursorEvent();
//Renables bell noises and visuals. Used to disable further bells for a short period of time
//after emitting the first in a sequence of bell events.
void enableBell();
private slots:
void swapColorTable();
void tripleClickTimeout(); // resets possibleTripleClick
private:
// -- Drawing helpers --
// determine the width of this text
int textWidth(int startColumn, int length, int line) const;
// determine the area that encloses this series of characters
QRect calculateTextArea(int topLeftX, int topLeftY, int startColumn, int line, int length);
// divides the part of the display specified by 'rect' into
// fragments according to their colors and styles and calls
// drawTextFragment() to draw the fragments
void drawContents(QPainter &paint, const QRect &rect);
// draws a section of text, all the text in this section
// has a common color and style
void drawTextFragment(QPainter& painter, const QRect& rect,
const QString& text, const Character* style);
// draws the background for a text fragment
// 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,
bool useOpacitySetting);
// draws the cursor character
void drawCursor(QPainter& painter, const QRect& rect , const QColor& foregroundColor,
const QColor& backgroundColor , bool& invertColors);
// draws the characters or line graphics in a text fragment
void drawCharacters(QPainter& painter, const QRect& rect, const QString& text,
const Character* style, bool invertCharacterColor);
// draws a string of line graphics
void drawLineCharString(QPainter& painter, int x, int y,
const QString& str, const Character* attributes);
// draws the preedit string for input methods
void drawInputMethodPreeditString(QPainter& painter , const QRect& rect);
// --
// maps an area in the character image to an area on the widget
QRect imageToWidget(const QRect& imageArea) const;
QRect widgetToImage(const QRect& widgetArea) const;
// the area where the preedit string for input methods will be draw
QRect preeditRect() const;
// shows a notification window in the middle of the widget indicating the terminal's
// current size in columns and lines
void showResizeNotification();
// scrolls the image by a number of lines.
// 'lines' may be positive ( to scroll the image down )
// or negative ( to scroll the image up )
// '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);
void calcGeometry();
void propagateSize();
void updateImageSize();
void makeImage();
void paintFilters(QPainter& painter);
void calDrawTextAdditionHeight(QPainter& painter);
// returns a region covering all of the areas of the widget which contain
// a hotspot
QRegion hotSpotRegion() const;
// returns the position of the cursor in columns and lines
QPoint cursorPosition() const;
// redraws the cursor
void updateCursor();
bool handleShortcutOverrideEvent(QKeyEvent* event);
bool canDraw(uint c) const;
bool isLineCharString(const QString& string) const;
// the window onto the terminal screen which this display
// is currently showing.
QPointer<ScreenWindow> _screenWindow;
bool _allowBell;
QGridLayout* _gridLayout;
bool _fixedFont; // has fixed pitch
int _fontHeight; // height
int _fontWidth; // width
int _fontAscent; // ascend
bool _boldIntense; // Whether intense colors should be rendered with bold font
int _drawTextAdditionHeight; // additional height to prevent font trancation
bool _drawTextTestFlag; // indicate it is a testing or not
int _leftMargin; // offset
int _topMargin; // offset
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
int _usedLines; // the number of lines that are actually being used, this will be less
// than 'lines' if the character image provided with setImage() is smaller
// than the maximum image size which can be displayed
int _usedColumns; // the number of columns that are actually being used, this will be less
// than 'columns' if the character image provided with setImage() is smaller
// than the maximum image size which can be displayed
QRect _contentRect;
int _contentHeight;
int _contentWidth;
Character* _image; // [lines][columns]
// only the area [usedLines][usedColumns] in the image contains valid data
int _imageSize;
QVector<LineProperty> _lineProperties;
ColorEntry _colorTable[TABLE_COLORS];
uint _randomSeed;
bool _resizing;
bool _terminalSizeHint;
bool _terminalSizeStartup;
bool _bidiEnabled;
bool _mouseMarks;
bool _alternateScrolling;
bool _bracketedPasteMode;
QPoint _iPntSel; // initial selection point
QPoint _pntSel; // current selection point
QPoint _tripleSelBegin; // help avoid flicker
int _actSel; // selection state
bool _wordSelectionMode;
bool _lineSelectionMode;
bool _preserveLineBreaks;
bool _columnSelectionMode;
QClipboard* _clipboard;
QScrollBar* _scrollBar;
QTermWidget::ScrollBarPosition _scrollbarLocation;
QString _wordCharacters;
int _bellMode;
bool _blinking; // hide text in paintEvent
bool _hasBlinker; // has characters to blink
bool _cursorBlinking; // hide cursor in paintEvent
bool _hasBlinkingCursor; // has blinking cursor enabled
bool _allowBlinkingText; // allow text to blink
bool _ctrlDrag; // require Ctrl key for drag
TripleClickMode _tripleClickMode;
bool _isFixedSize; //Columns / lines are locked.
QTimer* _blinkTimer; // active when hasBlinker
QTimer* _blinkCursorTimer; // active when hasBlinkingCursor
//QMenu* _drop;
QString _dropText;
int _dndFileCount;
bool _possibleTripleClick; // is set in mouseDoubleClickEvent and deleted
// after QApplication::doubleClickInterval() delay
bool m_bUserIsResizing; //用于判断当前控件是否正在resize
QLabel* _resizeWidget;
QTimer* _resizeTimer;
bool _flowControlWarningEnabled;
bool _hideCursor;
//widgets related to the warning message that appears when the user presses Ctrl+S to suspend
//terminal output - informing them what has happened and how to resume output
QLabel* _outputSuspendedLabel;
uint _lineSpacing;
bool _colorsInverted; // true during visual bell
QSize _size;
QRgb _blendColor;
QPixmap _backgroundImage;
// list of filters currently applied to the display. used for links and
// search highlight
TerminalImageFilterChain* _filterChain;
QRegion _mouseOverHotspotArea;
QTermWidget::KeyboardCursorShape _cursorShape;
// custom cursor color. if this is invalid then the foreground
// color of the character under the cursor is used
QColor _cursorColor;
MotionAfterPasting mMotionAfterPasting;
struct InputMethodData
{
QString preeditString;
QRect previousPreeditRect;
};
InputMethodData _inputMethodData;
static bool _antialiasText; // do we antialias or not
//the delay in milliseconds between redrawing blinking text
static const int TEXT_BLINK_DELAY = 500;
int _margin; // the contents margin
bool _centerContents; // center the contents between margins
int _leftBaseMargin;
int _topBaseMargin;
int _sessionId;
bool _drawLineChars;
//TerminalHeaderBar *_headerBar;
int _selStartLine = 0;
int _selStartColumn = 0;
int _selEndLine = 0;
int _selEndColumn = 0;
int _lastLeftEndColumn = 0;
int _lastLeftEndLine = 0;
int _lastRightEndColumn = 0;
int _lastRightEndLine = 0;
int _lastEndColumn = 0;
bool _selBegin = false;
// 当前窗口是否允许输出时回滚的标志位
bool m_isAllowScroll = true;
public:
static void setTransparencyEnabled(bool enable)
{
HAVE_TRANSPARENCY = enable;
}
QScrollBar* getScrollBar() {return _scrollBar;}
};
class AutoScrollHandler : public QObject
{
Q_OBJECT
public:
explicit AutoScrollHandler(QWidget* parent);
protected:
void timerEvent(QTimerEvent* event) override;
bool eventFilter(QObject* watched,QEvent* event) override;
private:
QWidget* widget() const { return static_cast<QWidget*>(parent()); }
int _timerId;
};
class KONSOLEPRIVATE_EXPORT TerminalScreen : public TerminalDisplay{
Q_OBJECT
public:
explicit TerminalScreen(QWidget *parent=nullptr);
~TerminalScreen() override;
protected:
bool event(QEvent* evt) override;
private:
bool gestureEvent(QGestureEvent *event);
void tapGestureTriggered(QTapGesture*);
void tapAndHoldGestureTriggered(QTapAndHoldGesture*);
void panTriggered(QPanGesture*);
void pinchTriggered(QPinchGesture*);
void swipeTriggered(QSwipeGesture*);
void slideGesture(qreal diff);
enum GestureAction{
GA_null,
GA_tap,
GA_slide,
GA_pinch,
GA_hold,
GA_pan,
GA_swipe
};
qreal m_scaleFactor = 1;
qreal m_currentStepScaleFactor = 1;
qint64 m_tapBeginTime = 0;
bool m_slideContinue = false;
int m_lastMouseYpos = 0;
ulong m_lastMouseTime = 0;
qreal m_stepSpeed = 0;
Qt::GestureState m_tapStatus = Qt::NoGesture;
GestureAction m_gestureAction = GA_null;
};
// Tween算法(模拟惯性)
typedef std::function<void (qreal)> FunSlideInertial;
class FlashTween : public QObject
{
Q_OBJECT
public:
FlashTween();
~FlashTween(){}
public:
void start(qreal t,qreal b,qreal c,qreal d, FunSlideInertial fSlideGesture);
void stop(){m_timer->stop();}
bool active(){return m_timer->isActive();}
private slots:
void __run();
private:
QTimer* m_timer = nullptr;
FunSlideInertial m_fSlideGesture = nullptr;
qreal m_currentTime = 0;
qreal m_beginValue = 0;
qreal m_changeValue = 0;
qreal m_durationTime = 0;
qreal m_direction = 1;
qreal m_lastValue = 0;
private:
/**
链接:https://www.cnblogs.com/cloudgamer/archive/2009/01/06/Tween.html
效果说明
Linear:无缓动效果;
Quadratic:二次方的缓动(t^2);
Cubic:三次方的缓动(t^3);
Quartic:四次方的缓动(t^4);
Quintic:五次方的缓动(t^5);
Sinusoidal:正弦曲线的缓动(sin(t));
Exponential:指数曲线的缓动(2^t);
Circular:圆形曲线的缓动(sqrt(1-t^2));
Elastic:指数衰减的正弦曲线缓动;
Back:超过范围的三次方缓动((s+1)*t^3 - s*t^2);
Bounce:指数衰减的反弹缓动。
每个效果都分三个缓动方式(方法),分别是:
easeIn:从0开始加速的缓动;
easeOut:减速到0的缓动;
easeInOut:前半段从0开始加速,后半段减速到0的缓动。
其中Linear是无缓动效果,没有以上效果。
四个参数分别是:
t: current time(当前时间);
b: beginning value(初始值);
c: change in value(变化量);
d: duration(持续时间)。
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsequence-point"
static qreal quadraticEaseOut(qreal t,qreal b,qreal c,qreal d){
return -c *(t/=d)*(t-2) + b;
}
static qreal cubicEaseOut(qreal t,qreal b,qreal c,qreal d){
return c*((t=t/d-1)*t*t + 1) + b;
}
static qreal quarticEaseOut(qreal t,qreal b,qreal c,qreal d){
return -c * ((t=t/d-1)*t*t*t - 1) + b;
}
static qreal quinticEaseOut(qreal t,qreal b,qreal c,qreal d){
return c*((t=t/d-1)*t*t*t*t + 1) + b;
}
static qreal sinusoidalEaseOut(qreal t,qreal b,qreal c,qreal d){
return c * sin(t/d * (3.14/2)) + b;
}
static qreal circularEaseOut(qreal t,qreal b,qreal c,qreal d){
return c * sqrt(1 - (t=t/d-1)*t) + b;
}
static qreal bounceEaseOut(qreal t,qreal b,qreal c,qreal d){
if ((t/=d) < (1/2.75)) {
return c*(7.5625*t*t) + b;
} else if (t < (2/2.75)) {
return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
} else if (t < (2.5/2.75)) {
return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
} else {
return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
}
}
#pragma GCC diagnostic pop
};
}
#endif // TERMINALDISPLAY_H
|