• Skip to content
  • Skip to link menu
KDE 4.1 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 2007-2008 by Robert Knight <robertknight@gmail.com>
00005     Copyright 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 #include <kdemacros.h>
00030 
00031 namespace Konsole
00032 {
00033 
00047 class ColorEntry
00048 {
00049 public:
00057   ColorEntry(QColor c, bool tr, bool b) : color(c), transparent(tr), bold(b) {}
00058 
00063   ColorEntry() : transparent(false), bold(false) {} 
00064  
00068   void operator=(const ColorEntry& rhs) 
00069   { 
00070        color = rhs.color; 
00071        transparent = rhs.transparent; 
00072        bold = rhs.bold; 
00073   }
00074 
00076   QColor color;
00077 
00082   bool   transparent;
00087   bool   bold;        
00088 };
00089 
00090 
00091 // Attributed Character Representations ///////////////////////////////
00092 
00093 // Colors
00094 
00095 #define BASE_COLORS   (2+8)
00096 #define INTENSITIES   2
00097 #define TABLE_COLORS  (INTENSITIES*BASE_COLORS)
00098 
00099 #define DEFAULT_FORE_COLOR 0
00100 #define DEFAULT_BACK_COLOR 1
00101 
00102 //a standard set of colors using black text on a white background.
00103 //defined in TerminalDisplay.cpp
00104 
00105 extern const ColorEntry base_color_table[TABLE_COLORS] KDE_NO_EXPORT;
00106 
00107 /* CharacterColor is a union of the various color spaces.
00108 
00109    Assignment is as follows:
00110 
00111    Type  - Space        - Values
00112 
00113    0     - Undefined   - u:  0,      v:0        w:0
00114    1     - Default     - u:  0..1    v:intense  w:0
00115    2     - System      - u:  0..7    v:intense  w:0
00116    3     - Index(256)  - u: 16..255  v:0        w:0
00117    4     - RGB         - u:  0..255  v:0..256   w:0..256
00118 
00119    Default colour space has two separate colours, namely
00120    default foreground and default background colour.
00121 */
00122 
00123 #define COLOR_SPACE_UNDEFINED   0
00124 #define COLOR_SPACE_DEFAULT     1
00125 #define COLOR_SPACE_SYSTEM      2
00126 #define COLOR_SPACE_256         3
00127 #define COLOR_SPACE_RGB         4
00128 
00132 class CharacterColor
00133 {
00134     friend class Character;
00135 
00136 public:
00138   CharacterColor() 
00139       : _colorSpace(COLOR_SPACE_UNDEFINED), 
00140         _u(0), 
00141         _v(0), 
00142         _w(0) 
00143   {}
00144 
00155   CharacterColor(quint8 colorSpace, int co) 
00156       : _colorSpace(colorSpace), 
00157         _u(0), 
00158         _v(0), 
00159         _w(0)
00160   {
00161     switch (colorSpace)
00162     {
00163         case COLOR_SPACE_DEFAULT:
00164             _u = co & 1;
00165             break;
00166         case COLOR_SPACE_SYSTEM:
00167             _u = co & 7;
00168             _v = (co >> 3) & 1;
00169             break;
00170         case COLOR_SPACE_256:  
00171             _u = co & 255;
00172             break;
00173         case COLOR_SPACE_RGB:
00174             _u = co >> 16;
00175             _v = co >> 8;
00176             _w = co;
00177             break;
00178         default:
00179             _colorSpace = COLOR_SPACE_UNDEFINED;
00180     }
00181   }
00182 
00186   bool isValid() 
00187   {
00188         return _colorSpace != COLOR_SPACE_UNDEFINED;
00189   }
00190     
00198   void toggleIntensive();
00199 
00206   QColor color(const ColorEntry* palette) const;
00207  
00212   friend bool operator == (const CharacterColor& a, const CharacterColor& b);
00217   friend bool operator != (const CharacterColor& a, const CharacterColor& b);
00218 
00219 private:
00220   quint8 _colorSpace;
00221 
00222   // bytes storing the character color 
00223   quint8 _u; 
00224   quint8 _v; 
00225   quint8 _w; 
00226 };
00227 
00228 inline bool operator == (const CharacterColor& a, const CharacterColor& b)
00229 { 
00230     return  a._colorSpace == b._colorSpace &&
00231             a._u == b._u &&
00232             a._v == b._v &&
00233             a._w == b._w;
00234 }
00235 inline bool operator != (const CharacterColor& a, const CharacterColor& b)
00236 {
00237     return !operator==(a,b);
00238 }
00239 
00240 inline const QColor color256(quint8 u, const ColorEntry* base)
00241 {
00242   //   0.. 16: system colors
00243   if (u <   8) return base[u+2            ].color; u -= 8;
00244   if (u <   8) return base[u+2+BASE_COLORS].color; u -= 8;
00245 
00246   //  16..231: 6x6x6 rgb color cube
00247   if (u < 216) return QColor(255*((u/36)%6)/5,
00248                              255*((u/ 6)%6)/5,
00249                              255*((u/ 1)%6)/5); u -= 216;
00250   
00251   // 232..255: gray, leaving out black and white
00252   int gray = u*10+8; return QColor(gray,gray,gray);
00253 }
00254 
00255 inline QColor CharacterColor::color(const ColorEntry* base) const
00256 {
00257   switch (_colorSpace)
00258   {
00259     case COLOR_SPACE_DEFAULT: return base[_u+0+(_v?BASE_COLORS:0)].color;
00260     case COLOR_SPACE_SYSTEM: return base[_u+2+(_v?BASE_COLORS:0)].color;
00261     case COLOR_SPACE_256: return color256(_u,base);
00262     case COLOR_SPACE_RGB: return QColor(_u,_v,_w);
00263     case COLOR_SPACE_UNDEFINED: return QColor();
00264   }
00265 
00266   Q_ASSERT(false); // invalid color space
00267 
00268   return QColor();
00269 }
00270 
00271 inline void CharacterColor::toggleIntensive()
00272 {
00273   if (_colorSpace == COLOR_SPACE_SYSTEM || _colorSpace == COLOR_SPACE_DEFAULT)
00274   {
00275     _v = !_v;
00276   }
00277 }
00278 
00279 
00280 }
00281 
00282 #endif // CHARACTERCOLOR_H
00283 

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