summaryrefslogtreecommitdiff
path: root/noncore/tools/calculator
Side-by-side diff
Diffstat (limited to 'noncore/tools/calculator') (more/less context) (show whitespace changes)
-rw-r--r--noncore/tools/calculator/calculatorimpl.cpp24
-rw-r--r--noncore/tools/calculator/calculatorimpl.h2
2 files changed, 21 insertions, 5 deletions
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
@@ -9,24 +9,29 @@
** 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>
@@ -125,43 +130,50 @@ CalculatorImpl::CalculatorImpl( QWidget * parent, const char * name,
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 );
@@ -211,34 +223,36 @@ bool CalculatorImpl::eventFilter( QObject *o, QEvent *e )
}
}
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();
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
@@ -115,21 +115,23 @@ private:
// 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