Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

calculatorimpl.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
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 // mode x functions
00031 enum Operation {
00032      oNop,
00033      oOpenBrace,
00034      oCloseBrace,
00035      oSum,
00036      oPoint,
00037      oAdd,
00038      oSub,
00039      oDiv,
00040      oMult,
00041 
00042 // mode 0 functions
00043      oSin,
00044      oCos,
00045      oTan,
00046      oDivX,
00047      oPercent,
00048      oXsquared,
00049      oRoot,
00050      oLog,
00051      oLn,
00052      oChSign
00053 };
00054 
00055 // states
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     // useful values for conversion stuff
00112     int current_mode, max_mode, conversion_mode_count, last_conversion;
00113 
00114     // make adding new modes easier for ourselves
00115     static const int pre_conv_modes_count = 1;
00116     static const int post_conv_modes_count = 0;
00117 
00118     // an array of pointers to the func buttons
00119     static const int func_button_count = 12;
00120         // this is an abomination
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     // an array of doubles holding the conversion ratios
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

Generated on Sat Nov 5 16:18:01 2005 for OPIE by  doxygen 1.4.2