2
This file is part of Konsole, KDE's terminal.
4
Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
5
Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
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.
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.
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
23
#ifndef CHARACTERCOLOR_H
24
#define CHARACTERCOLOR_H
27
#include <QtGui/QColor>
29
//#include <kdemacros.h>
33
* An entry in a terminal display's color palette.
35
* A color palette is an array of 16 ColorEntry instances which map
36
* system color indexes (from 0 to 15) into actual colors.
38
* Each entry can be set as bold, in which case any text
39
* drawn using the color should be drawn in bold.
41
* Each entry can also be transparent, in which case the terminal
42
* display should avoid drawing the background for any characters
43
* using the entry as a background.
48
/** Specifies the weight to use when drawing text with this color. */
51
/** Always draw text in this color with a bold weight. */
53
/** Always draw text in this color with a normal weight. */
56
* Use the current font weight set by the terminal application.
57
* This is the default behavior.
63
* Constructs a new color palette entry.
65
* @param c The color value for this entry.
66
* @param tr Specifies that the color should be transparent when used as a background color.
67
* @param weight Specifies the font weight to use when drawing text with this color.
69
ColorEntry(QColor c, bool tr, FontWeight weight = UseCurrentFormat)
70
: color(c), transparent(tr), fontWeight(weight) {}
73
* Constructs a new color palette entry with an undefined color, and
74
* with the transparent and bold flags set to false.
76
ColorEntry() : transparent(false), fontWeight(UseCurrentFormat) {}
79
* Sets the color, transparency and boldness of this color to those of @p rhs.
81
void operator=(const ColorEntry& rhs)
84
transparent = rhs.transparent;
85
fontWeight = rhs.fontWeight;
88
/** The color value of this entry for display. */
92
* If true character backgrounds using this color should be transparent.
93
* This is not applicable when the color is used to render text.
97
* Specifies the font weight to use when drawing text with this color.
98
* This is not applicable when the color is used to draw a character's background.
100
FontWeight fontWeight;
104
// Attributed Character Representations ///////////////////////////////
108
#define BASE_COLORS (2+8)
109
#define INTENSITIES 2
110
#define TABLE_COLORS (INTENSITIES*BASE_COLORS)
112
#define DEFAULT_FORE_COLOR 0
113
#define DEFAULT_BACK_COLOR 1
115
//a standard set of colors using black text on a white background.
116
//defined in TerminalDisplay.cpp
118
extern const ColorEntry base_color_table[TABLE_COLORS] KDE_NO_EXPORT;
120
/* CharacterColor is a union of the various color spaces.
122
Assignment is as follows:
124
Type - Space - Values
126
0 - Undefined - u: 0, v:0 w:0
127
1 - Default - u: 0..1 v:intense w:0
128
2 - System - u: 0..7 v:intense w:0
129
3 - Index(256) - u: 16..255 v:0 w:0
130
4 - RGB - u: 0..255 v:0..256 w:0..256
132
Default colour space has two separate colours, namely
133
default foreground and default background colour.
136
#define COLOR_SPACE_UNDEFINED 0
137
#define COLOR_SPACE_DEFAULT 1
138
#define COLOR_SPACE_SYSTEM 2
139
#define COLOR_SPACE_256 3
140
#define COLOR_SPACE_RGB 4
143
* Describes the color of a single character in the terminal.
147
friend class Character;
150
/** Constructs a new CharacterColor whoose color and color space are undefined. */
152
: _colorSpace(COLOR_SPACE_UNDEFINED),
159
* Constructs a new CharacterColor using the specified @p colorSpace and with
162
* The meaning of @p co depends on the @p colorSpace used.
164
* TODO : Document how @p co relates to @p colorSpace
166
* TODO : Add documentation about available color spaces.
168
CharacterColor(quint8 colorSpace, int co)
169
: _colorSpace(colorSpace),
176
case COLOR_SPACE_DEFAULT:
179
case COLOR_SPACE_SYSTEM:
183
case COLOR_SPACE_256:
186
case COLOR_SPACE_RGB:
192
_colorSpace = COLOR_SPACE_UNDEFINED;
197
* Returns true if this character color entry is valid.
201
return _colorSpace != COLOR_SPACE_UNDEFINED;
205
* Toggles the value of this color between a normal system color and the corresponding intensive
208
* This is only applicable if the color is using the COLOR_SPACE_DEFAULT or COLOR_SPACE_SYSTEM
211
void toggleIntensive();
214
* Returns the color within the specified color @p palette
216
* The @p palette is only used if this color is one of the 16 system colors, otherwise
219
QColor color(const ColorEntry* palette) const;
222
* Compares two colors and returns true if they represent the same color value and
223
* use the same color space.
225
friend bool operator == (const CharacterColor& a, const CharacterColor& b);
227
* Compares two colors and returns true if they represent different color values
228
* or use different color spaces.
230
friend bool operator != (const CharacterColor& a, const CharacterColor& b);
235
// bytes storing the character color
241
inline bool operator == (const CharacterColor& a, const CharacterColor& b)
243
return a._colorSpace == b._colorSpace &&
248
inline bool operator != (const CharacterColor& a, const CharacterColor& b)
250
return !operator==(a,b);
253
inline const QColor color256(quint8 u, const ColorEntry* base)
255
// 0.. 16: system colors
256
if (u < 8) return base[u+2 ].color; u -= 8;
257
if (u < 8) return base[u+2+BASE_COLORS].color; u -= 8;
259
// 16..231: 6x6x6 rgb color cube
260
if (u < 216) return QColor(((u/36)%6) ? (40*((u/36)%6)+55) : 0,
261
((u/ 6)%6) ? (40*((u/ 6)%6)+55) : 0,
262
((u/ 1)%6) ? (40*((u/ 1)%6)+55) : 0); u -= 216;
264
// 232..255: gray, leaving out black and white
265
int gray = u*10+8; return QColor(gray,gray,gray);
268
inline QColor CharacterColor::color(const ColorEntry* base) const
272
case COLOR_SPACE_DEFAULT: return base[_u+0+(_v?BASE_COLORS:0)].color;
273
case COLOR_SPACE_SYSTEM: return base[_u+2+(_v?BASE_COLORS:0)].color;
274
case COLOR_SPACE_256: return color256(_u,base);
275
case COLOR_SPACE_RGB: return QColor(_u,_v,_w);
276
case COLOR_SPACE_UNDEFINED: return QColor();
279
Q_ASSERT(false); // invalid color space
284
inline void CharacterColor::toggleIntensive()
286
if (_colorSpace == COLOR_SPACE_SYSTEM || _colorSpace == COLOR_SPACE_DEFAULT)
293
#endif // CHARACTERCOLOR_H