1 #include "lc_global.h"
2 #include "lc_profile.h"
3 #include "lc_context.h"
4 #include "image.h"
5 #include "lc_model.h"
6 #include "project.h"
7 #include "lc_viewsphere.h"
8 
lcProfileEntry(const char * Section,const char * Key,int DefaultValue)9 lcProfileEntry::lcProfileEntry(const char* Section, const char* Key, int DefaultValue)
10 {
11 	mType = LC_PROFILE_ENTRY_INT;
12 	mSection = Section;
13 	mKey = Key;
14 	mDefault.IntValue = DefaultValue;
15 }
16 
lcProfileEntry(const char * Section,const char * Key,unsigned int DefaultValue)17 lcProfileEntry::lcProfileEntry(const char* Section, const char* Key, unsigned int DefaultValue)
18 {
19 	mType = LC_PROFILE_ENTRY_INT;
20 	mSection = Section;
21 	mKey = Key;
22 	mDefault.IntValue = DefaultValue;
23 }
24 
lcProfileEntry(const char * Section,const char * Key,float DefaultValue)25 lcProfileEntry::lcProfileEntry(const char* Section, const char* Key, float DefaultValue)
26 {
27 	mType = LC_PROFILE_ENTRY_FLOAT;
28 	mSection = Section;
29 	mKey = Key;
30 	mDefault.FloatValue = DefaultValue;
31 }
32 
lcProfileEntry(const char * Section,const char * Key,const char * DefaultValue)33 lcProfileEntry::lcProfileEntry(const char* Section, const char* Key, const char* DefaultValue)
34 {
35 	mType = LC_PROFILE_ENTRY_STRING;
36 	mSection = Section;
37 	mKey = Key;
38 	mDefault.StringValue = DefaultValue;
39 }
40 
lcProfileEntry(const char * Section,const char * Key,const QStringList &)41 lcProfileEntry::lcProfileEntry(const char* Section, const char* Key, const QStringList& /*StringList*/)
42 {
43 	mType = LC_PROFILE_ENTRY_STRINGLIST;
44 	mSection = Section;
45 	mKey = Key;
46 	mDefault.IntValue = 0;
47 }
48 
lcProfileEntry(const char * Section,const char * Key)49 lcProfileEntry::lcProfileEntry(const char* Section, const char* Key)
50 {
51 	mType = LC_PROFILE_ENTRY_BUFFER;
52 	mSection = Section;
53 	mKey = Key;
54 	mDefault.IntValue = 0;
55 }
56 
57 static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] =
58 {
59 	lcProfileEntry("Settings", "FixedAxes", false),                                            // LC_PROFILE_FIXED_AXES
60 	lcProfileEntry("Settings", "LineWidth", 1.0f),                                             // LC_PROFILE_LINE_WIDTH
61 	lcProfileEntry("Settings", "AllowLOD", true),                                              // LC_PROFILE_ALLOW_LOD
62 	lcProfileEntry("Settings", "LODDistance", 750.0f),                                         // LC_PROFILE_LOD_DISTANCE
63 	lcProfileEntry("Settings", "FadeSteps", false),                                            // LC_PROFILE_FADE_STEPS
64 	lcProfileEntry("Settings", "FadeStepsColor", LC_RGBA(128, 128, 128, 128)),                 // LC_PROFILE_FADE_STEPS_COLOR
65 	lcProfileEntry("Settings", "HighlightNewParts", 0),                                        // LC_PROFILE_HIGHLIGHT_NEW_PARTS
66 	lcProfileEntry("Settings", "HighlightNewPartsColor", LC_RGBA(255, 242, 0, 192)),           // LC_PROFILE_HIGHLIGHT_NEW_PARTS_COLOR
67 	lcProfileEntry("Settings", "ShadingMode", static_cast<int>(lcShadingMode::DefaultLights)), // LC_PROFILE_SHADING_MODE
68 	lcProfileEntry("Settings", "BackgroundGradient", false),                                   // LC_PROFILE_BACKGROUND_GRADIENT
69 	lcProfileEntry("Settings", "BackgroundColor", LC_RGB(49, 52, 55)),                         // LC_PROFILE_BACKGROUND_COLOR
70 	lcProfileEntry("Settings", "GradientColorTop", LC_RGB(54, 72, 95)),                        // LC_PROFILE_GRADIENT_COLOR_TOP
71 	lcProfileEntry("Settings", "GradientColorBottom", LC_RGB(49, 52, 55)),                     // LC_PROFILE_GRADIENT_COLOR_BOTTOM
72 	lcProfileEntry("Settings", "DrawAxes", 0),                                                 // LC_PROFILE_DRAW_AXES
73 	lcProfileEntry("Settings", "DrawAxesLocation", static_cast<int>(lcAxisIconLocation::BottomLeft)), // LC_PROFILE_DRAW_AXES_LOCATION
74 	lcProfileEntry("Settings", "AxesColor", LC_RGBA(0, 0, 0, 255)),                            // LC_PROFILE_AXES_COLOR
75 	lcProfileEntry("Settings", "TextColor", LC_RGBA(0, 0, 0, 255)),                            // LC_PROFILE_TEXT_COLOR
76 	lcProfileEntry("Settings", "MarqueeBorderColor", LC_RGBA(64, 64, 255, 255)),               // LC_PROFILE_MARQUEE_BORDER_COLOR
77 	lcProfileEntry("Settings", "MarqueeFillColor", LC_RGBA(64, 64, 255, 64)),                  // LC_PROFILE_MARQUEE_FILL_COLOR
78 	lcProfileEntry("Settings", "OverlayColor", LC_RGBA(0, 0, 0, 255)),                         // LC_PROFILE_OVERLAY_COLOR
79 	lcProfileEntry("Settings", "ActiveViewColor", LC_RGBA(41, 128, 185, 255)),                 // LC_PROFILE_ACTIVE_VIEW_COLOR
80 	lcProfileEntry("Settings", "InactiveViewColor", LC_RGBA(69, 69, 69, 255)),                 // LC_PROFILE_INACTIVE_VIEW_COLOR
81 	lcProfileEntry("Settings", "DrawEdgeLines", 1),                                            // LC_PROFILE_DRAW_EDGE_LINES
82 	lcProfileEntry("Settings", "DrawConditionalLines", 1),                                     // LC_PROFILE_DRAW_CONDITIONAL_LINES
83 	lcProfileEntry("Settings", "GridStuds", 1),                                                // LC_PROFILE_GRID_STUDS
84 	lcProfileEntry("Settings", "GridStudColor", LC_RGBA(24, 24, 24, 192)),                     // LC_PROFILE_GRID_STUD_COLOR
85 	lcProfileEntry("Settings", "GridLines", 1),                                                // LC_PROFILE_GRID_LINES
86 	lcProfileEntry("Settings", "GridLineSpacing", 5),                                          // LC_PROFILE_GRID_LINE_SPACING
87 	lcProfileEntry("Settings", "GridLineColor", LC_RGBA(24, 24, 24, 255)),                     // LC_PROFILE_GRID_LINE_COLOR
88 	lcProfileEntry("Settings", "GridOrigin", 0),                                               // LC_PROFILE_GRID_ORIGIN
89 	lcProfileEntry("Settings", "AASamples", 1),                                                // LC_PROFILE_ANTIALIASING_SAMPLES
90 	lcProfileEntry("Settings", "ViewSphereEnabled", 1),                                        // LC_PROFILE_VIEW_SPHERE_ENABLED
91 	lcProfileEntry("Settings", "ViewSphereLocation", (int)lcViewSphereLocation::TopRight),     // LC_PROFILE_VIEW_SPHERE_LOCATION
92 	lcProfileEntry("Settings", "ViewSphereSize", 100),                                         // LC_PROFILE_VIEW_SPHERE_SIZE
93 	lcProfileEntry("Settings", "ViewSphereColor", LC_RGBA(35, 38, 41, 255)),                   // LC_PROFILE_VIEW_SPHERE_COLOR
94 	lcProfileEntry("Settings", "ViewSphereTextColor", LC_RGBA(224, 224, 224, 255)),            // LC_PROFILE_VIEW_SPHERE_TEXT_COLOR
95 	lcProfileEntry("Settings", "ViewSphereHighlightColor", LC_RGBA(41, 128, 185, 255)),        // LC_PROFILE_VIEW_SPHERE_HIGHLIGHT_COLOR
96 
97 	lcProfileEntry("Settings", "Language", ""),                                                // LC_PROFILE_LANGUAGE
98 	lcProfileEntry("Settings", "ColorTheme", static_cast<int>(lcColorTheme::Dark)),            // LC_PROFILE_COLOR_THEME
99 	lcProfileEntry("Settings", "CheckUpdates", 1),                                             // LC_PROFILE_CHECK_UPDATES
100 	lcProfileEntry("Settings", "ProjectsPath", ""),                                            // LC_PROFILE_PROJECTS_PATH
101 	lcProfileEntry("Settings", "PartsLibrary", ""),                                            // LC_PROFILE_PARTS_LIBRARY
102 	lcProfileEntry("Settings", "PartPalettes"),                                                // LC_PROFILE_PART_PALETTES
103 	lcProfileEntry("Settings", "MinifigSettings", ""),                                         // LC_PROFILE_MINIFIG_SETTINGS
104 	lcProfileEntry("Settings", "ColorConfig", ""),                                             // LC_PROFILE_COLOR_CONFIG
105 	lcProfileEntry("Settings", "Shortcuts"),                                                   // LC_PROFILE_KEYBOARD_SHORTCUTS
106 	lcProfileEntry("Settings", "MouseShortcuts", QStringList()),                               // LC_PROFILE_MOUSE_SHORTCUTS
107 	lcProfileEntry("Settings", "Categories"),                                                  // LC_PROFILE_CATEGORIES
108 	lcProfileEntry("Settings", "RecentFile1", ""),                                             // LC_PROFILE_RECENT_FILE1
109 	lcProfileEntry("Settings", "RecentFile2", ""),                                             // LC_PROFILE_RECENT_FILE2
110 	lcProfileEntry("Settings", "RecentFile3", ""),                                             // LC_PROFILE_RECENT_FILE3
111 	lcProfileEntry("Settings", "RecentFile4", ""),                                             // LC_PROFILE_RECENT_FILE4
112 	lcProfileEntry("Settings", "AutoLoadMostRecent", false),                                   // LC_PROFILE_AUTOLOAD_MOSTRECENT
113 	lcProfileEntry("Settings", "RestoreTabLayout", true),                                      // LC_PROFILE_RESTORE_TAB_LAYOUT
114 	lcProfileEntry("Settings", "AutosaveInterval", 10),                                        // LC_PROFILE_AUTOSAVE_INTERVAL
115 	lcProfileEntry("Settings", "MouseSensitivity", 11),                                        // LC_PROFILE_MOUSE_SENSITIVITY
116 	lcProfileEntry("Settings", "ImageWidth", 1280),                                            // LC_PROFILE_IMAGE_WIDTH
117 	lcProfileEntry("Settings", "ImageHeight", 720),                                            // LC_PROFILE_IMAGE_HEIGHT
118 	lcProfileEntry("Settings", "ImageExtension", ".png"),                                      // LC_PROFILE_IMAGE_EXTENSION
119 	lcProfileEntry("Settings", "PartsListIcons", 64),                                          // LC_PROFILE_PARTS_LIST_ICONS
120 	lcProfileEntry("Settings", "PartsListNames", 0),                                           // LC_PROFILE_PARTS_LIST_NAMES
121 	lcProfileEntry("Settings", "PartsListFixedColor", -1),                                     // LC_PROFILE_PARTS_LIST_FIXED_COLOR
122 	lcProfileEntry("Settings", "PartsListDecorated", 1),                                       // LC_PROFILE_PARTS_LIST_DECORATED
123 	lcProfileEntry("Settings", "PartsListAliases", 1),                                         // LC_PROFILE_PARTS_LIST_ALIASES
124 	lcProfileEntry("Settings", "PartsListListMode", 0),                                        // LC_PROFILE_PARTS_LIST_LISTMODE
125 	lcProfileEntry("Settings", "StudStyle", 0),                                                // LC_PROFILE_STUD_STYLE
126 
127 	lcProfileEntry("Defaults", "Author", ""),                                                  // LC_PROFILE_DEFAULT_AUTHOR_NAME
128 	lcProfileEntry("Defaults", "AmbientColor", LC_RGB(75, 75, 75)),                            // LC_PROFILE_DEFAULT_AMBIENT_COLOR
129 
130 	lcProfileEntry("HTML", "Options", LC_HTML_SINGLEPAGE),                                     // LC_PROFILE_HTML_OPTIONS
131 	lcProfileEntry("HTML", "ImageOptions", LC_IMAGE_TRANSPARENT),                              // LC_PROFILE_HTML_IMAGE_OPTIONS
132 	lcProfileEntry("HTML", "ImageWidth", 640),                                                 // LC_PROFILE_HTML_IMAGE_WIDTH
133 	lcProfileEntry("HTML", "ImageHeight", 480),                                                // LC_PROFILE_HTML_IMAGE_HEIGHT
134 
135 	lcProfileEntry("POVRay", "Path", "/usr/bin/povray"),                                       // LC_PROFILE_POVRAY_PATH
136 	lcProfileEntry("POVRay", "LGEOPath", ""),                                                  // LC_PROFILE_POVRAY_LGEO_PATH
137 	lcProfileEntry("POVRay", "Width", 1280),                                                   // LC_PROFILE_POVRAY_WIDTH
138 	lcProfileEntry("POVRay", "Height", 720),                                                   // LC_PROFILE_POVRAY_HEIGHT
139 
140 	lcProfileEntry("Settgins", "PreviewViewSphereEnabled", 0),                                    // LC_PROFILE_PREVIEW_VIEW_SPHERE_ENABLED
141 	lcProfileEntry("Settings", "PreviewViewSphereSize", 75),                                      // LC_PROFILE_PREVIEW_VIEW_SPHERE_SIZE
142 	lcProfileEntry("Settings", "PreviewViewSphereLocation", (int)lcViewSphereLocation::TopRight), // LC_PROFILE_PREVIEW_VIEW_SPHERE_LOCATION
143 	lcProfileEntry("Settings", "DrawPreviewAxis", 0),                                             // LC_PROFILE_PREVIEW_DRAW_AXES
144 
145 	lcProfileEntry("Settings", "StudCylinderColor", LC_RGBA(27, 42, 52, 255)),                 // LC_PROFILE_STUD_CYLINDER_COLOR
146 	lcProfileEntry("Settings", "PartEdgeColor", LC_RGBA(0, 0, 0, 255)),                        // LC_PROFILE_PART_EDGE_COLOR
147 	lcProfileEntry("Settings", "BlackEdgeColor", LC_RGBA(255, 255, 255, 255)),                 // LC_PROFILE_BLACK_EDGE_COLOR
148 	lcProfileEntry("Settings", "DarkEdgeColor", LC_RGBA(27, 42, 52, 255)),                     // LC_PROFILE_DARK_EDGE_COLOR
149 	lcProfileEntry("Settings", "PartEdgeContrast", 0.5f),                                      // LC_PROFILE_PART_EDGE_CONTRAST
150 	lcProfileEntry("Settings", "mPartColorValueLDIndex", 0.5f),                                // LC_PROFILE_PART_COLOR_VALUE_LD_INDEX
151 	lcProfileEntry("Settings", "AutomateEdgeColor", 0)                                         // LC_PROFILE_AUTOMATE_EDGE_COLOR
152 };
153 
lcRemoveProfileKey(LC_PROFILE_KEY Key)154 void lcRemoveProfileKey(LC_PROFILE_KEY Key)
155 {
156 	lcProfileEntry& Entry = gProfileEntries[Key];
157 	QSettings Settings;
158 
159 	Settings.remove(QString("%1/%2").arg(Entry.mSection, Entry.mKey));
160 }
161 
lcGetDefaultProfileInt(LC_PROFILE_KEY Key)162 int lcGetDefaultProfileInt(LC_PROFILE_KEY Key)
163 {
164 	return gProfileEntries[Key].mDefault.IntValue;
165 }
166 
lcGetDefaultProfileFloat(LC_PROFILE_KEY Key)167 float lcGetDefaultProfileFloat(LC_PROFILE_KEY Key)
168 {
169 	return gProfileEntries[Key].mDefault.FloatValue;
170 }
171 
lcGetDefaultProfileString(LC_PROFILE_KEY Key)172 QString lcGetDefaultProfileString(LC_PROFILE_KEY Key)
173 {
174 	return QString::fromLatin1(gProfileEntries[Key].mDefault.StringValue);
175 }
176 
lcGetProfileInt(LC_PROFILE_KEY Key)177 int lcGetProfileInt(LC_PROFILE_KEY Key)
178 {
179 	lcProfileEntry& Entry = gProfileEntries[Key];
180 	QSettings Settings;
181 
182 	return Settings.value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), Entry.mDefault.IntValue).toInt();
183 }
184 
lcGetProfileFloat(LC_PROFILE_KEY Key)185 float lcGetProfileFloat(LC_PROFILE_KEY Key)
186 {
187 	lcProfileEntry& Entry = gProfileEntries[Key];
188 	QSettings Settings;
189 
190 	return Settings.value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), Entry.mDefault.FloatValue).toFloat();
191 }
192 
lcGetProfileString(LC_PROFILE_KEY Key)193 QString lcGetProfileString(LC_PROFILE_KEY Key)
194 {
195 	lcProfileEntry& Entry = gProfileEntries[Key];
196 	QSettings Settings;
197 
198 	return Settings.value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), Entry.mDefault.StringValue).toString();
199 }
200 
lcGetProfileStringList(LC_PROFILE_KEY Key)201 QStringList lcGetProfileStringList(LC_PROFILE_KEY Key)
202 {
203 	lcProfileEntry& Entry = gProfileEntries[Key];
204 	QSettings Settings;
205 
206 	return Settings.value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), QStringList()).toStringList();
207 }
208 
lcGetProfileBuffer(LC_PROFILE_KEY Key)209 QByteArray lcGetProfileBuffer(LC_PROFILE_KEY Key)
210 {
211 	lcProfileEntry& Entry = gProfileEntries[Key];
212 	QSettings Settings;
213 
214 	return Settings.value(QString("%1/%2").arg(Entry.mSection, Entry.mKey)).toByteArray();
215 }
216 
lcSetProfileInt(LC_PROFILE_KEY Key,int Value)217 void lcSetProfileInt(LC_PROFILE_KEY Key, int Value)
218 {
219 	lcProfileEntry& Entry = gProfileEntries[Key];
220 	QSettings Settings;
221 
222 	Settings.setValue(QString("%1/%2").arg(Entry.mSection, Entry.mKey), Value);
223 }
224 
lcSetProfileFloat(LC_PROFILE_KEY Key,float Value)225 void lcSetProfileFloat(LC_PROFILE_KEY Key, float Value)
226 {
227 	lcProfileEntry& Entry = gProfileEntries[Key];
228 	QSettings Settings;
229 
230 	Settings.setValue(QString("%1/%2").arg(Entry.mSection, Entry.mKey), Value);
231 }
232 
lcSetProfileString(LC_PROFILE_KEY Key,const QString & Value)233 void lcSetProfileString(LC_PROFILE_KEY Key, const QString& Value)
234 {
235 	lcProfileEntry& Entry = gProfileEntries[Key];
236 	QSettings Settings;
237 
238 	Settings.setValue(QString("%1/%2").arg(Entry.mSection, Entry.mKey), Value);
239 }
240 
lcSetProfileStringList(LC_PROFILE_KEY Key,const QStringList & Value)241 void lcSetProfileStringList(LC_PROFILE_KEY Key, const QStringList& Value)
242 {
243 	lcProfileEntry& Entry = gProfileEntries[Key];
244 	QSettings Settings;
245 
246 	Settings.setValue(QString("%1/%2").arg(Entry.mSection, Entry.mKey), Value);
247 }
248 
lcSetProfileBuffer(LC_PROFILE_KEY Key,const QByteArray & Buffer)249 void lcSetProfileBuffer(LC_PROFILE_KEY Key, const QByteArray& Buffer)
250 {
251 	lcProfileEntry& Entry = gProfileEntries[Key];
252 	QSettings Settings;
253 
254 	Settings.setValue(QString("%1/%2").arg(Entry.mSection, Entry.mKey), Buffer);
255 }
256