• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Konsole

TerminalDisplay.h

Go to the documentation of this file.
00001 /*
00002     Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
00003     Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00018     02110-1301  USA.
00019 */
00020 
00021 #ifndef TERMINALDISPLAY_H
00022 #define TERMINALDISPLAY_H
00023 
00024 // Qt
00025 #include <QtGui/QColor>
00026 #include <QtCore/QPointer>
00027 #include <QtGui/QWidget>
00028 
00029 // Konsole
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     // reimplemented
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     // drag and drop
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     // classifies the 'ch' into one of three categories
00559     // and returns a character to indicate which category it is in
00560     //
00561     //     - A space (returns ' ') 
00562     //     - Part of a word (returns 'a')
00563     //     - Other characters (returns the input character)
00564     QChar charClass(QChar ch) const;
00565 
00566     void clearImage();
00567 
00568     void mouseTripleClickEvent(QMouseEvent* ev);
00569 
00570     // reimplemented
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     //Renables bell noises and visuals.  Used to disable further bells for a short period of time
00581     //after emitting the first in a sequence of bell events.
00582     void enableBell();
00583 
00584 private slots:
00585 
00586     void swapColorTable();
00587     void tripleClickTimeout();  // resets possibleTripleClick
00588 
00589 private:
00590 
00591     // -- Drawing helpers --
00592 
00593     // divides the part of the display specified by 'rect' into
00594     // fragments according to their colors and styles and calls
00595     // drawTextFragment() to draw the fragments 
00596     void drawContents(QPainter &paint, const QRect &rect);
00597     // draws a section of text, all the text in this section
00598     // has a common color and style
00599     void drawTextFragment(QPainter& painter, const QRect& rect, 
00600                           const QString& text, const Character* style); 
00601     // draws the background for a text fragment
00602     // if useOpacitySetting is true then the color's alpha value will be set to
00603     // the display's transparency (set with setOpacity()), otherwise the background
00604     // will be drawn fully opaque
00605     void drawBackground(QPainter& painter, const QRect& rect, const QColor& color,
00606                         bool useOpacitySetting);
00607     // draws the cursor character
00608     void drawCursor(QPainter& painter, const QRect& rect , const QColor& foregroundColor, 
00609                                        const QColor& backgroundColor , bool& invertColors);
00610     // draws the characters or line graphics in a text fragment
00611     void drawCharacters(QPainter& painter, const QRect& rect,  const QString& text, 
00612                                            const Character* style, bool invertCharacterColor);
00613     // draws a string of line graphics
00614     void drawLineCharString(QPainter& painter, int x, int y, 
00615                             const QString& str, const Character* attributes);
00616 
00617     // draws the preedit string for input methods
00618     void drawInputMethodPreeditString(QPainter& painter , const QRect& rect);
00619 
00620     // --
00621 
00622     // maps an area in the character image to an area on the widget 
00623     QRect imageToWidget(const QRect& imageArea) const;
00624 
00625     // maps a point on the widget to the position ( ie. line and column ) 
00626     // of the character at that point.
00627     void getCharacterPosition(const QPoint& widgetPoint,int& line,int& column) const;
00628 
00629     // the area where the preedit string for input methods will be draw
00630     QRect preeditRect() const;
00631 
00632     // shows a notification window in the middle of the widget indicating the terminal's
00633     // current size in columns and lines
00634     void showResizeNotification();
00635 
00636     // scrolls the image by a number of lines.  
00637     // 'lines' may be positive ( to scroll the image down ) 
00638     // or negative ( to scroll the image up )
00639     // 'region' is the part of the image to scroll - currently only
00640     // the top, bottom and height of 'region' are taken into account,
00641     // the left and right are ignored.
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     // returns a region covering all of the areas of the widget which contain
00652     // a hotspot
00653     QRegion hotSpotRegion() const;
00654 
00655     // returns the position of the cursor in columns and lines
00656     QPoint cursorPosition() const;
00657 
00658     // redraws the cursor
00659     void updateCursor();
00660 
00661     bool handleShortcutOverrideEvent(QKeyEvent* event);
00662 
00663     // the window onto the terminal screen which this display
00664     // is currently showing.  
00665     QPointer<ScreenWindow> _screenWindow;
00666 
00667     bool _allowBell;
00668 
00669     QGridLayout* _gridLayout;
00670 
00671     bool _fixedFont; // has fixed pitch
00672     int  _fontHeight;     // height
00673     int  _fontWidth;     // width
00674     int  _fontAscent;     // ascend
00675 
00676     int _leftMargin;    // offset
00677     int _topMargin;    // offset
00678 
00679     int _lines;      // the number of lines that can be displayed in the widget
00680     int _columns;    // the number of columns that can be displayed in the widget
00681     
00682     int _usedLines;  // the number of lines that are actually being used, this will be less
00683                     // than 'lines' if the character image provided with setImage() is smaller
00684                     // than the maximum image size which can be displayed
00685 
00686     int _usedColumns; // the number of columns that are actually being used, this will be less
00687                      // than 'columns' if the character image provided with setImage() is smaller
00688                      // than the maximum image size which can be displayed
00689     
00690     int _contentHeight;
00691     int _contentWidth;
00692     Character* _image; // [lines][columns]
00693                // only the area [usedLines][usedColumns] in the image contains valid data
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; // initial selection point
00708     QPoint  _pntSel; // current selection point
00709     QPoint  _tripleSelBegin; // help avoid flicker
00710     int     _actSel; // selection state
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;   // hide text in paintEvent
00723     bool _hasBlinker; // has characters to blink
00724     bool _cursorBlinking;     // hide cursor in paintEvent
00725     bool _hasBlinkingCursor;  // has blinking cursor enabled
00726     bool _ctrlDrag;           // require Ctrl key for drag
00727     TripleClickMode _tripleClickMode;
00728     bool _isFixedSize; //Columns / lines are locked.
00729     QTimer* _blinkTimer;  // active when hasBlinker
00730     QTimer* _blinkCursorTimer;  // active when hasBlinkingCursor
00731 
00732     KMenu* _drop;
00733     QString _dropText;
00734     int _dndFileCount;
00735 
00736     bool _possibleTripleClick;  // is set in mouseDoubleClickEvent and deleted
00737                                // after QApplication::doubleClickInterval() delay
00738 
00739 
00740     QLabel* _resizeWidget;
00741     QTimer* _resizeTimer;
00742 
00743     bool _flowControlWarningEnabled;
00744 
00745     //widgets related to the warning message that appears when the user presses Ctrl+S to suspend
00746     //terminal output - informing them what has happened and how to resume output
00747     QLabel* _outputSuspendedLabel; 
00748         
00749     uint _lineSpacing;
00750 
00751     bool _colorsInverted; // true during visual bell
00752 
00753     QSize _size;
00754     
00755     QRgb _blendColor;
00756 
00757     // list of filters currently applied to the display.  used for links and
00758     // search highlight
00759     TerminalImageFilterChain* _filterChain;
00760     QRegion _mouseOverHotspotArea;
00761 
00762     KeyboardCursorShape _cursorShape;
00763 
00764     // custom cursor color.  if this is invalid then the foreground
00765     // color of the character under the cursor is used
00766     QColor _cursorColor;  
00767 
00768 
00769     struct InputMethodData
00770     {
00771         QString preeditString;
00772         QRect previousPreeditRect;
00773     };
00774     InputMethodData _inputMethodData;
00775 
00776     static bool _antialiasText;   // do we antialias or not
00777 
00778     //the delay in milliseconds between redrawing blinking text
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

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • Konsole
  • Libraries
  •   libkonq
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal