~ubuntu-branches/ubuntu/precise/konsole/precise-proposed

« back to all changes in this revision

Viewing changes to src/CharacterColor.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-16 13:14:43 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: package-import@ubuntu.com-20111216131443-rhdplbmmuxntat3k
Tags: upstream-4.7.90
ImportĀ upstreamĀ versionĀ 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
    This file is part of Konsole, KDE's terminal.
3
 
    
 
3
 
4
4
    Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
5
5
    Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
6
6
 
26
26
// Qt
27
27
#include <QtGui/QColor>
28
28
 
 
29
// KDE
29
30
#include <kdemacros.h>
30
31
 
31
32
namespace Konsole
32
33
{
33
34
 
34
 
/** 
35
 
 * An entry in a terminal display's color palette. 
 
35
/**
 
36
 * An entry in a terminal display's color palette.
36
37
 *
37
38
 * A color palette is an array of 16 ColorEntry instances which map
38
39
 * system color indexes (from 0 to 15) into actual colors.
39
40
 *
40
41
 * Each entry can be set as bold, in which case any text
41
 
 * drawn using the color should be drawn in bold.  
 
42
 * drawn using the color should be drawn in bold.
42
43
 *
43
44
 * Each entry can also be transparent, in which case the terminal
44
45
 * display should avoid drawing the background for any characters
48
49
{
49
50
public:
50
51
  /** Specifies the weight to use when drawing text with this color. */
51
 
  enum FontWeight 
 
52
  enum FontWeight
52
53
  {
53
54
    /** Always draw text in this color with a bold weight. */
54
55
    Bold,
55
56
    /** Always draw text in this color with a normal weight. */
56
57
    Normal,
57
 
    /** 
58
 
     * Use the current font weight set by the terminal application.  
 
58
    /**
 
59
     * Use the current font weight set by the terminal application.
59
60
     * This is the default behavior.
60
61
     */
61
62
    UseCurrentFormat
62
63
  };
63
64
 
64
 
  /** 
 
65
  /**
65
66
   * Constructs a new color palette entry.
66
67
   *
67
68
   * @param c The color value for this entry.
68
69
   * @param tr Specifies that the color should be transparent when used as a background color.
69
 
   * @param weight Specifies the font weight to use when drawing text with this color. 
 
70
   * @param weight Specifies the font weight to use when drawing text with this color.
70
71
   */
71
72
  ColorEntry(QColor c, bool tr, FontWeight weight = UseCurrentFormat) 
72
73
          : color(c), transparent(tr), fontWeight(weight) {}
76
77
   * with the transparent and bold flags set to false.
77
78
   */ 
78
79
  ColorEntry() : transparent(false), fontWeight(UseCurrentFormat) {} 
79
 
 
 
80
 
80
81
  /**
81
82
   * Sets the color, transparency and boldness of this color to those of @p rhs.
82
83
   */ 
90
91
  /** The color value of this entry for display. */
91
92
  QColor color;
92
93
 
93
 
  /** 
94
 
   * If true character backgrounds using this color should be transparent. 
 
94
  /**
 
95
   * If true character backgrounds using this color should be transparent.
95
96
   * This is not applicable when the color is used to render text.
96
97
   */
97
98
  bool   transparent;
98
99
  /**
99
 
   * Specifies the font weight to use when drawing text with this color. 
 
100
   * Specifies the font weight to use when drawing text with this color.
100
101
   * This is not applicable when the color is used to draw a character's background.
101
102
   */
102
103
  FontWeight fontWeight;        
131
132
   3     - Index(256)  - u: 16..255  v:0        w:0
132
133
   4     - RGB         - u:  0..255  v:0..256   w:0..256
133
134
 
134
 
   Default colour space has two separate colours, namely
135
 
   default foreground and default background colour.
 
135
   Default color space has two separate colors, namely
 
136
   default foreground and default background color.
136
137
*/
137
138
 
138
139
#define COLOR_SPACE_UNDEFINED   0
149
150
    friend class Character;
150
151
 
151
152
public:
152
 
  /** Constructs a new CharacterColor whoose color and color space are undefined. */
 
153
  /** Constructs a new CharacterColor whose color and color space are undefined. */
153
154
  CharacterColor() 
154
155
      : _colorSpace(COLOR_SPACE_UNDEFINED), 
155
156
        _u(0), 
157
158
        _w(0) 
158
159
  {}
159
160
 
160
 
  /** 
161
 
   * Constructs a new CharacterColor using the specified @p colorSpace and with 
 
161
  /**
 
162
   * Constructs a new CharacterColor using the specified @p colorSpace and with
162
163
   * color value @p co
163
164
   *
164
165
   * The meaning of @p co depends on the @p colorSpace used.
195
196
    }
196
197
  }
197
198
 
198
 
  /** 
 
199
  /**
199
200
   * Returns true if this character color entry is valid.
200
201
   */
201
202
  bool isValid() 
202
203
  {
203
204
        return _colorSpace != COLOR_SPACE_UNDEFINED;
204
205
  }
205
 
    
206
 
  /** 
207
 
   * Toggles the value of this color between a normal system color and the corresponding intensive
208
 
   * system color.
209
 
   * 
 
206
 
 
207
  /**
 
208
   * Set this color as an intensive system color.
 
209
   *
210
210
   * This is only applicable if the color is using the COLOR_SPACE_DEFAULT or COLOR_SPACE_SYSTEM
211
211
   * color spaces.
212
212
   */
213
 
  void toggleIntensive();
 
213
  void setIntensive();
214
214
 
215
 
  /** 
 
215
  /**
216
216
   * Returns the color within the specified color @p palette
217
217
   *
218
218
   * The @p palette is only used if this color is one of the 16 system colors, otherwise
219
219
   * it is ignored.
220
220
   */
221
221
  QColor color(const ColorEntry* palette) const;
222
 
 
223
 
  /** 
 
222
 
 
223
  /**
224
224
   * Compares two colors and returns true if they represent the same color value and
225
225
   * use the same color space.
226
226
   */
234
234
private:
235
235
  quint8 _colorSpace;
236
236
 
237
 
  // bytes storing the character color 
 
237
  // bytes storing the character color
238
238
  quint8 _u; 
239
239
  quint8 _v; 
240
240
  quint8 _w; 
262
262
  if (u < 216) return QColor(((u/36)%6) ? (40*((u/36)%6)+55) : 0,
263
263
                             ((u/ 6)%6) ? (40*((u/ 6)%6)+55) : 0,
264
264
                             ((u/ 1)%6) ? (40*((u/ 1)%6)+55) : 0); u -= 216;
265
 
  
 
265
 
266
266
  // 232..255: gray, leaving out black and white
267
267
  int gray = u*10+8; return QColor(gray,gray,gray);
268
268
}
283
283
  return QColor();
284
284
}
285
285
 
286
 
inline void CharacterColor::toggleIntensive()
 
286
inline void CharacterColor::setIntensive()
287
287
{
288
288
  if (_colorSpace == COLOR_SPACE_SYSTEM || _colorSpace == COLOR_SPACE_DEFAULT)
289
289
  {
290
 
    _v = !_v;
 
290
    _v = 1;
291
291
  }
292
292
}
293
293