00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef CALCULATORIMPL_H
00021 #define CALCULATORIMPL_H
00022
00023
00024 #include <qlcdnumber.h>
00025 #include "calculator.h"
00026 #include <qpushbutton.h>
00027 #include <qbuttongroup.h>
00028 #include <qvaluestack.h>
00029
00030
00031 enum Operation {
00032 oNop,
00033 oOpenBrace,
00034 oCloseBrace,
00035 oSum,
00036 oPoint,
00037 oAdd,
00038 oSub,
00039 oDiv,
00040 oMult,
00041
00042
00043 oSin,
00044 oCos,
00045 oTan,
00046 oDivX,
00047 oPercent,
00048 oXsquared,
00049 oRoot,
00050 oLog,
00051 oLn,
00052 oChSign
00053 };
00054
00055
00056 #define sStart 0
00057 #define sNewNumber 1
00058 #define sError 2
00059
00060 struct Op
00061 {
00062 Op() { number = 0; operation = oNop; }
00063 Op( double num, Operation op )
00064 { number = num; operation = op; }
00065 double number;
00066 Operation operation;
00067 };
00068
00069 class QLabel;
00070 class CalculatorImpl : public Calculator
00071 {
00072 Q_OBJECT
00073
00074 public:
00075 CalculatorImpl( QWidget * parent = 0, const char * name = 0,
00076 WFlags f = 0 );
00077 static QString appName() { return QString::fromLatin1("calculator"); }
00078
00079
00080 public slots:
00081 void command_buttons(int);
00082 void enterNumber(int i);
00083 void std_buttons(int);
00084 void std_funcs(int);
00085 void do_convert(int);
00086 void function_button(int);
00087
00088 protected:
00089 virtual bool eventFilter( QObject *o, QEvent *e );
00090
00091 private:
00092 void clear();
00093
00094 void reset_conv();
00095
00096 void processStack( int op );
00097
00098 QValueStack<Op> operationStack;
00099 int state;
00100
00101 double acc, num, mem;
00102 int numDecimals;
00103 bool flPoint;
00104 int numOpenBraces;
00105
00106 void execOp( Operation i );
00107 double evalExpr( int op );
00108 QLabel * memMark;
00109 QString fake;
00110
00111
00112 int current_mode, max_mode, conversion_mode_count, last_conversion;
00113
00114
00115 static const int pre_conv_modes_count = 1;
00116 static const int post_conv_modes_count = 0;
00117
00118
00119 static const int func_button_count = 12;
00120
00121 static const int changeable_func_button_count = 10;
00122 QPushButton* func_buttons[func_button_count];
00123
00124 QButtonGroup bgr_function, bgr_digits, bgr_std, bgr_command;
00125 QStringList faces, captions;
00126
00127
00128 double* entry_list;
00129 double* preoffset_list;
00130 double* postoffset_list;
00131
00132 QPixmap xtopowerofy;
00133 QPixmap ythrootofx;
00134 QPixmap oneoverx;
00135
00136 void display_pixmap_faces(void);
00137 };
00138
00139 #endif