Qt 4.8
Classes | Macros | Functions | Variables
qcolor_p.cpp File Reference
#include "qglobal.h"
#include "qrgb.h"
#include "qstringlist.h"

Go to the source code of this file.

Classes

struct  RGBData
 

Macros

#define rgb(r, g, b)   (0xff000000 | (r << 16) | (g << 8) | b)
 

Functions

static bool get_named_rgb (const char *name_no_space, QRgb *rgb)
 
static int h2i (char hex)
 
static int hex2int (const char *s)
 
static int hex2int (char s)
 
bool operator< (const char *name, const RGBData &data)
 
bool operator< (const RGBData &data, const char *name)
 
QStringList qt_get_colornames ()
 
bool qt_get_hex_rgb (const char *name, QRgb *rgb)
 
bool qt_get_hex_rgb (const QChar *str, int len, QRgb *rgb)
 
bool qt_get_named_rgb (const char *name, QRgb *rgb)
 
bool qt_get_named_rgb (const QChar *name, int len, QRgb *rgb)
 
uint qt_get_rgb_val (const char *name)
 

Variables

static const struct RGBData rgbTbl []
 
static const int rgbTblSize = sizeof(rgbTbl) / sizeof(RGBData)
 

Macro Definition Documentation

◆ rgb

#define rgb (   r,
  g,
 
)    (0xff000000 | (r << 16) | (g << 8) | b)

Function Documentation

◆ get_named_rgb()

static bool get_named_rgb ( const char *  name_no_space,
QRgb rgb 
)
static

Definition at line 295 of file qcolor_p.cpp.

Referenced by qt_get_named_rgb().

