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(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 bool handleShortcutOverrideEvent(QKeyEvent* event);
00662
00663
00664
00665 QPointer<ScreenWindow> _screenWindow;
00666
00667 bool _allowBell;
00668
00669 QGridLayout* _gridLayout;
00670
00671 bool _fixedFont;
00672 int _fontHeight;
00673 int _fontWidth;
00674 int _fontAscent;
00675
00676 int _leftMargin;
00677 int _topMargin;
00678
00679 int _lines;
00680 int _columns;
00681
00682 int _usedLines;
00683
00684
00685
00686 int _usedColumns;
00687
00688
00689
00690 int _contentHeight;
00691 int _contentWidth;
00692 Character* _image;
00693
00694
00695 int _imageSize;
00696 QVector<LineProperty> _lineProperties;
00697
00698 ColorEntry _colorTable[TABLE_COLORS];
00699 uint _randomSeed;
00700
00701 bool _resizing;
00702 bool _terminalSizeHint;
00703 bool _terminalSizeStartup;
00704 bool _bidiEnabled;
00705 bool _mouseMarks;
00706
00707 QPoint _iPntSel;
00708 QPoint _pntSel;
00709 QPoint _tripleSelBegin;
00710 int _actSel;
00711 bool _wordSelectionMode;
00712 bool _lineSelectionMode;
00713 bool _preserveLineBreaks;
00714 bool _columnSelectionMode;
00715
00716 QClipboard* _clipboard;
00717 QScrollBar* _scrollBar;
00718 ScrollBarPosition _scrollbarLocation;
00719 QString _wordCharacters;
00720 int _bellMode;
00721
00722 bool _blinking;
00723 bool _hasBlinker;
00724 bool _cursorBlinking;
00725 bool _hasBlinkingCursor;
00726 bool _ctrlDrag;
00727 TripleClickMode _tripleClickMode;
00728 bool _isFixedSize;
00729 QTimer* _blinkTimer;
00730 QTimer* _blinkCursorTimer;
00731
00732 KMenu* _drop;
00733 QString _dropText;
00734 int _dndFileCount;
00735
00736 bool _possibleTripleClick;
00737
00738
00739
00740 QLabel* _resizeWidget;
00741 QTimer* _resizeTimer;
00742
00743 bool _flowControlWarningEnabled;
00744
00745
00746
00747 QLabel* _outputSuspendedLabel;
00748
00749 uint _lineSpacing;
00750
00751 bool _colorsInverted;
00752
00753 QSize _size;
00754
00755 QRgb _blendColor;
00756
00757
00758
00759 TerminalImageFilterChain* _filterChain;
00760 QRegion _mouseOverHotspotArea;
00761
00762 KeyboardCursorShape _cursorShape;
00763
00764
00765
00766 QColor _cursorColor;
00767
00768
00769 struct InputMethodData
00770 {
00771 QString preeditString;
00772 QRect previousPreeditRect;
00773 };
00774 InputMethodData _inputMethodData;
00775
00776 static bool _antialiasText;
00777
00778
00779 static const int BLINK_DELAY = 500;
00780 static const int DEFAULT_LEFT_MARGIN = 1;
00781 static const int DEFAULT_TOP_MARGIN = 1;
00782
00783 public:
00784 static void setTransparencyEnabled(bool enable)
00785 {
00786 HAVE_TRANSPARENCY = enable;
00787 }
00788 };
00789
00790 class AutoScrollHandler : public QObject
00791 {
00792 Q_OBJECT
00793
00794 public:
00795 AutoScrollHandler(QWidget* parent);
00796 protected:
00797 virtual void timerEvent(QTimerEvent* event);
00798 virtual bool eventFilter(QObject* watched,QEvent* event);
00799 private:
00800 QWidget* widget() const { return static_cast<QWidget*>(parent()); }
00801 int _timerId;
00802 };
00803
00804 }
00805
00806 #endif // TERMINALDISPLAY_H