~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to ksplash/ksplashx/qcolor.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** This file is based on sources of the Qt GUI Toolkit, used under the terms
 
4
** of the GNU General Public License version 2 (see the original copyright
 
5
** notice below).
 
6
** All further contributions to this file are (and are required to be)
 
7
** licensed under the terms of the GNU General Public License as published by
 
8
** the Free Software Foundation; either version 2 of the License, or
 
9
** (at your option) any later version.
 
10
**
 
11
** The original Qt license header follows:
 
12
** 
 
13
**
 
14
** Definition of QColor class
 
15
**
 
16
** Created : 940112
 
17
**
 
18
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
 
19
**
 
20
** This file is part of the kernel module of the Qt GUI Toolkit.
 
21
**
 
22
** This file may be distributed under the terms of the Q Public License
 
23
** as defined by Trolltech AS of Norway and appearing in the file
 
24
** LICENSE.QPL included in the packaging of this file.
 
25
**
 
26
** This file may be distributed and/or modified under the terms of the
 
27
** GNU General Public License version 2 as published by the Free Software
 
28
** Foundation and appearing in the file LICENSE.GPL included in the
 
29
** packaging of this file.
 
30
**
 
31
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
 
32
** licenses may use this file in accordance with the Qt Commercial License
 
33
** Agreement provided with the Software.
 
34
**
 
35
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
36
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
37
**
 
38
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
39
**   information about Qt Commercial License Agreements.
 
40
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
41
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
42
**
 
43
** Contact info@trolltech.com if any conditions of this licensing are
 
44
** not clear to you.
 
45
**
 
46
**********************************************************************/
 
47
 
 
48
#ifndef QCOLOR_H
 
49
#define QCOLOR_H
 
50
 
 
51
#ifndef QT_H
 
52
#include "qwindowdefs.h"
 
53
//##include "qstringlist.h"
 
54
#endif // QT_H
 
55
 
 
56
const QRgb  RGB_MASK    = 0x00ffffff;           // masks RGB values
 
57
 
 
58
Q_EXPORT inline int qRed( QRgb rgb )            // get red part of RGB
 
59
{ return (int)((rgb >> 16) & 0xff); }
 
60
 
 
61
Q_EXPORT inline int qGreen( QRgb rgb )          // get green part of RGB
 
62
{ return (int)((rgb >> 8) & 0xff); }
 
63
 
 
64
Q_EXPORT inline int qBlue( QRgb rgb )           // get blue part of RGB
 
65
{ return (int)(rgb & 0xff); }
 
66
 
 
67
Q_EXPORT inline int qAlpha( QRgb rgb )          // get alpha part of RGBA
 
68
{ return (int)((rgb >> 24) & 0xff); }
 
69
 
 
70
Q_EXPORT inline QRgb qRgb( int r, int g, int b )// set RGB value
 
71
{ return (0xff << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); }
 
72
 
 
73
Q_EXPORT inline QRgb qRgba( int r, int g, int b, int a )// set RGBA value
 
