Qt 4.8
Macros | Functions | Variables
qcolor.cpp File Reference
#include "qcolor.h"
#include "qcolor_p.h"
#include "qnamespace.h"
#include "qcolormap.h"
#include "qdatastream.h"
#include "qvariant.h"
#include "qdebug.h"
#include "qapplication.h"
#include "qx11info_x11.h"
#include "private/qt_x11_p.h"
#include <math.h>
#include <stdio.h>
#include <limits.h>

Go to the source code of this file.

Macros

#define Q_MAX_3(a, b, c)   ( ( a > b && a > c) ? a : (b > c ? b : c) )
 
#define Q_MIN_3(a, b, c)   ( ( a < b && a < c) ? a : (b < c ? b : c) )
 
#define QCOLOR_INT_RANGE_CHECK(fn, var)
 
#define QCOLOR_REAL_RANGE_CHECK(fn, var)
 
#define QRGB(r, g, b)   QRgb(((0xffu << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff)))
 
#define QRGBA(r, g, b, a)   QRgb(((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff))
 

Functions

QDebug operator<< (QDebug dbg, const QColor &c)
 
QDataStreamoperator<< (QDataStream &stream, const QColor &color)
 
QDataStreamoperator>> (QDataStream &stream, QColor &color)
 

Variables

static bool allowX11ColorNames = false
 

Macro Definition Documentation

◆ Q_MAX_3

#define Q_MAX_3 (   a,
  b,
  c 
)    ( ( a > b && a > c) ? a : (b > c ? b : c) )

Definition at line 1773 of file qcolor.cpp.

Referenced by QColor::toHsl(), and QColor::toHsv().

◆ Q_MIN_3

#define Q_MIN_3 (   a,
  b,
  c 
)    ( ( a < b && a < c) ? a : (b < c ? b : c) )

Definition at line 1774 of file qcolor.cpp.

Referenced by QColor::toHsl(), and QColor::toHsv().

◆ QCOLOR_INT_RANGE_CHECK

#define QCOLOR_INT_RANGE_CHECK (   fn,
  var 
)
Value:
do { \
if (var < 0 || var > 255) { \
qWarning(#fn": invalid value %d", var); \
var = qMax(0, qMin(var, 255)); \
} \
} while (0)
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217

Definition at line 281 of file qcolor.cpp.

Referenced by QColor::setAlpha(), QColor::setBlue(), QColor::setGreen(), and QColor::setRed().

◆ QCOLOR_REAL_RANGE_CHECK

#define QCOLOR_REAL_RANGE_CHECK (   fn,
  var 
)
Value:
do { \
if (var < qreal(0.0) || var > qreal(1.0)) { \
qWarning(#fn": invalid value %g", var); \
var = qMax(qreal(0.0), qMin(var, qreal(1.0))); \
} \
} while (0)
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217

Definition at line 289 of file qcolor.cpp.

Referenced by QColor::setAlphaF(), QColor::setBlueF(), QColor::setGreenF(), and QColor::setRedF().

◆ QRGB

#define QRGB (   r,
  g,
 
)    QRgb(((0xffu << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff)))

Referenced by QColor::QColor().

◆ QRGBA

