summaryrefslogtreecommitdiff
path: root/noncore/tools/calculator/calculatorimpl.cpp
Side-by-side diff
Diffstat (limited to 'noncore/tools/calculator/calculatorimpl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/calculator/calculatorimpl.cpp11
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
@@ -1,90 +1,97 @@
/**********************************************************************
** 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.
*/
// Sat 03-09-2002 L.J. Potter added the inlined pixmaps here
#include "calculatorimpl.h"
+/* OPIE */
+#include <opie2/odebug.h>
#include <qpe/resource.h>
#include <qpe/qmath.h>
#include <qpe/qpeapplication.h>
+using namespace Opie::Core;
+/* QT */
#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>
+
+/* STD */
#include <math.h>
+
/* XPM */
static char *oneoverx_xpm[] = {
/* width height num_colors chars_per_pixel */
" 13 11 2 1",
/* colors */
". c None",
"# c #000000",
/* pixels */
"......#......",
".....##......",
"......#......"
".....###.....",
".............",
"..#########..",
".............",
"....##.##....",
"......#......",
"......#......",
"....##.##....",
};
/* XPM */
static char *ythrootofx_xpm[] = {
/* width height num_colors chars_per_pixel */
" 13 11 2 1",
/* colors */
". c None",
"# c #000000",
/* pixels */
"#.#..........",
"#.#..........",
"###...#######",
"..#..#.......",
"###..#.......",
".....#.#...#.",
".#..#...#.#..",
"#.#.#....#...",
"..#.#...#.#..",
"...#...#...#.",
"...#........."
};
/* XPM */
static char *xtopowerofy_xpm[] = {
/* width height num_colors chars_per_pixel */
" 9 8 2 1",
/* colors */
". c None",
"# c #000000",
/* pixels */
@@ -188,97 +195,97 @@ CalculatorImpl::CalculatorImpl( QWidget * parent, const char * name,
bgr_digits.insert(PushButton8);
bgr_digits.insert(PushButton9);
connect( &bgr_digits, SIGNAL(clicked(int) ), this, SLOT(enterNumber(int)));
bgr_std.insert(PushButtonEquals);
bgr_std.insert(PushButtonDecimal);
bgr_std.insert(PushButtonAdd);
bgr_std.insert(PushButtonMinus);
bgr_std.insert(PushButtonDivide);
bgr_std.insert(PushButtonTimes);
connect( &bgr_std, SIGNAL(clicked(int) ), this, SLOT(std_buttons(int)));
// change the / to a proper division signal
PushButtonDivide->setText(QChar(0xF7));
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(tr("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 ) ) {
- qDebug("Data file unit_conversion.dat not found\nNo conversion features will be available\n"+tmp);
+ odebug << "Data file unit_conversion.dat not found\nNo conversion features will be available\n"+tmp << oendl;
// 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 << tr( line.remove(0,10) );
ComboBoxFunction->insertItem(captions.last());
while ( !line.contains("ENDTYPE") ) {
line = ts2.readLine();
if ( line.contains("NAME") ) {
faces << tr( 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();
@@ -462,97 +469,97 @@ void CalculatorImpl::std_funcs(int button) {
}
void CalculatorImpl::execOp( Operation i )
{
switch (i) {
// these operators only affect the current number.
case oDivX:
case oLog:
case oLn:
case oSin:
case oCos:
case oTan:
num = evalExpr(i);
break;
case oAdd:
case oSub: {
processStack( oAdd );
Op op( num, i );
operationStack.push( op );
break;
}
case oDiv:
case oMult:
case oRoot:
case oXsquared: {
processStack( oDiv );
Op op( num, i );
operationStack.push( op );
break;
}
case oChSign:
num = -num;
LCD->display(num);
return;
case oOpenBrace: {
Op op( 0, oOpenBrace );
operationStack.push( op );
numOpenBraces++;
state = sNewNumber;
return;
}
case oCloseBrace: {
if ( numOpenBraces == 0 )
return;
processStack( oAdd );
if ( operationStack.top().operation != oOpenBrace )
- qDebug( "Calculator: internal Error" );
+ odebug << "Calculator: internal Error" << oendl;
operationStack.pop();
state = sNewNumber;
numOpenBraces--;
break;
}
case oPoint:
flPoint = TRUE;
return;
case oPercent:
processStack( oPercent );
break;
case oSum:
processStack( oSum );
break;
default:
return;
};
if ( state == sError ) {
LCD->display( "Error" );
return;
} else {
LCD->display(num);
}
state = sNewNumber;
numDecimals = 0;
flPoint = FALSE;
}
void CalculatorImpl::processStack( int op )
{
//dubious percent hack, since the changeable operator precedences are
//pretty much hardwired to be less than the non-changeable
bool percent = FALSE;
if ( op == oPercent ) {
percent = TRUE;
op = oSum;
}
while( !operationStack.isEmpty() && operationStack.top().operation >= op ) {
Op operation = operationStack.pop();
acc = operation.number;
if ( percent ) {