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

Konsole

  • kde-4.14
  • 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 inline bool operator == (const ColorEntry& a, const ColorEntry& b)
101 {
102  return a.color == b.color &&
103  a.fontWeight == b.fontWeight;
104 }
105 
106 inline bool operator != (const ColorEntry& a, const ColorEntry& b)
107 {
108  return !operator==(a, b);
109 }
110 
111 // Attributed Character Representations ///////////////////////////////
112 
113 // Colors
114 
115 #define BASE_COLORS (2+8)
116 #define INTENSITIES 2
117 #define TABLE_COLORS (INTENSITIES*BASE_COLORS)
118 
119 #define DEFAULT_FORE_COLOR 0
120 #define DEFAULT_BACK_COLOR 1
121 
122 /* CharacterColor is a union of the various color spaces.
123 
124  Assignment is as follows:
125 
126  Type - Space - Values
127 
128  0 - Undefined - u: 0, v:0 w:0
129  1 - Default - u: 0..1 v:intense w:0
130  2 - System - u: 0..7 v:intense w:0
131  3 - Index(256) - u: 16..255 v:0 w:0
132  4 - RGB - u: 0..255 v:0..256 w:0..256
133 
134  Default color space has two separate colors, namely
135  default foreground and default background color.
136 */
137 
138 #define COLOR_SPACE_UNDEFINED 0
139 #define COLOR_SPACE_DEFAULT 1
140 #define COLOR_SPACE_SYSTEM 2
141 #define COLOR_SPACE_256 3
142 #define COLOR_SPACE_RGB 4
143 
147 class CharacterColor
148 {
149  friend class Character;
150 
151 public:
153  CharacterColor()
154  : _colorSpace(COLOR_SPACE_UNDEFINED),
155  _u(0),
156  _v(0),
157  _w(0)
158  {}
159 
170  CharacterColor(quint8 colorSpace, int co)
171  : _colorSpace(colorSpace),
172  _u(0),
173  _v(0),
174  _w(0) {
175  switch (colorSpace) {
176  case COLOR_SPACE_DEFAULT:
177  _u = co & 1;
178  break;
179  case COLOR_SPACE_SYSTEM:
180  _u = co & 7;
181  _v = (co >> 3) & 1;
182  break;
183  case COLOR_SPACE_256:
184  _u = co & 255;
185  break;
186  case COLOR_SPACE_RGB:
187  _u = co >> 16;
188  _v = co >> 8;
189  _w = co;
190  break;
191  default:
192  _colorSpace = COLOR_SPACE_UNDEFINED;
193  }
194  }
195 
199  bool isValid() const {
200  return _colorSpace != COLOR_SPACE_UNDEFINED;
201  }
202 
209  void setIntensive();
210 
217  QColor color(const ColorEntry* palette) const;
218 
223  friend bool operator == (const CharacterColor& a, const CharacterColor& b);
228  friend bool operator != (const CharacterColor& a, const CharacterColor& b);
229 
230 private:
231  quint8 _colorSpace;
232 
233  // bytes storing the character color
234  quint8 _u;
235  quint8 _v;
236  quint8 _w;
237 };
238 
239 inline bool operator == (const CharacterColor& a, const CharacterColor& b)
240 {
241  return a._colorSpace == b._colorSpace &&
242  a._u == b._u &&
243  a._v == b._v &&
244  a._w == b._w;
245 }
246 inline bool operator != (const CharacterColor& a, const CharacterColor& b)
247 {
248  return !operator==(a, b);
249 }
250 
251 inline const QColor color256(quint8 u, const ColorEntry* base)
252 {
253  // 0.. 16: system colors
254  if (u < 8) {
255  return base[u + 2].color;
256  }
257  u -= 8;
258  if (u < 8) {
259  return base[u + 2 + BASE_COLORS].color;
260  }
261  u -= 8;
262 
263  // 16..231: 6x6x6 rgb color cube
264  if (u < 216) {
265  return QColor(((u / 36) % 6) ? (40 * ((u / 36) % 6) + 55) : 0,
266  ((u / 6) % 6) ? (40 * ((u / 6) % 6) + 55) : 0,
267  ((u / 1) % 6) ? (40 * ((u / 1) % 6) + 55) : 0);
268  }
269  u -= 216;
270 
271  // 232..255: gray, leaving out black and white
272  int gray = u * 10 + 8;
273 
274  return QColor(gray, gray, gray);
275 }
276 
277 inline QColor CharacterColor::color(const ColorEntry* base) const
278 {
279  switch (_colorSpace) {
280  case COLOR_SPACE_DEFAULT:
281  return base[_u + 0 + (_v ? BASE_COLORS : 0)].color;
282  case COLOR_SPACE_SYSTEM:
283  return base[_u + 2 + (_v ? BASE_COLORS : 0)].color;
284  case COLOR_SPACE_256:
285  return color256(_u, base);
286  case COLOR_SPACE_RGB:
287  return QColor(_u, _v, _w);
288  case COLOR_SPACE_UNDEFINED:
289  return QColor();
290  }
291 
292  Q_ASSERT(false); // invalid color space
293 
294  return QColor();
295 }
296 
297 inline void CharacterColor::setIntensive()
298 {
299  if (_colorSpace == COLOR_SPACE_SYSTEM || _colorSpace == COLOR_SPACE_DEFAULT) {
300  _v = 1;
301  }
302 }
303 }
304 
305 #endif // CHARACTERCOLOR_H
306 
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:142
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:239
Konsole::CharacterColor::CharacterColor
CharacterColor(quint8 colorSpace, int co)
Constructs a new CharacterColor using the specified colorSpace and with color value co...
Definition: CharacterColor.h:170
COLOR_SPACE_DEFAULT
#define COLOR_SPACE_DEFAULT
Definition: CharacterColor.h:139
Konsole::CharacterColor::setIntensive
void setIntensive()
Set this color as an intensive system color.
Definition: CharacterColor.h:297
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:141
Konsole::CharacterColor::CharacterColor
CharacterColor()
Constructs a new CharacterColor whose color and color space are undefined.
Definition: CharacterColor.h:153
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:246
Konsole::ColorEntry
An entry in a terminal display's color palette.
Definition: CharacterColor.h:40
BASE_COLORS
#define BASE_COLORS
Definition: CharacterColor.h:115
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:277
QColor
Konsole::CharacterColor
Describes the color of a single character in the terminal.
Definition: CharacterColor.h:147
COLOR_SPACE_UNDEFINED
#define COLOR_SPACE_UNDEFINED
Definition: CharacterColor.h:138
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:100
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:140
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:106
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:199
Konsole::color256
const QColor color256(quint8 u, const ColorEntry *base)
Definition: CharacterColor.h:251
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:27 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
  • 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