• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KHTML

Color.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003-6 Apple Computer, Inc.  All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  * 1. Redistributions of source code must retain the above copyright
00008  *    notice, this list of conditions and the following disclaimer.
00009  * 2. Redistributions in binary form must reproduce the above copyright
00010  *    notice, this list of conditions and the following disclaimer in the
00011  *    documentation and/or other materials provided with the distribution.
00012  *
00013  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
00014  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00015  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00016  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
00017  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00018  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00019  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00020  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00021  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00022  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00023  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00024  */
00025 
00026 #ifndef Color_h
00027 #define Color_h
00028 
00029 #include <wtf/Platform.h>
00030 #include "PlatformString.h"
00031 
00032 #if PLATFORM(CG)
00033 typedef struct CGColor* CGColorRef;
00034 #endif
00035 
00036 #if PLATFORM(QT)
00037 #include <qglobal.h>
00038 QT_BEGIN_NAMESPACE
00039 class QColor;
00040 QT_END_NAMESPACE
00041 #endif
00042 
00043 #if PLATFORM(GTK)
00044 typedef struct _GdkColor GdkColor;
00045 #endif
00046 
00047 #if PLATFORM(WX)
00048 class wxColour;
00049 #endif
00050 
00051 namespace WebCore {
00052 
00053 //class String;
00054 class Color;
00055 
00056 typedef unsigned RGBA32;        // RGBA quadruplet
00057 
00058 RGBA32 makeRGB(int r, int g, int b);
00059 RGBA32 makeRGBA(int r, int g, int b, int a);
00060 RGBA32 makeRGBAFromHSLA(double h, double s, double l, double a);
00061 
00062 int differenceSquared(const Color&, const Color&);
00063 
00064 class Color {
00065 public:
00066     Color() : m_color(0), m_valid(false) { }
00067     Color(RGBA32 col) : m_color(col), m_valid(true) { }
00068     Color(int r, int g, int b) : m_color(makeRGB(r, g, b)), m_valid(true) { }
00069     Color(int r, int g, int b, int a) : m_color(makeRGBA(r, g, b, a)), m_valid(true) { }
00070     explicit Color(const String&);
00071     explicit Color(const char*);
00072     
00073     String name() const;
00074     void setNamedColor(const String&);
00075 
00076     bool isValid() const { return m_valid; }
00077 
00078     bool hasAlpha() const { return alpha() < 255; }
00079 
00080     int red() const { return (m_color >> 16) & 0xFF; }
00081     int green() const { return (m_color >> 8) & 0xFF; }
00082     int blue() const { return m_color & 0xFF; }
00083     int alpha() const { return (m_color >> 24) & 0xFF; }
00084     
00085     RGBA32 rgb() const { return m_color; } // Preserve the alpha.
00086     void setRGB(int r, int g, int b) { m_color = makeRGB(r, g, b); m_valid = true; }
00087     void setRGB(RGBA32 rgb) { m_color = rgb; m_valid = true; }
00088     void getRGBA(float& r, float& g, float& b, float& a) const;
00089     void getRGBA(double& r, double& g, double& b, double& a) const;
00090 
00091     Color light() const;
00092     Color dark() const;
00093 
00094     Color blend(const Color&) const;
00095     Color blendWithWhite() const;
00096 
00097 #if PLATFORM(QT)
00098     Color(const QColor&);
00099     operator QColor() const;
00100 #endif
00101 
00102 #if PLATFORM(GTK)
00103     Color(const GdkColor&);
00104     // We can't sensibly go back to GdkColor without losing the alpha value
00105 #endif
00106 
00107 #if PLATFORM(WX)
00108     Color(const wxColour&);
00109     operator wxColour() const;
00110 #endif
00111 
00112 #if PLATFORM(CG)
00113     Color(CGColorRef);
00114 #endif
00115 
00116     static bool parseHexColor(const String& name, RGBA32& rgb);
00117 
00118     static const RGBA32 black = 0xFF000000;
00119     static const RGBA32 white = 0xFFFFFFFF;
00120     static const RGBA32 darkGray = 0xFF808080;
00121     static const RGBA32 gray = 0xFFA0A0A0;
00122     static const RGBA32 lightGray = 0xFFC0C0C0;
00123     static const RGBA32 transparent = 0x00000000;
00124 
00125 private:
00126     RGBA32 m_color;
00127     bool m_valid : 1;
00128 };
00129 
00130 inline bool operator==(const Color& a, const Color& b)
00131 {
00132     return a.rgb() == b.rgb() && a.isValid() == b.isValid();
00133 }
00134 
00135 inline bool operator!=(const Color& a, const Color& b)
00136 {
00137     return !(a == b);
00138 }
00139 
00140 Color focusRingColor();
00141 void setFocusRingColorChangeFunction(void (*)());
00142 
00143 #if PLATFORM(CG)
00144 CGColorRef cgColor(const Color&);
00145 #endif
00146 
00147 } // namespace WebCore
00148 
00149 #endif // Color_h

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal