author | kergoth <kergoth> | 2002-02-08 18:07:57 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-02-08 18:07:57 (UTC) |
commit | d5714ac7fe62676ee1a63be2f965cb567ef7ae3e (patch) (side-by-side diff) | |
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 @@ /********************************************************************** ** Copyright (C) 2001 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ STARTTYPE Weight STND grams NAME mg RATIO 1000 +PREOFF 0.0 +POSTOFF 0.0 + NAME g RATIO 1 +PREOFF 0.0 +POSTOFF 0.0 + NAME kg RATIO 0.001 +PREOFF 0.0 +POSTOFF 0.0 + NAME tonnes RATIO 1e-06 +PREOFF 0.0 +POSTOFF 0.0 + NAME carats RATIO 5 +PREOFF 0.0 +POSTOFF 0.0 + NAME oz RATIO 0.03527336860670194 +PREOFF 0.0 +POSTOFF 0.0 + NAME lb RATIO 0.002204585537918871 +PREOFF 0.0 +POSTOFF 0.0 + NAME st RATIO 0.0001574703955656337 +PREOFF 0.0 +POSTOFF 0.0 + NAME St tons RATIO 1.102292768959636e-06 +PREOFF 0.0 +POSTOFF 0.0 + NAME Lg tons RATIO 9.841899722852103e-07 +PREOFF 0.0 +POSTOFF 0.0 + NAME RATIO 1. +PREOFF 0.0 +POSTOFF 0.0 + NAME RATIO 1. +PREOFF 0.0 +POSTOFF 0.0 + ENDTYPE STARTTYPE Distance STND m NAME mm RATIO 1000 +PREOFF 0.0 +POSTOFF 0.0 + NAME cm RATIO 100 +PREOFF 0.0 +POSTOFF 0.0 + NAME m RATIO 1 +PREOFF 0.0 +POSTOFF 0.0 + NAME km RATIO 0.001 +PREOFF 0.0 +POSTOFF 0.0 + NAME points RATIO 2834.64566929134 +PREOFF 0.0 +POSTOFF 0.0 + NAME in RATIO 39.3700787401575 +PREOFF 0.0 +POSTOFF 0.0 + NAME ft RATIO 3.280839895013123 +PREOFF 0.0 +POSTOFF 0.0 + NAME yd RATIO 1.093613298337708 +PREOFF 0.0 +POSTOFF 0.0 + NAME mi RATIO 0.0006213711922373339 +PREOFF 0.0 +POSTOFF 0.0 + NAME naut. mi RATIO 0.0005399568034557236 +PREOFF 0.0 +POSTOFF 0.0 + NAME RATIO 1. +PREOFF 0.0 +POSTOFF 0.0 + NAME RATIO 1. +PREOFF 0.0 +POSTOFF 0.0 + ENDTYPE STARTTYPE Area STND sq m NAME sq mm RATIO 1000000 +PREOFF 0.0 +POSTOFF 0.0 + NAME sq cm RATIO 10000 +PREOFF 0.0 +POSTOFF 0.0 + NAME sq m RATIO 1 +PREOFF 0.0 +POSTOFF 0.0 + NAME sq km RATIO 1e-06 +PREOFF 0.0 +POSTOFF 0.0 + NAME hectares RATIO 0.0001 +PREOFF 0.0 +POSTOFF 0.0 + NAME sq in RATIO 1550.0031000062 +PREOFF 0.0 +POSTOFF 0.0 + NAME sq ft RATIO 10.7639104167097 +PREOFF 0.0 +POSTOFF 0.0 + NAME sq yd RATIO 1.19599004630108 +PREOFF 0.0 +POSTOFF 0.0 + NAME sq mi RATIO 0.000000386102158542446 +PREOFF 0.0 +POSTOFF 0.0 + NAME acres RATIO 0.0002471053814671653 +PREOFF 0.0 +POSTOFF 0.0 + NAME RATIO 1. +PREOFF 0.0 +POSTOFF 0.0 + NAME RATIO 1. +PREOFF 0.0 +POSTOFF 0.0 + ENDTYPE +STARTTYPE Temperatures +STND °C + +NAME +RATIO 1. +PREOFF 0.0 +POSTOFF 0.0 + +NAME +RATIO 1. +PREOFF 0.0 +POSTOFF 0.0 + +NAME +RATIO 1. +PREOFF 0.0 +POSTOFF 0.0 + +NAME +RATIO 1. +PREOFF 0.0 +POSTOFF 0.0 + +NAME +RATIO 1. +PREOFF 0.0 +POSTOFF 0.0 + +NAME °C +RATIO 1.0 +PREOFF 0.0 +POSTOFF 0.0 + +NAME °F +RATIO 1.8 +PREOFF -32.0 +POSTOFF +32.0 + +NAME +RATIO 1. +PREOFF 0.0 +POSTOFF 0.0 + +NAME +RATIO 1. +PREOFF 0.0 +POSTOFF 0.0 + +NAME +RATIO 1. +PREOFF 0.0 +POSTOFF 0.0 + +NAME +RATIO 1. +PREOFF 0.0 +POSTOFF 0.0 + +NAME +RATIO 1. +PREOFF 0.0 +POSTOFF 0.0 + +ENDTYPE STARTTYPE Volume STND litres NAME cu cm RATIO 1000 +PREOFF 0.0 +POSTOFF 0.0 + NAME ml RATIO 1000 +PREOFF 0.0 +POSTOFF 0.0 + NAME l RATIO 1 +PREOFF 0.0 +POSTOFF 0.0 + NAME tblspoon RATIO 67.6280454036859 +PREOFF 0.0 +POSTOFF 0.0 + NAME teaspoons RATIO 202.884136211058 +PREOFF 0.0 +POSTOFF 0.0 + NAME cu in RATIO 61.0237440947323 +PREOFF 0.0 +POSTOFF 0.0 + NAME cu ft RATIO 0.0353146667214886 +PREOFF 0.0 +POSTOFF 0.0 + NAME pt RATIO 2.11337641886519 +PREOFF 0.0 +POSTOFF 0.0 + NAME qt RATIO 1.05668820943259 +PREOFF 0.0 +POSTOFF 0.0 + NAME gal (US) RATIO 0.264172052358148 +PREOFF 0.0 +POSTOFF 0.0 + NAME RATIO 1. +PREOFF 0.0 +POSTOFF 0.0 + NAME RATIO 1. +PREOFF 0.0 +POSTOFF 0.0 + ENDTYPE Extra units NAME fl oz (US) RATIO 33.8140227018429 +PREOFF 0.0 +POSTOFF 0.0 + 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,68 +1,73 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ +/* + * 01/14/2002 Charles-Edouard Ruault <ce@ruault.com> + * Added support for Temperature conversions. + */ + #include "calculatorimpl.h" #include <qpe/resource.h> #include <qpe/qmath.h> #include <qpe/qpeapplication.h> #include <qpushbutton.h> #include <qcombobox.h> #include <qlabel.h> #include <qfont.h> #include <qlayout.h> #include <qstringlist.h> #include <qfile.h> #include <qtextstream.h> #include <qmessagebox.h> #include <math.h> CalculatorImpl::CalculatorImpl( QWidget * parent, const char * name, WFlags f ) : Calculator( parent, name, f ) { xtopowerofy = Resource::loadPixmap("xtopowerofy"); ythrootofx = Resource::loadPixmap("ythrootofx"); oneoverx = Resource::loadPixmap("oneoverx"); memMark = new QLabel( "m", LCD ); memMark->setFont( QFont( "helvetica", 12, QFont::Bold, TRUE ) ); memMark->resize( 12, 12 ); memMark->move( 4, 2 ); memMark->hide(); mem = 0; PushButtonMR->setEnabled( FALSE ); current_mode = max_mode = conversion_mode_count = 0; last_conversion = -1; //bgr_command.insert( PushButtonFunction); bgr_command.insert( PushButtonMPlus); bgr_command.insert( PushButtonMR); bgr_command.insert( PushButtonMC); bgr_command.insert( PushButtonCE); connect( &bgr_command, SIGNAL(clicked(int) ), this, SLOT(command_buttons(int))); bgr_digits.insert(PushButton0); bgr_digits.insert(PushButton1); bgr_digits.insert(PushButton2); bgr_digits.insert(PushButton3); @@ -89,192 +94,201 @@ CalculatorImpl::CalculatorImpl( QWidget * parent, const char * name, func_buttons[0] = PushButtonF1; func_buttons[1] = PushButtonF2; func_buttons[2] = PushButtonF3; func_buttons[3] = PushButtonF4; func_buttons[4] = PushButtonF5; func_buttons[5] = PushButtonF6; func_buttons[6] = PushButtonF7; func_buttons[7] = PushButtonF8; func_buttons[8] = PushButtonF9; func_buttons[9] = PushButtonF10; func_buttons[10] = PushButtonF11; func_buttons[11] = PushButtonF12; for ( int x = 0 ; x < func_button_count ; x++ ) { QPushButton* tmpbutton = func_buttons[x]; faces << tmpbutton->text(); bgr_function.insert(tmpbutton); } connect( &bgr_function, SIGNAL(clicked(int) ) , this, SLOT(do_convert(int) ) ); connect( &bgr_function, SIGNAL(clicked(int) ) , this, SLOT(std_funcs (int) ) ); connect(ComboBoxFunction, SIGNAL(activated(int) ), this, SLOT(function_button(int) ) ); captions.append("Standard"); ComboBoxFunction->insertItem(captions.last()); // now add in the conversion modes // when the menu gets done, these should be in a submenu QString tmp = QPEApplication::qpeDir(); tmp += "/etc/unit_conversion.dat"; QFile myfile(tmp); if ( !myfile.open( IO_Translate | IO_ReadOnly ) ) { // QMessageBox::warning(this, "Warning", "Data file\nunit_conversion.dat\nnot found\nNo conversion\nfeatures will\nbe available"); // disable the f button if no conv file available ComboBoxFunction->setEnabled(FALSE); } else { QString line, line2; QTextStream ts(&myfile); // first pass, see how many conversion types there are in order to allocate for them while ( ! ts.eof() ) { line = ts.readLine(); if ( line.contains ("STARTTYPE" ) ) conversion_mode_count++; } entry_list = new double[conversion_mode_count*func_button_count]; - + preoffset_list = new double[conversion_mode_count*func_button_count]; + postoffset_list = new double[conversion_mode_count*func_button_count]; myfile.close(); myfile.open( IO_Translate | IO_ReadOnly ); QTextStream ts2(&myfile); // second pass, read in values int x = 0; while ( ! ts2.eof() ) { line = ts2.readLine(); if ( line.contains("STARTTYPE") ) { captions << line.remove(0,10); ComboBoxFunction->insertItem(captions.last()); while ( !line.contains("ENDTYPE") ) { line = ts2.readLine(); if ( line.contains("NAME") ) { faces << line.remove(0,5); line2 = ts2.readLine(); line2.remove(0,6); entry_list[x] = line2.toDouble(); + line2 = ts2.readLine(); + line2.remove(0,7); + preoffset_list[x] = line2.toDouble(); + line2 = ts2.readLine(); + line2.remove(0,8); + postoffset_list[x] = line2.toDouble(); x++; } } } } } myfile.close(); clear(); max_mode = pre_conv_modes_count + conversion_mode_count + post_conv_modes_count - 1; display_pixmap_faces(); qApp->installEventFilter( this ); } bool CalculatorImpl::eventFilter( QObject *o, QEvent *e ) { if ( e->type() == QEvent::KeyPress && state != sError ) { QKeyEvent *k = (QKeyEvent*)e; if ( k->key() >= Key_0 && k->key() <= Key_9 ) { enterNumber( k->key() - Key_0 ); return true; } else { switch ( k->key() ) { case Key_Equal: std_buttons(0); return true; case Key_Period: std_buttons(1); return true; case Key_Plus: std_buttons(2); return true; case Key_Minus: std_buttons(3); return true; case Key_Slash: std_buttons(4); return true; case Key_Asterisk: std_buttons(5); return true; case Key_Percent: execOp( oPercent ); return true; case Key_ParenLeft: if ( current_mode < pre_conv_modes_count ) execOp( oOpenBrace ); return true; case Key_ParenRight: if ( current_mode < pre_conv_modes_count ) execOp( oCloseBrace ); return true; default: break; } } } return Calculator::eventFilter( o, e ); } void CalculatorImpl::do_convert(int button) { if ( state == sError ) return; if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) && button < changeable_func_button_count ) { if ( last_conversion > -1 ) { if( state == sNewNumber ){ - acc = num + acc = (num+ preoffset_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion]) / (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion]) - * (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + button]) ; + * (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + button]) + +postoffset_list[(current_mode - pre_conv_modes_count) * func_button_count + button]; num = acc; LCD->display( acc ); } else { state = sNewNumber; - num = num + num = (num+ preoffset_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion]) / (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion]) - * (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + button]) ; + * (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + button]) + + postoffset_list[(current_mode - pre_conv_modes_count) * func_button_count + button];; LCD->display( num ); acc = num; } } last_conversion = button; } } void CalculatorImpl::function_button(int mode){ if ( state == sError ) clear(); // dont need the next line when using a popup menu current_mode = mode; // reset the last conv last_conversion = -1; // set the caption this->setCaption( captions[current_mode] ); reset_conv(); for ( int x = 0 ; x < changeable_func_button_count ; x++ ) { QPushButton* tmpbutton = func_buttons[x]; // if its a conversion , make it a toggle button if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) ) { tmpbutton->setToggleButton(TRUE); } else { tmpbutton->setToggleButton(FALSE); } tmpbutton->setText( faces[current_mode * func_button_count + x] ); } if ( current_mode == 0 ) display_pixmap_faces(); if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) ) { bgr_function.setExclusive(TRUE); } else { bgr_function.setExclusive(FALSE); } } void CalculatorImpl::display_pixmap_faces() { QPushButton* tmpbutton = func_buttons[5]; tmpbutton->setPixmap(xtopowerofy); 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 @@ -79,57 +79,59 @@ public slots: void command_buttons(int); void enterNumber(int i); void std_buttons(int); void std_funcs(int); void do_convert(int); void function_button(int); protected: virtual bool eventFilter( QObject *o, QEvent *e ); private: void clear(); void reset_conv(); void processStack( int op ); QValueStack<Op> operationStack; int state; double acc, num, mem; int numDecimals; bool flPoint; int numOpenBraces; void execOp( Operation i ); double evalExpr( int op ); QLabel * memMark; QString fake; // useful values for conversion stuff int current_mode, max_mode, conversion_mode_count, last_conversion; // make adding new modes easier for ourselves static const int pre_conv_modes_count = 1; static const int post_conv_modes_count = 0; // an array of pointers to the func buttons static const int func_button_count = 12; // this is an abomination static const int changeable_func_button_count = 10; QPushButton* func_buttons[func_button_count]; QButtonGroup bgr_function, bgr_digits, bgr_std, bgr_command; QStringList faces, captions; // an array of doubles holding the conversion ratios double* entry_list; + double* preoffset_list; + double* postoffset_list; QPixmap xtopowerofy; QPixmap ythrootofx; QPixmap oneoverx; void display_pixmap_faces(void); }; #endif |