~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/gui/painting/qcolor.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the painting module of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "qcolor.h"
 
30
#include "qcolor_p.h"
 
31
#include "qnamespace.h"
 
32
#include "qcolormap.h"
 
33
#include "qdatastream.h"
 
34
#include "qvariant.h"
 
35
#include "qdebug.h"
 
36
 
 
37
#include <math.h>
 
38
#include <stdio.h>
 
39
#include <limits.h>
 
40
 
 
41
 
 
42
/*!
 
43
    \class QColor
 
44
    \brief The QColor class provides colors based on RGB or HSV values.
 
45
 
 
46
    \ingroup multimedia
 
47
    \ingroup appearance
 
48
    \mainclass
 
49
 
 
50
    A color is normally specified in terms of RGB (red, green, and blue)
 
51
    components, but it is also possible to specify HSV (hue, saturation,
 
52
    and value) or set a color name (the names are copied from from the
 
53
    X11 color database).
 
54
 
 
55
    QColor's validity (isValid()) indicates whether it is legal at
 
56
    all. For example, a RGB color with RGB values out of range is
 
57
    illegal. For performance reasons, QColor mostly disregards illegal
 
58
    colors. Therefore, the result of using an invalid color is undefined.
 
59
 
 
60
    There are 20 predefined QColor objects: \c white, \c black, \c
 
61
    red, \c darkRed, \c green, \c darkGreen, \c blue, \c darkBlue, \c
 
62
    cyan, \c darkCyan, \c magenta, \c darkMagenta, \c yellow, \c
 
63
    darkYellow, \c gray, \c darkGray, \c lightGray, \c color0, \c
 
64
    color1, and \c transparent, accessible as members of the Qt
 
65
    namespace (i.e. \c Qt::red).
 
66
 
 
67
    \img qt-colors.png Qt Colors
 
68
 
 
69
    The colors \c Qt::color0 (zero pixel value) and \c Qt::color1 (non-zero
 
70
    pixel value) are special colors for drawing in QBitmaps. Painting with \c
 
71
    Qt::color0 sets the bitmap bits to 0 (transparent, i.e. background), and
 
72
    painting with \c Qt::color1 sets the bits to 1 (opaque, i.e. foreground).
 
73
 
 
74
    QColor is platform and device independent. The QColormap class maps the
 
75
    color to the hardware.
 
76
 
 
77
    A color can be set by passing an RGB string to setNamedColor() (such
 
78
    as "#112233"), or a color name (such as "blue"). The names are taken
 
79
    from X11's rgb.txt database but can also be used on all platforms. To get
 
80
    a lighter or darker color use light() and dark() respectively.
 
81
    Colors can also be set using setRgb() and setHsv(). The color
 
82
    components can be accessed in one go with rgb() and hsv(), or
 
83
    individually with red(), green(), and blue().
 
84
 
 
85
    \section1 HSV Colors
 
86
 
 
87
    Because many people don't know the HSV color model very well, we'll
 
88
    cover it briefly here.
 
89
 
 
90
    The RGB model is hardware-oriented. Its representation is close to
 
91
    what most monitors show. In contrast, HSV represents color in a way
 
92
    more suited to the human perception of color. For example, the
 
93
    relationships "stronger than", "darker than", and "the opposite of"
 
94
    are easily expressed in HSV but are much harder to express in RGB.
 
95
 
 
96
    HSV, like RGB, has three components:
 
97
 
 
98
    \list
 
99
 
 
100
    \i H, for hue, is in the range 0 to 359 if the color is chromatic (not
 
101
    gray), or meaningless if it is gray. It represents degrees on the
 
102
    color wheel familiar to most people. Red is 0 (degrees), green is
 
103
    120, and blue is 240.
 
104
 
 
105
    \i S, for saturation, is in the range 0 to 255, and the bigger it is,
 
106
    the stronger the color is. Grayish colors have saturation near 0; very
 
107
    strong colors have saturation near 255.
 
108
 
 
109
    \i V, for value, is in the range 0 to 255 and represents lightness or
 
110
    brightness of the color. 0 is black; 255 is as far from black as
 
111
    possible.
 
112
 
 
113
    \endlist
 
114
 
 
115
    Here are some examples: pure red is H=0, S=255, V=255; a dark red,
 
116
    moving slightly towards the magenta, could be H=350 (equivalent to
 
117
    -10), S=255, V=180; a grayish light red could have H about 0 (say
 
118
    350-359 or 0-10), S about 50-100, and S=255.
 
119
 
 
120
    Qt returns a hue value of -1 for achromatic colors. If you pass a
 
121
    hue value that is too large, Qt forces it into range. Hue 360 or 720 is
 
122
    treated as 0; hue 540 is treated as 180.
 
123
 
 
124
    \sa QPalette, QApplication::setColorSpec()
 
125
*/
 
126
 
 
127
 
 
128
/*****************************************************************************
 
129
  QColor member functions
 
130
 *****************************************************************************/
 
131
 
 
132
/*!
 
133
    \enum QColor::Spec
 
134
 
 
135
    The type of color specified, either RGB, HSV or CMYK.
 
136
 
 
137
    \value Rgb
 
138
    \value Hsv
 
139
    \value Cmyk
 
140
    \value Invalid
 
141
*/
 
142
 
 
143
/*!
 
144
    \fn Spec QColor::spec() const
 
145
 
 
146
    Returns how the color was specified.
 
147
*/
 
148
 
 
149
 
 
150
/*!
 
151
    \fn QColor::QColor()
 
152
 
 
153
    Constructs an invalid color with the RGB value (0, 0, 0). An
 
154
    invalid color is a color that is not properly set up for the
 
155
    underlying window system.
 
156
 
 
157
    The alpha value of an invalid color is unspecified.
 
158
 
 
159
    \sa isValid()
 
160
*/
 
161
 
 
162
/*!
 
163
    \overload
 
164
 
 
165
    Constructs a new color with a color value of \a color.
 
166
 */
 
167
QColor::QColor(Qt::GlobalColor color)
 
