00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef TERMINALDISPLAY_H
00022 #define TERMINALDISPLAY_H
00023
00024
00025 #include <QtGui/QColor>
00026 #include <QtCore/QPointer>
00027 #include <QtGui/QWidget>
00028
00029
00030 #include "Filter.h"
00031 #include "Character.h"
00032
00033 class QDrag;
00034 class QDragEnterEvent;
00035 class QDropEvent;
00036 class QLabel;
00037 class QTimer;
00038 class QEvent;
00039 class QFrame;
00040 class QGridLayout;
00041 class QKeyEvent;
00042 class QScrollBar;
00043 class QShowEvent;
00044 class QHideEvent;
00045 class QTimerEvent;
00046 class QWidget;
00047
00048 class KMenu;
00049
00050 namespace Konsole
00051 {
00052
00053 extern unsigned short vt100_graphics[32];
00054
00055 class ScreenWindow;
00056
00066 class TerminalDisplay : public QWidget
00067 {
00068 Q_OBJECT
00069
00070 public:
00072 TerminalDisplay(QWidget *parent=0);
00073 virtual ~TerminalDisplay();
00074
00076 const ColorEntry* colorTable() const;
00078 void setColorTable(const ColorEntry table[]);
00083 void setRandomSeed(uint seed);
00088 uint randomSeed() const;
00089
00091 void setOpacity(qreal opacity);
00092
00096 enum ScrollBarPosition
00097 {
00099 NoScrollBar=0,
00101 ScrollBarLeft=1,
00103 ScrollBarRight=2
00104 };
00109 void setScrollBarPosition(ScrollBarPosition position);
00110
00117 void setScroll(int cursor, int lines);
00118
00130 FilterChain* filterChain() const;
00131
00146 void processFilters();
00147
00152 QList<QAction*> filterActions(const QPoint& position);
00153
00155 bool blinkingCursor() { return _hasBlinkingCursor; }
00157 void setBlinkingCursor(bool blink);
00158
00159 void setCtrlDrag(bool enable) { _ctrlDrag=enable; }
00160 bool ctrlDrag() { return _ctrlDrag; }
00161
00166 enum TripleClickMode
00167 {
00169 SelectWholeLine,
00171 SelectForwardsFromCursor
00172 };
00174 void setTripleClickMode(TripleClickMode mode) { _tripleClickMode = mode; }
00176 TripleClickMode tripleClickMode() { return _tripleClickMode; }
00177
00178 void setLineSpacing(uint);
00179 uint lineSpacing() const;
00180
00181 void emitSelection(bool useXselection,bool appendReturn);
00182
00187 enum KeyboardCursorShape
00188 {
00190 BlockCursor,
00195 UnderlineCursor,
00200 IBeamCursor
00201 };
00212 void setKeyboardCursorShape(KeyboardCursorShape shape);
00216 KeyboardCursorShape keyboardCursorShape() const;
00217
00231 void setKeyboardCursorColor(bool useForegroundColor , const QColor& color);
00232
00238 QColor keyboardCursorColor() const;
00239
00246 int lines() { return _lines; }
00254 int columns() { return _columns; }
00255
00259 int fontHeight() { return _fontHeight; }
00264 int fontWidth() { return _fontWidth; }
00265
00266 void setSize(int cols, int lins);
00267 void setFixedSize(int cols, int lins);
00268
00269
00270 QSize sizeHint() const;
00271
00283 void setWordCharacters(const QString& wc);
00290 QString wordCharacters() { return _wordCharacters; }
00291
00299 void setBellMode(int mode);
00306 int bellMode() { return _bellMode; }
00307
00313 enum BellMode
00314 {
00316 SystemBeepBell=0,
00321 NotifyBell=1,
00323 VisualBell=2,
00325 NoBell=3
00326 };
00327
00328 void setSelection(const QString &t);
00329
00334 virtual void setFont(const QFont &);
00335
00337 QFont getVTFont() { return font(); }
00338
00343 void setVTFont(const QFont& font);
00344
00349 static void setAntialias( bool antialias ) { _antialiasText = antialias; }
00353 static bool antialias() { return _antialiasText; }
00354
00360 void setTerminalSizeHint(bool on) { _terminalSizeHint=on; }
00366 bool terminalSizeHint() { return _terminalSizeHint; }
00373 void setTerminalSizeStartup(bool on) { _terminalSizeStartup=on; }
00374
00379 void setBidiEnabled(bool set) { _bidiEnabled=set; }
00383 bool isBidiEnabled() { return _bidiEnabled; }
00384
00393 void setScreenWindow( ScreenWindow* window );
00395 ScreenWindow* screenWindow() const;
00396
00397 static bool HAVE_TRANSPARENCY;
00398
00399 public slots:
00400
00405 void updateImage();
00410 void updateLineProperties();
00411
00413 void copyClipboard();
00418 void pasteClipboard();
00423 void pasteSelection();
00424
00429 void setFlowControlWarningEnabled(bool enabled);
00434 bool flowControlWarningEnabled() const
00435 { return _flowControlWarningEnabled; }
00436
00445 void outputSuspended(bool suspended);
00446
00461 void setUsesMouse(bool usesMouse);
00462
00464 bool usesMouse() const;
00465
00470 void bell(const QString& message);
00471
00476 void setBackgroundColor(const QColor& color);
00477
00482 void setForegroundColor(const QColor& color);
00483
00484 signals:
00485
00489 void keyPressedSignal(QKeyEvent *e);
00490
00498 void mouseSignal(int button, int column, int line, int eventType);
00499 void changedFontMetricSignal(int height, int width);
00500 void changedContentSizeSignal(int height, int width);
00501
00508 void configureRequest( TerminalDisplay*, int state, const QPoint& position );
00509
00519 void overrideShortcutCheck(QKeyEvent* keyEvent,bool& override);
00520
00521 void isBusySelecting(bool);
00522 void sendStringToEmu(const char*);
00523
00524 protected:
00525 virtual bool event( QEvent * );
00526
00527 virtual void paintEvent( QPaintEvent * );
00528
00529 virtual void showEvent(QShowEvent*);
00530 virtual void hideEvent(QHideEvent*);
00531 virtual void resizeEvent(QResizeEvent*);
00532
00533 virtual void fontChange(const QFont &font);
00534 virtual void focusInEvent(QFocusEvent* event);
00535 virtual void focusOutEvent(QFocusEvent* event);
00536 virtual void keyPressEvent(QKeyEvent* event);
00537 virtual void mouseDoubleClickEvent(QMouseEvent* ev);
00538 virtual void mousePressEvent( QMouseEvent* );
00539 virtual void mouseReleaseEvent( QMouseEvent* );
00540 virtual void mouseMoveEvent( QMouseEvent* );
00541 virtual void extendSelection( const QPoint& pos );
00542 virtual void wheelEvent( QWheelEvent* );
00543
00544 virtual bool focusNextPrevChild( bool next );
00545
00546
00547 virtual void dragEnterEvent(QDragEnterEvent* event);
00548 virtual void dropEvent(QDropEvent* event);
00549 void doDrag();
00550 enum DragState { diNone, diPending, diDragging };
00551
00552 struct _dragInfo {
00553 DragState state;
00554 QPoint start;
00555 QDrag *dragObject;
00556 } dragInfo;
00557
00558
00559
00560
00561
00562
00563
00564 QChar charClass(QChar ch) const;
00565
00566 void clearImage();
00567
00568 void mouseTripleClickEvent(QMouseEvent* ev);
00569
00570
00571 virtual void inputMethodEvent ( QInputMethodEvent* event );
00572 virtual QVariant inputMethodQuery( Qt::InputMethodQuery query ) const;
00573
00574 protected slots:
00575
00576 void scrollBarPositionChanged(int value);
00577 void blinkEvent();
00578 void blinkCursorEvent();
00579
00580
00581
00582 void enableBell();
00583
00584 private slots:
00585
00586 void swapColorTable();
00587 void tripleClickTimeout();
00588
00589 private:
00590
00591
00592
00593
00594
00595
00596 void drawContents(QPainter &paint, const QRect &rect);
00597
00598
00599 void drawTextFragment(QPainter& painter, const QRect& rect,
00600 const QString& text, const Character* style);
00601
00602
00603
00604
00605 void drawBackground(QPainter& painter, const QRect& rect, const QColor& color,
00606 bool useOpacitySetting);
00607
00608 void drawCursor(QPainter& painter, const QRect& rect , const QColor& foregroundColor,
00609 const QColor& backgroundColor , bool& invertColors);
00610
00611 void drawCharacters(QPainter& painter, const QRect& rect, const QString& text,
00612 const Character* style, bool invertCharacterColor);
00613
00614 void drawLineCharString(QPainter& painter, int x, int y,
00615 const QString& str, const Character* attributes);
00616
00617
00618 void drawInputMethodPreeditString(QPainter& painter , const QRect& rect);
00619
00620
00621
00622
00623 QRect imageToWidget(const QRect& imageArea) const;
00624
00625
00626
00627 void getCharacterPosition(const QPoint& widgetPoint,int& line,int& column) const;
00628
00629
00630 QRect preeditRect() const;
00631
00632
00633
00634 void showResizeNotification();
00635
00636
00637
00638
00639
00640
00641
00642 void scrollImage(int lines , const QRect& region);
00643
00644 void calcGeometry();
00645 void propagateSize();
00646 void updateImageSize();
00647 void makeImage();
00648
00649 void paintFilters(QPainter& painter);
00650
00651
00652
00653 QRegion hotSpotRegion() const;
00654
00655
00656 QPoint cursorPosition() const;
00657
00658
00659 void updateCursor();
00660
00661
00662
00663 QPointer<ScreenWindow> _screenWindow;
00664
00665 bool _allowBell;
00666
00667 QGridLayout* _gridLayout;
00668
00669 bool _fixedFont;
00670 int _fontHeight;
00671 int _fontWidth;
00672 int _fontAscent;
00673
00674 int _leftMargin;
00675 int _topMargin;
00676
00677 int _lines;
00678 int _columns;
00679
00680 int _usedLines;
00681
00682
00683
00684 int _usedColumns;
00685
00686
00687
00688 int _contentHeight;
00689 int _contentWidth;
00690 Character* _image;
00691
00692
00693 int _imageSize;
00694 QVector<LineProperty> _lineProperties;
00695
00696 ColorEntry _colorTable[TABLE_COLORS];
00697 uint _randomSeed;
00698
00699 bool _resizing;
00700 bool _terminalSizeHint;
00701 bool _terminalSizeStartup;
00702 bool _bidiEnabled;
00703 bool _mouseMarks;
00704
00705 QPoint _iPntSel;
00706 QPoint _pntSel;
00707 QPoint _tripleSelBegin;
00708 int _actSel;
00709 bool _wordSelectionMode;
00710 bool _lineSelectionMode;
00711 bool _preserveLineBreaks;
00712 bool _columnSelectionMode;
00713
00714 QClipboard* _clipboard;
00715 QScrollBar* _scrollBar;
00716 ScrollBarPosition _scrollbarLocation;
00717 QString _wordCharacters;
00718 int _bellMode;
00719
00720 bool _blinking;
00721 bool _hasBlinker;
00722 bool _cursorBlinking;
00723 bool _hasBlinkingCursor;
00724 bool _ctrlDrag;
00725 TripleClickMode _tripleClickMode;
00726 bool _isFixedSize;
00727 QTimer* _blinkTimer;
00728 QTimer* _blinkCursorTimer;
00729
00730 KMenu* _drop;
00731 QString _dropText;
00732 int _dndFileCount;
00733
00734 bool _possibleTripleClick;
00735
00736
00737
00738 QLabel* _resizeWidget;
00739 QTimer* _resizeTimer;
00740
00741 bool _flowControlWarningEnabled;
00742
00743
00744
00745 QLabel* _outputSuspendedLabel;
00746
00747 uint _lineSpacing;
00748
00749 bool _colorsInverted;
00750
00751 QSize _size;
00752
00753 QRgb _blendColor;
00754
00755
00756
00757 TerminalImageFilterChain* _filterChain;
00758 QRect _mouseOverHotspotArea;
00759
00760 KeyboardCursorShape _cursorShape;
00761
00762
00763
00764 QColor _cursorColor;
00765
00766
00767 struct InputMethodData
00768 {
00769 QString preeditString;
00770 QRect previousPreeditRect;
00771 };
00772 InputMethodData _inputMethodData;
00773
00774 static bool _antialiasText;
00775
00776
00777 static const int BLINK_DELAY = 500;
00778 static const int DEFAULT_LEFT_MARGIN = 1;
00779 static const int DEFAULT_TOP_MARGIN = 1;
00780
00781 public:
00782 static void setTransparencyEnabled(bool enable)
00783 {
00784 HAVE_TRANSPARENCY = enable;
00785 }
00786 };
00787
00788 class AutoScrollHandler : public QObject
00789 {
00790 public:
00791 AutoScrollHandler(QWidget* parent);
00792 protected:
00793 virtual void timerEvent(QTimerEvent* event);
00794 virtual bool eventFilter(QObject* watched,QEvent* event);
00795 private:
00796 QWidget* widget() const { return static_cast<QWidget*>(parent()); }
00797 int _timerId;
00798 };
00799
00800 }
00801
00802 #endif // TERMINALDISPLAY_H