not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / ksplash / ksplashx / qcolor.h
blobdeb973f450c70a76d2895f2fab958e8ef1fc694c
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.
11 ** The original Qt license header follows:
12 **
14 ** Definition of QColor class
16 ** Created : 940112
18 ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
20 ** This file is part of the kernel module of the Qt GUI Toolkit.
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.
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.
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.
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.
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.
43 ** Contact info@trolltech.com if any conditions of this licensing are
44 ** not clear to you.
46 **********************************************************************/
48 #ifndef QCOLOR_H
49 #define QCOLOR_H
51 #ifndef QT_H
52 #include "qwindowdefs.h"
53 //##include "qstringlist.h"
54 #endif // QT_H
56 const QRgb RGB_MASK = 0x00ffffff; // masks RGB values
58 Q_EXPORT inline int qRed( QRgb rgb ) // get red part of RGB
59 { return (int)((rgb >> 16) & 0xff); }
61 Q_EXPORT inline int qGreen( QRgb rgb ) // get green part of RGB
62 { return (int)((rgb >> 8) & 0xff); }
64 Q_EXPORT inline int qBlue( QRgb rgb ) // get blue part of RGB
65 { return (int)(rgb & 0xff); }
67 Q_EXPORT inline int qAlpha( QRgb rgb ) // get alpha part of RGBA
68 { return (int)((rgb >> 24) & 0xff); }
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); }
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); }
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; }
79 Q_EXPORT inline int qGray( QRgb rgb ) // convert RGB to gray 0..255
80 { return qGray( qRed(rgb), qGreen(rgb), qBlue(rgb) ); }
83 class Q_EXPORT QColor
85 public:
86 enum Spec { Rgb, Hsv };
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 & );
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
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
114 int red() const;
115 int green() const;
116 int blue() const;
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
123 QColor light( int f = 150 ) const;
124 QColor dark( int f = 200 ) const;
126 bool operator==( const QColor &c ) const;
127 bool operator!=( const QColor &c ) const;
129 uint alloc();
130 uint pixel() const;
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
138 static int maxColors();
139 static int numBitPlanes();
141 static int enterAllocContext();
142 static void leaveAllocContext();
143 static int currentAllocContext();
144 static void destroyAllocContext( int );
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
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 };
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;
196 inline QColor::QColor()
197 { d.d32.argb = Invalid; d.d32.pix = Dirt; }
199 inline QColor::QColor( int r, int g, int b )
201 d.d32.argb = Invalid;
202 d.d32.pix = Dirt;
203 setRgb( r, g, b );
206 inline QRgb QColor::rgb() const
207 { return d.argb; }
209 inline int QColor::red() const
210 { return qRed(d.argb); }
212 inline int QColor::green() const
213 { return qGreen(d.argb); }
215 inline int QColor::blue() const
216 { return qBlue(d.argb); }
218 inline bool QColor::isValid() const
220 if ( colormodel == d8 )
221 return !d.d8.invalid;
222 else
223 return !d.d32.invalid();
226 inline bool QColor::operator==( const QColor &c ) const
228 return d.argb == c.d.argb && isValid() == c.isValid();
231 inline bool QColor::operator!=( const QColor &c ) const
233 return !operator==(c);
237 /*****************************************************************************
238 QColor stream functions
239 *****************************************************************************/
241 #ifndef QT_NO_DATASTREAM
242 Q_EXPORT QDataStream &operator<<( QDataStream &, const QColor & );
243 Q_EXPORT QDataStream &operator>>( QDataStream &, QColor & );
244 #endif
246 #endif // QCOLOR_H