00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef QCOLOR_H
00025 #define QCOLOR_H
00026
00027 #include <QtGui/qrgb.h>
00028 #include <QtCore/qnamespace.h>
00029 #include <QtCore/qstringlist.h>
00030
00031 QT_BEGIN_HEADER
00032
00033 QT_MODULE(Gui)
00034
00035 class QColor;
00036 class QColormap;
00037 class QVariant;
00038
00039 #ifndef QT_NO_DEBUG_STREAM
00040 Q_GUI_EXPORT QDebug operator<<(QDebug, const QColor &);
00041 #endif
00042 #ifndef QT_NO_DATASTREAM
00043 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QColor &);
00044 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QColor &);
00045 #endif
00046
00047 class Q_GUI_EXPORT QColor
00048 {
00049 public:
00050 enum Spec { Invalid, Rgb, Hsv, Cmyk };
00051
00052 QColor();
00053 QColor(Qt::GlobalColor color);
00054 QColor(int r, int g, int b, int a = 255);
00055 QColor(QRgb rgb);
00056 QColor(const QString& name);
00057 QColor(const char *name);
00058 QColor(const QColor &color);
00059 QColor(Spec spec);
00060
00061 bool isValid() const;
00062
00063 QString name() const;
00064 void setNamedColor(const QString& name);
00065
00066 static QStringList colorNames();
00067
00068 inline Spec spec() const
00069 { return cspec; }
00070
00071 int alpha() const;
00072 void setAlpha(int alpha);
00073
00074 qreal alphaF() const;
00075 void setAlphaF(qreal alpha);
00076
00077 int red() const;
00078 int green() const;
00079 int blue() const;
00080 void setRed(int red);
00081 void setGreen(int green);
00082 void setBlue(int blue);
00083
00084 qreal redF() const;
00085 qreal greenF() const;
00086 qreal blueF() const;
00087 void setRedF(qreal red);
00088 void setGreenF(qreal green);
00089 void setBlueF(qreal blue);
00090
00091 void getRgb(int *r, int *g, int *b, int *a = 0) const;
00092 void setRgb(int r, int g, int b, int a = 255);
00093
00094 void getRgbF(qreal *r, qreal *g, qreal *b, qreal *a = 0) const;
00095 void setRgbF(qreal r, qreal g, qreal b, qreal a = 1.0);
00096
00097 QRgb rgba() const;
00098 void setRgba(QRgb rgba);
00099
00100 QRgb rgb() const;
00101 void setRgb(QRgb rgb);
00102
00103 int hue() const;
00104 int saturation() const;
00105 int value() const;
00106
00107 qreal hueF() const;
00108 qreal saturationF() const;
00109 qreal valueF() const;
00110
00111 void getHsv(int *h, int *s, int *v, int *a = 0) const;
00112 void setHsv(int h, int s, int v, int a = 255);
00113
00114 void getHsvF(qreal *h, qreal *s, qreal *v, qreal *a = 0) const;
00115 void setHsvF(qreal h, qreal s, qreal v, qreal a = 1.0);
00116
00117 int cyan() const;
00118 int magenta() const;
00119 int yellow() const;
00120 int black() const;
00121
00122 qreal cyanF() const;
00123 qreal magentaF() const;
00124 qreal yellowF() const;
00125 qreal blackF() const;
00126
00127 void getCmyk(int *c, int *m, int *y, int *k, int *a = 0);
00128 void setCmyk(int c, int m, int y, int k, int a = 255);
00129
00130 void getCmykF(qreal *c, qreal *m, qreal *y, qreal *k, qreal *a = 0);
00131 void setCmykF(qreal c, qreal m, qreal y, qreal k, qreal a = 1.0);
00132
00133 QColor toRgb() const;
00134 QColor toHsv() const;
00135 QColor toCmyk() const;
00136
00137 QColor convertTo(Spec colorSpec) const;
00138
00139 static QColor fromRgb(QRgb rgb);
00140 static QColor fromRgba(QRgb rgba);
00141
00142 static QColor fromRgb(int r, int g, int b, int a = 255);
00143 static QColor fromRgbF(qreal r, qreal g, qreal b, qreal a = 1.0);
00144
00145 static QColor fromHsv(int h, int s, int v, int a = 255);
00146 static QColor fromHsvF(qreal h, qreal s, qreal v, qreal a = 1.0);
00147
00148 static QColor fromCmyk(int c, int m, int y, int k, int a = 255);
00149 static QColor fromCmykF(qreal c, qreal m, qreal y, qreal k, qreal a = 1.0);
00150
00151 QColor light(int f = 150) const;
00152 QColor dark(int f = 200) const;
00153
00154 QColor &operator=(const QColor &);
00155 QColor &operator=(Qt::GlobalColor color);
00156
00157 bool operator==(const QColor &c) const;
00158 bool operator!=(const QColor &c) const;
00159
00160 operator QVariant() const;
00161
00162 #ifdef QT3_SUPPORT
00163 inline QT3_SUPPORT_CONSTRUCTOR QColor(int x, int y, int z, Spec colorSpec)
00164 { if (colorSpec == Hsv) setHsv(x, y, z); else setRgb(x, y, z); }
00165
00166 inline QT3_SUPPORT void rgb(int *r, int *g, int *b) const
00167 { getRgb(r, g, b); }
00168 inline QT3_SUPPORT void hsv(int *h, int *s, int *v) const
00169 { getHsv(h, s, v); }
00170
00171 inline QT3_SUPPORT void setRgba(int r, int g, int b, int a)
00172 { setRgb(r, g, b, a); }
00173 inline QT3_SUPPORT void getRgba(int *r, int *g, int *b, int *a) const
00174 { getRgb(r, g, b, a); }
00175
00176 QT3_SUPPORT uint pixel(int screen = -1) const;
00177 #endif
00178
00179 private:
00180 #ifndef QT3_SUPPORT
00181
00182 QColor(int, int, int, Spec);
00183 #endif
00184
00185 void invalidate();
00186
00187 Spec cspec;
00188 union {
00189 struct {
00190 ushort alpha;
00191 ushort red;
00192 ushort green;
00193 ushort blue;
00194 ushort pad;
00195 } argb;
00196 struct {
00197 ushort alpha;
00198 ushort hue;
00199 ushort saturation;
00200 ushort value;
00201 ushort pad;
00202 } ahsv;
00203 struct {
00204 ushort alpha;
00205 ushort cyan;
00206 ushort magenta;
00207 ushort yellow;
00208 ushort black;
00209 } acmyk;
00210 } ct;
00211
00212 friend class QColormap;
00213 #ifndef QT_NO_DATASTREAM
00214 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QColor &);
00215 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QColor &);
00216 #endif
00217 };
00218
00219 inline QColor::QColor()
00220 { invalidate(); }
00221
00222 inline QColor::QColor(int r, int g, int b, int a)
00223 { setRgb(r, g, b, a); }
00224
00225 inline QColor::QColor(const char *aname)
00226 { setNamedColor(QLatin1String(aname)); }
00227
00228 inline QColor::QColor(const QString& aname)
00229 { setNamedColor(aname); }
00230
00231 inline QColor::QColor(const QColor &acolor)
00232 : cspec(acolor.cspec)
00233 { ct.argb = acolor.ct.argb; }
00234
00235 inline bool QColor::isValid() const
00236 { return cspec != Invalid; }
00237
00238 QT_END_HEADER
00239
00240 #endif // QCOLOR_H