• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Konsole

  • sources
  • kde-4.12
  • applications
  • konsole
  • src
CharacterColor.h
Go to the documentation of this file.
1 /*
2  This file is part of Konsole, KDE's terminal.
3 
4  Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
5  Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  02110-1301 USA.
21 */
22 
23 #ifndef CHARACTERCOLOR_H
24 #define CHARACTERCOLOR_H
25 
26 // Qt
27 #include <QtGui/QColor>
28 
29 namespace Konsole
30 {
40 class ColorEntry
41 {
42 public:
44  enum FontWeight {
46  Bold,
48  Normal,
53  UseCurrentFormat
54  };
55 
62  explicit ColorEntry(QColor c, FontWeight weight = UseCurrentFormat)
63  : color(c), fontWeight(weight) {}
64 
69  ColorEntry() : fontWeight(UseCurrentFormat) {}
70 
74  void operator=(const ColorEntry& rhs) {
75  color = rhs.color;
76  fontWeight = rhs.fontWeight;
77  }
78 
80  QColor color;
81 
86  FontWeight fontWeight;
87 
92  friend bool operator == (const ColorEntry& a, const ColorEntry& b);
97  friend bool operator != (const ColorEntry& a, const ColorEntry& b);
98 
99 };
100 
101 inline bool operator == (const ColorEntry& a, const ColorEntry& b)
102 {
103  return a.color == b.color &&
104  a.fontWeight == b.fontWeight;
105 }
106 
107 inline bool operator != (const ColorEntry& a, const ColorEntry& b)
108 {
109  return !operator==(a, b);
110 }
111 
112 // Attributed Character Representations ///////////////////////////////
113 
114 // Colors
115 
116 #define BASE_COLORS (2+8)
117 #define INTENSITIES 2
118 #define TABLE_COLORS (INTENSITIES*BASE_COLORS)
119 
120 #define DEFAULT_FORE_COLOR 0
121 #define DEFAULT_BACK_COLOR 1
122 
123 /* CharacterColor is a union of the various color spaces.
124 
125  Assignment is as follows:
126 
127  Type - Space - Values
128 
129  0 - Undefined - u: 0, v:0 w:0
130  1 - Default - u: 0..1 v:intense w:0
131  2 - System - u: 0..7 v:intense w:0
132  3 - Index(256) - u: 16..255 v:0 w:0
133  4 - RGB - u: 0..255 v:0..256 w:0..256
134 
135  Default color space has two separate colors, namely
136  default foreground and default background color.
137 */
138 
139 #define COLOR_SPACE_UNDEFINED 0
140 #define COLOR_SPACE_DEFAULT 1
141 #define COLOR_SPACE_SYSTEM 2
142 #define COLOR_SPACE_256 3
143 #define COLOR_SPACE_RGB 4
144 
148 class CharacterColor
149 {
150  friend class Character;
151 
152 public:
154  CharacterColor()
155  : _colorSpace(COLOR_SPACE_UNDEFINED),
156  _u(0),
157  _v(0),
158  _w(0)
159  {}
160 
171  CharacterColor(quint8 colorSpace, int co)
172  : _colorSpace(colorSpace),
173  _u(0),
174  _v(0),
175  _w(0) {
176  switch (colorSpace) {
177  case COLOR_SPACE_DEFAULT:
178  _u = co & 1;
179  break;
180  case COLOR_SPACE_SYSTEM:
181  _u = co & 7;
182  _v = (co >> 3) & 1;
183  break;
184  case COLOR_SPACE_256:
185  _u = co & 255;
186  break;
187  case COLOR_SPACE_RGB:
188  _u = co >> 16;
189  _v = co >> 8;
190  _w = co;
191  break;
192  default:
193  _colorSpace = COLOR_SPACE_UNDEFINED;
194  }
195  }
196 
200  bool isValid() const {
201  return _colorSpace != COLOR_SPACE_UNDEFINED;
202  }
203 
210  void setIntensive();
211 
218  QColor color(const ColorEntry* palette) const;
219 
224  friend bool operator == (const CharacterColor& a, const CharacterColor& b);
229  friend bool operator != (const CharacterColor& a, const CharacterColor& b);
230 
231 private:
232  quint8 _colorSpace;
233 
234  // bytes storing the character color
235  quint8 _u;
236  quint8 _v;
237  quint8 _w;
238 };
239 
240 inline bool operator == (const CharacterColor& a, const CharacterColor& b)
241 {
242  return a._colorSpace == b._colorSpace &&
243  a._u == b._u &&
244  a._v == b._v &&
245  a._w == b._w;
246 }
247 inline bool operator != (const CharacterColor& a, const CharacterColor& b)
248 {
249  return !operator==(a, b);
250 }
251 
252 inline const QColor color256(quint8 u, const ColorEntry* base)
253 {
254  // 0.. 16: system colors
255  if (u < 8) {
256  return base[u + 2].color;
257  }
258  u -= 8;
259  if (u < 8) {
260  return base[u + 2 + BASE_COLORS].color;
261  }
262  u -= 8;
263 
264  // 16..231: 6x6x6 rgb color cube
265  if (u < 216) {
266  return QColor(((u / 36) % 6) ? (40 * ((u / 36) % 6) + 55) : 0,
267  ((u / 6) % 6) ? (40 * ((u / 6) % 6) + 55) : 0,
268  ((u / 1) % 6) ? (40 * ((u / 1) % 6) + 55) : 0);
269  }
270  u -= 216;
271 
272  // 232..255: gray, leaving out black and white
273  int gray = u * 10 + 8;
274 
275  return QColor(gray, gray, gray);
276 }
277 
278 inline QColor CharacterColor::color(const ColorEntry* base) const
279 {
280  switch (_colorSpace) {
281  case COLOR_SPACE_DEFAULT:
282  return base[_u + 0 + (_v ? BASE_COLORS : 0)].color;
283  case COLOR_SPACE_SYSTEM:
284  return base[_u + 2 + (_v ? BASE_COLORS : 0)].color;
285  case COLOR_SPACE_256:
286  return color256(_u, base);
287  case COLOR_SPACE_RGB:
288  return QColor(_u, _v, _w);
289  case COLOR_SPACE_UNDEFINED:
290  return QColor();
291  }
292 
293  Q_ASSERT(false); // invalid color space
294 
295  return QColor();
296 }
297 
298 inline void CharacterColor::setIntensive()
299 {
300  if (_colorSpace == COLOR_SPACE_SYSTEM || _colorSpace == COLOR_SPACE_DEFAULT) {
301  _v = 1;
302  }
303 }
304 }
305 
306 #endif // CHARACTERCOLOR_H
307 
Konsole::ColorEntry::ColorEntry
ColorEntry()
Constructs a new color palette entry with an undefined color, and with the bold flags set to false...
Definition: CharacterColor.h:69
Konsole::ColorEntry::operator=
void operator=(const ColorEntry &rhs)
Sets the color and boldness of this color to those of rhs.
Definition: CharacterColor.h:74
COLOR_SPACE_RGB
#define COLOR_SPACE_RGB
Definition: CharacterColor.h:143
Konsole::CharacterColor::operator==
friend bool operator==(const CharacterColor &a, const CharacterColor &b)
Compares two colors and returns true if they represent the same color value and use the same color sp...
Definition: CharacterColor.h:240
Konsole::CharacterColor::CharacterColor
CharacterColor(quint8 colorSpace, int co)
Constructs a new CharacterColor using the specified colorSpace and with color value co...
Definition: CharacterColor.h:171
COLOR_SPACE_DEFAULT
#define COLOR_SPACE_DEFAULT
Definition: CharacterColor.h:140
Konsole::CharacterColor::setIntensive
void setIntensive()
Set this color as an intensive system color.
Definition: CharacterColor.h:298
Konsole::ColorEntry::Normal
Always draw text in this color with a normal weight.
Definition: CharacterColor.h:48
COLOR_SPACE_256
#define COLOR_SPACE_256
Definition: CharacterColor.h:142
Konsole::CharacterColor::CharacterColor
CharacterColor()
Constructs a new CharacterColor whose color and color space are undefined.
Definition: CharacterColor.h:154
Konsole::ColorEntry::Bold
Always draw text in this color with a bold weight.
Definition: CharacterColor.h:46
Konsole::Character
A single character in the terminal which consists of a unicode character value, foreground and backgr...
Definition: Character.h:77
Konsole::CharacterColor::operator!=
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 ...
Definition: CharacterColor.h:247
Konsole::ColorEntry
An entry in a terminal display's color palette.
Definition: CharacterColor.h:40
BASE_COLORS
#define BASE_COLORS
Definition: CharacterColor.h:116
Konsole::ColorEntry::FontWeight
FontWeight
Specifies the weight to use when drawing text with this color.
Definition: CharacterColor.h:44
Konsole::operator==
bool operator==(const Character &a, const Character &b)
Definition: Character.h:171
Konsole::CharacterColor::color
QColor color(const ColorEntry *palette) const
Returns the color within the specified color palette.
Definition: CharacterColor.h:278
Konsole::CharacterColor
Describes the color of a single character in the terminal.
Definition: CharacterColor.h:148
COLOR_SPACE_UNDEFINED
#define COLOR_SPACE_UNDEFINED
Definition: CharacterColor.h:139
Konsole::operator!=
bool operator!=(const Character &a, const Character &b)
Definition: Character.h:176
Konsole::ColorEntry::operator==
friend bool operator==(const ColorEntry &a, const ColorEntry &b)
Compares two color entries and returns true if they represent the same color and font weight...
Definition: CharacterColor.h:101
Konsole::ColorEntry::ColorEntry
ColorEntry(QColor c, FontWeight weight=UseCurrentFormat)
Constructs a new color palette entry.
Definition: CharacterColor.h:62
Konsole::ColorEntry::color
QColor color
The color value of this entry for display.
Definition: CharacterColor.h:80
Konsole::ColorEntry::UseCurrentFormat
Use the current font weight set by the terminal application.
Definition: CharacterColor.h:53
COLOR_SPACE_SYSTEM
#define COLOR_SPACE_SYSTEM
Definition: CharacterColor.h:141
Konsole::ColorEntry::operator!=
friend bool operator!=(const ColorEntry &a, const ColorEntry &b)
Compares two color entries and returns true if they represent different color and font weight...
Definition: CharacterColor.h:107
Konsole::ColorEntry::fontWeight
FontWeight fontWeight
Specifies the font weight to use when drawing text with this color.
Definition: CharacterColor.h:86
Konsole::CharacterColor::isValid
bool isValid() const
Returns true if this character color entry is valid.
Definition: CharacterColor.h:200
Konsole::color256
const QColor color256(quint8 u, const ColorEntry *base)
Definition: CharacterColor.h:252
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:31:23 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Konsole

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

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Applications
  •   Libraries
  •     libkonq
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal