25 |
25 |
26 // ============================================================================= |
26 // ============================================================================= |
27 // |
27 // |
28 // Helper function for parseLDConfig |
28 // Helper function for parseLDConfig |
29 // |
29 // |
30 static bool parseLDConfigTag (LDConfigParser& pars, char const* tag, QString& val) |
30 static bool ParseLDConfigTag (LDConfigParser& pars, char const* tag, QString& val) |
31 { |
31 { |
32 int pos; |
32 int pos; |
33 |
33 |
34 // Try find the token and get its position |
34 // Try find the token and get its position |
35 if (not pars.findToken (pos, tag, 1)) |
35 if (not pars.findToken (pos, tag, 1)) |
41 |
41 |
42 // ============================================================================= |
42 // ============================================================================= |
43 // |
43 // |
44 void LDConfigParser::parseLDConfig() |
44 void LDConfigParser::parseLDConfig() |
45 { |
45 { |
46 QFile* fp = openLDrawFile ("LDConfig.ldr", false); |
46 QFile* fp = OpenLDrawFile ("LDConfig.ldr", false); |
47 |
47 |
48 if (fp == null) |
48 if (fp == null) |
49 { |
49 { |
50 critical (QObject::tr ("Unable to open LDConfig.ldr for parsing.")); |
50 CriticalError (QObject::tr ("Unable to open LDConfig.ldr for parsing.")); |
51 return; |
51 return; |
52 } |
52 } |
53 |
53 |
54 // Read in the lines |
54 // Read in the lines |
55 while (not fp->atEnd()) |
55 while (not fp->atEnd()) |
78 |
78 |
79 // Replace underscores in the name with spaces for readability |
79 // Replace underscores in the name with spaces for readability |
80 name.replace ("_", " "); |
80 name.replace ("_", " "); |
81 |
81 |
82 // Get the CODE tag |
82 // Get the CODE tag |
83 if (not parseLDConfigTag (pars, "CODE", valuestr)) |
83 if (not ParseLDConfigTag (pars, "CODE", valuestr)) |
84 continue; |
84 continue; |
85 |
85 |
86 // Ensure that the code is within [0 - 511] |
86 // Ensure that the code is within [0 - 511] |
87 bool ok; |
87 bool ok; |
88 code = valuestr.toShort (&ok); |
88 code = valuestr.toShort (&ok); |
89 |
89 |
90 if (not ok or code < 0 or code >= 512) |
90 if (not ok or code < 0 or code >= 512) |
91 continue; |
91 continue; |
92 |
92 |
93 // VALUE and EDGE tags |
93 // VALUE and EDGE tags |
94 if (not parseLDConfigTag (pars, "VALUE", facename) or not parseLDConfigTag (pars, "EDGE", edgename)) |
94 if (not ParseLDConfigTag (pars, "VALUE", facename) or not ParseLDConfigTag (pars, "EDGE", edgename)) |
95 continue; |
95 continue; |
96 |
96 |
97 // Ensure that our colors are correct |
97 // Ensure that our colors are correct |
98 QColor faceColor (facename), |
98 QColor faceColor (facename), |
99 edgeColor (edgename); |
99 edgeColor (edgename); |
100 |
100 |
101 if (not faceColor.isValid() or not edgeColor.isValid()) |
101 if (not faceColor.isValid() or not edgeColor.isValid()) |
102 continue; |
102 continue; |
103 |
103 |
104 // Parse alpha if given. |
104 // Parse alpha if given. |
105 if (parseLDConfigTag (pars, "ALPHA", valuestr)) |
105 if (ParseLDConfigTag (pars, "ALPHA", valuestr)) |
106 alpha = clamp (valuestr.toInt(), 0, 255); |
106 alpha = Clamp (valuestr.toInt(), 0, 255); |
107 |
107 |
108 LDColorData* col = new LDColorData; |
108 LDColorData* col = new LDColorData; |
109 col->_name = name; |
109 col->m_name = name; |
110 col->_faceColor = faceColor; |
110 col->m_faceColor = faceColor; |
111 col->_edgeColor = edgeColor; |
111 col->m_edgeColor = edgeColor; |
112 col->_hexcode = facename; |
112 col->m_hexcode = facename; |
113 col->_faceColor.setAlpha (alpha); |
113 col->m_faceColor.setAlpha (alpha); |
114 col->_index = code; |
114 col->m_index = code; |
115 LDColor::addLDConfigColor (code, LDColor (col)); |
115 LDColor::addLDConfigColor (code, LDColor (col)); |
116 } |
116 } |
117 |
117 |
118 fp->close(); |
118 fp->close(); |
119 fp->deleteLater(); |
119 fp->deleteLater(); |