summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-09-30 03:36:02 (UTC)
committer llornkcor <llornkcor>2002-09-30 03:36:02 (UTC)
commit57e740cb3826b88b10daad09b8d453dd609af9cb (patch) (unidiff)
tree32bdbebdd37107d62225aa71c926b8cb8f0c39e8
parent251458a2dd6d75c59440dc006060db2544de5d0e (diff)
downloadopie-57e740cb3826b88b10daad09b8d453dd609af9cb.zip
opie-57e740cb3826b88b10daad09b8d453dd609af9cb.tar.gz
opie-57e740cb3826b88b10daad09b8d453dd609af9cb.tar.bz2
one tr - Standard, the rest of the catagories are in etc/unit_conversion.dat
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/calculator/calculatorimpl.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/tools/calculator/calculatorimpl.cpp b/noncore/tools/calculator/calculatorimpl.cpp
index 0925073..8d11132 100644
--- a/noncore/tools/calculator/calculatorimpl.cpp
+++ b/noncore/tools/calculator/calculatorimpl.cpp
@@ -1,676 +1,676 @@
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/* 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#include <qpe/resource.h> 29#include <qpe/resource.h>
30#include <qpe/qmath.h> 30#include <qpe/qmath.h>
31#include <qpe/qpeapplication.h> 31#include <qpe/qpeapplication.h>
32 32
33#include <qpushbutton.h> 33#include <qpushbutton.h>
34#include <qcombobox.h> 34#include <qcombobox.h>
35#include <qlabel.h> 35#include <qlabel.h>
36#include <qfont.h> 36#include <qfont.h>
37#include <qlayout.h> 37#include <qlayout.h>
38#include <qstringlist.h> 38#include <qstringlist.h>
39#include <qfile.h> 39#include <qfile.h>
40#include <qtextstream.h> 40#include <qtextstream.h>
41#include <qmessagebox.h> 41#include <qmessagebox.h>
42#include <math.h> 42#include <math.h>
43/* XPM */ 43/* XPM */
44static char *oneoverx_xpm[] = { 44static char *oneoverx_xpm[] = {
45/* width height num_colors chars_per_pixel */ 45/* width height num_colors chars_per_pixel */
46" 13 11 2 1", 46" 13 11 2 1",
47/* colors */ 47/* colors */
48". c None", 48". c None",
49"# c #000000", 49"# c #000000",
50/* pixels */ 50/* pixels */
51"......#......", 51"......#......",
52".....##......", 52".....##......",
53"......#......" 53"......#......"
54".....###.....", 54".....###.....",
55".............", 55".............",
56"..#########..", 56"..#########..",
57".............", 57".............",
58"....##.##....", 58"....##.##....",
59"......#......", 59"......#......",
60"......#......", 60"......#......",
61"....##.##....", 61"....##.##....",
62}; 62};
63/* XPM */ 63/* XPM */
64static char *ythrootofx_xpm[] = { 64static char *ythrootofx_xpm[] = {
65/* width height num_colors chars_per_pixel */ 65/* width height num_colors chars_per_pixel */
66" 13 11 2 1", 66" 13 11 2 1",
67/* colors */ 67/* colors */
68". c None", 68". c None",
69"# c #000000", 69"# c #000000",
70/* pixels */ 70/* pixels */
71"#.#..........", 71"#.#..........",
72"#.#..........", 72"#.#..........",
73"###...#######", 73"###...#######",
74"..#..#.......", 74"..#..#.......",
75"###..#.......", 75"###..#.......",
76".....#.#...#.", 76".....#.#...#.",
77".#..#...#.#..", 77".#..#...#.#..",
78"#.#.#....#...", 78"#.#.#....#...",
79"..#.#...#.#..", 79"..#.#...#.#..",
80"...#...#...#.", 80"...#...#...#.",
81"...#........." 81"...#........."
82}; 82};
83/* XPM */ 83/* XPM */
84static char *xtopowerofy_xpm[] = { 84static char *xtopowerofy_xpm[] = {
85/* width height num_colors chars_per_pixel */ 85/* width height num_colors chars_per_pixel */
86" 9 8 2 1", 86" 9 8 2 1",
87/* colors */ 87/* colors */
88". c None", 88". c None",
89"# c #000000", 89"# c #000000",
90/* pixels */ 90/* pixels */
91"......#.#", 91"......#.#",
92"......#.#", 92"......#.#",
93"......###", 93"......###",
94"#...#...#", 94"#...#...#",
95".#.#..###", 95".#.#..###",
96"..#......", 96"..#......",
97".#.#.....", 97".#.#.....",
98"#...#...." 98"#...#...."
99}; 99};
100 100
101CalculatorImpl::CalculatorImpl( QWidget * parent, const char * name, 101CalculatorImpl::CalculatorImpl( QWidget * parent, const char * name,
102 WFlags f ) 102 WFlags f )
103 : Calculator( parent, name, f ) 103 : Calculator( parent, name, f )
104{ 104{
105// xtopowerofy = Resource::loadPixmap("xtopowerofy"); 105// xtopowerofy = Resource::loadPixmap("xtopowerofy");
106// ythrootofx = Resource::loadPixmap("ythrootofx"); 106// ythrootofx = Resource::loadPixmap("ythrootofx");
107// oneoverx = Resource::loadPixmap("oneoverx"); 107// oneoverx = Resource::loadPixmap("oneoverx");
108 108
109 memMark = new QLabel( "m", LCD ); 109 memMark = new QLabel( "m", LCD );
110 memMark->setFont( QFont( "helvetica", 12, QFont::Bold, TRUE ) ); 110 memMark->setFont( QFont( "helvetica", 12, QFont::Bold, TRUE ) );
111 memMark->resize( 12, 12 ); 111 memMark->resize( 12, 12 );
112 memMark->move( 4, 2 ); 112 memMark->move( 4, 2 );
113 memMark->hide(); 113 memMark->hide();
114 mem = 0; 114 mem = 0;
115 115
116 PushButtonMR->setEnabled( FALSE ); 116 PushButtonMR->setEnabled( FALSE );
117 117
118 current_mode = max_mode = conversion_mode_count = 0; 118 current_mode = max_mode = conversion_mode_count = 0;
119 last_conversion = -1; 119 last_conversion = -1;
120 120
121//bgr_command.insert( PushButtonFunction); 121//bgr_command.insert( PushButtonFunction);
122 bgr_command.insert( PushButtonMPlus); 122 bgr_command.insert( PushButtonMPlus);
123 bgr_command.insert( PushButtonMR); 123 bgr_command.insert( PushButtonMR);
124 bgr_command.insert( PushButtonMC); 124 bgr_command.insert( PushButtonMC);
125 bgr_command.insert( PushButtonCE); 125 bgr_command.insert( PushButtonCE);
126 connect( &bgr_command, SIGNAL(clicked(int) ), this, SLOT(command_buttons(int))); 126 connect( &bgr_command, SIGNAL(clicked(int) ), this, SLOT(command_buttons(int)));
127 127
128 bgr_digits.insert(PushButton0); 128 bgr_digits.insert(PushButton0);
129 bgr_digits.insert(PushButton1); 129 bgr_digits.insert(PushButton1);
130 bgr_digits.insert(PushButton2); 130 bgr_digits.insert(PushButton2);
131 bgr_digits.insert(PushButton3); 131 bgr_digits.insert(PushButton3);
132 bgr_digits.insert(PushButton4); 132 bgr_digits.insert(PushButton4);
133 bgr_digits.insert(PushButton5); 133 bgr_digits.insert(PushButton5);
134 bgr_digits.insert(PushButton6); 134 bgr_digits.insert(PushButton6);
135 bgr_digits.insert(PushButton7); 135 bgr_digits.insert(PushButton7);
136 bgr_digits.insert(PushButton8); 136 bgr_digits.insert(PushButton8);
137 bgr_digits.insert(PushButton9); 137 bgr_digits.insert(PushButton9);
138 connect( &bgr_digits, SIGNAL(clicked(int) ), this, SLOT(enterNumber(int))); 138 connect( &bgr_digits, SIGNAL(clicked(int) ), this, SLOT(enterNumber(int)));
139 139
140 140
141 bgr_std.insert(PushButtonEquals); 141 bgr_std.insert(PushButtonEquals);
142 bgr_std.insert(PushButtonDecimal); 142 bgr_std.insert(PushButtonDecimal);
143 bgr_std.insert(PushButtonAdd); 143 bgr_std.insert(PushButtonAdd);
144 bgr_std.insert(PushButtonMinus); 144 bgr_std.insert(PushButtonMinus);
145 bgr_std.insert(PushButtonDivide); 145 bgr_std.insert(PushButtonDivide);
146 bgr_std.insert(PushButtonTimes); 146 bgr_std.insert(PushButtonTimes);
147 connect( &bgr_std, SIGNAL(clicked(int) ), this, SLOT(std_buttons(int))); 147 connect( &bgr_std, SIGNAL(clicked(int) ), this, SLOT(std_buttons(int)));
148 148
149// change the / to a proper division signal 149// change the / to a proper division signal
150 PushButtonDivide->setText(QChar(0xF7)); 150 PushButtonDivide->setText(QChar(0xF7));
151 151
152 func_buttons[0] = PushButtonF1; 152 func_buttons[0] = PushButtonF1;
153 func_buttons[1] = PushButtonF2; 153 func_buttons[1] = PushButtonF2;
154 func_buttons[2] = PushButtonF3; 154 func_buttons[2] = PushButtonF3;
155 func_buttons[3] = PushButtonF4; 155 func_buttons[3] = PushButtonF4;
156 func_buttons[4] = PushButtonF5; 156 func_buttons[4] = PushButtonF5;
157 func_buttons[5] = PushButtonF6; 157 func_buttons[5] = PushButtonF6;
158 func_buttons[6] = PushButtonF7; 158 func_buttons[6] = PushButtonF7;
159 func_buttons[7] = PushButtonF8; 159 func_buttons[7] = PushButtonF8;
160 func_buttons[8] = PushButtonF9; 160 func_buttons[8] = PushButtonF9;
161 func_buttons[9] = PushButtonF10; 161 func_buttons[9] = PushButtonF10;
162 func_buttons[10] = PushButtonF11; 162 func_buttons[10] = PushButtonF11;
163 func_buttons[11] = PushButtonF12; 163 func_buttons[11] = PushButtonF12;
164 164
165 for ( int x = 0 ; x < func_button_count ; x++ ) { 165 for ( int x = 0 ; x < func_button_count ; x++ ) {
166 QPushButton* tmpbutton = func_buttons[x]; 166 QPushButton* tmpbutton = func_buttons[x];
167 faces << tmpbutton->text(); 167 faces << tmpbutton->text();
168 bgr_function.insert(tmpbutton); 168 bgr_function.insert(tmpbutton);
169 } 169 }
170 connect( &bgr_function, SIGNAL(clicked(int) ) , this, SLOT(do_convert(int) ) ); 170 connect( &bgr_function, SIGNAL(clicked(int) ) , this, SLOT(do_convert(int) ) );
171 connect( &bgr_function, SIGNAL(clicked(int) ) , this, SLOT(std_funcs (int) ) ); 171 connect( &bgr_function, SIGNAL(clicked(int) ) , this, SLOT(std_funcs (int) ) );
172 172
173 connect(ComboBoxFunction, SIGNAL(activated(int) ), this, SLOT(function_button(int) ) ); 173 connect(ComboBoxFunction, SIGNAL(activated(int) ), this, SLOT(function_button(int) ) );
174 174
175 captions.append("Standard"); 175 captions.append(tr("Standard"));
176 ComboBoxFunction->insertItem(captions.last()); 176 ComboBoxFunction->insertItem(captions.last());
177 177
178 // now add in the conversion modes 178 // now add in the conversion modes
179 // when the menu gets done, these should be in a submenu 179 // when the menu gets done, these should be in a submenu
180 QString tmp = QPEApplication::qpeDir(); 180 QString tmp = QPEApplication::qpeDir();
181 tmp += "etc/unit_conversion.dat"; 181 tmp += "etc/unit_conversion.dat";
182 QFile myfile(tmp); 182 QFile myfile(tmp);
183 if ( !myfile.open( IO_Translate | IO_ReadOnly ) ) { 183 if ( !myfile.open( IO_Translate | IO_ReadOnly ) ) {
184 qDebug("Data file unit_conversion.dat not found\nNo conversion features will be available\n"+tmp); 184 qDebug("Data file unit_conversion.dat not found\nNo conversion features will be available\n"+tmp);
185 // disable the f button if no conv file available 185 // disable the f button if no conv file available
186 ComboBoxFunction->setEnabled(FALSE); 186 ComboBoxFunction->setEnabled(FALSE);
187 } 187 }
188 else { 188 else {
189 QString line, line2; 189 QString line, line2;
190 QTextStream ts(&myfile); 190 QTextStream ts(&myfile);
191 191
192 // first pass, see how many conversion types there are in order to allocate for them 192 // first pass, see how many conversion types there are in order to allocate for them
193 while ( ! ts.eof() ) { 193 while ( ! ts.eof() ) {
194 line = ts.readLine(); 194 line = ts.readLine();
195 if ( line.contains ("STARTTYPE" ) ) 195 if ( line.contains ("STARTTYPE" ) )
196 conversion_mode_count++; 196 conversion_mode_count++;
197 } 197 }
198 198
199 entry_list = new double[conversion_mode_count*func_button_count]; 199 entry_list = new double[conversion_mode_count*func_button_count];
200 preoffset_list = new double[conversion_mode_count*func_button_count]; 200 preoffset_list = new double[conversion_mode_count*func_button_count];
201 postoffset_list = new double[conversion_mode_count*func_button_count]; 201 postoffset_list = new double[conversion_mode_count*func_button_count];
202 myfile.close(); 202 myfile.close();
203 myfile.open( IO_Translate | IO_ReadOnly ); 203 myfile.open( IO_Translate | IO_ReadOnly );
204 QTextStream ts2(&myfile); 204 QTextStream ts2(&myfile);
205 205
206 // second pass, read in values 206 // second pass, read in values
207 int x = 0; 207 int x = 0;
208 while ( ! ts2.eof() ) { 208 while ( ! ts2.eof() ) {
209 line = ts2.readLine(); 209 line = ts2.readLine();
210 if ( line.contains("STARTTYPE") ) { 210 if ( line.contains("STARTTYPE") ) {
211 captions << line.remove(0,10); 211 captions << line.remove(0,10);
212 ComboBoxFunction->insertItem(captions.last()); 212 ComboBoxFunction->insertItem(captions.last());
213 while ( !line.contains("ENDTYPE") ) { 213 while ( !line.contains("ENDTYPE") ) {
214 line = ts2.readLine(); 214 line = ts2.readLine();
215 if ( line.contains("NAME") ) { 215 if ( line.contains("NAME") ) {
216 faces << line.remove(0,5); 216 faces << line.remove(0,5);
217 line2 = ts2.readLine(); 217 line2 = ts2.readLine();
218 line2.remove(0,6); 218 line2.remove(0,6);
219 entry_list[x] = line2.toDouble(); 219 entry_list[x] = line2.toDouble();
220 line2 = ts2.readLine(); 220 line2 = ts2.readLine();
221 line2.remove(0,7); 221 line2.remove(0,7);
222 preoffset_list[x] = line2.toDouble(); 222 preoffset_list[x] = line2.toDouble();
223 line2 = ts2.readLine(); 223 line2 = ts2.readLine();
224 line2.remove(0,8); 224 line2.remove(0,8);
225 postoffset_list[x] = line2.toDouble(); 225 postoffset_list[x] = line2.toDouble();
226 x++; 226 x++;
227 } 227 }
228 } 228 }
229 } 229 }
230 } 230 }
231 } 231 }
232 myfile.close(); 232 myfile.close();
233 clear(); 233 clear();
234 max_mode = pre_conv_modes_count + conversion_mode_count + post_conv_modes_count - 1; 234 max_mode = pre_conv_modes_count + conversion_mode_count + post_conv_modes_count - 1;
235 display_pixmap_faces(); 235 display_pixmap_faces();
236 236
237 qApp->installEventFilter( this ); 237 qApp->installEventFilter( this );
238} 238}
239 239
240bool CalculatorImpl::eventFilter( QObject *o, QEvent *e ) 240bool CalculatorImpl::eventFilter( QObject *o, QEvent *e )
241{ 241{
242 if ( e->type() == QEvent::KeyPress && state != sError ) { 242 if ( e->type() == QEvent::KeyPress && state != sError ) {
243 QKeyEvent *k = (QKeyEvent*)e; 243 QKeyEvent *k = (QKeyEvent*)e;
244 if ( k->key() >= Key_0 && k->key() <= Key_9 ) { 244 if ( k->key() >= Key_0 && k->key() <= Key_9 ) {
245 enterNumber( k->key() - Key_0 ); 245 enterNumber( k->key() - Key_0 );
246 return true; 246 return true;
247 } else { 247 } else {
248 switch ( k->key() ) { 248 switch ( k->key() ) {
249 case Key_Equal: 249 case Key_Equal:
250 std_buttons(0); 250 std_buttons(0);
251 return true; 251 return true;
252 case Key_Period: 252 case Key_Period:
253 std_buttons(1); 253 std_buttons(1);
254 return true; 254 return true;
255 case Key_Plus: 255 case Key_Plus:
256 std_buttons(2); 256 std_buttons(2);
257 return true; 257 return true;
258 case Key_Minus: 258 case Key_Minus:
259 std_buttons(3); 259 std_buttons(3);
260 return true; 260 return true;
261 case Key_Slash: 261 case Key_Slash:
262 std_buttons(4); 262 std_buttons(4);
263 return true; 263 return true;
264 case Key_Asterisk: 264 case Key_Asterisk:
265 std_buttons(5); 265 std_buttons(5);
266 return true; 266 return true;
267 case Key_Percent: 267 case Key_Percent:
268 execOp( oPercent ); 268 execOp( oPercent );
269 return true; 269 return true;
270 case Key_ParenLeft: 270 case Key_ParenLeft:
271 if ( current_mode < pre_conv_modes_count ) 271 if ( current_mode < pre_conv_modes_count )
272 execOp( oOpenBrace ); 272 execOp( oOpenBrace );
273 return true; 273 return true;
274 case Key_ParenRight: 274 case Key_ParenRight:
275 if ( current_mode < pre_conv_modes_count ) 275 if ( current_mode < pre_conv_modes_count )
276 execOp( oCloseBrace ); 276 execOp( oCloseBrace );
277 return true; 277 return true;
278 default: 278 default:
279 break; 279 break;
280 } 280 }
281 } 281 }
282 } 282 }
283 return Calculator::eventFilter( o, e ); 283 return Calculator::eventFilter( o, e );
284} 284}
285 285
286void CalculatorImpl::do_convert(int button) { 286void CalculatorImpl::do_convert(int button) {
287 if ( state == sError ) 287 if ( state == sError )
288 return; 288 return;
289 if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) && 289 if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) &&
290 button < changeable_func_button_count ) { 290 button < changeable_func_button_count ) {
291 if ( last_conversion > -1 ) { 291 if ( last_conversion > -1 ) {
292 if( state == sNewNumber ){ 292 if( state == sNewNumber ){
293 acc = (num+ preoffset_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion]) 293 acc = (num+ preoffset_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion])
294 / (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion]) 294 / (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion])
295 * (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + button]) 295 * (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + button])
296 +postoffset_list[(current_mode - pre_conv_modes_count) * func_button_count + button]; 296 +postoffset_list[(current_mode - pre_conv_modes_count) * func_button_count + button];
297 num = acc; 297 num = acc;
298 LCD->display( acc ); 298 LCD->display( acc );
299 } else { 299 } else {
300 state = sNewNumber; 300 state = sNewNumber;
301 num = (num+ preoffset_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion]) 301 num = (num+ preoffset_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion])
302 / (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion]) 302 / (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion])
303 * (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + button]) 303 * (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + button])
304 + postoffset_list[(current_mode - pre_conv_modes_count) * func_button_count + button];; 304 + postoffset_list[(current_mode - pre_conv_modes_count) * func_button_count + button];;
305 LCD->display( num ); 305 LCD->display( num );
306 acc = num; 306 acc = num;
307 } 307 }
308 } 308 }
309 last_conversion = button; 309 last_conversion = button;
310 } 310 }
311} 311}
312 312
313 313
314void CalculatorImpl::function_button(int mode){ 314void CalculatorImpl::function_button(int mode){
315 if ( state == sError ) 315 if ( state == sError )
316 clear(); 316 clear();
317 // dont need the next line when using a popup menu 317 // dont need the next line when using a popup menu
318 current_mode = mode; 318 current_mode = mode;
319 319
320 // reset the last conv 320 // reset the last conv
321 last_conversion = -1; 321 last_conversion = -1;
322 322
323 // set the caption 323 // set the caption
324 this->setCaption( captions[current_mode] ); 324 this->setCaption( captions[current_mode] );
325 325
326 reset_conv(); 326 reset_conv();
327 327
328 for ( int x = 0 ; x < changeable_func_button_count ; x++ ) { 328 for ( int x = 0 ; x < changeable_func_button_count ; x++ ) {
329 QPushButton* tmpbutton = func_buttons[x]; 329 QPushButton* tmpbutton = func_buttons[x];
330 330
331 // if its a conversion , make it a toggle button 331 // if its a conversion , make it a toggle button
332 if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) ) { 332 if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) ) {
333 tmpbutton->setToggleButton(TRUE); 333 tmpbutton->setToggleButton(TRUE);
334 } else { 334 } else {
335 tmpbutton->setToggleButton(FALSE); 335 tmpbutton->setToggleButton(FALSE);
336 } 336 }
337 tmpbutton->setText( faces[current_mode * func_button_count + x] ); 337 tmpbutton->setText( faces[current_mode * func_button_count + x] );
338 } 338 }
339 339
340 if ( current_mode == 0 ) display_pixmap_faces(); 340 if ( current_mode == 0 ) display_pixmap_faces();
341 341
342 if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) ) { 342 if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) ) {
343 bgr_function.setExclusive(TRUE); 343 bgr_function.setExclusive(TRUE);
344 } else { 344 } else {
345 bgr_function.setExclusive(FALSE); 345 bgr_function.setExclusive(FALSE);
346 } 346 }
347} 347}
348 348
349void CalculatorImpl::display_pixmap_faces() { 349void CalculatorImpl::display_pixmap_faces() {
350 QPixmap image0( ( const char** ) xtopowerofy_xpm); 350 QPixmap image0( ( const char** ) xtopowerofy_xpm);
351 QPushButton* tmpbutton = func_buttons[5]; 351 QPushButton* tmpbutton = func_buttons[5];
352 tmpbutton->setPixmap(image0); 352 tmpbutton->setPixmap(image0);
353 353
354 QPixmap image1( ( const char** ) ythrootofx_xpm); 354 QPixmap image1( ( const char** ) ythrootofx_xpm);
355 tmpbutton = func_buttons[6]; 355 tmpbutton = func_buttons[6];
356 tmpbutton->setPixmap(image1); 356 tmpbutton->setPixmap(image1);
357 357
358 QPixmap image2( ( const char** ) oneoverx_xpm); 358 QPixmap image2( ( const char** ) oneoverx_xpm);
359 tmpbutton = func_buttons[3]; 359 tmpbutton = func_buttons[3];
360 tmpbutton->setPixmap(image2); 360 tmpbutton->setPixmap(image2);
361} 361}
362 362
363void CalculatorImpl::clear() { 363void CalculatorImpl::clear() {
364 acc = num = 0; 364 acc = num = 0;
365 operationStack.clear(); 365 operationStack.clear();
366 state = sStart; 366 state = sStart;
367 numDecimals = 0; 367 numDecimals = 0;
368 numOpenBraces = 0; 368 numOpenBraces = 0;
369 flPoint = FALSE; 369 flPoint = FALSE;
370 LCD->display( 0 ); 370 LCD->display( 0 );
371 fake = QString::null; 371 fake = QString::null;
372 372
373 reset_conv(); 373 reset_conv();
374} 374}
375 375
376void CalculatorImpl::reset_conv() { 376void CalculatorImpl::reset_conv() {
377 for ( int x = 0 ; x < changeable_func_button_count ; x++ ) { 377 for ( int x = 0 ; x < changeable_func_button_count ; x++ ) {
378 QPushButton* tmpbutton = func_buttons[x]; 378 QPushButton* tmpbutton = func_buttons[x];
379 379
380 // dont carry any selections into the next mode 380 // dont carry any selections into the next mode
381 if ( tmpbutton->state() == QPushButton::On ) { 381 if ( tmpbutton->state() == QPushButton::On ) {
382 tmpbutton->toggle(); 382 tmpbutton->toggle();
383 } 383 }
384 } 384 }
385 385
386 last_conversion = -1; 386 last_conversion = -1;
387} 387}
388 388
389void CalculatorImpl::std_buttons(int button) 389void CalculatorImpl::std_buttons(int button)
390{ 390{
391 if ( state == sError ) 391 if ( state == sError )
392 return; 392 return;
393 execOp( (Operation)(button + oSum) ); 393 execOp( (Operation)(button + oSum) );
394} 394}
395 395
396void CalculatorImpl::std_funcs(int button) { 396void CalculatorImpl::std_funcs(int button) {
397 if ( state == sError ) 397 if ( state == sError )
398 return; 398 return;
399 if ( current_mode < pre_conv_modes_count || 399 if ( current_mode < pre_conv_modes_count ||
400 button > changeable_func_button_count-1 ) { 400 button > changeable_func_button_count-1 ) {
401 Operation op; 401 Operation op;
402 if ( button < 10 ) 402 if ( button < 10 )
403 op = (Operation)(button + oSin); 403 op = (Operation)(button + oSin);
404 else if ( button == 10 ) 404 else if ( button == 10 )
405 op = oOpenBrace; 405 op = oOpenBrace;
406 else 406 else
407 op = oCloseBrace; 407 op = oCloseBrace;
408 execOp( op ); 408 execOp( op );
409 } 409 }
410} 410}
411 411
412void CalculatorImpl::execOp( Operation i ) 412void CalculatorImpl::execOp( Operation i )
413{ 413{
414 switch (i) { 414 switch (i) {
415 // these operators only affect the current number. 415 // these operators only affect the current number.
416 case oDivX: 416 case oDivX:
417 case oLog: 417 case oLog:
418 case oLn: 418 case oLn:
419 case oSin: 419 case oSin:
420 case oCos: 420 case oCos:
421 case oTan: 421 case oTan:
422 num = evalExpr(i); 422 num = evalExpr(i);
423 break; 423 break;
424 424
425 case oAdd: 425 case oAdd:
426 case oSub: { 426 case oSub: {
427 processStack( oAdd ); 427 processStack( oAdd );
428 Op op( num, i ); 428 Op op( num, i );
429 operationStack.push( op ); 429 operationStack.push( op );
430 break; 430 break;
431 } 431 }
432 case oDiv: 432 case oDiv:
433 case oMult: 433 case oMult:
434 case oRoot: 434 case oRoot:
435 case oXsquared: { 435 case oXsquared: {
436 processStack( oDiv ); 436 processStack( oDiv );
437 Op op( num, i ); 437 Op op( num, i );
438 operationStack.push( op ); 438 operationStack.push( op );
439 break; 439 break;
440 } 440 }
441 case oChSign: 441 case oChSign:
442 num = -num; 442 num = -num;
443 LCD->display(num); 443 LCD->display(num);
444 return; 444 return;
445 445
446 case oOpenBrace: { 446 case oOpenBrace: {
447 Op op( 0, oOpenBrace ); 447 Op op( 0, oOpenBrace );
448 operationStack.push( op ); 448 operationStack.push( op );
449 numOpenBraces++; 449 numOpenBraces++;
450 state = sNewNumber; 450 state = sNewNumber;
451 return; 451 return;
452 } 452 }
453 case oCloseBrace: { 453 case oCloseBrace: {
454 if ( numOpenBraces == 0 ) 454 if ( numOpenBraces == 0 )
455 return; 455 return;
456 processStack( oAdd ); 456 processStack( oAdd );
457 if ( operationStack.top().operation != oOpenBrace ) 457 if ( operationStack.top().operation != oOpenBrace )
458 qDebug( "Calculator: internal Error" ); 458 qDebug( "Calculator: internal Error" );
459 operationStack.pop(); 459 operationStack.pop();
460 state = sNewNumber; 460 state = sNewNumber;
461 numOpenBraces--; 461 numOpenBraces--;
462 break; 462 break;
463 } 463 }
464 464
465 case oPoint: 465 case oPoint:
466 flPoint = TRUE; 466 flPoint = TRUE;
467 return; 467 return;
468 468
469 case oPercent: 469 case oPercent:
470 processStack( oPercent ); 470 processStack( oPercent );
471 break; 471 break;
472 472
473 473
474 case oSum: 474 case oSum:
475 processStack( oSum ); 475 processStack( oSum );
476 break; 476 break;
477 477
478 default: 478 default:
479 return; 479 return;
480 }; 480 };
481 481
482 if ( state == sError ) { 482 if ( state == sError ) {
483 LCD->display( "Error" ); 483 LCD->display( "Error" );
484 return; 484 return;
485 } else { 485 } else {
486 LCD->display(num); 486 LCD->display(num);
487 } 487 }
488 state = sNewNumber; 488 state = sNewNumber;
489 numDecimals = 0; 489 numDecimals = 0;
490 flPoint = FALSE; 490 flPoint = FALSE;
491} 491}
492 492
493 493
494void CalculatorImpl::processStack( int op ) 494void CalculatorImpl::processStack( int op )
495{ 495{
496 //dubious percent hack, since the changeable operator precedences are 496 //dubious percent hack, since the changeable operator precedences are
497 //pretty much hardwired to be less than the non-changeable 497 //pretty much hardwired to be less than the non-changeable
498 bool percent = FALSE; 498 bool percent = FALSE;
499 if ( op == oPercent ) { 499 if ( op == oPercent ) {
500 percent = TRUE; 500 percent = TRUE;
501 op = oSum; 501 op = oSum;
502 } 502 }
503 while( !operationStack.isEmpty() && operationStack.top().operation >= op ) { 503 while( !operationStack.isEmpty() && operationStack.top().operation >= op ) {
504 Op operation = operationStack.pop(); 504 Op operation = operationStack.pop();
505 acc = operation.number; 505 acc = operation.number;
506 if ( percent ) { 506 if ( percent ) {
507 if ( operation.operation == oAdd || operation.operation == oSub ) 507 if ( operation.operation == oAdd || operation.operation == oSub )
508 num = acc*num/100; 508 num = acc*num/100;
509 else 509 else
510 num = num / 100; 510 num = num / 100;
511 } 511 }
512 num = evalExpr( operation.operation ); 512 num = evalExpr( operation.operation );
513 percent = FALSE; 513 percent = FALSE;
514 } 514 }
515} 515}
516 516
517 517
518double CalculatorImpl::evalExpr( int op ) { 518double CalculatorImpl::evalExpr( int op ) {
519 double sum = 0; 519 double sum = 0;
520 520
521 switch( op ){ 521 switch( op ){
522 case oPercent: sum = num / 100.; break; 522 case oPercent: sum = num / 100.; break;
523 case oDivX: 523 case oDivX:
524 if (num == 0) 524 if (num == 0)
525 state = sError; 525 state = sError;
526 else 526 else
527 sum = 1 / num; 527 sum = 1 / num;
528 break; 528 break;
529 case oXsquared: 529 case oXsquared:
530 sum = pow(acc,num); 530 sum = pow(acc,num);
531 break; 531 break;
532 case oChSign: (state == sStart) ? sum = -num : sum = -acc; break; 532 case oChSign: (state == sStart) ? sum = -num : sum = -acc; break;
533 case oSub: sum = acc - num; break; 533 case oSub: sum = acc - num; break;
534 case oMult: sum = acc * num; break; 534 case oMult: sum = acc * num; break;
535 case oAdd: sum = acc + num; break; 535 case oAdd: sum = acc + num; break;
536 case oDiv: { 536 case oDiv: {
537 if (num == 0) { 537 if (num == 0) {
538 state = sError; 538 state = sError;
539 } else { 539 } else {
540 sum = acc / num; 540 sum = acc / num;
541 } 541 }
542 break; 542 break;
543 } 543 }
544 case oRoot: 544 case oRoot:
545 /* the linux library is dumb, and can't to -x to 1/n 545 /* the linux library is dumb, and can't to -x to 1/n
546 when n is odd. (even and error of course is acceptable */ 546 when n is odd. (even and error of course is acceptable */
547 if((acc < 0) && (int(num) == num) && (int(num) % 2 == 1 )) { 547 if((acc < 0) && (int(num) == num) && (int(num) % 2 == 1 )) {
548 sum = pow(-acc, 1 / num); 548 sum = pow(-acc, 1 / num);
549 sum = -sum; 549 sum = -sum;
550 } else { 550 } else {
551 sum = pow(acc, 1 / num); 551 sum = pow(acc, 1 / num);
552 } 552 }
553 break; 553 break;
554 case oLog: 554 case oLog:
555 sum = log10(num); 555 sum = log10(num);
556 break; 556 break;
557 case oLn: 557 case oLn:
558 sum = log(num); 558 sum = log(num);
559 break; 559 break;
560 case oTan: sum = qTan(num);break; 560 case oTan: sum = qTan(num);break;
561 case oSin: sum = qSin(num);break; 561 case oSin: sum = qSin(num);break;
562 case oCos: sum = qCos(num);break; 562 case oCos: sum = qCos(num);break;
563 default: sum = num; break; 563 default: sum = num; break;
564 } 564 }
565 565
566 if ( isinf( sum ) || isnan( sum ) ) 566 if ( isinf( sum ) || isnan( sum ) )
567 state = sError; 567 state = sError;
568 return sum; 568 return sum;
569} 569}
570 570
571 571
572void CalculatorImpl::enterNumber( int n ) 572void CalculatorImpl::enterNumber( int n )
573{ 573{
574 if ( state == sError ) 574 if ( state == sError )
575 return; 575 return;
576 if( state == sStart ){ 576 if( state == sStart ){
577 if( LCD->value() > 0 ){ 577 if( LCD->value() > 0 ){
578 QString s = QString::number( LCD->value(), 'g', LCD->numDigits()); 578 QString s = QString::number( LCD->value(), 'g', LCD->numDigits());
579 if( s.length() > (uint)(LCD->numDigits() - 2)) return; 579 if( s.length() > (uint)(LCD->numDigits() - 2)) return;
580 580
581 } else if( (int)fake.length() >= LCD->numDigits() || numDecimals >=12 ){ 581 } else if( (int)fake.length() >= LCD->numDigits() || numDecimals >=12 ){
582 return; 582 return;
583 } 583 }
584 } 584 }
585 585
586 if( state == sNewNumber ){ 586 if( state == sNewNumber ){
587 state = sStart; 587 state = sStart;
588 acc = 0; 588 acc = 0;
589 if( flPoint ){ 589 if( flPoint ){
590 numDecimals = 1; 590 numDecimals = 1;
591 num = n / pow(10, numDecimals); 591 num = n / pow(10, numDecimals);
592 } else 592 } else
593 num = n; 593 num = n;
594 } else if( flPoint ){ 594 } else if( flPoint ){
595 numDecimals++; 595 numDecimals++;
596 if( num < 0 ){ 596 if( num < 0 ){
597 num -= n / pow(10, numDecimals); 597 num -= n / pow(10, numDecimals);
598 } else { 598 } else {
599 num += n / pow(10, numDecimals); 599 num += n / pow(10, numDecimals);
600 } 600 }
601 } else { 601 } else {
602 num *= 10; 602 num *= 10;
603 if( num < 0 ) 603 if( num < 0 )
604 num -= n; 604 num -= n;
605 else 605 else
606 num += n; 606 num += n;
607 } 607 }
608 608
609 // We need feedback in the calc display while entering fl.point zeros. 609 // We need feedback in the calc display while entering fl.point zeros.
610 // This is a small hack to display sequences like: 0.000 and 1.100 610 // This is a small hack to display sequences like: 0.000 and 1.100
611 double integer, fraction; 611 double integer, fraction;
612 fraction = modf( num, &integer ); 612 fraction = modf( num, &integer );
613 if( flPoint ){ 613 if( flPoint ){
614 QString is, fs, zeros; 614 QString is, fs, zeros;
615 615
616 is = QString::number( integer, 'g', 13 ); 616 is = QString::number( integer, 'g', 13 );
617 fs = QString::number( fraction, 'g', numDecimals ); 617 fs = QString::number( fraction, 'g', numDecimals );
618 if( fs.contains('e') ){ 618 if( fs.contains('e') ){
619 fs = QString::number( fraction, 'f', LCD->numDigits() ); 619 fs = QString::number( fraction, 'f', LCD->numDigits() );
620 } 620 }
621 fs = fs.mid( 2, numDecimals ); 621 fs = fs.mid( 2, numDecimals );
622 622
623 if( (integer == 0) && (fraction == 0) ) 623 if( (integer == 0) && (fraction == 0) )
624 fake = "0."; 624 fake = "0.";
625 else if( (integer != 0) && (fraction == 0) ) 625 else if( (integer != 0) && (fraction == 0) )
626 fake = is + "."; 626 fake = is + ".";
627 else 627 else
628 fake = is + "." + fs; 628 fake = is + "." + fs;
629 629
630 zeros.fill( '0', (numDecimals - fs.length()) ); 630 zeros.fill( '0', (numDecimals - fs.length()) );
631 fake += zeros; 631 fake += zeros;
632 // ### This code sets LCD->value() to zero since it sets a text 632 // ### This code sets LCD->value() to zero since it sets a text
633 // ### Avoid getting the current value from LCD->value() for 633 // ### Avoid getting the current value from LCD->value() for
634 // ### calculations. 634 // ### calculations.
635 LCD->display( fake ); 635 LCD->display( fake );
636 } else 636 } else
637 LCD->display( num ); 637 LCD->display( num );
638} 638}
639 639
640void CalculatorImpl::command_buttons(int i) { 640void CalculatorImpl::command_buttons(int i) {
641 if ( state == sError && i != 3 ) 641 if ( state == sError && i != 3 )
642 return; 642 return;
643 switch (i) { 643 switch (i) {
644 case 0: // M+ 644 case 0: // M+
645 mem += num; 645 mem += num;
646 if( mem != 0 ){ 646 if( mem != 0 ){
647 memMark->show(); 647 memMark->show();
648 PushButtonMR->setEnabled( TRUE ); }; 648 PushButtonMR->setEnabled( TRUE ); };
649 state = sNewNumber; 649 state = sNewNumber;
650 break; 650 break;
651 case 1: // MR 651 case 1: // MR
652 acc = num = mem; 652 acc = num = mem;
653 state = sNewNumber; 653 state = sNewNumber;
654 LCD->display( mem ); 654 LCD->display( mem );
655 break; 655 break;
656 case 2: // MC 656 case 2: // MC
657 mem = 0; 657 mem = 0;
658 memMark->hide(); 658 memMark->hide();
659 PushButtonMR->setEnabled( FALSE ); 659 PushButtonMR->setEnabled( FALSE );
660 break; 660 break;
661 case 3: // CE 661 case 3: // CE
662 if ( state == sStart ) { 662 if ( state == sStart ) {
663 // clear the entered number on the first press 663 // clear the entered number on the first press
664 state = sNewNumber; 664 state = sNewNumber;
665 num = acc = 0; 665 num = acc = 0;
666 flPoint = FALSE; 666 flPoint = FALSE;
667 LCD->display( 0 ); 667 LCD->display( 0 );
668 fake = QString::null; 668 fake = QString::null;
669 numDecimals = 0; 669 numDecimals = 0;
670 } else { 670 } else {
671 clear(); 671 clear();
672 } 672 }
673 break; 673 break;
674 }; 674 };
675 675
676} 676}