QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskRgbValue.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_RGB_VALUE_H
7#define QSK_RGB_VALUE_H
8
9#include "QskGlobal.h"
10#include "QskGradientStop.h"
11
12#include <qcolor.h>
13
14class QEasingCurve;
15class QImage;
16
17namespace QskRgb
18{
19 /* Web colors */
20
21 constexpr const QRgb AliceBlue = 0xfff0f8ff;
22 constexpr const QRgb AntiqueWhite = 0xfffaebd7;
23 constexpr const QRgb Aqua = 0xff00ffff;
24 constexpr const QRgb Aquamarine = 0xff7fffd4;
25 constexpr const QRgb Azure = 0xfff0ffff;
26 constexpr const QRgb Beige = 0xfff5f5dc;
27 constexpr const QRgb Bisque = 0xffffe4c4;
28 constexpr const QRgb Black = 0xff000000;
29 constexpr const QRgb BlanchedAlmond = 0xffffebcd;
30 constexpr const QRgb Blue = 0xff0000ff;
31 constexpr const QRgb BlueViolet = 0xff8a2be2;
32 constexpr const QRgb Brown = 0xffa52a2a;
33 constexpr const QRgb Burlywood = 0xffdeb887;
34 constexpr const QRgb CadetBlue = 0xff5f9ea0;
35 constexpr const QRgb Chartreuse = 0xff7fff00;
36 constexpr const QRgb Chocolate = 0xffd2691e;
37 constexpr const QRgb Coral = 0xffff7f50;
38 constexpr const QRgb CornflowerBlue = 0xff6495ed;
39 constexpr const QRgb Cornsilk = 0xfffff8dc;
40 constexpr const QRgb Crimson = 0xffdc143c;
41 constexpr const QRgb Cyan = 0xff00ffff;
42 constexpr const QRgb DarkBlue = 0xff00008b;
43 constexpr const QRgb DarkCyan = 0xff008b8b;
44 constexpr const QRgb DarkGoldenrod = 0xffb8860b;
45 constexpr const QRgb DarkGray = 0xffa9a9a9;
46 constexpr const QRgb DarkGreen = 0xff006400;
47 constexpr const QRgb DarkGrey = 0xffa9a9a9;
48 constexpr const QRgb DarkKhaki = 0xffbdb76b;
49 constexpr const QRgb DarkMagenta = 0xff8b008b;
50 constexpr const QRgb DarkOliveGreen = 0xff556b2f;
51 constexpr const QRgb DarkOrange = 0xffff8c00;
52 constexpr const QRgb DarkOrchid = 0xff9932cc;
53 constexpr const QRgb DarkRed = 0xff8b0000;
54 constexpr const QRgb DarkSalmon = 0xffe9967a;
55 constexpr const QRgb DarkSeaGreen = 0xff8fbc8f;
56 constexpr const QRgb DarkSlateBlue = 0xff483d8b;
57 constexpr const QRgb DarkSlateGray = 0xff2f4f4f;
58 constexpr const QRgb DarkSlateGrey = 0xff2f4f4f;
59 constexpr const QRgb DarkTurquoise = 0xff00ced1;
60 constexpr const QRgb DarkViolet = 0xff9400d3;
61 constexpr const QRgb DeepPink = 0xffff1493;
62 constexpr const QRgb DeepSkyBlue = 0xff00bfff;
63 constexpr const QRgb DimGray = 0xff696969;
64 constexpr const QRgb DimGrey = 0xff696969;
65 constexpr const QRgb DodgerBlue = 0xff1e90ff;
66 constexpr const QRgb FireBrick = 0xffb22222;
67 constexpr const QRgb FloralWhite = 0xfffffaf0;
68 constexpr const QRgb ForestGreen = 0xff228b22;
69 constexpr const QRgb Fuchsia = 0xffff00ff;
70 constexpr const QRgb Gainsboro = 0xffdcdcdc;
71 constexpr const QRgb GhostWhite = 0xfff8f8ff;
72 constexpr const QRgb Gold = 0xffffd700;
73 constexpr const QRgb Goldenrod = 0xffdaa520;
74 constexpr const QRgb Gray = 0xff808080;
75 constexpr const QRgb Green = 0xff008000;
76 constexpr const QRgb GreenYellow = 0xffadff2f;
77 constexpr const QRgb Grey = 0xff808080;
78 constexpr const QRgb Honeydew = 0xfff0fff0;
79 constexpr const QRgb HotPink = 0xffff69b4;
80 constexpr const QRgb IndianRed = 0xffcd5c5c;
81 constexpr const QRgb Indigo = 0xff4b0082;
82 constexpr const QRgb Ivory = 0xfffffff0;
83 constexpr const QRgb Khaki = 0xfff0e68c;
84 constexpr const QRgb Lavender = 0xffe6e6fa;
85 constexpr const QRgb LavenderBlush = 0xfffff0f5;
86 constexpr const QRgb LawnGreen = 0xff7cfc00;
87 constexpr const QRgb LemonChiffon = 0xfffffacd;
88 constexpr const QRgb LightBlue = 0xffadd8e6;
89 constexpr const QRgb LightCoral = 0xfff08080;
90 constexpr const QRgb LightCyan = 0xffe0ffff;
91 constexpr const QRgb LightGoldenrodYellow = 0xfffafad2;
92 constexpr const QRgb LightGray = 0xffd3d3d3;
93 constexpr const QRgb LightGreen = 0xff90ee90;
94 constexpr const QRgb LightGrey = 0xffd3d3d3;
95 constexpr const QRgb LightPink = 0xffffb6c1;
96 constexpr const QRgb LightSalmon = 0xffffa07a;
97 constexpr const QRgb LightSeaGreen = 0xff20b2aa;
98 constexpr const QRgb LightSkyBlue = 0xff87cefa;
99 constexpr const QRgb LightSlateGray = 0xff778899;
100 constexpr const QRgb LightSlateGrey = 0xff778899;
101 constexpr const QRgb LightSteelBlue = 0xffb0c4de;
102 constexpr const QRgb LightYellow = 0xffffffe0;
103 constexpr const QRgb Lime = 0xff00ff00;
104 constexpr const QRgb LimeGreen = 0xff32cd32;
105 constexpr const QRgb Linen = 0xfffaf0e6;
106 constexpr const QRgb Magenta = 0xffff00ff;
107 constexpr const QRgb Maroon = 0xff800000;
108 constexpr const QRgb MediumAquamarine = 0xff66cdaa;
109 constexpr const QRgb MediumBlue = 0xff0000cd;
110 constexpr const QRgb MediumOrchid = 0xffba55d3;
111 constexpr const QRgb MediumPurple = 0xff9370db;
112 constexpr const QRgb MediumSeaGreen = 0xff3cb371;
113 constexpr const QRgb MediumSlateBlue = 0xff7b68ee;
114 constexpr const QRgb MediumSpringGreen = 0xff00fa9a;
115 constexpr const QRgb MediumTurquoise = 0xff48d1cc;
116 constexpr const QRgb MediumVioletRed = 0xffc71585;
117 constexpr const QRgb MidnightBlue = 0xff191970;
118 constexpr const QRgb MintCream = 0xfff5fffa;
119 constexpr const QRgb MistyRose = 0xffffe4e1;
120 constexpr const QRgb Moccasin = 0xffffe4b5;
121 constexpr const QRgb NavajoWhite = 0xffffdead;
122 constexpr const QRgb Navy = 0xff000080;
123 constexpr const QRgb OldLace = 0xfffdf5e6;
124 constexpr const QRgb Olive = 0xff808000;
125 constexpr const QRgb OliveDrab = 0xff6b8e23;
126 constexpr const QRgb Orange = 0xffffa500;
127 constexpr const QRgb OrangeRed = 0xffff4500;
128 constexpr const QRgb Orchid = 0xffda70d6;
129 constexpr const QRgb PaleGoldenrod = 0xffeee8aa;
130 constexpr const QRgb PaleGreen = 0xff98fb98;
131 constexpr const QRgb PaleTurquoise = 0xffafeeee;
132 constexpr const QRgb PaleVioletRed = 0xffdb7093;
133 constexpr const QRgb PapayaWhip = 0xffffefd5;
134 constexpr const QRgb PeachPuff = 0xffffdab9;
135 constexpr const QRgb Peru = 0xffcd853f;
136 constexpr const QRgb Pink = 0xffffc0cb;
137 constexpr const QRgb Plum = 0xffdda0dd;
138 constexpr const QRgb PowderBlue = 0xffb0e0e6;
139 constexpr const QRgb Purple = 0xff800080;
140 constexpr const QRgb Red = 0xffff0000;
141 constexpr const QRgb RosyBrown = 0xffbc8f8f;
142 constexpr const QRgb RoyalBlue = 0xff4169e1;
143 constexpr const QRgb SaddleBrown = 0xff8b4513;
144 constexpr const QRgb Salmon = 0xfffa8072;
145 constexpr const QRgb SandyBrown = 0xfff4a460;
146 constexpr const QRgb SeaGreen = 0xff2e8b57;
147 constexpr const QRgb Seashell = 0xfffff5ee;
148 constexpr const QRgb Sienna = 0xffa0522d;
149 constexpr const QRgb Silver = 0xffc0c0c0;
150 constexpr const QRgb SkyBlue = 0xff87ceeb;
151 constexpr const QRgb SlateBlue = 0xff6a5acd;
152 constexpr const QRgb SlateGrey = 0xff708090;
153 constexpr const QRgb Snow = 0xfffffafa;
154 constexpr const QRgb SpringGreen = 0xff00ff7f;
155 constexpr const QRgb SteelBlue = 0xff4682b4;
156 constexpr const QRgb Tan = 0xffd2b48c;
157 constexpr const QRgb Teal = 0xff008080;
158 constexpr const QRgb Thistle = 0xffd8bfd8;
159 constexpr const QRgb Tomato = 0xffff6347;
160 constexpr const QRgb Turquoise = 0xff40e0d0;
161 constexpr const QRgb Violet = 0xffee82ee;
162 constexpr const QRgb Wheat = 0xfff5deb3;
163 constexpr const QRgb WhiteSmoke = 0xfff5f5f5;
164 constexpr const QRgb Yellow = 0xffffff00;
165 constexpr const QRgb YellowGreen = 0xff9acd32;
166 constexpr const QRgb White = 0xffffffff;
167
168 // others
169 constexpr const QRgb Transparent = 0x00000000;
170 constexpr const QRgb AlphaMask = 0xff000000;
171 constexpr const QRgb ColorMask = 0x00ffffff;
172 constexpr const QRgb RGBAMask = 0xffffffff;
173}
174
175namespace QskRgb
176{
177 QSK_EXPORT QRgb rgb( Qt::GlobalColor );
178 QSK_EXPORT QRgb interpolated( QRgb rgb1, QRgb rgb2, qreal ratio );
179 QSK_EXPORT QColor interpolated( const QColor& c1, const QColor& c2, qreal ratio );
180
181 inline QColor toTransparent( const QColor& c1, int alpha = 0 )
182 {
183 const auto alphaU = static_cast< uint >( alpha );
184 return QColor::fromRgba( ( c1.rgb() & ColorMask ) | ( ( alphaU & 0xffu ) << 24 ) );
185 }
186
187 inline QColor toTransparent( Qt::GlobalColor color, int alpha = 0 )
188 {
189 return toTransparent( QColor( color ), alpha );
190 }
191
192 inline constexpr QRgb toTransparent( QRgb rgb, int alpha = 0 ) noexcept
193 {
194 return ( rgb & ColorMask ) | ( ( static_cast< uint >( alpha ) & 0xffu ) << 24 );
195 }
196
197 inline QColor toTransparentF( const QColor& color, qreal opacity )
198 {
199 return toTransparent( color, qRound( opacity * 255 ) );
200 }
201
202 inline QColor toTransparentF( Qt::GlobalColor color, qreal opacity )
203 {
204 return toTransparent( QColor( color ), qRound( opacity * 255 ) );
205 }
206
207 inline constexpr QRgb toTransparentF( QRgb rgb, qreal opacity ) noexcept
208 {
209 return toTransparent( rgb, qRound( opacity * 255 ) );
210 }
211
212 inline bool isVisible( QRgb rgb )
213 {
214 return qAlpha( rgb ) > 0;
215 }
216
217 inline bool isVisible( const QColor& color )
218 {
219 return color.isValid() && color.alpha() > 0;
220 }
221
222 QSK_EXPORT QRgb lighter( QRgb, int factor = 150 ) noexcept;
223 QSK_EXPORT QRgb darker( QRgb, int factor = 200 ) noexcept;
224}
225
226namespace QskRgb
227{
228 /*
229 One dimensional array of colors ( height is always 1 ) of
230 Format_RGBA8888_Premultiplied
231 */
232
233 QSK_EXPORT QImage colorTable( int size, const QskGradientStops& );
234 QSK_EXPORT QImage colorTable( int size, QRgb, QRgb, const QEasingCurve& );
235}
236
237#ifndef QT_NO_DEBUG_STREAM
238
239class QDebug;
240
241namespace QskRgb
242{
243 QSK_EXPORT void debugColor( QDebug, const QColor& );
244 QSK_EXPORT void debugColor( QDebug, QRgb );
245}
246
247#endif
248
249#endif