summaryrefslogtreecommitdiffstats
path: root/doc/html/tqcolor.html
blob: d44963cdb4dbe561896814706ae6681f58f288ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>TQColor Class</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>TQColor Class Reference</h1>

<p>The TQColor class provides colors based on RGB or HSV values.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="tqcolor-h.html">tqcolor.h</a>&gt;</tt>
<p><a href="tqcolor-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn>enum <a href="#Spec-enum"><b>Spec</b></a> { Rgb, Hsv }</li>
<li class=fn><a href="#TQColor"><b>TQColor</b></a> ()</li>
<li class=fn><a href="#TQColor-2"><b>TQColor</b></a> ( int&nbsp;r, int&nbsp;g, int&nbsp;b )</li>
<li class=fn><a href="#TQColor-3"><b>TQColor</b></a> ( int&nbsp;x, int&nbsp;y, int&nbsp;z, Spec&nbsp;colorSpec )</li>
<li class=fn><a href="#TQColor-4"><b>TQColor</b></a> ( TQRgb&nbsp;rgb, uint&nbsp;pixel = 0xffffffff )</li>
<li class=fn><a href="#TQColor-5"><b>TQColor</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;name )</li>
<li class=fn><a href="#TQColor-6"><b>TQColor</b></a> ( const&nbsp;char&nbsp;*&nbsp;name )</li>
<li class=fn><a href="#TQColor-7"><b>TQColor</b></a> ( const&nbsp;TQColor&nbsp;&amp;&nbsp;c )</li>
<li class=fn>TQColor &amp; <a href="#operator-eq"><b>operator=</b></a> ( const&nbsp;TQColor&nbsp;&amp;&nbsp;c )</li>
<li class=fn>bool <a href="#isValid"><b>isValid</b></a> () const</li>
<li class=fn>TQString <a href="#name"><b>name</b></a> () const</li>
<li class=fn>void <a href="#setNamedColor"><b>setNamedColor</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;name )</li>
<li class=fn>TQRgb <a href="#rgb"><b>rgb</b></a> () const</li>
<li class=fn>void <a href="#setRgb"><b>setRgb</b></a> ( int&nbsp;r, int&nbsp;g, int&nbsp;b )</li>
<li class=fn>void <a href="#setRgb-2"><b>setRgb</b></a> ( TQRgb&nbsp;rgb )</li>
<li class=fn>void <a href="#getRgb"><b>getRgb</b></a> ( int&nbsp;*&nbsp;r, int&nbsp;*&nbsp;g, int&nbsp;*&nbsp;b ) const</li>
<li class=fn>void rgb ( int&nbsp;*&nbsp;r, int&nbsp;*&nbsp;g, int&nbsp;*&nbsp;b ) const &nbsp;<em>(obsolete)</em></li>
<li class=fn>int <a href="#red"><b>red</b></a> () const</li>
<li class=fn>int <a href="#green"><b>green</b></a> () const</li>
<li class=fn>int <a href="#blue"><b>blue</b></a> () const</li>
<li class=fn>void <a href="#setHsv"><b>setHsv</b></a> ( int&nbsp;h, int&nbsp;s, int&nbsp;v )</li>
<li class=fn>void <a href="#getHsv"><b>getHsv</b></a> ( int&nbsp;*&nbsp;h, int&nbsp;*&nbsp;s, int&nbsp;*&nbsp;v ) const</li>
<li class=fn>void hsv ( int&nbsp;*&nbsp;h, int&nbsp;*&nbsp;s, int&nbsp;*&nbsp;v ) const &nbsp;<em>(obsolete)</em></li>
<li class=fn>void getHsv ( int&nbsp;&amp;&nbsp;h, int&nbsp;&amp;&nbsp;s, int&nbsp;&amp;&nbsp;v ) const &nbsp;<em>(obsolete)</em></li>
<li class=fn>TQColor <a href="#light"><b>light</b></a> ( int&nbsp;factor = 150 ) const</li>
<li class=fn>TQColor <a href="#dark"><b>dark</b></a> ( int&nbsp;factor = 200 ) const</li>
<li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const&nbsp;TQColor&nbsp;&amp;&nbsp;c ) const</li>
<li class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const&nbsp;TQColor&nbsp;&amp;&nbsp;c ) const</li>
<li class=fn>uint <a href="#alloc"><b>alloc</b></a> ()</li>
<li class=fn>uint <a href="#pixel"><b>pixel</b></a> () const</li>
<li class=fn>uint <a href="#pixel-2"><b>pixel</b></a> ( int&nbsp;screen ) const</li>
</ul>
<h2>Static Public Members</h2>
<ul>
<li class=fn>int <a href="#maxColors"><b>maxColors</b></a> ()</li>
<li class=fn>int <a href="#numBitPlanes"><b>numBitPlanes</b></a> ()</li>
<li class=fn>int <a href="#enterAllocContext"><b>enterAllocContext</b></a> ()</li>
<li class=fn>void <a href="#leaveAllocContext"><b>leaveAllocContext</b></a> ()</li>
<li class=fn>int <a href="#currentAllocContext"><b>currentAllocContext</b></a> ()</li>
<li class=fn>void <a href="#destroyAllocContext"><b>destroyAllocContext</b></a> ( int&nbsp;context )</li>
<li class=fn>void <a href="#initialize"><b>initialize</b></a> ()</li>
<li class=fn>void <a href="#cleanup"><b>cleanup</b></a> ()</li>
<li class=fn>TQStringList <a href="#colorNames"><b>colorNames</b></a> ()</li>
</ul>
<h2>Related Functions</h2>
<ul>
<li class=fn>TQDataStream &amp; <a href="#operator-lt-lt"><b>operator&lt;&lt;</b></a> ( TQDataStream&nbsp;&amp;&nbsp;s, const&nbsp;TQColor&nbsp;&amp;&nbsp;c )</li>
<li class=fn>TQDataStream &amp; <a href="#operator-gt-gt"><b>operator&gt;&gt;</b></a> ( TQDataStream&nbsp;&amp;&nbsp;s, TQColor&nbsp;&amp;&nbsp;c )</li>
<li class=fn>int <a href="#qRed"><b>tqRed</b></a> ( TQRgb&nbsp;rgb )</li>
<li class=fn>int <a href="#qGreen"><b>tqGreen</b></a> ( TQRgb&nbsp;rgb )</li>
<li class=fn>int <a href="#qBlue"><b>tqBlue</b></a> ( TQRgb&nbsp;rgb )</li>
<li class=fn>int <a href="#qAlpha"><b>tqAlpha</b></a> ( TQRgb&nbsp;rgba )</li>
<li class=fn>TQRgb <a href="#qRgb"><b>tqRgb</b></a> ( int&nbsp;r, int&nbsp;g, int&nbsp;b )</li>
<li class=fn>TQRgb <a href="#qRgba"><b>tqRgba</b></a> ( int&nbsp;r, int&nbsp;g, int&nbsp;b, int&nbsp;a )</li>
<li class=fn>int <a href="#qGray"><b>tqGray</b></a> ( int&nbsp;r, int&nbsp;g, int&nbsp;b )</li>
<li class=fn>int <a href="#qGray-2"><b>tqGray</b></a> ( tqRgb&nbsp;rgb )</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>