74
{ return ((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); }
 
75
 
 
76
Q_EXPORT inline int qGray( int r, int g, int b )// convert R,G,B to gray 0..255
 
77
{ return (r*11+g*16+b*5)/32; }
 
78
 
 
79
Q_EXPORT inline int qGray( QRgb rgb )           // convert RGB to gray 0..255
 
80
{ return qGray( qRed(rgb), qGreen(rgb), qBlue(rgb) ); }
 
81
 
 
82
 
 
83
class Q_EXPORT QColor
 
84
{
 
85
public:
 
86
    enum Spec { Rgb, Hsv };
 
87
 
 
88
    QColor();
 
89
    QColor( int r, int g, int b );
 
90
    QColor( int x, int y, int z, Spec );
 
91
    explicit QColor( QRgb rgb, uint pixel=0xffffffff);
 
92
#if 0
 
93
    QColor( const QString& name );
 
94
#endif
 
95
    explicit QColor( const char *name );
 
96
    QColor( const QColor & );
 
97
    QColor &operator=( const QColor & );
 
98
 
 
99
    bool   isValid() const;
 
100
    bool   isDirty() const;
 
101
#if 0
 
102
    QString name() const;
 
103
    void   setNamedColor( const QString& name );
 
104
#else
 
105
    void   setNamedColor( const char* name );
 
106
#endif
 
107
 
 
108
    QRgb   rgb()    const;
 
109
    void   setRgb( int r, int g, int b );
 
110
    void   setRgb( QRgb rgb );
 
111
    void   getRgb( int *r, int *g, int *b ) const { rgb( r, g, b ); }
 
112
    void   rgb( int *r, int *g, int *b ) const; // obsolete
 
113
 
 
114
    int    red()    const;
 
115
    int    green()  const;
 
116
    int    blue()   const;
 
117
 
 
118
    void   setHsv( int h, int s, int v );
 
119
    void   getHsv( int *h, int *s, int *v ) const { hsv( h, s, v ); }
 
120
    void   hsv( int *h, int *s, int *v ) const; // obsolete
 
121
    void   getHsv( int &h, int &s, int &v ) const { hsv( &h, &s, &v ); } // obsolete
 
122
 
 
123
    QColor light( int f = 150 ) const;
 
124
    QColor dark( int f = 200 )  const;
 
125
 
 
126
    bool   operator==( const QColor &c ) const;
 
127
    bool   operator!=( const QColor &c ) const;
 
128
 
 
129
    uint   alloc();
 
130
    uint   pixel()  const;
 
131
 
 
132
#if defined(Q_WS_X11)
 
133
    // ### in 4.0, make this take a default argument of -1 for default screen?
 
134
    uint alloc( int screen );
 
135
    uint pixel( int screen ) const;
 
136
#endif
 
137
 
 
138
    static int  maxColors();
 
139
    static int  numBitPlanes();
 
140
 
 
141
    static int  enterAllocContext();
 
142
    static void leaveAllocContext();
 
143
    static int  currentAllocContext();
 
144
    static void destroyAllocContext( int );
 
145
 
 
146
#if defined(Q_WS_WIN)
 
147
    static const QRgb* palette( int* numEntries = 0 );
 
148
    static int setPaletteEntries( const QRgb* entries, int numEntries,
 
149
                                  int base = -1 );
 
150
    static HPALETTE hPal()  { return hpal; }
 
151
    static uint realizePal( QWidget * );
 
152
#endif
 
153
 
 
154
    static void initialize();
 
155
    static void cleanup();
 
156
#ifndef QT_NO_STRINGLIST
 
157
    static QStringList colorNames();
 
158
#endif
 
159
    enum { Dirt = 0x44495254, Invalid = 0x49000000 };
 
160
 
 
161
private:
 
162
#if 0
 
163
    void setSystemNamedColor( const QString& name );
 
164
#else
 
165
    void setSystemNamedColor( const char* name );
 
166
#endif
 
167
    void setPixel( uint pixel );
 
168
    static void initGlobalColors();
 
169
    static uint argbToPix32(QRgb);
 
170
    static QColor* globalColors();
 
171
    static bool color_init;
 
172
    static bool globals_init;
 
173
#if defined(Q_WS_WIN)
 
174
    static HPALETTE hpal;
 
175
#endif
 
176
    static enum ColorModel { d8, d32 } colormodel;
 
177
    union {
 
178
        QRgb argb;
 
179
        struct D8 {
 
180
            QRgb argb;
 
181
            uchar pix;
 
182
            uchar invalid;
 
183
            uchar dirty;
 
184
            uchar direct;
 
185
        } d8;
 
186
        struct D32 {
 
187
            QRgb argb;
 
188
            uint pix;
 
189
            bool invalid() const { return argb == QColor::Invalid && pix == QColor::Dirt; }
 
190
            bool probablyDirty() const { return pix == QColor::Dirt; }
 
191
        } d32;
 
192
    } d;
 
193
};
 
194
 
 
195
 
 
196
inline QColor::QColor()
 
197
{ d.d32.argb = Invalid; d.d32.pix = Dirt; }
 
198
 
 
199
inline QColor::QColor( int r, int g, int b )
 
200
{
 
201
    d.d32.argb = Invalid;
 
202
    d.d32.pix = Dirt;
 
203
    setRgb( r, g, b );
 
204
}
 
205
 
 
206
inline QRgb QColor::rgb() const
 
207
{ return d.argb; }
 
208
 
 
209
inline int QColor::red() const
 
210
{ return qRed(d.argb); }
 
211
 
 
212
inline int QColor::green() const
 
213
{ return qGreen(d.argb); }
 
214
 
 
215
inline int QColor::blue() const
 
216
{ return qBlue(d.argb); }
 
217
 
 
218
inline bool QColor::isValid() const
 
219
{
 
220
    if ( colormodel == d8 )
 
221
        return !d.d8.invalid;
 
222
    else
 
223
        return !d.d32.invalid();
 
224
}
 
225
 
 
226
inline bool QColor::operator==( const QColor &c ) const
 
227
{
 
228
    return d.argb == c.d.argb && isValid() == c.isValid();
 
229
}
 
230
 
 
231
inline bool QColor::operator!=( const QColor &c ) const
 
232
{
 
233
    return !operator==(c);
 
234
}
 
235
 
 
236
 
 
237
/*****************************************************************************
 
238
  QColor stream functions
 
239
 *****************************************************************************/
 
240
 
 
241
#ifndef QT_NO_DATASTREAM
 
242
Q_EXPORT QDataStream &operator<<( QDataStream &, const QColor & );
 
243
Q_EXPORT QDataStream &operator>>( QDataStream &, QColor & );
 
244
#endif
 
245
 
 
246
#endif // QCOLOR_H