Eneboo - Documentación para desarrolladores
|
00001 /**************************************************************************** 00002 ** $Id: qt/qcolor.h 3.3.8 edited Jan 11 14:38 $ 00003 ** 00004 ** Definition of QColor class 00005 ** 00006 ** Created : 940112 00007 ** 00008 ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved. 00009 ** 00010 ** This file is part of the kernel module of the Qt GUI Toolkit. 00011 ** 00012 ** This file may be distributed under the terms of the Q Public License 00013 ** as defined by Trolltech ASA of Norway and appearing in the file 00014 ** LICENSE.QPL included in the packaging of this file. 00015 ** 00016 ** This file may be distributed and/or modified under the terms of the 00017 ** GNU General Public License version 2 as published by the Free Software 00018 ** Foundation and appearing in the file LICENSE.GPL included in the 00019 ** packaging of this file. 00020 ** 00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 00022 ** licenses may use this file in accordance with the Qt Commercial License 00023 ** Agreement provided with the Software. 00024 ** 00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00027 ** 00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 00029 ** information about Qt Commercial License Agreements. 00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information. 00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 00032 ** 00033 ** Contact info@trolltech.com if any conditions of this licensing are 00034 ** not clear to you. 00035 ** 00036 **********************************************************************/ 00037 00038 #ifndef QCOLOR_H 00039 #define QCOLOR_H 00040 00041 #ifndef QT_H 00042 #include "qwindowdefs.h" 00043 #include "qstringlist.h" 00044 #endif // QT_H 00045 00046 const QRgb RGB_MASK = 0x00ffffff; // masks RGB values 00047 00048 Q_EXPORT inline int qRed( QRgb rgb ) // get red part of RGB 00049 { return (int)((rgb >> 16) & 0xff); } 00050 00051 Q_EXPORT inline int qGreen( QRgb rgb ) // get green part of RGB 00052 { return (int)((rgb >> 8) & 0xff); } 00053 00054 Q_EXPORT inline int qBlue( QRgb rgb ) // get blue part of RGB 00055 { return (int)(rgb & 0xff); } 00056 00057 Q_EXPORT inline int qAlpha( QRgb rgb ) // get alpha part of RGBA 00058 { return (int)((rgb >> 24) & 0xff); } 00059 00060 Q_EXPORT inline QRgb qRgb( int r, int g, int b )// set RGB value 00061 { return (0xff << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); } 00062 00063 Q_EXPORT inline QRgb qRgba( int r, int g, int b, int a )// set RGBA value 00064 { return ((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); } 00065 00066 Q_EXPORT inline int qGray( int r, int g, int b )// convert R,G,B to gray 0..255 00067 { return (r*11+g*16+b*5)/32; } 00068 00069 Q_EXPORT inline int qGray( QRgb rgb ) // convert RGB to gray 0..255 00070 { return qGray( qRed(rgb), qGreen(rgb), qBlue(rgb) ); } 00071 00072 00073 class Q_EXPORT QColor 00074 { 00075 public: 00076 enum Spec { Rgb, Hsv }; 00077 00078 QColor(); 00079 QColor( int r, int g, int b ); 00080 QColor( int x, int y, int z, Spec ); 00081 QColor( QRgb rgb, uint pixel=0xffffffff); 00082 QColor( const QString& name ); 00083 QColor( const char *name ); 00084 QColor( const QColor & ); 00085 QColor &operator=( const QColor & ); 00086 00087 bool isValid() const; 00088 bool isDirty() const; 00089 QString name() const; 00090 void setNamedColor( const QString& name ); 00091 00092 QRgb rgb() const; 00093 void setRgb( int r, int g, int b ); 00094 void setRgb( QRgb rgb ); 00095 void getRgb( int *r, int *g, int *b ) const { rgb( r, g, b ); } 00096 void rgb( int *r, int *g, int *b ) const; // obsolete 00097 00098 int red() const; 00099 int green() const; 00100 int blue() const; 00101 00102 void setHsv( int h, int s, int v ); 00103 void getHsv( int *h, int *s, int *v ) const { hsv( h, s, v ); } 00104 void hsv( int *h, int *s, int *v ) const; // obsolete 00105 void getHsv( int &h, int &s, int &v ) const { hsv( &h, &s, &v ); } // obsolete 00106 00107 QColor light( int f = 150 ) const; 00108 QColor dark( int f = 200 ) const; 00109 00110 bool operator==( const QColor &c ) const; 00111 bool operator!=( const QColor &c ) const; 00112 00113 uint alloc(); 00114 uint pixel() const; 00115 00116 #if defined(Q_WS_X11) 00117 // ### in 4.0, make this take a default argument of -1 for default screen? 00118 uint alloc( int screen ); 00119 uint pixel( int screen ) const; 00120 #endif 00121 00122 static int maxColors(); 00123 static int numBitPlanes(); 00124 00125 static int enterAllocContext(); 00126 static void leaveAllocContext(); 00127 static int currentAllocContext(); 00128 static void destroyAllocContext( int ); 00129 00130 #if defined(Q_WS_WIN) 00131 static const QRgb* palette( int* numEntries = 0 ); 00132 static int setPaletteEntries( const QRgb* entries, int numEntries, 00133 int base = -1 ); 00134 static HPALETTE hPal() { return hpal; } 00135 static uint realizePal( QWidget * ); 00136 #endif 00137 00138 static void initialize(); 00139 static void cleanup(); 00140 #ifndef QT_NO_STRINGLIST 00141 static QStringList colorNames(); 00142 #endif 00143 enum { Dirt = 0x44495254, Invalid = 0x49000000 }; 00144 00145 private: 00146 void setSystemNamedColor( const QString& name ); 00147 void setPixel( uint pixel ); 00148 static void initGlobalColors(); 00149 static uint argbToPix32(QRgb); 00150 static QColor* globalColors(); 00151 static bool color_init; 00152 static bool globals_init; 00153 #if defined(Q_WS_WIN) 00154 static HPALETTE hpal; 00155 #endif 00156 static enum ColorModel { d8, d32 } colormodel; 00157 union { 00158 QRgb argb; 00159 struct D8 { 00160 QRgb argb; 00161 uchar pix; 00162 uchar invalid; 00163 uchar dirty; 00164 uchar direct; 00165 } d8; 00166 struct D32 { 00167 QRgb argb; 00168 uint pix; 00169 bool invalid() const { return argb == QColor::Invalid && pix == QColor::Dirt; } 00170 bool probablyDirty() const { return pix == QColor::Dirt; } 00171 } d32; 00172 } d; 00173 }; 00174 00175 00176 inline QColor::QColor() 00177 { d.d32.argb = Invalid; d.d32.pix = Dirt; } 00178 00179 inline QColor::QColor( int r, int g, int b ) 00180 { 00181 d.d32.argb = Invalid; 00182 d.d32.pix = Dirt; 00183 setRgb( r, g, b ); 00184 } 00185 00186 inline QRgb QColor::rgb() const 00187 { return d.argb; } 00188 00189 inline int QColor::red() const 00190 { return qRed(d.argb); } 00191 00192 inline int QColor::green() const 00193 { return qGreen(d.argb); } 00194 00195 inline int QColor::blue() const 00196 { return qBlue(d.argb); } 00197 00198 inline bool QColor::isValid() const 00199 { 00200 if ( colormodel == d8 ) 00201 return !d.d8.invalid; 00202 else 00203 return !d.d32.invalid(); 00204 } 00205 00206 inline bool QColor::operator==( const QColor &c ) const 00207 { 00208 return d.argb == c.d.argb && isValid() == c.isValid(); 00209 } 00210 00211 inline bool QColor::operator!=( const QColor &c ) const 00212 { 00213 return !operator==(c); 00214 } 00215 00216 00217 /***************************************************************************** 00218 QColor stream functions 00219 *****************************************************************************/ 00220 00221 #ifndef QT_NO_DATASTREAM 00222 Q_EXPORT QDataStream &operator<<( QDataStream &, const QColor & ); 00223 Q_EXPORT QDataStream &operator>>( QDataStream &, QColor & ); 00224 #endif 00225 00226 #endif // QCOLOR_H