The TQColor class provides colors based on RGB or HSV values.
<p> 


<p> A color is normally specified in terms of RGB (red, green and blue)
components, but it is also possible to specify HSV (hue, saturation
and value) or set a color name (the names are copied from from the
X11 color database).
<p> In addition to the RGB value, a TQColor also has a pixel value and a
validity. The pixel value is used by the underlying window system
to refer to a color. It can be thought of as an index into the
display hardware's color table.
<p> The validity (<a href="#isValid">isValid</a>()) indicates whether the color is legal at
all. For example, a RGB color with RGB values out of range is
illegal. For performance reasons, TQColor mostly disregards illegal
colors. The result of using an invalid color is unspecified and
will usually be surprising.
<p> There are 19 predefined TQColor objects: <tt>white</tt>, <tt>black</tt>, <tt>red</tt>, <tt>darkRed</tt>, <tt>green</tt>, <tt>darkGreen</tt>, <tt>blue</tt>, <tt>darkBlue</tt>, <tt>cyan</tt>, <tt>darkCyan</tt>, <tt>magenta</tt>, <tt>darkMagenta</tt>, <tt>yellow</tt>, <tt>darkYellow</tt>, <tt>gray</tt>, <tt>darkGray</tt>, <tt>lightGray</tt>, <tt>color0</tt> and <tt>color1</tt>, accessible as members of the TQt namespace (ie. <tt>TQt::red</tt>).
<p> <center><img src="qt-colors.png" alt="TQt Colors"></center> 
<p> The colors <tt>color0</tt> (zero pixel value) and <tt>color1</tt> (non-zero
pixel value) are special colors for drawing in <a href="tqbitmap.html">bitmaps</a>. Painting with <tt>color0</tt> sets the bitmap bits to 0
(transparent, i.e. background), and painting with <tt>color1</tt> sets the
bits to 1 (opaque, i.e. foreground).
<p> The TQColor class has an efficient, dynamic color allocation
strategy. A color is normally allocated the first time it is used
(lazy allocation), that is, whenever the <a href="#pixel">pixel</a>() function is called.
The following steps are taken to allocate a color. If, at any point,
a suitable color is found then the appropriate pixel value is
returned and the subsequent steps are not taken:
<p> <ol type=1>
<li> Is the pixel value valid? If it is, just return it; otherwise,
allocate a pixel value.
<li> Check an internal hash table to see if we allocated an equal RGB
value earlier. If we did, set the corresponding pixel value for the
color and return it.
<li> Try to allocate the RGB value. If we succeed, we get a pixel value
that we save in the internal table with the RGB value.
Return the pixel value.
<li> The color could not be allocated. Find the closest matching
color, save it in the internal table, and return it.
</ol>
<p> A color can be set by passing <a href="#setNamedColor">setNamedColor</a>() an RGB string like
"#112233", or a color name, e.g. "blue". The names are taken from
X11's rgb.txt database but can also be used under Windows. To get
a lighter or darker color use <a href="#light">light</a>() and <a href="#dark">dark</a>() respectively.
Colors can also be set using <a href="#setRgb">setRgb</a>() and <a href="#setHsv">setHsv</a>(). The color
components can be accessed in one go with <a href="#rgb">rgb</a>() and <a href="#hsv">hsv</a>(), or
individually with <a href="#red">red</a>(), <a href="#green">green</a>() and <a href="#blue">blue</a>().
<p> Use <a href="#maxColors">maxColors</a>() and <a href="#numBitPlanes">numBitPlanes</a>() to determine the maximum number
of colors and the number of bit planes supported by the underlying
window system,
<p> If you need to allocate many colors temporarily, for example in an
image viewer application, <a href="#enterAllocContext">enterAllocContext</a>(), <a href="#leaveAllocContext">leaveAllocContext</a>() and
<a href="#destroyAllocContext">destroyAllocContext</a>() will prove useful.
<p> <h3> HSV Colors
</h3>
<a name="1"></a><p> Because many people don't know the HSV color model very well, we'll
cover it briefly here.
<p> The RGB model is hardware-oriented. Its representation is close to
what most monitors show. In contrast, HSV represents color in a way
more suited to the human perception of color. For example, the
relationships "stronger than", "darker than" and "the opposite of"
are easily expressed in HSV but are much harder to express in RGB.
<p> HSV, like RGB, has three components:
<p> <ul>
<p> <li> H, for hue, is either 0-359 if the color is chromatic (not
gray), or meaningless if it is gray. It represents degrees on the
color wheel familiar to most people. Red is 0 (degrees), green is
120 and blue is 240.
<p> <li> S, for saturation, is 0-255, and the bigger it is, the
stronger the color is. Grayish colors have saturation near 0; very
strong colors have saturation near 255.
<p> <li> V, for value, is 0-255 and represents lightness or brightness
of the color. 0 is black; 255 is as far from black as possible.
<p> </ul>
<p> Here are some examples: Pure red is H=0, S=255, V=255. A dark red,
moving slightly towards the magenta, could be H=350 (equivalent to
-10), S=255, V=180. A grayish light red could have H about 0 (say
350-359 or 0-10), S about 50-100, and S=255.
<p> TQt returns a hue value of -1 for achromatic colors. If you pass a
too-big hue value, TQt forces it into range. Hue 360 or 720 is
treated as 0; hue 540 is treated as 180.
<p> <p>See also <a href="tqpalette.html">TQPalette</a>, <a href="tqcolorgroup.html">TQColorGroup</a>, <a href="tqapplication.html#setColorSpec">TQApplication::setColorSpec</a>(), <a href="http://www.poynton.com/ColorFAQ.html">Color FAQ</a>, <a href="appearance.html">Widget Appearance and Style</a>, <a href="graphics.html">Graphics Classes</a>, and <a href="images.html">Image Processing Classes</a>.

