18 |
18 |
19 #pragma once |
19 #pragma once |
20 #include <QColor> |
20 #include <QColor> |
21 #include "basics.h" |
21 #include "basics.h" |
22 |
22 |
|
23 /* |
|
24 * ColorData |
|
25 * |
|
26 * This class contains the model data for LDConfig-defined colors. |
|
27 */ |
23 class ColorData |
28 class ColorData |
24 { |
29 { |
25 public: |
30 public: |
26 struct Entry |
31 struct Entry |
27 { |
32 { |
28 QString name; |
33 QString name; |
29 QString hexcode; |
|
30 QColor faceColor; |
34 QColor faceColor; |
31 QColor edgeColor; |
35 QColor edgeColor; |
32 }; |
36 }; |
33 |
37 |
34 enum { EntryCount = 512 }; |
|
35 ColorData(); |
38 ColorData(); |
36 ~ColorData(); |
39 ~ColorData(); |
37 void loadFromLdconfig(); |
40 void loadFromLdconfig(); |
38 bool contains (int code) const; |
41 bool contains(int code) const; |
39 const Entry& get (int code) const; |
42 const Entry& get(int code) const; |
40 |
43 |
41 private: |
44 private: |
42 Entry m_data[EntryCount]; |
45 Entry m_data[512]; |
43 }; |
46 }; |
44 |
47 |
|
48 /* |
|
49 * LDColor |
|
50 * |
|
51 * This class represents an LDraw color. For a color index, this class provides information for that color. |
|
52 * It only contains the index of the color. Therefore it is a wrapper around an integer and should be passed by value. |
|
53 */ |
45 class LDColor |
54 class LDColor |
46 { |
55 { |
47 public: |
56 public: |
48 LDColor() : m_index (0) {} |
57 LDColor(); |
49 LDColor (qint32 index) : m_index (index) {} |
58 LDColor(qint32 index); |
50 LDColor (const LDColor& other) : m_index (other.m_index) {} |
59 LDColor(const LDColor& other) = default; |
51 |
60 |
52 bool isLDConfigColor() const; |
61 bool isLDConfigColor() const; |
53 bool isValid() const; |
62 bool isValid() const; |
54 QString name() const; |
63 QString name() const; |
55 QString hexcode() const; |
64 QString hexcode() const; |
56 QColor faceColor() const; |
65 QColor faceColor() const; |
57 QColor edgeColor() const; |
66 QColor edgeColor() const; |
58 qint32 index() const; |
67 qint32 index() const; |
59 int luma() const; |
|
60 int edgeLuma() const; |
|
61 bool isDirect() const; |
68 bool isDirect() const; |
62 QString indexString() const; |
69 QString indexString() const; |
63 |
70 |
64 static LDColor nullColor() { return LDColor (-1); } |
71 static LDColor nullColor(); |
65 |
72 |
66 LDColor& operator= (qint32 index) { m_index = index; return *this; } |
73 LDColor& operator=(qint32 index) { m_index = index; return *this; } |
67 LDColor& operator= (LDColor other) { m_index = other.index(); return *this; } |
74 LDColor& operator=(const LDColor &other) = default; |
68 LDColor operator++() { return ++m_index; } |
75 LDColor operator++() { return ++m_index; } |
69 LDColor operator++ (int) { return m_index++; } |
76 LDColor operator++(int) { return m_index++; } |
70 LDColor operator--() { return --m_index; } |
77 LDColor operator--() { return --m_index; } |
71 LDColor operator-- (int) { return m_index--; } |
78 LDColor operator--(int) { return m_index--; } |
72 |
79 bool operator==(LDColor other) const { return index() == other.index(); } |
73 bool operator== (LDColor other) const { return index() == other.index(); } |
80 bool operator!=(LDColor other) const { return index() != other.index(); } |
74 bool operator!= (LDColor other) const { return index() != other.index(); } |
81 bool operator<(LDColor other) const { return index() < other.index(); } |
75 bool operator< (LDColor other) const { return index() < other.index(); } |
82 bool operator<=(LDColor other) const { return index() <= other.index(); } |
76 bool operator<= (LDColor other) const { return index() <= other.index(); } |
83 bool operator>(LDColor other) const { return index() > other.index(); } |
77 bool operator> (LDColor other) const { return index() > other.index(); } |
84 bool operator>=(LDColor other) const { return index() >= other.index(); } |
78 bool operator>= (LDColor other) const { return index() >= other.index(); } |
|
79 |
85 |
80 private: |
86 private: |
81 const ColorData::Entry& data() const; |
87 const ColorData::Entry& data() const; |
82 |
88 |
83 qint32 m_index; |
89 qint32 m_index; |
84 }; |
90 }; |
85 |
91 |
86 uint qHash(LDColor color); |
92 uint qHash(LDColor color); |
87 |
93 |
88 // |
94 /* |
89 // Parses ldconfig.ldr |
95 * LDConfigParser |
90 // |
96 * |
|
97 * Parses LDConfig.ldr. |
|
98 */ |
91 class LDConfigParser |
99 class LDConfigParser |
92 { |
100 { |
93 public: |
101 public: |
94 LDConfigParser (QString inText, char sep); |
102 LDConfigParser(QString inputText); |
95 |
103 |
96 bool getToken (QString& val, const int pos); |
104 bool getToken(QString& tokenText, int position); |
97 bool findToken (int& result, char const* needle, int args); |
105 bool findToken(int& tokenPosition, QString needle, int args); |
98 bool compareToken (int inPos, QString text); |
106 bool compareToken(int inPos, QString text); |
99 bool parseTag (char const* tag, QString& val); |
107 bool parseTag(QString key, QString& value); |
100 |
|
101 inline QString operator[] (const int idx) |
|
102 { |
|
103 return m_tokens[idx]; |
|
104 } |
|
105 |
108 |
106 private: |
109 private: |
107 QStringList m_tokens; |
110 QStringList m_tokens; |
108 int m_pos; |
|
109 }; |
111 }; |
110 |
112 |
111 void initColors(); |
113 void initColors(); |
112 int luma (const QColor& col); |
114 int luma(const QColor& col); |
113 |
115 |
114 enum |
116 enum |
115 { |
117 { |
116 MainColor = 16, |
118 MainColor = 16, |
117 EdgeColor = 24, |
119 EdgeColor = 24, |