StanfordCPPLib
gcolor.h
1 /*
2  * File: gcolor.h
3  * --------------
4  *
5  * @author Marty Stepp
6  * @version 2018/09/16
7  * - added splitRGB/ARGB, hasAlpha; better ARGB support
8  * @version 2018/09/07
9  * - added doc comments for new documentation generation
10  * @version 2018/08/23
11  * - renamed to gcolor.h to replace Java version
12  * @version 2018/06/30
13  * - initial version
14  */
15 
16 #include "private/init.h" // ensure that Stanford C++ lib is initialized
17 
18 #ifndef INTERNAL_INCLUDE
19 // signal that GUI system is in use (so it will be initialized)
20 #define SPL_QT_GUI_IN_USE 1
21 #include "private/initstudent.h" // insert necessary included code by student
22 #endif // INTERNAL_INCLUDE
23 
24 #ifndef _gcolor_h
25 #define _gcolor_h
26 
27 #include <string>
28 #include <QColor>
29 
30 #define INTERNAL_INCLUDE 1
31 #include "map.h"
32 #undef INTERNAL_INCLUDE
33 
76 class GColor {
77 public:
81  enum {
82  BLACK = 0x000000,
83  BLUE = 0x0000FF,
84  BROWN = 0x926239,
85  CYAN = 0x00FFFF,
86  DARKGRAY = 0x595959,
87  GRAY = 0x999999,
88  GREEN = 0x00FF00,
89  LIGHTGRAY = 0xBFBFBF,
90  MAGENTA = 0xFF00FF,
91  ORANGE = 0xFFC800,
92  PINK = 0xFFAFAF,
93  PURPLE = 0xFF00FF,
94  RED = 0xFF0000,
95  WHITE = 0xFFFFFF,
96  YELLOW = 0xFFFF00
97  } Color;
98 
106  static string convertARGBToColor(int a, int r, int g, int b);
107 
112  static string convertARGBToColor(int argb);
113 
121  static int convertARGBToARGB(int a, int r, int g, int b);
122 
127  static int convertColorToARGB(const string& colorName);
128 
134  static int convertColorToRGB(const string& colorName);
135 
140  static string convertQColorToColor(const QColor& color);
141 
146  static int convertQColorToRGB(const QColor& color);
147 
153  static string convertRGBToColor(int rgb);
154 
162  static string convertRGBToColor(int r, int g, int b);
163 
170  static int convertRGBToRGB(int r, int g, int b);
171 
177  static bool hasAlpha(const string& color);
178 
185  static void splitARGB(int argb, int& a, int& r, int& g, int& b);
186 
193  static void splitRGB(int rgb, int& r, int& g, int& b);
194 
199  static QColor toQColor(const string& color);
200 
205  static QColor toQColorARGB(int argb);
206 
207 private:
208  GColor(); // forbid construction
209 
213  static string canonicalColorName(const string& str);
214 
219  static const Map<string, int>& colorTable();
220 
225  static const Map<string, string>& colorNameTable();
226 
232  static int fixAlpha(int argb);
233 
234  // internal color tables
235  static Map<string, int> _colorTable;
236  static Map<string, string> _colorNameTable;
237 };
238 
239 #endif // _gcolor_h
static QColor toQColorARGB(int argb)
Converts an ARGB integer into a Qt color object.
Definition: gcolor.cpp:217
static bool hasAlpha(string color)
Returns true if the given color string is of the 8-hex-character form that contains an alpha channel ...
Definition: gcolor.cpp:187
Definition: gcolor.h:87
static string convertARGBToColor(int a, int r, int g, int b)
Converts four integer RGB values from 0-255 into a color name in the form "#aarrggbb".
Definition: gcolor.cpp:102
static QColor toQColor(string color)
Converts a color string into a Qt color object.
Definition: gcolor.cpp:205
enum GColor::@0 Color
Constants representing common system color names.
static int convertColorToARGB(string colorName)
Converts a color name into an ARGB integer that encodes the alpha (opacity), red, green...
Definition: gcolor.cpp:121
static string convertRGBToColor(int rgb)
Converts an RGB integer value into a color name in the form "#rrggbb".
Definition: gcolor.cpp:152
static int convertQColorToRGB(const QColor &color)
Converts a Qt color object into an RGB integer.
Definition: gcolor.cpp:148
Definition: gcolor.h:86
This class provides static methods for dealing with colors.
Definition: gcolor.h:76
static int convertRGBToRGB(int r, int g, int b)
Converts three integer RGB values from 0-255 into a single RGB integer.
Definition: gcolor.cpp:183
Definition: gcolor.h:85
static string convertQColorToColor(const QColor &color)
Converts a Qt RGB color object into a color string.
Definition: gcolor.cpp:144
Definition: gcolor.h:83
Definition: gcolor.h:95
Definition: gcolor.h:92
static void splitARGB(int argb, int &a, int &r, int &g, int &b)
Splits the given ARGB integer into four integer RGB values from 0-255.
Definition: gcolor.cpp:192
Definition: gcolor.h:84
static int convertARGBToARGB(int a, int r, int g, int b)
Converts four integer RGB values from 0-255 into an ARGB integer of the form 0xaarrggbb.
Definition: gcolor.cpp:98
Definition: gcolor.h:91
Definition: gcolor.h:82
Definition: gcolor.h:90
static int convertColorToRGB(string colorName)
Converts a color name into an integer that encodes the red, green, and blue components of the color...
Definition: gcolor.cpp:125
Definition: gcolor.h:93
Definition: gcolor.h:88
static void splitRGB(int rgb, int &r, int &g, int &b)
Splits the given RGB integer into three integer RGB values from 0-255.
Definition: gcolor.cpp:199
Definition: gcolor.h:96
Definition: gcolor.h:94
Definition: gcolor.h:89