<hr><h2>Member Type Documentation</h2>
<h3 class=fn><a name="Spec-enum"></a>TQColor::Spec</h3>

<p> The type of color specified, either RGB or HSV, e.g. in the
<tt>TQColor::TQColor( x, y, z, colorSpec)</tt> constructor.
<ul>
<li><tt>TQColor::Rgb</tt>
<li><tt>TQColor::Hsv</tt>
</ul>
<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="TQColor"></a>TQColor::TQColor ()
</h3>

<p> Constructs an invalid color with the RGB value (0, 0, 0). An
invalid color is a color that is not properly set up for the
underlying window system.
<p> The alpha value of an invalid color is unspecified.
<p> <p>See also <a href="#isValid">isValid</a>().

<h3 class=fn><a name="TQColor-2"></a>TQColor::TQColor ( int&nbsp;r, int&nbsp;g, int&nbsp;b )
</h3>

<p> Constructs a color with the RGB value <em>r</em>, <em>g</em>, <em>b</em>, in the
same way as <a href="#setRgb">setRgb</a>().
<p> The color is left invalid if any or the arguments are illegal.
<p> <p>See also <a href="#setRgb">setRgb</a>().

<h3 class=fn><a name="TQColor-3"></a>TQColor::TQColor ( int&nbsp;x, int&nbsp;y, int&nbsp;z, <a href="tqcolor.html#Spec-enum">Spec</a>&nbsp;colorSpec )
</h3>
Constructs a color with the RGB or HSV value <em>x</em>, <em>y</em>, <em>z</em>.
<p> The arguments are an RGB value if <em>colorSpec</em> is TQColor::Rgb. <em>x</em> (red), <em>y</em> (green), and <em>z</em> (blue). All of them must be in the
range 0-255.
<p> The arguments are an HSV value if <em>colorSpec</em> is TQColor::Hsv. <em>x</em> (hue) must be -1 for achromatic colors and 0-359 for chromatic
colors; <em>y</em> (saturation) and <em>z</em> (value) must both be in the
range 0-255.
<p> <p>See also <a href="#setRgb">setRgb</a>() and <a href="#setHsv">setHsv</a>().

