author | kergoth <kergoth> | 2002-02-08 18:07:57 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-02-08 18:07:57 (UTC) |
commit | d5714ac7fe62676ee1a63be2f965cb567ef7ae3e (patch) (unidiff) | |
tree | a9518ba91ba235733e00fbe6926f0ae7e29e8350 | |
parent | acae430926d1b5a8877e0d92cfc7abef749c8f1a (diff) | |
download | opie-d5714ac7fe62676ee1a63be2f965cb567ef7ae3e.zip opie-d5714ac7fe62676ee1a63be2f965cb567ef7ae3e.tar.gz opie-d5714ac7fe62676ee1a63be2f965cb567ef7ae3e.tar.bz2 |
Merged in Charles-Edouard Ruault's calculator patch to add temp conversion.
-rw-r--r-- | etc/unit_conversion.dat | 211 | ||||
-rw-r--r-- | noncore/tools/calculator/calculatorimpl.cpp | 24 | ||||
-rw-r--r-- | noncore/tools/calculator/calculatorimpl.h | 2 |
3 files changed, 232 insertions, 5 deletions
diff --git a/etc/unit_conversion.dat b/etc/unit_conversion.dat index 5ae312e..c19adf1 100644 --- a/etc/unit_conversion.dat +++ b/etc/unit_conversion.dat | |||
@@ -1,195 +1,406 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | STARTTYPE Weight | 21 | STARTTYPE Weight |
22 | STND grams | 22 | STND grams |
23 | 23 | ||
24 | NAME mg | 24 | NAME mg |
25 | RATIO 1000 | 25 | RATIO 1000 |
26 | PREOFF 0.0 | ||
27 | POSTOFF 0.0 | ||
28 | |||
26 | 29 | ||
27 | NAME g | 30 | NAME g |
28 | RATIO 1 | 31 | RATIO 1 |
32 | PREOFF 0.0 | ||
33 | POSTOFF 0.0 | ||
34 | |||
29 | 35 | ||
30 | NAME kg | 36 | NAME kg |
31 | RATIO 0.001 | 37 | RATIO 0.001 |
38 | PREOFF 0.0 | ||
39 | POSTOFF 0.0 | ||
40 | |||
32 | 41 | ||
33 | NAME tonnes | 42 | NAME tonnes |
34 | RATIO 1e-06 | 43 | RATIO 1e-06 |
44 | PREOFF 0.0 | ||
45 | POSTOFF 0.0 | ||
46 | |||
35 | 47 | ||
36 | NAME carats | 48 | NAME carats |
37 | RATIO 5 | 49 | RATIO 5 |
50 | PREOFF 0.0 | ||
51 | POSTOFF 0.0 | ||
52 | |||
38 | 53 | ||
39 | NAME oz | 54 | NAME oz |
40 | RATIO 0.03527336860670194 | 55 | RATIO 0.03527336860670194 |
56 | PREOFF 0.0 | ||
57 | POSTOFF 0.0 | ||
58 | |||
41 | 59 | ||
42 | NAME lb | 60 | NAME lb |
43 | RATIO 0.002204585537918871 | 61 | RATIO 0.002204585537918871 |
62 | PREOFF 0.0 | ||
63 | POSTOFF 0.0 | ||
64 | |||
44 | 65 | ||
45 | NAME st | 66 | NAME st |
46 | RATIO 0.0001574703955656337 | 67 | RATIO 0.0001574703955656337 |
68 | PREOFF 0.0 | ||
69 | POSTOFF 0.0 | ||
70 | |||
47 | 71 | ||
48 | NAME St tons | 72 | NAME St tons |
49 | RATIO 1.102292768959636e-06 | 73 | RATIO 1.102292768959636e-06 |
74 | PREOFF 0.0 | ||
75 | POSTOFF 0.0 | ||
76 | |||
50 | 77 | ||
51 | NAME Lg tons | 78 | NAME Lg tons |
52 | RATIO 9.841899722852103e-07 | 79 | RATIO 9.841899722852103e-07 |
80 | PREOFF 0.0 | ||
81 | POSTOFF 0.0 | ||
82 | |||
53 | 83 | ||
54 | NAME | 84 | NAME |
55 | RATIO 1. | 85 | RATIO 1. |
86 | PREOFF 0.0 | ||
87 | POSTOFF 0.0 | ||
88 | |||
56 | 89 | ||
57 | NAME | 90 | NAME |
58 | RATIO 1. | 91 | RATIO 1. |
92 | PREOFF 0.0 | ||
93 | POSTOFF 0.0 | ||
94 | |||
59 | 95 | ||
60 | ENDTYPE | 96 | ENDTYPE |
61 | 97 | ||
62 | 98 | ||
63 | 99 | ||
64 | STARTTYPE Distance | 100 | STARTTYPE Distance |
65 | STND m | 101 | STND m |
66 | 102 | ||
67 | NAME mm | 103 | NAME mm |
68 | RATIO 1000 | 104 | RATIO 1000 |
105 | PREOFF 0.0 | ||
106 | POSTOFF 0.0 | ||
107 | |||
69 | 108 | ||
70 | NAME cm | 109 | NAME cm |
71 | RATIO 100 | 110 | RATIO 100 |
111 | PREOFF 0.0 | ||
112 | POSTOFF 0.0 | ||
113 | |||
72 | 114 | ||
73 | NAME m | 115 | NAME m |
74 | RATIO 1 | 116 | RATIO 1 |
117 | PREOFF 0.0 | ||
118 | POSTOFF 0.0 | ||
119 | |||
75 | 120 | ||
76 | NAME km | 121 | NAME km |
77 | RATIO 0.001 | 122 | RATIO 0.001 |
123 | PREOFF 0.0 | ||
124 | POSTOFF 0.0 | ||
125 | |||
78 | 126 | ||
79 | NAME points | 127 | NAME points |
80 | RATIO 2834.64566929134 | 128 | RATIO 2834.64566929134 |
129 | PREOFF 0.0 | ||
130 | POSTOFF 0.0 | ||
131 | |||
81 | 132 | ||
82 | NAME in | 133 | NAME in |
83 | RATIO 39.3700787401575 | 134 | RATIO 39.3700787401575 |
135 | PREOFF 0.0 | ||
136 | POSTOFF 0.0 | ||
137 | |||
84 | 138 | ||
85 | NAME ft | 139 | NAME ft |
86 | RATIO 3.280839895013123 | 140 | RATIO 3.280839895013123 |
141 | PREOFF 0.0 | ||
142 | POSTOFF 0.0 | ||
143 | |||
87 | 144 | ||
88 | NAME yd | 145 | NAME yd |
89 | RATIO 1.093613298337708 | 146 | RATIO 1.093613298337708 |
147 | PREOFF 0.0 | ||
148 | POSTOFF 0.0 | ||
149 | |||
90 | 150 | ||
91 | NAME mi | 151 | NAME mi |
92 | RATIO 0.0006213711922373339 | 152 | RATIO 0.0006213711922373339 |
153 | PREOFF 0.0 | ||
154 | POSTOFF 0.0 | ||
155 | |||
93 | 156 | ||
94 | NAME naut. mi | 157 | NAME naut. mi |
95 | RATIO 0.0005399568034557236 | 158 | RATIO 0.0005399568034557236 |
159 | PREOFF 0.0 | ||
160 | POSTOFF 0.0 | ||
161 | |||
96 | 162 | ||
97 | NAME | 163 | NAME |
98 | RATIO 1. | 164 | RATIO 1. |
165 | PREOFF 0.0 | ||
166 | POSTOFF 0.0 | ||
167 | |||
99 | 168 | ||
100 | NAME | 169 | NAME |
101 | RATIO 1. | 170 | RATIO 1. |
171 | PREOFF 0.0 | ||
172 | POSTOFF 0.0 | ||
173 | |||
102 | 174 | ||
103 | ENDTYPE | 175 | ENDTYPE |
104 | 176 | ||
105 | 177 | ||
106 | 178 | ||
107 | STARTTYPE Area | 179 | STARTTYPE Area |
108 | STND sq m | 180 | STND sq m |
109 | 181 | ||
110 | NAME sq mm | 182 | NAME sq mm |
111 | RATIO 1000000 | 183 | RATIO 1000000 |
184 | PREOFF 0.0 | ||
185 | POSTOFF 0.0 | ||
186 | |||
112 | 187 | ||
113 | NAME sq cm | 188 | NAME sq cm |
114 | RATIO 10000 | 189 | RATIO 10000 |
190 | PREOFF 0.0 | ||
191 | POSTOFF 0.0 | ||
192 | |||
115 | 193 | ||
116 | NAME sq m | 194 | NAME sq m |
117 | RATIO 1 | 195 | RATIO 1 |
196 | PREOFF 0.0 | ||
197 | POSTOFF 0.0 | ||
198 | |||
118 | 199 | ||
119 | NAME sq km | 200 | NAME sq km |
120 | RATIO 1e-06 | 201 | RATIO 1e-06 |
202 | PREOFF 0.0 | ||
203 | POSTOFF 0.0 | ||
204 | |||
121 | 205 | ||
122 | NAME hectares | 206 | NAME hectares |
123 | RATIO 0.0001 | 207 | RATIO 0.0001 |
208 | PREOFF 0.0 | ||
209 | POSTOFF 0.0 | ||
210 | |||
124 | 211 | ||
125 | NAME sq in | 212 | NAME sq in |
126 | RATIO 1550.0031000062 | 213 | RATIO 1550.0031000062 |
214 | PREOFF 0.0 | ||
215 | POSTOFF 0.0 | ||
216 | |||
127 | 217 | ||
128 | NAME sq ft | 218 | NAME sq ft |
129 | RATIO 10.7639104167097 | 219 | RATIO 10.7639104167097 |
220 | PREOFF 0.0 | ||
221 | POSTOFF 0.0 | ||
222 | |||
130 | 223 | ||
131 | NAME sq yd | 224 | NAME sq yd |
132 | RATIO 1.19599004630108 | 225 | RATIO 1.19599004630108 |
226 | PREOFF 0.0 | ||
227 | POSTOFF 0.0 | ||
228 | |||
133 | 229 | ||
134 | NAME sq mi | 230 | NAME sq mi |
135 | RATIO 0.000000386102158542446 | 231 | RATIO 0.000000386102158542446 |
232 | PREOFF 0.0 | ||
233 | POSTOFF 0.0 | ||
234 | |||
136 | 235 | ||
137 | NAME acres | 236 | NAME acres |
138 | RATIO 0.0002471053814671653 | 237 | RATIO 0.0002471053814671653 |
238 | PREOFF 0.0 | ||
239 | POSTOFF 0.0 | ||
240 | |||
139 | 241 | ||
140 | NAME | 242 | NAME |
141 | RATIO 1. | 243 | RATIO 1. |
244 | PREOFF 0.0 | ||
245 | POSTOFF 0.0 | ||
246 | |||
142 | 247 | ||
143 | NAME | 248 | NAME |
144 | RATIO 1. | 249 | RATIO 1. |
250 | PREOFF 0.0 | ||
251 | POSTOFF 0.0 | ||
252 | |||
145 | 253 | ||
146 | ENDTYPE | 254 | ENDTYPE |
147 | 255 | ||
256 | STARTTYPE Temperatures | ||
257 | STND °C | ||
258 | |||
259 | NAME | ||
260 | RATIO 1. | ||
261 | PREOFF 0.0 | ||
262 | POSTOFF 0.0 | ||
263 | |||
264 | NAME | ||
265 | RATIO 1. | ||
266 | PREOFF 0.0 | ||
267 | POSTOFF 0.0 | ||
268 | |||
269 | NAME | ||
270 | RATIO 1. | ||
271 | PREOFF 0.0 | ||
272 | POSTOFF 0.0 | ||
273 | |||
274 | NAME | ||
275 | RATIO 1. | ||
276 | PREOFF 0.0 | ||
277 | POSTOFF 0.0 | ||
278 | |||
279 | NAME | ||
280 | RATIO 1. | ||
281 | PREOFF 0.0 | ||
282 | POSTOFF 0.0 | ||
283 | |||
284 | NAME °C | ||
285 | RATIO 1.0 | ||
286 | PREOFF 0.0 | ||
287 | POSTOFF 0.0 | ||
288 | |||
289 | NAME °F | ||
290 | RATIO 1.8 | ||
291 | PREOFF -32.0 | ||
292 | POSTOFF +32.0 | ||
293 | |||
294 | NAME | ||
295 | RATIO 1. | ||
296 | PREOFF 0.0 | ||
297 | POSTOFF 0.0 | ||
298 | |||
299 | NAME | ||
300 | RATIO 1. | ||
301 | PREOFF 0.0 | ||
302 | POSTOFF 0.0 | ||
303 | |||
304 | NAME | ||
305 | RATIO 1. | ||
306 | PREOFF 0.0 | ||
307 | POSTOFF 0.0 | ||
308 | |||
309 | NAME | ||
310 | RATIO 1. | ||
311 | PREOFF 0.0 | ||
312 | POSTOFF 0.0 | ||
313 | |||
314 | NAME | ||
315 | RATIO 1. | ||
316 | PREOFF 0.0 | ||
317 | POSTOFF 0.0 | ||
318 | |||
319 | ENDTYPE | ||
148 | 320 | ||
149 | 321 | ||
150 | STARTTYPE Volume | 322 | STARTTYPE Volume |
151 | STND litres | 323 | STND litres |
152 | 324 | ||
153 | NAME cu cm | 325 | NAME cu cm |
154 | RATIO 1000 | 326 | RATIO 1000 |
327 | PREOFF 0.0 | ||
328 | POSTOFF 0.0 | ||
329 | |||
155 | 330 | ||
156 | NAME ml | 331 | NAME ml |
157 | RATIO 1000 | 332 | RATIO 1000 |
333 | PREOFF 0.0 | ||
334 | POSTOFF 0.0 | ||
335 | |||
158 | 336 | ||
159 | NAME l | 337 | NAME l |
160 | RATIO 1 | 338 | RATIO 1 |
339 | PREOFF 0.0 | ||
340 | POSTOFF 0.0 | ||
341 | |||
161 | 342 | ||
162 | NAME tblspoon | 343 | NAME tblspoon |
163 | RATIO 67.6280454036859 | 344 | RATIO 67.6280454036859 |
345 | PREOFF 0.0 | ||
346 | POSTOFF 0.0 | ||
347 | |||
164 | 348 | ||
165 | NAME teaspoons | 349 | NAME teaspoons |
166 | RATIO 202.884136211058 | 350 | RATIO 202.884136211058 |
351 | PREOFF 0.0 | ||
352 | POSTOFF 0.0 | ||
353 | |||
167 | 354 | ||
168 | NAME cu in | 355 | NAME cu in |
169 | RATIO 61.0237440947323 | 356 | RATIO 61.0237440947323 |
357 | PREOFF 0.0 | ||
358 | POSTOFF 0.0 | ||
359 | |||
170 | 360 | ||
171 | NAME cu ft | 361 | NAME cu ft |
172 | RATIO 0.0353146667214886 | 362 | RATIO 0.0353146667214886 |
363 | PREOFF 0.0 | ||
364 | POSTOFF 0.0 | ||
365 | |||
173 | 366 | ||
174 | NAME pt | 367 | NAME pt |
175 | RATIO 2.11337641886519 | 368 | RATIO 2.11337641886519 |
369 | PREOFF 0.0 | ||
370 | POSTOFF 0.0 | ||
371 | |||
176 | 372 | ||
177 | NAME qt | 373 | NAME qt |
178 | RATIO 1.05668820943259 | 374 | RATIO 1.05668820943259 |
375 | PREOFF 0.0 | ||
376 | POSTOFF 0.0 | ||
377 | |||
179 | 378 | ||
180 | NAME gal (US) | 379 | NAME gal (US) |
181 | RATIO 0.264172052358148 | 380 | RATIO 0.264172052358148 |
381 | PREOFF 0.0 | ||
382 | POSTOFF 0.0 | ||
383 | |||
182 | 384 | ||
183 | NAME | 385 | NAME |
184 | RATIO 1. | 386 | RATIO 1. |
387 | PREOFF 0.0 | ||
388 | POSTOFF 0.0 | ||
389 | |||
185 | 390 | ||
186 | NAME | 391 | NAME |
187 | RATIO 1. | 392 | RATIO 1. |
393 | PREOFF 0.0 | ||
394 | POSTOFF 0.0 | ||
395 | |||
188 | 396 | ||
189 | ENDTYPE | 397 | ENDTYPE |
190 | 398 | ||
191 | Extra units | 399 | Extra units |
192 | 400 | ||
193 | NAME fl oz (US) | 401 | NAME fl oz (US) |
194 | RATIO 33.8140227018429 | 402 | RATIO 33.8140227018429 |
403 | PREOFF 0.0 | ||
404 | POSTOFF 0.0 | ||
405 | |||
195 | 406 | ||
diff --git a/noncore/tools/calculator/calculatorimpl.cpp b/noncore/tools/calculator/calculatorimpl.cpp index 2f7d7ce..1b93c7f 100644 --- a/noncore/tools/calculator/calculatorimpl.cpp +++ b/noncore/tools/calculator/calculatorimpl.cpp | |||
@@ -1,601 +1,615 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | /* | ||
22 | * 01/14/2002 Charles-Edouard Ruault <ce@ruault.com> | ||
23 | * Added support for Temperature conversions. | ||
24 | */ | ||
25 | |||
21 | #include "calculatorimpl.h" | 26 | #include "calculatorimpl.h" |
22 | 27 | ||
23 | #include <qpe/resource.h> | 28 | #include <qpe/resource.h> |
24 | #include <qpe/qmath.h> | 29 | #include <qpe/qmath.h> |
25 | #include <qpe/qpeapplication.h> | 30 | #include <qpe/qpeapplication.h> |
26 | 31 | ||
27 | #include <qpushbutton.h> | 32 | #include <qpushbutton.h> |
28 | #include <qcombobox.h> | 33 | #include <qcombobox.h> |
29 | #include <qlabel.h> | 34 | #include <qlabel.h> |
30 | #include <qfont.h> | 35 | #include <qfont.h> |
31 | #include <qlayout.h> | 36 | #include <qlayout.h> |
32 | #include <qstringlist.h> | 37 | #include <qstringlist.h> |
33 | #include <qfile.h> | 38 | #include <qfile.h> |
34 | #include <qtextstream.h> | 39 | #include <qtextstream.h> |
35 | #include <qmessagebox.h> | 40 | #include <qmessagebox.h> |
36 | #include <math.h> | 41 | #include <math.h> |
37 | 42 | ||
38 | CalculatorImpl::CalculatorImpl( QWidget * parent, const char * name, | 43 | CalculatorImpl::CalculatorImpl( QWidget * parent, const char * name, |
39 | WFlags f ) | 44 | WFlags f ) |
40 | : Calculator( parent, name, f ) | 45 | : Calculator( parent, name, f ) |
41 | { | 46 | { |
42 | xtopowerofy = Resource::loadPixmap("xtopowerofy"); | 47 | xtopowerofy = Resource::loadPixmap("xtopowerofy"); |
43 | ythrootofx = Resource::loadPixmap("ythrootofx"); | 48 | ythrootofx = Resource::loadPixmap("ythrootofx"); |
44 | oneoverx = Resource::loadPixmap("oneoverx"); | 49 | oneoverx = Resource::loadPixmap("oneoverx"); |
45 | 50 | ||
46 | memMark = new QLabel( "m", LCD ); | 51 | memMark = new QLabel( "m", LCD ); |
47 | memMark->setFont( QFont( "helvetica", 12, QFont::Bold, TRUE ) ); | 52 | memMark->setFont( QFont( "helvetica", 12, QFont::Bold, TRUE ) ); |
48 | memMark->resize( 12, 12 ); | 53 | memMark->resize( 12, 12 ); |
49 | memMark->move( 4, 2 ); | 54 | memMark->move( 4, 2 ); |
50 | memMark->hide(); | 55 | memMark->hide(); |
51 | mem = 0; | 56 | mem = 0; |
52 | 57 | ||
53 | PushButtonMR->setEnabled( FALSE ); | 58 | PushButtonMR->setEnabled( FALSE ); |
54 | 59 | ||
55 | current_mode = max_mode = conversion_mode_count = 0; | 60 | current_mode = max_mode = conversion_mode_count = 0; |
56 | last_conversion = -1; | 61 | last_conversion = -1; |
57 | 62 | ||
58 | //bgr_command.insert( PushButtonFunction); | 63 | //bgr_command.insert( PushButtonFunction); |
59 | bgr_command.insert( PushButtonMPlus); | 64 | bgr_command.insert( PushButtonMPlus); |
60 | bgr_command.insert( PushButtonMR); | 65 | bgr_command.insert( PushButtonMR); |
61 | bgr_command.insert( PushButtonMC); | 66 | bgr_command.insert( PushButtonMC); |
62 | bgr_command.insert( PushButtonCE); | 67 | bgr_command.insert( PushButtonCE); |
63 | connect( &bgr_command, SIGNAL(clicked(int) ), this, SLOT(command_buttons(int))); | 68 | connect( &bgr_command, SIGNAL(clicked(int) ), this, SLOT(command_buttons(int))); |
64 | 69 | ||
65 | bgr_digits.insert(PushButton0); | 70 | bgr_digits.insert(PushButton0); |
66 | bgr_digits.insert(PushButton1); | 71 | bgr_digits.insert(PushButton1); |
67 | bgr_digits.insert(PushButton2); | 72 | bgr_digits.insert(PushButton2); |
68 | bgr_digits.insert(PushButton3); | 73 | bgr_digits.insert(PushButton3); |
69 | bgr_digits.insert(PushButton4); | 74 | bgr_digits.insert(PushButton4); |
70 | bgr_digits.insert(PushButton5); | 75 | bgr_digits.insert(PushButton5); |
71 | bgr_digits.insert(PushButton6); | 76 | bgr_digits.insert(PushButton6); |
72 | bgr_digits.insert(PushButton7); | 77 | bgr_digits.insert(PushButton7); |
73 | bgr_digits.insert(PushButton8); | 78 | bgr_digits.insert(PushButton8); |
74 | bgr_digits.insert(PushButton9); | 79 | bgr_digits.insert(PushButton9); |
75 | connect( &bgr_digits, SIGNAL(clicked(int) ), this, SLOT(enterNumber(int))); | 80 | connect( &bgr_digits, SIGNAL(clicked(int) ), this, SLOT(enterNumber(int))); |
76 | 81 | ||
77 | 82 | ||
78 | bgr_std.insert(PushButtonEquals); | 83 | bgr_std.insert(PushButtonEquals); |
79 | bgr_std.insert(PushButtonDecimal); | 84 | bgr_std.insert(PushButtonDecimal); |
80 | bgr_std.insert(PushButtonAdd); | 85 | bgr_std.insert(PushButtonAdd); |
81 | bgr_std.insert(PushButtonMinus); | 86 | bgr_std.insert(PushButtonMinus); |
82 | bgr_std.insert(PushButtonDivide); | 87 | bgr_std.insert(PushButtonDivide); |
83 | bgr_std.insert(PushButtonTimes); | 88 | bgr_std.insert(PushButtonTimes); |
84 | connect( &bgr_std, SIGNAL(clicked(int) ), this, SLOT(std_buttons(int))); | 89 | connect( &bgr_std, SIGNAL(clicked(int) ), this, SLOT(std_buttons(int))); |
85 | 90 | ||
86 | // change the / to a proper division signal | 91 | // change the / to a proper division signal |
87 | PushButtonDivide->setText(QChar(0xF7)); | 92 | PushButtonDivide->setText(QChar(0xF7)); |
88 | 93 | ||
89 | func_buttons[0] = PushButtonF1; | 94 | func_buttons[0] = PushButtonF1; |
90 | func_buttons[1] = PushButtonF2; | 95 | func_buttons[1] = PushButtonF2; |
91 | func_buttons[2] = PushButtonF3; | 96 | func_buttons[2] = PushButtonF3; |
92 | func_buttons[3] = PushButtonF4; | 97 | func_buttons[3] = PushButtonF4; |
93 | func_buttons[4] = PushButtonF5; | 98 | func_buttons[4] = PushButtonF5; |
94 | func_buttons[5] = PushButtonF6; | 99 | func_buttons[5] = PushButtonF6; |
95 | func_buttons[6] = PushButtonF7; | 100 | func_buttons[6] = PushButtonF7; |
96 | func_buttons[7] = PushButtonF8; | 101 | func_buttons[7] = PushButtonF8; |
97 | func_buttons[8] = PushButtonF9; | 102 | func_buttons[8] = PushButtonF9; |
98 | func_buttons[9] = PushButtonF10; | 103 | func_buttons[9] = PushButtonF10; |
99 | func_buttons[10] = PushButtonF11; | 104 | func_buttons[10] = PushButtonF11; |
100 | func_buttons[11] = PushButtonF12; | 105 | func_buttons[11] = PushButtonF12; |
101 | 106 | ||
102 | for ( int x = 0 ; x < func_button_count ; x++ ) { | 107 | for ( int x = 0 ; x < func_button_count ; x++ ) { |
103 | QPushButton* tmpbutton = func_buttons[x]; | 108 | QPushButton* tmpbutton = func_buttons[x]; |
104 | faces << tmpbutton->text(); | 109 | faces << tmpbutton->text(); |
105 | bgr_function.insert(tmpbutton); | 110 | bgr_function.insert(tmpbutton); |
106 | } | 111 | } |
107 | connect( &bgr_function, SIGNAL(clicked(int) ) , this, SLOT(do_convert(int) ) ); | 112 | connect( &bgr_function, SIGNAL(clicked(int) ) , this, SLOT(do_convert(int) ) ); |
108 | connect( &bgr_function, SIGNAL(clicked(int) ) , this, SLOT(std_funcs (int) ) ); | 113 | connect( &bgr_function, SIGNAL(clicked(int) ) , this, SLOT(std_funcs (int) ) ); |
109 | 114 | ||
110 | connect(ComboBoxFunction, SIGNAL(activated(int) ), this, SLOT(function_button(int) ) ); | 115 | connect(ComboBoxFunction, SIGNAL(activated(int) ), this, SLOT(function_button(int) ) ); |
111 | 116 | ||
112 | captions.append("Standard"); | 117 | captions.append("Standard"); |
113 | ComboBoxFunction->insertItem(captions.last()); | 118 | ComboBoxFunction->insertItem(captions.last()); |
114 | 119 | ||
115 | // now add in the conversion modes | 120 | // now add in the conversion modes |
116 | // when the menu gets done, these should be in a submenu | 121 | // when the menu gets done, these should be in a submenu |
117 | QString tmp = QPEApplication::qpeDir(); | 122 | QString tmp = QPEApplication::qpeDir(); |
118 | tmp += "/etc/unit_conversion.dat"; | 123 | tmp += "/etc/unit_conversion.dat"; |
119 | QFile myfile(tmp); | 124 | QFile myfile(tmp); |
120 | if ( !myfile.open( IO_Translate | IO_ReadOnly ) ) { | 125 | if ( !myfile.open( IO_Translate | IO_ReadOnly ) ) { |
121 | // QMessageBox::warning(this, "Warning", "Data file\nunit_conversion.dat\nnot found\nNo conversion\nfeatures will\nbe available"); | 126 | // QMessageBox::warning(this, "Warning", "Data file\nunit_conversion.dat\nnot found\nNo conversion\nfeatures will\nbe available"); |
122 | // disable the f button if no conv file available | 127 | // disable the f button if no conv file available |
123 | ComboBoxFunction->setEnabled(FALSE); | 128 | ComboBoxFunction->setEnabled(FALSE); |
124 | } | 129 | } |
125 | else { | 130 | else { |
126 | QString line, line2; | 131 | QString line, line2; |
127 | QTextStream ts(&myfile); | 132 | QTextStream ts(&myfile); |
128 | 133 | ||
129 | // first pass, see how many conversion types there are in order to allocate for them | 134 | // first pass, see how many conversion types there are in order to allocate for them |
130 | while ( ! ts.eof() ) { | 135 | while ( ! ts.eof() ) { |
131 | line = ts.readLine(); | 136 | line = ts.readLine(); |
132 | if ( line.contains ("STARTTYPE" ) ) | 137 | if ( line.contains ("STARTTYPE" ) ) |
133 | conversion_mode_count++; | 138 | conversion_mode_count++; |
134 | } | 139 | } |
135 | 140 | ||
136 | entry_list = new double[conversion_mode_count*func_button_count]; | 141 | entry_list = new double[conversion_mode_count*func_button_count]; |
137 | 142 | preoffset_list = new double[conversion_mode_count*func_button_count]; | |
143 | postoffset_list = new double[conversion_mode_count*func_button_count]; | ||
138 | myfile.close(); | 144 | myfile.close(); |
139 | myfile.open( IO_Translate | IO_ReadOnly ); | 145 | myfile.open( IO_Translate | IO_ReadOnly ); |
140 | QTextStream ts2(&myfile); | 146 | QTextStream ts2(&myfile); |
141 | 147 | ||
142 | // second pass, read in values | 148 | // second pass, read in values |
143 | int x = 0; | 149 | int x = 0; |
144 | while ( ! ts2.eof() ) { | 150 | while ( ! ts2.eof() ) { |
145 | line = ts2.readLine(); | 151 | line = ts2.readLine(); |
146 | if ( line.contains("STARTTYPE") ) { | 152 | if ( line.contains("STARTTYPE") ) { |
147 | captions << line.remove(0,10); | 153 | captions << line.remove(0,10); |
148 | ComboBoxFunction->insertItem(captions.last()); | 154 | ComboBoxFunction->insertItem(captions.last()); |
149 | while ( !line.contains("ENDTYPE") ) { | 155 | while ( !line.contains("ENDTYPE") ) { |
150 | line = ts2.readLine(); | 156 | line = ts2.readLine(); |
151 | if ( line.contains("NAME") ) { | 157 | if ( line.contains("NAME") ) { |
152 | faces << line.remove(0,5); | 158 | faces << line.remove(0,5); |
153 | line2 = ts2.readLine(); | 159 | line2 = ts2.readLine(); |
154 | line2.remove(0,6); | 160 | line2.remove(0,6); |
155 | entry_list[x] = line2.toDouble(); | 161 | entry_list[x] = line2.toDouble(); |
162 | line2 = ts2.readLine(); | ||
163 | line2.remove(0,7); | ||
164 | preoffset_list[x] = line2.toDouble(); | ||
165 | line2 = ts2.readLine(); | ||
166 | line2.remove(0,8); | ||
167 | postoffset_list[x] = line2.toDouble(); | ||
156 | x++; | 168 | x++; |
157 | } | 169 | } |
158 | } | 170 | } |
159 | } | 171 | } |
160 | } | 172 | } |
161 | } | 173 | } |
162 | myfile.close(); | 174 | myfile.close(); |
163 | clear(); | 175 | clear(); |
164 | max_mode = pre_conv_modes_count + conversion_mode_count + post_conv_modes_count - 1; | 176 | max_mode = pre_conv_modes_count + conversion_mode_count + post_conv_modes_count - 1; |
165 | display_pixmap_faces(); | 177 | display_pixmap_faces(); |
166 | 178 | ||
167 | qApp->installEventFilter( this ); | 179 | qApp->installEventFilter( this ); |
168 | } | 180 | } |
169 | 181 | ||
170 | bool CalculatorImpl::eventFilter( QObject *o, QEvent *e ) | 182 | bool CalculatorImpl::eventFilter( QObject *o, QEvent *e ) |
171 | { | 183 | { |
172 | if ( e->type() == QEvent::KeyPress && state != sError ) { | 184 | if ( e->type() == QEvent::KeyPress && state != sError ) { |
173 | QKeyEvent *k = (QKeyEvent*)e; | 185 | QKeyEvent *k = (QKeyEvent*)e; |
174 | if ( k->key() >= Key_0 && k->key() <= Key_9 ) { | 186 | if ( k->key() >= Key_0 && k->key() <= Key_9 ) { |
175 | enterNumber( k->key() - Key_0 ); | 187 | enterNumber( k->key() - Key_0 ); |
176 | return true; | 188 | return true; |
177 | } else { | 189 | } else { |
178 | switch ( k->key() ) { | 190 | switch ( k->key() ) { |
179 | case Key_Equal: | 191 | case Key_Equal: |
180 | std_buttons(0); | 192 | std_buttons(0); |
181 | return true; | 193 | return true; |
182 | case Key_Period: | 194 | case Key_Period: |
183 | std_buttons(1); | 195 | std_buttons(1); |
184 | return true; | 196 | return true; |
185 | case Key_Plus: | 197 | case Key_Plus: |
186 | std_buttons(2); | 198 | std_buttons(2); |
187 | return true; | 199 | return true; |
188 | case Key_Minus: | 200 | case Key_Minus: |
189 | std_buttons(3); | 201 | std_buttons(3); |
190 | return true; | 202 | return true; |
191 | case Key_Slash: | 203 | case Key_Slash: |
192 | std_buttons(4); | 204 | std_buttons(4); |
193 | return true; | 205 | return true; |
194 | case Key_Asterisk: | 206 | case Key_Asterisk: |
195 | std_buttons(5); | 207 | std_buttons(5); |
196 | return true; | 208 | return true; |
197 | case Key_Percent: | 209 | case Key_Percent: |
198 | execOp( oPercent ); | 210 | execOp( oPercent ); |
199 | return true; | 211 | return true; |
200 | case Key_ParenLeft: | 212 | case Key_ParenLeft: |
201 | if ( current_mode < pre_conv_modes_count ) | 213 | if ( current_mode < pre_conv_modes_count ) |
202 | execOp( oOpenBrace ); | 214 | execOp( oOpenBrace ); |
203 | return true; | 215 | return true; |
204 | case Key_ParenRight: | 216 | case Key_ParenRight: |
205 | if ( current_mode < pre_conv_modes_count ) | 217 | if ( current_mode < pre_conv_modes_count ) |
206 | execOp( oCloseBrace ); | 218 | execOp( oCloseBrace ); |
207 | return true; | 219 | return true; |
208 | default: | 220 | default: |
209 | break; | 221 | break; |
210 | } | 222 | } |
211 | } | 223 | } |
212 | } | 224 | } |
213 | return Calculator::eventFilter( o, e ); | 225 | return Calculator::eventFilter( o, e ); |
214 | } | 226 | } |
215 | 227 | ||
216 | void CalculatorImpl::do_convert(int button) { | 228 | void CalculatorImpl::do_convert(int button) { |
217 | if ( state == sError ) | 229 | if ( state == sError ) |
218 | return; | 230 | return; |
219 | if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) && | 231 | if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) && |
220 | button < changeable_func_button_count ) { | 232 | button < changeable_func_button_count ) { |
221 | if ( last_conversion > -1 ) { | 233 | if ( last_conversion > -1 ) { |
222 | if( state == sNewNumber ){ | 234 | if( state == sNewNumber ){ |
223 | acc = num | 235 | acc = (num+ preoffset_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion]) |
224 | / (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion]) | 236 | / (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion]) |
225 | * (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + button]) ; | 237 | * (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + button]) |
238 | +postoffset_list[(current_mode - pre_conv_modes_count) * func_button_count + button]; | ||
226 | num = acc; | 239 | num = acc; |
227 | LCD->display( acc ); | 240 | LCD->display( acc ); |
228 | } else { | 241 | } else { |
229 | state = sNewNumber; | 242 | state = sNewNumber; |
230 | num = num | 243 | num = (num+ preoffset_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion]) |
231 | / (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion]) | 244 | / (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion]) |
232 | * (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + button]) ; | 245 | * (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + button]) |
246 | + postoffset_list[(current_mode - pre_conv_modes_count) * func_button_count + button];; | ||
233 | LCD->display( num ); | 247 | LCD->display( num ); |
234 | acc = num; | 248 | acc = num; |
235 | } | 249 | } |
236 | } | 250 | } |
237 | last_conversion = button; | 251 | last_conversion = button; |
238 | } | 252 | } |
239 | } | 253 | } |
240 | 254 | ||
241 | 255 | ||
242 | void CalculatorImpl::function_button(int mode){ | 256 | void CalculatorImpl::function_button(int mode){ |
243 | if ( state == sError ) | 257 | if ( state == sError ) |
244 | clear(); | 258 | clear(); |
245 | // dont need the next line when using a popup menu | 259 | // dont need the next line when using a popup menu |
246 | current_mode = mode; | 260 | current_mode = mode; |
247 | 261 | ||
248 | // reset the last conv | 262 | // reset the last conv |
249 | last_conversion = -1; | 263 | last_conversion = -1; |
250 | 264 | ||
251 | // set the caption | 265 | // set the caption |
252 | this->setCaption( captions[current_mode] ); | 266 | this->setCaption( captions[current_mode] ); |
253 | 267 | ||
254 | reset_conv(); | 268 | reset_conv(); |
255 | 269 | ||
256 | for ( int x = 0 ; x < changeable_func_button_count ; x++ ) { | 270 | for ( int x = 0 ; x < changeable_func_button_count ; x++ ) { |
257 | QPushButton* tmpbutton = func_buttons[x]; | 271 | QPushButton* tmpbutton = func_buttons[x]; |
258 | 272 | ||
259 | // if its a conversion , make it a toggle button | 273 | // if its a conversion , make it a toggle button |
260 | if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) ) { | 274 | if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) ) { |
261 | tmpbutton->setToggleButton(TRUE); | 275 | tmpbutton->setToggleButton(TRUE); |
262 | } else { | 276 | } else { |
263 | tmpbutton->setToggleButton(FALSE); | 277 | tmpbutton->setToggleButton(FALSE); |
264 | } | 278 | } |
265 | tmpbutton->setText( faces[current_mode * func_button_count + x] ); | 279 | tmpbutton->setText( faces[current_mode * func_button_count + x] ); |
266 | } | 280 | } |
267 | 281 | ||
268 | if ( current_mode == 0 ) display_pixmap_faces(); | 282 | if ( current_mode == 0 ) display_pixmap_faces(); |
269 | 283 | ||
270 | if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) ) { | 284 | if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) ) { |
271 | bgr_function.setExclusive(TRUE); | 285 | bgr_function.setExclusive(TRUE); |
272 | } else { | 286 | } else { |
273 | bgr_function.setExclusive(FALSE); | 287 | bgr_function.setExclusive(FALSE); |
274 | } | 288 | } |
275 | } | 289 | } |
276 | 290 | ||
277 | void CalculatorImpl::display_pixmap_faces() { | 291 | void CalculatorImpl::display_pixmap_faces() { |
278 | QPushButton* tmpbutton = func_buttons[5]; | 292 | QPushButton* tmpbutton = func_buttons[5]; |
279 | tmpbutton->setPixmap(xtopowerofy); | 293 | tmpbutton->setPixmap(xtopowerofy); |
280 | 294 | ||
281 | tmpbutton = func_buttons[6]; | 295 | tmpbutton = func_buttons[6]; |
282 | tmpbutton->setPixmap(ythrootofx); | 296 | tmpbutton->setPixmap(ythrootofx); |
283 | 297 | ||
284 | tmpbutton = func_buttons[3]; | 298 | tmpbutton = func_buttons[3]; |
285 | tmpbutton->setPixmap(oneoverx); | 299 | tmpbutton->setPixmap(oneoverx); |
286 | } | 300 | } |
287 | 301 | ||
288 | void CalculatorImpl::clear() { | 302 | void CalculatorImpl::clear() { |
289 | acc = num = 0; | 303 | acc = num = 0; |
290 | operationStack.clear(); | 304 | operationStack.clear(); |
291 | state = sStart; | 305 | state = sStart; |
292 | numDecimals = 0; | 306 | numDecimals = 0; |
293 | numOpenBraces = 0; | 307 | numOpenBraces = 0; |
294 | flPoint = FALSE; | 308 | flPoint = FALSE; |
295 | LCD->display( 0 ); | 309 | LCD->display( 0 ); |
296 | fake = QString::null; | 310 | fake = QString::null; |
297 | 311 | ||
298 | reset_conv(); | 312 | reset_conv(); |
299 | } | 313 | } |
300 | 314 | ||
301 | void CalculatorImpl::reset_conv() { | 315 | void CalculatorImpl::reset_conv() { |
302 | for ( int x = 0 ; x < changeable_func_button_count ; x++ ) { | 316 | for ( int x = 0 ; x < changeable_func_button_count ; x++ ) { |
303 | QPushButton* tmpbutton = func_buttons[x]; | 317 | QPushButton* tmpbutton = func_buttons[x]; |
304 | 318 | ||
305 | // dont carry any selections into the next mode | 319 | // dont carry any selections into the next mode |
306 | if ( tmpbutton->state() == QPushButton::On ) { | 320 | if ( tmpbutton->state() == QPushButton::On ) { |
307 | tmpbutton->toggle(); | 321 | tmpbutton->toggle(); |
308 | } | 322 | } |
309 | } | 323 | } |
310 | 324 | ||
311 | last_conversion = -1; | 325 | last_conversion = -1; |
312 | } | 326 | } |
313 | 327 | ||
314 | void CalculatorImpl::std_buttons(int button) | 328 | void CalculatorImpl::std_buttons(int button) |
315 | { | 329 | { |
316 | if ( state == sError ) | 330 | if ( state == sError ) |
317 | return; | 331 | return; |
318 | execOp( (Operation)(button + oSum) ); | 332 | execOp( (Operation)(button + oSum) ); |
319 | } | 333 | } |
320 | 334 | ||
321 | void CalculatorImpl::std_funcs(int button) { | 335 | void CalculatorImpl::std_funcs(int button) { |
322 | if ( state == sError ) | 336 | if ( state == sError ) |
323 | return; | 337 | return; |
324 | if ( current_mode < pre_conv_modes_count || | 338 | if ( current_mode < pre_conv_modes_count || |
325 | button > changeable_func_button_count-1 ) { | 339 | button > changeable_func_button_count-1 ) { |
326 | Operation op; | 340 | Operation op; |
327 | if ( button < 10 ) | 341 | if ( button < 10 ) |
328 | op = (Operation)(button + oSin); | 342 | op = (Operation)(button + oSin); |
329 | else if ( button == 10 ) | 343 | else if ( button == 10 ) |
330 | op = oOpenBrace; | 344 | op = oOpenBrace; |
331 | else | 345 | else |
332 | op = oCloseBrace; | 346 | op = oCloseBrace; |
333 | execOp( op ); | 347 | execOp( op ); |
334 | } | 348 | } |
335 | } | 349 | } |
336 | 350 | ||
337 | void CalculatorImpl::execOp( Operation i ) | 351 | void CalculatorImpl::execOp( Operation i ) |
338 | { | 352 | { |
339 | switch (i) { | 353 | switch (i) { |
340 | // these operators only affect the current number. | 354 | // these operators only affect the current number. |
341 | case oDivX: | 355 | case oDivX: |
342 | case oLog: | 356 | case oLog: |
343 | case oLn: | 357 | case oLn: |
344 | case oSin: | 358 | case oSin: |
345 | case oCos: | 359 | case oCos: |
346 | case oTan: | 360 | case oTan: |
347 | num = evalExpr(i); | 361 | num = evalExpr(i); |
348 | break; | 362 | break; |
349 | 363 | ||
350 | case oAdd: | 364 | case oAdd: |
351 | case oSub: { | 365 | case oSub: { |
352 | processStack( oAdd ); | 366 | processStack( oAdd ); |
353 | Op op( num, i ); | 367 | Op op( num, i ); |
354 | operationStack.push( op ); | 368 | operationStack.push( op ); |
355 | break; | 369 | break; |
356 | } | 370 | } |
357 | case oDiv: | 371 | case oDiv: |
358 | case oMult: | 372 | case oMult: |
359 | case oRoot: | 373 | case oRoot: |
360 | case oXsquared: { | 374 | case oXsquared: { |
361 | processStack( oDiv ); | 375 | processStack( oDiv ); |
362 | Op op( num, i ); | 376 | Op op( num, i ); |
363 | operationStack.push( op ); | 377 | operationStack.push( op ); |
364 | break; | 378 | break; |
365 | } | 379 | } |
366 | case oChSign: | 380 | case oChSign: |
367 | num = -num; | 381 | num = -num; |
368 | LCD->display(num); | 382 | LCD->display(num); |
369 | return; | 383 | return; |
370 | 384 | ||
371 | case oOpenBrace: { | 385 | case oOpenBrace: { |
372 | Op op( 0, oOpenBrace ); | 386 | Op op( 0, oOpenBrace ); |
373 | operationStack.push( op ); | 387 | operationStack.push( op ); |
374 | numOpenBraces++; | 388 | numOpenBraces++; |
375 | state = sNewNumber; | 389 | state = sNewNumber; |
376 | return; | 390 | return; |
377 | } | 391 | } |
378 | case oCloseBrace: { | 392 | case oCloseBrace: { |
379 | if ( numOpenBraces == 0 ) | 393 | if ( numOpenBraces == 0 ) |
380 | return; | 394 | return; |
381 | processStack( oAdd ); | 395 | processStack( oAdd ); |
382 | if ( operationStack.top().operation != oOpenBrace ) | 396 | if ( operationStack.top().operation != oOpenBrace ) |
383 | qDebug( "Calculator: internal Error" ); | 397 | qDebug( "Calculator: internal Error" ); |
384 | operationStack.pop(); | 398 | operationStack.pop(); |
385 | state = sNewNumber; | 399 | state = sNewNumber; |
386 | numOpenBraces--; | 400 | numOpenBraces--; |
387 | break; | 401 | break; |
388 | } | 402 | } |
389 | 403 | ||
390 | case oPoint: | 404 | case oPoint: |
391 | flPoint = TRUE; | 405 | flPoint = TRUE; |
392 | return; | 406 | return; |
393 | 407 | ||
394 | case oPercent: | 408 | case oPercent: |
395 | processStack( oPercent ); | 409 | processStack( oPercent ); |
396 | break; | 410 | break; |
397 | 411 | ||
398 | 412 | ||
399 | case oSum: | 413 | case oSum: |
400 | processStack( oSum ); | 414 | processStack( oSum ); |
401 | break; | 415 | break; |
402 | 416 | ||
403 | default: | 417 | default: |
404 | return; | 418 | return; |
405 | }; | 419 | }; |
406 | 420 | ||
407 | if ( state == sError ) { | 421 | if ( state == sError ) { |
408 | LCD->display( "Error" ); | 422 | LCD->display( "Error" ); |
409 | return; | 423 | return; |
410 | } else { | 424 | } else { |
411 | LCD->display(num); | 425 | LCD->display(num); |
412 | } | 426 | } |
413 | state = sNewNumber; | 427 | state = sNewNumber; |
414 | numDecimals = 0; | 428 | numDecimals = 0; |
415 | flPoint = FALSE; | 429 | flPoint = FALSE; |
416 | } | 430 | } |
417 | 431 | ||
418 | 432 | ||
419 | void CalculatorImpl::processStack( int op ) | 433 | void CalculatorImpl::processStack( int op ) |
420 | { | 434 | { |
421 | //dubious percent hack, since the changeable operator precedences are | 435 | //dubious percent hack, since the changeable operator precedences are |
422 | //pretty much hardwired to be less than the non-changeable | 436 | //pretty much hardwired to be less than the non-changeable |
423 | bool percent = FALSE; | 437 | bool percent = FALSE; |
424 | if ( op == oPercent ) { | 438 | if ( op == oPercent ) { |
425 | percent = TRUE; | 439 | percent = TRUE; |
426 | op = oSum; | 440 | op = oSum; |
427 | } | 441 | } |
428 | while( !operationStack.isEmpty() && operationStack.top().operation >= op ) { | 442 | while( !operationStack.isEmpty() && operationStack.top().operation >= op ) { |
429 | Op operation = operationStack.pop(); | 443 | Op operation = operationStack.pop(); |
430 | acc = operation.number; | 444 | acc = operation.number; |
431 | if ( percent ) { | 445 | if ( percent ) { |
432 | if ( operation.operation == oAdd || operation.operation == oSub ) | 446 | if ( operation.operation == oAdd || operation.operation == oSub ) |
433 | num = acc*num/100; | 447 | num = acc*num/100; |
434 | else | 448 | else |
435 | num = num / 100; | 449 | num = num / 100; |
436 | } | 450 | } |
437 | num = evalExpr( operation.operation ); | 451 | num = evalExpr( operation.operation ); |
438 | percent = FALSE; | 452 | percent = FALSE; |
439 | } | 453 | } |
440 | } | 454 | } |
441 | 455 | ||
442 | 456 | ||
443 | double CalculatorImpl::evalExpr( int op ) { | 457 | double CalculatorImpl::evalExpr( int op ) { |
444 | double sum = 0; | 458 | double sum = 0; |
445 | 459 | ||
446 | switch( op ){ | 460 | switch( op ){ |
447 | case oPercent: sum = num / 100.; break; | 461 | case oPercent: sum = num / 100.; break; |
448 | case oDivX: | 462 | case oDivX: |
449 | if (num == 0) | 463 | if (num == 0) |
450 | state = sError; | 464 | state = sError; |
451 | else | 465 | else |
452 | sum = 1 / num; | 466 | sum = 1 / num; |
453 | break; | 467 | break; |
454 | case oXsquared: | 468 | case oXsquared: |
455 | sum = pow(acc,num); | 469 | sum = pow(acc,num); |
456 | break; | 470 | break; |
457 | case oChSign: (state == sStart) ? sum = -num : sum = -acc; break; | 471 | case oChSign: (state == sStart) ? sum = -num : sum = -acc; break; |
458 | case oSub: sum = acc - num; break; | 472 | case oSub: sum = acc - num; break; |
459 | case oMult: sum = acc * num; break; | 473 | case oMult: sum = acc * num; break; |
460 | case oAdd: sum = acc + num; break; | 474 | case oAdd: sum = acc + num; break; |
461 | case oDiv: { | 475 | case oDiv: { |
462 | if (num == 0) { | 476 | if (num == 0) { |
463 | state = sError; | 477 | state = sError; |
464 | } else { | 478 | } else { |
465 | sum = acc / num; | 479 | sum = acc / num; |
466 | } | 480 | } |
467 | break; | 481 | break; |
468 | } | 482 | } |
469 | case oRoot: | 483 | case oRoot: |
470 | /* the linux library is dumb, and can't to -x to 1/n | 484 | /* the linux library is dumb, and can't to -x to 1/n |
471 | when n is odd. (even and error of course is acceptable */ | 485 | when n is odd. (even and error of course is acceptable */ |
472 | if((acc < 0) && (int(num) == num) && (int(num) % 2 == 1 )) { | 486 | if((acc < 0) && (int(num) == num) && (int(num) % 2 == 1 )) { |
473 | sum = pow(-acc, 1 / num); | 487 | sum = pow(-acc, 1 / num); |
474 | sum = -sum; | 488 | sum = -sum; |
475 | } else { | 489 | } else { |
476 | sum = pow(acc, 1 / num); | 490 | sum = pow(acc, 1 / num); |
477 | } | 491 | } |
478 | break; | 492 | break; |
479 | case oLog: | 493 | case oLog: |
480 | sum = log10(num); | 494 | sum = log10(num); |
481 | break; | 495 | break; |
482 | case oLn: | 496 | case oLn: |
483 | sum = log(num); | 497 | sum = log(num); |
484 | break; | 498 | break; |
485 | case oTan: sum = qTan(num);break; | 499 | case oTan: sum = qTan(num);break; |
486 | case oSin: sum = qSin(num);break; | 500 | case oSin: sum = qSin(num);break; |
487 | case oCos: sum = qCos(num);break; | 501 | case oCos: sum = qCos(num);break; |
488 | default: sum = num; break; | 502 | default: sum = num; break; |
489 | } | 503 | } |
490 | 504 | ||
491 | if ( isinf( sum ) || isnan( sum ) ) | 505 | if ( isinf( sum ) || isnan( sum ) ) |
492 | state = sError; | 506 | state = sError; |
493 | return sum; | 507 | return sum; |
494 | } | 508 | } |
495 | 509 | ||
496 | 510 | ||
497 | void CalculatorImpl::enterNumber( int n ) | 511 | void CalculatorImpl::enterNumber( int n ) |
498 | { | 512 | { |
499 | if ( state == sError ) | 513 | if ( state == sError ) |
500 | return; | 514 | return; |
501 | if( state == sStart ){ | 515 | if( state == sStart ){ |
502 | if( LCD->value() > 0 ){ | 516 | if( LCD->value() > 0 ){ |
503 | QString s = QString::number( LCD->value(), 'g', LCD->numDigits()); | 517 | QString s = QString::number( LCD->value(), 'g', LCD->numDigits()); |
504 | if( s.length() > (uint)(LCD->numDigits() - 2)) return; | 518 | if( s.length() > (uint)(LCD->numDigits() - 2)) return; |
505 | 519 | ||
506 | } else if( (int)fake.length() >= LCD->numDigits() || numDecimals >=12 ){ | 520 | } else if( (int)fake.length() >= LCD->numDigits() || numDecimals >=12 ){ |
507 | return; | 521 | return; |
508 | } | 522 | } |
509 | } | 523 | } |
510 | 524 | ||
511 | if( state == sNewNumber ){ | 525 | if( state == sNewNumber ){ |
512 | state = sStart; | 526 | state = sStart; |
513 | acc = 0; | 527 | acc = 0; |
514 | if( flPoint ){ | 528 | if( flPoint ){ |
515 | numDecimals = 1; | 529 | numDecimals = 1; |
516 | num = n / pow(10, numDecimals); | 530 | num = n / pow(10, numDecimals); |
517 | } else | 531 | } else |
518 | num = n; | 532 | num = n; |
519 | } else if( flPoint ){ | 533 | } else if( flPoint ){ |
520 | numDecimals++; | 534 | numDecimals++; |
521 | if( num < 0 ){ | 535 | if( num < 0 ){ |
522 | num -= n / pow(10, numDecimals); | 536 | num -= n / pow(10, numDecimals); |
523 | } else { | 537 | } else { |
524 | num += n / pow(10, numDecimals); | 538 | num += n / pow(10, numDecimals); |
525 | } | 539 | } |
526 | } else { | 540 | } else { |
527 | num *= 10; | 541 | num *= 10; |
528 | if( num < 0 ) | 542 | if( num < 0 ) |
529 | num -= n; | 543 | num -= n; |
530 | else | 544 | else |
531 | num += n; | 545 | num += n; |
532 | } | 546 | } |
533 | 547 | ||
534 | // We need feedback in the calc display while entering fl.point zeros. | 548 | // We need feedback in the calc display while entering fl.point zeros. |
535 | // This is a small hack to display sequences like: 0.000 and 1.100 | 549 | // This is a small hack to display sequences like: 0.000 and 1.100 |
536 | double integer, fraction; | 550 | double integer, fraction; |
537 | fraction = modf( num, &integer ); | 551 | fraction = modf( num, &integer ); |
538 | if( flPoint ){ | 552 | if( flPoint ){ |
539 | QString is, fs, zeros; | 553 | QString is, fs, zeros; |
540 | 554 | ||
541 | is = QString::number( integer, 'g', 13 ); | 555 | is = QString::number( integer, 'g', 13 ); |
542 | fs = QString::number( fraction, 'g', numDecimals ); | 556 | fs = QString::number( fraction, 'g', numDecimals ); |
543 | if( fs.contains('e') ){ | 557 | if( fs.contains('e') ){ |
544 | fs = QString::number( fraction, 'f', LCD->numDigits() ); | 558 | fs = QString::number( fraction, 'f', LCD->numDigits() ); |
545 | } | 559 | } |
546 | fs = fs.mid( 2, numDecimals ); | 560 | fs = fs.mid( 2, numDecimals ); |
547 | 561 | ||
548 | if( (integer == 0) && (fraction == 0) ) | 562 | if( (integer == 0) && (fraction == 0) ) |
549 | fake = "0."; | 563 | fake = "0."; |
550 | else if( (integer != 0) && (fraction == 0) ) | 564 | else if( (integer != 0) && (fraction == 0) ) |
551 | fake = is + "."; | 565 | fake = is + "."; |
552 | else | 566 | else |
553 | fake = is + "." + fs; | 567 | fake = is + "." + fs; |
554 | 568 | ||
555 | zeros.fill( '0', (numDecimals - fs.length()) ); | 569 | zeros.fill( '0', (numDecimals - fs.length()) ); |
556 | fake += zeros; | 570 | fake += zeros; |
557 | // ### This code sets LCD->value() to zero since it sets a text | 571 | // ### This code sets LCD->value() to zero since it sets a text |
558 | // ### Avoid getting the current value from LCD->value() for | 572 | // ### Avoid getting the current value from LCD->value() for |
559 | // ### calculations. | 573 | // ### calculations. |
560 | LCD->display( fake ); | 574 | LCD->display( fake ); |
561 | } else | 575 | } else |
562 | LCD->display( num ); | 576 | LCD->display( num ); |
563 | } | 577 | } |
564 | 578 | ||
565 | void CalculatorImpl::command_buttons(int i) { | 579 | void CalculatorImpl::command_buttons(int i) { |
566 | if ( state == sError && i != 3 ) | 580 | if ( state == sError && i != 3 ) |
567 | return; | 581 | return; |
568 | switch (i) { | 582 | switch (i) { |
569 | case 0: // M+ | 583 | case 0: // M+ |
570 | mem += num; | 584 | mem += num; |
571 | if( mem != 0 ){ | 585 | if( mem != 0 ){ |
572 | memMark->show(); | 586 | memMark->show(); |
573 | PushButtonMR->setEnabled( TRUE ); }; | 587 | PushButtonMR->setEnabled( TRUE ); }; |
574 | state = sNewNumber; | 588 | state = sNewNumber; |
575 | break; | 589 | break; |
576 | case 1: // MR | 590 | case 1: // MR |
577 | acc = num = mem; | 591 | acc = num = mem; |
578 | state = sNewNumber; | 592 | state = sNewNumber; |
579 | LCD->display( mem ); | 593 | LCD->display( mem ); |
580 | break; | 594 | break; |
581 | case 2: // MC | 595 | case 2: // MC |
582 | mem = 0; | 596 | mem = 0; |
583 | memMark->hide(); | 597 | memMark->hide(); |
584 | PushButtonMR->setEnabled( FALSE ); | 598 | PushButtonMR->setEnabled( FALSE ); |
585 | break; | 599 | break; |
586 | case 3: // CE | 600 | case 3: // CE |
587 | if ( state == sStart ) { | 601 | if ( state == sStart ) { |
588 | // clear the entered number on the first press | 602 | // clear the entered number on the first press |
589 | state = sNewNumber; | 603 | state = sNewNumber; |
590 | num = acc = 0; | 604 | num = acc = 0; |
591 | flPoint = FALSE; | 605 | flPoint = FALSE; |
592 | LCD->display( 0 ); | 606 | LCD->display( 0 ); |
593 | fake = QString::null; | 607 | fake = QString::null; |
594 | numDecimals = 0; | 608 | numDecimals = 0; |
595 | } else { | 609 | } else { |
596 | clear(); | 610 | clear(); |
597 | } | 611 | } |
598 | break; | 612 | break; |
599 | }; | 613 | }; |
600 | 614 | ||
601 | } | 615 | } |
diff --git a/noncore/tools/calculator/calculatorimpl.h b/noncore/tools/calculator/calculatorimpl.h index bfb726f..f0180c9 100644 --- a/noncore/tools/calculator/calculatorimpl.h +++ b/noncore/tools/calculator/calculatorimpl.h | |||
@@ -1,135 +1,137 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #ifndef CALCULATORIMPL_H | 20 | #ifndef CALCULATORIMPL_H |
21 | #define CALCULATORIMPL_H | 21 | #define CALCULATORIMPL_H |
22 | 22 | ||
23 | 23 | ||
24 | #include <qlcdnumber.h> | 24 | #include <qlcdnumber.h> |
25 | #include "calculator.h" | 25 | #include "calculator.h" |
26 | #include <qpushbutton.h> | 26 | #include <qpushbutton.h> |
27 | #include <qbuttongroup.h> | 27 | #include <qbuttongroup.h> |
28 | #include <qvaluestack.h> | 28 | #include <qvaluestack.h> |
29 | 29 | ||
30 | // mode x functions | 30 | // mode x functions |
31 | enum Operation { | 31 | enum Operation { |
32 | oNop, | 32 | oNop, |
33 | oOpenBrace, | 33 | oOpenBrace, |
34 | oCloseBrace, | 34 | oCloseBrace, |
35 | oSum, | 35 | oSum, |
36 | oPoint, | 36 | oPoint, |
37 | oAdd, | 37 | oAdd, |
38 | oSub, | 38 | oSub, |
39 | oDiv, | 39 | oDiv, |
40 | oMult, | 40 | oMult, |
41 | 41 | ||
42 | // mode 0 functions | 42 | // mode 0 functions |
43 | oSin, | 43 | oSin, |
44 | oCos, | 44 | oCos, |
45 | oTan, | 45 | oTan, |
46 | oDivX, | 46 | oDivX, |
47 | oPercent, | 47 | oPercent, |
48 | oXsquared, | 48 | oXsquared, |
49 | oRoot, | 49 | oRoot, |
50 | oLog, | 50 | oLog, |
51 | oLn, | 51 | oLn, |
52 | oChSign | 52 | oChSign |
53 | }; | 53 | }; |
54 | 54 | ||
55 | // states | 55 | // states |
56 | #define sStart 0 | 56 | #define sStart 0 |
57 | #define sNewNumber 1 | 57 | #define sNewNumber 1 |
58 | #define sError 2 | 58 | #define sError 2 |
59 | 59 | ||
60 | struct Op | 60 | struct Op |
61 | { | 61 | { |
62 | Op() { number = 0; operation = oNop; } | 62 | Op() { number = 0; operation = oNop; } |
63 | Op( double num, Operation op ) | 63 | Op( double num, Operation op ) |
64 | { number = num; operation = op; } | 64 | { number = num; operation = op; } |
65 | double number; | 65 | double number; |
66 | Operation operation; | 66 | Operation operation; |
67 | }; | 67 | }; |
68 | 68 | ||
69 | class QLabel; | 69 | class QLabel; |
70 | class CalculatorImpl : public Calculator | 70 | class CalculatorImpl : public Calculator |
71 | { | 71 | { |
72 | Q_OBJECT | 72 | Q_OBJECT |
73 | 73 | ||
74 | public: | 74 | public: |
75 | CalculatorImpl( QWidget * parent = 0, const char * name = 0, | 75 | CalculatorImpl( QWidget * parent = 0, const char * name = 0, |
76 | WFlags f = 0 ); | 76 | WFlags f = 0 ); |
77 | 77 | ||
78 | public slots: | 78 | public slots: |
79 | void command_buttons(int); | 79 | void command_buttons(int); |
80 | void enterNumber(int i); | 80 | void enterNumber(int i); |
81 | void std_buttons(int); | 81 | void std_buttons(int); |
82 | void std_funcs(int); | 82 | void std_funcs(int); |
83 | void do_convert(int); | 83 | void do_convert(int); |
84 | void function_button(int); | 84 | void function_button(int); |
85 | 85 | ||
86 | protected: | 86 | protected: |
87 | virtual bool eventFilter( QObject *o, QEvent *e ); | 87 | virtual bool eventFilter( QObject *o, QEvent *e ); |
88 | 88 | ||
89 | private: | 89 | private: |
90 | void clear(); | 90 | void clear(); |
91 | 91 | ||
92 | void reset_conv(); | 92 | void reset_conv(); |
93 | 93 | ||
94 | void processStack( int op ); | 94 | void processStack( int op ); |
95 | 95 | ||
96 | QValueStack<Op> operationStack; | 96 | QValueStack<Op> operationStack; |
97 | int state; | 97 | int state; |
98 | 98 | ||
99 | double acc, num, mem; | 99 | double acc, num, mem; |
100 | int numDecimals; | 100 | int numDecimals; |
101 | bool flPoint; | 101 | bool flPoint; |
102 | int numOpenBraces; | 102 | int numOpenBraces; |
103 | 103 | ||
104 | void execOp( Operation i ); | 104 | void execOp( Operation i ); |
105 | double evalExpr( int op ); | 105 | double evalExpr( int op ); |
106 | QLabel * memMark; | 106 | QLabel * memMark; |
107 | QString fake; | 107 | QString fake; |
108 | 108 | ||
109 | // useful values for conversion stuff | 109 | // useful values for conversion stuff |
110 | int current_mode, max_mode, conversion_mode_count, last_conversion; | 110 | int current_mode, max_mode, conversion_mode_count, last_conversion; |
111 | 111 | ||
112 | // make adding new modes easier for ourselves | 112 | // make adding new modes easier for ourselves |
113 | static const int pre_conv_modes_count = 1; | 113 | static const int pre_conv_modes_count = 1; |
114 | static const int post_conv_modes_count = 0; | 114 | static const int post_conv_modes_count = 0; |
115 | 115 | ||
116 | // an array of pointers to the func buttons | 116 | // an array of pointers to the func buttons |
117 | static const int func_button_count = 12; | 117 | static const int func_button_count = 12; |
118 | // this is an abomination | 118 | // this is an abomination |
119 | static const int changeable_func_button_count = 10; | 119 | static const int changeable_func_button_count = 10; |
120 | QPushButton* func_buttons[func_button_count]; | 120 | QPushButton* func_buttons[func_button_count]; |
121 | 121 | ||
122 | QButtonGroup bgr_function, bgr_digits, bgr_std, bgr_command; | 122 | QButtonGroup bgr_function, bgr_digits, bgr_std, bgr_command; |
123 | QStringList faces, captions; | 123 | QStringList faces, captions; |
124 | 124 | ||
125 | // an array of doubles holding the conversion ratios | 125 | // an array of doubles holding the conversion ratios |
126 | double* entry_list; | 126 | double* entry_list; |
127 | double* preoffset_list; | ||
128 | double* postoffset_list; | ||
127 | 129 | ||
128 | QPixmap xtopowerofy; | 130 | QPixmap xtopowerofy; |
129 | QPixmap ythrootofx; | 131 | QPixmap ythrootofx; |
130 | QPixmap oneoverx; | 132 | QPixmap oneoverx; |
131 | 133 | ||
132 | void display_pixmap_faces(void); | 134 | void display_pixmap_faces(void); |
133 | }; | 135 | }; |
134 | 136 | ||
135 | #endif | 137 | #endif |