296 {
297  QByteArray name = QByteArray(name_no_space).toLower();
298  const RGBData *r = qBinaryFind(rgbTbl, rgbTbl + rgbTblSize, name.constData());
299  if (r != rgbTbl + rgbTblSize) {
300  *rgb = r->value;
301  return true;
302  }
303  return false;
304 }
static const struct RGBData rgbTbl[]
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QByteArray toLower() const
Returns a lowercase copy of the byte array.
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qBinaryFind(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
Definition: qalgorithms.h:295
const char * name
#define rgb(r, g, b)
Definition: qcolor_p.cpp:130
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
static const int rgbTblSize
Definition: qcolor_p.cpp:286
uint value
Definition: qcolor_p.cpp:134

◆ h2i()

static int h2i ( char  hex)
inlinestatic

Definition at line 54 of file qcolor_p.cpp.

Referenced by hex2int().

55 {
56  if (hex >= '0' && hex <= '9')
57  return hex - '0';
58  if (hex >= 'a' && hex <= 'f')
59  return hex - 'a' + 10;
60  if (hex >= 'A' && hex <= 'F')
61  return hex - 'A' + 10;
62  return -1;
63 }
QTextStream & hex(QTextStream &stream)
Calls QTextStream::setIntegerBase(16) on stream and returns stream.

◆ hex2int() [1/2]

static int hex2int ( const char *  s)
inlinestatic

Definition at line 65 of file qcolor_p.cpp.

Referenced by qt_get_hex_rgb().

66 {
67  return (h2i(s[0]) << 4) | h2i(s[1]);
68 }
static int h2i(char hex)
Definition: qcolor_p.cpp:54

◆ hex2int() [2/2]

static int hex2int ( char  s)
inlinestatic

Definition at line 70 of file qcolor_p.cpp.

71 {
72  int h = h2i(s);
73  return (h << 4) | h;
74 }
static int h2i(char hex)
Definition: qcolor_p.cpp:54

◆ operator<() [1/2]

bool operator< ( const char *  name,
const RGBData data 
)
inline

Definition at line 290 of file qcolor_p.cpp.

291 { return qstrcmp(name, data.name) < 0; }
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231
const char * name
Definition: qcolor_p.cpp:133
const char * name

◆ operator<() [2/2]

bool operator< ( const RGBData data,
const char *  name 
)
inline

Definition at line 292 of file qcolor_p.cpp.

293 { return qstrcmp(data.name, name) < 0; }
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231
const char * name
Definition: qcolor_p.cpp:133
const char * name

◆ qt_get_colornames()

QStringList qt_get_colornames ( )

Definition at line 344 of file qcolor_p.cpp.

Referenced by QColor::colorNames(), and qt_get_colornames().

345 {
346  int i = 0;
347  QStringList lst;
348  for (i = 0; i < rgbTblSize; i++)
349  lst << QLatin1String(rgbTbl[i].name);
350  return lst;
351 }
static const struct RGBData rgbTbl[]
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
const char * name
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static const int rgbTblSize
Definition: qcolor_p.cpp:286

◆ qt_get_hex_rgb() [1/2]

bool qt_get_hex_rgb ( const char *  name,
QRgb rgb 
)

Definition at line 76 of file qcolor_p.cpp.

Referenced by qt_get_hex_rgb(), read_xpm_body(), and QColor::setColorFromString().

77 {
78  if(name[0] != '#')
79  return false;
80  name++;
81  int len = qstrlen(name);
82  int r, g, b;
83  if (len == 12) {
84  r = hex2int(name);
85  g = hex2int(name + 4);
86  b = hex2int(name + 8);
87  } else if (len == 9) {
88  r = hex2int(name);
89  g = hex2int(name + 3);
90  b = hex2int(name + 6);
91  } else if (len == 6) {
92  r = hex2int(name);
93  g = hex2int(name + 2);
94  b = hex2int(name + 4);
95  } else if (len == 3) {
96  r = hex2int(name[0]);
97  g = hex2int(name[1]);
98  b = hex2int(name[2]);
99  } else {
100  r = g = b = -1;
101  }
102  if ((uint)r > 255 || (uint)g > 255 || (uint)b > 255) {
103  *rgb = 0;
104  return false;
105  }
106  *rgb = qRgb(r, g ,b);
107  return true;
108 }
const char * name
unsigned int uint
Definition: qglobal.h:996
#define rgb(r, g, b)
Definition: qcolor_p.cpp:130
QRgb qRgb(int r, int g, int b)
Returns the ARGB quadruplet (255, {r}, {g}, {b}).
Definition: qrgb.h:69
uint qstrlen(const char *str)
Definition: qbytearray.h:79
static int hex2int(const char *s)
Definition: qcolor_p.cpp:65

◆ qt_get_hex_rgb() [2/2]

bool qt_get_hex_rgb ( const QChar str,
int  len,
QRgb rgb 
)

Definition at line 110 of file qcolor_p.cpp.

111 {
112  if (len > 13)
113  return false;
114  char tmp[16];
115  for(int i = 0; i < len; ++i)
116  tmp[i] = str[i].toLatin1();
117  tmp[len] = 0;
118  return qt_get_hex_rgb(tmp, rgb);
119 }
#define rgb(r, g, b)
Definition: qcolor_p.cpp:130
bool qt_get_hex_rgb(const char *name, QRgb *rgb)
Definition: qcolor_p.cpp:76

◆ qt_get_named_rgb() [1/2]

bool qt_get_named_rgb ( const char *  name,
QRgb rgb 
)

Definition at line 306 of file qcolor_p.cpp.

Referenced by qt_get_colornames(), qt_get_rgb_val(), and QColor::setColorFromString().

307 {
308  int len = int(strlen(name));
309  if(len > 255)
310  return false;
311  char name_no_space[256];
312  int pos = 0;
313  for(int i = 0; i < len; i++) {
314  if(name[i] != '\t' && name[i] != ' ')
315  name_no_space[pos++] = name[i];
316  }
317  name_no_space[pos] = 0;
318 
319  return get_named_rgb(name_no_space, rgb);
320 }
static bool get_named_rgb(const char *name_no_space, QRgb *rgb)
Definition: qcolor_p.cpp:295
const char * name
#define rgb(r, g, b)
Definition: qcolor_p.cpp:130

◆ qt_get_named_rgb() [2/2]

bool qt_get_named_rgb ( const QChar name,
int  len,
QRgb rgb 
)

Definition at line 322 of file qcolor_p.cpp.

323 {
324  if(len > 255)
325  return false;
326  char name_no_space[256];
327  int pos = 0;
328  for(int i = 0; i < len; i++) {
329  if(name[i] != QLatin1Char('\t') && name[i] != QLatin1Char(' '))
330  name_no_space[pos++] = name[i].toLatin1();
331  }
332  name_no_space[pos] = 0;
333  return get_named_rgb(name_no_space, rgb);
334 }
static bool get_named_rgb(const char *name_no_space, QRgb *rgb)
Definition: qcolor_p.cpp:295
#define rgb(r, g, b)
Definition: qcolor_p.cpp:130
char toLatin1() const
Returns the Latin-1 character equivalent to the QChar, or 0.
Definition: qchar.h:376
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ qt_get_rgb_val()

uint qt_get_rgb_val ( const char *  name)

Definition at line 337 of file qcolor_p.cpp.

Referenced by qt_get_colornames().

338 {
339  QRgb r = 0;
341  return r;
342 }
unsigned int QRgb
Definition: qrgb.h:53
bool qt_get_named_rgb(const char *name, QRgb *rgb)
Definition: qcolor_p.cpp:306
const char * name

Variable Documentation

◆ rgbTbl

const struct RGBData rgbTbl[]
static

Referenced by get_named_rgb(), and qt_get_colornames().

◆ rgbTblSize

const int rgbTblSize = sizeof(rgbTbl) / sizeof(RGBData)
static

Definition at line 286 of file qcolor_p.cpp.

Referenced by get_named_rgb(), and qt_get_colornames().