Diffstat (limited to 'noncore/tools/calculator/calculatorimpl.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/tools/calculator/calculatorimpl.h | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/noncore/tools/calculator/calculatorimpl.h b/noncore/tools/calculator/calculatorimpl.h new file mode 100644 index 0000000..bfb726f --- a/dev/null +++ b/noncore/tools/calculator/calculatorimpl.h | |||
@@ -0,0 +1,135 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef CALCULATORIMPL_H | ||
21 | #define CALCULATORIMPL_H | ||
22 | |||
23 | |||
24 | #include <qlcdnumber.h> | ||
25 | #include "calculator.h" | ||
26 | #include <qpushbutton.h> | ||
27 | #include <qbuttongroup.h> | ||
28 | #include <qvaluestack.h> | ||
29 | |||
30 | // mode x functions | ||
31 | enum Operation { | ||
32 | oNop, | ||
33 | oOpenBrace, | ||
34 | oCloseBrace, | ||
35 | oSum, | ||
36 | oPoint, | ||
37 | oAdd, | ||
38 | oSub, | ||
39 | oDiv, | ||
40 | oMult, | ||
41 | |||
42 | // mode 0 functions | ||
43 | oSin, | ||
44 | oCos, | ||
45 | oTan, | ||
46 | oDivX, | ||
47 | oPercent, | ||
48 | oXsquared, | ||
49 | oRoot, | ||
50 | oLog, | ||
51 | oLn, | ||
52 | oChSign | ||
53 | }; | ||
54 | |||
55 | // states | ||
56 | #define sStart 0 | ||
57 | #define sNewNumber 1 | ||
58 | #define sError 2 | ||
59 | |||
60 | struct Op | ||
61 | { | ||
62 | Op() { number = 0; operation = oNop; } | ||
63 | Op( double num, Operation op ) | ||
64 | { number = num; operation = op; } | ||
65 | double number; | ||
66 | Operation operation; | ||
67 | }; | ||
68 | |||
69 | class QLabel; | ||
70 | class CalculatorImpl : public Calculator | ||
71 | { | ||
72 | Q_OBJECT | ||
73 | |||
74 | public: | ||
75 | CalculatorImpl( QWidget * parent = 0, const char * name = 0, | ||
76 | WFlags f = 0 ); | ||
77 | |||
78 | public slots: | ||
79 | void command_buttons(int); | ||
80 | void enterNumber(int i); | ||
81 | void std_buttons(int); | ||
82 | void std_funcs(int); | ||
83 | void do_convert(int); | ||
84 | void function_button(int); | ||
85 | |||
86 | protected: | ||
87 | virtual bool eventFilter( QObject *o, QEvent *e ); | ||
88 | |||
89 | private: | ||
90 | void clear(); | ||
91 | |||
92 | void reset_conv(); | ||
93 | |||
94 | void processStack( int op ); | ||
95 | |||
96 | QValueStack<Op> operationStack; | ||
97 | int state; | ||
98 | |||
99 | double acc, num, mem; | ||
100 | int numDecimals; | ||
101 | bool flPoint; | ||
102 | int numOpenBraces; | ||
103 | |||
104 | void execOp( Operation i ); | ||
105 | double evalExpr( int op ); | ||
106 | QLabel * memMark; | ||
107 | QString fake; | ||
108 | |||
109 | // useful values for conversion stuff | ||
110 | int current_mode, max_mode, conversion_mode_count, last_conversion; | ||
111 | |||
112 | // make adding new modes easier for ourselves | ||
113 | static const int pre_conv_modes_count = 1; | ||
114 | static const int post_conv_modes_count = 0; | ||
115 | |||
116 | // an array of pointers to the func buttons | ||
117 | static const int func_button_count = 12; | ||
118 | // this is an abomination | ||
119 | static const int changeable_func_button_count = 10; | ||
120 | QPushButton* func_buttons[func_button_count]; | ||
121 | |||
122 | QButtonGroup bgr_function, bgr_digits, bgr_std, bgr_command; | ||
123 | QStringList faces, captions; | ||
124 | |||
125 | // an array of doubles holding the conversion ratios | ||
126 | double* entry_list; | ||
127 | |||
128 | QPixmap xtopowerofy; | ||
129 | QPixmap ythrootofx; | ||
130 | QPixmap oneoverx; | ||
131 | |||
132 | void display_pixmap_faces(void); | ||
133 | }; | ||
134 | |||
135 | #endif | ||