Engauge Digitizer  2
EnumsToQt.cpp
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #include "EngaugeAssert.h"
8 #include "EnumsToQt.h"
9 #include <QHash>
10 #include <QString>
11 
12 static QHash<ColorPalette, QColor> colorPaletteLookupTable;
13 static QHash<QSysInfo::Endian, QString> endianLookupTable;
14 
15 QColor ColorPaletteToQColor (ColorPalette color)
16 {
17  if (colorPaletteLookupTable.count() == 0) {
18 
19  // Initialize
20  colorPaletteLookupTable [COLOR_PALETTE_BLACK] = QColor (Qt::black);
21  colorPaletteLookupTable [COLOR_PALETTE_BLUE] = QColor (Qt::blue);
22  colorPaletteLookupTable [COLOR_PALETTE_CYAN] = QColor (Qt::cyan);
23  colorPaletteLookupTable [COLOR_PALETTE_GOLD] = QColor (255, 215, 0);
24  colorPaletteLookupTable [COLOR_PALETTE_GREEN] = QColor (Qt::green);
25  colorPaletteLookupTable [COLOR_PALETTE_MAGENTA] = QColor (255, 0, 255);
26  colorPaletteLookupTable [COLOR_PALETTE_RED] = QColor (Qt::red);
27  colorPaletteLookupTable [COLOR_PALETTE_YELLOW] = QColor (255, 255, 0);
28  colorPaletteLookupTable [COLOR_PALETTE_TRANSPARENT] = QColor (Qt::transparent);
29  }
30 
31  if (colorPaletteLookupTable.contains (color)) {
32 
33  return colorPaletteLookupTable [color];
34 
35  } else {
36 
37  ENGAUGE_ASSERT (false);
38  return colorPaletteLookupTable [COLOR_PALETTE_BLACK];
39 
40  }
41 }
42 
43 QString EndianToString (QSysInfo::Endian endian)
44 {
45  if (endianLookupTable.count() == 0) {
46 
47  // Initialize
48  endianLookupTable [QSysInfo::BigEndian] = "BigEndian";
49  endianLookupTable [QSysInfo::LittleEndian] = "LittleEndian";
50  }
51 
52  if (endianLookupTable.contains (endian)) {
53 
54  return endianLookupTable [endian];
55 
56  } else {
57 
58  return "<Unknown>";
59 
60  }
61 }