Diffstat (limited to 'noncore/tools/calculator/calculatorimpl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/tools/calculator/calculatorimpl.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/noncore/tools/calculator/calculatorimpl.cpp b/noncore/tools/calculator/calculatorimpl.cpp index dead03d..05cb9b5 100644 --- a/noncore/tools/calculator/calculatorimpl.cpp +++ b/noncore/tools/calculator/calculatorimpl.cpp | |||
@@ -5,62 +5,69 @@ | |||
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 | /* | 21 | /* |
22 | * 01/14/2002 Charles-Edouard Ruault <ce@ruault.com> | 22 | * 01/14/2002 Charles-Edouard Ruault <ce@ruault.com> |
23 | * Added support for Temperature conversions. | 23 | * Added support for Temperature conversions. |
24 | */ | 24 | */ |
25 | // Sat 03-09-2002 L.J. Potter added the inlined pixmaps here | 25 | // Sat 03-09-2002 L.J. Potter added the inlined pixmaps here |
26 | 26 | ||
27 | #include "calculatorimpl.h" | 27 | #include "calculatorimpl.h" |
28 | 28 | ||
29 | /* OPIE */ | ||
30 | #include <opie2/odebug.h> | ||
29 | #include <qpe/resource.h> | 31 | #include <qpe/resource.h> |
30 | #include <qpe/qmath.h> | 32 | #include <qpe/qmath.h> |
31 | #include <qpe/qpeapplication.h> | 33 | #include <qpe/qpeapplication.h> |
34 | using namespace Opie::Core; | ||
32 | 35 | ||
36 | /* QT */ | ||
33 | #include <qpushbutton.h> | 37 | #include <qpushbutton.h> |
34 | #include <qcombobox.h> | 38 | #include <qcombobox.h> |
35 | #include <qlabel.h> | 39 | #include <qlabel.h> |
36 | #include <qfont.h> | 40 | #include <qfont.h> |
37 | #include <qlayout.h> | 41 | #include <qlayout.h> |
38 | #include <qstringlist.h> | 42 | #include <qstringlist.h> |
39 | #include <qfile.h> | 43 | #include <qfile.h> |
40 | #include <qtextstream.h> | 44 | #include <qtextstream.h> |
41 | #include <qmessagebox.h> | 45 | #include <qmessagebox.h> |
46 | |||
47 | /* STD */ | ||
42 | #include <math.h> | 48 | #include <math.h> |
49 | |||
43 | /* XPM */ | 50 | /* XPM */ |
44 | static char *oneoverx_xpm[] = { | 51 | static char *oneoverx_xpm[] = { |
45 | /* width height num_colors chars_per_pixel */ | 52 | /* width height num_colors chars_per_pixel */ |
46 | " 13 11 2 1", | 53 | " 13 11 2 1", |
47 | /* colors */ | 54 | /* colors */ |
48 | ". c None", | 55 | ". c None", |
49 | "# c #000000", | 56 | "# c #000000", |
50 | /* pixels */ | 57 | /* pixels */ |
51 | "......#......", | 58 | "......#......", |
52 | ".....##......", | 59 | ".....##......", |
53 | "......#......" | 60 | "......#......" |
54 | ".....###.....", | 61 | ".....###.....", |
55 | ".............", | 62 | ".............", |
56 | "..#########..", | 63 | "..#########..", |
57 | ".............", | 64 | ".............", |
58 | "....##.##....", | 65 | "....##.##....", |
59 | "......#......", | 66 | "......#......", |
60 | "......#......", | 67 | "......#......", |
61 | "....##.##....", | 68 | "....##.##....", |
62 | }; | 69 | }; |
63 | /* XPM */ | 70 | /* XPM */ |
64 | static char *ythrootofx_xpm[] = { | 71 | static char *ythrootofx_xpm[] = { |
65 | /* width height num_colors chars_per_pixel */ | 72 | /* width height num_colors chars_per_pixel */ |
66 | " 13 11 2 1", | 73 | " 13 11 2 1", |
@@ -212,49 +219,49 @@ CalculatorImpl::CalculatorImpl( QWidget * parent, const char * name, | |||
212 | func_buttons[8] = PushButtonF9; | 219 | func_buttons[8] = PushButtonF9; |
213 | func_buttons[9] = PushButtonF10; | 220 | func_buttons[9] = PushButtonF10; |
214 | func_buttons[10] = PushButtonF11; | 221 | func_buttons[10] = PushButtonF11; |
215 | func_buttons[11] = PushButtonF12; | 222 | func_buttons[11] = PushButtonF12; |
216 | 223 | ||
217 | for ( int x = 0 ; x < func_button_count ; x++ ) { | 224 | for ( int x = 0 ; x < func_button_count ; x++ ) { |
218 | QPushButton* tmpbutton = func_buttons[x]; | 225 | QPushButton* tmpbutton = func_buttons[x]; |
219 | faces << tmpbutton->text(); | 226 | faces << tmpbutton->text(); |
220 | bgr_function.insert(tmpbutton); | 227 | bgr_function.insert(tmpbutton); |
221 | } | 228 | } |
222 | connect( &bgr_function, SIGNAL(clicked(int) ) , this, SLOT(do_convert(int) ) ); | 229 | connect( &bgr_function, SIGNAL(clicked(int) ) , this, SLOT(do_convert(int) ) ); |
223 | connect( &bgr_function, SIGNAL(clicked(int) ) , this, SLOT(std_funcs(int) ) ); | 230 | connect( &bgr_function, SIGNAL(clicked(int) ) , this, SLOT(std_funcs(int) ) ); |
224 | 231 | ||
225 | connect(ComboBoxFunction, SIGNAL(activated(int) ), this, SLOT(function_button(int) ) ); | 232 | connect(ComboBoxFunction, SIGNAL(activated(int) ), this, SLOT(function_button(int) ) ); |
226 | 233 | ||
227 | captions.append(tr("Standard")); | 234 | captions.append(tr("Standard")); |
228 | ComboBoxFunction->insertItem(captions.last()); | 235 | ComboBoxFunction->insertItem(captions.last()); |
229 | 236 | ||
230 | // now add in the conversion modes | 237 | // now add in the conversion modes |
231 | // when the menu gets done, these should be in a submenu | 238 | // when the menu gets done, these should be in a submenu |
232 | QString tmp = QPEApplication::qpeDir(); | 239 | QString tmp = QPEApplication::qpeDir(); |
233 | tmp += "etc/unit_conversion.dat"; | 240 | tmp += "etc/unit_conversion.dat"; |
234 | QFile myfile(tmp); | 241 | QFile myfile(tmp); |
235 | if ( !myfile.open( IO_Translate | IO_ReadOnly ) ) { | 242 | if ( !myfile.open( IO_Translate | IO_ReadOnly ) ) { |
236 | qDebug("Data file unit_conversion.dat not found\nNo conversion features will be available\n"+tmp); | 243 | odebug << "Data file unit_conversion.dat not found\nNo conversion features will be available\n"+tmp << oendl; |
237 | // disable the f button if no conv file available | 244 | // disable the f button if no conv file available |
238 | ComboBoxFunction->setEnabled(FALSE); | 245 | ComboBoxFunction->setEnabled(FALSE); |
239 | } | 246 | } |
240 | else { | 247 | else { |
241 | QString line, line2; | 248 | QString line, line2; |
242 | QTextStream ts(&myfile); | 249 | QTextStream ts(&myfile); |
243 | 250 | ||
244 | // first pass, see how many conversion types there are in order to allocate for them | 251 | // first pass, see how many conversion types there are in order to allocate for them |
245 | while ( ! ts.eof() ) { | 252 | while ( ! ts.eof() ) { |
246 | line = ts.readLine(); | 253 | line = ts.readLine(); |
247 | if ( line.contains ("STARTTYPE" ) ) | 254 | if ( line.contains ("STARTTYPE" ) ) |
248 | conversion_mode_count++; | 255 | conversion_mode_count++; |
249 | } | 256 | } |
250 | 257 | ||
251 | entry_list = new double[conversion_mode_count*func_button_count]; | 258 | entry_list = new double[conversion_mode_count*func_button_count]; |
252 | preoffset_list = new double[conversion_mode_count*func_button_count]; | 259 | preoffset_list = new double[conversion_mode_count*func_button_count]; |
253 | postoffset_list = new double[conversion_mode_count*func_button_count]; | 260 | postoffset_list = new double[conversion_mode_count*func_button_count]; |
254 | myfile.close(); | 261 | myfile.close(); |
255 | myfile.open( IO_Translate | IO_ReadOnly ); | 262 | myfile.open( IO_Translate | IO_ReadOnly ); |
256 | QTextStream ts2(&myfile); | 263 | QTextStream ts2(&myfile); |
257 | 264 | ||
258 | // second pass, read in values | 265 | // second pass, read in values |
259 | int x = 0; | 266 | int x = 0; |
260 | while ( ! ts2.eof() ) { | 267 | while ( ! ts2.eof() ) { |
@@ -486,49 +493,49 @@ void CalculatorImpl::execOp( Operation i ) | |||
486 | case oRoot: | 493 | case oRoot: |
487 | case oXsquared: { | 494 | case oXsquared: { |
488 | processStack( oDiv ); | 495 | processStack( oDiv ); |
489 | Op op( num, i ); | 496 | Op op( num, i ); |
490 | operationStack.push( op ); | 497 | operationStack.push( op ); |
491 | break; | 498 | break; |
492 | } | 499 | } |
493 | case oChSign: | 500 | case oChSign: |
494 | num = -num; | 501 | num = -num; |
495 | LCD->display(num); | 502 | LCD->display(num); |
496 | return; | 503 | return; |
497 | 504 | ||
498 | case oOpenBrace: { | 505 | case oOpenBrace: { |
499 | Op op( 0, oOpenBrace ); | 506 | Op op( 0, oOpenBrace ); |
500 | operationStack.push( op ); | 507 | operationStack.push( op ); |
501 | numOpenBraces++; | 508 | numOpenBraces++; |
502 | state = sNewNumber; | 509 | state = sNewNumber; |
503 | return; | 510 | return; |
504 | } | 511 | } |
505 | case oCloseBrace: { | 512 | case oCloseBrace: { |
506 | if ( numOpenBraces == 0 ) | 513 | if ( numOpenBraces == 0 ) |
507 | return; | 514 | return; |
508 | processStack( oAdd ); | 515 | processStack( oAdd ); |
509 | if ( operationStack.top().operation != oOpenBrace ) | 516 | if ( operationStack.top().operation != oOpenBrace ) |
510 | qDebug( "Calculator: internal Error" ); | 517 | odebug << "Calculator: internal Error" << oendl; |
511 | operationStack.pop(); | 518 | operationStack.pop(); |
512 | state = sNewNumber; | 519 | state = sNewNumber; |
513 | numOpenBraces--; | 520 | numOpenBraces--; |
514 | break; | 521 | break; |
515 | } | 522 | } |
516 | 523 | ||
517 | case oPoint: | 524 | case oPoint: |
518 | flPoint = TRUE; | 525 | flPoint = TRUE; |
519 | return; | 526 | return; |
520 | 527 | ||
521 | case oPercent: | 528 | case oPercent: |
522 | processStack( oPercent ); | 529 | processStack( oPercent ); |
523 | break; | 530 | break; |
524 | 531 | ||
525 | 532 | ||
526 | case oSum: | 533 | case oSum: |
527 | processStack( oSum ); | 534 | processStack( oSum ); |
528 | break; | 535 | break; |
529 | 536 | ||
530 | default: | 537 | default: |
531 | return; | 538 | return; |
532 | }; | 539 | }; |
533 | 540 | ||
534 | if ( state == sError ) { | 541 | if ( state == sError ) { |