1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 #include <QtGui/qrgb.h>
46 #include <QtCore/qnamespace.h>
47 #include <QtCore/qstringlist.h>
58 #ifndef QT_NO_DEBUG_STREAM
59 Q_GUI_EXPORT QDebug operator<<(QDebug, const QColor &);
61 #ifndef QT_NO_DATASTREAM
62 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QColor &);
63 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QColor &);
66 class Q_GUI_EXPORT QColor
69 enum Spec { Invalid, Rgb, Hsv, Cmyk, Hsl };
72 QColor(Qt::GlobalColor color);
73 QColor(int r, int g, int b, int a = 255);
75 QColor(const QString& name);
76 QColor(const char *name);
77 QColor(const QColor &color);
83 void setNamedColor(const QString& name);
85 static QStringList colorNames();
87 inline Spec spec() const
91 void setAlpha(int alpha);
94 void setAlphaF(qreal alpha);
100 void setGreen(int green);
101 void setBlue(int blue);
104 qreal greenF() const;
106 void setRedF(qreal red);
107 void setGreenF(qreal green);
108 void setBlueF(qreal blue);
110 void getRgb(int *r, int *g, int *b, int *a = 0) const;
111 void setRgb(int r, int g, int b, int a = 255);
113 void getRgbF(qreal *r, qreal *g, qreal *b, qreal *a = 0) const;
114 void setRgbF(qreal r, qreal g, qreal b, qreal a = 1.0);
117 void setRgba(QRgb rgba);
120 void setRgb(QRgb rgb);
122 int hue() const; // 0 <= hue < 360
123 int saturation() const;
124 int hsvHue() const; // 0 <= hue < 360
125 int hsvSaturation() const;
128 qreal hueF() const; // 0.0 <= hueF < 360.0
129 qreal saturationF() const;
130 qreal hsvHueF() const; // 0.0 <= hueF < 360.0
131 qreal hsvSaturationF() const;
132 qreal valueF() const;
134 void getHsv(int *h, int *s, int *v, int *a = 0) const;
135 void setHsv(int h, int s, int v, int a = 255);
137 void getHsvF(qreal *h, qreal *s, qreal *v, qreal *a = 0) const;
138 void setHsvF(qreal h, qreal s, qreal v, qreal a = 1.0);
146 qreal magentaF() const;
147 qreal yellowF() const;
148 qreal blackF() const;
150 void getCmyk(int *c, int *m, int *y, int *k, int *a = 0);
151 void setCmyk(int c, int m, int y, int k, int a = 255);
153 void getCmykF(qreal *c, qreal *m, qreal *y, qreal *k, qreal *a = 0);
154 void setCmykF(qreal c, qreal m, qreal y, qreal k, qreal a = 1.0);
156 int hslHue() const; // 0 <= hue < 360
157 int hslSaturation() const;
158 int lightness() const;
160 qreal hslHueF() const; // 0.0 <= hueF < 360.0
161 qreal hslSaturationF() const;
162 qreal lightnessF() const;
164 void getHsl(int *h, int *s, int *l, int *a = 0) const;
165 void setHsl(int h, int s, int l, int a = 255);
167 void getHslF(qreal *h, qreal *s, qreal *l, qreal *a = 0) const;
168 void setHslF(qreal h, qreal s, qreal l, qreal a = 1.0);
170 QColor toRgb() const;
171 QColor toHsv() const;
172 QColor toCmyk() const;
173 QColor toHsl() const;
175 QColor convertTo(Spec colorSpec) const;
177 static QColor fromRgb(QRgb rgb);
178 static QColor fromRgba(QRgb rgba);
180 static QColor fromRgb(int r, int g, int b, int a = 255);
181 static QColor fromRgbF(qreal r, qreal g, qreal b, qreal a = 1.0);
183 static QColor fromHsv(int h, int s, int v, int a = 255);
184 static QColor fromHsvF(qreal h, qreal s, qreal v, qreal a = 1.0);
186 static QColor fromCmyk(int c, int m, int y, int k, int a = 255);
187 static QColor fromCmykF(qreal c, qreal m, qreal y, qreal k, qreal a = 1.0);
189 static QColor fromHsl(int h, int s, int l, int a = 255);
190 static QColor fromHslF(qreal h, qreal s, qreal l, qreal a = 1.0);
192 QColor light(int f = 150) const;
193 QColor lighter(int f = 150) const;
194 QColor dark(int f = 200) const;
195 QColor darker(int f = 200) const;
197 QColor &operator=(const QColor &);
198 QColor &operator=(Qt::GlobalColor color);
200 bool operator==(const QColor &c) const;
201 bool operator!=(const QColor &c) const;
203 operator QVariant() const;
205 static bool isValidColor(const QString &name);
210 bool setColorFromString(const QString &name);
245 friend class QColormap;
246 #ifndef QT_NO_DATASTREAM
247 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QColor &);
248 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QColor &);
252 inline QColor::QColor()
255 inline QColor::QColor(int r, int g, int b, int a)
256 { setRgb(r, g, b, a); }
258 inline QColor::QColor(const char *aname)
259 { setNamedColor(QLatin1String(aname)); }
261 inline QColor::QColor(const QString& aname)
262 { setNamedColor(aname); }
264 inline QColor::QColor(const QColor &acolor)
265 : cspec(acolor.cspec)
266 { ct.argb = acolor.ct.argb; }
268 inline bool QColor::isValid() const
269 { return cspec != Invalid; }
271 inline QColor QColor::lighter(int f) const
274 inline QColor QColor::darker(int f) const