#define QRGBA (   r,
  g,
  b,
  a 
)    QRgb(((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff))

Referenced by QColor::QColor().

Function Documentation

◆ operator<<() [1/2]

QDebug operator<< ( QDebug  dbg,
const QColor c 
)

Definition at line 2602 of file qcolor.cpp.

2603 {
2604 #ifndef Q_BROKEN_DEBUG_STREAM
2605  if (!c.isValid())
2606  dbg.nospace() << "QColor(Invalid)";
2607  else if (c.spec() == QColor::Rgb)
2608  dbg.nospace() << "QColor(ARGB " << c.alphaF() << ", " << c.redF() << ", " << c.greenF() << ", " << c.blueF() << ')';
2609  else if (c.spec() == QColor::Hsv)
2610  dbg.nospace() << "QColor(AHSV " << c.alphaF() << ", " << c.hueF() << ", " << c.saturationF() << ", " << c.valueF() << ')';
2611  else if (c.spec() == QColor::Cmyk)
2612  dbg.nospace() << "QColor(ACMYK " << c.alphaF() << ", " << c.cyanF() << ", " << c.magentaF() << ", " << c.yellowF() << ", "
2613  << c.blackF()<< ')';
2614  else if (c.spec() == QColor::Hsl)
2615  dbg.nospace() << "QColor(AHSL " << c.alphaF() << ", " << c.hslHueF() << ", " << c.hslSaturationF() << ", " << c.lightnessF() << ')';
2616 
2617  return dbg.space();
2618 #else
2619  qWarning("This compiler doesn't support streaming QColor to QDebug");
2620  return dbg;
2621  Q_UNUSED(c);
2622 #endif
2623 }
qreal cyanF() const
Returns the cyan color component of this color.
Definition: qcolor.cpp:1585
qreal alphaF() const
Returns the alpha color component of this color.
Definition: qcolor.cpp:1106
qreal hslHueF() const
Returns the hue color component of this color.
Definition: qcolor.cpp:1485
qreal valueF() const
Returns the value color component of this color.
Definition: qcolor.cpp:1416
qreal greenF() const
Returns the green color component of this color.
Definition: qcolor.cpp:1241
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92
qreal blackF() const
Returns the black color component of this color.
Definition: qcolor.cpp:1624
qreal lightnessF() const
Returns the lightness color component of this color.
Definition: qcolor.cpp:1519
qreal hslSaturationF() const
Returns the saturation color component of this color.
Definition: qcolor.cpp:1502
qreal saturationF() const
Returns the saturation color component of this color.
Definition: qcolor.cpp:1392
Q_CORE_EXPORT void qWarning(const char *,...)
qreal yellowF() const
Returns the yellow color component of this color.
Definition: qcolor.cpp:1611
qreal hueF() const
Returns the hue color component of this color.
Definition: qcolor.cpp:1366
qreal redF() const
Returns the red color component of this color.
Definition: qcolor.cpp:1213
qreal blueF() const
Returns the blue color component of this color.
Definition: qcolor.cpp:1269
bool isValid() const
Returns true if the color is valid; otherwise returns false.
Definition: qcolor.h:295
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Definition: qdebug.h:91
qreal magentaF() const
Returns the magenta color component of this color.
Definition: qcolor.cpp:1598
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
Spec spec() const
Returns how the color was specified.
Definition: qcolor.h:88

◆ operator<<() [2/2]

QDataStream& operator<< ( QDataStream stream,
const QColor color 
)

Definition at line 2638 of file qcolor.cpp.

2639 {
2640  if (stream.version() < 7) {
2641  if (!color.isValid())
2642  return stream << quint32(0x49000000);
2643  quint32 p = (quint32)color.rgb();
2644  if (stream.version() == 1) // Swap red and blue
2645  p = ((p << 16) & 0xff0000) | ((p >> 16) & 0xff) | (p & 0xff00ff00);
2646  return stream << p;
2647  }
2648 
2649  qint8 s = color.cspec;
2650  quint16 a = color.ct.argb.alpha;
2651  quint16 r = color.ct.argb.red;
2652  quint16 g = color.ct.argb.green;
2653  quint16 b = color.ct.argb.blue;
2654  quint16 p = color.ct.argb.pad;
2655 
2656  stream << s;
2657  stream << a;
2658  stream << r;
2659  stream << g;
2660  stream << b;
2661  stream << p;
2662 
2663  return stream;
2664 }
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
struct QColor::@220::@221 argb
signed char qint8
Definition: qglobal.h:933
static FILE * stream
unsigned short quint16
Definition: qglobal.h:936
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
unsigned int quint32
Definition: qglobal.h:938
bool isValid() const
Returns true if the color is valid; otherwise returns false.
Definition: qcolor.h:295
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051

◆ operator>>()

QDataStream& operator>> ( QDataStream stream,
QColor color 
)

Definition at line 2677 of file qcolor.cpp.

2678 {
2679  if (stream.version() < 7) {
2680  quint32 p;
2681  stream >> p;
2682  if (p == 0x49000000) {
2683  color.invalidate();
2684  return stream;
2685  }
2686  if (stream.version() == 1) // Swap red and blue
2687  p = ((p << 16) & 0xff0000) | ((p >> 16) & 0xff) | (p & 0xff00ff00);
2688  color.setRgb(p);
2689  return stream;
2690  }
2691 
2692  qint8 s;
2693  quint16 a, r, g, b, p;
2694  stream >> s;
2695  stream >> a;
2696  stream >> r;
2697  stream >> g;
2698  stream >> b;
2699  stream >> p;
2700 
2701  color.cspec = QColor::Spec(s);
2702  color.ct.argb.alpha = a;
2703  color.ct.argb.red = r;
2704  color.ct.argb.green = g;
2705  color.ct.argb.blue = b;
2706  color.ct.argb.pad = p;
2707 
2708  return stream;
2709 }
void setRgb(int r, int g, int b, int a=255)
Sets the RGB value to r, g, b and the alpha value to a.
Definition: qcolor.cpp:980
union QColor::@220 ct
Spec
The type of color specified, either RGB, HSV, CMYK or HSL.
Definition: qcolor.h:70
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
struct QColor::@220::@221 argb
void invalidate()
Marks the color as invalid and sets all components to zero (alpha is set to fully opaque for compatib...
Definition: qcolor.cpp:2563
signed char qint8
Definition: qglobal.h:933
static FILE * stream
unsigned short quint16
Definition: qglobal.h:936
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
unsigned int quint32
Definition: qglobal.h:938

Variable Documentation

◆ allowX11ColorNames

bool allowX11ColorNames = false
static

Definition at line 55 of file qcolor.cpp.

Referenced by QColor::allowX11ColorNames(), qt_set_x11_resources(), and QColor::spec().