diff --git a/lib/BlockArray.h b/lib/BlockArray.h index 886c4cc..4fee623 100644 --- a/lib/BlockArray.h +++ b/lib/BlockArray.h @@ -30,8 +30,7 @@ #define BlockSize (1 << 12) #define ENTRIES ((BlockSize - sizeof(size_t) ) / sizeof(unsigned char)) -namespace Konsole -{ +namespace Konsole { struct Block { Block() { @@ -43,8 +42,7 @@ struct Block { // /////////////////////////////////////////////////////// -class BlockArray -{ +class BlockArray { public: /** * Creates a history file for holding diff --git a/lib/Character.h b/lib/Character.h index 4088def..2825704 100644 --- a/lib/Character.h +++ b/lib/Character.h @@ -1,6 +1,6 @@ /* This file is part of Konsole, KDE's terminal. - + Copyright 2007-2008 by Robert Knight Copyright 1997,1998 by Lars Doelle @@ -29,8 +29,7 @@ // Local #include "CharacterColor.h" -namespace Konsole -{ +namespace Konsole { typedef unsigned char LineProperty; @@ -53,105 +52,103 @@ static const int LINE_DOUBLEHEIGHT = (1 << 2); * value, foreground and background colors and a set of rendition attributes * which specify how it should be drawn. */ -class Character -{ +class Character { public: - /** - * Constructs a new character. - * - * @param _c The unicode character value of this character. - * @param _f The foreground color used to draw the character. - * @param _b The color used to draw the character's background. - * @param _r A set of rendition flags which specify how this character is to be drawn. - */ - inline Character(quint16 _c = ' ', - CharacterColor _f = CharacterColor(COLOR_SPACE_DEFAULT,DEFAULT_FORE_COLOR), - CharacterColor _b = CharacterColor(COLOR_SPACE_DEFAULT,DEFAULT_BACK_COLOR), - quint8 _r = DEFAULT_RENDITION) - : character(_c), rendition(_r), foregroundColor(_f), backgroundColor(_b) {} - - union - { - /** The unicode character value for this character. */ - quint16 character; - /** - * Experimental addition which allows a single Character instance to contain more than - * one unicode character. + /** + * Constructs a new character. * - * charSequence is a hash code which can be used to look up the unicode - * character sequence in the ExtendedCharTable used to create the sequence. + * @param _c The unicode character value of this character. + * @param _f The foreground color used to draw the character. + * @param _b The color used to draw the character's background. + * @param _r A set of rendition flags which specify how this character is to be drawn. */ - quint16 charSequence; - }; + inline Character(quint16 _c = ' ', + CharacterColor _f = CharacterColor(COLOR_SPACE_DEFAULT,DEFAULT_FORE_COLOR), + CharacterColor _b = CharacterColor(COLOR_SPACE_DEFAULT,DEFAULT_BACK_COLOR), + quint8 _r = DEFAULT_RENDITION) + : character(_c), rendition(_r), foregroundColor(_f), backgroundColor(_b) {} - /** A combination of RENDITION flags which specify options for drawing the character. */ - quint8 rendition; + union { + /** The unicode character value for this character. */ + quint16 character; + /** + * Experimental addition which allows a single Character instance to contain more than + * one unicode character. + * + * charSequence is a hash code which can be used to look up the unicode + * character sequence in the ExtendedCharTable used to create the sequence. + */ + quint16 charSequence; + }; - /** The foreground color used to draw this character. */ - CharacterColor foregroundColor; - /** The color used to draw this character's background. */ - CharacterColor backgroundColor; + /** A combination of RENDITION flags which specify options for drawing the character. */ + quint8 rendition; - /** - * Returns true if this character has a transparent background when - * it is drawn with the specified @p palette. - */ - bool isTransparent(const ColorEntry* palette) const; - /** - * Returns true if this character should always be drawn in bold when - * it is drawn with the specified @p palette, independent of whether - * or not the character has the RE_BOLD rendition flag. - */ - ColorEntry::FontWeight fontWeight(const ColorEntry* base) const; - - /** - * returns true if the format (color, rendition flag) of the compared characters is equal - */ - bool equalsFormat(const Character &other) const; + /** The foreground color used to draw this character. */ + CharacterColor foregroundColor; + /** The color used to draw this character's background. */ + CharacterColor backgroundColor; - /** - * Compares two characters and returns true if they have the same unicode character value, - * rendition and colors. - */ - friend bool operator == (const Character& a, const Character& b); - /** - * Compares two characters and returns true if they have different unicode character values, - * renditions or colors. - */ - friend bool operator != (const Character& a, const Character& b); + /** + * Returns true if this character has a transparent background when + * it is drawn with the specified @p palette. + */ + bool isTransparent(const ColorEntry* palette) const; + /** + * Returns true if this character should always be drawn in bold when + * it is drawn with the specified @p palette, independent of whether + * or not the character has the RE_BOLD rendition flag. + */ + ColorEntry::FontWeight fontWeight(const ColorEntry* base) const; + + /** + * returns true if the format (color, rendition flag) of the compared characters is equal + */ + bool equalsFormat(const Character &other) const; + + /** + * Compares two characters and returns true if they have the same unicode character value, + * rendition and colors. + */ + friend bool operator == (const Character& a, const Character& b); + /** + * Compares two characters and returns true if they have different unicode character values, + * renditions or colors. + */ + friend bool operator != (const Character& a, const Character& b); }; inline bool operator == (const Character& a, const Character& b) -{ - return a.character == b.character && - a.rendition == b.rendition && - a.foregroundColor == b.foregroundColor && - a.backgroundColor == b.backgroundColor; +{ + return a.character == b.character && + a.rendition == b.rendition && + a.foregroundColor == b.foregroundColor && + a.backgroundColor == b.backgroundColor; } inline bool operator != (const Character& a, const Character& b) { - return a.character != b.character || - a.rendition != b.rendition || - a.foregroundColor != b.foregroundColor || - a.backgroundColor != b.backgroundColor; + return a.character != b.character || + a.rendition != b.rendition || + a.foregroundColor != b.foregroundColor || + a.backgroundColor != b.backgroundColor; } inline bool Character::isTransparent(const ColorEntry* base) const { - return ((backgroundColor._colorSpace == COLOR_SPACE_DEFAULT) && - base[backgroundColor._u+0+(backgroundColor._v?BASE_COLORS:0)].transparent) - || ((backgroundColor._colorSpace == COLOR_SPACE_SYSTEM) && - base[backgroundColor._u+2+(backgroundColor._v?BASE_COLORS:0)].transparent); + return ((backgroundColor._colorSpace == COLOR_SPACE_DEFAULT) && + base[backgroundColor._u+0+(backgroundColor._v?BASE_COLORS:0)].transparent) + || ((backgroundColor._colorSpace == COLOR_SPACE_SYSTEM) && + base[backgroundColor._u+2+(backgroundColor._v?BASE_COLORS:0)].transparent); } inline bool Character::equalsFormat(const Character& other) const { - return - backgroundColor==other.backgroundColor && - foregroundColor==other.foregroundColor && - rendition==other.rendition; -} + return + backgroundColor==other.backgroundColor && + foregroundColor==other.foregroundColor && + rendition==other.rendition; +} inline ColorEntry::FontWeight Character::fontWeight(const ColorEntry* base) const { @@ -172,8 +169,7 @@ extern unsigned short vt100_graphics[32]; * character ( ushort ) so that it can occupy the same space in * a structure. */ -class ExtendedCharTable -{ +class ExtendedCharTable { public: /** Constructs a new character table. */ ExtendedCharTable(); @@ -196,7 +192,7 @@ public: * which was added to the table using createExtendedChar(). * * @param hash The hash key returned by createExtendedChar() - * @param length This variable is set to the length of the + * @param length This variable is set to the length of the * character sequence. * * @return A unicode character sequence of size @p length. @@ -208,7 +204,7 @@ public: private: // calculates the hash key of a sequence of unicode points of size 'length' ushort extendedCharHash(ushort* unicodePoints , ushort length) const; - // tests whether the entry in the table specified by 'hash' matches the + // tests whether the entry in the table specified by 'hash' matches the // character sequence 'unicodePoints' of size 'length' bool extendedCharMatch(ushort hash , ushort* unicodePoints , ushort length) const; // internal, maps hash keys to character sequence buffers. The first ushort diff --git a/lib/CharacterColor.h b/lib/CharacterColor.h index 3181073..11cc6e2 100644 --- a/lib/CharacterColor.h +++ b/lib/CharacterColor.h @@ -1,6 +1,6 @@ /* This file is part of Konsole, KDE's terminal. - + Copyright 2007-2008 by Robert Knight Copyright 1997,1998 by Lars Doelle @@ -28,78 +28,74 @@ #include -namespace Konsole -{ +namespace Konsole { -/** - * An entry in a terminal display's color palette. +/** + * An entry in a terminal display's color palette. * * A color palette is an array of 16 ColorEntry instances which map * system color indexes (from 0 to 15) into actual colors. * * Each entry can be set as bold, in which case any text - * drawn using the color should be drawn in bold. + * drawn using the color should be drawn in bold. * * Each entry can also be transparent, in which case the terminal * display should avoid drawing the background for any characters * using the entry as a background. */ -class ColorEntry -{ +class ColorEntry { public: - /** Specifies the weight to use when drawing text with this color. */ - enum FontWeight - { - /** Always draw text in this color with a bold weight. */ - Bold, - /** Always draw text in this color with a normal weight. */ - Normal, - /** - * Use the current font weight set by the terminal application. - * This is the default behavior. + /** Specifies the weight to use when drawing text with this color. */ + enum FontWeight { + /** Always draw text in this color with a bold weight. */ + Bold, + /** Always draw text in this color with a normal weight. */ + Normal, + /** + * Use the current font weight set by the terminal application. + * This is the default behavior. + */ + UseCurrentFormat + }; + + /** + * Constructs a new color palette entry. + * + * @param c The color value for this entry. + * @param tr Specifies that the color should be transparent when used as a background color. + * @param weight Specifies the font weight to use when drawing text with this color. */ - UseCurrentFormat - }; + ColorEntry(QColor c, bool tr, FontWeight weight = UseCurrentFormat) + : color(c), transparent(tr), fontWeight(weight) {} - /** - * Constructs a new color palette entry. - * - * @param c The color value for this entry. - * @param tr Specifies that the color should be transparent when used as a background color. - * @param weight Specifies the font weight to use when drawing text with this color. - */ - ColorEntry(QColor c, bool tr, FontWeight weight = UseCurrentFormat) - : color(c), transparent(tr), fontWeight(weight) {} + /** + * Constructs a new color palette entry with an undefined color, and + * with the transparent and bold flags set to false. + */ + ColorEntry() : transparent(false), fontWeight(UseCurrentFormat) {} - /** - * Constructs a new color palette entry with an undefined color, and - * with the transparent and bold flags set to false. - */ - ColorEntry() : transparent(false), fontWeight(UseCurrentFormat) {} - - /** - * Sets the color, transparency and boldness of this color to those of @p rhs. - */ - void operator=(const ColorEntry& rhs) - { - color = rhs.color; - transparent = rhs.transparent; - fontWeight = rhs.fontWeight; - } + /** + * Sets the color, transparency and boldness of this color to those of @p rhs. + */ + void operator=(const ColorEntry& rhs) { + color = rhs.color; + transparent = rhs.transparent; + fontWeight = rhs.fontWeight; + } - /** The color value of this entry for display. */ - QColor color; + /** The color value of this entry for display. */ + QColor color; - /** - * If true character backgrounds using this color should be transparent. - * This is not applicable when the color is used to render text. - */ - bool transparent; - /** - * Specifies the font weight to use when drawing text with this color. - * This is not applicable when the color is used to draw a character's background. - */ - FontWeight fontWeight; + /** + * If true character backgrounds using this color should be transparent. + * This is not applicable when the color is used to render text. + */ + bool transparent; + /** + * Specifies the font weight to use when drawing text with this color. + * This is not applicable when the color is used to draw a character's background. + */ + FontWeight fontWeight; }; @@ -144,37 +140,33 @@ extern const ColorEntry base_color_table[TABLE_COLORS] KDE_NO_EXPORT; /** * Describes the color of a single character in the terminal. */ -class CharacterColor -{ +class CharacterColor { friend class Character; public: - /** Constructs a new CharacterColor whoose color and color space are undefined. */ - CharacterColor() - : _colorSpace(COLOR_SPACE_UNDEFINED), - _u(0), - _v(0), - _w(0) - {} + /** Constructs a new CharacterColor whoose color and color space are undefined. */ + CharacterColor() + : _colorSpace(COLOR_SPACE_UNDEFINED), + _u(0), + _v(0), + _w(0) {} - /** - * Constructs a new CharacterColor using the specified @p colorSpace and with - * color value @p co - * - * The meaning of @p co depends on the @p colorSpace used. - * - * TODO : Document how @p co relates to @p colorSpace - * - * TODO : Add documentation about available color spaces. - */ - CharacterColor(quint8 colorSpace, int co) - : _colorSpace(colorSpace), - _u(0), - _v(0), - _w(0) - { - switch (colorSpace) - { + /** + * Constructs a new CharacterColor using the specified @p colorSpace and with + * color value @p co + * + * The meaning of @p co depends on the @p colorSpace used. + * + * TODO : Document how @p co relates to @p colorSpace + * + * TODO : Add documentation about available color spaces. + */ + CharacterColor(quint8 colorSpace, int co) + : _colorSpace(colorSpace), + _u(0), + _v(0), + _w(0) { + switch (colorSpace) { case COLOR_SPACE_DEFAULT: _u = co & 1; break; @@ -182,7 +174,7 @@ public: _u = co & 7; _v = (co >> 3) & 1; break; - case COLOR_SPACE_256: + case COLOR_SPACE_256: _u = co & 255; break; case COLOR_SPACE_RGB: @@ -192,60 +184,59 @@ public: break; default: _colorSpace = COLOR_SPACE_UNDEFINED; + } } - } - /** - * Returns true if this character color entry is valid. - */ - bool isValid() - { + /** + * Returns true if this character color entry is valid. + */ + bool isValid() { return _colorSpace != COLOR_SPACE_UNDEFINED; - } - - /** - * Toggles the value of this color between a normal system color and the corresponding intensive - * system color. - * - * This is only applicable if the color is using the COLOR_SPACE_DEFAULT or COLOR_SPACE_SYSTEM - * color spaces. - */ - void toggleIntensive(); + } - /** - * Returns the color within the specified color @p palette - * - * The @p palette is only used if this color is one of the 16 system colors, otherwise - * it is ignored. - */ - QColor color(const ColorEntry* palette) const; - - /** - * Compares two colors and returns true if they represent the same color value and - * use the same color space. - */ - friend bool operator == (const CharacterColor& a, const CharacterColor& b); - /** - * Compares two colors and returns true if they represent different color values - * or use different color spaces. - */ - friend bool operator != (const CharacterColor& a, const CharacterColor& b); + /** + * Toggles the value of this color between a normal system color and the corresponding intensive + * system color. + * + * This is only applicable if the color is using the COLOR_SPACE_DEFAULT or COLOR_SPACE_SYSTEM + * color spaces. + */ + void toggleIntensive(); + + /** + * Returns the color within the specified color @p palette + * + * The @p palette is only used if this color is one of the 16 system colors, otherwise + * it is ignored. + */ + QColor color(const ColorEntry* palette) const; + + /** + * Compares two colors and returns true if they represent the same color value and + * use the same color space. + */ + friend bool operator == (const CharacterColor& a, const CharacterColor& b); + /** + * Compares two colors and returns true if they represent different color values + * or use different color spaces. + */ + friend bool operator != (const CharacterColor& a, const CharacterColor& b); private: - quint8 _colorSpace; + quint8 _colorSpace; - // bytes storing the character color - quint8 _u; - quint8 _v; - quint8 _w; + // bytes storing the character color + quint8 _u; + quint8 _v; + quint8 _w; }; inline bool operator == (const CharacterColor& a, const CharacterColor& b) -{ +{ return a._colorSpace == b._colorSpace && - a._u == b._u && - a._v == b._v && - a._w == b._w; + a._u == b._u && + a._v == b._v && + a._w == b._w; } inline bool operator != (const CharacterColor& a, const CharacterColor& b) { @@ -254,41 +245,48 @@ inline bool operator != (const CharacterColor& a, const CharacterColor& b) inline const QColor color256(quint8 u, const ColorEntry* base) { - // 0.. 16: system colors - if (u < 8) return base[u+2 ].color; u -= 8; - if (u < 8) return base[u+2+BASE_COLORS].color; u -= 8; + // 0.. 16: system colors + if (u < 8) return base[u+2 ].color; + u -= 8; + if (u < 8) return base[u+2+BASE_COLORS].color; + u -= 8; - // 16..231: 6x6x6 rgb color cube - if (u < 216) return QColor(((u/36)%6) ? (40*((u/36)%6)+55) : 0, - ((u/ 6)%6) ? (40*((u/ 6)%6)+55) : 0, - ((u/ 1)%6) ? (40*((u/ 1)%6)+55) : 0); u -= 216; - - // 232..255: gray, leaving out black and white - int gray = u*10+8; return QColor(gray,gray,gray); + // 16..231: 6x6x6 rgb color cube + if (u < 216) return QColor(((u/36)%6) ? (40*((u/36)%6)+55) : 0, + ((u/ 6)%6) ? (40*((u/ 6)%6)+55) : 0, + ((u/ 1)%6) ? (40*((u/ 1)%6)+55) : 0); + u -= 216; + + // 232..255: gray, leaving out black and white + int gray = u*10+8; + return QColor(gray,gray,gray); } inline QColor CharacterColor::color(const ColorEntry* base) const { - switch (_colorSpace) - { - case COLOR_SPACE_DEFAULT: return base[_u+0+(_v?BASE_COLORS:0)].color; - case COLOR_SPACE_SYSTEM: return base[_u+2+(_v?BASE_COLORS:0)].color; - case COLOR_SPACE_256: return color256(_u,base); - case COLOR_SPACE_RGB: return QColor(_u,_v,_w); - case COLOR_SPACE_UNDEFINED: return QColor(); - } + switch (_colorSpace) { + case COLOR_SPACE_DEFAULT: + return base[_u+0+(_v?BASE_COLORS:0)].color; + case COLOR_SPACE_SYSTEM: + return base[_u+2+(_v?BASE_COLORS:0)].color; + case COLOR_SPACE_256: + return color256(_u,base); + case COLOR_SPACE_RGB: + return QColor(_u,_v,_w); + case COLOR_SPACE_UNDEFINED: + return QColor(); + } - Q_ASSERT(false); // invalid color space + Q_ASSERT(false); // invalid color space - return QColor(); + return QColor(); } inline void CharacterColor::toggleIntensive() { - if (_colorSpace == COLOR_SPACE_SYSTEM || _colorSpace == COLOR_SPACE_DEFAULT) - { - _v = !_v; - } + if (_colorSpace == COLOR_SPACE_SYSTEM || _colorSpace == COLOR_SPACE_DEFAULT) { + _v = !_v; + } } diff --git a/lib/Emulation.h b/lib/Emulation.h index 6b492ca..4a59105 100644 --- a/lib/Emulation.h +++ b/lib/Emulation.h @@ -36,8 +36,7 @@ #include -namespace Konsole -{ +namespace Konsole { class KeyboardTranslator; class HistoryType; @@ -118,8 +117,7 @@ enum { * how long the emulation has been active/idle for and also respond to * a 'bell' event in different ways. */ -class Emulation : public QObject -{ +class Emulation : public QObject { Q_OBJECT public: diff --git a/lib/Filter.h b/lib/Filter.h index 38e2c47..9947f9f 100644 --- a/lib/Filter.h +++ b/lib/Filter.h @@ -33,8 +33,7 @@ // Local #include "Character.h" -namespace Konsole -{ +namespace Konsole { /** * A filter processes blocks of text looking for certain patterns (such as URLs or keywords from a list) @@ -54,8 +53,7 @@ namespace Konsole * When processing the text they should create instances of Filter::HotSpot subclasses for sections of interest * and add them to the filter's list of hotspots using addHotSpot() */ -class Filter -{ +class Filter { public: /** * Represents an area of text which matched the pattern a particular filter has been looking for. @@ -69,8 +67,7 @@ public: * Hotspots may have more than one action, in which case the list of actions can be obtained using the * actions() method. These actions may then be displayed in a popup menu or toolbar for example. */ - class HotSpot - { + class HotSpot { public: /** * Constructs a new hotspot which covers the area from (@p startLine,@p startColumn) to (@p endLine,@p endColumn) @@ -190,15 +187,13 @@ private: * Subclasses can reimplement newHotSpot() to return custom hotspot types when matches for the regular expression * are found. */ -class RegExpFilter : public Filter -{ +class RegExpFilter : public Filter { public: /** * Type of hotspot created by RegExpFilter. The capturedTexts() method can be used to find the text * matched by the filter's regular expression. */ - class HotSpot : public Filter::HotSpot - { + class HotSpot : public Filter::HotSpot { public: HotSpot(int startLine, int startColumn, int endLine , int endColumn); virtual void activate(QObject * object = 0); @@ -247,15 +242,13 @@ private: class FilterObject; /** A filter which matches URLs in blocks of text */ -class UrlFilter : public RegExpFilter -{ +class UrlFilter : public RegExpFilter { public: /** * Hotspot type created by UrlFilter instances. The activate() method opens a web browser * at the given URL when called. */ - class HotSpot : public RegExpFilter::HotSpot - { + class HotSpot : public RegExpFilter::HotSpot { public: HotSpot(int startLine,int startColumn,int endLine,int endColumn); virtual ~HotSpot(); @@ -294,8 +287,7 @@ private: static const QRegExp CompleteUrlRegExp; }; -class FilterObject : public QObject -{ +class FilterObject : public QObject { Q_OBJECT public: FilterObject(Filter::HotSpot * filter) : _filter(filter) {} @@ -322,8 +314,7 @@ private: * The hotSpots() and hotSpotsAtLine() method return all of the hotspots in the text and on * a given line respectively. */ -class FilterChain : protected QList -{ +class FilterChain : protected QList { public: virtual ~FilterChain(); @@ -356,8 +347,7 @@ public: }; /** A filter chain which processes character images from terminal displays */ -class TerminalImageFilterChain : public FilterChain -{ +class TerminalImageFilterChain : public FilterChain { public: TerminalImageFilterChain(); virtual ~TerminalImageFilterChain(); diff --git a/lib/History.h b/lib/History.h index 29ce1d9..fb8aa34 100644 --- a/lib/History.h +++ b/lib/History.h @@ -32,16 +32,14 @@ #include "BlockArray.h" #include "Character.h" -namespace Konsole -{ +namespace Konsole { #if 1 /* An extendable tmpfile(1) based buffer. */ -class HistoryFile -{ +class HistoryFile { public: HistoryFile(); virtual ~HistoryFile(); @@ -84,8 +82,7 @@ private: ////////////////////////////////////////////////////////////////////// class HistoryType; -class HistoryScroll -{ +class HistoryScroll { public: HistoryScroll(HistoryType *); virtual ~HistoryScroll(); @@ -135,8 +132,7 @@ protected: // File-based history (e.g. file log, no limitation in length) ////////////////////////////////////////////////////////////////////// -class HistoryScrollFile : public HistoryScroll -{ +class HistoryScrollFile : public HistoryScroll { public: HistoryScrollFile(const QString & logFileName); virtual ~HistoryScrollFile(); @@ -162,8 +158,7 @@ private: ////////////////////////////////////////////////////////////////////// // Buffer-based history (limited to a fixed nb of lines) ////////////////////////////////////////////////////////////////////// -class HistoryScrollBuffer : public HistoryScroll -{ +class HistoryScrollBuffer : public HistoryScroll { public: typedef QVector HistoryLine; @@ -221,8 +216,7 @@ public: ////////////////////////////////////////////////////////////////////// // Nothing-based history (no history :-) ////////////////////////////////////////////////////////////////////// -class HistoryScrollNone : public HistoryScroll -{ +class HistoryScrollNone : public HistoryScroll { public: HistoryScrollNone(); virtual ~HistoryScrollNone(); @@ -241,8 +235,7 @@ public: ////////////////////////////////////////////////////////////////////// // BlockArray-based history ////////////////////////////////////////////////////////////////////// -class HistoryScrollBlockArray : public HistoryScroll -{ +class HistoryScrollBlockArray : public HistoryScroll { public: HistoryScrollBlockArray(size_t size); virtual ~HistoryScrollBlockArray(); @@ -264,8 +257,7 @@ protected: // History type ////////////////////////////////////////////////////////////////////// -class HistoryType -{ +class HistoryType { public: HistoryType(); virtual ~HistoryType(); @@ -290,8 +282,7 @@ public: virtual HistoryScroll * scroll(HistoryScroll *) const = 0; }; -class HistoryTypeNone : public HistoryType -{ +class HistoryTypeNone : public HistoryType { public: HistoryTypeNone(); @@ -301,8 +292,7 @@ public: virtual HistoryScroll * scroll(HistoryScroll *) const; }; -class HistoryTypeBlockArray : public HistoryType -{ +class HistoryTypeBlockArray : public HistoryType { public: HistoryTypeBlockArray(size_t size); @@ -316,8 +306,7 @@ protected: }; #if 1 -class HistoryTypeFile : public HistoryType -{ +class HistoryTypeFile : public HistoryType { public: HistoryTypeFile(const QString & fileName=QString()); @@ -332,8 +321,7 @@ protected: }; -class HistoryTypeBuffer : public HistoryType -{ +class HistoryTypeBuffer : public HistoryType { public: HistoryTypeBuffer(unsigned int nbLines); diff --git a/lib/KeyboardTranslator.h b/lib/KeyboardTranslator.h index 8437ea5..62db165 100644 --- a/lib/KeyboardTranslator.h +++ b/lib/KeyboardTranslator.h @@ -40,8 +40,7 @@ typedef void (*CleanUpFunction)(); * Helper class for K_GLOBAL_STATIC to clean up the object on library unload or application * shutdown. */ -class CleanUpGlobalStatic -{ +class CleanUpGlobalStatic { public: CleanUpFunction func; @@ -112,8 +111,7 @@ static struct K_GLOBAL_STATIC_STRUCT_NAME(NAME) \ class QIODevice; class QTextStream; -namespace Konsole -{ +namespace Konsole { /** * A convertor which maps between key sequences pressed by the user and the @@ -128,8 +126,7 @@ namespace Konsole * (Shift,Ctrl,Alt,Meta etc.) and state flags which indicate the state * which the terminal must be in for the key sequence to apply. */ -class KeyboardTranslator -{ +class KeyboardTranslator { public: /** * The meaning of a particular key sequence may depend upon the state which @@ -193,8 +190,7 @@ public: * and the character sequence and commands associated with it for a particular * KeyboardTranslator. */ - class Entry - { + class Entry { public: /** * Constructs a new entry for a keyboard translator. @@ -421,8 +417,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(KeyboardTranslator::Commands) * } * @endcode */ -class KeyboardTranslatorReader -{ +class KeyboardTranslatorReader { public: /** Constructs a new reader which parses the given @p source */ KeyboardTranslatorReader( QIODevice * source ); @@ -486,8 +481,7 @@ private: }; /** Writes a keyboard translation to disk. */ -class KeyboardTranslatorWriter -{ +class KeyboardTranslatorWriter { public: /** * Constructs a new writer which saves data into @p destination. @@ -513,8 +507,7 @@ private: * Manages the keyboard translations available for use by terminal sessions, * see KeyboardTranslator. */ -class KeyboardTranslatorManager -{ +class KeyboardTranslatorManager { public: /** * Constructs a new KeyboardTranslatorManager and loads the list of diff --git a/lib/Pty.h b/lib/Pty.h index 6466155..eb952e9 100644 --- a/lib/Pty.h +++ b/lib/Pty.h @@ -34,8 +34,7 @@ #include "k3process.h" -namespace Konsole -{ +namespace Konsole { /** * The Pty class is used to start the terminal process, @@ -50,8 +49,7 @@ namespace Konsole * To start the terminal process, call the start() method * with the program name and appropriate arguments. */ -class Pty: public K3Process -{ +class Pty: public K3Process { Q_OBJECT public: @@ -215,8 +213,7 @@ private: // a buffer of data in the queue to be sent to the // terminal process - class SendJob - { + class SendJob { public: SendJob() {} SendJob(const char * b, int len) : buffer(len) { diff --git a/lib/Screen.h b/lib/Screen.h index f8fd7fb..e04cc28 100644 --- a/lib/Screen.h +++ b/lib/Screen.h @@ -42,8 +42,7 @@ #define MODE_NewLine 5 #define MODES_SCREEN 6 -namespace Konsole -{ +namespace Konsole { /*! */ @@ -76,8 +75,7 @@ class TerminalCharacterDecoder; using selectedText(). When getImage() is used to retrieve the the visible image, characters which are part of the selection have their colours inverted. */ -class Screen -{ +class Screen { public: /** Construct a new screen image of size @p lines by @p columns. */ Screen(int lines, int columns); diff --git a/lib/ScreenWindow.h b/lib/ScreenWindow.h index ab49e5b..9b16108 100644 --- a/lib/ScreenWindow.h +++ b/lib/ScreenWindow.h @@ -30,8 +30,7 @@ // Konsole #include "Character.h" -namespace Konsole -{ +namespace Konsole { class Screen; @@ -51,8 +50,7 @@ class Screen; * be called. This in turn will update the window's position and emit the outputChanged() signal * if necessary. */ -class ScreenWindow : public QObject -{ +class ScreenWindow : public QObject { Q_OBJECT public: diff --git a/lib/Session.cpp b/lib/Session.cpp index fad3bfe..4d599b7 100644 --- a/lib/Session.cpp +++ b/lib/Session.cpp @@ -261,10 +261,10 @@ void Session::run() // Upon a KPty error, there is no description on what that error was... // Check to see if the given program is executable. - - - /* ok iam not exactly sure where _program comes from - however it was set to /bin/bash on my system - * Thats bad for BSD as its /usr/local/bin/bash there - its also bad for arch as its /usr/bin/bash there too! + + + /* ok iam not exactly sure where _program comes from - however it was set to /bin/bash on my system + * Thats bad for BSD as its /usr/local/bin/bash there - its also bad for arch as its /usr/bin/bash there too! * So i added a check to see if /bin/bash exists - if no then we use $SHELL - if that does not exist either, we fall back to /bin/sh * As far as i know /bin/sh exists on every unix system.. You could also just put some ifdef __FREEBSD__ here but i think these 2 filechecks are worth * their computing time on any system - especially with the problem on arch linux beeing there too. @@ -278,13 +278,13 @@ void Session::run() exec = getenv("SHELL"); } excheck.setFileName(exec); - + if ( exec.isEmpty() || !excheck.exists() ) { exec = "/bin/sh"; } qDebug() << exec; - - + + QStringList arguments = _arguments.join(QChar(' ')).isEmpty() ? QStringList() << exec : _arguments; QString pexec = exec; @@ -322,7 +322,7 @@ void Session::run() _environment << backgroundColorHint, windowId(), _addToUtmp); - + if (result < 0) { qDebug() << "CRASHED! result: " << result; return; diff --git a/lib/Session.h b/lib/Session.h index 05d962f..746de77 100644 --- a/lib/Session.h +++ b/lib/Session.h @@ -35,8 +35,7 @@ class KProcess; -namespace Konsole -{ +namespace Konsole { class Emulation; class Pty; @@ -54,8 +53,7 @@ class TerminalDisplay; * or send input to the program in the terminal in the form of keypresses and mouse * activity. */ -class Session : public QObject -{ +class Session : public QObject { Q_OBJECT public: @@ -552,8 +550,7 @@ private: * The type of activity which is propagated and method of propagation is controlled * by the masterMode() flags. */ -class SessionGroup : public QObject -{ +class SessionGroup : public QObject { Q_OBJECT public: diff --git a/lib/ShellCommand.h b/lib/ShellCommand.h index 9211aaa..bd1ecbb 100644 --- a/lib/ShellCommand.h +++ b/lib/ShellCommand.h @@ -25,8 +25,7 @@ // Qt #include -namespace Konsole -{ +namespace Konsole { /** * A class to parse and extract information about shell commands. @@ -49,8 +48,7 @@ namespace Konsole * * */ -class ShellCommand -{ +class ShellCommand { public: /** * Constructs a ShellCommand from a command line. diff --git a/lib/TerminalCharacterDecoder.cpp b/lib/TerminalCharacterDecoder.cpp index c02c789..15578c2 100644 --- a/lib/TerminalCharacterDecoder.cpp +++ b/lib/TerminalCharacterDecoder.cpp @@ -1,8 +1,8 @@ /* This file is part of Konsole, an X terminal. - + Copyright 2006-2008 by Robert Knight - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -30,9 +30,9 @@ using namespace Konsole; PlainTextDecoder::PlainTextDecoder() - : _output(0) - , _includeTrailingWhitespace(true) - , _recordLinePositions(false) + : _output(0) + , _includeTrailingWhitespace(true) + , _recordLinePositions(false) { } @@ -46,9 +46,9 @@ bool PlainTextDecoder::trailingWhitespace() const } void PlainTextDecoder::begin(QTextStream* output) { - _output = output; - if (!_linePositions.isEmpty()) - _linePositions.clear(); + _output = output; + if (!_linePositions.isEmpty()) + _linePositions.clear(); } void PlainTextDecoder::end() { @@ -64,12 +64,11 @@ QList PlainTextDecoder::linePositions() const return _linePositions; } void PlainTextDecoder::decodeLine(const Character* const characters, int count, LineProperty /*properties*/ - ) + ) { Q_ASSERT( _output ); - if (_recordLinePositions && _output->string()) - { + if (_recordLinePositions && _output->string()) { int pos = _output->string()->count(); _linePositions << pos; } @@ -81,24 +80,21 @@ void PlainTextDecoder::decodeLine(const Character* const characters, int count, //(since QTextStream always deals with QStrings internally anyway) QString plainText; plainText.reserve(count); - + int outputCount = count; // if inclusion of trailing whitespace is disabled then find the end of the // line - if ( !_includeTrailingWhitespace ) - { - for (int i = count-1 ; i >= 0 ; i--) - { + if ( !_includeTrailingWhitespace ) { + for (int i = count-1 ; i >= 0 ; i--) { if ( characters[i].character != ' ' ) break; else outputCount--; } } - - for (int i=0;i') - text.append(">"); - else - text.append(ch); - } - else - { + text.append(">"); + else + text.append(ch); + } else { text.append(" "); //HTML truncates multiple spaces, so use a space marker instead } - + } //close any remaining open inner spans @@ -229,7 +218,7 @@ void HTMLDecoder::decodeLine(const Character* const characters, int count, LineP //start new line text.append("
"); - + *_output << text; } void HTMLDecoder::openSpan(QString& text , const QString& style) diff --git a/lib/TerminalCharacterDecoder.h b/lib/TerminalCharacterDecoder.h index 5bdc035..3dd3332 100644 --- a/lib/TerminalCharacterDecoder.h +++ b/lib/TerminalCharacterDecoder.h @@ -1,8 +1,8 @@ /* This file is part of Konsole, an X terminal. - + Copyright 2006-2008 by Robert Knight - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -28,8 +28,7 @@ class QTextStream; -namespace Konsole -{ +namespace Konsole { /** * Base class for terminal character decoders @@ -38,10 +37,9 @@ namespace Konsole * and background colours and other appearance-related properties into text strings. * * Derived classes may produce either plain text with no other colour or appearance information, or - * they may produce text which incorporates these additional properties. + * they may produce text which incorporates these additional properties. */ -class TerminalCharacterDecoder -{ +class TerminalCharacterDecoder { public: virtual ~TerminalCharacterDecoder() {} @@ -58,22 +56,21 @@ public: * @param count The number of characters * @param properties Additional properties which affect all characters in the line */ - virtual void decodeLine(const Character* const characters, + virtual void decodeLine(const Character* const characters, int count, - LineProperty properties) = 0; + LineProperty properties) = 0; }; /** * A terminal character decoder which produces plain text, ignoring colours and other appearance-related * properties of the original characters. */ -class PlainTextDecoder : public TerminalCharacterDecoder -{ +class PlainTextDecoder : public TerminalCharacterDecoder { public: - PlainTextDecoder(); + PlainTextDecoder(); - /** - * Set whether trailing whitespace at the end of lines should be included + /** + * Set whether trailing whitespace at the end of lines should be included * in the output. * Defaults to true. */ @@ -83,9 +80,9 @@ public: * in the output. */ bool trailingWhitespace() const; - /** + /** * Returns of character positions in the output stream - * at which new lines where added. Returns an empty if setTrackLinePositions() is false or if + * at which new lines where added. Returns an empty if setTrackLinePositions() is false or if * the output device is not a string. */ QList linePositions() const; @@ -97,9 +94,9 @@ public: virtual void decodeLine(const Character* const characters, int count, - LineProperty properties); + LineProperty properties); + - private: QTextStream* _output; bool _includeTrailingWhitespace; @@ -111,10 +108,9 @@ private: /** * A terminal character decoder which produces pretty HTML markup */ -class HTMLDecoder : public TerminalCharacterDecoder -{ +class HTMLDecoder : public TerminalCharacterDecoder { public: - /** + /** * Constructs an HTML decoder using a default black-on-white color scheme. */ HTMLDecoder(); @@ -124,7 +120,7 @@ public: * output */ void setColorTable( const ColorEntry* table ); - + virtual void decodeLine(const Character* const characters, int count, LineProperty properties); @@ -138,7 +134,7 @@ private: QTextStream* _output; const ColorEntry* _colorTable; - bool _innerSpanOpen; + bool _innerSpanOpen; quint8 _lastRendition; CharacterColor _lastForeColor; CharacterColor _lastBackColor; diff --git a/lib/TerminalDisplay.cpp b/lib/TerminalDisplay.cpp index af26f9a..1b8805c 100644 --- a/lib/TerminalDisplay.cpp +++ b/lib/TerminalDisplay.cpp @@ -1,11 +1,11 @@ /* This file is part of Konsole, a terminal emulator for KDE. - + Copyright 2006-2008 by Robert Knight Copyright 1997,1998 by Lars Doelle - + Rewritten for QT4 by e_k , Copyright (C)2008 - + 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 @@ -67,19 +67,19 @@ const ColorEntry Konsole::base_color_table[TABLE_COLORS] = // gamma correction for the dim colors to compensate for bright X screens. // It contains the 8 ansiterm/xterm colors in 2 intensities. { - // Fixme: could add faint colors here, also. - // normal - ColorEntry(QColor(0x00,0x00,0x00), 0), ColorEntry( QColor(0xB2,0xB2,0xB2), 1), // Dfore, Dback - ColorEntry(QColor(0x00,0x00,0x00), 0), ColorEntry( QColor(0xB2,0x18,0x18), 0), // Black, Red - ColorEntry(QColor(0x18,0xB2,0x18), 0), ColorEntry( QColor(0xB2,0x68,0x18), 0), // Green, Yellow - ColorEntry(QColor(0x18,0x18,0xB2), 0), ColorEntry( QColor(0xB2,0x18,0xB2), 0), // Blue, Magenta - ColorEntry(QColor(0x18,0xB2,0xB2), 0), ColorEntry( QColor(0xB2,0xB2,0xB2), 0), // Cyan, White - // intensiv - ColorEntry(QColor(0x00,0x00,0x00), 0), ColorEntry( QColor(0xFF,0xFF,0xFF), 1), - ColorEntry(QColor(0x68,0x68,0x68), 0), ColorEntry( QColor(0xFF,0x54,0x54), 0), - ColorEntry(QColor(0x54,0xFF,0x54), 0), ColorEntry( QColor(0xFF,0xFF,0x54), 0), - ColorEntry(QColor(0x54,0x54,0xFF), 0), ColorEntry( QColor(0xFF,0x54,0xFF), 0), - ColorEntry(QColor(0x54,0xFF,0xFF), 0), ColorEntry( QColor(0xFF,0xFF,0xFF), 0) + // Fixme: could add faint colors here, also. + // normal + ColorEntry(QColor(0x00,0x00,0x00), 0), ColorEntry( QColor(0xB2,0xB2,0xB2), 1), // Dfore, Dback + ColorEntry(QColor(0x00,0x00,0x00), 0), ColorEntry( QColor(0xB2,0x18,0x18), 0), // Black, Red + ColorEntry(QColor(0x18,0xB2,0x18), 0), ColorEntry( QColor(0xB2,0x68,0x18), 0), // Green, Yellow + ColorEntry(QColor(0x18,0x18,0xB2), 0), ColorEntry( QColor(0xB2,0x18,0xB2), 0), // Blue, Magenta + ColorEntry(QColor(0x18,0xB2,0xB2), 0), ColorEntry( QColor(0xB2,0xB2,0xB2), 0), // Cyan, White + // intensiv + ColorEntry(QColor(0x00,0x00,0x00), 0), ColorEntry( QColor(0xFF,0xFF,0xFF), 1), + ColorEntry(QColor(0x68,0x68,0x68), 0), ColorEntry( QColor(0xFF,0x54,0x54), 0), + ColorEntry(QColor(0x54,0xFF,0x54), 0), ColorEntry( QColor(0xFF,0xFF,0x54), 0), + ColorEntry(QColor(0x54,0x54,0xFF), 0), ColorEntry( QColor(0xFF,0x54,0xFF), 0), + ColorEntry(QColor(0x54,0xFF,0xFF), 0), ColorEntry( QColor(0xFF,0xFF,0xFF), 0) }; // scroll increment used when dragging selection at top/bottom of window. @@ -89,7 +89,7 @@ bool TerminalDisplay::_antialiasText = true; bool TerminalDisplay::HAVE_TRANSPARENCY = false; // we use this to force QPainter to display text in LTR mode -// more information can be found in: http://unicode.org/reports/tr9/ +// more information can be found in: http://unicode.org/reports/tr9/ const QChar LTR_OVERRIDE_CHAR( 0x202D ); /* ------------------------------------------------------------------------- */ @@ -113,15 +113,13 @@ ScreenWindow* TerminalDisplay::screenWindow() const void TerminalDisplay::setScreenWindow(ScreenWindow* window) { // disconnect existing screen window if any - if ( _screenWindow ) - { + if ( _screenWindow ) { disconnect( _screenWindow , 0 , this , 0 ); } _screenWindow = window; - if ( window ) - { + if ( window ) { // TODO: Determine if this is an issue. //#warning "The order here is not specified - does it matter whether updateImage or updateLineProperties comes first?" @@ -134,17 +132,17 @@ void TerminalDisplay::setScreenWindow(ScreenWindow* window) const ColorEntry* TerminalDisplay::colorTable() const { - return _colorTable; + return _colorTable; } void TerminalDisplay::setBackgroundColor(const QColor& color) { _colorTable[DEFAULT_BACK_COLOR].color = color; QPalette p = palette(); - p.setColor( backgroundRole(), color ); - setPalette( p ); + p.setColor( backgroundRole(), color ); + setPalette( p ); - // Avoid propagating the palette change to the scroll bar - _scrollBar->setPalette( QApplication::palette() ); + // Avoid propagating the palette change to the scroll bar + _scrollBar->setPalette( QApplication::palette() ); update(); } @@ -156,10 +154,10 @@ void TerminalDisplay::setForegroundColor(const QColor& color) } void TerminalDisplay::setColorTable(const ColorEntry table[]) { - for (int i = 0; i < TABLE_COLORS; i++) - _colorTable[i] = table[i]; + for (int i = 0; i < TABLE_COLORS; i++) + _colorTable[i] = table[i]; - setBackgroundColor(_colorTable[DEFAULT_BACK_COLOR].color); + setBackgroundColor(_colorTable[DEFAULT_BACK_COLOR].color); } /* ------------------------------------------------------------------------- */ @@ -180,87 +178,85 @@ void TerminalDisplay::setColorTable(const ColorEntry table[]) QCodec. */ -static inline bool isLineChar(quint16 c) { return ((c & 0xFF80) == 0x2500);} +static inline bool isLineChar(quint16 c) +{ + return ((c & 0xFF80) == 0x2500); +} static inline bool isLineCharString(const QString& string) { - return (string.length() > 0) && (isLineChar(string.at(0).unicode())); + return (string.length() > 0) && (isLineChar(string.at(0).unicode())); } - + // assert for i in [0..31] : vt100extended(vt100_graphics[i]) == i. -unsigned short Konsole::vt100_graphics[32] = -{ // 0/8 1/9 2/10 3/11 4/12 5/13 6/14 7/15 - 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, - 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, - 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534, - 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7 +unsigned short Konsole::vt100_graphics[32] = { // 0/8 1/9 2/10 3/11 4/12 5/13 6/14 7/15 + 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, + 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, + 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534, + 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7 }; void TerminalDisplay::fontChange(const QFont&) { - QFontMetrics fm(font()); - _fontHeight = fm.height() + _lineSpacing; + QFontMetrics fm(font()); + _fontHeight = fm.height() + _lineSpacing; - // waba TerminalDisplay 1.123: - // "Base character width on widest ASCII character. This prevents too wide - // characters in the presence of double wide (e.g. Japanese) characters." - // Get the width from representative normal width characters - _fontWidth = qRound((double)fm.width(REPCHAR)/(double)strlen(REPCHAR)); + // waba TerminalDisplay 1.123: + // "Base character width on widest ASCII character. This prevents too wide + // characters in the presence of double wide (e.g. Japanese) characters." + // Get the width from representative normal width characters + _fontWidth = qRound((double)fm.width(REPCHAR)/(double)strlen(REPCHAR)); - _fixedFont = true; + _fixedFont = true; - int fw = fm.width(REPCHAR[0]); - for(unsigned int i=1; i< strlen(REPCHAR); i++) - { - if (fw != fm.width(REPCHAR[i])) - { - _fixedFont = false; - break; + int fw = fm.width(REPCHAR[0]); + for (unsigned int i=1; i< strlen(REPCHAR); i++) { + if (fw != fm.width(REPCHAR[i])) { + _fixedFont = false; + break; + } } - } - if (_fontWidth < 1) - _fontWidth=1; + if (_fontWidth < 1) + _fontWidth=1; - _fontAscent = fm.ascent(); + _fontAscent = fm.ascent(); - emit changedFontMetricSignal( _fontHeight, _fontWidth ); - propagateSize(); - update(); + emit changedFontMetricSignal( _fontHeight, _fontWidth ); + propagateSize(); + update(); } void TerminalDisplay::setVTFont(const QFont& f) { - QFont font = f; + QFont font = f; - QFontMetrics metrics(font); + QFontMetrics metrics(font); - if ( !QFontInfo(font).fixedPitch() ) - { - qDebug() << "Using an unsupported variable-width font in the terminal. This may produce display errors."; - } + if ( !QFontInfo(font).fixedPitch() ) { + qDebug() << "Using an unsupported variable-width font in the terminal. This may produce display errors."; + } - if ( metrics.height() < height() && metrics.maxWidth() < width() ) - { - // hint that text should be drawn without anti-aliasing. - // depending on the user's font configuration, this may not be respected - if (!_antialiasText) - font.setStyleStrategy( QFont::NoAntialias ); - - // experimental optimization. Konsole assumes that the terminal is using a - // mono-spaced font, in which case kerning information should have an effect. - // Disabling kerning saves some computation when rendering text. - font.setKerning(false); + if ( metrics.height() < height() && metrics.maxWidth() < width() ) { + // hint that text should be drawn without anti-aliasing. + // depending on the user's font configuration, this may not be respected + if (!_antialiasText) + font.setStyleStrategy( QFont::NoAntialias ); - QWidget::setFont(font); - fontChange(font); - } + // experimental optimization. Konsole assumes that the terminal is using a + // mono-spaced font, in which case kerning information should have an effect. + // Disabling kerning saves some computation when rendering text. + font.setKerning(false); + + QWidget::setFont(font); + fontChange(font); + } } void TerminalDisplay::setFont(const QFont &) { - // ignore font change request if not coming from konsole itself + // ignore font change request if not coming from konsole itself } /* ------------------------------------------------------------------------- */ @@ -270,115 +266,115 @@ void TerminalDisplay::setFont(const QFont &) /* ------------------------------------------------------------------------- */ TerminalDisplay::TerminalDisplay(QWidget *parent) -:QWidget(parent) -,_screenWindow(0) -,_allowBell(true) -,_gridLayout(0) -,_fontHeight(1) -,_fontWidth(1) -,_fontAscent(1) -,_boldIntense(true) -,_lines(1) -,_columns(1) -,_usedLines(1) -,_usedColumns(1) -,_contentHeight(1) -,_contentWidth(1) -,_image(0) -,_randomSeed(0) -,_resizing(false) -,_terminalSizeHint(false) -,_terminalSizeStartup(true) -,_bidiEnabled(false) -,_actSel(0) -,_wordSelectionMode(false) -,_lineSelectionMode(false) -,_preserveLineBreaks(false) -,_columnSelectionMode(false) -,_scrollbarLocation(NoScrollBar) -,_wordCharacters(":@-./_~") -,_bellMode(SystemBeepBell) -,_blinking(false) -,_hasBlinker(false) -,_cursorBlinking(false) -,_hasBlinkingCursor(false) -,_allowBlinkingText(true) -,_ctrlDrag(false) -,_tripleClickMode(SelectWholeLine) -,_isFixedSize(false) -,_possibleTripleClick(false) -,_resizeWidget(0) -,_resizeTimer(0) -,_flowControlWarningEnabled(false) -,_outputSuspendedLabel(0) -,_lineSpacing(0) -,_colorsInverted(false) -,_blendColor(qRgba(0,0,0,0xff)) -,_filterChain(new TerminalImageFilterChain()) -,_cursorShape(BlockCursor) + :QWidget(parent) + ,_screenWindow(0) + ,_allowBell(true) + ,_gridLayout(0) + ,_fontHeight(1) + ,_fontWidth(1) + ,_fontAscent(1) + ,_boldIntense(true) + ,_lines(1) + ,_columns(1) + ,_usedLines(1) + ,_usedColumns(1) + ,_contentHeight(1) + ,_contentWidth(1) + ,_image(0) + ,_randomSeed(0) + ,_resizing(false) + ,_terminalSizeHint(false) + ,_terminalSizeStartup(true) + ,_bidiEnabled(false) + ,_actSel(0) + ,_wordSelectionMode(false) + ,_lineSelectionMode(false) + ,_preserveLineBreaks(false) + ,_columnSelectionMode(false) + ,_scrollbarLocation(NoScrollBar) + ,_wordCharacters(":@-./_~") + ,_bellMode(SystemBeepBell) + ,_blinking(false) + ,_hasBlinker(false) + ,_cursorBlinking(false) + ,_hasBlinkingCursor(false) + ,_allowBlinkingText(true) + ,_ctrlDrag(false) + ,_tripleClickMode(SelectWholeLine) + ,_isFixedSize(false) + ,_possibleTripleClick(false) + ,_resizeWidget(0) + ,_resizeTimer(0) + ,_flowControlWarningEnabled(false) + ,_outputSuspendedLabel(0) + ,_lineSpacing(0) + ,_colorsInverted(false) + ,_blendColor(qRgba(0,0,0,0xff)) + ,_filterChain(new TerminalImageFilterChain()) + ,_cursorShape(BlockCursor) { - // terminal applications are not designed with Right-To-Left in mind, - // so the layout is forced to Left-To-Right - setLayoutDirection(Qt::LeftToRight); + // terminal applications are not designed with Right-To-Left in mind, + // so the layout is forced to Left-To-Right + setLayoutDirection(Qt::LeftToRight); - // The offsets are not yet calculated. - // Do not calculate these too often to be more smoothly when resizing - // konsole in opaque mode. - _topMargin = DEFAULT_TOP_MARGIN; - _leftMargin = DEFAULT_LEFT_MARGIN; + // The offsets are not yet calculated. + // Do not calculate these too often to be more smoothly when resizing + // konsole in opaque mode. + _topMargin = DEFAULT_TOP_MARGIN; + _leftMargin = DEFAULT_LEFT_MARGIN; - // create scroll bar for scrolling output up and down - // set the scroll bar's slider to occupy the whole area of the scroll bar initially - _scrollBar = new QScrollBar(this); - setScroll(0,0); - _scrollBar->setCursor( Qt::ArrowCursor ); - connect(_scrollBar, SIGNAL(valueChanged(int)), this, - SLOT(scrollBarPositionChanged(int))); + // create scroll bar for scrolling output up and down + // set the scroll bar's slider to occupy the whole area of the scroll bar initially + _scrollBar = new QScrollBar(this); + setScroll(0,0); + _scrollBar->setCursor( Qt::ArrowCursor ); + connect(_scrollBar, SIGNAL(valueChanged(int)), this, + SLOT(scrollBarPositionChanged(int))); - // setup timers for blinking cursor and text - _blinkTimer = new QTimer(this); - connect(_blinkTimer, SIGNAL(timeout()), this, SLOT(blinkEvent())); - _blinkCursorTimer = new QTimer(this); - connect(_blinkCursorTimer, SIGNAL(timeout()), this, SLOT(blinkCursorEvent())); + // setup timers for blinking cursor and text + _blinkTimer = new QTimer(this); + connect(_blinkTimer, SIGNAL(timeout()), this, SLOT(blinkEvent())); + _blinkCursorTimer = new QTimer(this); + connect(_blinkCursorTimer, SIGNAL(timeout()), this, SLOT(blinkCursorEvent())); - //KCursor::setAutoHideCursor( this, true ); - - setUsesMouse(true); - setColorTable(base_color_table); - setMouseTracking(true); + //KCursor::setAutoHideCursor( this, true ); - // Enable drag and drop - setAcceptDrops(true); // attempt - dragInfo.state = diNone; + setUsesMouse(true); + setColorTable(base_color_table); + setMouseTracking(true); - setFocusPolicy( Qt::WheelFocus ); + // Enable drag and drop + setAcceptDrops(true); // attempt + dragInfo.state = diNone; - // enable input method support - setAttribute(Qt::WA_InputMethodEnabled, true); + setFocusPolicy( Qt::WheelFocus ); - // this is an important optimization, it tells Qt - // that TerminalDisplay will handle repainting its entire area. - setAttribute(Qt::WA_OpaquePaintEvent); + // enable input method support + setAttribute(Qt::WA_InputMethodEnabled, true); - _gridLayout = new QGridLayout(this); - _gridLayout->setContentsMargins(0, 0, 0, 0); + // this is an important optimization, it tells Qt + // that TerminalDisplay will handle repainting its entire area. + setAttribute(Qt::WA_OpaquePaintEvent); - setLayout( _gridLayout ); + _gridLayout = new QGridLayout(this); + _gridLayout->setContentsMargins(0, 0, 0, 0); - new AutoScrollHandler(this); + setLayout( _gridLayout ); + + new AutoScrollHandler(this); } TerminalDisplay::~TerminalDisplay() { - disconnect(_blinkTimer); - disconnect(_blinkCursorTimer); - qApp->removeEventFilter( this ); - - delete[] _image; + disconnect(_blinkTimer); + disconnect(_blinkCursorTimer); + qApp->removeEventFilter( this ); - delete _gridLayout; - delete _outputSuspendedLabel; - delete _filterChain; + delete[] _image; + + delete _gridLayout; + delete _outputSuspendedLabel; + delete _filterChain; } /* ------------------------------------------------------------------------- */ @@ -406,8 +402,7 @@ where _ = none */ -enum LineEncode -{ +enum LineEncode { TopL = (1<<1), TopC = (1<<2), TopR = (1<<3), @@ -503,26 +498,24 @@ static void drawLineChar(QPainter& paint, int x, int y, int w, int h, uchar code } -void TerminalDisplay::drawLineCharString( QPainter& painter, int x, int y, const QString& str, - const Character* attributes) +void TerminalDisplay::drawLineCharString( QPainter& painter, int x, int y, const QString& str, + const Character* attributes) { - const QPen& currentPen = painter.pen(); - - if ( (attributes->rendition & RE_BOLD) && _boldIntense ) - { - QPen boldPen(currentPen); - boldPen.setWidth(3); - painter.setPen( boldPen ); - } - - for (int i=0 ; i < str.length(); i++) - { - uchar code = str[i].cell(); - if (LineChars[code]) - drawLineChar(painter, x + (_fontWidth*i), y, _fontWidth, _fontHeight, code); - } + const QPen& currentPen = painter.pen(); - painter.setPen( currentPen ); + if ( (attributes->rendition & RE_BOLD) && _boldIntense ) { + QPen boldPen(currentPen); + boldPen.setWidth(3); + painter.setPen( boldPen ); + } + + for (int i=0 ; i < str.length(); i++) { + uchar code = str[i].cell(); + if (LineChars[code]) + drawLineChar(painter, x + (_fontWidth*i), y, _fontWidth, _fontHeight, code); + } + + painter.setPen( currentPen ); } void TerminalDisplay::setKeyboardCursorShape(KeyboardCursorShape shape) @@ -537,9 +530,9 @@ void TerminalDisplay::setKeyboardCursorColor(bool useForegroundColor, const QCol { if (useForegroundColor) _cursorColor = QColor(); // an invalid color means that - // the foreground color of the - // current character should - // be used + // the foreground color of the + // current character should + // be used else _cursorColor = color; @@ -556,7 +549,7 @@ void TerminalDisplay::setOpacity(qreal opacity) // enable automatic background filling to prevent the display // flickering if there is no transparency - /*if ( color.alpha() == 255 ) + /*if ( color.alpha() == 255 ) { setAutoFillBackground(true); } @@ -570,37 +563,35 @@ void TerminalDisplay::setOpacity(qreal opacity) void TerminalDisplay::drawBackground(QPainter& painter, const QRect& rect, const QColor& backgroundColor, bool useOpacitySetting ) { - // the area of the widget showing the contents of the terminal display is drawn - // using the background color from the color scheme set with setColorTable() - // - // the area of the widget behind the scroll-bar is drawn using the background - // brush from the scroll-bar's palette, to give the effect of the scroll-bar - // being outside of the terminal display and visual consistency with other KDE - // applications. - // - QRect scrollBarArea = _scrollBar->isVisible() ? - rect.intersected(_scrollBar->geometry()) : - QRect(); - QRegion contentsRegion = QRegion(rect).subtracted(scrollBarArea); - QRect contentsRect = contentsRegion.boundingRect(); + // the area of the widget showing the contents of the terminal display is drawn + // using the background color from the color scheme set with setColorTable() + // + // the area of the widget behind the scroll-bar is drawn using the background + // brush from the scroll-bar's palette, to give the effect of the scroll-bar + // being outside of the terminal display and visual consistency with other KDE + // applications. + // + QRect scrollBarArea = _scrollBar->isVisible() ? + rect.intersected(_scrollBar->geometry()) : + QRect(); + QRegion contentsRegion = QRegion(rect).subtracted(scrollBarArea); + QRect contentsRect = contentsRegion.boundingRect(); - if ( HAVE_TRANSPARENCY && qAlpha(_blendColor) < 0xff && useOpacitySetting ) - { - QColor color(backgroundColor); - color.setAlpha(qAlpha(_blendColor)); + if ( HAVE_TRANSPARENCY && qAlpha(_blendColor) < 0xff && useOpacitySetting ) { + QColor color(backgroundColor); + color.setAlpha(qAlpha(_blendColor)); - painter.save(); - painter.setCompositionMode(QPainter::CompositionMode_Source); - painter.fillRect(contentsRect, color); - painter.restore(); - } - else - painter.fillRect(contentsRect, backgroundColor); + painter.save(); + painter.setCompositionMode(QPainter::CompositionMode_Source); + painter.fillRect(contentsRect, color); + painter.restore(); + } else + painter.fillRect(contentsRect, backgroundColor); - painter.fillRect(scrollBarArea,_scrollBar->palette().background()); + painter.fillRect(scrollBarArea,_scrollBar->palette().background()); } -void TerminalDisplay::drawCursor(QPainter& painter, +void TerminalDisplay::drawCursor(QPainter& painter, const QRect& rect, const QColor& foregroundColor, const QColor& /*backgroundColor*/, @@ -608,16 +599,14 @@ void TerminalDisplay::drawCursor(QPainter& painter, { QRect cursorRect = rect; cursorRect.setHeight(_fontHeight - _lineSpacing - 1); - - if (!_cursorBlinking) - { - if ( _cursorColor.isValid() ) - painter.setPen(_cursorColor); - else - painter.setPen(foregroundColor); - if ( _cursorShape == BlockCursor ) - { + if (!_cursorBlinking) { + if ( _cursorColor.isValid() ) + painter.setPen(_cursorColor); + else + painter.setPen(foregroundColor); + + if ( _cursorShape == BlockCursor ) { // draw the cursor outline, adjusting the area so that // it is draw entirely inside 'rect' int penWidth = qMax(1,painter.pen().width()); @@ -626,29 +615,26 @@ void TerminalDisplay::drawCursor(QPainter& painter, penWidth/2, - penWidth/2 - penWidth%2, - penWidth/2 - penWidth%2)); - if ( hasFocus() ) - { + if ( hasFocus() ) { painter.fillRect(cursorRect, _cursorColor.isValid() ? _cursorColor : foregroundColor); - - if ( !_cursorColor.isValid() ) - { + + if ( !_cursorColor.isValid() ) { // invert the colour used to draw the text to ensure that the character at // the cursor position is readable invertCharacterColor = true; } } - } - else if ( _cursorShape == UnderlineCursor ) + } else if ( _cursorShape == UnderlineCursor ) painter.drawLine(cursorRect.left(), cursorRect.bottom(), cursorRect.right(), cursorRect.bottom()); - else if ( _cursorShape == IBeamCursor ) + else if ( _cursorShape == IBeamCursor ) painter.drawLine(cursorRect.left(), cursorRect.top(), cursorRect.left(), cursorRect.bottom()); - + } } @@ -660,11 +646,11 @@ void TerminalDisplay::drawCharacters(QPainter& painter, { // don't draw text which is currently blinking if ( _blinking && (style->rendition & RE_BLINK) ) - return; - + return; + // setup bold and underline bool useBold; - ColorEntry::FontWeight weight = style->fontWeight(_colorTable); + ColorEntry::FontWeight weight = style->fontWeight(_colorTable); if (weight == ColorEntry::UseCurrentFormat) useBold = ((style->rendition & RE_BOLD) && _boldIntense) || font().bold(); else @@ -672,20 +658,18 @@ void TerminalDisplay::drawCharacters(QPainter& painter, bool useUnderline = style->rendition & RE_UNDERLINE || font().underline(); QFont font = painter.font(); - if ( font.bold() != useBold - || font.underline() != useUnderline ) - { - font.setBold(useBold); - font.setUnderline(useUnderline); - painter.setFont(font); + if ( font.bold() != useBold + || font.underline() != useUnderline ) { + font.setBold(useBold); + font.setUnderline(useUnderline); + painter.setFont(font); } // setup pen const CharacterColor& textColor = ( invertCharacterColor ? style->backgroundColor : style->foregroundColor ); const QColor color = textColor.color(_colorTable); QPen pen = painter.pen(); - if ( pen.color() != color ) - { + if ( pen.color() != color ) { pen.setColor(color); painter.setPen(color); } @@ -693,14 +677,13 @@ void TerminalDisplay::drawCharacters(QPainter& painter, // draw text if ( isLineCharString(text) ) drawLineCharString(painter,rect.x(),rect.y(),text,style); - else - { + else { // the drawText(rect,flags,string) overload is used here with null flags - // instead of drawText(rect,string) because the (rect,string) overload causes - // the application's default layout direction to be used instead of + // instead of drawText(rect,string) because the (rect,string) overload causes + // the application's default layout direction to be used instead of // the widget-specific layout direction, which should always be // Qt::LeftToRight for this widget - // This was discussed in: http://lists.kde.org/?t=120552223600002&r=1&w=2 + // This was discussed in: http://lists.kde.org/?t=120552223600002&r=1&w=2 if (_bidiEnabled) painter.drawText(rect,0,text); else @@ -708,17 +691,17 @@ void TerminalDisplay::drawCharacters(QPainter& painter, } } -void TerminalDisplay::drawTextFragment(QPainter& painter , +void TerminalDisplay::drawTextFragment(QPainter& painter , const QRect& rect, - const QString& text, + const QString& text, const Character* style) { painter.save(); - // setup painter + // setup painter const QColor foregroundColor = style->foregroundColor.color(_colorTable); const QColor backgroundColor = style->backgroundColor.color(_colorTable); - + // draw background if different from the display's background color if ( backgroundColor != palette().background().color() ) drawBackground(painter,rect,backgroundColor, @@ -736,8 +719,14 @@ void TerminalDisplay::drawTextFragment(QPainter& painter , painter.restore(); } -void TerminalDisplay::setRandomSeed(uint randomSeed) { _randomSeed = randomSeed; } -uint TerminalDisplay::randomSeed() const { return _randomSeed; } +void TerminalDisplay::setRandomSeed(uint randomSeed) +{ + _randomSeed = randomSeed; +} +uint TerminalDisplay::randomSeed() const +{ + return _randomSeed; +} #if 0 /*! @@ -761,15 +750,15 @@ void TerminalDisplay::setCursorPos(const int curx, const int cury) // scrolls the image by 'lines', down if lines > 0 or up otherwise. // -// the terminal emulation keeps track of the scrolling of the character -// image as it receives input, and when the view is updated, it calls scrollImage() -// with the final scroll amount. this improves performance because scrolling the -// display is much cheaper than re-rendering all the text for the -// part of the image which has moved up or down. +// the terminal emulation keeps track of the scrolling of the character +// image as it receives input, and when the view is updated, it calls scrollImage() +// with the final scroll amount. this improves performance because scrolling the +// display is much cheaper than re-rendering all the text for the +// part of the image which has moved up or down. // Instead only new lines have to be drawn void TerminalDisplay::scrollImage(int lines , const QRect& screenWindowRegion) { - // if the flow control warning is enabled this will interfere with the + // if the flow control warning is enabled this will interfere with the // scrolling optimizations and cause artifacts. the simple solution here // is to just disable the optimization whilst it is visible if ( _outputSuspendedLabel && _outputSuspendedLabel->isVisible() ) @@ -780,14 +769,14 @@ void TerminalDisplay::scrollImage(int lines , const QRect& screenWindowRegion) // internal image - 2, so that the height of 'region' is strictly less // than the height of the internal image. QRect region = screenWindowRegion; - region.setBottom( qMin(region.bottom(),this->_lines-2) ); + region.setBottom( qMin(region.bottom(),this->_lines-2) ); // return if there is nothing to do - if ( lines == 0 - || _image == 0 - || !region.isValid() - || (region.top() + abs(lines)) >= region.bottom() - || this->_lines <= region.height() ) return; + if ( lines == 0 + || _image == 0 + || !region.isValid() + || (region.top() + abs(lines)) >= region.bottom() + || this->_lines <= region.height() ) return; // hide terminal size label to prevent it being scrolled if (_resizeWidget && _resizeWidget->isVisible()) @@ -796,8 +785,8 @@ void TerminalDisplay::scrollImage(int lines , const QRect& screenWindowRegion) // Note: With Qt 4.4 the left edge of the scrolled area must be at 0 // to get the correct (newly exposed) part of the widget repainted. // - // The right edge must be before the left edge of the scroll bar to - // avoid triggering a repaint of the entire widget, the distance is + // The right edge must be before the left edge of the scroll bar to + // avoid triggering a repaint of the entire widget, the distance is // given by SCROLLBAR_CONTENT_GAP // // Set the QT_FLUSH_PAINT environment variable to '1' before starting the @@ -806,13 +795,10 @@ void TerminalDisplay::scrollImage(int lines , const QRect& screenWindowRegion) int scrollBarWidth = _scrollBar->isHidden() ? 0 : _scrollBar->width(); const int SCROLLBAR_CONTENT_GAP = 1; QRect scrollRect; - if ( _scrollbarLocation == ScrollBarLeft ) - { + if ( _scrollbarLocation == ScrollBarLeft ) { scrollRect.setLeft(scrollBarWidth+SCROLLBAR_CONTENT_GAP); scrollRect.setRight(width()); - } - else - { + } else { scrollRect.setLeft(0); scrollRect.setRight(width() - scrollBarWidth - SCROLLBAR_CONTENT_GAP); } @@ -821,7 +807,7 @@ void TerminalDisplay::scrollImage(int lines , const QRect& screenWindowRegion) int top = _topMargin + (region.top() * _fontHeight); int linesToMove = region.height() - abs(lines); - int bytesToMove = linesToMove * + int bytesToMove = linesToMove * this->_columns * sizeof(Character); @@ -829,31 +815,28 @@ void TerminalDisplay::scrollImage(int lines , const QRect& screenWindowRegion) Q_ASSERT( bytesToMove > 0 ); //scroll internal image - if ( lines > 0 ) - { + if ( lines > 0 ) { // check that the memory areas that we are going to move are valid - Q_ASSERT( (char*)lastCharPos + bytesToMove < + Q_ASSERT( (char*)lastCharPos + bytesToMove < (char*)(_image + (this->_lines * this->_columns)) ); - - Q_ASSERT( (lines*this->_columns) < _imageSize ); + + Q_ASSERT( (lines*this->_columns) < _imageSize ); //scroll internal image down - memmove( firstCharPos , lastCharPos , bytesToMove ); - + memmove( firstCharPos , lastCharPos , bytesToMove ); + //set region of display to scroll scrollRect.setTop(top); - } - else - { + } else { // check that the memory areas that we are going to move are valid - Q_ASSERT( (char*)firstCharPos + bytesToMove < + Q_ASSERT( (char*)firstCharPos + bytesToMove < (char*)(_image + (this->_lines * this->_columns)) ); //scroll internal image up - memmove( lastCharPos , firstCharPos , bytesToMove ); - + memmove( lastCharPos , firstCharPos , bytesToMove ); + //set region of the display to scroll - scrollRect.setTop(top + abs(lines) * _fontHeight); + scrollRect.setTop(top + abs(lines) * _fontHeight); } scrollRect.setHeight(linesToMove * _fontHeight ); @@ -863,11 +846,10 @@ void TerminalDisplay::scrollImage(int lines , const QRect& screenWindowRegion) scroll( 0 , _fontHeight * (-lines) , scrollRect ); } -QRegion TerminalDisplay::hotSpotRegion() const +QRegion TerminalDisplay::hotSpotRegion() const { QRegion region; - foreach( Filter::HotSpot* hotSpot , _filterChain->hotSpots() ) - { + foreach( Filter::HotSpot* hotSpot , _filterChain->hotSpots() ) { QRect r; if (hotSpot->startLine()==hotSpot->endLine()) { r.setLeft(hotSpot->startColumn()); @@ -898,7 +880,7 @@ QRegion TerminalDisplay::hotSpotRegion() const return region; } -void TerminalDisplay::processFilters() +void TerminalDisplay::processFilters() { if (!_screenWindow) return; @@ -908,7 +890,7 @@ void TerminalDisplay::processFilters() // use _screenWindow->getImage() here rather than _image because // other classes may call processFilters() when this display's // ScreenWindow emits a scrolled() signal - which will happen before - // updateImage() is called on the display and therefore _image is + // updateImage() is called on the display and therefore _image is // out of date at this point _filterChain->setImage( _screenWindow->getImage(), _screenWindow->windowLines(), @@ -921,247 +903,237 @@ void TerminalDisplay::processFilters() update( preUpdateHotSpots | postUpdateHotSpots ); } -void TerminalDisplay::updateImage() +void TerminalDisplay::updateImage() { - if ( !_screenWindow ) - return; + if ( !_screenWindow ) + return; - // optimization - scroll the existing image where possible and - // avoid expensive text drawing for parts of the image that - // can simply be moved up or down - scrollImage( _screenWindow->scrollCount() , - _screenWindow->scrollRegion() ); - _screenWindow->resetScrollCount(); + // optimization - scroll the existing image where possible and + // avoid expensive text drawing for parts of the image that + // can simply be moved up or down + scrollImage( _screenWindow->scrollCount() , + _screenWindow->scrollRegion() ); + _screenWindow->resetScrollCount(); - Character* const newimg = _screenWindow->getImage(); - int lines = _screenWindow->windowLines(); - int columns = _screenWindow->windowColumns(); + Character* const newimg = _screenWindow->getImage(); + int lines = _screenWindow->windowLines(); + int columns = _screenWindow->windowColumns(); - setScroll( _screenWindow->currentLine() , _screenWindow->lineCount() ); + setScroll( _screenWindow->currentLine() , _screenWindow->lineCount() ); - if (!_image) - updateImageSize(); // Create _image + if (!_image) + updateImageSize(); // Create _image - Q_ASSERT( this->_usedLines <= this->_lines ); - Q_ASSERT( this->_usedColumns <= this->_columns ); + Q_ASSERT( this->_usedLines <= this->_lines ); + Q_ASSERT( this->_usedColumns <= this->_columns ); - int y,x,len; + int y,x,len; - QPoint tL = contentsRect().topLeft(); - int tLx = tL.x(); - int tLy = tL.y(); - _hasBlinker = false; + QPoint tL = contentsRect().topLeft(); + int tLx = tL.x(); + int tLy = tL.y(); + _hasBlinker = false; - CharacterColor cf; // undefined - CharacterColor _clipboard; // undefined - int cr = -1; // undefined + CharacterColor cf; // undefined + CharacterColor _clipboard; // undefined + int cr = -1; // undefined - const int linesToUpdate = qMin(this->_lines, qMax(0,lines )); - const int columnsToUpdate = qMin(this->_columns,qMax(0,columns)); + const int linesToUpdate = qMin(this->_lines, qMax(0,lines )); + const int columnsToUpdate = qMin(this->_columns,qMax(0,columns)); - QChar *disstrU = new QChar[columnsToUpdate]; - char *dirtyMask = new char[columnsToUpdate+2]; - QRegion dirtyRegion; + QChar *disstrU = new QChar[columnsToUpdate]; + char *dirtyMask = new char[columnsToUpdate+2]; + QRegion dirtyRegion; - // debugging variable, this records the number of lines that are found to - // be 'dirty' ( ie. have changed from the old _image to the new _image ) and - // which therefore need to be repainted - int dirtyLineCount = 0; + // debugging variable, this records the number of lines that are found to + // be 'dirty' ( ie. have changed from the old _image to the new _image ) and + // which therefore need to be repainted + int dirtyLineCount = 0; - for (y = 0; y < linesToUpdate; ++y) - { - const Character* currentLine = &_image[y*this->_columns]; - const Character* const newLine = &newimg[y*columns]; + for (y = 0; y < linesToUpdate; ++y) { + const Character* currentLine = &_image[y*this->_columns]; + const Character* const newLine = &newimg[y*columns]; - bool updateLine = false; - - // The dirty mask indicates which characters need repainting. We also - // mark surrounding neighbours dirty, in case the character exceeds - // its cell boundaries - memset(dirtyMask, 0, columnsToUpdate+2); - - for( x = 0 ; x < columnsToUpdate ; ++x) - { - if ( newLine[x] != currentLine[x] ) - { - dirtyMask[x] = true; - } - } + bool updateLine = false; - if (!_resizing) // not while _resizing, we're expecting a paintEvent - for (x = 0; x < columnsToUpdate; ++x) - { - _hasBlinker |= (newLine[x].rendition & RE_BLINK); - - // Start drawing if this character or the next one differs. - // We also take the next one into account to handle the situation - // where characters exceed their cell width. - if (dirtyMask[x]) - { - quint16 c = newLine[x+0].character; - if ( !c ) - continue; - int p = 0; - disstrU[p++] = c; //fontMap(c); - bool lineDraw = isLineChar(c); - bool doubleWidth = (x+1 == columnsToUpdate) ? false : (newLine[x+1].character == 0); - cr = newLine[x].rendition; - _clipboard = newLine[x].backgroundColor; - if (newLine[x].foregroundColor != cf) cf = newLine[x].foregroundColor; - int lln = columnsToUpdate - x; - for (len = 1; len < lln; ++len) - { - const Character& ch = newLine[x+len]; + // The dirty mask indicates which characters need repainting. We also + // mark surrounding neighbours dirty, in case the character exceeds + // its cell boundaries + memset(dirtyMask, 0, columnsToUpdate+2); - if (!ch.character) - continue; // Skip trailing part of multi-col chars. - - bool nextIsDoubleWidth = (x+len+1 == columnsToUpdate) ? false : (newLine[x+len+1].character == 0); - - if ( ch.foregroundColor != cf || - ch.backgroundColor != _clipboard || - ch.rendition != cr || - !dirtyMask[x+len] || - isLineChar(c) != lineDraw || - nextIsDoubleWidth != doubleWidth ) - break; - - disstrU[p++] = c; //fontMap(c); + for ( x = 0 ; x < columnsToUpdate ; ++x) { + if ( newLine[x] != currentLine[x] ) { + dirtyMask[x] = true; + } } - QString unistr(disstrU, p); + if (!_resizing) // not while _resizing, we're expecting a paintEvent + for (x = 0; x < columnsToUpdate; ++x) { + _hasBlinker |= (newLine[x].rendition & RE_BLINK); - bool saveFixedFont = _fixedFont; - if (lineDraw) - _fixedFont = false; - if (doubleWidth) - _fixedFont = false; + // Start drawing if this character or the next one differs. + // We also take the next one into account to handle the situation + // where characters exceed their cell width. + if (dirtyMask[x]) { + quint16 c = newLine[x+0].character; + if ( !c ) + continue; + int p = 0; + disstrU[p++] = c; //fontMap(c); + bool lineDraw = isLineChar(c); + bool doubleWidth = (x+1 == columnsToUpdate) ? false : (newLine[x+1].character == 0); + cr = newLine[x].rendition; + _clipboard = newLine[x].backgroundColor; + if (newLine[x].foregroundColor != cf) cf = newLine[x].foregroundColor; + int lln = columnsToUpdate - x; + for (len = 1; len < lln; ++len) { + const Character& ch = newLine[x+len]; - updateLine = true; + if (!ch.character) + continue; // Skip trailing part of multi-col chars. - _fixedFont = saveFixedFont; - x += len - 1; - } - + bool nextIsDoubleWidth = (x+len+1 == columnsToUpdate) ? false : (newLine[x+len+1].character == 0); + + if ( ch.foregroundColor != cf || + ch.backgroundColor != _clipboard || + ch.rendition != cr || + !dirtyMask[x+len] || + isLineChar(c) != lineDraw || + nextIsDoubleWidth != doubleWidth ) + break; + + disstrU[p++] = c; //fontMap(c); + } + + QString unistr(disstrU, p); + + bool saveFixedFont = _fixedFont; + if (lineDraw) + _fixedFont = false; + if (doubleWidth) + _fixedFont = false; + + updateLine = true; + + _fixedFont = saveFixedFont; + x += len - 1; + } + + } + + //both the top and bottom halves of double height _lines must always be redrawn + //although both top and bottom halves contain the same characters, only + //the top one is actually + //drawn. + if (_lineProperties.count() > y) + updateLine |= (_lineProperties[y] & LINE_DOUBLEHEIGHT); + + // if the characters on the line are different in the old and the new _image + // then this line must be repainted. + if (updateLine) { + dirtyLineCount++; + + // add the area occupied by this line to the region which needs to be + // repainted + QRect dirtyRect = QRect( _leftMargin+tLx , + _topMargin+tLy+_fontHeight*y , + _fontWidth * columnsToUpdate , + _fontHeight ); + + dirtyRegion |= dirtyRect; + } + + // replace the line of characters in the old _image with the + // current line of the new _image + memcpy((void*)currentLine,(const void*)newLine,columnsToUpdate*sizeof(Character)); } - //both the top and bottom halves of double height _lines must always be redrawn - //although both top and bottom halves contain the same characters, only - //the top one is actually - //drawn. - if (_lineProperties.count() > y) - updateLine |= (_lineProperties[y] & LINE_DOUBLEHEIGHT); - - // if the characters on the line are different in the old and the new _image - // then this line must be repainted. - if (updateLine) - { - dirtyLineCount++; - - // add the area occupied by this line to the region which needs to be - // repainted - QRect dirtyRect = QRect( _leftMargin+tLx , - _topMargin+tLy+_fontHeight*y , - _fontWidth * columnsToUpdate , - _fontHeight ); - - dirtyRegion |= dirtyRect; + // if the new _image is smaller than the previous _image, then ensure that the area + // outside the new _image is cleared + if ( linesToUpdate < _usedLines ) { + dirtyRegion |= QRect( _leftMargin+tLx , + _topMargin+tLy+_fontHeight*linesToUpdate , + _fontWidth * this->_columns , + _fontHeight * (_usedLines-linesToUpdate) ); } + _usedLines = linesToUpdate; - // replace the line of characters in the old _image with the - // current line of the new _image - memcpy((void*)currentLine,(const void*)newLine,columnsToUpdate*sizeof(Character)); - } + if ( columnsToUpdate < _usedColumns ) { + dirtyRegion |= QRect( _leftMargin+tLx+columnsToUpdate*_fontWidth , + _topMargin+tLy , + _fontWidth * (_usedColumns-columnsToUpdate) , + _fontHeight * this->_lines ); + } + _usedColumns = columnsToUpdate; - // if the new _image is smaller than the previous _image, then ensure that the area - // outside the new _image is cleared - if ( linesToUpdate < _usedLines ) - { - dirtyRegion |= QRect( _leftMargin+tLx , - _topMargin+tLy+_fontHeight*linesToUpdate , - _fontWidth * this->_columns , - _fontHeight * (_usedLines-linesToUpdate) ); - } - _usedLines = linesToUpdate; - - if ( columnsToUpdate < _usedColumns ) - { - dirtyRegion |= QRect( _leftMargin+tLx+columnsToUpdate*_fontWidth , - _topMargin+tLy , - _fontWidth * (_usedColumns-columnsToUpdate) , - _fontHeight * this->_lines ); - } - _usedColumns = columnsToUpdate; + dirtyRegion |= _inputMethodData.previousPreeditRect; - dirtyRegion |= _inputMethodData.previousPreeditRect; + // update the parts of the display which have changed + update(dirtyRegion); - // update the parts of the display which have changed - update(dirtyRegion); - - if ( _hasBlinker && !_blinkTimer->isActive()) _blinkTimer->start( TEXT_BLINK_DELAY ); - if (!_hasBlinker && _blinkTimer->isActive()) { _blinkTimer->stop(); _blinking = false; } - delete[] dirtyMask; - delete[] disstrU; + if ( _hasBlinker && !_blinkTimer->isActive()) _blinkTimer->start( TEXT_BLINK_DELAY ); + if (!_hasBlinker && _blinkTimer->isActive()) { + _blinkTimer->stop(); + _blinking = false; + } + delete[] dirtyMask; + delete[] disstrU; } void TerminalDisplay::showResizeNotification() { - if (_terminalSizeHint && isVisible()) - { - if (_terminalSizeStartup) { - _terminalSizeStartup=false; - return; - } - if (!_resizeWidget) - { - _resizeWidget = new QLabel(("Size: XXX x XXX"), this); - _resizeWidget->setMinimumWidth(_resizeWidget->fontMetrics().width(("Size: XXX x XXX"))); - _resizeWidget->setMinimumHeight(_resizeWidget->sizeHint().height()); - _resizeWidget->setAlignment(Qt::AlignCenter); + if (_terminalSizeHint && isVisible()) { + if (_terminalSizeStartup) { + _terminalSizeStartup=false; + return; + } + if (!_resizeWidget) { + _resizeWidget = new QLabel(("Size: XXX x XXX"), this); + _resizeWidget->setMinimumWidth(_resizeWidget->fontMetrics().width(("Size: XXX x XXX"))); + _resizeWidget->setMinimumHeight(_resizeWidget->sizeHint().height()); + _resizeWidget->setAlignment(Qt::AlignCenter); - _resizeWidget->setStyleSheet("background-color:palette(window);border-style:solid;border-width:1px;border-color:palette(dark)"); + _resizeWidget->setStyleSheet("background-color:palette(window);border-style:solid;border-width:1px;border-color:palette(dark)"); - _resizeTimer = new QTimer(this); - _resizeTimer->setSingleShot(true); - connect(_resizeTimer, SIGNAL(timeout()), _resizeWidget, SLOT(hide())); - } - QString sizeStr; - sizeStr.sprintf("Size: %d x %d", _columns, _lines); - _resizeWidget->setText(sizeStr); - _resizeWidget->move((width()-_resizeWidget->width())/2, - (height()-_resizeWidget->height())/2+20); - _resizeWidget->show(); - _resizeTimer->start(1000); - } + _resizeTimer = new QTimer(this); + _resizeTimer->setSingleShot(true); + connect(_resizeTimer, SIGNAL(timeout()), _resizeWidget, SLOT(hide())); + } + QString sizeStr; + sizeStr.sprintf("Size: %d x %d", _columns, _lines); + _resizeWidget->setText(sizeStr); + _resizeWidget->move((width()-_resizeWidget->width())/2, + (height()-_resizeWidget->height())/2+20); + _resizeWidget->show(); + _resizeTimer->start(1000); + } } void TerminalDisplay::setBlinkingCursor(bool blink) { - _hasBlinkingCursor=blink; - - if (blink && !_blinkCursorTimer->isActive()) - _blinkCursorTimer->start(QApplication::cursorFlashTime() / 2); - - if (!blink && _blinkCursorTimer->isActive()) - { - _blinkCursorTimer->stop(); - if (_cursorBlinking) - blinkCursorEvent(); - else - _cursorBlinking = false; - } + _hasBlinkingCursor=blink; + + if (blink && !_blinkCursorTimer->isActive()) + _blinkCursorTimer->start(QApplication::cursorFlashTime() / 2); + + if (!blink && _blinkCursorTimer->isActive()) { + _blinkCursorTimer->stop(); + if (_cursorBlinking) + blinkCursorEvent(); + else + _cursorBlinking = false; + } } void TerminalDisplay::setBlinkingTextEnabled(bool blink) { _allowBlinkingText = blink; - if (blink && !_blinkTimer->isActive()) + if (blink && !_blinkTimer->isActive()) _blinkTimer->start(TEXT_BLINK_DELAY); - - if (!blink && _blinkTimer->isActive()) - { + + if (!blink && _blinkTimer->isActive()) { _blinkTimer->stop(); _blinking = false; } @@ -1185,8 +1157,7 @@ void TerminalDisplay::focusOutEvent(QFocusEvent*) void TerminalDisplay::focusInEvent(QFocusEvent*) { emit termGetFocus(); - if (_hasBlinkingCursor) - { + if (_hasBlinkingCursor) { _blinkCursorTimer->start(); } updateCursor(); @@ -1197,16 +1168,15 @@ void TerminalDisplay::focusInEvent(QFocusEvent*) void TerminalDisplay::paintEvent( QPaintEvent* pe ) { - QPainter paint(this); + QPainter paint(this); - foreach (const QRect &rect, (pe->region() & contentsRect()).rects()) - { - drawBackground(paint,rect,palette().background().color(), - true /* use opacity setting */); - drawContents(paint, rect); - } - drawInputMethodPreeditString(paint,preeditRect()); - paintFilters(paint); + foreach (const QRect &rect, (pe->region() & contentsRect()).rects()) { + drawBackground(paint,rect,palette().background().color(), + true /* use opacity setting */); + drawContents(paint, rect); + } + drawInputMethodPreeditString(paint,preeditRect()); + paintFilters(paint); } QPoint TerminalDisplay::cursorPosition() const @@ -1228,14 +1198,14 @@ QRect TerminalDisplay::preeditRect() const _topMargin + _fontHeight*cursorPosition().y(), _fontWidth*preeditLength, _fontHeight); -} +} void TerminalDisplay::drawInputMethodPreeditString(QPainter& painter , const QRect& rect) { if ( _inputMethodData.preeditString.isEmpty() ) return; - const QPoint cursorPos = cursorPosition(); + const QPoint cursorPos = cursorPosition(); bool invertColors = false; const QColor background = _colorTable[DEFAULT_BACK_COLOR].color; @@ -1246,7 +1216,7 @@ void TerminalDisplay::drawInputMethodPreeditString(QPainter& painter , const QRe drawCursor(painter,rect,foreground,background,invertColors); drawCharacters(painter,rect,_inputMethodData.preeditString,style,invertColors); - _inputMethodData.previousPreeditRect = rect; + _inputMethodData.previousPreeditRect = rect; } FilterChain* TerminalDisplay::filterChain() const @@ -1268,56 +1238,54 @@ void TerminalDisplay::paintFilters(QPainter& painter) painter.setPen( QPen(cursorCharacter.foregroundColor.color(colorTable())) ); - // iterate over hotspots identified by the display's currently active filters + // iterate over hotspots identified by the display's currently active filters // and draw appropriate visuals to indicate the presence of the hotspot QList spots = _filterChain->hotSpots(); QListIterator iter(spots); - while (iter.hasNext()) - { + while (iter.hasNext()) { Filter::HotSpot* spot = iter.next(); QRegion region; if ( spot->type() == Filter::HotSpot::Link ) { QRect r; if (spot->startLine()==spot->endLine()) { - r.setCoords( spot->startColumn()*_fontWidth + 1 + scrollBarWidth, + r.setCoords( spot->startColumn()*_fontWidth + 1 + scrollBarWidth, spot->startLine()*_fontHeight + 1, - (spot->endColumn()-1)*_fontWidth - 1 + scrollBarWidth, - (spot->endLine()+1)*_fontHeight - 1 ); + (spot->endColumn()-1)*_fontWidth - 1 + scrollBarWidth, + (spot->endLine()+1)*_fontHeight - 1 ); region |= r; } else { - r.setCoords( spot->startColumn()*_fontWidth + 1 + scrollBarWidth, + r.setCoords( spot->startColumn()*_fontWidth + 1 + scrollBarWidth, spot->startLine()*_fontHeight + 1, - (_columns-1)*_fontWidth - 1 + scrollBarWidth, - (spot->startLine()+1)*_fontHeight - 1 ); + (_columns-1)*_fontWidth - 1 + scrollBarWidth, + (spot->startLine()+1)*_fontHeight - 1 ); region |= r; for ( int line = spot->startLine()+1 ; line < spot->endLine() ; line++ ) { - r.setCoords( 0*_fontWidth + 1 + scrollBarWidth, + r.setCoords( 0*_fontWidth + 1 + scrollBarWidth, line*_fontHeight + 1, (_columns-1)*_fontWidth - 1 + scrollBarWidth, - (line+1)*_fontHeight - 1 ); + (line+1)*_fontHeight - 1 ); region |= r; } r.setCoords( 0*_fontWidth + 1 + scrollBarWidth, spot->endLine()*_fontHeight + 1, (spot->endColumn()-1)*_fontWidth - 1 + scrollBarWidth, - (spot->endLine()+1)*_fontHeight - 1 ); + (spot->endLine()+1)*_fontHeight - 1 ); region |= r; } } - for ( int line = spot->startLine() ; line <= spot->endLine() ; line++ ) - { + for ( int line = spot->startLine() ; line <= spot->endLine() ; line++ ) { int startColumn = 0; - int endColumn = _columns-1; // TODO use number of _columns which are actually - // occupied on this line rather than the width of the - // display in _columns + int endColumn = _columns-1; // TODO use number of _columns which are actually + // occupied on this line rather than the width of the + // display in _columns // ignore whitespace at the end of the lines while ( QChar(_image[loc(endColumn,line)].character).isSpace() && endColumn > 0 ) endColumn--; - + // increment here because the column which we want to set 'endColumn' to // is the first whitespace character at the end of the line endColumn++; @@ -1333,34 +1301,32 @@ void TerminalDisplay::paintFilters(QPainter& painter) // hotspots // // subtracting one pixel from all sides also prevents an edge case where - // moving the mouse outside a link could still leave it underlined + // moving the mouse outside a link could still leave it underlined // because the check below for the position of the cursor // finds it on the border of the target area QRect r; r.setCoords( startColumn*_fontWidth + 1 + scrollBarWidth, line*_fontHeight + 1, endColumn*_fontWidth - 1 + scrollBarWidth, - (line+1)*_fontHeight - 1 ); - // Underline link hotspots - if ( spot->type() == Filter::HotSpot::Link ) - { + (line+1)*_fontHeight - 1 ); + // Underline link hotspots + if ( spot->type() == Filter::HotSpot::Link ) { QFontMetrics metrics(font()); - + // find the baseline (which is the invisible line that the characters in the font sit on, // with some having tails dangling below) int baseline = r.bottom() - metrics.descent(); // find the position of the underline below that int underlinePos = baseline + metrics.underlinePos(); - if ( region.contains( mapFromGlobal(QCursor::pos()) ) ){ - painter.drawLine( r.left() , underlinePos , + if ( region.contains( mapFromGlobal(QCursor::pos()) ) ) { + painter.drawLine( r.left() , underlinePos , r.right() , underlinePos ); } } // Marker hotspots simply have a transparent rectanglular shape // drawn on top of them - else if ( spot->type() == Filter::HotSpot::Marker ) - { - //TODO - Do not use a hardcoded colour for this + else if ( spot->type() == Filter::HotSpot::Marker ) { + //TODO - Do not use a hardcoded colour for this painter.fillRect(r,QBrush(QColor(255,0,0,120))); } } @@ -1368,151 +1334,141 @@ void TerminalDisplay::paintFilters(QPainter& painter) } void TerminalDisplay::drawContents(QPainter &paint, const QRect &rect) { - QPoint tL = contentsRect().topLeft(); - int tLx = tL.x(); - int tLy = tL.y(); + QPoint tL = contentsRect().topLeft(); + int tLx = tL.x(); + int tLy = tL.y(); - int lux = qMin(_usedColumns-1, qMax(0,(rect.left() - tLx - _leftMargin ) / _fontWidth)); - int luy = qMin(_usedLines-1, qMax(0,(rect.top() - tLy - _topMargin ) / _fontHeight)); - int rlx = qMin(_usedColumns-1, qMax(0,(rect.right() - tLx - _leftMargin ) / _fontWidth)); - int rly = qMin(_usedLines-1, qMax(0,(rect.bottom() - tLy - _topMargin ) / _fontHeight)); + int lux = qMin(_usedColumns-1, qMax(0,(rect.left() - tLx - _leftMargin ) / _fontWidth)); + int luy = qMin(_usedLines-1, qMax(0,(rect.top() - tLy - _topMargin ) / _fontHeight)); + int rlx = qMin(_usedColumns-1, qMax(0,(rect.right() - tLx - _leftMargin ) / _fontWidth)); + int rly = qMin(_usedLines-1, qMax(0,(rect.bottom() - tLy - _topMargin ) / _fontHeight)); - const int bufferSize = _usedColumns; - QString unistr; - unistr.reserve(bufferSize); - for (int y = luy; y <= rly; y++) - { - quint16 c = _image[loc(lux,y)].character; - int x = lux; - if(!c && x) - x--; // Search for start of multi-column character - for (; x <= rlx; x++) - { - int len = 1; - int p = 0; + const int bufferSize = _usedColumns; + QString unistr; + unistr.reserve(bufferSize); + for (int y = luy; y <= rly; y++) { + quint16 c = _image[loc(lux,y)].character; + int x = lux; + if (!c && x) + x--; // Search for start of multi-column character + for (; x <= rlx; x++) { + int len = 1; + int p = 0; - // reset our buffer to the maximal size - unistr.resize(bufferSize); - QChar *disstrU = unistr.data(); + // reset our buffer to the maximal size + unistr.resize(bufferSize); + QChar *disstrU = unistr.data(); - // is this a single character or a sequence of characters ? - if ( _image[loc(x,y)].rendition & RE_EXTENDED_CHAR ) - { - // sequence of characters - ushort extendedCharLength = 0; - ushort* chars = ExtendedCharTable::instance - .lookupExtendedChar(_image[loc(x,y)].charSequence,extendedCharLength); - for ( int index = 0 ; index < extendedCharLength ; index++ ) - { - Q_ASSERT( p < bufferSize ); - disstrU[p++] = chars[index]; - } - } - else - { - // single character - c = _image[loc(x,y)].character; - if (c) - { - Q_ASSERT( p < bufferSize ); - disstrU[p++] = c; //fontMap(c); - } - } + // is this a single character or a sequence of characters ? + if ( _image[loc(x,y)].rendition & RE_EXTENDED_CHAR ) { + // sequence of characters + ushort extendedCharLength = 0; + ushort* chars = ExtendedCharTable::instance + .lookupExtendedChar(_image[loc(x,y)].charSequence,extendedCharLength); + for ( int index = 0 ; index < extendedCharLength ; index++ ) { + Q_ASSERT( p < bufferSize ); + disstrU[p++] = chars[index]; + } + } else { + // single character + c = _image[loc(x,y)].character; + if (c) { + Q_ASSERT( p < bufferSize ); + disstrU[p++] = c; //fontMap(c); + } + } - bool lineDraw = isLineChar(c); - bool doubleWidth = (_image[ qMin(loc(x,y)+1,_imageSize) ].character == 0); - CharacterColor currentForeground = _image[loc(x,y)].foregroundColor; - CharacterColor currentBackground = _image[loc(x,y)].backgroundColor; - quint8 currentRendition = _image[loc(x,y)].rendition; - - while (x+len <= rlx && - _image[loc(x+len,y)].foregroundColor == currentForeground && - _image[loc(x+len,y)].backgroundColor == currentBackground && - _image[loc(x+len,y)].rendition == currentRendition && - (_image[ qMin(loc(x+len,y)+1,_imageSize) ].character == 0) == doubleWidth && - isLineChar( c = _image[loc(x+len,y)].character) == lineDraw) // Assignment! - { - if (c) - disstrU[p++] = c; //fontMap(c); - if (doubleWidth) // assert((_image[loc(x+len,y)+1].character == 0)), see above if condition - len++; // Skip trailing part of multi-column character - len++; - } - if ((x+len < _usedColumns) && (!_image[loc(x+len,y)].character)) - len++; // Adjust for trailing part of multi-column character + bool lineDraw = isLineChar(c); + bool doubleWidth = (_image[ qMin(loc(x,y)+1,_imageSize) ].character == 0); + CharacterColor currentForeground = _image[loc(x,y)].foregroundColor; + CharacterColor currentBackground = _image[loc(x,y)].backgroundColor; + quint8 currentRendition = _image[loc(x,y)].rendition; + + while (x+len <= rlx && + _image[loc(x+len,y)].foregroundColor == currentForeground && + _image[loc(x+len,y)].backgroundColor == currentBackground && + _image[loc(x+len,y)].rendition == currentRendition && + (_image[ qMin(loc(x+len,y)+1,_imageSize) ].character == 0) == doubleWidth && + isLineChar( c = _image[loc(x+len,y)].character) == lineDraw) { // Assignment! + if (c) + disstrU[p++] = c; //fontMap(c); + if (doubleWidth) // assert((_image[loc(x+len,y)+1].character == 0)), see above if condition + len++; // Skip trailing part of multi-column character + len++; + } + if ((x+len < _usedColumns) && (!_image[loc(x+len,y)].character)) + len++; // Adjust for trailing part of multi-column character bool save__fixedFont = _fixedFont; - if (lineDraw) - _fixedFont = false; - if (doubleWidth) - _fixedFont = false; - unistr.resize(p); + if (lineDraw) + _fixedFont = false; + if (doubleWidth) + _fixedFont = false; + unistr.resize(p); - // Create a text scaling matrix for double width and double height lines. - QMatrix textScale; + // Create a text scaling matrix for double width and double height lines. + QMatrix textScale; - if (y < _lineProperties.size()) - { - if (_lineProperties[y] & LINE_DOUBLEWIDTH) - textScale.scale(2,1); + if (y < _lineProperties.size()) { + if (_lineProperties[y] & LINE_DOUBLEWIDTH) + textScale.scale(2,1); - if (_lineProperties[y] & LINE_DOUBLEHEIGHT) - textScale.scale(1,2); - } + if (_lineProperties[y] & LINE_DOUBLEHEIGHT) + textScale.scale(1,2); + } - //Apply text scaling matrix. - paint.setWorldMatrix(textScale, true); + //Apply text scaling matrix. + paint.setWorldMatrix(textScale, true); - //calculate the area in which the text will be drawn - QRect textArea = QRect( _leftMargin+tLx+_fontWidth*x , _topMargin+tLy+_fontHeight*y , _fontWidth*len , _fontHeight); - - //move the calculated area to take account of scaling applied to the painter. - //the position of the area from the origin (0,0) is scaled - //by the opposite of whatever - //transformation has been applied to the painter. this ensures that - //painting does actually start from textArea.topLeft() - //(instead of textArea.topLeft() * painter-scale) - textArea.moveTopLeft( textScale.inverted().map(textArea.topLeft()) ); - - //paint text fragment - drawTextFragment( paint, - textArea, - unistr, - &_image[loc(x,y)] ); //, - //0, - //!_isPrinting ); - - _fixedFont = save__fixedFont; - - //reset back to single-width, single-height _lines - paint.setWorldMatrix(textScale.inverted(), true); + //calculate the area in which the text will be drawn + QRect textArea = QRect( _leftMargin+tLx+_fontWidth*x , _topMargin+tLy+_fontHeight*y , _fontWidth*len , _fontHeight); - if (y < _lineProperties.size()-1) - { - //double-height _lines are represented by two adjacent _lines - //containing the same characters - //both _lines will have the LINE_DOUBLEHEIGHT attribute. - //If the current line has the LINE_DOUBLEHEIGHT attribute, - //we can therefore skip the next line - if (_lineProperties[y] & LINE_DOUBLEHEIGHT) - y++; - } - - x += len - 1; + //move the calculated area to take account of scaling applied to the painter. + //the position of the area from the origin (0,0) is scaled + //by the opposite of whatever + //transformation has been applied to the painter. this ensures that + //painting does actually start from textArea.topLeft() + //(instead of textArea.topLeft() * painter-scale) + textArea.moveTopLeft( textScale.inverted().map(textArea.topLeft()) ); + + //paint text fragment + drawTextFragment( paint, + textArea, + unistr, + &_image[loc(x,y)] ); //, + //0, + //!_isPrinting ); + + _fixedFont = save__fixedFont; + + //reset back to single-width, single-height _lines + paint.setWorldMatrix(textScale.inverted(), true); + + if (y < _lineProperties.size()-1) { + //double-height _lines are represented by two adjacent _lines + //containing the same characters + //both _lines will have the LINE_DOUBLEHEIGHT attribute. + //If the current line has the LINE_DOUBLEHEIGHT attribute, + //we can therefore skip the next line + if (_lineProperties[y] & LINE_DOUBLEHEIGHT) + y++; + } + + x += len - 1; + } } - } } void TerminalDisplay::blinkEvent() { - if (!_allowBlinkingText) return; + if (!_allowBlinkingText) return; - _blinking = !_blinking; + _blinking = !_blinking; - //TODO: Optimize to only repaint the areas of the widget - // where there is blinking text - // rather than repainting the whole widget. - update(); + //TODO: Optimize to only repaint the areas of the widget + // where there is blinking text + // rather than repainting the whole widget. + update(); } QRect TerminalDisplay::imageToWidget(const QRect& imageArea) const @@ -1528,14 +1484,14 @@ QRect TerminalDisplay::imageToWidget(const QRect& imageArea) const void TerminalDisplay::updateCursor() { - QRect cursorRect = imageToWidget( QRect(cursorPosition(),QSize(1,1)) ); - update(cursorRect); + QRect cursorRect = imageToWidget( QRect(cursorPosition(),QSize(1,1)) ); + update(cursorRect); } void TerminalDisplay::blinkCursorEvent() { - _cursorBlinking = !_cursorBlinking; - updateCursor(); + _cursorBlinking = !_cursorBlinking; + updateCursor(); } /* ------------------------------------------------------------------------- */ @@ -1546,64 +1502,60 @@ void TerminalDisplay::blinkCursorEvent() void TerminalDisplay::resizeEvent(QResizeEvent*) { - updateImageSize(); + updateImageSize(); } void TerminalDisplay::propagateSize() { - if (_isFixedSize) - { - setSize(_columns, _lines); - QWidget::setFixedSize(sizeHint()); - parentWidget()->adjustSize(); - parentWidget()->setFixedSize(parentWidget()->sizeHint()); - return; - } - if (_image) - updateImageSize(); + if (_isFixedSize) { + setSize(_columns, _lines); + QWidget::setFixedSize(sizeHint()); + parentWidget()->adjustSize(); + parentWidget()->setFixedSize(parentWidget()->sizeHint()); + return; + } + if (_image) + updateImageSize(); } void TerminalDisplay::updateImageSize() { - Character* oldimg = _image; - int oldlin = _lines; - int oldcol = _columns; + Character* oldimg = _image; + int oldlin = _lines; + int oldcol = _columns; - makeImage(); - - // copy the old image to reduce flicker - int lines = qMin(oldlin,_lines); - int columns = qMin(oldcol,_columns); + makeImage(); - if (oldimg) - { - for (int line = 0; line < lines; line++) - { - memcpy((void*)&_image[_columns*line], - (void*)&oldimg[oldcol*line],columns*sizeof(Character)); + // copy the old image to reduce flicker + int lines = qMin(oldlin,_lines); + int columns = qMin(oldcol,_columns); + + if (oldimg) { + for (int line = 0; line < lines; line++) { + memcpy((void*)&_image[_columns*line], + (void*)&oldimg[oldcol*line],columns*sizeof(Character)); + } + delete[] oldimg; } - delete[] oldimg; - } - if (_screenWindow) - _screenWindow->setWindowLines(_lines); + if (_screenWindow) + _screenWindow->setWindowLines(_lines); - _resizing = (oldlin!=_lines) || (oldcol!=_columns); + _resizing = (oldlin!=_lines) || (oldcol!=_columns); - if ( _resizing ) - { - showResizeNotification(); - emit changedContentSizeSignal(_contentHeight, _contentWidth); // expose resizeEvent - } - - _resizing = false; + if ( _resizing ) { + showResizeNotification(); + emit changedContentSizeSignal(_contentHeight, _contentWidth); // expose resizeEvent + } + + _resizing = false; } -//showEvent and hideEvent are reimplemented here so that it appears to other classes that the +//showEvent and hideEvent are reimplemented here so that it appears to other classes that the //display has been resized when the display is hidden or shown. // //TODO: Perhaps it would be better to have separate signals for show and hide instead of using -//the same signal as the one for a content size change +//the same signal as the one for a content size change void TerminalDisplay::showEvent(QShowEvent*) { emit changedContentSizeSignal(_contentHeight,_contentWidth); @@ -1621,465 +1573,444 @@ void TerminalDisplay::hideEvent(QHideEvent*) void TerminalDisplay::scrollBarPositionChanged(int) { - if ( !_screenWindow ) - return; + if ( !_screenWindow ) + return; - _screenWindow->scrollTo( _scrollBar->value() ); + _screenWindow->scrollTo( _scrollBar->value() ); - // if the thumb has been moved to the bottom of the _scrollBar then set - // the display to automatically track new output, - // that is, scroll down automatically - // to how new _lines as they are added - const bool atEndOfOutput = (_scrollBar->value() == _scrollBar->maximum()); - _screenWindow->setTrackOutput( atEndOfOutput ); + // if the thumb has been moved to the bottom of the _scrollBar then set + // the display to automatically track new output, + // that is, scroll down automatically + // to how new _lines as they are added + const bool atEndOfOutput = (_scrollBar->value() == _scrollBar->maximum()); + _screenWindow->setTrackOutput( atEndOfOutput ); - updateImage(); + updateImage(); } void TerminalDisplay::setScroll(int cursor, int slines) { - // update _scrollBar if the range or value has changed, - // otherwise return - // - // setting the range or value of a _scrollBar will always trigger - // a repaint, so it should be avoided if it is not necessary - if ( _scrollBar->minimum() == 0 && - _scrollBar->maximum() == (slines - _lines) && - _scrollBar->value() == cursor ) - { + // update _scrollBar if the range or value has changed, + // otherwise return + // + // setting the range or value of a _scrollBar will always trigger + // a repaint, so it should be avoided if it is not necessary + if ( _scrollBar->minimum() == 0 && + _scrollBar->maximum() == (slines - _lines) && + _scrollBar->value() == cursor ) { return; - } + } - disconnect(_scrollBar, SIGNAL(valueChanged(int)), this, SLOT(scrollBarPositionChanged(int))); - _scrollBar->setRange(0,slines - _lines); - _scrollBar->setSingleStep(1); - _scrollBar->setPageStep(_lines); - _scrollBar->setValue(cursor); - connect(_scrollBar, SIGNAL(valueChanged(int)), this, SLOT(scrollBarPositionChanged(int))); + disconnect(_scrollBar, SIGNAL(valueChanged(int)), this, SLOT(scrollBarPositionChanged(int))); + _scrollBar->setRange(0,slines - _lines); + _scrollBar->setSingleStep(1); + _scrollBar->setPageStep(_lines); + _scrollBar->setValue(cursor); + connect(_scrollBar, SIGNAL(valueChanged(int)), this, SLOT(scrollBarPositionChanged(int))); } void TerminalDisplay::setScrollBarPosition(ScrollBarPosition position) { - if (_scrollbarLocation == position) - return; - - if ( position == NoScrollBar ) - _scrollBar->hide(); - else - _scrollBar->show(); + if (_scrollbarLocation == position) + return; - _topMargin = _leftMargin = 1; - _scrollbarLocation = position; - - propagateSize(); - update(); + if ( position == NoScrollBar ) + _scrollBar->hide(); + else + _scrollBar->show(); + + _topMargin = _leftMargin = 1; + _scrollbarLocation = position; + + propagateSize(); + update(); } void TerminalDisplay::mousePressEvent(QMouseEvent* ev) { - if ( _possibleTripleClick && (ev->button()==Qt::LeftButton) ) { - mouseTripleClickEvent(ev); - return; - } - - if ( !contentsRect().contains(ev->pos()) ) return; - - if ( !_screenWindow ) return; - - int charLine; - int charColumn; - getCharacterPosition(ev->pos(),charLine,charColumn); - QPoint pos = QPoint(charColumn,charLine); - - if ( ev->button() == Qt::LeftButton) - { - _lineSelectionMode = false; - _wordSelectionMode = false; - - emit isBusySelecting(true); // Keep it steady... - // Drag only when the Control key is hold - bool selected = false; - - // The receiver of the testIsSelected() signal will adjust - // 'selected' accordingly. - //emit testIsSelected(pos.x(), pos.y(), selected); - - selected = _screenWindow->isSelected(pos.x(),pos.y()); - - if ((!_ctrlDrag || ev->modifiers() & Qt::ControlModifier) && selected ) { - // The user clicked inside selected text - dragInfo.state = diPending; - dragInfo.start = ev->pos(); + if ( _possibleTripleClick && (ev->button()==Qt::LeftButton) ) { + mouseTripleClickEvent(ev); + return; } - else { - // No reason to ever start a drag event - dragInfo.state = diNone; - _preserveLineBreaks = !( ( ev->modifiers() & Qt::ControlModifier ) && !(ev->modifiers() & Qt::AltModifier) ); - _columnSelectionMode = (ev->modifiers() & Qt::AltModifier) && (ev->modifiers() & Qt::ControlModifier); + if ( !contentsRect().contains(ev->pos()) ) return; - if (_mouseMarks || (ev->modifiers() & Qt::ShiftModifier)) - { - _screenWindow->clearSelection(); + if ( !_screenWindow ) return; - //emit clearSelectionSignal(); - pos.ry() += _scrollBar->value(); - _iPntSel = _pntSel = pos; - _actSel = 1; // left mouse button pressed but nothing selected yet. - - } - else - { - emit mouseSignal( 0, charColumn + 1, charLine + 1 +_scrollBar->value() -_scrollBar->maximum() , 0); - } + int charLine; + int charColumn; + getCharacterPosition(ev->pos(),charLine,charColumn); + QPoint pos = QPoint(charColumn,charLine); + + if ( ev->button() == Qt::LeftButton) { + _lineSelectionMode = false; + _wordSelectionMode = false; + + emit isBusySelecting(true); // Keep it steady... + // Drag only when the Control key is hold + bool selected = false; + + // The receiver of the testIsSelected() signal will adjust + // 'selected' accordingly. + //emit testIsSelected(pos.x(), pos.y(), selected); + + selected = _screenWindow->isSelected(pos.x(),pos.y()); + + if ((!_ctrlDrag || ev->modifiers() & Qt::ControlModifier) && selected ) { + // The user clicked inside selected text + dragInfo.state = diPending; + dragInfo.start = ev->pos(); + } else { + // No reason to ever start a drag event + dragInfo.state = diNone; + + _preserveLineBreaks = !( ( ev->modifiers() & Qt::ControlModifier ) && !(ev->modifiers() & Qt::AltModifier) ); + _columnSelectionMode = (ev->modifiers() & Qt::AltModifier) && (ev->modifiers() & Qt::ControlModifier); + + if (_mouseMarks || (ev->modifiers() & Qt::ShiftModifier)) { + _screenWindow->clearSelection(); + + //emit clearSelectionSignal(); + pos.ry() += _scrollBar->value(); + _iPntSel = _pntSel = pos; + _actSel = 1; // left mouse button pressed but nothing selected yet. + + } else { + emit mouseSignal( 0, charColumn + 1, charLine + 1 +_scrollBar->value() -_scrollBar->maximum() , 0); + } + } + } else if ( ev->button() == Qt::MidButton ) { + if ( _mouseMarks || (!_mouseMarks && (ev->modifiers() & Qt::ShiftModifier)) ) + emitSelection(true,ev->modifiers() & Qt::ControlModifier); + else + emit mouseSignal( 1, charColumn +1, charLine +1 +_scrollBar->value() -_scrollBar->maximum() , 0); + } else if ( ev->button() == Qt::RightButton ) { + if (_mouseMarks || (ev->modifiers() & Qt::ShiftModifier)) + emit configureRequest(ev->pos()); + else + emit mouseSignal( 2, charColumn +1, charLine +1 +_scrollBar->value() -_scrollBar->maximum() , 0); } - } - else if ( ev->button() == Qt::MidButton ) - { - if ( _mouseMarks || (!_mouseMarks && (ev->modifiers() & Qt::ShiftModifier)) ) - emitSelection(true,ev->modifiers() & Qt::ControlModifier); - else - emit mouseSignal( 1, charColumn +1, charLine +1 +_scrollBar->value() -_scrollBar->maximum() , 0); - } - else if ( ev->button() == Qt::RightButton ) - { - if (_mouseMarks || (ev->modifiers() & Qt::ShiftModifier)) - emit configureRequest(ev->pos()); - else - emit mouseSignal( 2, charColumn +1, charLine +1 +_scrollBar->value() -_scrollBar->maximum() , 0); - } } QList TerminalDisplay::filterActions(const QPoint& position) { - int charLine, charColumn; - getCharacterPosition(position,charLine,charColumn); + int charLine, charColumn; + getCharacterPosition(position,charLine,charColumn); - Filter::HotSpot* spot = _filterChain->hotSpotAt(charLine,charColumn); + Filter::HotSpot* spot = _filterChain->hotSpotAt(charLine,charColumn); - return spot ? spot->actions() : QList(); + return spot ? spot->actions() : QList(); } void TerminalDisplay::mouseMoveEvent(QMouseEvent* ev) { - int charLine = 0; - int charColumn = 0; - int scrollBarWidth = (_scrollbarLocation == ScrollBarLeft) ? _scrollBar->width() : 0; + int charLine = 0; + int charColumn = 0; + int scrollBarWidth = (_scrollbarLocation == ScrollBarLeft) ? _scrollBar->width() : 0; - getCharacterPosition(ev->pos(),charLine,charColumn); + getCharacterPosition(ev->pos(),charLine,charColumn); - // handle filters - // change link hot-spot appearance on mouse-over - Filter::HotSpot* spot = _filterChain->hotSpotAt(charLine,charColumn); - if ( spot && spot->type() == Filter::HotSpot::Link) - { - QRegion previousHotspotArea = _mouseOverHotspotArea; - _mouseOverHotspotArea = QRegion(); - QRect r; - if (spot->startLine()==spot->endLine()) { - r.setCoords( spot->startColumn()*_fontWidth + scrollBarWidth, - spot->startLine()*_fontHeight, - spot->endColumn()*_fontWidth + scrollBarWidth, - (spot->endLine()+1)*_fontHeight - 1 ); - _mouseOverHotspotArea |= r; - } else { - r.setCoords( spot->startColumn()*_fontWidth + scrollBarWidth, - spot->startLine()*_fontHeight, - _columns*_fontWidth - 1 + scrollBarWidth, - (spot->startLine()+1)*_fontHeight ); - _mouseOverHotspotArea |= r; - for ( int line = spot->startLine()+1 ; line < spot->endLine() ; line++ ) { - r.setCoords( 0*_fontWidth + scrollBarWidth, - line*_fontHeight, - _columns*_fontWidth + scrollBarWidth, - (line+1)*_fontHeight ); + // handle filters + // change link hot-spot appearance on mouse-over + Filter::HotSpot* spot = _filterChain->hotSpotAt(charLine,charColumn); + if ( spot && spot->type() == Filter::HotSpot::Link) { + QRegion previousHotspotArea = _mouseOverHotspotArea; + _mouseOverHotspotArea = QRegion(); + QRect r; + if (spot->startLine()==spot->endLine()) { + r.setCoords( spot->startColumn()*_fontWidth + scrollBarWidth, + spot->startLine()*_fontHeight, + spot->endColumn()*_fontWidth + scrollBarWidth, + (spot->endLine()+1)*_fontHeight - 1 ); + _mouseOverHotspotArea |= r; + } else { + r.setCoords( spot->startColumn()*_fontWidth + scrollBarWidth, + spot->startLine()*_fontHeight, + _columns*_fontWidth - 1 + scrollBarWidth, + (spot->startLine()+1)*_fontHeight ); + _mouseOverHotspotArea |= r; + for ( int line = spot->startLine()+1 ; line < spot->endLine() ; line++ ) { + r.setCoords( 0*_fontWidth + scrollBarWidth, + line*_fontHeight, + _columns*_fontWidth + scrollBarWidth, + (line+1)*_fontHeight ); + _mouseOverHotspotArea |= r; + } + r.setCoords( 0*_fontWidth + scrollBarWidth, + spot->endLine()*_fontHeight, + spot->endColumn()*_fontWidth + scrollBarWidth, + (spot->endLine()+1)*_fontHeight ); _mouseOverHotspotArea |= r; } - r.setCoords( 0*_fontWidth + scrollBarWidth, - spot->endLine()*_fontHeight, - spot->endColumn()*_fontWidth + scrollBarWidth, - (spot->endLine()+1)*_fontHeight ); - _mouseOverHotspotArea |= r; - } - // display tooltips when mousing over links - // TODO: Extend this to work with filter types other than links - const QString& tooltip = spot->tooltip(); - if ( !tooltip.isEmpty() ) - { - QToolTip::showText( mapToGlobal(ev->pos()) , tooltip , this , _mouseOverHotspotArea.boundingRect() ); - } + // display tooltips when mousing over links + // TODO: Extend this to work with filter types other than links + const QString& tooltip = spot->tooltip(); + if ( !tooltip.isEmpty() ) { + QToolTip::showText( mapToGlobal(ev->pos()) , tooltip , this , _mouseOverHotspotArea.boundingRect() ); + } - update( _mouseOverHotspotArea | previousHotspotArea ); - } - else if ( !_mouseOverHotspotArea.isEmpty() ) - { + update( _mouseOverHotspotArea | previousHotspotArea ); + } else if ( !_mouseOverHotspotArea.isEmpty() ) { update( _mouseOverHotspotArea ); // set hotspot area to an invalid rectangle _mouseOverHotspotArea = QRegion(); - } - - // for auto-hiding the cursor, we need mouseTracking - if (ev->buttons() == Qt::NoButton ) return; - - // if the terminal is interested in mouse movements - // then emit a mouse movement signal, unless the shift - // key is being held down, which overrides this. - if (!_mouseMarks && !(ev->modifiers() & Qt::ShiftModifier)) - { - int button = 3; - if (ev->buttons() & Qt::LeftButton) - button = 0; - if (ev->buttons() & Qt::MidButton) - button = 1; - if (ev->buttons() & Qt::RightButton) - button = 2; - - - emit mouseSignal( button, - charColumn + 1, - charLine + 1 +_scrollBar->value() -_scrollBar->maximum(), - 1 ); - - return; - } - - if (dragInfo.state == diPending) - { - // we had a mouse down, but haven't confirmed a drag yet - // if the mouse has moved sufficiently, we will confirm - //! \todo TODO/FIXME: obtain some sane value - int distance = 10; //KGlobalSettings::dndEventDelay(); - if ( ev->x() > dragInfo.start.x() + distance || ev->x() < dragInfo.start.x() - distance || - ev->y() > dragInfo.start.y() + distance || ev->y() < dragInfo.start.y() - distance) - { - // we've left the drag square, we can start a real drag operation now - emit isBusySelecting(false); // Ok.. we can breath again. - - _screenWindow->clearSelection(); - doDrag(); } - return; - } - else if (dragInfo.state == diDragging) - { - // this isn't technically needed because mouseMoveEvent is suppressed during - // Qt drag operations, replaced by dragMoveEvent - return; - } - if (_actSel == 0) return; + // for auto-hiding the cursor, we need mouseTracking + if (ev->buttons() == Qt::NoButton ) return; - // don't extend selection while pasting - if (ev->buttons() & Qt::MidButton) return; + // if the terminal is interested in mouse movements + // then emit a mouse movement signal, unless the shift + // key is being held down, which overrides this. + if (!_mouseMarks && !(ev->modifiers() & Qt::ShiftModifier)) { + int button = 3; + if (ev->buttons() & Qt::LeftButton) + button = 0; + if (ev->buttons() & Qt::MidButton) + button = 1; + if (ev->buttons() & Qt::RightButton) + button = 2; - extendSelection( ev->pos() ); + + emit mouseSignal( button, + charColumn + 1, + charLine + 1 +_scrollBar->value() -_scrollBar->maximum(), + 1 ); + + return; + } + + if (dragInfo.state == diPending) { + // we had a mouse down, but haven't confirmed a drag yet + // if the mouse has moved sufficiently, we will confirm + //! \todo TODO/FIXME: obtain some sane value + int distance = 10; //KGlobalSettings::dndEventDelay(); + if ( ev->x() > dragInfo.start.x() + distance || ev->x() < dragInfo.start.x() - distance || + ev->y() > dragInfo.start.y() + distance || ev->y() < dragInfo.start.y() - distance) { + // we've left the drag square, we can start a real drag operation now + emit isBusySelecting(false); // Ok.. we can breath again. + + _screenWindow->clearSelection(); + doDrag(); + } + return; + } else if (dragInfo.state == diDragging) { + // this isn't technically needed because mouseMoveEvent is suppressed during + // Qt drag operations, replaced by dragMoveEvent + return; + } + + if (_actSel == 0) return; + +// don't extend selection while pasting + if (ev->buttons() & Qt::MidButton) return; + + extendSelection( ev->pos() ); } void TerminalDisplay::extendSelection( const QPoint& position ) { - QPoint pos = position; + QPoint pos = position; - if ( !_screenWindow ) - return; + if ( !_screenWindow ) + return; - //if ( !contentsRect().contains(ev->pos()) ) return; - QPoint tL = contentsRect().topLeft(); - int tLx = tL.x(); - int tLy = tL.y(); - int scroll = _scrollBar->value(); + //if ( !contentsRect().contains(ev->pos()) ) return; + QPoint tL = contentsRect().topLeft(); + int tLx = tL.x(); + int tLy = tL.y(); + int scroll = _scrollBar->value(); - // we're in the process of moving the mouse with the left button pressed - // the mouse cursor will kept caught within the bounds of the text in - // this widget. + // we're in the process of moving the mouse with the left button pressed + // the mouse cursor will kept caught within the bounds of the text in + // this widget. - int linesBeyondWidget = 0; + int linesBeyondWidget = 0; - QRect textBounds(tLx + _leftMargin, + QRect textBounds(tLx + _leftMargin, tLy + _topMargin, - _usedColumns*_fontWidth-1, - _usedLines*_fontHeight-1); + _usedColumns*_fontWidth-1, + _usedLines*_fontHeight-1); - // Adjust position within text area bounds. - QPoint oldpos = pos; - - pos.setX( qBound(textBounds.left(),pos.x(),textBounds.right()) ); - pos.setY( qBound(textBounds.top(),pos.y(),textBounds.bottom()) ); + // Adjust position within text area bounds. + QPoint oldpos = pos; - if ( oldpos.y() > textBounds.bottom() ) - { - linesBeyondWidget = (oldpos.y()-textBounds.bottom()) / _fontHeight; - _scrollBar->setValue(_scrollBar->value()+linesBeyondWidget+1); // scrollforward - } - if ( oldpos.y() < textBounds.top() ) - { - linesBeyondWidget = (textBounds.top()-oldpos.y()) / _fontHeight; - _scrollBar->setValue(_scrollBar->value()-linesBeyondWidget-1); // history - } + pos.setX( qBound(textBounds.left(),pos.x(),textBounds.right()) ); + pos.setY( qBound(textBounds.top(),pos.y(),textBounds.bottom()) ); - int charColumn = 0; - int charLine = 0; - getCharacterPosition(pos,charLine,charColumn); - - QPoint here = QPoint(charColumn,charLine); //QPoint((pos.x()-tLx-_leftMargin+(_fontWidth/2))/_fontWidth,(pos.y()-tLy-_topMargin)/_fontHeight); - QPoint ohere; - QPoint _iPntSelCorr = _iPntSel; - _iPntSelCorr.ry() -= _scrollBar->value(); - QPoint _pntSelCorr = _pntSel; - _pntSelCorr.ry() -= _scrollBar->value(); - bool swapping = false; - - if ( _wordSelectionMode ) - { - // Extend to word boundaries - int i; - QChar selClass; - - bool left_not_right = ( here.y() < _iPntSelCorr.y() || - ( here.y() == _iPntSelCorr.y() && here.x() < _iPntSelCorr.x() ) ); - bool old_left_not_right = ( _pntSelCorr.y() < _iPntSelCorr.y() || - ( _pntSelCorr.y() == _iPntSelCorr.y() && _pntSelCorr.x() < _iPntSelCorr.x() ) ); - swapping = left_not_right != old_left_not_right; - - // Find left (left_not_right ? from here : from start) - QPoint left = left_not_right ? here : _iPntSelCorr; - i = loc(left.x(),left.y()); - if (i>=0 && i<=_imageSize) { - selClass = charClass(_image[i].character); - while ( ((left.x()>0) || (left.y()>0 && (_lineProperties[left.y()-1] & LINE_WRAPPED) )) - && charClass(_image[i-1].character) == selClass ) - { i--; if (left.x()>0) left.rx()--; else {left.rx()=_usedColumns-1; left.ry()--;} } + if ( oldpos.y() > textBounds.bottom() ) { + linesBeyondWidget = (oldpos.y()-textBounds.bottom()) / _fontHeight; + _scrollBar->setValue(_scrollBar->value()+linesBeyondWidget+1); // scrollforward + } + if ( oldpos.y() < textBounds.top() ) { + linesBeyondWidget = (textBounds.top()-oldpos.y()) / _fontHeight; + _scrollBar->setValue(_scrollBar->value()-linesBeyondWidget-1); // history } - // Find left (left_not_right ? from start : from here) - QPoint right = left_not_right ? _iPntSelCorr : here; - i = loc(right.x(),right.y()); - if (i>=0 && i<=_imageSize) { - selClass = charClass(_image[i].character); - while( ((right.x()<_usedColumns-1) || (right.y()<_usedLines-1 && (_lineProperties[right.y()] & LINE_WRAPPED) )) - && charClass(_image[i+1].character) == selClass ) - { i++; if (right.x()<_usedColumns-1) right.rx()++; else {right.rx()=0; right.ry()++; } } + int charColumn = 0; + int charLine = 0; + getCharacterPosition(pos,charLine,charColumn); + + QPoint here = QPoint(charColumn,charLine); //QPoint((pos.x()-tLx-_leftMargin+(_fontWidth/2))/_fontWidth,(pos.y()-tLy-_topMargin)/_fontHeight); + QPoint ohere; + QPoint _iPntSelCorr = _iPntSel; + _iPntSelCorr.ry() -= _scrollBar->value(); + QPoint _pntSelCorr = _pntSel; + _pntSelCorr.ry() -= _scrollBar->value(); + bool swapping = false; + + if ( _wordSelectionMode ) { + // Extend to word boundaries + int i; + QChar selClass; + + bool left_not_right = ( here.y() < _iPntSelCorr.y() || + ( here.y() == _iPntSelCorr.y() && here.x() < _iPntSelCorr.x() ) ); + bool old_left_not_right = ( _pntSelCorr.y() < _iPntSelCorr.y() || + ( _pntSelCorr.y() == _iPntSelCorr.y() && _pntSelCorr.x() < _iPntSelCorr.x() ) ); + swapping = left_not_right != old_left_not_right; + + // Find left (left_not_right ? from here : from start) + QPoint left = left_not_right ? here : _iPntSelCorr; + i = loc(left.x(),left.y()); + if (i>=0 && i<=_imageSize) { + selClass = charClass(_image[i].character); + while ( ((left.x()>0) || (left.y()>0 && (_lineProperties[left.y()-1] & LINE_WRAPPED) )) + && charClass(_image[i-1].character) == selClass ) { + i--; + if (left.x()>0) left.rx()--; + else { + left.rx()=_usedColumns-1; + left.ry()--; + } + } + } + + // Find left (left_not_right ? from start : from here) + QPoint right = left_not_right ? _iPntSelCorr : here; + i = loc(right.x(),right.y()); + if (i>=0 && i<=_imageSize) { + selClass = charClass(_image[i].character); + while ( ((right.x()<_usedColumns-1) || (right.y()<_usedLines-1 && (_lineProperties[right.y()] & LINE_WRAPPED) )) + && charClass(_image[i+1].character) == selClass ) { + i++; + if (right.x()<_usedColumns-1) right.rx()++; + else { + right.rx()=0; + right.ry()++; + } + } + } + + // Pick which is start (ohere) and which is extension (here) + if ( left_not_right ) { + here = left; + ohere = right; + } else { + here = right; + ohere = left; + } + ohere.rx()++; } - // Pick which is start (ohere) and which is extension (here) - if ( left_not_right ) - { - here = left; ohere = right; - } - else - { - here = right; ohere = left; - } - ohere.rx()++; - } + if ( _lineSelectionMode ) { + // Extend to complete line + bool above_not_below = ( here.y() < _iPntSelCorr.y() ); - if ( _lineSelectionMode ) - { - // Extend to complete line - bool above_not_below = ( here.y() < _iPntSelCorr.y() ); + QPoint above = above_not_below ? here : _iPntSelCorr; + QPoint below = above_not_below ? _iPntSelCorr : here; - QPoint above = above_not_below ? here : _iPntSelCorr; - QPoint below = above_not_below ? _iPntSelCorr : here; + while (above.y()>0 && (_lineProperties[above.y()-1] & LINE_WRAPPED) ) + above.ry()--; + while (below.y()<_usedLines-1 && (_lineProperties[below.y()] & LINE_WRAPPED) ) + below.ry()++; - while (above.y()>0 && (_lineProperties[above.y()-1] & LINE_WRAPPED) ) - above.ry()--; - while (below.y()<_usedLines-1 && (_lineProperties[below.y()] & LINE_WRAPPED) ) - below.ry()++; + above.setX(0); + below.setX(_usedColumns-1); - above.setX(0); - below.setX(_usedColumns-1); + // Pick which is start (ohere) and which is extension (here) + if ( above_not_below ) { + here = above; + ohere = below; + } else { + here = below; + ohere = above; + } - // Pick which is start (ohere) and which is extension (here) - if ( above_not_below ) - { - here = above; ohere = below; - } - else - { - here = below; ohere = above; + QPoint newSelBegin = QPoint( ohere.x(), ohere.y() ); + swapping = !(_tripleSelBegin==newSelBegin); + _tripleSelBegin = newSelBegin; + + ohere.rx()++; } - QPoint newSelBegin = QPoint( ohere.x(), ohere.y() ); - swapping = !(_tripleSelBegin==newSelBegin); - _tripleSelBegin = newSelBegin; + int offset = 0; + if ( !_wordSelectionMode && !_lineSelectionMode ) { + int i; + QChar selClass; - ohere.rx()++; - } + bool left_not_right = ( here.y() < _iPntSelCorr.y() || + ( here.y() == _iPntSelCorr.y() && here.x() < _iPntSelCorr.x() ) ); + bool old_left_not_right = ( _pntSelCorr.y() < _iPntSelCorr.y() || + ( _pntSelCorr.y() == _iPntSelCorr.y() && _pntSelCorr.x() < _iPntSelCorr.x() ) ); + swapping = left_not_right != old_left_not_right; - int offset = 0; - if ( !_wordSelectionMode && !_lineSelectionMode ) - { - int i; - QChar selClass; + // Find left (left_not_right ? from here : from start) + QPoint left = left_not_right ? here : _iPntSelCorr; - bool left_not_right = ( here.y() < _iPntSelCorr.y() || - ( here.y() == _iPntSelCorr.y() && here.x() < _iPntSelCorr.x() ) ); - bool old_left_not_right = ( _pntSelCorr.y() < _iPntSelCorr.y() || - ( _pntSelCorr.y() == _iPntSelCorr.y() && _pntSelCorr.x() < _iPntSelCorr.x() ) ); - swapping = left_not_right != old_left_not_right; + // Find left (left_not_right ? from start : from here) + QPoint right = left_not_right ? _iPntSelCorr : here; + if ( right.x() > 0 && !_columnSelectionMode ) { + i = loc(right.x(),right.y()); + if (i>=0 && i<=_imageSize) { + selClass = charClass(_image[i-1].character); + /* if (selClass == ' ') + { + while ( right.x() < _usedColumns-1 && charClass(_image[i+1].character) == selClass && (right.y()<_usedLines-1) && + !(_lineProperties[right.y()] & LINE_WRAPPED)) + { i++; right.rx()++; } + if (right.x() < _usedColumns-1) + right = left_not_right ? _iPntSelCorr : here; + else + right.rx()++; // will be balanced later because of offset=-1; + }*/ + } + } - // Find left (left_not_right ? from here : from start) - QPoint left = left_not_right ? here : _iPntSelCorr; - - // Find left (left_not_right ? from start : from here) - QPoint right = left_not_right ? _iPntSelCorr : here; - if ( right.x() > 0 && !_columnSelectionMode ) - { - i = loc(right.x(),right.y()); - if (i>=0 && i<=_imageSize) { - selClass = charClass(_image[i-1].character); - /* if (selClass == ' ') - { - while ( right.x() < _usedColumns-1 && charClass(_image[i+1].character) == selClass && (right.y()<_usedLines-1) && - !(_lineProperties[right.y()] & LINE_WRAPPED)) - { i++; right.rx()++; } - if (right.x() < _usedColumns-1) - right = left_not_right ? _iPntSelCorr : here; - else - right.rx()++; // will be balanced later because of offset=-1; - }*/ - } + // Pick which is start (ohere) and which is extension (here) + if ( left_not_right ) { + here = left; + ohere = right; + offset = 0; + } else { + here = right; + ohere = left; + offset = -1; + } } - // Pick which is start (ohere) and which is extension (here) - if ( left_not_right ) - { - here = left; ohere = right; offset = 0; - } - else - { - here = right; ohere = left; offset = -1; - } - } + if ((here == _pntSelCorr) && (scroll == _scrollBar->value())) return; // not moved - if ((here == _pntSelCorr) && (scroll == _scrollBar->value())) return; // not moved + if (here == ohere) return; // It's not left, it's not right. - if (here == ohere) return; // It's not left, it's not right. + if ( _actSel < 2 || swapping ) { + if ( _columnSelectionMode && !_lineSelectionMode && !_wordSelectionMode ) { + _screenWindow->setSelectionStart( ohere.x() , ohere.y() , true ); + } else { + _screenWindow->setSelectionStart( ohere.x()-1-offset , ohere.y() , false ); + } - if ( _actSel < 2 || swapping ) - { - if ( _columnSelectionMode && !_lineSelectionMode && !_wordSelectionMode ) - { - _screenWindow->setSelectionStart( ohere.x() , ohere.y() , true ); - } - else - { - _screenWindow->setSelectionStart( ohere.x()-1-offset , ohere.y() , false ); } - } + _actSel = 2; // within selection + _pntSel = here; + _pntSel.ry() += _scrollBar->value(); - _actSel = 2; // within selection - _pntSel = here; - _pntSel.ry() += _scrollBar->value(); - - if ( _columnSelectionMode && !_lineSelectionMode && !_wordSelectionMode ) - { - _screenWindow->setSelectionEnd( here.x() , here.y() ); - } - else - { - _screenWindow->setSelectionEnd( here.x()+offset , here.y() ); - } + if ( _columnSelectionMode && !_lineSelectionMode && !_wordSelectionMode ) { + _screenWindow->setSelectionEnd( here.x() , here.y() ); + } else { + _screenWindow->setSelectionEnd( here.x()+offset , here.y() ); + } } @@ -2092,46 +2023,40 @@ void TerminalDisplay::mouseReleaseEvent(QMouseEvent* ev) int charColumn; getCharacterPosition(ev->pos(),charLine,charColumn); - if ( ev->button() == Qt::LeftButton) - { - emit isBusySelecting(false); - if(dragInfo.state == diPending) - { - // We had a drag event pending but never confirmed. Kill selection - _screenWindow->clearSelection(); - //emit clearSelectionSignal(); + if ( ev->button() == Qt::LeftButton) { + emit isBusySelecting(false); + if (dragInfo.state == diPending) { + // We had a drag event pending but never confirmed. Kill selection + _screenWindow->clearSelection(); + //emit clearSelectionSignal(); + } else { + if ( _actSel > 1 ) { + setSelection( _screenWindow->selectedText(_preserveLineBreaks) ); + } + + _actSel = 0; + + //FIXME: emits a release event even if the mouse is + // outside the range. The procedure used in `mouseMoveEvent' + // applies here, too. + + if (!_mouseMarks && !(ev->modifiers() & Qt::ShiftModifier)) + emit mouseSignal( 3, // release + charColumn + 1, + charLine + 1 +_scrollBar->value() -_scrollBar->maximum() , 0); + } + dragInfo.state = diNone; } - else - { - if ( _actSel > 1 ) - { - setSelection( _screenWindow->selectedText(_preserveLineBreaks) ); - } - _actSel = 0; - //FIXME: emits a release event even if the mouse is - // outside the range. The procedure used in `mouseMoveEvent' - // applies here, too. - - if (!_mouseMarks && !(ev->modifiers() & Qt::ShiftModifier)) - emit mouseSignal( 3, // release - charColumn + 1, - charLine + 1 +_scrollBar->value() -_scrollBar->maximum() , 0); + if ( !_mouseMarks && + ((ev->button() == Qt::RightButton && !(ev->modifiers() & Qt::ShiftModifier)) + || ev->button() == Qt::MidButton) ) { + emit mouseSignal( 3, + charColumn + 1, + charLine + 1 +_scrollBar->value() -_scrollBar->maximum() , + 0); } - dragInfo.state = diNone; - } - - - if ( !_mouseMarks && - ((ev->button() == Qt::RightButton && !(ev->modifiers() & Qt::ShiftModifier)) - || ev->button() == Qt::MidButton) ) - { - emit mouseSignal( 3, - charColumn + 1, - charLine + 1 +_scrollBar->value() -_scrollBar->maximum() , - 0); - } } void TerminalDisplay::getCharacterPosition(const QPoint& widgetPoint,int& line,int& column) const @@ -2158,222 +2083,210 @@ void TerminalDisplay::getCharacterPosition(const QPoint& widgetPoint,int& line,i void TerminalDisplay::updateLineProperties() { - if ( !_screenWindow ) + if ( !_screenWindow ) return; - _lineProperties = _screenWindow->getLineProperties(); + _lineProperties = _screenWindow->getLineProperties(); } void TerminalDisplay::mouseDoubleClickEvent(QMouseEvent* ev) { - if ( ev->button() != Qt::LeftButton) return; - if ( !_screenWindow ) return; + if ( ev->button() != Qt::LeftButton) return; + if ( !_screenWindow ) return; - int charLine = 0; - int charColumn = 0; + int charLine = 0; + int charColumn = 0; - getCharacterPosition(ev->pos(),charLine,charColumn); + getCharacterPosition(ev->pos(),charLine,charColumn); - QPoint pos(charColumn,charLine); + QPoint pos(charColumn,charLine); - // pass on double click as two clicks. - if (!_mouseMarks && !(ev->modifiers() & Qt::ShiftModifier)) - { - // Send just _ONE_ click event, since the first click of the double click - // was already sent by the click handler - emit mouseSignal( 0, - pos.x()+1, - pos.y()+1 +_scrollBar->value() -_scrollBar->maximum(), - 0 ); // left button - return; - } + // pass on double click as two clicks. + if (!_mouseMarks && !(ev->modifiers() & Qt::ShiftModifier)) { + // Send just _ONE_ click event, since the first click of the double click + // was already sent by the click handler + emit mouseSignal( 0, + pos.x()+1, + pos.y()+1 +_scrollBar->value() -_scrollBar->maximum(), + 0 ); // left button + return; + } - _screenWindow->clearSelection(); - QPoint bgnSel = pos; - QPoint endSel = pos; - int i = loc(bgnSel.x(),bgnSel.y()); - _iPntSel = bgnSel; - _iPntSel.ry() += _scrollBar->value(); + _screenWindow->clearSelection(); + QPoint bgnSel = pos; + QPoint endSel = pos; + int i = loc(bgnSel.x(),bgnSel.y()); + _iPntSel = bgnSel; + _iPntSel.ry() += _scrollBar->value(); - _wordSelectionMode = true; + _wordSelectionMode = true; - // find word boundaries... - QChar selClass = charClass(_image[i].character); - { - // find the start of the word - int x = bgnSel.x(); - while ( ((x>0) || (bgnSel.y()>0 && (_lineProperties[bgnSel.y()-1] & LINE_WRAPPED) )) - && charClass(_image[i-1].character) == selClass ) - { - i--; - if (x>0) - x--; - else - { - x=_usedColumns-1; - bgnSel.ry()--; - } - } + // find word boundaries... + QChar selClass = charClass(_image[i].character); + { + // find the start of the word + int x = bgnSel.x(); + while ( ((x>0) || (bgnSel.y()>0 && (_lineProperties[bgnSel.y()-1] & LINE_WRAPPED) )) + && charClass(_image[i-1].character) == selClass ) { + i--; + if (x>0) + x--; + else { + x=_usedColumns-1; + bgnSel.ry()--; + } + } - bgnSel.setX(x); - _screenWindow->setSelectionStart( bgnSel.x() , bgnSel.y() , false ); + bgnSel.setX(x); + _screenWindow->setSelectionStart( bgnSel.x() , bgnSel.y() , false ); - // find the end of the word - i = loc( endSel.x(), endSel.y() ); - x = endSel.x(); - while( ((x<_usedColumns-1) || (endSel.y()<_usedLines-1 && (_lineProperties[endSel.y()] & LINE_WRAPPED) )) - && charClass(_image[i+1].character) == selClass ) - { - i++; - if (x<_usedColumns-1) - x++; - else - { - x=0; - endSel.ry()++; - } - } + // find the end of the word + i = loc( endSel.x(), endSel.y() ); + x = endSel.x(); + while ( ((x<_usedColumns-1) || (endSel.y()<_usedLines-1 && (_lineProperties[endSel.y()] & LINE_WRAPPED) )) + && charClass(_image[i+1].character) == selClass ) { + i++; + if (x<_usedColumns-1) + x++; + else { + x=0; + endSel.ry()++; + } + } - endSel.setX(x); + endSel.setX(x); - // In word selection mode don't select @ (64) if at end of word. - if ( ( QChar( _image[i].character ) == '@' ) && ( ( endSel.x() - bgnSel.x() ) > 0 ) ) - endSel.setX( x - 1 ); + // In word selection mode don't select @ (64) if at end of word. + if ( ( QChar( _image[i].character ) == '@' ) && ( ( endSel.x() - bgnSel.x() ) > 0 ) ) + endSel.setX( x - 1 ); - _actSel = 2; // within selection - - _screenWindow->setSelectionEnd( endSel.x() , endSel.y() ); - - setSelection( _screenWindow->selectedText(_preserveLineBreaks) ); - } + _actSel = 2; // within selection - _possibleTripleClick=true; + _screenWindow->setSelectionEnd( endSel.x() , endSel.y() ); - QTimer::singleShot(QApplication::doubleClickInterval(),this, - SLOT(tripleClickTimeout())); + setSelection( _screenWindow->selectedText(_preserveLineBreaks) ); + } + + _possibleTripleClick=true; + + QTimer::singleShot(QApplication::doubleClickInterval(),this, + SLOT(tripleClickTimeout())); } void TerminalDisplay::wheelEvent( QWheelEvent* ev ) { - if (ev->orientation() != Qt::Vertical) - return; + if (ev->orientation() != Qt::Vertical) + return; - // if the terminal program is not interested mouse events - // then send the event to the scrollbar if the slider has room to move - // or otherwise send simulated up / down key presses to the terminal program - // for the benefit of programs such as 'less' - if ( _mouseMarks ) - { - bool canScroll = _scrollBar->maximum() > 0; - if (canScroll) - _scrollBar->event(ev); - else - { - // assume that each Up / Down key event will cause the terminal application - // to scroll by one line. - // - // to get a reasonable scrolling speed, scroll by one line for every 5 degrees - // of mouse wheel rotation. Mouse wheels typically move in steps of 15 degrees, - // giving a scroll of 3 lines - int key = ev->delta() > 0 ? Qt::Key_Up : Qt::Key_Down; + // if the terminal program is not interested mouse events + // then send the event to the scrollbar if the slider has room to move + // or otherwise send simulated up / down key presses to the terminal program + // for the benefit of programs such as 'less' + if ( _mouseMarks ) { + bool canScroll = _scrollBar->maximum() > 0; + if (canScroll) + _scrollBar->event(ev); + else { + // assume that each Up / Down key event will cause the terminal application + // to scroll by one line. + // + // to get a reasonable scrolling speed, scroll by one line for every 5 degrees + // of mouse wheel rotation. Mouse wheels typically move in steps of 15 degrees, + // giving a scroll of 3 lines + int key = ev->delta() > 0 ? Qt::Key_Up : Qt::Key_Down; - // QWheelEvent::delta() gives rotation in eighths of a degree - int wheelDegrees = ev->delta() / 8; - int linesToScroll = abs(wheelDegrees) / 5; + // QWheelEvent::delta() gives rotation in eighths of a degree + int wheelDegrees = ev->delta() / 8; + int linesToScroll = abs(wheelDegrees) / 5; - QKeyEvent keyScrollEvent(QEvent::KeyPress,key,Qt::NoModifier); + QKeyEvent keyScrollEvent(QEvent::KeyPress,key,Qt::NoModifier); - for (int i=0;ipos() , charLine , charColumn ); + + emit mouseSignal( ev->delta() > 0 ? 4 : 5, + charColumn + 1, + charLine + 1 +_scrollBar->value() -_scrollBar->maximum() , + 0); } - } - else - { - // terminal program wants notification of mouse activity - - int charLine; - int charColumn; - getCharacterPosition( ev->pos() , charLine , charColumn ); - - emit mouseSignal( ev->delta() > 0 ? 4 : 5, - charColumn + 1, - charLine + 1 +_scrollBar->value() -_scrollBar->maximum() , - 0); - } } void TerminalDisplay::tripleClickTimeout() { - _possibleTripleClick=false; + _possibleTripleClick=false; } void TerminalDisplay::mouseTripleClickEvent(QMouseEvent* ev) { - if ( !_screenWindow ) return; + if ( !_screenWindow ) return; - int charLine; - int charColumn; - getCharacterPosition(ev->pos(),charLine,charColumn); - _iPntSel = QPoint(charColumn,charLine); + int charLine; + int charColumn; + getCharacterPosition(ev->pos(),charLine,charColumn); + _iPntSel = QPoint(charColumn,charLine); - _screenWindow->clearSelection(); + _screenWindow->clearSelection(); - _lineSelectionMode = true; - _wordSelectionMode = false; + _lineSelectionMode = true; + _wordSelectionMode = false; - _actSel = 2; // within selection - emit isBusySelecting(true); // Keep it steady... + _actSel = 2; // within selection + emit isBusySelecting(true); // Keep it steady... - while (_iPntSel.y()>0 && (_lineProperties[_iPntSel.y()-1] & LINE_WRAPPED) ) - _iPntSel.ry()--; - - if (_tripleClickMode == SelectForwardsFromCursor) { - // find word boundary start - int i = loc(_iPntSel.x(),_iPntSel.y()); - QChar selClass = charClass(_image[i].character); - int x = _iPntSel.x(); - - while ( ((x>0) || - (_iPntSel.y()>0 && (_lineProperties[_iPntSel.y()-1] & LINE_WRAPPED) ) - ) - && charClass(_image[i-1].character) == selClass ) - { - i--; - if (x>0) - x--; - else - { - x=_columns-1; - _iPntSel.ry()--; - } + while (_iPntSel.y()>0 && (_lineProperties[_iPntSel.y()-1] & LINE_WRAPPED) ) + _iPntSel.ry()--; + + if (_tripleClickMode == SelectForwardsFromCursor) { + // find word boundary start + int i = loc(_iPntSel.x(),_iPntSel.y()); + QChar selClass = charClass(_image[i].character); + int x = _iPntSel.x(); + + while ( ((x>0) || + (_iPntSel.y()>0 && (_lineProperties[_iPntSel.y()-1] & LINE_WRAPPED) ) + ) + && charClass(_image[i-1].character) == selClass ) { + i--; + if (x>0) + x--; + else { + x=_columns-1; + _iPntSel.ry()--; + } + } + + _screenWindow->setSelectionStart( x , _iPntSel.y() , false ); + _tripleSelBegin = QPoint( x, _iPntSel.y() ); + } else if (_tripleClickMode == SelectWholeLine) { + _screenWindow->setSelectionStart( 0 , _iPntSel.y() , false ); + _tripleSelBegin = QPoint( 0, _iPntSel.y() ); } - _screenWindow->setSelectionStart( x , _iPntSel.y() , false ); - _tripleSelBegin = QPoint( x, _iPntSel.y() ); - } - else if (_tripleClickMode == SelectWholeLine) { - _screenWindow->setSelectionStart( 0 , _iPntSel.y() , false ); - _tripleSelBegin = QPoint( 0, _iPntSel.y() ); - } + while (_iPntSel.y()<_lines-1 && (_lineProperties[_iPntSel.y()] & LINE_WRAPPED) ) + _iPntSel.ry()++; - while (_iPntSel.y()<_lines-1 && (_lineProperties[_iPntSel.y()] & LINE_WRAPPED) ) - _iPntSel.ry()++; - - _screenWindow->setSelectionEnd( _columns - 1 , _iPntSel.y() ); + _screenWindow->setSelectionEnd( _columns - 1 , _iPntSel.y() ); - setSelection(_screenWindow->selectedText(_preserveLineBreaks)); + setSelection(_screenWindow->selectedText(_preserveLineBreaks)); - _iPntSel.ry() += _scrollBar->value(); + _iPntSel.ry() += _scrollBar->value(); } bool TerminalDisplay::focusNextPrevChild( bool next ) { - if (next) - return false; // This disables changing the active part in konqueror - // when pressing Tab - return QWidget::focusNextPrevChild( next ); + if (next) + return false; // This disables changing the active part in konqueror + // when pressing Tab + return QWidget::focusNextPrevChild( next ); } @@ -2382,7 +2295,7 @@ QChar TerminalDisplay::charClass(QChar qch) const if ( qch.isSpace() ) return ' '; if ( qch.isLetterOrNumber() || _wordCharacters.contains(qch, Qt::CaseInsensitive ) ) - return 'a'; + return 'a'; return qch; } @@ -2394,8 +2307,8 @@ void TerminalDisplay::setWordCharacters(const QString& wc) void TerminalDisplay::setUsesMouse(bool on) { - _mouseMarks = on; - setCursor( _mouseMarks ? Qt::IBeamCursor : Qt::ArrowCursor ); + _mouseMarks = on; + setCursor( _mouseMarks ? Qt::IBeamCursor : Qt::ArrowCursor ); } bool TerminalDisplay::usesMouse() const { @@ -2412,47 +2325,46 @@ bool TerminalDisplay::usesMouse() const void TerminalDisplay::emitSelection(bool useXselection,bool appendReturn) { - if ( !_screenWindow ) - return; + if ( !_screenWindow ) + return; - // Paste Clipboard by simulating keypress events - QString text = QApplication::clipboard()->text(useXselection ? QClipboard::Selection : - QClipboard::Clipboard); - if(appendReturn) - text.append("\r"); - if ( ! text.isEmpty() ) - { - text.replace('\n', '\r'); - QKeyEvent e(QEvent::KeyPress, 0, Qt::NoModifier, text); - emit keyPressedSignal(&e); // expose as a big fat keypress event - - _screenWindow->clearSelection(); - } + // Paste Clipboard by simulating keypress events + QString text = QApplication::clipboard()->text(useXselection ? QClipboard::Selection : + QClipboard::Clipboard); + if (appendReturn) + text.append("\r"); + if ( ! text.isEmpty() ) { + text.replace('\n', '\r'); + QKeyEvent e(QEvent::KeyPress, 0, Qt::NoModifier, text); + emit keyPressedSignal(&e); // expose as a big fat keypress event + + _screenWindow->clearSelection(); + } } void TerminalDisplay::setSelection(const QString& t) { - QApplication::clipboard()->setText(t, QClipboard::Selection); + QApplication::clipboard()->setText(t, QClipboard::Selection); } void TerminalDisplay::copyClipboard() { - if ( !_screenWindow ) - return; + if ( !_screenWindow ) + return; - QString text = _screenWindow->selectedText(_preserveLineBreaks); - if (!text.isEmpty()) - QApplication::clipboard()->setText(text); + QString text = _screenWindow->selectedText(_preserveLineBreaks); + if (!text.isEmpty()) + QApplication::clipboard()->setText(text); } void TerminalDisplay::pasteClipboard() { - emitSelection(false,false); + emitSelection(false,false); } void TerminalDisplay::pasteSelection() { - emitSelection(true,false); + emitSelection(true,false); } /* ------------------------------------------------------------------------- */ @@ -2464,8 +2376,8 @@ void TerminalDisplay::pasteSelection() void TerminalDisplay::setFlowControlWarningEnabled( bool enable ) { _flowControlWarningEnabled = enable; - - // if the dialog is currently visible and the flow control warning has + + // if the dialog is currently visible and the flow control warning has // been disabled then hide the dialog if (!enable) outputSuspended(false); @@ -2476,33 +2388,23 @@ void TerminalDisplay::keyPressEvent( QKeyEvent* event ) bool emitKeyPressSignal = true; // Keyboard-based navigation - if ( event->modifiers() == Qt::ShiftModifier ) - { + if ( event->modifiers() == Qt::ShiftModifier ) { bool update = true; - if ( event->key() == Qt::Key_PageUp ) - { + if ( event->key() == Qt::Key_PageUp ) { _screenWindow->scrollBy( ScreenWindow::ScrollPages , -1 ); - } - else if ( event->key() == Qt::Key_PageDown ) - { + } else if ( event->key() == Qt::Key_PageDown ) { _screenWindow->scrollBy( ScreenWindow::ScrollPages , 1 ); - } - else if ( event->key() == Qt::Key_Up ) - { + } else if ( event->key() == Qt::Key_Up ) { _screenWindow->scrollBy( ScreenWindow::ScrollLines , -1 ); - } - else if ( event->key() == Qt::Key_Down ) - { + } else if ( event->key() == Qt::Key_Down ) { _screenWindow->scrollBy( ScreenWindow::ScrollLines , 1 ); - } - else + } else update = false; - if ( update ) - { + if ( update ) { _screenWindow->setTrackOutput( _screenWindow->atEndOfOutput() ); - + updateLineProperties(); updateImage(); @@ -2512,15 +2414,14 @@ void TerminalDisplay::keyPressEvent( QKeyEvent* event ) } _actSel=0; // Key stroke implies a screen update, so TerminalDisplay won't - // know where the current selection is. + // know where the current selection is. - if (_hasBlinkingCursor) - { - _blinkCursorTimer->start(QApplication::cursorFlashTime() / 2); - if (_cursorBlinking) - blinkCursorEvent(); - else - _cursorBlinking = false; + if (_hasBlinkingCursor) { + _blinkCursorTimer->start(QApplication::cursorFlashTime() / 2); + if (_cursorBlinking) + blinkCursorEvent(); + else + _cursorBlinking = false; } if ( emitKeyPressSignal ) @@ -2536,41 +2437,39 @@ void TerminalDisplay::inputMethodEvent( QInputMethodEvent* event ) _inputMethodData.preeditString = event->preeditString(); update(preeditRect() | _inputMethodData.previousPreeditRect); - + event->accept(); } QVariant TerminalDisplay::inputMethodQuery( Qt::InputMethodQuery query ) const { const QPoint cursorPos = _screenWindow ? _screenWindow->cursorPosition() : QPoint(0,0); - switch ( query ) - { - case Qt::ImMicroFocus: - return imageToWidget(QRect(cursorPos.x(),cursorPos.y(),1,1)); - break; - case Qt::ImFont: - return font(); - break; - case Qt::ImCursorPosition: - // return the cursor position within the current line - return cursorPos.x(); - break; - case Qt::ImSurroundingText: - { - // return the text from the current line - QString lineText; - QTextStream stream(&lineText); - PlainTextDecoder decoder; - decoder.begin(&stream); - decoder.decodeLine(&_image[loc(0,cursorPos.y())],_usedColumns,_lineProperties[cursorPos.y()]); - decoder.end(); - return lineText; - } - break; - case Qt::ImCurrentSelection: - return QString(); - break; - default: - break; + switch ( query ) { + case Qt::ImMicroFocus: + return imageToWidget(QRect(cursorPos.x(),cursorPos.y(),1,1)); + break; + case Qt::ImFont: + return font(); + break; + case Qt::ImCursorPosition: + // return the cursor position within the current line + return cursorPos.x(); + break; + case Qt::ImSurroundingText: { + // return the text from the current line + QString lineText; + QTextStream stream(&lineText); + PlainTextDecoder decoder; + decoder.begin(&stream); + decoder.decodeLine(&_image[loc(0,cursorPos.y())],_usedColumns,_lineProperties[cursorPos.y()]); + decoder.end(); + return lineText; + } + break; + case Qt::ImCurrentSelection: + return QString(); + break; + default: + break; } return QVariant(); @@ -2580,26 +2479,22 @@ bool TerminalDisplay::handleShortcutOverrideEvent(QKeyEvent* keyEvent) { int modifiers = keyEvent->modifiers(); - // When a possible shortcut combination is pressed, + // When a possible shortcut combination is pressed, // emit the overrideShortcutCheck() signal to allow the host // to decide whether the terminal should override it or not. - if (modifiers != Qt::NoModifier) - { + if (modifiers != Qt::NoModifier) { int modifierCount = 0; unsigned int currentModifier = Qt::ShiftModifier; - while (currentModifier <= Qt::KeypadModifier) - { + while (currentModifier <= Qt::KeypadModifier) { if (modifiers & currentModifier) modifierCount++; currentModifier <<= 1; } - if (modifierCount < 2) - { + if (modifierCount < 2) { bool override = false; emit overrideShortcutCheck(keyEvent,override); - if (override) - { + if (override) { keyEvent->accept(); return true; } @@ -2609,16 +2504,15 @@ bool TerminalDisplay::handleShortcutOverrideEvent(QKeyEvent* keyEvent) // Override any of the following shortcuts because // they are needed by the terminal int keyCode = keyEvent->key() | modifiers; - switch ( keyCode ) - { - // list is taken from the QLineEdit::event() code - case Qt::Key_Tab: - case Qt::Key_Delete: - case Qt::Key_Home: - case Qt::Key_End: - case Qt::Key_Backspace: - case Qt::Key_Left: - case Qt::Key_Right: + switch ( keyCode ) { + // list is taken from the QLineEdit::event() code + case Qt::Key_Tab: + case Qt::Key_Delete: + case Qt::Key_Home: + case Qt::Key_End: + case Qt::Key_Backspace: + case Qt::Key_Left: + case Qt::Key_Right: keyEvent->accept(); return true; } @@ -2627,9 +2521,8 @@ bool TerminalDisplay::handleShortcutOverrideEvent(QKeyEvent* keyEvent) bool TerminalDisplay::event(QEvent* event) { - bool eventHandled = false; - switch (event->type()) - { + bool eventHandled = false; + switch (event->type()) { case QEvent::ShortcutOverride: eventHandled = handleShortcutOverrideEvent((QKeyEvent*)event); break; @@ -2639,13 +2532,13 @@ bool TerminalDisplay::event(QEvent* event) break; default: break; - } - return eventHandled ? true : QWidget::event(event); + } + return eventHandled ? true : QWidget::event(event); } void TerminalDisplay::setBellMode(int mode) { - _bellMode=mode; + _bellMode=mode; } void TerminalDisplay::enableBell() @@ -2655,32 +2548,26 @@ void TerminalDisplay::enableBell() void TerminalDisplay::bell(const QString& message) { - if (_bellMode==NoBell) return; + if (_bellMode==NoBell) return; - //limit the rate at which bells can occur - //...mainly for sound effects where rapid bells in sequence - //produce a horrible noise - if ( _allowBell ) - { - _allowBell = false; - QTimer::singleShot(500,this,SLOT(enableBell())); - - if (_bellMode==SystemBeepBell) - { - //! \todo TODO/FIXME: some notifications for Qt4? - //KNotification::beep(); - } - else if (_bellMode==NotifyBell) - { - //! \todo TODO/FIXME: some notifications for Qt4? - //KNotification::event("BellVisible", message,QPixmap(),this); - } - else if (_bellMode==VisualBell) - { - swapColorTable(); - QTimer::singleShot(200,this,SLOT(swapColorTable())); + //limit the rate at which bells can occur + //...mainly for sound effects where rapid bells in sequence + //produce a horrible noise + if ( _allowBell ) { + _allowBell = false; + QTimer::singleShot(500,this,SLOT(enableBell())); + + if (_bellMode==SystemBeepBell) { + //! \todo TODO/FIXME: some notifications for Qt4? + //KNotification::beep(); + } else if (_bellMode==NotifyBell) { + //! \todo TODO/FIXME: some notifications for Qt4? + //KNotification::event("BellVisible", message,QPixmap(),this); + } else if (_bellMode==VisualBell) { + swapColorTable(); + QTimer::singleShot(200,this,SLOT(swapColorTable())); + } } - } } void TerminalDisplay::selectionChanged() @@ -2690,120 +2577,115 @@ void TerminalDisplay::selectionChanged() void TerminalDisplay::swapColorTable() { - ColorEntry color = _colorTable[1]; - _colorTable[1]=_colorTable[0]; - _colorTable[0]= color; - _colorsInverted = !_colorsInverted; - update(); + ColorEntry color = _colorTable[1]; + _colorTable[1]=_colorTable[0]; + _colorTable[0]= color; + _colorsInverted = !_colorsInverted; + update(); } void TerminalDisplay::clearImage() { - // We initialize _image[_imageSize] too. See makeImage() - for (int i = 0; i <= _imageSize; i++) - { - _image[i].character = ' '; - _image[i].foregroundColor = CharacterColor(COLOR_SPACE_DEFAULT, - DEFAULT_FORE_COLOR); - _image[i].backgroundColor = CharacterColor(COLOR_SPACE_DEFAULT, - DEFAULT_BACK_COLOR); - _image[i].rendition = DEFAULT_RENDITION; - } + // We initialize _image[_imageSize] too. See makeImage() + for (int i = 0; i <= _imageSize; i++) { + _image[i].character = ' '; + _image[i].foregroundColor = CharacterColor(COLOR_SPACE_DEFAULT, + DEFAULT_FORE_COLOR); + _image[i].backgroundColor = CharacterColor(COLOR_SPACE_DEFAULT, + DEFAULT_BACK_COLOR); + _image[i].rendition = DEFAULT_RENDITION; + } } void TerminalDisplay::calcGeometry() { - _scrollBar->resize(_scrollBar->sizeHint().width(), contentsRect().height()); - switch(_scrollbarLocation) - { + _scrollBar->resize(_scrollBar->sizeHint().width(), contentsRect().height()); + switch (_scrollbarLocation) { case NoScrollBar : - _leftMargin = DEFAULT_LEFT_MARGIN; - _contentWidth = contentsRect().width() - 2 * DEFAULT_LEFT_MARGIN; - break; + _leftMargin = DEFAULT_LEFT_MARGIN; + _contentWidth = contentsRect().width() - 2 * DEFAULT_LEFT_MARGIN; + break; case ScrollBarLeft : - _leftMargin = DEFAULT_LEFT_MARGIN + _scrollBar->width(); - _contentWidth = contentsRect().width() - 2 * DEFAULT_LEFT_MARGIN - _scrollBar->width(); - _scrollBar->move(contentsRect().topLeft()); - break; + _leftMargin = DEFAULT_LEFT_MARGIN + _scrollBar->width(); + _contentWidth = contentsRect().width() - 2 * DEFAULT_LEFT_MARGIN - _scrollBar->width(); + _scrollBar->move(contentsRect().topLeft()); + break; case ScrollBarRight: - _leftMargin = DEFAULT_LEFT_MARGIN; - _contentWidth = contentsRect().width() - 2 * DEFAULT_LEFT_MARGIN - _scrollBar->width(); - _scrollBar->move(contentsRect().topRight() - QPoint(_scrollBar->width()-1,0)); - break; - } + _leftMargin = DEFAULT_LEFT_MARGIN; + _contentWidth = contentsRect().width() - 2 * DEFAULT_LEFT_MARGIN - _scrollBar->width(); + _scrollBar->move(contentsRect().topRight() - QPoint(_scrollBar->width()-1,0)); + break; + } - _topMargin = DEFAULT_TOP_MARGIN; - _contentHeight = contentsRect().height() - 2 * DEFAULT_TOP_MARGIN + /* mysterious */ 1; - - if (!_isFixedSize) - { - // ensure that display is always at least one column wide - _columns = qMax(1,_contentWidth / _fontWidth); - _usedColumns = qMin(_usedColumns,_columns); - - // ensure that display is always at least one line high - _lines = qMax(1,_contentHeight / _fontHeight); - _usedLines = qMin(_usedLines,_lines); - } + _topMargin = DEFAULT_TOP_MARGIN; + _contentHeight = contentsRect().height() - 2 * DEFAULT_TOP_MARGIN + /* mysterious */ 1; + + if (!_isFixedSize) { + // ensure that display is always at least one column wide + _columns = qMax(1,_contentWidth / _fontWidth); + _usedColumns = qMin(_usedColumns,_columns); + + // ensure that display is always at least one line high + _lines = qMax(1,_contentHeight / _fontHeight); + _usedLines = qMin(_usedLines,_lines); + } } void TerminalDisplay::makeImage() { - calcGeometry(); + calcGeometry(); - // confirm that array will be of non-zero size, since the painting code - // assumes a non-zero array length - Q_ASSERT( _lines > 0 && _columns > 0 ); - Q_ASSERT( _usedLines <= _lines && _usedColumns <= _columns ); + // confirm that array will be of non-zero size, since the painting code + // assumes a non-zero array length + Q_ASSERT( _lines > 0 && _columns > 0 ); + Q_ASSERT( _usedLines <= _lines && _usedColumns <= _columns ); - _imageSize=_lines*_columns; - - // We over-commit one character so that we can be more relaxed in dealing with - // certain boundary conditions: _image[_imageSize] is a valid but unused position - _image = new Character[_imageSize+1]; + _imageSize=_lines*_columns; - clearImage(); + // We over-commit one character so that we can be more relaxed in dealing with + // certain boundary conditions: _image[_imageSize] is a valid but unused position + _image = new Character[_imageSize+1]; + + clearImage(); } // calculate the needed size, this must be synced with calcGeometry() void TerminalDisplay::setSize(int columns, int lines) { - int scrollBarWidth = _scrollBar->isHidden() ? 0 : _scrollBar->sizeHint().width(); - int horizontalMargin = 2 * DEFAULT_LEFT_MARGIN; - int verticalMargin = 2 * DEFAULT_TOP_MARGIN; + int scrollBarWidth = _scrollBar->isHidden() ? 0 : _scrollBar->sizeHint().width(); + int horizontalMargin = 2 * DEFAULT_LEFT_MARGIN; + int verticalMargin = 2 * DEFAULT_TOP_MARGIN; - QSize newSize = QSize( horizontalMargin + scrollBarWidth + (columns * _fontWidth) , - verticalMargin + (lines * _fontHeight) ); + QSize newSize = QSize( horizontalMargin + scrollBarWidth + (columns * _fontWidth) , + verticalMargin + (lines * _fontHeight) ); - if ( newSize != size() ) - { - _size = newSize; - updateGeometry(); - } + if ( newSize != size() ) { + _size = newSize; + updateGeometry(); + } } void TerminalDisplay::setFixedSize(int cols, int lins) { - _isFixedSize = true; - - //ensure that display is at least one line by one column in size - _columns = qMax(1,cols); - _lines = qMax(1,lins); - _usedColumns = qMin(_usedColumns,_columns); - _usedLines = qMin(_usedLines,_lines); + _isFixedSize = true; - if (_image) - { - delete[] _image; - makeImage(); - } - setSize(cols, lins); - QWidget::setFixedSize(_size); + //ensure that display is at least one line by one column in size + _columns = qMax(1,cols); + _lines = qMax(1,lins); + _usedColumns = qMin(_usedColumns,_columns); + _usedLines = qMin(_usedLines,_lines); + + if (_image) { + delete[] _image; + makeImage(); + } + setSize(cols, lins); + QWidget::setFixedSize(_size); } QSize TerminalDisplay::sizeHint() const { - return _size; + return _size; } @@ -2815,95 +2697,93 @@ QSize TerminalDisplay::sizeHint() const void TerminalDisplay::dragEnterEvent(QDragEnterEvent* event) { - if (event->mimeData()->hasFormat("text/plain")) - event->acceptProposedAction(); + if (event->mimeData()->hasFormat("text/plain")) + event->acceptProposedAction(); } void TerminalDisplay::dropEvent(QDropEvent* event) { - //KUrl::List urls = KUrl::List::fromMimeData(event->mimeData()); + //KUrl::List urls = KUrl::List::fromMimeData(event->mimeData()); - QString dropText; -/* - if (!urls.isEmpty()) - { - for ( int i = 0 ; i < urls.count() ; i++ ) - { - KUrl url = KIO::NetAccess::mostLocalUrl( urls[i] , 0 ); - QString urlText; + QString dropText; + /* + if (!urls.isEmpty()) + { + for ( int i = 0 ; i < urls.count() ; i++ ) + { + KUrl url = KIO::NetAccess::mostLocalUrl( urls[i] , 0 ); + QString urlText; - if (url.isLocalFile()) - urlText = url.path(); - else - urlText = url.url(); - - // in future it may be useful to be able to insert file names with drag-and-drop - // without quoting them (this only affects paths with spaces in) - urlText = KShell::quoteArg(urlText); - - dropText += urlText; + if (url.isLocalFile()) + urlText = url.path(); + else + urlText = url.url(); - if ( i != urls.count()-1 ) - dropText += ' '; - } - } - else - { - */ + // in future it may be useful to be able to insert file names with drag-and-drop + // without quoting them (this only affects paths with spaces in) + urlText = KShell::quoteArg(urlText); + + dropText += urlText; + + if ( i != urls.count()-1 ) + dropText += ' '; + } + } + else + { + */ dropText = event->mimeData()->text(); - //} + //} - if(event->mimeData()->hasFormat("text/plain")) - { - emit sendStringToEmu(dropText.toLocal8Bit()); - } + if (event->mimeData()->hasFormat("text/plain")) { + emit sendStringToEmu(dropText.toLocal8Bit()); + } } void TerminalDisplay::doDrag() { - dragInfo.state = diDragging; - dragInfo.dragObject = new QDrag(this); - QMimeData *mimeData = new QMimeData; - mimeData->setText(QApplication::clipboard()->text(QClipboard::Selection)); - dragInfo.dragObject->setMimeData(mimeData); - dragInfo.dragObject->start(Qt::CopyAction); - // Don't delete the QTextDrag object. Qt will delete it when it's done with it. + dragInfo.state = diDragging; + dragInfo.dragObject = new QDrag(this); + QMimeData *mimeData = new QMimeData; + mimeData->setText(QApplication::clipboard()->text(QClipboard::Selection)); + dragInfo.dragObject->setMimeData(mimeData); + dragInfo.dragObject->start(Qt::CopyAction); + // Don't delete the QTextDrag object. Qt will delete it when it's done with it. } void TerminalDisplay::outputSuspended(bool suspended) { //create the label when this function is first called - if (!_outputSuspendedLabel) - { - //This label includes a link to an English language website - //describing the 'flow control' (Xon/Xoff) feature found in almost - //all terminal emulators. - //If there isn't a suitable article available in the target language the link - //can simply be removed. - _outputSuspendedLabel = new QLabel( ("Output has been " - "suspended" - " by pressing Ctrl+S." - " Press Ctrl+Q to resume."), - this ); + if (!_outputSuspendedLabel) { + //This label includes a link to an English language website + //describing the 'flow control' (Xon/Xoff) feature found in almost + //all terminal emulators. + //If there isn't a suitable article available in the target language the link + //can simply be removed. + _outputSuspendedLabel = new QLabel( ("Output has been " + "suspended" + " by pressing Ctrl+S." + " Press Ctrl+Q to resume."), + this ); - QPalette palette(_outputSuspendedLabel->palette()); - //KColorScheme::adjustBackground(palette,KColorScheme::NeutralBackground); - _outputSuspendedLabel->setPalette(palette); - _outputSuspendedLabel->setAutoFillBackground(true); - _outputSuspendedLabel->setBackgroundRole(QPalette::Base); - _outputSuspendedLabel->setFont(QApplication::font()); - _outputSuspendedLabel->setContentsMargins(5, 5, 5, 5); + QPalette palette(_outputSuspendedLabel->palette()); + //KColorScheme::adjustBackground(palette,KColorScheme::NeutralBackground); + _outputSuspendedLabel->setPalette(palette); + _outputSuspendedLabel->setAutoFillBackground(true); + _outputSuspendedLabel->setBackgroundRole(QPalette::Base); + _outputSuspendedLabel->setFont(QApplication::font()); + _outputSuspendedLabel->setContentsMargins(5, 5, 5, 5); - //enable activation of "Xon/Xoff" link in label - _outputSuspendedLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse | - Qt::LinksAccessibleByKeyboard); - _outputSuspendedLabel->setOpenExternalLinks(true); - _outputSuspendedLabel->setVisible(false); + //enable activation of "Xon/Xoff" link in label + _outputSuspendedLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse | + Qt::LinksAccessibleByKeyboard); + _outputSuspendedLabel->setOpenExternalLinks(true); + _outputSuspendedLabel->setVisible(false); - _gridLayout->addWidget(_outputSuspendedLabel); - _gridLayout->addItem( new QSpacerItem(0,0,QSizePolicy::Expanding, - QSizePolicy::Expanding), - 1,0); + _gridLayout->addWidget(_outputSuspendedLabel); + _gridLayout->addItem( new QSpacerItem(0,0,QSizePolicy::Expanding, + QSizePolicy::Expanding), + 1,0); } @@ -2912,18 +2792,18 @@ void TerminalDisplay::outputSuspended(bool suspended) uint TerminalDisplay::lineSpacing() const { - return _lineSpacing; + return _lineSpacing; } void TerminalDisplay::setLineSpacing(uint i) { - _lineSpacing = i; - setVTFont(font()); // Trigger an update. + _lineSpacing = i; + setVTFont(font()); // Trigger an update. } AutoScrollHandler::AutoScrollHandler(QWidget* parent) -: QObject(parent) -, _timerId(0) + : QObject(parent) + , _timerId(0) { parent->installEventFilter(this); } @@ -2933,12 +2813,12 @@ void AutoScrollHandler::timerEvent(QTimerEvent* event) return; QMouseEvent mouseEvent( QEvent::MouseMove, - widget()->mapFromGlobal(QCursor::pos()), - Qt::NoButton, - Qt::LeftButton, - Qt::NoModifier); + widget()->mapFromGlobal(QCursor::pos()), + Qt::NoButton, + Qt::LeftButton, + Qt::NoModifier); - QApplication::sendEvent(widget(),&mouseEvent); + QApplication::sendEvent(widget(),&mouseEvent); } bool AutoScrollHandler::eventFilter(QObject* watched,QEvent* event) { @@ -2946,33 +2826,27 @@ bool AutoScrollHandler::eventFilter(QObject* watched,QEvent* event) Q_UNUSED( watched ); QMouseEvent* mouseEvent = (QMouseEvent*)event; - switch (event->type()) - { - case QEvent::MouseMove: - { - bool mouseInWidget = widget()->rect().contains(mouseEvent->pos()); + switch (event->type()) { + case QEvent::MouseMove: { + bool mouseInWidget = widget()->rect().contains(mouseEvent->pos()); - if (mouseInWidget) - { - if (_timerId) - killTimer(_timerId); - _timerId = 0; - } - else - { - if (!_timerId && (mouseEvent->buttons() & Qt::LeftButton)) - _timerId = startTimer(100); - } - break; - } - case QEvent::MouseButtonRelease: - if (_timerId && (mouseEvent->buttons() & ~Qt::LeftButton)) - { + if (mouseInWidget) { + if (_timerId) killTimer(_timerId); - _timerId = 0; - } + _timerId = 0; + } else { + if (!_timerId && (mouseEvent->buttons() & Qt::LeftButton)) + _timerId = startTimer(100); + } break; - default: + } + case QEvent::MouseButtonRelease: + if (_timerId && (mouseEvent->buttons() & ~Qt::LeftButton)) { + killTimer(_timerId); + _timerId = 0; + } + break; + default: break; }; diff --git a/lib/TerminalDisplay.h b/lib/TerminalDisplay.h index 69adc95..4d6c0a5 100644 --- a/lib/TerminalDisplay.h +++ b/lib/TerminalDisplay.h @@ -1,7 +1,7 @@ /* Copyright 2007-2008 by Robert Knight Copyright 1997,1998 by Lars Doelle - + Rewritten for QT4 by e_k , Copyright (C)2008 This program is free software; you can redistribute it and/or modify @@ -48,8 +48,7 @@ class QWidget; //class KMenu; -namespace Konsole -{ +namespace Konsole { extern unsigned short vt100_graphics[32]; @@ -59,14 +58,13 @@ 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, + * 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 TerminalDisplay : public QWidget -{ - Q_OBJECT +class TerminalDisplay : public QWidget { + Q_OBJECT public: /** Constructs a new terminal display widget with the specified parent. */ @@ -91,25 +89,24 @@ public: /** Sets the opacity of the terminal display. */ void setOpacity(qreal opacity); - /** + /** * This enum describes the location where the scroll bar is positioned in the display widget. */ - enum ScrollBarPosition - { + enum ScrollBarPosition { /** Do not show the scroll bar. */ - NoScrollBar=0, + NoScrollBar=0, /** Show the scroll bar on the left side of the display. */ - ScrollBarLeft=1, + ScrollBarLeft=1, /** Show the scroll bar on the right side of the display. */ - ScrollBarRight=2 + ScrollBarRight=2 }; - /** + /** * 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(ScrollBarPosition position); - /** + /** * Sets the current position and range of the display's scroll bar. * * @param cursor The position of the scroll bar's thumb. @@ -117,7 +114,7 @@ public: */ void setScroll(int cursor, int lines); - /** + /** * 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). @@ -130,11 +127,11 @@ public: */ 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 + * 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 @@ -143,41 +140,50 @@ public: * 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 filterActions(const QPoint& position); /** Returns true if the cursor is set to blink or false otherwise. */ - bool blinkingCursor() { return _hasBlinkingCursor; } + 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; } + 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. + * the user triple-clicks within the display. */ - enum TripleClickMode - { + 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; } + /** 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; } + TripleClickMode tripleClickMode() { + return _tripleClickMode; + } void setLineSpacing(uint); uint lineSpacing() const; @@ -188,26 +194,25 @@ public: * This enum describes the available shapes for the keyboard cursor. * See setKeyboardCursorShape() */ - enum KeyboardCursorShape - { + enum KeyboardCursorShape { /** A rectangular block which covers the entire area of the cursor character. */ BlockCursor, - /** + /** * A single flat line which occupies the space at the bottom of the cursor * character's area. */ UnderlineCursor, - /** - * An cursor shaped like the capital letter 'I', similar to the IBeam + /** + * An cursor shaped like the capital letter 'I', similar to the IBeam * cursor used in Qt/KDE text editors. */ IBeamCursor }; - /** - * Sets the shape of the keyboard cursor. This is the cursor drawn + /** + * 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 + * In addition the terminal display widget also has a cursor for * the mouse pointer, which can be set using the QWidget::setCursor() * method. * @@ -220,7 +225,7 @@ public: KeyboardCursorShape keyboardCursorShape() const; /** - * Sets the color used to draw the keyboard cursor. + * Sets the color used to draw the keyboard cursor. * * The keyboard cursor defaults to using the foreground color of the character * underneath it. @@ -234,10 +239,10 @@ public: */ 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. + * underneath it. */ QColor keyboardCursorColor() const; @@ -247,7 +252,9 @@ public: * This will depend upon the height of the widget and the current font. * See fontHeight() */ - int lines() { return _lines; } + int lines() { + return _lines; + } /** * Returns the number of characters of text which can be displayed on * each line in the widget. @@ -255,26 +262,32 @@ public: * This will depend upon the width of the widget and the current font. * See fontWidth() */ - int columns() { return _columns; } + 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; } + int fontHeight() { + return _fontHeight; + } /** - * Returns the width of the characters in the display. + * Returns the width of the characters in the display. * This assumes the use of a fixed-width font. */ - int fontWidth() { return _fontWidth; } + int fontWidth() { + return _fontWidth; + } void setSize(int cols, int lins); void setFixedSize(int cols, int lins); - + // reimplemented QSize sizeHint() const; /** - * Sets which characters, in addition to letters and numbers, + * 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. * @@ -285,64 +298,69 @@ public: * 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 + /** + * 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; } + QString wordCharacters() { + return _wordCharacters; + } - /** - * Sets the type of effect used to alert the user when a 'bell' occurs in the + /** + * 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; } + 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 - { + enum BellMode { /** A system beep. */ - SystemBeepBell=0, - /** + 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, + NotifyBell=1, /** A silent, visual bell (eg. inverting the display's colors briefly) */ - VisualBell=2, + VisualBell=2, /** No bell effects */ - NoBell=3 + NoBell=3 }; void setSelection(const QString &t); - /** + /** * 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(); } + 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. + * is larger than the size of the display itself. */ void setVTFont(const QFont& font); @@ -350,51 +368,69 @@ public: * Specified whether anti-aliasing of text in the terminal display * is enabled or not. Defaults to enabled. */ - static void setAntialias( bool antialias ) { _antialiasText = antialias; } - /** + static void setAntialias( bool antialias ) { + _antialiasText = antialias; + } + /** * Returns true if anti-aliasing of text in the terminal is enabled. */ - static bool antialias() { return _antialiasText; } + static bool antialias() { + return _antialiasText; + } /** * Specifies whether characters with intense colors should be rendered * as bold. Defaults to true. */ - void setBoldIntense(bool value) { _boldIntense = value; } + void setBoldIntense(bool value) { + _boldIntense = value; + } /** * Returns true if characters with intense colors are rendered in bold. */ - bool getBoldIntense() { return _boldIntense; } - + bool getBoldIntense() { + return _boldIntense; + } + /** - * Sets whether or not the current height and width of the + * 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; } - /** + 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; } - /** + 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; } + 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; } + void setBidiEnabled(bool set) { + _bidiEnabled=set; + } /** * Returns the status of the BiDi rendering in this widget. */ - bool isBidiEnabled() { return _bidiEnabled; } + bool isBidiEnabled() { + return _bidiEnabled; + } /** * Sets the terminal screen section which is displayed in this widget. @@ -412,21 +448,21 @@ public: 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(); + void updateImage(); /** - * Causes the terminal display to fetch the latest line status flags from the - * associated terminal screen ( see setScreenWindow() ). - */ + * 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 + /** + * Pastes the content of the clipboard into the * display. */ void pasteClipboard(); @@ -436,26 +472,27 @@ public slots: */ 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. + /** + * Returns true if the flow control warning box is enabled. * See outputSuspended() and setFlowControlWarningEnabled() */ - bool flowControlWarningEnabled() const - { return _flowControlWarningEnabled; } + 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); /** @@ -465,7 +502,7 @@ public slots: * 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 + * 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. * @@ -473,28 +510,28 @@ public slots: * or false otherwise. */ void setUsesMouse(bool usesMouse); - + /** See setUsesMouse() */ bool usesMouse() 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() + /** + * 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. + /** + * Sets the text of the display to the specified color. * @see setColorTable(), setBackgroundColor() */ void setForegroundColor(const QColor& color); - + void selectionChanged(); signals: @@ -506,7 +543,7 @@ signals: */ 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 @@ -517,7 +554,7 @@ signals: 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. * @@ -526,9 +563,9 @@ signals: 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 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. * @@ -536,9 +573,9 @@ signals: */ void overrideShortcutCheck(QKeyEvent* keyEvent,bool& override); - void isBusySelecting(bool); - void sendStringToEmu(const char*); - + void isBusySelecting(bool); + void sendStringToEmu(const char*); + //! Signals to inform that the widget get or lost focus void termGetFocus(); void termLostFocus(); @@ -564,7 +601,7 @@ protected: virtual void wheelEvent( QWheelEvent* ); virtual bool focusNextPrevChild( bool next ); - + // drag and drop virtual void dragEnterEvent(QDragEnterEvent* event); virtual void dropEvent(QDropEvent* event); @@ -572,15 +609,15 @@ protected: enum DragState { diNone, diPending, diDragging }; struct _dragInfo { - DragState state; - QPoint start; - QDrag *dragObject; + 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 ' ') + // - A space (returns ' ') // - Part of a word (returns 'a') // - Other characters (returns the input character) QChar charClass(QChar ch) const; @@ -598,7 +635,7 @@ 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(); @@ -614,12 +651,12 @@ private: // divides the part of the display specified by 'rect' into // fragments according to their colors and styles and calls - // drawTextFragment() to draw the fragments + // 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); + 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 @@ -627,13 +664,13 @@ private: 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); + 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); + 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, + void drawLineCharString(QPainter& painter, int x, int y, const QString& str, const Character* attributes); // draws the preedit string for input methods @@ -641,10 +678,10 @@ private: // -- - // maps an area in the character image to an area on the widget + // maps an area in the character image to an area on the widget QRect imageToWidget(const QRect& imageArea) const; - // maps a point on the widget to the position ( ie. line and column ) + // 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; @@ -655,8 +692,8 @@ private: // 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 ) + // 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, @@ -667,7 +704,7 @@ private: void propagateSize(); void updateImageSize(); void makeImage(); - + void paintFilters(QPainter& painter); // returns a region covering all of the areas of the widget which contain @@ -683,7 +720,7 @@ private: bool handleShortcutOverrideEvent(QKeyEvent* event); // the window onto the terminal screen which this display - // is currently showing. + // is currently showing. QPointer _screenWindow; bool _allowBell; @@ -701,19 +738,19 @@ private: 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 + // 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 - + // than 'columns' if the character image provided with setImage() is smaller + // than the maximum image size which can be displayed + int _contentHeight; int _contentWidth; Character* _image; // [lines][columns] - // only the area [usedLines][usedColumns] in the image contains valid data + // only the area [usedLines][usedColumns] in the image contains valid data int _imageSize; QVector _lineProperties; @@ -758,7 +795,7 @@ private: int _dndFileCount; bool _possibleTripleClick; // is set in mouseDoubleClickEvent and deleted - // after QApplication::doubleClickInterval() delay + // after QApplication::doubleClickInterval() delay QLabel* _resizeWidget; @@ -768,14 +805,14 @@ private: //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; - + QLabel* _outputSuspendedLabel; + uint _lineSpacing; bool _colorsInverted; // true during visual bell QSize _size; - + QRgb _blendColor; // list of filters currently applied to the display. used for links and @@ -787,11 +824,10 @@ private: // custom cursor color. if this is invalid then the foreground // color of the character under the cursor is used - QColor _cursorColor; + QColor _cursorColor; - struct InputMethodData - { + struct InputMethodData { QString preeditString; QRect previousPreeditRect; }; @@ -805,15 +841,13 @@ private: static const int DEFAULT_TOP_MARGIN = 1; public: - static void setTransparencyEnabled(bool enable) - { + static void setTransparencyEnabled(bool enable) { HAVE_TRANSPARENCY = enable; } }; -class AutoScrollHandler : public QObject -{ -Q_OBJECT +class AutoScrollHandler : public QObject { + Q_OBJECT public: AutoScrollHandler(QWidget* parent); @@ -821,7 +855,9 @@ protected: virtual void timerEvent(QTimerEvent* event); virtual bool eventFilter(QObject* watched,QEvent* event); private: - QWidget* widget() const { return static_cast(parent()); } + QWidget* widget() const { + return static_cast(parent()); + } int _timerId; }; diff --git a/lib/Vt102Emulation.h b/lib/Vt102Emulation.h index a70f8b1..b04771e 100644 --- a/lib/Vt102Emulation.h +++ b/lib/Vt102Emulation.h @@ -47,8 +47,7 @@ #define MODE_Ansi (MODES_SCREEN+7) #define MODE_total (MODES_SCREEN+8) -namespace Konsole -{ +namespace Konsole { struct DECpar { bool mode[MODE_total]; @@ -74,8 +73,7 @@ struct CharCodes { * sequences. * */ -class Vt102Emulation : public Emulation -{ +class Vt102Emulation : public Emulation { Q_OBJECT public: diff --git a/lib/k3process.cpp b/lib/k3process.cpp index 28bcade..de210d5 100644 --- a/lib/k3process.cpp +++ b/lib/k3process.cpp @@ -74,8 +74,7 @@ // private data // ////////////////// -class K3ProcessPrivate -{ +class K3ProcessPrivate { public: K3ProcessPrivate() : usePty(K3Process::NoCommunication), diff --git a/lib/k3process.h b/lib/k3process.h index 36c796f..80ae181 100644 --- a/lib/k3process.h +++ b/lib/k3process.h @@ -124,8 +124,7 @@ class KPty; * @author Christian Czezatke e9025461@student.tuwien.ac.at * **/ -class K3Process : public QObject -{ +class K3Process : public QObject { Q_OBJECT public: @@ -860,8 +859,7 @@ class K3ShellProcessPrivate; * processes through a shell. * @author Christian Czezatke */ -class K3ShellProcess : public K3Process -{ +class K3ShellProcess : public K3Process { Q_OBJECT public: diff --git a/lib/k3processcontroller.cpp b/lib/k3processcontroller.cpp index 5f69db4..df61a52 100644 --- a/lib/k3processcontroller.cpp +++ b/lib/k3processcontroller.cpp @@ -36,8 +36,7 @@ #include #include -class K3ProcessController::Private -{ +class K3ProcessController::Private { public: Private() : needcheck( false ), diff --git a/lib/k3processcontroller.h b/lib/k3processcontroller.h index f4d467c..f25000b 100644 --- a/lib/k3processcontroller.h +++ b/lib/k3processcontroller.h @@ -36,8 +36,7 @@ * * This class takes care of the actual (UN*X) signal handling. */ -class K3ProcessController : public QObject -{ +class K3ProcessController : public QObject { Q_OBJECT public: diff --git a/lib/kpty.cpp b/lib/kpty.cpp index e4faea5..d1f51ac 100644 --- a/lib/kpty.cpp +++ b/lib/kpty.cpp @@ -26,9 +26,9 @@ #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) -#define HAVE_LOGIN -#define HAVE_LIBUTIL_H -#endif +#define HAVE_LOGIN +#define HAVE_LIBUTIL_H +#endif #ifdef __sgi #define __svr4__ diff --git a/lib/kpty.h b/lib/kpty.h index 999ffd6..094b758 100644 --- a/lib/kpty.h +++ b/lib/kpty.h @@ -32,8 +32,7 @@ struct termios; * Provides primitives for opening & closing a pseudo TTY pair, assigning the * controlling TTY, utmp registration and setting various terminal attributes. */ -class KPty -{ +class KPty { Q_DECLARE_PRIVATE(KPty) public: diff --git a/lib/qtermwidget.cpp b/lib/qtermwidget.cpp index 231244d..8220fb8 100644 --- a/lib/qtermwidget.cpp +++ b/lib/qtermwidget.cpp @@ -53,20 +53,20 @@ Session *TermWidgetImpl::createSession() Session *session = new Session(); session->setTitle(Session::NameRole, "QTermWidget"); - + /* Thats a freaking bad idea!!!! * /bin/bash is not there on every system * better set it to the current $SHELL * Maybe you can also make a list available and then let the widget-owner decide what to use. * By setting it to $SHELL right away we actually make the first filecheck obsolete. * But as iam not sure if you want to do anything else ill just let both checks in and set this to $SHELL anyway. - */ - //session->setProgram("/bin/bash"); - + */ + //session->setProgram("/bin/bash"); + session->setProgram(getenv("SHELL")); - - - + + + QStringList args(""); session->setArguments(args); session->setAutoClose(true); diff --git a/lib/qtermwidget.h b/lib/qtermwidget.h index 5124dec..b24ba41 100644 --- a/lib/qtermwidget.h +++ b/lib/qtermwidget.h @@ -29,8 +29,7 @@ enum COLOR_SCHEME { COLOR_SCHEME_WHITE_ON_BLACK = 1, COLOR_SCHEME_BLACK_ON_LIGHT_YELLOW }; -class QTermWidget : public QWidget -{ +class QTermWidget : public QWidget { Q_OBJECT public: