You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
619 lines
33 KiB
619 lines
33 KiB
13 years ago
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||
4 months ago
|
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/kernel/tqcolor.cpp:45 -->
|
||
13 years ago
|
<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 Classes</font></a>
|
||
|
| <a href="mainclasses.html">
|
||
|
<font color="#004faf">Main Classes</font></a>
|
||
|
| <a href="annotated.html">
|
||
|
<font color="#004faf">Annotated</font></a>
|
||
|
| <a href="groups.html">
|
||
|
<font color="#004faf">Grouped 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>
|
||
4 months ago
|
<p><tt>#include <<a href="tqcolor-h.html">tqcolor.h</a>></tt>
|
||
|
<p><a href="tqcolor-members.html">List of all member functions.</a>
|
||
13 years ago
|
<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 r, int g, int b )</li>
|
||
|
<li class=fn><a href="#TQColor-3"><b>TQColor</b></a> ( int x, int y, int z, Spec colorSpec )</li>
|
||
|
<li class=fn><a href="#TQColor-4"><b>TQColor</b></a> ( TQRgb rgb, uint pixel = 0xffffffff )</li>
|
||
|
<li class=fn><a href="#TQColor-5"><b>TQColor</b></a> ( const TQString & name )</li>
|
||
|
<li class=fn><a href="#TQColor-6"><b>TQColor</b></a> ( const char * name )</li>
|
||
|
<li class=fn><a href="#TQColor-7"><b>TQColor</b></a> ( const TQColor & c )</li>
|
||
|
<li class=fn>TQColor & <a href="#operator-eq"><b>operator=</b></a> ( const TQColor & 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 TQString & 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 r, int g, int b )</li>
|
||
|
<li class=fn>void <a href="#setRgb-2"><b>setRgb</b></a> ( TQRgb rgb )</li>
|
||
|
<li class=fn>void <a href="#getRgb"><b>getRgb</b></a> ( int * r, int * g, int * b ) const</li>
|
||
|
<li class=fn>void rgb ( int * r, int * g, int * b ) const <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 h, int s, int v )</li>
|
||
|
<li class=fn>void <a href="#getHsv"><b>getHsv</b></a> ( int * h, int * s, int * v ) const</li>
|
||
|
<li class=fn>void hsv ( int * h, int * s, int * v ) const <em>(obsolete)</em></li>
|
||
|
<li class=fn>void getHsv ( int & h, int & s, int & v ) const <em>(obsolete)</em></li>
|
||
|
<li class=fn>TQColor <a href="#light"><b>light</b></a> ( int factor = 150 ) const</li>
|
||
|
<li class=fn>TQColor <a href="#dark"><b>dark</b></a> ( int factor = 200 ) const</li>
|
||
|
<li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const TQColor & c ) const</li>
|
||
|
<li class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const TQColor & 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 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 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 & <a href="#operator-lt-lt"><b>operator<<</b></a> ( TQDataStream & s, const TQColor & c )</li>
|
||
|
<li class=fn>TQDataStream & <a href="#operator-gt-gt"><b>operator>></b></a> ( TQDataStream & s, TQColor & c )</li>
|
||
12 years ago
|
<li class=fn>int <a href="#qRed"><b>tqRed</b></a> ( TQRgb rgb )</li>
|
||
|
<li class=fn>int <a href="#qGreen"><b>tqGreen</b></a> ( TQRgb rgb )</li>
|
||
|
<li class=fn>int <a href="#qBlue"><b>tqBlue</b></a> ( TQRgb rgb )</li>
|
||
|
<li class=fn>int <a href="#qAlpha"><b>tqAlpha</b></a> ( TQRgb rgba )</li>
|
||
|
<li class=fn>TQRgb <a href="#qRgb"><b>tqRgb</b></a> ( int r, int g, int b )</li>
|
||
|
<li class=fn>TQRgb <a href="#qRgba"><b>tqRgba</b></a> ( int r, int g, int b, int a )</li>
|
||
|
<li class=fn>int <a href="#qGray"><b>tqGray</b></a> ( int r, int g, int b )</li>
|
||
|
<li class=fn>int <a href="#qGray-2"><b>tqGray</b></a> ( tqRgb rgb )</li>
|
||
13 years ago
|
</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
|
||
5 months ago
|
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
|
||
13 years ago
|
(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.
|
||
4 months ago
|
<p> <p>See also <a href="ntqpalette.html">TQPalette</a>, <a href="tqcolorgroup.html">TQColorGroup</a>, <a href="ntqapplication.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>.
|
||
13 years ago
|
|
||
|
<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 r, int g, int 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>().
|
||
|
|
||
4 months ago
|
<h3 class=fn><a name="TQColor-3"></a>TQColor::TQColor ( int x, int y, int z, <a href="tqcolor.html#Spec-enum">Spec</a> colorSpec )
|
||
13 years ago
|
</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 rgb, uint 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.
|
||
|
|
||
6 months ago
|
<h3 class=fn><a name="TQColor-5"></a>TQColor::TQColor ( const <a href="tqstring.html">TQString</a> & name )
|
||
13 years ago
|
</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 char * 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>().
|
||
|
|
||
4 months ago
|
<h3 class=fn><a name="TQColor-7"></a>TQColor::TQColor ( const <a href="tqcolor.html">TQColor</a> & c )
|
||
13 years ago
|
</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>
|
||
13 years ago
|
Internal clean up required for TQColor.
|
||
13 years ago
|
This function is called from the <a href="ntqapplication.html">TQApplication</a> destructor.
|
||
13 years ago
|
<p> <p>See also <a href="#initialize">initialize</a>().
|
||
|
|
||
6 months ago
|
<h3 class=fn><a href="tqstringlist.html">TQStringList</a> <a name="colorNames"></a>TQColor::colorNames ()<tt> [static]</tt>
|
||
13 years ago
|
</h3>
|
||
|
|
||
6 months ago
|
Returns a <a href="tqstringlist.html">TQStringList</a> containing the color names TQt knows about.
|
||
13 years ago
|
|
||
|
<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>().
|
||
|
|
||
4 months ago
|
<h3 class=fn><a href="tqcolor.html">TQColor</a> <a name="dark"></a>TQColor::dark ( int factor = 200 ) const
|
||
13 years ago
|
</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 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>
|
||
6 months ago
|
<a href="ntqpixmap.html">TQPixmap</a> loadPixmap( <a href="tqstring.html">TQString</a> fileName )
|
||
13 years ago
|
{
|
||
|
static int alloc_context = 0;
|
||
|
if ( alloc_context )
|
||
|
TQColor::<a href="#destroyAllocContext">destroyAllocContext</a>( alloc_context );
|
||
|
alloc_context = TQColor::<a href="#enterAllocContext">enterAllocContext</a>();
|
||
13 years ago
|
<a href="ntqpixmap.html">TQPixmap</a> pm( fileName );
|
||
13 years ago
|
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.
|
||
13 years ago
|
See <a href="ntqapplication.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="ntqapplication.html#setColorSpec">TQApplication::setColorSpec</a>().
|
||
13 years ago
|
|
||
|
<p>Example: <a href="showimg-example.html#x1314">showimg/showimg.cpp</a>.
|
||
|
<h3 class=fn>void <a name="getHsv"></a>TQColor::getHsv ( int * h, int * s, int * 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 & h, int & s, int & 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 * r, int * g, int * 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 * h, int * s, int * 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>
|
||
13 years ago
|
Internal initialization required for TQColor.
|
||
13 years ago
|
This function is called from the <a href="ntqapplication.html">TQApplication</a> constructor.
|
||
13 years ago
|
<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>.
|
||
4 months ago
|
<h3 class=fn><a href="tqcolor.html">TQColor</a> <a name="light"></a>TQColor::light ( int factor = 150 ) const
|
||
13 years ago
|
</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.
|
||
|
|
||
6 months ago
|
<h3 class=fn><a href="tqstring.html">TQString</a> <a name="name"></a>TQColor::name () const
|
||
13 years ago
|
</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.
|
||
13 years ago
|
<p> <p>See also <a href="ntqpixmap.html#defaultDepth">TQPixmap::defaultDepth</a>().
|
||
13 years ago
|
|
||
4 months ago
|
<h3 class=fn>bool <a name="operator!-eq"></a>TQColor::operator!= ( const <a href="tqcolor.html">TQColor</a> & c ) const
|
||
13 years ago
|
</h3>
|
||
|
|
||
|
Returns TRUE if this color has a different RGB value from <em>c</em>;
|
||
|
otherwise returns FALSE.
|
||
|
|
||
4 months ago
|
<h3 class=fn><a href="tqcolor.html">TQColor</a> & <a name="operator-eq"></a>TQColor::operator= ( const <a href="tqcolor.html">TQColor</a> & c )
|
||
13 years ago
|
</h3>
|
||
|
Assigns a copy of the color <em>c</em> and returns a reference to this
|
||
|
color.
|
||
|
|
||
4 months ago
|
<h3 class=fn>bool <a name="operator-eq-eq"></a>TQColor::operator== ( const <a href="tqcolor.html">TQColor</a> & c ) const
|
||
13 years ago
|
</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 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.
|
||
12 years ago
|
<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>().
|
||
13 years ago
|
|
||
|
<h3 class=fn>void <a name="rgb-2"></a>TQColor::rgb ( int * r, int * g, int * 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 h, int s, int 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>, <a href="grapher-nsplugin-example.html#x2740">grapher/grapher.cpp</a>, and <a href="progress-example.html#x66">progress/progress.cpp</a>.
|
||
6 months ago
|
<h3 class=fn>void <a name="setNamedColor"></a>TQColor::setNamedColor ( const <a href="tqstring.html">TQString</a> & name )
|
||
13 years ago
|
</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 r, int g, int 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 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>
|
||
4 months ago
|
<h3 class=fn><a href="tqdatastream.html">TQDataStream</a> & <a name="operator-lt-lt"></a>operator<< ( <a href="tqdatastream.html">TQDataStream</a> & s, const <a href="tqcolor.html">TQColor</a> & c )
|
||
13 years ago
|
</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>.
|
||
|
|
||
4 months ago
|
<h3 class=fn><a href="tqdatastream.html">TQDataStream</a> & <a name="operator-gt-gt"></a>operator>> ( <a href="tqdatastream.html">TQDataStream</a> & s, <a href="tqcolor.html">TQColor</a> & c )
|
||
13 years ago
|
</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>.
|
||
|
|
||
12 years ago
|
<h3 class=fn>int <a name="qAlpha"></a>tqAlpha ( TQRgb rgba )
|
||
13 years ago
|
</h3>
|
||
|
|
||
|
|
||
|
<p> Returns the alpha component of the RGBA quadruplet <em>rgba</em>.
|
||
|
|
||
12 years ago
|
<h3 class=fn>int <a name="qBlue"></a>tqBlue ( TQRgb rgb )
|
||
13 years ago
|
</h3>
|
||
|
|
||
|
|
||
|
<p> Returns the blue component of the RGB triplet <em>rgb</em>.
|
||
12 years ago
|
<p>See also <a href="#qRgb">tqRgb</a>() and <a href="#blue">TQColor::blue</a>().
|
||
13 years ago
|
|
||
12 years ago
|
<h3 class=fn>int <a name="qGray"></a>tqGray ( int r, int g, int b )
|
||
13 years ago
|
</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.
|
||
|
|
||
12 years ago
|
<h3 class=fn>int <a name="qGray-2"></a>tqGray ( tqRgb rgb )
|
||
13 years ago
|
</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.
|
||
|
|
||
12 years ago
|
<h3 class=fn>int <a name="qGreen"></a>tqGreen ( TQRgb rgb )
|
||
13 years ago
|
</h3>
|
||
|
|
||
|
|
||
|
<p> Returns the green component of the RGB triplet <em>rgb</em>.
|
||
12 years ago
|
<p>See also <a href="#qRgb">tqRgb</a>() and <a href="#green">TQColor::green</a>().
|
||
13 years ago
|
|
||
12 years ago
|
<h3 class=fn>int <a name="qRed"></a>tqRed ( TQRgb rgb )
|
||
13 years ago
|
</h3>
|
||
|
|
||
|
|
||
|
<p> Returns the red component of the RGB triplet <em>rgb</em>.
|
||
12 years ago
|
<p>See also <a href="#qRgb">tqRgb</a>() and <a href="#red">TQColor::red</a>().
|
||
13 years ago
|
|
||
12 years ago
|
<h3 class=fn>TQRgb <a name="qRgb"></a>tqRgb ( int r, int g, int b )
|
||
13 years ago
|
</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>.
|
||
12 years ago
|
<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>().
|
||
13 years ago
|
|
||
12 years ago
|
<h3 class=fn>TQRgb <a name="qRgba"></a>tqRgba ( int r, int g, int b, int a )
|
||
13 years ago
|
</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>.
|
||
12 years ago
|
<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>().
|
||
13 years ago
|
|
||
|
<!-- eof -->
|
||
|
<hr><p>
|
||
|
This file is part of the <a href="index.html">TQt toolkit</a>.
|
||
|
Copyright © 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 © 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>
|