Mon, 15 Apr 2013 18:07:29 +0300
Added select by type. Selection is now preserved over operations.
30
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
1 | /* |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
104 | 3 | * Copyright (C) 2013 Santeri Piippo |
30
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
4 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
8 | * (at your option) any later version. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
9 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
13 | * GNU General Public License for more details. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
14 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
17 | */ |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
18 | |
0 | 19 | #ifndef __OPTIONS_H__ |
20 | #define __OPTIONS_H__ | |
21 | ||
22 | #include "common.h" | |
23 | #include "str.h" | |
24 | ||
25 | // ============================================================================= | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
26 | #define CONFIGFILE APPNAME ".cfg" |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
27 | #include <QString> |
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
28 | #include <qkeysequence.h> |
0 | 29 | |
30 | #define MAX_INI_LINE 512 | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
31 | #define NUM_CONFIG (g_pConfigPointers.size ()) |
0 | 32 | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
33 | #define cfg(T, NAME, DEFAULT) \ |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
34 | T##config NAME (DEFAULT, #NAME, #T, #DEFAULT) |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
35 | |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
36 | #define extern_cfg(T, NAME) \ |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
37 | extern T##config NAME |
0 | 38 | |
39 | // ============================================================================= | |
40 | enum configtype_e { | |
41 | CONFIG_none, | |
42 | CONFIG_int, | |
43 | CONFIG_str, | |
44 | CONFIG_float, | |
45 | CONFIG_bool, | |
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
46 | CONFIG_keyseq, |
0 | 47 | }; |
48 | ||
49 | // ========================================================= | |
50 | class config { | |
51 | public: | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
52 | const char* name, *typestring, *defaultstring; |
0 | 53 | |
54 | virtual configtype_e getType () { | |
55 | return CONFIG_none; | |
56 | } | |
57 | ||
58 | virtual void resetValue () {} | |
59 | ||
60 | // ------------------------------------------ | |
61 | static bool load (); | |
62 | static bool save (); | |
63 | static void reset (); | |
64 | static str dirpath (); | |
65 | static str filepath (); | |
66 | }; | |
67 | ||
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
68 | extern std::vector<config*> g_pConfigPointers; |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
69 | |
0 | 70 | // ============================================================================= |
71 | #define DEFINE_UNARY_OPERATOR(T, OP) \ | |
72 | T operator OP () { \ | |
73 | return (OP value); \ | |
74 | } \ | |
75 | ||
76 | #define DEFINE_BINARY_OPERATOR(T, OP) \ | |
77 | T operator OP (const T other) { \ | |
78 | return (value OP other); \ | |
79 | } \ | |
80 | ||
81 | #define DEFINE_ASSIGN_OPERATOR(T, OP) \ | |
82 | T& operator OP (const T other) { \ | |
83 | return (value OP other); \ | |
84 | } \ | |
85 | ||
86 | #define DEFINE_COMPARE_OPERATOR(T, OP) \ | |
87 | bool operator OP (const T other) { \ | |
88 | return (value OP other); \ | |
89 | } \ | |
90 | ||
91 | #define DEFINE_CAST_OPERATOR(T) \ | |
92 | operator T () { \ | |
93 | return (T) value; \ | |
94 | } \ | |
95 | ||
96 | #define DEFINE_ALL_COMPARE_OPERATORS(T) \ | |
97 | DEFINE_COMPARE_OPERATOR (T, ==) \ | |
98 | DEFINE_COMPARE_OPERATOR (T, !=) \ | |
99 | DEFINE_COMPARE_OPERATOR (T, >) \ | |
100 | DEFINE_COMPARE_OPERATOR (T, <) \ | |
101 | DEFINE_COMPARE_OPERATOR (T, >=) \ | |
102 | DEFINE_COMPARE_OPERATOR (T, <=) \ | |
103 | ||
104 | #define DEFINE_INCREMENT_OPERATORS(T) \ | |
105 | T operator++ () {return ++value;} \ | |
106 | T operator++ (int) {return value++;} \ | |
107 | T operator-- () {return --value;} \ | |
108 | T operator-- (int) {return value--;} | |
109 | ||
110 | #define CONFIGTYPE(T) \ | |
111 | class T##config : public config | |
112 | ||
113 | #define IMPLEMENT_CONFIG(T) \ | |
114 | T value, defval; \ | |
115 | \ | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
116 | T##config (T _defval, const char* _name, const char* _typestring, \ |
0 | 117 | const char* _defaultstring) \ |
118 | { \ | |
119 | value = defval = _defval; \ | |
120 | name = _name; \ | |
121 | typestring = _typestring; \ | |
122 | defaultstring = _defaultstring; \ | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
123 | g_pConfigPointers.push_back (this); \ |
0 | 124 | } \ |
125 | operator T () { \ | |
126 | return value; \ | |
127 | } \ | |
128 | configtype_e getType () { \ | |
129 | return CONFIG_##T; \ | |
130 | } \ | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
131 | virtual void resetValue () { \ |
0 | 132 | value = defval; \ |
133 | } | |
134 | ||
135 | // ============================================================================= | |
136 | CONFIGTYPE (int) { | |
137 | public: | |
138 | IMPLEMENT_CONFIG (int) | |
139 | ||
140 | // Int-specific operators | |
141 | DEFINE_ALL_COMPARE_OPERATORS (int) | |
142 | DEFINE_INCREMENT_OPERATORS (int) | |
143 | DEFINE_BINARY_OPERATOR (int, +) | |
144 | DEFINE_BINARY_OPERATOR (int, -) | |
145 | DEFINE_BINARY_OPERATOR (int, *) | |
146 | DEFINE_BINARY_OPERATOR (int, /) | |
147 | DEFINE_BINARY_OPERATOR (int, %) | |
148 | DEFINE_BINARY_OPERATOR (int, ^) | |
149 | DEFINE_BINARY_OPERATOR (int, |) | |
150 | DEFINE_BINARY_OPERATOR (int, &) | |
151 | DEFINE_BINARY_OPERATOR (int, >>) | |
152 | DEFINE_BINARY_OPERATOR (int, <<) | |
153 | DEFINE_UNARY_OPERATOR (int, !) | |
154 | DEFINE_UNARY_OPERATOR (int, ~) | |
155 | DEFINE_UNARY_OPERATOR (int, -) | |
156 | DEFINE_UNARY_OPERATOR (int, +) | |
157 | DEFINE_ASSIGN_OPERATOR (int, =) | |
158 | DEFINE_ASSIGN_OPERATOR (int, +=) | |
159 | DEFINE_ASSIGN_OPERATOR (int, -=) | |
160 | DEFINE_ASSIGN_OPERATOR (int, *=) | |
161 | DEFINE_ASSIGN_OPERATOR (int, /=) | |
162 | DEFINE_ASSIGN_OPERATOR (int, %=) | |
163 | DEFINE_ASSIGN_OPERATOR (int, >>=) | |
164 | DEFINE_ASSIGN_OPERATOR (int, <<=) | |
165 | }; | |
166 | ||
167 | // ============================================================================= | |
168 | CONFIGTYPE (str) { | |
169 | public: | |
170 | IMPLEMENT_CONFIG (str) | |
171 | ||
172 | DEFINE_ALL_COMPARE_OPERATORS (str) | |
173 | DEFINE_BINARY_OPERATOR (str, -) | |
174 | DEFINE_BINARY_OPERATOR (str, *) | |
175 | DEFINE_UNARY_OPERATOR (str, !) | |
176 | DEFINE_ASSIGN_OPERATOR (str, =) | |
177 | DEFINE_ASSIGN_OPERATOR (str, +=) | |
178 | DEFINE_ASSIGN_OPERATOR (str, -=) | |
179 | DEFINE_ASSIGN_OPERATOR (str, *=) | |
180 | DEFINE_CAST_OPERATOR (char*) | |
181 | ||
182 | char operator[] (size_t n) { | |
183 | return value[n]; | |
184 | } | |
185 | ||
186 | #ifdef CONFIG_WITH_QT | |
187 | operator QString () { | |
188 | return QString (value.chars()); | |
189 | } | |
190 | #endif // CONFIG_WITH_QT | |
191 | }; | |
192 | ||
193 | // ============================================================================= | |
194 | CONFIGTYPE (float) { | |
195 | public: | |
196 | IMPLEMENT_CONFIG (float) | |
197 | ||
198 | DEFINE_ALL_COMPARE_OPERATORS (float) | |
199 | DEFINE_INCREMENT_OPERATORS (float) | |
200 | DEFINE_BINARY_OPERATOR (float, +) | |
201 | DEFINE_BINARY_OPERATOR (float, -) | |
202 | DEFINE_BINARY_OPERATOR (float, *) | |
203 | DEFINE_UNARY_OPERATOR (float, !) | |
204 | DEFINE_ASSIGN_OPERATOR (float, =) | |
205 | DEFINE_ASSIGN_OPERATOR (float, +=) | |
206 | DEFINE_ASSIGN_OPERATOR (float, -=) | |
207 | DEFINE_ASSIGN_OPERATOR (float, *=) | |
208 | }; | |
209 | ||
210 | // ============================================================================= | |
211 | CONFIGTYPE (bool) { | |
212 | public: | |
213 | IMPLEMENT_CONFIG (bool) | |
214 | DEFINE_ALL_COMPARE_OPERATORS (bool) | |
215 | DEFINE_ASSIGN_OPERATOR (bool, =) | |
216 | }; | |
217 | ||
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
218 | // ============================================================================= |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
219 | typedef QKeySequence keyseq; |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
220 | |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
221 | CONFIGTYPE (keyseq) { |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
222 | public: |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
223 | IMPLEMENT_CONFIG (keyseq) |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
224 | DEFINE_ALL_COMPARE_OPERATORS (keyseq) |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
225 | DEFINE_ASSIGN_OPERATOR (keyseq, =) |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
226 | }; |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
227 | |
0 | 228 | #endif // __OPTIONS_H__ |