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

Konsole

CharacterColor.h

Go to the documentation of this file.
00001 /*
00002     This file is part of Konsole, KDE's terminal.
00003     
00004     Copyright (C) 2007 by Robert Knight <robertknight@gmail.com>
00005     Copyright (C) 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00020     02110-1301  USA.
00021 */
00022 
00023 #ifndef CHARACTERCOLOR_H
00024 #define CHARACTERCOLOR_H
00025 
00026 // Qt
00027 #include <QtGui/QColor>
00028 
00029 namespace Konsole
00030 {
00031 
00045 class ColorEntry
00046 {
00047 public:
00055   ColorEntry(QColor c, bool tr, bool b) : color(c), transparent(tr), bold(b) {}
00056 
00061   ColorEntry() : transparent(false), bold(false) {} 
00062  
00066   void operator=(const ColorEntry& rhs) 
00067   { 
00068        color = rhs.color; 
00069        transparent = rhs.transparent; 
00070        bold = rhs.bold; 
00071   }
00072 
00074   QColor color;
00075 
00080   bool   transparent;
00085   bool   bold;        
00086 };
00087 
00088 
00089 // Attributed Character Representations ///////////////////////////////
00090 
00091 // Colors
00092 
00093 #define BASE_COLORS   (2+8)
00094 #define INTENSITIES   2
00095 #define TABLE_COLORS  (INTENSITIES*BASE_COLORS)
00096 
00097 #define DEFAULT_FORE_COLOR 0
00098 #define DEFAULT_BACK_COLOR 1
00099 
00100 //a standard set of colors using black text on a white background.
00101 //defined in TerminalDisplay.cpp
00102 
00103 static const ColorEntry base_color_table[TABLE_COLORS] =
00104 // The following are almost IBM standard color codes, with some slight
00105 // gamma correction for the dim colors to compensate for bright X screens.
00106 // It contains the 8 ansiterm/xterm colors in 2 intensities.
00107 {
00108   // Fixme: could add faint colors here, also.
00109   // normal
00110   ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback
00111   ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red
00112   ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow
00113   ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta
00114   ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White
00115   // intensiv
00116   ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ),
00117   ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ),
00118   ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ),
00119   ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0xFF), 0, 0 ),
00120   ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 )
00121 };
00122 
00123 
00124 /* CharacterColor is a union of the various color spaces.
00125 
00126    Assignment is as follows:
00127 
00128    Type  - Space        - Values
00129 
00130    0     - Undefined   - u:  0,      v:0        w:0
00131    1     - Default     - u:  0..1    v:intense  w:0
00132    2     - System      - u:  0..7    v:intense  w:0
00133    3     - Index(256)  - u: 16..255  v:0        w:0
00134    4     - RGB         - u:  0..255  v:0..256   w:0..256
00135 
00136    Default colour space has two separate colours, namely
00137    default foreground and default background colour.
00138 */
00139 
00140 #define COLOR_SPACE_UNDEFINED   0
00141 #define COLOR_SPACE_DEFAULT     1
00142 #define COLOR_SPACE_SYSTEM      2
00143 #define COLOR_SPACE_256         3
00144 #define COLOR_SPACE_RGB         4
00145 
00149 class CharacterColor
00150 {
00151     friend class Character;
00152 
00153 public:
00155   CharacterColor() 
00156       : _colorSpace(COLOR_SPACE_UNDEFINED), 
00157         _u(0), 
00158         _v(0), 
00159         _w(0) 
00160   {}
00161 
00172   CharacterColor(quint8 colorSpace, int co) 
00173       : _colorSpace(colorSpace), 
00174         _u(0), 
00175         _v(0), 
00176         _w(0)
00177   {
00178     switch (colorSpace)
00179     {
00180         case COLOR_SPACE_DEFAULT:
00181             _u = co & 1;
00182             break;
00183         case COLOR_SPACE_SYSTEM:
00184             _u = co & 7;
00185             _v = (co >> 3) & 1;
00186             break;
00187         case COLOR_SPACE_256:  
00188             _u = co & 255;
00189             break;
00190         case COLOR_SPACE_RGB:
00191             _u = co >> 16;
00192             _v = co >> 8;
00193             _w = co;
00194             break;
00195         default:
00196             _colorSpace = COLOR_SPACE_UNDEFINED;
00197     }
00198   }
00199 
00203   bool isValid() 
00204   {
00205         return _colorSpace != COLOR_SPACE_UNDEFINED;
00206   }
00207     
00215   void toggleIntensive();
00216 
00223   QColor color(const ColorEntry* palette) const;
00224  
00229   friend bool operator == (const CharacterColor& a, const CharacterColor& b);
00234   friend bool operator != (const CharacterColor& a, const CharacterColor& b);
00235 
00236 private:
00237   quint8 _colorSpace;
00238 
00239   // bytes storing the character color 
00240   quint8 _u; 
00241   quint8 _v; 
00242   quint8 _w; 
00243 };
00244 
00245 inline bool operator == (const CharacterColor& a, const CharacterColor& b)
00246 { 
00247   return *reinterpret_cast<const quint32*>(&a._colorSpace) == 
00248          *reinterpret_cast<const quint32*>(&b._colorSpace);
00249 }
00250 
00251 inline bool operator != (const CharacterColor& a, const CharacterColor& b)
00252 {
00253   return *reinterpret_cast<const quint32*>(&a._colorSpace) != 
00254          *reinterpret_cast<const quint32*>(&b._colorSpace);
00255 }
00256 
00257 inline const QColor color256(quint8 u, const ColorEntry* base)
00258 {
00259   //   0.. 16: system colors
00260   if (u <   8) return base[u+2            ].color; u -= 8;
00261   if (u <   8) return base[u+2+BASE_COLORS].color; u -= 8;
00262 
00263   //  16..231: 6x6x6 rgb color cube
00264   if (u < 216) return QColor(255*((u/36)%6)/5,
00265                              255*((u/ 6)%6)/5,
00266                              255*((u/ 1)%6)/5); u -= 216;
00267   
00268   // 232..255: gray, leaving out black and white
00269   int gray = u*10+8; return QColor(gray,gray,gray);
00270 }
00271 
00272 inline QColor CharacterColor::color(const ColorEntry* base) const
00273 {
00274   switch (_colorSpace)
00275   {
00276     case COLOR_SPACE_DEFAULT: return base[_u+0+(_v?BASE_COLORS:0)].color;
00277     case COLOR_SPACE_SYSTEM: return base[_u+2+(_v?BASE_COLORS:0)].color;
00278     case COLOR_SPACE_256: return color256(_u,base);
00279     case COLOR_SPACE_RGB: return QColor(_u,_v,_w);
00280     case COLOR_SPACE_UNDEFINED: return QColor();
00281   }
00282 
00283   Q_ASSERT(false); // invalid color space
00284 
00285   return QColor();
00286 }
00287 
00288 inline void CharacterColor::toggleIntensive()
00289 {
00290   if (_colorSpace == COLOR_SPACE_SYSTEM || _colorSpace == COLOR_SPACE_DEFAULT)
00291   {
00292     _v = !_v;
00293   }
00294 }
00295 
00296 
00297 }
00298 
00299 #endif // CHARACTERCOLOR_H
00300 

Konsole

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

API Reference

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