<h3 class=fn><a name="TQColor-4"></a>TQColor::TQColor ( TQRgb&nbsp;rgb, uint&nbsp;pixel = 0xffffffff )
</h3>
Constructs a color with the RGB value <em>rgb</em> and a custom pixel
value <em>pixel</em>.
<p> If <em>pixel</em> == 0xffffffff (the default), then the color uses the
RGB value in a standard way. If <em>pixel</em> is something else, then
the pixel value is set directly to <em>pixel</em>, skipping the normal
allocation procedure.

<h3 class=fn><a name="TQColor-5"></a>TQColor::TQColor ( const&nbsp;<a href="tqstring.html">TQString</a>&nbsp;&amp;&nbsp;name )
</h3>
Constructs a named color in the same way as <a href="#setNamedColor">setNamedColor</a>() using
name <em>name</em>.
<p> The color is left invalid if <em>name</em> cannot be parsed.
<p> <p>See also <a href="#setNamedColor">setNamedColor</a>().

<h3 class=fn><a name="TQColor-6"></a>TQColor::TQColor ( const&nbsp;char&nbsp;*&nbsp;name )
</h3>
Constructs a named color in the same way as <a href="#setNamedColor">setNamedColor</a>() using
name <em>name</em>.
<p> The color is left invalid if <em>name</em> cannot be parsed.
<p> <p>See also <a href="#setNamedColor">setNamedColor</a>().

<h3 class=fn><a name="TQColor-7"></a>TQColor::TQColor ( const&nbsp;<a href="tqcolor.html">TQColor</a>&nbsp;&amp;&nbsp;c )
</h3>
Constructs a color that is a copy of <em>c</em>.

<h3 class=fn>uint <a name="alloc"></a>TQColor::alloc ()
</h3>
Allocates the RGB color and returns the pixel value.
<p> Allocating a color means to obtain a pixel value from the RGB
specification.  The pixel value is an index into the global color
table, but should be considered an arbitrary platform-dependent value.
<p> The <a href="#pixel">pixel</a>() function calls <a href="#alloc">alloc</a>() if necessary, so in general you
don't need to call this function.
<p> <p>See also <a href="#enterAllocContext">enterAllocContext</a>().

<h3 class=fn>int <a name="blue"></a>TQColor::blue () const
</h3>

<p> Returns the B (blue) component of the RGB value.

<h3 class=fn>void <a name="cleanup"></a>TQColor::cleanup ()<tt> [static]</tt>
</h3>
Internal clean up required for TQColor.
This function is called from the <a href="tqapplication.html">TQApplication</a> destructor.
<p> <p>See also <a href="#initialize">initialize</a>().

<h3 class=fn><a href="tqstringlist.html">TQStringList</a> <a name="colorNames"></a>TQColor::colorNames ()<tt> [static]</tt>
</h3>

Returns a <a href="tqstringlist.html">TQStringList</a> containing the color names TQt knows about.

<h3 class=fn>int <a name="currentAllocContext"></a>TQColor::currentAllocContext ()<tt> [static]</tt>
</h3>
Returns the current color allocation context.
<p> The default context is 0.
<p> <p>See also <a href="#enterAllocContext">enterAllocContext</a>() and <a href="#leaveAllocContext">leaveAllocContext</a>().

<h3 class=fn><a href="tqcolor.html">TQColor</a> <a name="dark"></a>TQColor::dark ( int&nbsp;factor = 200 ) const
</h3>
Returns a darker (or lighter) color, but does not change this
object.
<p> Returns a darker color if <em>factor</em> is greater than 100. Setting
<em>factor</em> to 300 returns a color that has one-third the
brightness.
<p> Returns a lighter color if <em>factor</em> is less than 100. We
recommend using lighter() for this purpose. If <em>factor</em> is 0 or
negative, the return value is unspecified.
<p> (This function converts the current RGB color to HSV, divides V by
<em>factor</em> and converts back to RGB.)
<p> <p>See also <a href="#light">light</a>().

