~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to src/gui/painting/qcolor.h

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the QtGui module of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
9
** Commercial License Usage
 
10
** Licensees holding valid commercial Qt licenses may use this file in
 
11
** accordance with the commercial license agreement provided with the
 
12
** Software or, alternatively, in accordance with the terms contained in
 
13
** a written agreement between you and Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/contact-us.
 
16
**
 
17
** GNU Lesser General Public License Usage
 
18
** Alternatively, this file may be used under the terms of the GNU Lesser
 
19
** General Public License version 2.1 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL included in the
 
21
** packaging of this file.  Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 2.1 requirements
 
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#ifndef QCOLOR_H
 
43
#define QCOLOR_H
 
44
 
 
45
#include <QtGui/qrgb.h>
 
46
#include <QtCore/qnamespace.h>
 
47
#include <QtCore/qstringlist.h>
 
48
 
 
49
QT_BEGIN_HEADER
 
50
 
 
51
QT_BEGIN_NAMESPACE
 
52
 
 
53
 
 
54
class QColor;
 
55
class QColormap;
 
56
class QVariant;
 
57
 
 
58
#ifndef QT_NO_DEBUG_STREAM
 
59
Q_GUI_EXPORT QDebug operator<<(QDebug, const QColor &);
 
60
#endif
 
61
#ifndef QT_NO_DATASTREAM
 
62
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QColor &);
 
63
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QColor &);
 
64
#endif
 
65
 
 
66
class Q_GUI_EXPORT QColor
 
67
{
 
68
public:
 
69
    enum Spec { Invalid, Rgb, Hsv, Cmyk, Hsl };
 
70
 
 
71
    QColor();
 
72
    QColor(Qt::GlobalColor color);
 
73
    QColor(int r, int g, int b, int a = 255);
 
74
    QColor(QRgb rgb);
 
75
    QColor(const QString& name);
 
76
    QColor(const char *name);
 
77
    QColor(const QColor &color);
 
78
    QColor(Spec spec);
 
79
 
 
80
    bool isValid() const;
 
81
 
 
82
    QString name() const;
 
83
    void setNamedColor(const QString& name);
 
84
 
 
85
    static QStringList colorNames();
 
86
 
 
87
    inline Spec spec() const
 
88
    { return cspec; }
 
89
 
 
90
    int alpha() const;
 
91
    void setAlpha(int alpha);
 
92
 
 
93
    qreal alphaF() const;
 
94
    void setAlphaF(qreal alpha);
 
95
 
 
96
    int red() const;
 
97
    int green() const;
 
98
    int blue() const;
 
99
    void setRed(int red);
 
100
    void setGreen(int green);
 
101
    void setBlue(int blue);
 
102
 
 
103
    qreal redF() const;
 
104
    qreal greenF() const;
 
105
    qreal blueF() const;
 
106
    void setRedF(qreal red);
 
107
    void setGreenF(qreal green);
 
108
    void setBlueF(qreal blue);
 
109
 
 
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);
 
112
 
 
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);
 
115
 
 
116
    QRgb rgba() const;
 
117
    void setRgba(QRgb rgba);
 
118
 
 
119
    QRgb rgb() const;
 
120
    void setRgb(QRgb rgb);
 
121
 
 
122
    int hue() const; // 0 <= hue < 360
 
123
    int saturation() const;
 
124
    int hsvHue() const; // 0 <= hue < 360
 
125
    int hsvSaturation() const;
 
126
    int value() const;
 
127
 
 
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;
 
133
 
 
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);
 
136
 
 
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);
 
139
 
 
140
    int cyan() const;
 
141
    int magenta() const;
 
142
    int yellow() const;
 
143
    int black() const;
 
144
 
 
145
    qreal cyanF() const;
 
146
    qreal magentaF() const;
 
147
    qreal yellowF() const;
 
148
    qreal blackF() const;
 
149
 
 
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);
 
152
 
 
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);
 
155
 
 
156
    int hslHue() const; // 0 <= hue < 360
 
157
    int hslSaturation() const;
 
158
    int lightness() const;
 
159
 
 
160
    qreal hslHueF() const; // 0.0 <= hueF < 360.0
 
161
    qreal hslSaturationF() const;
 
162
    qreal lightnessF() const;
 
163
 
 
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);
 
166
 
 
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);
 
169
 
 
170
    QColor toRgb() const;
 
171
    QColor toHsv() const;
 
172
    QColor toCmyk() const;
 
173
    QColor toHsl() const;
 
174
 
 
175
    QColor convertTo(Spec colorSpec) const;
 
176
 
 
177
    static QColor fromRgb(QRgb rgb);
 
178
    static QColor fromRgba(QRgb rgba);
 
179
 
 
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);
 
182
 
 
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);
 
185
 
 
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);
 
188
 
 
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);
 
191
 
 
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;
 
196
 
 
197
    QColor &operator=(const QColor &);
 
198
    QColor &operator=(Qt::GlobalColor color);
 
199
 
 
200
    bool operator==(const QColor &c) const;
 
201
    bool operator!=(const QColor &c) const;
 
202
 
 
203
    operator QVariant() const;
 
204
 
 
205
    static bool isValidColor(const QString &name);
 
206
 
 
207
private:
 
208
 
 
209
    void invalidate();
 
210
    bool setColorFromString(const QString &name);
 
211
 
 
212
    Spec cspec;
 
213
    union {
 
214
        struct {
 
215
            ushort alpha;
 
216
            ushort red;
 
217
            ushort green;
 
218
            ushort blue;
 
219
            ushort pad;
 
220
        } argb;
 
221
        struct {
 
222
            ushort alpha;
 
223
            ushort hue;
 
224
            ushort saturation;
 
225
            ushort value;
 
226
            ushort pad;
 
227
        } ahsv;
 
228
        struct {
 
229
            ushort alpha;
 
230
            ushort cyan;
 
231
            ushort magenta;
 
232
            ushort yellow;
 
233
            ushort black;
 
234
        } acmyk;
 
235
        struct {
 
236
            ushort alpha;
 
237
            ushort hue;
 
238
            ushort saturation;
 
239
            ushort lightness;
 
240
            ushort pad;
 
241
        } ahsl;
 
242
        ushort array[5];
 
243
    } ct;
 
244
 
 
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 &);
 
249
#endif
 
250
};
 
251
 
 
252
inline QColor::QColor()
 
253
{ invalidate(); }
 
254
 
 
255
inline QColor::QColor(int r, int g, int b, int a)
 
256
{ setRgb(r, g, b, a); }
 
257
 
 
258
inline QColor::QColor(const char *aname)
 
259
{ setNamedColor(QLatin1String(aname)); }
 
260
 
 
261
inline QColor::QColor(const QString& aname)
 
262
{ setNamedColor(aname); }
 
263
 
 
264
inline QColor::QColor(const QColor &acolor)
 
265
    : cspec(acolor.cspec)
 
266
{ ct.argb = acolor.ct.argb; }
 
267
 
 
268
inline bool QColor::isValid() const
 
269
{ return cspec != Invalid; }
 
270
 
 
271
inline QColor QColor::lighter(int f) const 
 
272
{ return light(f); }
 
273
 
 
274
inline QColor QColor::darker(int f) const 
 
275
{ return dark(f); }
 
276
 
 
277
QT_END_NAMESPACE
 
278
 
 
279
QT_END_HEADER
 
280
 
 
281
#endif // QCOLOR_H