168
{
 
169
#define QRGB(r, g, b) \
 
170
    QRgb(((0xff << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff)))
 
171
#define QRGBA(r, g, b, a) \
 
172
    QRgb(((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff))
 
173
 
 
174
    static const QRgb global_colors[] = {
 
175
        QRGB(255, 255, 255), // Qt::color0
 
176
        QRGB(  0,   0,   0), // Qt::color1
 
177
        QRGB(  0,   0,   0), // black
 
178
        QRGB(255, 255, 255), // white
 
179
        /*
 
180
         * From the "The Palette Manager: How and Why" by Ron Gery,
 
181
         * March 23, 1992, archived on MSDN:
 
182
         *
 
183
         *     The Windows system palette is broken up into two
 
184
         *     sections, one with fixed colors and one with colors
 
185
         *     that can be changed by applications. The system palette
 
186
         *     predefines 20 entries; these colors are known as the
 
187
         *     static or reserved colors and consist of the 16 colors
 
188
         *     found in the Windows version 3.0 VGA driver and 4
 
189
         *     additional colors chosen for their visual appeal.  The
 
190
         *     DEFAULT_PALETTE stock object is, as the name implies,
 
191
         *     the default palette selected into a device context (DC)
 
192
         *     and consists of these static colors. Applications can
 
193
         *     set the remaining 236 colors using the Palette Manager.
 
194
         *
 
195
         * The 20 reserved entries have indices in [0,9] and
 
196
         * [246,255]. We reuse 17 of them.
 
197
         */
 
198
        QRGB(128, 128, 128), // index 248   medium gray
 
199
        QRGB(160, 160, 164), // index 247   light gray
 
200
        QRGB(192, 192, 192), // index 7     light gray
 
201
        QRGB(255,   0,   0), // index 249   red
 
202
        QRGB(  0, 255,   0), // index 250   green
 
203
        QRGB(  0,   0, 255), // index 252   blue
 
204
        QRGB(  0, 255, 255), // index 254   cyan
 
205
        QRGB(255,   0, 255), // index 253   magenta
 
206
        QRGB(255, 255,   0), // index 251   yellow
 
207
        QRGB(128,   0,   0), // index 1     dark red
 
208
        QRGB(  0, 128,   0), // index 2     dark green
 
209
        QRGB(  0,   0, 128), // index 4     dark blue
 
210
        QRGB(  0, 128, 128), // index 6     dark cyan
 
211
        QRGB(128,   0, 128), // index 5     dark magenta
 
212
        QRGB(128, 128,   0), // index 3     dark yellow
 
213
        QRGBA(0, 0, 0, 0)    //             transparent
 
214
    };
 
215
#undef QRGB
 
216
#undef QRGBA
 
217
 
 
218
    setRgb(qRed(global_colors[color]),
 
219
           qGreen(global_colors[color]),
 
220
           qBlue(global_colors[color]),
 
221
           qAlpha(global_colors[color]));
 
222
}
 
223
 
 
224
/*!
 
225
    \fn QColor::QColor(int r, int g, int b, int a = 255)
 
226
 
 
227
    Constructs a color with the RGB value \a r, \a g, \a b, and the
 
228
    alpha-channel (transparency) value of \a a, in the same way as setRgb().
 
229
 
 
230
    The color is left invalid if any of the arguments are invalid.
 
231
 
 
232
    \sa setRgba()
 
233
*/
 
234
 
 
235
/*!
 
236
    Constructs a color with the value \a color. The alpha component is
 
237
    ignored and set to solid.
 
238
 
 
239
    \sa fromRgb()
 
240
*/
 
241
 
 
242
QColor::QColor(QRgb color)
 
243
{
 
244
    cspec = Rgb;
 
245
    ct.argb.alpha = 0xffff;
 
246
    ct.argb.red   = qRed(color)   * 0x101;
 
247
    ct.argb.green = qGreen(color) * 0x101;
 
248
    ct.argb.blue  = qBlue(color)  * 0x101;
 
249
    ct.argb.pad   = 0;
 
250
}
 
251
 
 
252
 
 
253
/*!
 
254
    \fn QColor::QColor(const QString &name)
 
255
 
 
256
    Constructs a named color in the same way as setNamedColor() using
 
257
    the \a name given.
 
258
 
 
259
    The color is left invalid if the \a name cannot be parsed.
 
260
 
 
261
    \sa setNamedColor()
 
262
*/
 
263
 
 
264
/*!
 
265
    \fn QColor::QColor(const char *name)
 
266
 
 
267
    Constructs a named color in the same way as setNamedColor() using
 
268
    the \a name given.
 
269
 
 
270
    The color is left invalid if the \a name cannot be parsed.
 
271
 
 
272
    \sa setNamedColor()
 
273
*/
 
274
 
 
275
/*!
 
276
    \fn QColor::QColor(const QColor &color)
 
277
 
 
278
    Constructs a color that is a copy of \a color.
 
279
*/
 
280
 
 
281
/*!
 
282
    \fn bool QColor::isValid() const
 
283
 
 
284
    Returns true if the color is valid; otherwise returns false.
 
285
 
 
286
    If the color was constructed using the default constructor, false is
 
287
    returned.
 
288
*/
 
289
 
 
290
/*!
 
291
    Returns the name of the color in the format "#AARRGGBB"; i.e. a "#"
 
292
    character followed by three two-digit hexadecimal numbers.
 
293
 
 
294
    \sa setNamedColor()
 
295
*/
 
296
 
 
297
QString QColor::name() const
 
298
{
 
299
#ifndef QT_NO_SPRINTF
 
300
    QString s;
 
301
    s.sprintf("#%02x%02x%02x", red(), green(), blue());
 
302
    return s;
 
303
#else
 
304
    char s[20];
 
305
    sprintf(s, "#%02x%02x%02x", red(), green(), blue());
 
306
    return QString(s);
 
307
#endif
 
308
}
 
309
 
 
310
/*!
 
311
    Sets the RGB value to \a name, which may be in one of these
 
312
    formats:
 
313
    \list
 
314
    \i #RGB (each of R, G, and B is a single hex digit)
 
315
    \i #RRGGBB
 
316
    \i #RRRGGGBBB
 
317
    \i #RRRRGGGGBBBB
 
318
    \i A name from the X color database (rgb.txt) (e.g.
 
319
    "steelblue" or "gainsboro"). These color names work on all platforms.
 
320
    \endlist
 
321
 
 
322
    The color is invalid if \a name cannot be parsed.
 
323
*/
 
324
 
 
325
void QColor::setNamedColor(const QString &name)
 
326
{
 
327
    if (name.isEmpty()) {
 
328
        invalidate();
 
329
        return;
 
330
    }
 
331
 
 
332
    QByteArray n = name.toLatin1();
 
333
    if (name[0] == '#') {
 
334
        QRgb rgb;
 
335
        if (qt_get_hex_rgb(n, &rgb)) {
 
336
            setRgb(rgb);
 
337
        } else {
 
338
            qWarning("QColor::setNamedColor: could not parse color '%s'", n.constData());
 
339
            invalidate();
 
340
        }
 
341
        return;
 
342
    }
 
343
 
 
344
    QRgb rgb;
 
345
    if (qt_get_named_rgb(n, &rgb)) {
 
346
        setRgb(rgb);
 
347
    } else {
 
348
        qWarning("QColor::setNamedColor: unknown color name '%s'", n.constData());
 
349
        invalidate();
 
350
    }
 
351
}
 
352
 
 
353
/*!
 
354
    Returns a QStringList containing the color names Qt knows about.
 
355
*/
 
356
QStringList QColor::colorNames()
 
357
{
 
358
    return qt_get_colornames();
 
359
}
 
360
 
 
361
/*!
 
362
    \overload
 
363
 
 
364
    Returns the current RGB value as HSV. The contents of the \a h, \a
 
365
    s, and \a v pointers are set to the HSV values, and the contents
 
366
    of \a a is set to the alpha-channel (transparency) value. If any
 
367
    of the pointers are null, the function does nothing.
 
368
 
 
369
    \sa setHsv(), rgb()
 
370
*/
 
371
void QColor::getHsvF(qreal *h, qreal *s, qreal *v, qreal *a) const
 
372
{
 
373
        if (!h || !s || !v)
 
374
        return;
 
375
 
 
376
    if (cspec != Invalid && cspec != Hsv) {
 
377
        toHsv().getHsvF(h, s, v, a);
 
378
        return;
 
379
    }
 
380
 
 
381
    *h = ct.ahsv.hue == USHRT_MAX ? -1.0 : ct.ahsv.hue / 36000.0;
 
382
    *s = ct.ahsv.saturation / qreal(USHRT_MAX);
 
383
    *v = ct.ahsv.value / qreal(USHRT_MAX);
 
384
 
 
385
    if (a)
 
386
        *a = ct.ahsv.alpha / qreal(USHRT_MAX);
 
387
}
 
388
 
 
389
/*!
 
390
    Returns the current RGB value as HSV. The contents of the \a h, \a
 
391
    s, and \a v pointers are set to the HSV values, and the contents
 
392
    of \a a is set to the alpha-channel (transparency) value. If any
 
393
    of the pointers are null, the function does nothing.
 
394
 
 
395
    The hue (which \a h points to) is set to -1 if the color is
 
396
    achromatic.
 
397
 
 
398
    \warning Colors are stored internally as RGB values, so getHSv()
 
399
    may return slightly different values to those set by setHsv().
 
400
 
 
401
    \sa setHsv(), rgb()
 
402
*/
 
403
void QColor::getHsv(int *h, int *s, int *v, int *a) const
 
404
{
 
405
    if (!h || !s || !v)
 
406
        return;
 
407
 
 
408
    if (cspec != Invalid && cspec != Hsv) {
 
409
        toHsv().getHsv(h, s, v, a);
 
410
        return;
 
411
    }
 
412
 
 
413
    *h = ct.ahsv.hue == USHRT_MAX ? -1 : ct.ahsv.hue / 100;
 
414
    *s = ct.ahsv.saturation >> 8;
 
415
    *v = ct.ahsv.value      >> 8;
 
416
 
 
417
    if (a)
 
418
        *a = ct.ahsv.alpha >> 8;
 
419
}
 
420
 
 
421
/*!
 
422
    \overload
 
423
 
 
424
    The value of \a h, \a s, \a v, and \a a must all be in the range 0.0-1.0.
 
425
*/
 
426
void QColor::setHsvF(qreal h, qreal s, qreal v, qreal a)
 
427
{
 
428
    if (((h < 0.0 || h > 1.0) && h != -1.0)
 
429
        || (s < 0.0 || s > 1.0)
 
430
        || (v < 0.0 || v > 1.0)
 
431
        || (a < 0.0 || a > 1.0)) {
 
432
        qWarning("QColor::setHsv: HSV parameters out of range");
 
433
        return;
 
434
    }
 
435
 
 
436
    cspec = Hsv;
 
437
    ct.ahsv.alpha      = qRound(a * USHRT_MAX);
 
438
    ct.ahsv.hue        = h == -1.0 ? USHRT_MAX : qRound(h * 36000);
 
439
    ct.ahsv.saturation = qRound(s * USHRT_MAX);
 
440
    ct.ahsv.value      = qRound(v * USHRT_MAX);
 
441
    ct.ahsv.pad        = 0;
 
442
}
 
443
 
 
444
/*!
 
445
    Sets a HSV color value; \a h is the hue, \a s is the saturation,
 
446
    \a v is the value and \a a is the alpha component of the HSV
 
447
    color.
 
448
 
 
449
    If \a s, \a v or \a a are not in the range 0 to 255, or \a h is <
 
450
    -1, the color is not changed.
 
451
 
 
452
    \sa getHsv(), setRgb()
 
453
*/
 
454
void QColor::setHsv(int h, int s, int v, int a)
 
455
{
 
456
    if (h < -1 || (uint)s > 255 || (uint)v > 255 || (uint)a > 255) {
 
457
        qWarning("QColor::setHsv: HSV parameters out of range");
 
458
        invalidate();
 
459
        return;
 
460
    }
 
461
 
 
462
    cspec = Hsv;
 
463
    ct.ahsv.alpha      = a * 0x101;
 
464
    ct.ahsv.hue        = h == -1 ? USHRT_MAX : (h % 360) * 100;
 
465
    ct.ahsv.saturation = s * 0x101;
 
466
    ct.ahsv.value      = v * 0x101;
 
467
    ct.ahsv.pad        = 0;
 
468
}
 
469
 
 
470
/*!
 
471
    \overload
 
472
 
 
473
    Sets the contents pointed to by \a r, \a g, \a b, and \a a, to the
 
474
    red, green, blue, and alpha-channel (transparency) components of
 
475
    the RGB value.
 
476
 
 
477
    \sa rgb(), setRgb(), getHsv()
 
478
*/
 
479
void QColor::getRgbF(qreal *r, qreal *g, qreal *b, qreal *a) const
 
480
{
 
481
    if (!r || !g || !b)
 
482
        return;
 
483
 
 
484
    if (cspec != Invalid && cspec != Rgb) {
 
485
        toRgb().getRgbF(r, g, b, a);
 
486
        return;
 
487
    }
 
488
 
 
489
    *r = ct.argb.red   / qreal(USHRT_MAX);
 
490
    *g = ct.argb.green / qreal(USHRT_MAX);
 
491
    *b = ct.argb.blue  / qreal(USHRT_MAX);
 
492
 
 
493
    if (a)
 
494
        *a = ct.argb.alpha / qreal(USHRT_MAX);
 
495
 
 
496
}
 
497
 
 
498
/*!
 
499
    Sets the contents pointed to by \a r, \a g, \a b, and \a a, to the
 
500
    red, green, blue, and alpha-channel (transparency) components of
 
501
    the RGB value.
 
502
 
 
503
    \sa rgb(), setRgb(), getHsv()
 
504
*/
 
505
void QColor::getRgb(int *r, int *g, int *b, int *a) const
 
506
{
 
507
    if (!r || !g || !b)
 
508
        return;
 
509
 
 
510
    if (cspec != Invalid && cspec != Rgb) {
 
511
        toRgb().getRgb(r, g, b, a);
 
512
        return;
 
513
    }
 
514
 
 
515
    *r = ct.argb.red   >> 8;
 
516
    *g = ct.argb.green >> 8;
 
517
    *b = ct.argb.blue  >> 8;
 
518
 
 
519
    if (a)
 
520
        *a = ct.argb.alpha >> 8;
 
521
}
 
522
 
 
523
/*! \obsolete
 
524
    \fn void QColor::getRgba(int *r, int *g, int *b, int *a) const
 
525
 
 
526
    Populates \a r, \a g, and \a b with the color's RGB values.
 
527
    \a a is populated with the color's alpha channel (opacity) value.
 
528
    All the values are in the range 0 to 255.
 
529
 
 
530
    \sa setRgba() setRgb() setHsv()
 
531
*/
 
532
 
 
533
/*!
 
534
    \fn void QColor::setRgbF(qreal r, qreal g, qreal b, qreal a)
 
535
 
 
536
    Sets the color channels of this color to \a r (red), \a g (green),
 
537
    \a b (blue) and \a a (alpha, transparency).
 
538
 
 
539
    \overload
 
540
 
 
541
    All values must be in the range 0.0-1.0.
 
542
*/
 
543
void QColor::setRgbF(qreal r, qreal g, qreal b, qreal a)
 
544
{
 
545
    if (r < 0.0 || r > 1.0
 
546
        || g < 0.0 || g > 1.0
 
547
        || b < 0.0 || b > 1.0
 
548
        || a < 0.0 || a > 1.0) {
 
549
        qWarning("QColor::setRgb: RGB parameter(s) out of range");
 
550
        invalidate();
 
551
        return;
 
552
    }
 
553
 
 
554
    cspec = Rgb;
 
555
    ct.argb.alpha = qRound(a * USHRT_MAX);
 
556
    ct.argb.red   = qRound(r * USHRT_MAX);
 
557
    ct.argb.green = qRound(g * USHRT_MAX);
 
558
    ct.argb.blue  = qRound(b * USHRT_MAX);
 
559
    ct.argb.pad   = 0;
 
560
}
 
561
 
 
562
/*!
 
563
    Sets the RGB value to \a r, \a g, \a b and the alpha value to \a
 
564
    a. The arguments, \a r, \a g, \a b and \a a must all be in the
 
565
    range 0 to 255. The color becomes invalid if any of them are
 
566
    outside the legal range.
 
567
 
 
568
    \sa rgb(), setHsv()
 
569
*/
 
570
void QColor::setRgb(int r, int g, int b, int a)
 
571
{
 
572
    if ((uint)r > 255 || (uint)g > 255 || (uint)b > 255 || (uint)a > 255) {
 
573
        qWarning("QColor::setRgb: RGB parameter(s) out of range");
 
574
        invalidate();
 
575
        return;
 
576
    }
 
577
 
 
578
    cspec = Rgb;
 
579
    ct.argb.alpha = a * 0x101;
 
580
    ct.argb.red   = r * 0x101;
 
581
    ct.argb.green = g * 0x101;
 
582
    ct.argb.blue  = b * 0x101;
 
583
    ct.argb.pad   = 0;
 
584
}
 
585
 
 
586
/*! \obsolete
 
587
    \fn void QColor::setRgba(int r, int g, int b, int a)
 
588
 
 
589
    Sets the RGBA value to \a r, \a g, \a b, \a a. The arguments, \a
 
590
    r, \a g, \a b, and \a a must all be in the range 0 to 255. If any of
 
591
    them are outside the legal range, the color is not changed.
 
592
 
 
593
    \sa getRgba(), setRgb(), setHsv()
 
594
*/
 
595
 
 
596
/*!
 
597
    \fn QRgb QColor::rgba() const
 
598
 
 
599
    Returns the RGB value of the color. Note that unlike rgb(), the
 
600
    alpha is not stripped.
 
601
 
 
602
    The return type \e QRgb is equivalent to \c unsigned \c int.
 
603
 
 
604
    For an invalid color, the alpha value of the returned color is
 
605
    unspecified.
 
606
 
 
607
    \sa setRgb(), setRgba(), getHsv(), qRed(), qBlue(), qGreen(), isValid()
 
608
*/
 
609
 
 
610
QRgb QColor::rgba() const
 
611
{
 
612
    if (cspec != Invalid && cspec != Rgb)
 
613
        return toRgb().rgba();
 
614
    return qRgba(ct.argb.red >> 8, ct.argb.green >> 8, ct.argb.blue >> 8, ct.argb.alpha >> 8);
 
615
}
 
616
 
 
617
/*!
 
618
    Sets the RGBA value to \a rgba. Note that unlike setRgb(QRgb rgb),
 
619
    this function does not ignore the alpha.
 
620
 
 
621
    The type \e QRgb is equivalent to \c unsigned \c int.
 
622
 
 
623
    \sa rgba()
 
624
*/
 
625
void QColor::setRgba(QRgb rgba)
 
626
{
 
627
    cspec = Rgb;
 
628
    ct.argb.alpha = qAlpha(rgba) * 0x101;
 
629
    ct.argb.red   = qRed(rgba)   * 0x101;
 
630
    ct.argb.green = qGreen(rgba) * 0x101;
 
631
    ct.argb.blue  = qBlue(rgba)  * 0x101;
 
632
    ct.argb.pad   = 0;
 
633
}
 
634
 
 
635
/*!
 
636
    \fn QRgb QColor::rgb() const
 
637
 
 
638
    Returns the RGB value of the color. The alpha is stripped for compatibility.
 
639
 
 
640
    The return type \e QRgb is equivalent to \c unsigned \c int.
 
641
 
 
642
    For an invalid color, the alpha value of the returned color is
 
643
    unspecified.
 
644
 
 
645
    \sa setRgb(), getHsv(), qRed(), qBlue(), qGreen(), isValid()
 
646
*/
 
647
QRgb QColor::rgb() const
 
648
{
 
649
    if (cspec != Invalid && cspec != Rgb)
 
650
        return toRgb().rgb();
 
651
    return qRgb(ct.argb.red >> 8, ct.argb.green >> 8, ct.argb.blue >> 8);
 
652
}
 
653
 
 
654
/*!
 
655
    \overload
 
656
    Sets the RGB value to \a rgb, ignoring the alpha.
 
657
 
 
658
    The type \e QRgb is equivalent to \c unsigned \c int.
 
659
 
 
660
    \sa rgb(), setHsv()
 
661
*/
 
662
void QColor::setRgb(QRgb rgb)
 
663
{
 
664
    cspec = Rgb;
 
665
    ct.argb.alpha = 0xffff;
 
666
    ct.argb.red   = qRed(rgb)   * 0x101;
 
667
    ct.argb.green = qGreen(rgb) * 0x101;
 
668
    ct.argb.blue  = qBlue(rgb)  * 0x101;
 
669
    ct.argb.pad   = 0;
 
670
}
 
671
 
 
672
/*!
 
673
    Returns the alpha color component of this color.
 
674
 
 
675
    \sa alphaF() red() green() blue()
 
676
*/
 
677
int QColor::alpha() const
 
678
{ return ct.argb.alpha >> 8; }
 
679
 
 
680
 
 
681
/*!
 
682
    Sets the alpha of this color to \a alpha. Integer alpha is
 
683
    specified in the range 0-255.
 
684
 
 
685
*/
 
686
 
 
687
void QColor::setAlpha(int alpha)
 
688
{
 
689
    ct.argb.alpha = alpha * 0x101;
 
690
}
 
691
 
 
692
/*!
 
693
    Returns the alpha color component of this color.
 
694
 
 
695
    \sa alpha() redF() greenF() blueF()
 
696
*/
 
697
qreal QColor::alphaF() const
 
698
{ return ct.argb.alpha / qreal(USHRT_MAX); }
 
699
 
 
700
/*!
 
701
    Sets the alpha of this color to \a alpha. Qreal alpha is
 
702
    specified in the range 0-1.
 
703
*/
 
704
void QColor::setAlphaF(qreal alpha)
 
705
{
 
706
    qreal tmp = alpha * USHRT_MAX;
 
707
    ct.argb.alpha = qRound(tmp);
 
708
}
 
709
 
 
710
 
 
711
/*!
 
712
    Returns the red color component of this color.
 
713
 
 
714
    \sa redF() green() blue() alpha()
 
715
*/
 
716
int QColor::red() const
 
717
{
 
718
    if (cspec != Invalid && cspec != Rgb)
 
719
        return toRgb().red();
 
720
    return ct.argb.red >> 8;
 
721
}
 
722
 
 
723
/*!
 
724
    Sets the red color component of this color to \a red. Int
 
725
    components are specified in the range 0-255.
 
726
*/
 
727
void QColor::setRed(int red)
 
728
{
 
729
    ct.argb.red = red * 0x101;
 
730
}
 
731
 
 
732
/*!
 
733
    Returns the green color component of this color.
 
734
 
 
735
    \sa greenF() red() blue() alpha()
 
736
*/
 
737
int QColor::green() const
 
738
{
 
739
    if (cspec != Invalid && cspec != Rgb)
 
740
        return toRgb().green();
 
741
    return ct.argb.green >> 8;
 
742
}
 
743
 
 
744
/*!
 
745
    Sets the green color component of this color to \a green. Int
 
746
    components are specified in the range 0-255.
 
747
*/
 
748
void QColor::setGreen(int green)
 
749
{
 
750
    ct.argb.green = green * 0x101;
 
751
}
 
752
 
 
753
 
 
754
/*!
 
755
    Returns the blue color component of this color.
 
756
 
 
757
    \sa blueF() red() green() alpha()
 
758
*/
 
759
int QColor::blue() const
 
760
{
 
761
    if (cspec != Invalid && cspec != Rgb)
 
762
        return toRgb().blue();
 
763
    return ct.argb.blue >> 8;
 
764
}
 
765
 
 
766
 
 
767
/*!
 
768
    Sets the blue color component of this color to \a blue. Int
 
769
    components are specified in the range 0-255.
 
770
*/
 
771
void QColor::setBlue(int blue)
 
772
{
 
773
    ct.argb.blue = blue * 0x101;
 
774
}
 
775
 
 
776
/*!
 
777
    Returns the red color component of this color.
 
778
 
 
779
    \sa red() greenF() blueF() alphaF()
 
780
*/
 
781
qreal QColor::redF() const
 
782
{
 
783
    if (cspec != Invalid && cspec != Rgb)
 
784
        return toRgb().redF();
 
785
    return ct.argb.red / qreal(USHRT_MAX);
 
786
}
 
787
 
 
788
 
 
789
/*!
 
790
    Sets the red color component of this color to \a red. Float
 
791
    components are specified in the range 0-1.
 
792
*/
 
793
void QColor::setRedF(qreal red)
 
794
{
 
795
    ct.argb.red = qRound(red * USHRT_MAX);
 
796
}
 
797
 
 
798
/*!
 
799
    Returns the green color component of this color.
 
800
 
 
801
    \sa green() redF() blueF() alphaF()
 
802
*/
 
803
qreal QColor::greenF() const
 
804
{
 
805
    if (cspec != Invalid && cspec != Rgb)
 
806
        return toRgb().greenF();
 
807
    return ct.argb.green / qreal(USHRT_MAX);
 
808
}
 
809
 
 
810
 
 
811
/*!
 
812
    Sets the green color component of this color to \a green. Float
 
813
    components are specified in the range 0-1.
 
814
*/
 
815
void QColor::setGreenF(qreal green)
 
816
{
 
817
    ct.argb.green = qRound(green * USHRT_MAX);
 
818
}
 
819
 
 
820
/*!
 
821
    Returns the blue color component of this color.
 
822
 
 
823
    \sa blue() redF() greenF() alphaF()
 
824
*/
 
825
qreal QColor::blueF() const
 
826
{
 
827
    if (cspec != Invalid && cspec != Rgb)
 
828
        return toRgb().blueF();
 
829
    return ct.argb.blue / qreal(USHRT_MAX);
 
830
}
 
831
 
 
832
/*!
 
833
    Sets the blue color component of this color to \a blue. Float
 
834
    components are specified in the range 0-1.
 
835
*/
 
836
void QColor::setBlueF(qreal blue)
 
837
{
 
838
    ct.argb.blue = qRound(blue * USHRT_MAX);
 
839
}
 
840
 
 
841
/*!
 
842
    Returns the hue color component of this color.
 
843
 
 
844
    \sa hueF() saturation() value() alpha()
 
845
*/
 
846
int QColor::hue() const
 
847
{
 
848
    if (cspec != Invalid && cspec != Hsv)
 
849
        return toHsv().hue();
 
850
    return ct.ahsv.hue == USHRT_MAX ? -1 : ct.ahsv.hue / 100;
 
851
}
 
852
 
 
853
/*!
 
854
    Returns the saturation color component of this color.
 
855
 
 
856
    \sa saturationF() hue() value() alpha()
 
857
*/
 
858
int QColor::saturation() const
 
859
{
 
860
    if (cspec != Invalid && cspec != Hsv)
 
861
        return toHsv().saturation();
 
862
    return ct.ahsv.saturation >> 8;
 
863
}
 
864
 
 
865
/*!
 
866
    Returns the value color component of this color.
 
867
 
 
868
    \sa valueF() hue() saturation() alpha()
 
869
*/
 
870
int QColor::value() const
 
871
{
 
872
    if (cspec != Invalid && cspec != Hsv)
 
873
        return toHsv().value();
 
874
    return ct.ahsv.value >> 8;
 
875
}
 
876
 
 
877
/*!
 
878
    Returns the hue color component of this color.
 
879
 
 
880
    \sa hue() saturationF() valueF() alphaF()
 
881
*/
 
882
qreal QColor::hueF() const
 
883
{
 
884
    if (cspec != Invalid && cspec != Hsv)
 
885
        return toHsv().hueF();
 
886
    return ct.ahsv.hue == USHRT_MAX ? -1.0 : ct.ahsv.hue / 36000.0;
 
887
}
 
888
 
 
889
/*!
 
890
    Returns the saturation color component of this color.
 
891
 
 
892
    \sa saturation() hueF() valueF() alphaF()
 
893
*/
 
894
qreal QColor::saturationF() const
 
895
{
 
896
    if (cspec != Invalid && cspec != Hsv)
 
897
        return toHsv().saturationF();
 
898
    return ct.ahsv.saturation / qreal(USHRT_MAX);
 
899
}
 
900
 
 
901
/*!
 
902
    Returns the value color component of this color.
 
903
 
 
904
    \sa value() hueF() saturationF() alphaF()
 
905
*/
 
906
qreal QColor::valueF() const
 
907
{
 
908
    if (cspec != Invalid && cspec != Hsv)
 
909
        return toHsv().valueF();
 
910
    return ct.ahsv.value / qreal(USHRT_MAX);
 
911
}
 
912
 
 
913
/*!
 
914
    Returns the cyan color component of this color.
 
915
 
 
916
    \sa cyanF() black() magenta() yellow() alpha()
 
917
*/
 
918
int QColor::cyan() const
 
919
{
 
920
    if (cspec != Invalid && cspec != Cmyk)
 
921
        return toCmyk().cyan();
 
922
    return ct.acmyk.cyan >> 8;
 
923
}
 
924
 
 
925
/*!
 
926
    Returns the magenta color component of this color.
 
927
 
 
928
    \sa magentaF() cyan() black() yellow() alpha()
 
929
*/
 
930
int QColor::magenta() const
 
931
{
 
932
    if (cspec != Invalid && cspec != Cmyk)
 
933
        return toCmyk().magenta();
 
934
    return ct.acmyk.magenta >> 8;
 
935
}
 
936
 
 
937
/*!
 
938
    Returns the yellow color component of this color.
 
939
 
 
940
    \sa yellowF() cyan() magenta() black() alpha()
 
941
*/
 
942
int QColor::yellow() const
 
943
{
 
944
    if (cspec != Invalid && cspec != Cmyk)
 
945
        return toCmyk().yellow();
 
946
    return ct.acmyk.yellow >> 8;
 
947
}
 
948
 
 
949
/*!
 
950
    Returns the black color component of this color.
 
951
 
 
952
    \sa blackF() cyan() magenta() yellow() alpha()
 
953
*/
 
954
int QColor::black() const
 
955
{
 
956
    if (cspec != Invalid && cspec != Cmyk)
 
957
        return toCmyk().black();
 
958
    return ct.acmyk.black >> 8;
 
959
}
 
960
 
 
961
/*!
 
962
    Returns the cyan color component of this color.
 
963
 
 
964
    \sa cyan() blackF() magentaF() yellowF() alphaF()
 
965
*/
 
966
qreal QColor::cyanF() const
 
967
{
 
968
    if (cspec != Invalid && cspec != Cmyk)
 
969
        return toCmyk().cyanF();
 
970
    return ct.acmyk.cyan / qreal(USHRT_MAX);
 
971
}
 
972
 
 
973
/*!
 
974
    Returns the magenta color component of this color.
 
975
 
 
976
    \sa magenta() cyanF() blackF() yellowF() alphaF()
 
977
*/
 
978
qreal QColor::magentaF() const
 
979
{
 
980
    if (cspec != Invalid && cspec != Cmyk)
 
981
        return toCmyk().magentaF();
 
982
    return ct.acmyk.magenta / qreal(USHRT_MAX);
 
983
}
 
984
 
 
985
/*!
 
986
    Returns the yellow color component of this color.
 
987
 
 
988
    \sa yellow() cyanF() magentaF() blackF() alphaF()
 
989
*/
 
990
qreal QColor::yellowF() const
 
991
{
 
992
    if (cspec != Invalid && cspec != Cmyk)
 
993
        return toCmyk().yellowF();
 
994
    return ct.acmyk.yellow / qreal(USHRT_MAX);
 
995
}
 
996
 
 
997
/*!
 
998
    Returns the black color component of this color.
 
999
 
 
1000
    \sa black() cyanF() magentaF() yellowF() alphaF()
 
1001
*/
 
1002
qreal QColor::blackF() const
 
1003
{
 
1004
    if (cspec != Invalid && cspec != Cmyk)
 
1005
        return toCmyk().blackF();
 
1006
    return ct.acmyk.black / qreal(USHRT_MAX);
 
1007
}
 
1008
 
 
1009
/*!
 
1010
    Returns an RGB QColor based on this color.
 
1011
 
 
1012
    \sa fromRgb() toCmyk() toHsv()
 
1013
*/
 
1014
QColor QColor::toRgb() const
 
1015
{
 
1016
    if (!isValid() || cspec == Rgb)
 
1017
        return *this;
 
1018
 
 
1019
    QColor color;
 
1020
    color.cspec = Rgb;
 
1021
    color.ct.argb.alpha = ct.argb.alpha;
 
1022
    color.ct.argb.pad = 0;
 
1023
 
 
1024
    switch (cspec) {
 
1025
    case Hsv:
 
1026
        {
 
1027
            if (ct.ahsv.saturation == 0 || ct.ahsv.hue == USHRT_MAX) {
 
1028
                // achromatic case
 
1029
                color.ct.argb.red = color.ct.argb.green = color.ct.argb.blue = ct.ahsv.value;
 
1030
                break;
 
1031
            }
 
1032
 
 
1033
            // chromatic case
 
1034
            const qreal h = ct.ahsv.hue / 6000.;
 
1035
            const qreal s = ct.ahsv.saturation / qreal(USHRT_MAX);
 
1036
            const qreal v = ct.ahsv.value / qreal(USHRT_MAX);
 
1037
            const int i = int(h);
 
1038
            const qreal f = h - i;
 
1039
            const qreal p = v * (1.0 - s);
 
1040
 
 
1041
            if (i & 1) {
 
1042
                const qreal q = v * (1.0 - (s * f));
 
1043
 
 
1044
                switch (i) {
 
1045
                case 1:
 
1046
                    color.ct.argb.red   = qRound(q * USHRT_MAX);
 
1047
                    color.ct.argb.green = qRound(v * USHRT_MAX);
 
1048
                    color.ct.argb.blue  = qRound(p * USHRT_MAX);
 
1049
                    break;
 
1050
                case 3:
 
1051
                    color.ct.argb.red   = qRound(p * USHRT_MAX);
 
1052
                    color.ct.argb.green = qRound(q * USHRT_MAX);
 
1053
                    color.ct.argb.blue  = qRound(v * USHRT_MAX);
 
1054
                    break;
 
1055
                case 5:
 
1056
                    color.ct.argb.red   = qRound(v * USHRT_MAX);
 
1057
                    color.ct.argb.green = qRound(p * USHRT_MAX);
 
1058
                    color.ct.argb.blue  = qRound(q * USHRT_MAX);
 
1059
                    break;
 
1060
                }
 
1061
            } else {
 
1062
                const qreal t = v * (1.0 - (s * (1.0 - f)));
 
1063
 
 
1064
                switch (i) {
 
1065
                case 0:
 
1066
                    color.ct.argb.red   = qRound(v * USHRT_MAX);
 
1067
                    color.ct.argb.green = qRound(t * USHRT_MAX);
 
1068
                    color.ct.argb.blue  = qRound(p * USHRT_MAX);
 
1069
                    break;
 
1070
                case 2:
 
1071
                    color.ct.argb.red   = qRound(p * USHRT_MAX);
 
1072
                    color.ct.argb.green = qRound(v * USHRT_MAX);
 
1073
                    color.ct.argb.blue  = qRound(t * USHRT_MAX);
 
1074
                    break;
 
1075
                case 4:
 
1076
                    color.ct.argb.red   = qRound(t * USHRT_MAX);
 
1077
                    color.ct.argb.green = qRound(p * USHRT_MAX);
 
1078
                    color.ct.argb.blue  = qRound(v * USHRT_MAX);
 
1079
                    break;
 
1080
                }
 
1081
            }
 
1082
            break;
 
1083
        }
 
1084
    case Cmyk:
 
1085
        {
 
1086
            const qreal c = ct.acmyk.cyan / qreal(USHRT_MAX);
 
1087
            const qreal m = ct.acmyk.magenta / qreal(USHRT_MAX);
 
1088
            const qreal y = ct.acmyk.yellow / qreal(USHRT_MAX);
 
1089
            const qreal k = ct.acmyk.black / qreal(USHRT_MAX);
 
1090
 
 
1091
            color.ct.argb.red   = qRound((1.0 - (c * (1.0 - k) + k)) * USHRT_MAX);
 
1092
            color.ct.argb.green = qRound((1.0 - (m * (1.0 - k) + k)) * USHRT_MAX);
 
1093
            color.ct.argb.blue  = qRound((1.0 - (y * (1.0 - k) + k)) * USHRT_MAX);
 
1094
            break;
 
1095
        }
 
1096
    default:
 
1097
        break;
 
1098
    }
 
1099
 
 
1100
    return color;
 
1101
};
 
1102
 
 
1103
 
 
1104
#define Q_MAX_3(a, b, c) ( ( a > b && a > c) ? a : (b > c ? b : c) )
 
1105
#define Q_MIN_3(a, b, c) ( ( a < b && a < c) ? a : (b < c ? b : c) )
 
1106
 
 
1107
 
 
1108
/*!
 
1109
    Returns an HSV QColor based on this color.
 
1110
 
 
1111
    \sa fromHsv() toCmyk() toRgb()
 
1112
*/
 
1113
QColor QColor::toHsv() const
 
1114
{
 
1115
    if (!isValid())
 
1116
        return *this;
 
1117
 
 
1118
    if (cspec != Rgb)
 
1119
        return toRgb().toHsv();
 
1120
 
 
1121
    QColor color;
 
1122
    color.cspec = Hsv;
 
1123
    color.ct.ahsv.alpha = ct.argb.alpha;
 
1124
    color.ct.ahsv.pad = 0;
 
1125
 
 
1126
    const qreal r = ct.argb.red   / qreal(USHRT_MAX);
 
1127
    const qreal g = ct.argb.green / qreal(USHRT_MAX);
 
1128
    const qreal b = ct.argb.blue  / qreal(USHRT_MAX);
 
1129
    const qreal max = Q_MAX_3(r, g, b);
 
1130
    const qreal min = Q_MIN_3(r, g, b);
 
1131
    const qreal delta = max - min;
 
1132
    color.ct.ahsv.value = qRound(max * USHRT_MAX);
 
1133
    if (delta == 0.0) {
 
1134
        // achromatic case, hue is undefined
 
1135
        color.ct.ahsv.hue = USHRT_MAX;
 
1136
        color.ct.ahsv.saturation = 0;
 
1137
    } else {
 
1138
        // chromatic case
 
1139
        qreal hue = 0;
 
1140
        color.ct.ahsv.saturation = qRound((delta / max) * USHRT_MAX);
 
1141
        if (r == max) {
 
1142
            hue = ((g - b) /delta);
 
1143
        } else if (g == max) {
 
1144
            hue = (2.0 + (b - r) / delta);
 
1145
        } else if (b == max) {
 
1146
            hue = (4.0 + (r - g) / delta);
 
1147
        } else {
 
1148
            Q_ASSERT_X(false, "QColor::toHsv", "internal error");
 
1149
        }
 
1150
        hue *= 60.0;
 
1151
        if (hue < 0.0)
 
1152
            hue += 360.0;
 
1153
        color.ct.ahsv.hue = qRound(hue * 100);
 
1154
    }
 
1155
 
 
1156
    return color;
 
1157
}
 
1158
 
 
1159
/*!
 
1160
    Returns a CMYK QColor based on this color.
 
1161
 
 
1162
    \sa fromCmyk() toHsv() toRgb()
 
1163
*/
 
1164
QColor QColor::toCmyk() const
 
1165
{
 
1166
    if (!isValid())
 
1167
        return *this;
 
1168
    if (cspec != Rgb)
 
1169
        return toRgb().toCmyk();
 
1170
 
 
1171
    QColor color;
 
1172
    color.cspec = Cmyk;
 
1173
    color.ct.acmyk.alpha = ct.argb.alpha;
 
1174
 
 
1175
    // rgb -> cmy
 
1176
    const qreal r = ct.argb.red   / qreal(USHRT_MAX);
 
1177
    const qreal g = ct.argb.green / qreal(USHRT_MAX);
 
1178
    const qreal b = ct.argb.blue  / qreal(USHRT_MAX);
 
1179
    qreal c = 1.0 - r;
 
1180
    qreal m = 1.0 - g;
 
1181
    qreal y = 1.0 - b;
 
1182
 
 
1183
    // cmy -> cmyk
 
1184
    const qreal k = qMin(c, qMin(m, y));
 
1185
    c = (c - k) / (1.0 - k);
 
1186
    m = (m - k) / (1.0 - k);
 
1187
    y = (y - k) / (1.0 - k);
 
1188
 
 
1189
    color.ct.acmyk.cyan    = qRound(c * USHRT_MAX);
 
1190
    color.ct.acmyk.magenta = qRound(m * USHRT_MAX);
 
1191
    color.ct.acmyk.yellow  = qRound(y * USHRT_MAX);
 
1192
    color.ct.acmyk.black   = qRound(k * USHRT_MAX);
 
1193
 
 
1194
    return color;
 
1195
}
 
1196
 
 
1197
/*!
 
1198
    Returns a new QColor of the given color specification based on
 
1199
    this color.
 
1200
*/
 
1201
QColor QColor::convertTo(QColor::Spec colorSpec) const
 
1202
{
 
1203
    if (colorSpec == cspec)
 
1204
        return *this;
 
1205
    switch (colorSpec) {
 
1206
    case Rgb:
 
1207
        return toRgb();
 
1208
    case Hsv:
 
1209
        return toHsv();
 
1210
    case Cmyk:
 
1211
        return toCmyk();
 
1212
    case Invalid:
 
1213
        break;
 
1214
    }
 
1215
    return QColor(); // must be invalid
 
1216
}
 
1217
 
 
1218
 
 
1219
/*!
 
1220
    Creates a color from the argb value \a rgb.
 
1221
 
 
1222
    The alpha component of \a rgb is ignored. For conversion from an RGBA value
 
1223
    use fromRgba().
 
1224
 
 
1225
    \sa fromRgba()
 
1226
*/
 
1227
 
 
1228
QColor QColor::fromRgb(QRgb rgb)
 
1229
{
 
1230
    return fromRgb(qRed(rgb), qGreen(rgb), qBlue(rgb));
 
1231
}
 
1232
 
 
1233
 
 
1234
/*!
 
1235
    Creates a color from the rgba value \a rgba.
 
1236
 
 
1237
    \sa fromRgb()
 
1238
*/
 
1239
 
 
1240
QColor QColor::fromRgba(QRgb rgba)
 
1241
{
 
1242
    return fromRgb(qRed(rgba), qGreen(rgba), qBlue(rgba), qAlpha(rgba));
 
1243
}
 
1244
 
 
1245
/*!
 
1246
    Static convenience function that returns a QColor constructed from
 
1247
    the RGB color values, \a r (red), \a g (green), \a b (blue),
 
1248
    and \a a (alpha-channel, i.e. transparency).
 
1249
 
 
1250
    All the values must be in the range 0-255.
 
1251
 
 
1252
    \sa toRgb() fromCmyk() fromHsv()
 
1253
*/
 
1254
QColor QColor::fromRgb(int r, int g, int b, int a)
 
1255
{
 
1256
    if (r < 0 || r > 255
 
1257
        || g < 0 || g > 255
 
1258
        || b < 0 || b > 255
 
1259
        || a < 0 || a > 255) {
 
1260
        qWarning("QColor::fromRgb: RGB paramaters out of range");
 
1261
        return QColor();
 
1262
    }
 
1263
 
 
1264
    QColor color;
 
1265
    color.cspec = Rgb;
 
1266
    color.ct.argb.alpha = a * 0x101;
 
1267
    color.ct.argb.red   = r * 0x101;
 
1268
    color.ct.argb.green = g * 0x101;
 
1269
    color.ct.argb.blue  = b * 0x101;
 
1270
    color.ct.argb.pad   = 0;
 
1271
    return color;
 
1272
}
 
1273
 
 
1274
/*!
 
1275
    \overload
 
1276
 
 
1277
    Static convenience function that returns a QColor constructed from
 
1278
    the RGB color values, \a r (red), \a g (green), \a b (blue),
 
1279
    and \a a (alpha-channel, i.e. transparency).
 
1280
 
 
1281
    All the values must be in the range 0.0-1.0.
 
1282
 
 
1283
    \sa toRgb() fromCmyk() fromHsv()
 
1284
*/
 
1285
QColor QColor::fromRgbF(qreal r, qreal g, qreal b, qreal a)
 
1286
{
 
1287
    if (r < 0.0 || r > 1.0
 
1288
        || g < 0.0 || g > 1.0
 
1289
        || b < 0.0 || b > 1.0
 
1290
        || a < 0.0 || a > 1.0) {
 
1291
        qWarning("QColor::fromRgb: RGB paramaters out of range");
 
1292
        return QColor();
 
1293
    }
 
1294
 
 
1295
    QColor color;
 
1296
    color.cspec = Rgb;
 
1297
    color.ct.argb.alpha = qRound(a * USHRT_MAX);
 
1298
    color.ct.argb.red   = qRound(r * USHRT_MAX);
 
1299
    color.ct.argb.green = qRound(g * USHRT_MAX);
 
1300
    color.ct.argb.blue  = qRound(b * USHRT_MAX);
 
1301
    color.ct.argb.pad   = 0;
 
1302
    return color;
 
1303
}
 
1304
 
 
1305
/*!
 
1306
    Static convenience function that returns a QColor constructed from
 
1307
    the HSV color values, \a h (hue), \a s (saturation), \a v (value),
 
1308
    and \a a (alpha-channel, i.e. transparency).
 
1309
 
 
1310
    The value of \a s, \a v, and \a a must all be in the range
 
1311
    0-255; the value of \a h must be in the range 0-360.
 
1312
 
 
1313
    \sa toHsv() fromCmyk() fromRgb()
 
1314
*/
 
1315
QColor QColor::fromHsv(int h, int s, int v, int a)
 
1316
{
 
1317
    if (((h < 0 || h >= 360) && h != -1)
 
1318
        || s < 0 || s > 255
 
1319
        || v < 0 || v > 255
 
1320
        || a < 0 || a > 255) {
 
1321
        qWarning("QColor::fromHsv: HSV parameters out of range");
 
1322
        return QColor();
 
1323
    }
 
1324
 
 
1325
    QColor color;
 
1326
    color.cspec = Hsv;
 
1327
    color.ct.ahsv.alpha      = a * 0x101;
 
1328
    color.ct.ahsv.hue        = h == -1 ? USHRT_MAX : (h % 360) * 100;
 
1329
    color.ct.ahsv.saturation = s * 0x101;
 
1330
    color.ct.ahsv.value      = v * 0x101;
 
1331
    color.ct.ahsv.pad        = 0;
 
1332
    return color;
 
1333
}
 
1334
 
 
1335
/*!
 
1336
    \overload
 
1337
 
 
1338
    Static convenience function that returns a QColor constructed from
 
1339
    the HSV color values, \a h (hue), \a s (saturation), \a v (value),
 
1340
    and \a a (alpha-channel, i.e. transparency).
 
1341
 
 
1342
    The value of \a h, \a s and \a v must all be in the range 0.0-1.0.
 
1343
 
 
1344
    \sa toHsv() fromCmyk() fromRgb()
 
1345
*/
 
1346
QColor QColor::fromHsvF(qreal h, qreal s, qreal v, qreal a)
 
1347
{
 
1348
    if (((h < 0.0 || h > 1.0) && h != -1.0)
 
1349
        || (s < 0.0 || s > 1.0)
 
1350
        || (v < 0.0 || v > 1.0)
 
1351
        || (a < 0.0 || a > 1.0)) {
 
1352
        qWarning("QColor::fromHsv: HSV parameters out of range");
 
1353
        return QColor();
 
1354
    }
 
1355
 
 
1356
    QColor color;
 
1357
    color.cspec = Hsv;
 
1358
    color.ct.ahsv.alpha      = qRound(a * USHRT_MAX);
 
1359
    color.ct.ahsv.hue        = h == -1.0 ? USHRT_MAX : qRound(h * 36000);
 
1360
    color.ct.ahsv.saturation = qRound(s * USHRT_MAX);
 
1361
    color.ct.ahsv.value      = qRound(v * USHRT_MAX);
 
1362
    color.ct.ahsv.pad        = 0;
 
1363
    return color;
 
1364
}
 
1365
 
 
1366
/*!
 
1367
    Sets the contents pointed to by \a c, \a m, \a y, \a k, and \a a,
 
1368
    to the cyan, magenta, yellow, black, and alpha-channel
 
1369
    (transparency) components of the CMYK value.
 
1370
 
 
1371
    \sa setCmyk() getRgb() getHsv()
 
1372
*/
 
1373
void QColor::getCmyk(int *c, int *m, int *y, int *k, int *a)
 
1374
{
 
1375
    if (!c || !m || !y || !k)
 
1376
        return;
 
1377
 
 
1378
    if (cspec != Invalid && cspec != Cmyk) {
 
1379
        toCmyk().getCmyk(c, m, y, k, a);
 
1380
        return;
 
1381
    }
 
1382
 
 
1383
    *c = ct.acmyk.cyan >> 8;
 
1384
    *m = ct.acmyk.magenta >> 8;
 
1385
    *y = ct.acmyk.yellow >> 8;
 
1386
    *k = ct.acmyk.black >> 8;
 
1387
 
 
1388
    if (a)
 
1389
        *a = ct.acmyk.alpha >> 8;
 
1390
}
 
1391
 
 
1392
/*!
 
1393
    \overload
 
1394
 
 
1395
    Sets the contents pointed to by \a c, \a m, \a y, \a k, and \a a,
 
1396
    to the cyan, magenta, yellow, black, and alpha-channel
 
1397
    (transparency) components of the CMYK value.
 
1398
 
 
1399
    \sa setCmyk() getRgb() getHsv()
 
1400
*/
 
1401
void QColor::getCmykF(qreal *c, qreal *m, qreal *y, qreal *k, qreal *a)
 
1402
{
 
1403
    if (!c || !m || !y || !k)
 
1404
        return;
 
1405
 
 
1406
    if (cspec != Invalid && cspec != Cmyk) {
 
1407
        toCmyk().getCmykF(c, m, y, k, a);
 
1408
        return;
 
1409
    }
 
1410
 
 
1411
    *c = ct.acmyk.cyan    / qreal(USHRT_MAX);
 
1412
    *m = ct.acmyk.magenta / qreal(USHRT_MAX);
 
1413
    *y = ct.acmyk.yellow  / qreal(USHRT_MAX);
 
1414
    *k = ct.acmyk.black   / qreal(USHRT_MAX);
 
1415
 
 
1416
    if (a)
 
1417
        *a = ct.acmyk.alpha / qreal(USHRT_MAX);
 
1418
}
 
1419
 
 
1420
/*!
 
1421
    Sets the color to CMYK values, \a c (cyan), \a m (magenta), \a y (yellow),
 
1422
    \a k (black), and \a a (alpha-channel, i.e. transparency).
 
1423
 
 
1424
    All the values must be in the range 0-255.
 
1425
 
 
1426
    \sa getCmyk() setRgb() setHsv()
 
1427
*/
 
1428
void QColor::setCmyk(int c, int m, int y, int k, int a)
 
1429
{
 
1430
    if (c < 0 || c > 255
 
1431
        || m < 0 || m > 255
 
1432
        || y < 0 || y > 255
 
1433
        || k < 0 || k > 255
 
1434
        || a < 0 || a > 255) {
 
1435
        qWarning("QColor::setCmyk: CMYK paramaters out of range");
 
1436
        return;
 
1437
    }
 
1438
 
 
1439
    cspec = Cmyk;
 
1440
    ct.acmyk.alpha   = a * 0x101;
 
1441
    ct.acmyk.cyan    = c * 0x101;
 
1442
    ct.acmyk.magenta = m * 0x101;
 
1443
    ct.acmyk.yellow  = y * 0x101;
 
1444
    ct.acmyk.black   = k * 0x101;
 
1445
}
 
1446
 
 
1447
/*!
 
1448
    \overload
 
1449
 
 
1450
    Sets the color to CMYK values, \a c (cyan), \a m (magenta), \a y (yellow),
 
1451
    \a k (black), and \a a (alpha-channel, i.e. transparency).
 
1452
 
 
1453
    All the values must be in the range 0.0-1.0.
 
1454
 
 
1455
    \sa getCmyk() setRgb() setHsv()
 
1456
*/
 
1457
void QColor::setCmykF(qreal c, qreal m, qreal y, qreal k, qreal a)
 
1458
{
 
1459
    if (c < 0.0 || c > 1.0
 
1460
        || m < 0.0 || m > 1.0
 
1461
        || y < 0.0 || y > 1.0
 
1462
        || k < 0.0 || k > 1.0
 
1463
        || a < 0.0 || a > 1.0) {
 
1464
        qWarning("QColor::setCmyk: CMYK paramaters out of range");
 
1465
        return;
 
1466
    }
 
1467
 
 
1468
    cspec = Cmyk;
 
1469
    ct.acmyk.alpha   = qRound(a * USHRT_MAX);
 
1470
    ct.acmyk.cyan    = qRound(c * USHRT_MAX);
 
1471
    ct.acmyk.magenta = qRound(m * USHRT_MAX);
 
1472
    ct.acmyk.yellow  = qRound(y * USHRT_MAX);
 
1473
    ct.acmyk.black   = qRound(k * USHRT_MAX);
 
1474
}
 
1475
 
 
1476
/*!
 
1477
    Static convenience function that returns a QColor constructed from
 
1478
    the CMYK color values, \a c (cyan), \a m (magenta), \a y (yellow),
 
1479
    \a k (black), and \a a (alpha-channel, i.e. transparency).
 
1480
 
 
1481
    All the values must be in the range 0-255.
 
1482
 
 
1483
    \sa toCmyk() fromHsv() fromRgb()
 
1484
*/
 
1485
QColor QColor::fromCmyk(int c, int m, int y, int k, int a)
 
1486
{
 
1487
    if (c < 0 || c > 255
 
1488
        || m < 0 || m > 255
 
1489
        || y < 0 || y > 255
 
1490
        || k < 0 || k > 255
 
1491
        || a < 0 || a > 255) {
 
1492
        qWarning("QColor::fromCmyk: CMYK paramaters out of range");
 
1493
        return QColor();
 
1494
    }
 
1495
 
 
1496
    QColor color;
 
1497
    color.cspec = Cmyk;
 
1498
    color.ct.acmyk.alpha   = a * 0x101;
 
1499
    color.ct.acmyk.cyan    = c * 0x101;
 
1500
    color.ct.acmyk.magenta = m * 0x101;
 
1501
    color.ct.acmyk.yellow  = y * 0x101;
 
1502
    color.ct.acmyk.black   = k * 0x101;
 
1503
    return color;
 
1504
}
 
1505
 
 
1506
/*!
 
1507
    \overload
 
1508
 
 
1509
    Static convenience function that returns a QColor constructed from
 
1510
    the CMYK color values, \a c (cyan), \a m (magenta), \a y (yellow),
 
1511
    \a k (black), and \a a (alpha-channel, i.e. transparency).
 
1512
 
 
1513
    All the values must be in the range 0.0-1.0.
 
1514
 
 
1515
    \sa toCmyk() fromHsv() fromRgb()
 
1516
*/
 
1517
QColor QColor::fromCmykF(qreal c, qreal m, qreal y, qreal k, qreal a)
 
1518
{
 
1519
    if (c < 0.0 || c > 1.0
 
1520
        || m < 0.0 || m > 1.0
 
1521
        || y < 0.0 || y > 1.0
 
1522
        || k < 0.0 || k > 1.0
 
1523
        || a < 0.0 || a > 1.0) {
 
1524
        qWarning("QColor::fromCmyk: CMYK paramaters out of range");
 
1525
        return QColor();
 
1526
    }
 
1527
 
 
1528
    QColor color;
 
1529
    color.cspec = Cmyk;
 
1530
    color.ct.acmyk.alpha   = qRound(a * USHRT_MAX);
 
1531
    color.ct.acmyk.cyan    = qRound(c * USHRT_MAX);
 
1532
    color.ct.acmyk.magenta = qRound(m * USHRT_MAX);
 
1533
    color.ct.acmyk.yellow  = qRound(y * USHRT_MAX);
 
1534
    color.ct.acmyk.black   = qRound(k * USHRT_MAX);
 
1535
    return color;
 
1536
}
 
1537
 
 
1538
/*!
 
1539
    Returns a lighter (or darker) color, but does not change this
 
1540
    object.
 
1541
 
 
1542
    Returns a lighter color if \a factor is greater than 100. Setting
 
1543
    \a factor to 150 returns a color that is 50% brighter.
 
1544
 
 
1545
    Returns a darker color if \a factor is less than 100. We recommend
 
1546
    using dark() for this purpose. If \a factor is 0 or negative, the
 
1547
    return value is unspecified.
 
1548
 
 
1549
    (This function converts the current RGB color to HSV, multiplies V
 
1550
    by \a factor, and converts the result back to RGB.)
 
1551
 
 
1552
    \sa dark()
 
1553
*/
 
1554
QColor QColor::light(int factor) const
 
1555
{
 
1556
    if (factor <= 0)                                // invalid lightness factor
 
1557
        return *this;
 
1558
    else if (factor < 100)                        // makes color darker
 
1559
        return dark(10000/factor);
 
1560
 
 
1561
    QColor hsv = toHsv();
 
1562
    int s = hsv.ct.ahsv.saturation;
 
1563
    int v = hsv.ct.ahsv.value;
 
1564
 
 
1565
    v = (factor*v)/100;
 
1566
    if (v > USHRT_MAX) {
 
1567
        // overflow... adjust saturation
 
1568
        s -= v - USHRT_MAX;
 
1569
        if (s < 0)
 
1570
            s = 0;
 
1571
        v = USHRT_MAX;
 
1572
    }
 
1573
 
 
1574
    hsv.ct.ahsv.saturation = s;
 
1575
    hsv.ct.ahsv.value = v;
 
1576
 
 
1577
    // convert back to same color spec as original color
 
1578
    return hsv.convertTo(cspec);
 
1579
}
 
1580
 
 
1581
/*!
 
1582
    Returns a darker (or lighter) color, but does not change this
 
1583
    object.
 
1584
 
 
1585
    Returns a darker color if \a factor is greater than 100. Setting
 
1586
    \a factor to 300 returns a color that has one-third the
 
1587
    brightness.
 
1588
 
 
1589
    Returns a lighter color if \a factor is less than 100. We
 
1590
    recommend using light() for this purpose. If \a factor is 0 or
 
1591
    negative, the return value is unspecified.
 
1592
 
 
1593
    (This function converts the current RGB color to HSV, divides V by
 
1594
    \a factor and converts back to RGB.)
 
1595
 
 
1596
    \sa light()
 
1597
*/
 
1598
QColor QColor::dark(int factor) const
 
1599
{
 
1600
    if (factor <= 0)                                // invalid darkness factor
 
1601
        return *this;
 
1602
    else if (factor < 100)                        // makes color lighter
 
1603
        return light(10000/factor);
 
1604
 
 
1605
    QColor hsv = toHsv();
 
1606
    hsv.ct.ahsv.value = (hsv.ct.ahsv.value * 100) / factor;
 
1607
 
 
1608
    // convert back to same color spec as original color
 
1609
    return hsv.convertTo(cspec);
 
1610
}
 
1611
 
 
1612
/*!
 
1613
    Assigns a copy of the color \a color to this color, and returns a
 
1614
    reference to it.
 
1615
*/
 
1616
QColor &QColor::operator=(const QColor &color)
 
1617
{
 
1618
    cspec = color.cspec;
 
1619
    ct.argb = color.ct.argb;
 
1620
    return *this;
 
1621
}
 
1622
 
 
1623
/*! \overload
 
1624
    Assigns a copy of the \a color and returns a reference to this color.
 
1625
 */
 
1626
QColor &QColor::operator=(Qt::GlobalColor color)
 
1627
{
 
1628
    return operator=(QColor(color));
 
1629
}
 
1630
 
 
1631
/*!
 
1632
    Returns true if this color has the same RGB value as the color \a
 
1633
    color; otherwise returns false.
 
1634
*/
 
1635
bool QColor::operator==(const QColor &color) const
 
1636
{
 
1637
    return (cspec == color.cspec
 
1638
            && ct.argb.alpha == color.ct.argb.alpha
 
1639
            && ct.argb.red   == color.ct.argb.red
 
1640
            && ct.argb.green == color.ct.argb.green
 
1641
            && ct.argb.blue  == color.ct.argb.blue
 
1642
            && ct.argb.pad   == color.ct.argb.pad);
 
1643
}
 
1644
 
 
1645
/*!
 
1646
    Returns true if this color has a different RGB value from the
 
1647
    color \a color; otherwise returns false.
 
1648
*/
 
1649
bool QColor::operator!=(const QColor &color) const
 
1650
{ return !operator==(color); }
 
1651
 
 
1652
 
 
1653
/*!
 
1654
   Returns the color as a QVariant
 
1655
*/
 
1656
QColor::operator QVariant() const
 
1657
{
 
1658
    return QVariant(QVariant::Color, this);
 
1659
}
 
1660
 
 
1661
/*! \internal
 
1662
 
 
1663
    Marks the color as invalid and sets all components to zero (alpha
 
1664
    is set to fully opaque for compatibility with Qt 3).
 
1665
*/
 
1666
void QColor::invalidate()
 
1667
{
 
1668
    cspec = Invalid;
 
1669
    ct.argb.alpha = USHRT_MAX;
 
1670
    ct.argb.red = 0;
 
1671
    ct.argb.green = 0;
 
1672
    ct.argb.blue = 0;
 
1673
    ct.argb.pad = 0;
 
1674
}
 
1675
 
 
1676
#ifdef QT3_SUPPORT
 
1677
 
 
1678
/*!
 
1679
    Returns the pixel value.
 
1680
 
 
1681
    This value is used by the underlying window system to refer to a
 
1682
    color. It can be thought of as an index into the display
 
1683
    hardware's color table, but the value is an arbitrary 32-bit
 
1684
    value.
 
1685
 
 
1686
    The \a screen parameter is only used under X11 to specify the X11
 
1687
    screen.
 
1688
*/
 
1689
uint QColor::pixel(int screen) const
 
1690
{
 
1691
    QColormap cmap = QColormap::instance(screen);
 
1692
    return cmap.pixel(*this);
 
1693
}
 
1694
 
 
1695
#endif // QT3_SUPPORT
 
1696
 
 
1697
/*****************************************************************************
 
1698
  QColor stream functions
 
1699
 *****************************************************************************/
 
1700
 
 
1701
#ifndef QT_NO_DEBUG_STREAM
 
1702
QDebug operator<<(QDebug dbg, const QColor &c)
 
1703
{
 
1704
#ifndef Q_BROKEN_DEBUG_STREAM
 
1705
    if (!c.isValid())
 
1706
        dbg.nospace() << "QColor(Invalid)";
 
1707
    else if (c.spec() == QColor::Rgb)
 
1708
        dbg.nospace() << "QColor(ARGB " << c.alphaF() << ", " << c.redF() << ", " << c.greenF() << ", " << c.blueF() << ")";
 
1709
    else if (c.spec() == QColor::Hsv)
 
1710
        dbg.nospace() << "QColor(AHSV " << c.alphaF() << ", " << c.hueF() << ", " << c.saturationF() << ", " << c.valueF() << ")";
 
1711
    else if (c.spec() == QColor::Cmyk)
 
1712
        dbg.nospace() << "QColor(ACMYK " << c.alphaF() << ", " << c.cyanF() << ", " << c.magentaF() << ", " << c.yellowF() << ", "
 
1713
                      << c.blackF()<< ")";
 
1714
 
 
1715
    return dbg.space();
 
1716
#else
 
1717
    qWarning("This compiler doesn't support streaming QColor to QDebug");
 
1718
    return dbg;
 
1719
    Q_UNUSED(c);
 
1720
#endif
 
1721
}
 
1722
#endif
 
1723
 
 
1724
#ifndef QT_NO_DATASTREAM
 
1725
/*!
 
1726
    \fn QDataStream &operator<<(QDataStream &stream, const QColor &color)
 
1727
 
 
1728
    \relates QColor
 
1729
    Writes the \a color to the \a stream.
 
1730
 
 
1731
    \sa \link datastreamformat.html Format of the QDataStream operators \endlink
 
1732
*/
 
1733
QDataStream &operator<<(QDataStream &stream, const QColor &color)
 
1734
{
 
1735
    if (stream.version() < 7) {
 
1736
        quint32 p = (quint32)color.rgb();
 
1737
        if (stream.version() == 1) // Swap red and blue
 
1738
            p = ((p << 16) & 0xff0000) | ((p >> 16) & 0xff) | (p & 0xff00ff00);
 
1739
        return stream << p;
 
1740
    }
 
1741
 
 
1742
    qint8   s = color.cspec;
 
1743
    quint16 a = color.ct.argb.alpha;
 
1744
    quint16 r = color.ct.argb.red;
 
1745
    quint16 g = color.ct.argb.green;
 
1746
    quint16 b = color.ct.argb.blue;
 
1747
    quint16 p = color.ct.argb.pad;
 
1748
 
 
1749
    stream << s;
 
1750
    stream << a;
 
1751
    stream << r;
 
1752
    stream << g;
 
1753
    stream << b;
 
1754
    stream << p;
 
1755
 
 
1756
    return stream;
 
1757
}
 
1758
 
 
1759
/*!
 
1760
    \fn QDataStream &operator>>(QDataStream &stream, QColor &color)
 
1761
 
 
1762
    \relates QColor
 
1763
    Reads the \a color from the \a stream.
 
1764
 
 
1765
    \sa \link datastreamformat.html Format of the QDataStream operators \endlink
 
1766
*/
 
1767
QDataStream &operator>>(QDataStream &stream, QColor &color)
 
1768
{
 
1769
    if (stream.version() < 7) {
 
1770
        quint32 p;
 
1771
        stream >> p;
 
1772
        if (stream.version() == 1) // Swap red and blue
 
1773
            p = ((p << 16) & 0xff0000) | ((p >> 16) & 0xff) | (p & 0xff00ff00);
 
1774
        color.setRgb(p);
 
1775
        return stream;
 
1776
    }
 
1777
 
 
1778
    qint8 s;
 
1779
    quint16 a, r, g, b, p;
 
1780
    stream >> s;
 
1781
    stream >> a;
 
1782
    stream >> r;
 
1783
    stream >> g;
 
1784
    stream >> b;
 
1785
    stream >> p;
 
1786
 
 
1787
    color.cspec = QColor::Spec(s);
 
1788
    color.ct.argb.alpha = a;
 
1789
    color.ct.argb.red   = r;
 
1790
    color.ct.argb.green = g;
 
1791
    color.ct.argb.blue  = b;
 
1792
    color.ct.argb.pad   = p;
 
1793
 
 
1794
    return stream;
 
1795
}
 
1796
#endif
 
1797
 
 
1798
 
 
1799
 
 
1800
 
 
1801
/*****************************************************************************
 
1802
  QColor global functions (documentation only)
 
1803
 *****************************************************************************/
 
1804
 
 
1805
/*!
 
1806
    \fn int qRed(QRgb rgb)
 
1807
    \relates QColor
 
1808
 
 
1809
    Returns the red component of the RGBA quadruplet \a rgb.
 
1810
    \sa qRgb(), QColor::red()
 
1811
*/
 
1812
 
 
1813
/*!
 
1814
    \fn int qGreen(QRgb rgb)
 
1815
    \relates QColor
 
1816
 
 
1817
    Returns the green component of the RGBA quadruplet \a rgb.
 
1818
    \sa qRgb(), QColor::green()
 
1819
*/
 
1820
 
 
1821
/*!
 
1822
    \fn int qBlue(QRgb rgb)
 
1823
    \relates QColor
 
1824
 
 
1825
    Returns the blue component of the RGBA quadruplet \a rgb.
 
1826
    \sa qRgb(), QColor::blue()
 
1827
*/
 
1828
 
 
1829
/*!
 
1830
    \fn int qAlpha(QRgb rgba)
 
1831
    \relates QColor
 
1832
 
 
1833
    Returns the alpha component of the RGBA quadruplet \a rgba.
 
1834
    */
 
1835
 
 
1836
/*!
 
1837
    \fn QRgb qRgb(int r, int g, int b)
 
1838
    \relates QColor
 
1839
 
 
1840
    Returns the RGB triplet (\a{r}, \a{g}, \a{b}).
 
1841
 
 
1842
    The return type QRgb is equivalent to \c unsigned \c int.
 
1843
 
 
1844
    \sa qRgba(), qRed(), qGreen(), qBlue()
 
1845
*/
 
1846
 
 
1847
/*!
 
1848
    \fn QRgb qRgba(int r, int g, int b, int a)
 
1849
    \relates QColor
 
1850
 
 
1851
    Returns the RGBA quadruplet (\a{r}, \a{g}, \a{b}, \a{a}).
 
1852
 
 
1853
    The return type QRgba is equivalent to \c unsigned \c int.
 
1854
 
 
1855
    \sa qRgb(), qRed(), qGreen(), qBlue()
 
1856
*/
 
1857
 
 
1858
/*!
 
1859
    \fn int qGray(int r, int g, int b)
 
1860
    \relates QColor
 
1861
 
 
1862
    Returns a gray value (0 to 255) from the (\a r, \a g, \a b) triplet.
 
1863
 
 
1864
    The gray value is calculated using the formula (r*11 + g*16 +
 
1865
    b*5)/32.
 
1866
*/
 
1867
 
 
1868
/*!
 
1869
    \fn int qGray(QRgb rgb)
 
1870
    \overload
 
1871
    \relates QColor
 
1872
 
 
1873
    Returns a gray value (0 to 255) from the given RGB triplet \a rgb.
 
1874
*/
 
1875
 
 
1876
/*!
 
1877
    \fn QColor::QColor(int x, int y, int z, Spec colorSpec)
 
1878
 
 
1879
    Use one of the other QColor constructors, or one of the static
 
1880
    convenience functions, instead.
 
1881
*/
 
1882
 
 
1883
/*!
 
1884
    \fn QColor::rgb(int *r, int *g, int *b) const
 
1885
 
 
1886
    Use getRgb() instead.
 
1887
*/
 
1888
 
 
1889
/*!
 
1890
    \fn QColor::hsv(int *h, int *s, int *v) const
 
1891
 
 
1892
    Use getHsv() instead.
 
1893
*/
 
1894
 
 
1895
/*!
 
1896
    \fn QColor QColor::convertTo(Spec colorSpec) const
 
1897
 
 
1898
    Converts the color to the color format specified by \a colorSpec
 
1899
*/