#ifndef QCOLOR_H_
#define QCOLOR_H_
#include "KWQString.h"
#ifdef __OBJC__
@class NSColor;
#else
class NSColor;
#endif
typedef unsigned int QRgb;
QRgb qRgb(int r, int g, int b);
QRgb qRgba(int r, int g, int b, int a);
int qAlpha(QRgb rgba);
class QColor {
public:
QColor() : color(0), valid(false) { }
QColor(QRgb col) : color(col), valid(true) { }
QColor(int r, int g, int b) : color(qRgb(r, g, b)), valid(true) { }
explicit QColor(const char *);
QString name() const;
void setNamedColor(const QString&);
bool isValid() const { return valid; }
int red() const { return (color >> 16) & 0xFF; }
int green() const { return (color >> 8) & 0xFF; }
int blue() const { return color & 0xFF; }
int alpha() const { return (color >> 24) & 0xFF; }
QRgb rgb() const { return color & 0xFFFFFFFF; } void setRgb(int r, int g, int b) { color = qRgb(r, g, b); valid = true; }
void setRgb(int rgb) { color = rgb; valid = true; }
void hsv(int *, int *, int *) const;
void setHsv(int h, int s, int v);
QColor light(int f = 150) const;
QColor dark(int f = 200) const;
friend bool operator==(const QColor &a, const QColor &b);
friend bool operator!=(const QColor &a, const QColor &b);
NSColor *getNSColor() const;
private:
QRgb color;
bool valid : 1;
};
inline bool operator==(const QColor &a, const QColor &b)
{
return a.color == b.color && a.valid == b.valid;
}
inline bool operator!=(const QColor &a, const QColor &b)
{
return a.color != b.color || a.valid != b.valid;
}
#endif