<p>Examples: <a href="desktop-example.html#x1725">desktop/desktop.cpp</a> and <a href="themes-example.html#x192">themes/wood.cpp</a>.
<h3 class=fn>void <a name="destroyAllocContext"></a>TQColor::destroyAllocContext ( int&nbsp;context )<tt> [static]</tt>
</h3>
Destroys a color allocation context, <em>context</em>.
<p> This function deallocates all colors that were allocated in the
specified <em>context</em>. If <em>context</em> == -1, it frees up all colors
that the application has allocated. If <em>context</em> == -2, it frees
up all colors that the application has allocated, except those in
the default context.
<p> The function does nothing for true color displays.
<p> <p>See also <a href="#enterAllocContext">enterAllocContext</a>() and <a href="#alloc">alloc</a>().

<p>Example: <a href="showimg-example.html#x1313">showimg/showimg.cpp</a>.
<h3 class=fn>int <a name="enterAllocContext"></a>TQColor::enterAllocContext ()<tt> [static]</tt>
</h3>
Enters a color allocation context and returns a non-zero unique
identifier.
<p> Color allocation contexts are useful for programs that need to
allocate many colors and throw them away later, like image
viewers. The allocation context functions work for true color
displays as well as for colormap displays, except that
<a href="#destroyAllocContext">TQColor::destroyAllocContext</a>() does nothing for true color.
<p> Example:
<pre>
    <a href="tqpixmap.html">TQPixmap</a> loadPixmap( <a href="tqstring.html">TQString</a> fileName )
    {
        static int alloc_context = 0;
        if ( alloc_context )
            TQColor::<a href="#destroyAllocContext">destroyAllocContext</a>( alloc_context );
        alloc_context = TQColor::<a href="#enterAllocContext">enterAllocContext</a>();
        <a href="tqpixmap.html">TQPixmap</a> pm( fileName );
        TQColor::<a href="#leaveAllocContext">leaveAllocContext</a>();
        return pm;
    }
    </pre>
 
<p> The example code loads a pixmap from file. It frees up all colors
that were allocated the last time loadPixmap() was called.
<p> The initial/default context is 0. TQt keeps a list of colors
associated with their allocation contexts. You can call
<a href="#destroyAllocContext">destroyAllocContext</a>() to get rid of all colors that were allocated
in a specific context.
<p> Calling <a href="#enterAllocContext">enterAllocContext</a>() enters an allocation context. The
allocation context lasts until you call <a href="#leaveAllocContext">leaveAllocContext</a>().
TQColor has an internal stack of allocation contexts. Each call to
enterAllocContex() must have a corresponding leaveAllocContext().
<p> <pre>
        // context 0 active
    int c1 = TQColor::<a href="#enterAllocContext">enterAllocContext</a>();    // enter context c1
        // context c1 active
    int c2 = TQColor::<a href="#enterAllocContext">enterAllocContext</a>();    // enter context c2
        // context c2 active
    TQColor::<a href="#leaveAllocContext">leaveAllocContext</a>();             // leave context c2
        // context c1 active
    TQColor::<a href="#leaveAllocContext">leaveAllocContext</a>();             // leave context c1
        // context 0 active
        // Now, free all colors that were allocated in context c2
    TQColor::<a href="#destroyAllocContext">destroyAllocContext</a>( c2 );
    </pre>
 
<p> You may also want to set the application's color specification.
See <a href="tqapplication.html#setColorSpec">TQApplication::setColorSpec</a>() for more information.
<p> <p>See also <a href="#leaveAllocContext">leaveAllocContext</a>(), <a href="#currentAllocContext">currentAllocContext</a>(), <a href="#destroyAllocContext">destroyAllocContext</a>(), and <a href="tqapplication.html#setColorSpec">TQApplication::setColorSpec</a>().

<p>Example: <a href="showimg-example.html#x1314">showimg/showimg.cpp</a>.
<h3 class=fn>void <a name="getHsv"></a>TQColor::getHsv ( int&nbsp;*&nbsp;h, int&nbsp;*&nbsp;s, int&nbsp;*&nbsp;v ) const
</h3>  
<p> Returns the current RGB value as HSV. The contents of the <em>h</em>, <em>s</em> and <em>v</em> pointers are set to the HSV values. If any of the three
pointers are null, the function does nothing.
<p> The hue (which <em>h</em> points to) is set to -1 if the color is
achromatic.
<p> <b>Warning:</b> Colors are stored internally as RGB values, so getHSv()
may return slightly different values to those set by <a href="#setHsv">setHsv</a>().
<p> <p>See also <a href="#setHsv">setHsv</a>() and <a href="#rgb">rgb</a>().

