summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-03-09 21:46:21 (UTC)
committer llornkcor <llornkcor>2002-03-09 21:46:21 (UTC)
commit80be7dabb1e1390e4d412c785d9f44e2293b2d5d (patch) (unidiff)
tree04daeda225b3be914885adaf6c46cf3b83ce123c
parent53fd2f87c62cf60e8326110f11838661d0521b63 (diff)
downloadopie-80be7dabb1e1390e4d412c785d9f44e2293b2d5d.zip
opie-80be7dabb1e1390e4d412c785d9f44e2293b2d5d.tar.gz
opie-80be7dabb1e1390e4d412c785d9f44e2293b2d5d.tar.bz2
fixed weirdness with the inlined xpm's- for some odd and unknown reason
they weren't showing correctly anymore...
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/calculator/calculatorimpl.cpp73
1 files changed, 67 insertions, 6 deletions
diff --git a/noncore/tools/calculator/calculatorimpl.cpp b/noncore/tools/calculator/calculatorimpl.cpp
index 3a6efe4..0925073 100644
--- a/noncore/tools/calculator/calculatorimpl.cpp
+++ b/noncore/tools/calculator/calculatorimpl.cpp
@@ -1,97 +1,155 @@
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 26
26#include "calculatorimpl.h" 27#include "calculatorimpl.h"
27 28
28#include <qpe/resource.h> 29#include <qpe/resource.h>
29#include <qpe/qmath.h> 30#include <qpe/qmath.h>
30#include <qpe/qpeapplication.h> 31#include <qpe/qpeapplication.h>
31 32
32#include <qpushbutton.h> 33#include <qpushbutton.h>
33#include <qcombobox.h> 34#include <qcombobox.h>
34#include <qlabel.h> 35#include <qlabel.h>
35#include <qfont.h> 36#include <qfont.h>
36#include <qlayout.h> 37#include <qlayout.h>
37#include <qstringlist.h> 38#include <qstringlist.h>
38#include <qfile.h> 39#include <qfile.h>
39#include <qtextstream.h> 40#include <qtextstream.h>
40#include <qmessagebox.h> 41#include <qmessagebox.h>
41#include <math.h> 42#include <math.h>
43/* XPM */
44static char *oneoverx_xpm[] = {
45/* width height num_colors chars_per_pixel */
46" 13 11 2 1",
47/* colors */
48". c None",
49"# c #000000",
50/* pixels */
51"......#......",
52".....##......",
53"......#......"
54".....###.....",
55".............",
56"..#########..",
57".............",
58"....##.##....",
59"......#......",
60"......#......",
61"....##.##....",
62};
63/* XPM */
64static char *ythrootofx_xpm[] = {
65/* width height num_colors chars_per_pixel */
66" 13 11 2 1",
67/* colors */
68". c None",
69"# c #000000",
70/* pixels */
71"#.#..........",
72"#.#..........",
73"###...#######",
74"..#..#.......",
75"###..#.......",
76".....#.#...#.",
77".#..#...#.#..",
78"#.#.#....#...",
79"..#.#...#.#..",
80"...#...#...#.",
81"...#........."
82};
83/* XPM */
84static char *xtopowerofy_xpm[] = {
85/* width height num_colors chars_per_pixel */
86" 9 8 2 1",
87/* colors */
88". c None",
89"# c #000000",
90/* pixels */
91"......#.#",
92"......#.#",
93"......###",
94"#...#...#",
95".#.#..###",
96"..#......",
97".#.#.....",
98"#...#...."
99};
42 100
43CalculatorImpl::CalculatorImpl( QWidget * parent, const char * name, 101CalculatorImpl::CalculatorImpl( QWidget * parent, const char * name,
44 WFlags f ) 102 WFlags f )
45 : Calculator( parent, name, f ) 103 : Calculator( parent, name, f )
46{ 104{
47 xtopowerofy = Resource::loadPixmap("xtopowerofy"); 105// xtopowerofy = Resource::loadPixmap("xtopowerofy");
48 ythrootofx = Resource::loadPixmap("ythrootofx"); 106// ythrootofx = Resource::loadPixmap("ythrootofx");
49 oneoverx = Resource::loadPixmap("oneoverx"); 107// oneoverx = Resource::loadPixmap("oneoverx");
50 108
51 memMark = new QLabel( "m", LCD ); 109 memMark = new QLabel( "m", LCD );
52 memMark->setFont( QFont( "helvetica", 12, QFont::Bold, TRUE ) ); 110 memMark->setFont( QFont( "helvetica", 12, QFont::Bold, TRUE ) );
53 memMark->resize( 12, 12 ); 111 memMark->resize( 12, 12 );
54 memMark->move( 4, 2 ); 112 memMark->move( 4, 2 );
55 memMark->hide(); 113 memMark->hide();
56 mem = 0; 114 mem = 0;
57 115
58 PushButtonMR->setEnabled( FALSE ); 116 PushButtonMR->setEnabled( FALSE );
59 117
60 current_mode = max_mode = conversion_mode_count = 0; 118 current_mode = max_mode = conversion_mode_count = 0;
61 last_conversion = -1; 119 last_conversion = -1;
62 120
63//bgr_command.insert( PushButtonFunction); 121//bgr_command.insert( PushButtonFunction);
64 bgr_command.insert( PushButtonMPlus); 122 bgr_command.insert( PushButtonMPlus);
65 bgr_command.insert( PushButtonMR); 123 bgr_command.insert( PushButtonMR);
66 bgr_command.insert( PushButtonMC); 124 bgr_command.insert( PushButtonMC);
67 bgr_command.insert( PushButtonCE); 125 bgr_command.insert( PushButtonCE);
68 connect( &bgr_command, SIGNAL(clicked(int) ), this, SLOT(command_buttons(int))); 126 connect( &bgr_command, SIGNAL(clicked(int) ), this, SLOT(command_buttons(int)));
69 127
70 bgr_digits.insert(PushButton0); 128 bgr_digits.insert(PushButton0);
71 bgr_digits.insert(PushButton1); 129 bgr_digits.insert(PushButton1);
72 bgr_digits.insert(PushButton2); 130 bgr_digits.insert(PushButton2);
73 bgr_digits.insert(PushButton3); 131 bgr_digits.insert(PushButton3);
74 bgr_digits.insert(PushButton4); 132 bgr_digits.insert(PushButton4);
75 bgr_digits.insert(PushButton5); 133 bgr_digits.insert(PushButton5);
76 bgr_digits.insert(PushButton6); 134 bgr_digits.insert(PushButton6);
77 bgr_digits.insert(PushButton7); 135 bgr_digits.insert(PushButton7);
78 bgr_digits.insert(PushButton8); 136 bgr_digits.insert(PushButton8);
79 bgr_digits.insert(PushButton9); 137 bgr_digits.insert(PushButton9);
80 connect( &bgr_digits, SIGNAL(clicked(int) ), this, SLOT(enterNumber(int))); 138 connect( &bgr_digits, SIGNAL(clicked(int) ), this, SLOT(enterNumber(int)));
81 139
82 140
83 bgr_std.insert(PushButtonEquals); 141 bgr_std.insert(PushButtonEquals);
84 bgr_std.insert(PushButtonDecimal); 142 bgr_std.insert(PushButtonDecimal);
85 bgr_std.insert(PushButtonAdd); 143 bgr_std.insert(PushButtonAdd);
86 bgr_std.insert(PushButtonMinus); 144 bgr_std.insert(PushButtonMinus);
87 bgr_std.insert(PushButtonDivide); 145 bgr_std.insert(PushButtonDivide);
88 bgr_std.insert(PushButtonTimes); 146 bgr_std.insert(PushButtonTimes);
89 connect( &bgr_std, SIGNAL(clicked(int) ), this, SLOT(std_buttons(int))); 147 connect( &bgr_std, SIGNAL(clicked(int) ), this, SLOT(std_buttons(int)));
90 148
91// change the / to a proper division signal 149// change the / to a proper division signal
92 PushButtonDivide->setText(QChar(0xF7)); 150 PushButtonDivide->setText(QChar(0xF7));
93 151
94 func_buttons[0] = PushButtonF1; 152 func_buttons[0] = PushButtonF1;
95 func_buttons[1] = PushButtonF2; 153 func_buttons[1] = PushButtonF2;
96 func_buttons[2] = PushButtonF3; 154 func_buttons[2] = PushButtonF3;
97 func_buttons[3] = PushButtonF4; 155 func_buttons[3] = PushButtonF4;
@@ -244,104 +302,107 @@ void CalculatorImpl::do_convert(int button) {
244 / (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])
245 * (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])
246 + 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];;
247 LCD->display( num ); 305 LCD->display( num );
248 acc = num; 306 acc = num;
249 } 307 }
250 } 308 }
251 last_conversion = button; 309 last_conversion = button;
252 } 310 }
253} 311}
254 312
255 313
256void CalculatorImpl::function_button(int mode){ 314void CalculatorImpl::function_button(int mode){
257 if ( state == sError ) 315 if ( state == sError )
258 clear(); 316 clear();
259 // dont need the next line when using a popup menu 317 // dont need the next line when using a popup menu
260 current_mode = mode; 318 current_mode = mode;
261 319
262 // reset the last conv 320 // reset the last conv
263 last_conversion = -1; 321 last_conversion = -1;
264 322
265 // set the caption 323 // set the caption
266 this->setCaption( captions[current_mode] ); 324 this->setCaption( captions[current_mode] );
267 325
268 reset_conv(); 326 reset_conv();
269 327
270 for ( int x = 0 ; x < changeable_func_button_count ; x++ ) { 328 for ( int x = 0 ; x < changeable_func_button_count ; x++ ) {
271 QPushButton* tmpbutton = func_buttons[x]; 329 QPushButton* tmpbutton = func_buttons[x];
272 330
273 // if its a conversion , make it a toggle button 331 // if its a conversion , make it a toggle button
274 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) ) {
275 tmpbutton->setToggleButton(TRUE); 333 tmpbutton->setToggleButton(TRUE);
276 } else { 334 } else {
277 tmpbutton->setToggleButton(FALSE); 335 tmpbutton->setToggleButton(FALSE);
278 } 336 }
279 tmpbutton->setText( faces[current_mode * func_button_count + x] ); 337 tmpbutton->setText( faces[current_mode * func_button_count + x] );
280 } 338 }
281 339
282 if ( current_mode == 0 ) display_pixmap_faces(); 340 if ( current_mode == 0 ) display_pixmap_faces();
283 341
284 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) ) {
285 bgr_function.setExclusive(TRUE); 343 bgr_function.setExclusive(TRUE);
286 } else { 344 } else {
287 bgr_function.setExclusive(FALSE); 345 bgr_function.setExclusive(FALSE);
288 } 346 }
289} 347}
290 348
291void CalculatorImpl::display_pixmap_faces() { 349void CalculatorImpl::display_pixmap_faces() {
350 QPixmap image0( ( const char** ) xtopowerofy_xpm);
292 QPushButton* tmpbutton = func_buttons[5]; 351 QPushButton* tmpbutton = func_buttons[5];
293 tmpbutton->setPixmap(xtopowerofy); 352 tmpbutton->setPixmap(image0);
294 353
354 QPixmap image1( ( const char** ) ythrootofx_xpm);
295 tmpbutton = func_buttons[6]; 355 tmpbutton = func_buttons[6];
296 tmpbutton->setPixmap(ythrootofx); 356 tmpbutton->setPixmap(image1);
297 357
358 QPixmap image2( ( const char** ) oneoverx_xpm);
298 tmpbutton = func_buttons[3]; 359 tmpbutton = func_buttons[3];
299 tmpbutton->setPixmap(oneoverx); 360 tmpbutton->setPixmap(image2);
300} 361}
301 362
302void CalculatorImpl::clear() { 363void CalculatorImpl::clear() {
303 acc = num = 0; 364 acc = num = 0;
304 operationStack.clear(); 365 operationStack.clear();
305 state = sStart; 366 state = sStart;
306 numDecimals = 0; 367 numDecimals = 0;
307 numOpenBraces = 0; 368 numOpenBraces = 0;
308 flPoint = FALSE; 369 flPoint = FALSE;
309 LCD->display( 0 ); 370 LCD->display( 0 );
310 fake = QString::null; 371 fake = QString::null;
311 372
312 reset_conv(); 373 reset_conv();
313} 374}
314 375
315void CalculatorImpl::reset_conv() { 376void CalculatorImpl::reset_conv() {
316 for ( int x = 0 ; x < changeable_func_button_count ; x++ ) { 377 for ( int x = 0 ; x < changeable_func_button_count ; x++ ) {
317 QPushButton* tmpbutton = func_buttons[x]; 378 QPushButton* tmpbutton = func_buttons[x];
318 379
319 // dont carry any selections into the next mode 380 // dont carry any selections into the next mode
320 if ( tmpbutton->state() == QPushButton::On ) { 381 if ( tmpbutton->state() == QPushButton::On ) {
321 tmpbutton->toggle(); 382 tmpbutton->toggle();
322 } 383 }
323 } 384 }
324 385
325 last_conversion = -1; 386 last_conversion = -1;
326} 387}
327 388
328void CalculatorImpl::std_buttons(int button) 389void CalculatorImpl::std_buttons(int button)
329{ 390{
330 if ( state == sError ) 391 if ( state == sError )
331 return; 392 return;
332 execOp( (Operation)(button + oSum) ); 393 execOp( (Operation)(button + oSum) );
333} 394}
334 395
335void CalculatorImpl::std_funcs(int button) { 396void CalculatorImpl::std_funcs(int button) {
336 if ( state == sError ) 397 if ( state == sError )
337 return; 398 return;
338 if ( current_mode < pre_conv_modes_count || 399 if ( current_mode < pre_conv_modes_count ||
339 button > changeable_func_button_count-1 ) { 400 button > changeable_func_button_count-1 ) {
340 Operation op; 401 Operation op;
341 if ( button < 10 ) 402 if ( button < 10 )
342 op = (Operation)(button + oSin); 403 op = (Operation)(button + oSin);
343 else if ( button == 10 ) 404 else if ( button == 10 )
344 op = oOpenBrace; 405 op = oOpenBrace;
345 else 406 else
346 op = oCloseBrace; 407 op = oCloseBrace;
347 execOp( op ); 408 execOp( op );