• Skip to content
  • Skip to link menu
KDE 4.2 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:
00051   enum FontWeight 
00052   {
00054     Bold,
00056     Normal,
00061     UseCurrentFormat
00062   };
00063 
00071   ColorEntry(QColor c, bool tr, FontWeight weight = UseCurrentFormat) 
00072           : color(c), transparent(tr), fontWeight(weight) {}
00073 
00078   ColorEntry() : transparent(false), fontWeight(UseCurrentFormat) {} 
00079  
00083   void operator=(const ColorEntry& rhs) 
00084   { 
00085        color = rhs.color; 
00086        transparent = rhs.transparent; 
00087        fontWeight = rhs.fontWeight; 
00088   }
00089 
00091   QColor color;
00092 
00097   bool   transparent;
00102   FontWeight fontWeight;        
00103 };
00104 
00105 
00106 // Attributed Character Representations ///////////////////////////////
00107 
00108 // Colors
00109 
00110 #define BASE_COLORS   (2+8)
00111 #define INTENSITIES   2
00112 #define TABLE_COLORS  (INTENSITIES*BASE_COLORS)
00113 
00114 #define DEFAULT_FORE_COLOR 0
00115 #define DEFAULT_BACK_COLOR 1
00116 
00117 //a standard set of colors using black text on a white background.
00118 //defined in TerminalDisplay.cpp
00119 
00120 extern const ColorEntry base_color_table[TABLE_COLORS] KDE_NO_EXPORT;
00121 
00122 /* CharacterColor is a union of the various color spaces.
00123 
00124    Assignment is as follows:
00125 
00126    Type  - Space        - Values
00127 
00128    0     - Undefined   - u:  0,      v:0        w:0
00129    1     - Default     - u:  0..1    v:intense  w:0
00130    2     - System      - u:  0..7    v:intense  w:0
00131    3     - Index(256)  - u: 16..255  v:0        w:0
00132    4     - RGB         - u:  0..255  v:0..256   w:0..256
00133 
00134    Default colour space has two separate colours, namely
00135    default foreground and default background colour.
00136 */
00137 
00138 #define COLOR_SPACE_UNDEFINED   0
00139 #define COLOR_SPACE_DEFAULT     1
00140 #define COLOR_SPACE_SYSTEM      2
00141 #define COLOR_SPACE_256         3
00142 #define COLOR_SPACE_RGB         4
00143 
00147 class CharacterColor
00148 {
00149     friend class Character;
00150 
00151 public:
00153   CharacterColor() 
00154       : _colorSpace(COLOR_SPACE_UNDEFINED), 
00155         _u(0), 
00156         _v(0), 
00157         _w(0) 
00158   {}
00159 
00170   CharacterColor(quint8 colorSpace, int co) 
00171       : _colorSpace(colorSpace), 
00172         _u(0), 
00173         _v(0), 
00174         _w(0)
00175   {
00176     switch (colorSpace)
00177     {
00178         case COLOR_SPACE_DEFAULT:
00179             _u = co & 1;
00180             break;
00181         case COLOR_SPACE_SYSTEM:
00182             _u = co & 7;
00183             _v = (co >> 3) & 1;
00184             break;
00185         case COLOR_SPACE_256:  
00186             _u = co & 255;
00187             break;
00188         case COLOR_SPACE_RGB:
00189             _u = co >> 16;
00190             _v = co >> 8;
00191             _w = co;
00192             break;
00193         default:
00194             _colorSpace = COLOR_SPACE_UNDEFINED;
00195     }
00196   }
00197 
00201   bool isValid() 
00202   {
00203         return _colorSpace != COLOR_SPACE_UNDEFINED;
00204   }
00205     
00213   void toggleIntensive();
00214 
00221   QColor color(const ColorEntry* palette) const;
00222  
00227   friend bool operator == (const CharacterColor& a, const CharacterColor& b);
00232   friend bool operator != (const CharacterColor& a, const CharacterColor& b);
00233 
00234 private:
00235   quint8 _colorSpace;
00236 
00237   // bytes storing the character color 
00238   quint8 _u; 
00239   quint8 _v; 
00240   quint8 _w; 
00241 };
00242 
00243 inline bool operator == (const CharacterColor& a, const CharacterColor& b)
00244 { 
00245     return     a._colorSpace == b._colorSpace &&
00246             a._u == b._u &&
00247             a._v == b._v &&
00248             a._w == b._w;
00249 }
00250 inline bool operator != (const CharacterColor& a, const CharacterColor& b)
00251 {
00252     return !operator==(a,b);
00253 }
00254 
00255 inline const QColor color256(quint8 u, const ColorEntry* base)
00256 {
00257   //   0.. 16: system colors
00258   if (u <   8) return base[u+2            ].color; u -= 8;
00259   if (u <   8) return base[u+2+BASE_COLORS].color; u -= 8;
00260 
00261   //  16..231: 6x6x6 rgb color cube
00262   if (u < 216) return QColor(((u/36)%6) ? (40*((u/36)%6)+55) : 0,
00263                              ((u/ 6)%6) ? (40*((u/ 6)%6)+55) : 0,
00264                              ((u/ 1)%6) ? (40*((u/ 1)%6)+55) : 0); u -= 216;
00265   
00266   // 232..255: gray, leaving out black and white
00267   int gray = u*10+8; return QColor(gray,gray,gray);
00268 }
00269 
00270 inline QColor CharacterColor::color(const ColorEntry* base) const
00271 {
00272   switch (_colorSpace)
00273   {
00274     case COLOR_SPACE_DEFAULT: return base[_u+0+(_v?BASE_COLORS:0)].color;
00275     case COLOR_SPACE_SYSTEM: return base[_u+2+(_v?BASE_COLORS:0)].color;
00276     case COLOR_SPACE_256: return color256(_u,base);
00277     case COLOR_SPACE_RGB: return QColor(_u,_v,_w);
00278     case COLOR_SPACE_UNDEFINED: return QColor();
00279   }
00280 
00281   Q_ASSERT(false); // invalid color space
00282 
00283   return QColor();
00284 }
00285 
00286 inline void CharacterColor::toggleIntensive()
00287 {
00288   if (_colorSpace == COLOR_SPACE_SYSTEM || _colorSpace == COLOR_SPACE_DEFAULT)
00289   {
00290     _v = !_v;
00291   }
00292 }
00293 
00294 
00295 }
00296 
00297 #endif // CHARACTERCOLOR_H
00298 

Konsole

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

API Reference

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