<h3 class=fn>void <a name="getHsv-2"></a>TQColor::getHsv ( int&nbsp;&amp;&nbsp;h, int&nbsp;&amp;&nbsp;s, int&nbsp;&amp;&nbsp;v ) const
</h3>

<b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code.
<p> 
<h3 class=fn>void <a name="getRgb"></a>TQColor::getRgb ( int&nbsp;*&nbsp;r, int&nbsp;*&nbsp;g, int&nbsp;*&nbsp;b ) const
</h3> 
<p> Sets the contents pointed to by <em>r</em>, <em>g</em> and <em>b</em> to the red,
green and blue components of the RGB value respectively. The value
range for a component is 0..255.
<p> <p>See also <a href="#rgb">rgb</a>(), <a href="#setRgb">setRgb</a>(), and <a href="#getHsv">getHsv</a>().

<h3 class=fn>int <a name="green"></a>TQColor::green () const
</h3>

<p> Returns the G (green) component of the RGB value.

<h3 class=fn>void <a name="hsv"></a>TQColor::hsv ( int&nbsp;*&nbsp;h, int&nbsp;*&nbsp;s, int&nbsp;*&nbsp;v ) const
</h3> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code.
Use <a href="#getHsv">getHsv</a>() instead.

<p>Example: <a href="themes-example.html#x272">themes/metal.cpp</a>.
<h3 class=fn>void <a name="initialize"></a>TQColor::initialize ()<tt> [static]</tt>
</h3>
Internal initialization required for TQColor.
This function is called from the <a href="tqapplication.html">TQApplication</a> constructor.
<p> <p>See also <a href="#cleanup">cleanup</a>().

<h3 class=fn>bool <a name="isValid"></a>TQColor::isValid () const
</h3>

<p> Returns FALSE if the color is invalid, i.e. it was constructed using the
default constructor; otherwise returns TRUE.

<p>Examples: <a href="tutorial2-03.html#x2550">chart/element.cpp</a>, <a href="tutorial2-08.html#x2599">chart/setdataform.cpp</a>, and <a href="scribble-example.html#x908">scribble/scribble.cpp</a>.
<h3 class=fn>void <a name="leaveAllocContext"></a>TQColor::leaveAllocContext ()<tt> [static]</tt>
</h3>
Leaves a color allocation context.
<p> See <a href="#enterAllocContext">enterAllocContext</a>() for a detailed explanation.
<p> <p>See also <a href="#enterAllocContext">enterAllocContext</a>() and <a href="#currentAllocContext">currentAllocContext</a>().

<p>Example: <a href="showimg-example.html#x1315">showimg/showimg.cpp</a>.
<h3 class=fn><a href="tqcolor.html">TQColor</a> <a name="light"></a>TQColor::light ( int&nbsp;factor = 150 ) const
</h3>
Returns a lighter (or darker) color, but does not change this
object.
<p> Returns a lighter color if <em>factor</em> is greater than 100. Setting
<em>factor</em> to 150 returns a color that is 50% brighter.
<p> Returns a darker color if <em>factor</em> is less than 100. We recommend
using <a href="#dark">dark</a>() for this purpose. If <em>factor</em> is 0 or negative, the
return value is unspecified.
<p> (This function converts the current RGB color to HSV, multiplies V
by <em>factor</em>, and converts the result back to RGB.)
<p> <p>See also <a href="#dark">dark</a>().

<p>Examples: <a href="desktop-example.html#x1726">desktop/desktop.cpp</a> and <a href="themes-example.html#x193">themes/wood.cpp</a>.
<h3 class=fn>int <a name="maxColors"></a>TQColor::maxColors ()<tt> [static]</tt>
</h3>
Returns the maximum number of colors supported by the underlying
window system if the window system uses a palette.
<p> Otherwise returns -1. Use <a href="#numBitPlanes">numBitPlanes</a>() to calculate the available
colors in that case.

<h3 class=fn><a href="tqstring.html">TQString</a> <a name="name"></a>TQColor::name () const
</h3>
Returns the name of the color in the format "#RRGGBB", i.e. a "#"
character followed by three two-digit hexadecimal numbers.
<p> <p>See also <a href="#setNamedColor">setNamedColor</a>().

<p>Example: <a href="tutorial2-08.html#x2600">chart/setdataform.cpp</a>.
<h3 class=fn>int <a name="numBitPlanes"></a>TQColor::numBitPlanes ()<tt> [static]</tt>
</h3>
Returns the number of color bit planes for the underlying window
system.
<p> The returned value is equal to the default pixmap depth.
<p> <p>See also <a href="tqpixmap.html#defaultDepth">TQPixmap::defaultDepth</a>().

<h3 class=fn>bool <a name="operator!-eq"></a>TQColor::operator!= ( const&nbsp;<a href="tqcolor.html">TQColor</a>&nbsp;&amp;&nbsp;c ) const
</h3>

Returns TRUE if this color has a different RGB value from <em>c</em>;
otherwise returns FALSE.

<h3 class=fn><a href="tqcolor.html">TQColor</a>&nbsp;&amp; <a name="operator-eq"></a>TQColor::operator= ( const&nbsp;<a href="tqcolor.html">TQColor</a>&nbsp;&amp;&nbsp;c )
</h3>
Assigns a copy of the color <em>c</em> and returns a reference to this
color.

<h3 class=fn>bool <a name="operator-eq-eq"></a>TQColor::operator== ( const&nbsp;<a href="tqcolor.html">TQColor</a>&nbsp;&amp;&nbsp;c ) const
</h3>

<p> Returns TRUE if this color has the same RGB value as <em>c</em>;
otherwise returns FALSE.

<h3 class=fn>uint <a name="pixel"></a>TQColor::pixel () const
</h3>
Returns the pixel value.
<p> This value is used by the underlying window system to refer to a
color. It can be thought of as an index into the display
hardware's color table, but the value is an arbitrary 32-bit
value.
<p> <p>See also <a href="#alloc">alloc</a>().

<h3 class=fn>uint <a name="pixel-2"></a>TQColor::pixel ( int&nbsp;screen ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns the pixel value for screen <em>screen</em>.
<p> This value is used by the underlying window system to refer to a color.
It can be thought of as an index into the display hardware's color table,
but the value is an arbitrary 32-bit value.
<p> <p>See also <a href="#alloc">alloc</a>().

<h3 class=fn>int <a name="red"></a>TQColor::red () const
</h3>

<p> Returns the R (red) component of the RGB value.

<h3 class=fn>TQRgb <a name="rgb"></a>TQColor::rgb () const
</h3>

<p> Returns the RGB value.
<p> The return type <em>TQRgb</em> is equivalent to <tt>unsigned</tt> <tt>int</tt>.
<p> For an invalid color, the alpha value of the returned color is
unspecified.
<p> <p>See also <a href="#setRgb">setRgb</a>(), <a href="#hsv">hsv</a>(), <a href="#qRed">tqRed</a>(), <a href="#qBlue">tqBlue</a>(), <a href="#qGreen">tqGreen</a>(), and <a href="#isValid">isValid</a>().

<h3 class=fn>void <a name="rgb-2"></a>TQColor::rgb ( int&nbsp;*&nbsp;r, int&nbsp;*&nbsp;g, int&nbsp;*&nbsp;b ) const
</h3> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code.
Use <a href="#getRgb">getRgb</a>() instead 
<h3 class=fn>void <a name="setHsv"></a>TQColor::setHsv ( int&nbsp;h, int&nbsp;s, int&nbsp;v )
</h3>
Sets a HSV color value. <em>h</em> is the hue, <em>s</em> is the saturation
and <em>v</em> is the value of the HSV color.
<p> If <em>s</em> or <em>v</em> are not in the range 0-255, or <em>h</em> is < -1, the
color is not changed.
<p> <b>Warning:</b> Colors are stored internally as RGB values, so getHSv()
may return slightly different values to those set by <a href="#setHsv">setHsv</a>().
<p> <p>See also <a href="#hsv">hsv</a>() and <a href="#setRgb">setRgb</a>().

<p>Examples: <a href="drawdemo-example.html#x1063">drawdemo/drawdemo.cpp</a> and <a href="progress-example.html#x66">progress/progress.cpp</a>.
<h3 class=fn>void <a name="setNamedColor"></a>TQColor::setNamedColor ( const&nbsp;<a href="tqstring.html">TQString</a>&nbsp;&amp;&nbsp;name )
</h3>
Sets the RGB value to <em>name</em>, which may be in one of these
formats:
<ul>
<li> #RGB (each of R, G and B is a single hex digit)
<li> #RRGGBB
<li> #RRRGGGBBB
<li> #RRRRGGGGBBBB
<li> A name from the X color database (rgb.txt) (e.g.
"steelblue" or "gainsboro"). These color names also work
under Windows.
</ul>
<p> The color is invalid if <em>name</em> cannot be parsed.

<h3 class=fn>void <a name="setRgb"></a>TQColor::setRgb ( int&nbsp;r, int&nbsp;g, int&nbsp;b )
</h3>
Sets the RGB value to <em>r</em>, <em>g</em>, <em>b</em>. The arguments, <em>r</em>, <em>g</em>
and <em>b</em> must all be in the range 0..255. If any of them are
outside the legal range, the color is not changed.
<p> <p>See also <a href="#rgb">rgb</a>() and <a href="#setHsv">setHsv</a>().

<h3 class=fn>void <a name="setRgb-2"></a>TQColor::setRgb ( TQRgb&nbsp;rgb )
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Sets the RGB value to <em>rgb</em>.
<p> The type <em>TQRgb</em> is equivalent to <tt>unsigned</tt> <tt>int</tt>.
<p> <p>See also <a href="#rgb">rgb</a>() and <a href="#setHsv">setHsv</a>().

<hr><h2>Related Functions</h2>
<h3 class=fn><a href="tqdatastream.html">TQDataStream</a>&nbsp;&amp; <a name="operator-lt-lt"></a>operator&lt;&lt; ( <a href="tqdatastream.html">TQDataStream</a>&nbsp;&amp;&nbsp;s, const&nbsp;<a href="tqcolor.html">TQColor</a>&nbsp;&amp;&nbsp;c )
</h3>

Writes a color object, <em>c</em> to the stream, <em>s</em>.
<p> <p>See also <a href="datastreamformat.html">Format of the TQDataStream operators</a>.

<h3 class=fn><a href="tqdatastream.html">TQDataStream</a>&nbsp;&amp; <a name="operator-gt-gt"></a>operator&gt;&gt; ( <a href="tqdatastream.html">TQDataStream</a>&nbsp;&amp;&nbsp;s, <a href="tqcolor.html">TQColor</a>&nbsp;&amp;&nbsp;c )
</h3>

Reads a color object, <em>c</em>, from the stream, <em>s</em>.
<p> <p>See also <a href="datastreamformat.html">Format of the TQDataStream operators</a>.

<h3 class=fn>int <a name="qAlpha"></a>tqAlpha ( TQRgb&nbsp;rgba )
</h3>


<p> Returns the alpha component of the RGBA quadruplet <em>rgba</em>.

<h3 class=fn>int <a name="qBlue"></a>tqBlue ( TQRgb&nbsp;rgb )
</h3>


<p> Returns the blue component of the RGB triplet <em>rgb</em>.
<p>See also <a href="#qRgb">tqRgb</a>() and <a href="#blue">TQColor::blue</a>().

<h3 class=fn>int <a name="qGray"></a>tqGray ( int&nbsp;r, int&nbsp;g, int&nbsp;b )
</h3>


<p> Returns a gray value 0..255 from the (<em>r</em>, <em>g</em>, <em>b</em>) triplet.
<p> The gray value is calculated using the formula (r*11 + g*16 +
b*5)/32.

<h3 class=fn>int <a name="qGray-2"></a>tqGray ( tqRgb&nbsp;rgb )
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> 
<p> Returns a gray value 0..255 from the given <em>rgb</em> colour.

<h3 class=fn>int <a name="qGreen"></a>tqGreen ( TQRgb&nbsp;rgb )
</h3>


<p> Returns the green component of the RGB triplet <em>rgb</em>.
<p>See also <a href="#qRgb">tqRgb</a>() and <a href="#green">TQColor::green</a>().

<h3 class=fn>int <a name="qRed"></a>tqRed ( TQRgb&nbsp;rgb )
</h3>


<p> Returns the red component of the RGB triplet <em>rgb</em>.
<p>See also <a href="#qRgb">tqRgb</a>() and <a href="#red">TQColor::red</a>().

<h3 class=fn>TQRgb <a name="qRgb"></a>tqRgb ( int&nbsp;r, int&nbsp;g, int&nbsp;b )
</h3>


<p> Returns the RGB triplet <em>(r,g,b)</em>.
<p> The return type TQRgb is equivalent to <tt>unsigned</tt> <tt>int</tt>.
<p> <p>See also <a href="#qRgba">tqRgba</a>(), <a href="#qRed">tqRed</a>(), <a href="#qGreen">tqGreen</a>(), and <a href="#qBlue">tqBlue</a>().

<h3 class=fn>TQRgb <a name="qRgba"></a>tqRgba ( int&nbsp;r, int&nbsp;g, int&nbsp;b, int&nbsp;a )
</h3>


<p> Returns the RGBA quadruplet <em>(r,g,b,a)</em>.
<p> The return type TQRgba is equivalent to <tt>unsigned</tt> <tt>int</tt>.
<p> <p>See also <a href="#qRgb">tqRgb</a>(), <a href="#qRed">tqRed</a>(), <a href="#qGreen">tqGreen</a>(), and <a href="#qBlue">tqBlue</a>().

<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">TQt toolkit</a>.
Copyright &copy; 1995-2007
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>TQt 3.3.8</div>
</table></div></address></body>
</html>