kspread

kcalc.h

00001 /*
00002     $Id: kcalc.h 466447 2005-10-02 17:54:10Z zander $
00003 
00004     KCalc, a scientific calculator for the X window system using the
00005     Qt widget libraries, available at no cost at http://www.troll.no
00006 
00007     Copyright (C) 1996 Bernd Johannes Wuebben
00008                        wuebben@math.cornell.edu
00009 
00010     This program is free software; you can redistribute it and/or modify
00011     it under the terms of the GNU General Public License as published by
00012     the Free Software Foundation; either version 2 of the License, or
00013     (at your option) any later version.
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU General Public License for more details.
00019 
00020     You should have received a copy of the GNU General Public License
00021     along with this program; if not, write to the Free Software
00022     Foundation, Inc., 51 Franklin Street, Fifth Floor,
00023  * Boston, MA 02110-1301, USA.
00024 
00025 */
00026 
00027 #ifndef QTCALC_H
00028 #define QTCALC_H
00029 
00030 #include <queue>
00031 using std::queue;
00032 
00033 #include <unistd.h>
00034 #include <stdlib.h>
00035 #include <ctype.h>
00036 
00037 #include <qlistbox.h>
00038 #include <qclipboard.h>
00039 #include <qptrlist.h>
00040 #include <qaccel.h>
00041 #include <qtabdialog.h>
00042 #include <qwidget.h>
00043 #include <qtimer.h>
00044 #include <qdialog.h>
00045 #include <qpixmap.h>
00046 #include <qapplication.h>
00047 #include <qfont.h>
00048 #include <qlabel.h>
00049 #include <qbuttongroup.h>
00050 #include <qcheckbox.h>
00051 #include <qframe.h>
00052 #include <qgroupbox.h>
00053 #include <qlineedit.h>
00054 #include <qpushbutton.h>
00055 #include <qradiobutton.h>
00056 #include <qtooltip.h>
00057 #include <qstring.h>
00058 #include <qrect.h>
00059 
00060 
00061 #include "dlabel.h"
00062 #include "stats.h"
00063 
00064 // IMPORTANT this has to come after ../config.h
00065 #include "kcalctype.h"
00066 
00067 #define STACK_SIZE  100
00068 #define TEMP_STACK_SIZE 1000 // the number of numbers kept in the temp stack
00069                              // which are accessible with the up and down arrow
00070                              // key
00071 
00072 #define PRECEDENCE_INCR 20
00073 
00074 #define FUNC_NULL   0
00075 #define FUNC_OR     1
00076 #define FUNC_XOR    2
00077 #define FUNC_AND    3
00078 #define FUNC_LSH    4
00079 #define FUNC_RSH    5
00080 #define FUNC_ADD    6
00081 #define FUNC_SUBTRACT   7
00082 #define FUNC_MULTIPLY   8
00083 #define FUNC_DIVIDE 9
00084 #define FUNC_MOD    10
00085 #define FUNC_POWER  11
00086 #define FUNC_PWR_ROOT   12
00087 #define FUNC_INTDIV 13
00088 
00089 #define     DEC_SIZE    19
00090 #define     BOH_SIZE    16
00091 #define     DSP_SIZE    50 //25
00092 
00093 #define     DEG2RAD(x)  (((2L*pi)/360L)*x)
00094 #define     GRA2RAD(x)  ((pi/200L)*x)
00095 #define     RAD2DEG(x)  ((360L/(2L*pi))*x)
00096 #define     RAD2GRA(x)  ((200L/pi)*x)
00097 #define     POS_ZERO     1e-19L  /* What we consider zero is   */
00098 #define     NEG_ZERO    -1e-19L  /* anything between these two */
00099 
00100 
00101 typedef CALCAMNT  (*Arith)(CALCAMNT, CALCAMNT);
00102 typedef CALCAMNT  (*Prcnt)(CALCAMNT, CALCAMNT, CALCAMNT);
00103 typedef CALCAMNT  (*Trig)(CALCAMNT);
00104 
00105 typedef enum _last_input_type {
00106   DIGIT = 1, OPERATION = 2, RECALL = 3, PASTE = 4
00107 } last_input_type;
00108 
00109 typedef enum   _num_base    {
00110     NB_BINARY = 2, NB_OCTAL = 8, NB_DECIMAL = 10, NB_HEX = 16
00111 } num_base;
00112 
00113 typedef enum   _angle_type  {
00114     ANG_DEGREE = 0, ANG_RADIAN = 1, ANG_GRADIENT = 2
00115 } angle_type;
00116 
00117 typedef enum   _item_type   {
00118     ITEM_FUNCTION, ITEM_AMOUNT
00119 } item_type;
00120 
00121 typedef struct   _func_data {
00122     int     item_function;
00123     int     item_precedence;
00124 } func_data;
00125 
00126 typedef union  _item_data   {   /* The item data     */
00127     CALCAMNT    item_amount;    /*  an amount    */
00128     func_data   item_func_data; /*  or a function    */
00129 } item_data;                /* called item_data      */
00130 
00131 typedef struct _item_contents   {   /* The item contents     */
00132     item_type   s_item_type;    /*  a type flag      */
00133     item_data   s_item_data;    /*      and data     */
00134 } item_contents;
00135 
00136 typedef struct stack_item   *stack_ptr;
00137 
00138 typedef struct stack_item {
00139 
00140     /* Contents of an item on the input stack */
00141 
00142     stack_ptr   prior_item;     /* Pointer to prior item */
00143     stack_ptr   prior_type;     /* Pointer to prior type */
00144     item_contents   item_value;     /* The value of the item */
00145 
00146 } stack_item;                   /* all called stack_item */
00147 
00148 
00149 CALCAMNT ExecOr(CALCAMNT left_op, CALCAMNT right_op);
00150 CALCAMNT ExecXor(CALCAMNT left_op, CALCAMNT right_op);
00151 CALCAMNT ExecAnd(CALCAMNT left_op, CALCAMNT right_op);
00152 CALCAMNT ExecLsh(CALCAMNT left_op, CALCAMNT right_op);
00153 CALCAMNT ExecRsh(CALCAMNT left_op, CALCAMNT right_op);
00154 CALCAMNT ExecAdd(CALCAMNT left_op, CALCAMNT right_op);
00155 CALCAMNT ExecSubtract(CALCAMNT left_op, CALCAMNT right_op);
00156 CALCAMNT ExecMultiply(CALCAMNT left_op, CALCAMNT right_op);
00157 CALCAMNT ExecDivide(CALCAMNT left_op, CALCAMNT right_op);
00158 CALCAMNT ExecMod(CALCAMNT left_op, CALCAMNT right_op);
00159 CALCAMNT ExecPower(CALCAMNT left_op, CALCAMNT right_op);
00160 CALCAMNT ExecPwrRoot(CALCAMNT left_op, CALCAMNT right_op);
00161 CALCAMNT ExecIntDiv(CALCAMNT left_op, CALCAMNT right_op);
00162 
00163 CALCAMNT ExecAddSubP(CALCAMNT left_op, CALCAMNT right_op, CALCAMNT result);
00164 CALCAMNT ExecMultiplyP(CALCAMNT left_op, CALCAMNT right_op, CALCAMNT result);
00165 CALCAMNT ExecDivideP(CALCAMNT left_op, CALCAMNT right_op, CALCAMNT result);
00166 CALCAMNT ExecPowerP(CALCAMNT left_op, CALCAMNT right_op, CALCAMNT result);
00167 CALCAMNT ExecPwrRootP(CALCAMNT left_op, CALCAMNT right_op, CALCAMNT result);
00168 
00169 
00170 int         UpdateStack(int run_precedence);
00171 CALCAMNT    ExecFunction(CALCAMNT left_op, int function, CALCAMNT right_op);
00172 int         cvb(char *out_str, long amount, int max_out);
00173 
00174 void        PrintStack(void);
00175 void        InitStack(void);
00176 void        PushStack(item_contents *add_item);
00177 item_contents   *PopStack(void);
00178 item_contents   *TopOfStack(void);
00179 item_contents   *TopTypeStack(item_type rqstd_type);
00180 
00181 
00182 #define     DISPLAY_AMOUNT  display_data.s_item_data.item_amount
00183 
00184 
00185 
00186 typedef struct _DefStruct{
00187   QColor forecolor;
00188   QColor backcolor;
00189   int precision;
00190   int fixedprecision;
00191   int style;
00192   bool fixed;
00193   bool beep;
00194     QFont font;
00195 }DefStruct;
00196 
00197 class Calculator;
00198 
00199 class QtCalculator : public QDialog
00200 {
00201     Q_OBJECT
00202 
00203 public:
00204 
00205     QtCalculator( Calculator* _corba, QWidget *parent=0, const char *name=0 );
00206     ~QtCalculator();
00207 
00208     void keyPressEvent( QKeyEvent *e );
00209     void keyReleaseEvent( QKeyEvent *e );
00210     void closeEvent( QCloseEvent *e );
00211     void readSettings();
00212     void writeSettings();
00213     void set_precision();
00214     void set_style();
00215     void set_display_font();
00216     void temp_stack_next();
00217     void temp_stack_prev();
00218     void ComputeMean();
00219     void ComputeSin();
00220     void ComputeStd();
00221     void ComputeCos();
00222     void ComputeMedean();
00223     void ComputeTan();
00224     void ComputeSum();
00225     void ComputeMul();
00226     void ComputeMin();
00227     void ComputeMax();
00228 
00229     void setLabel( const char *_text );
00230     void setValue( double _value );
00231     void setData( const QRect& _range, const char *_sheet );
00232     void useData();
00233 
00234 public slots:
00235 
00236     void helpclicked();
00237     void set_colors();
00238     void display_selected();
00239     void invertColors();
00240     void selection_timed_out();
00241     void clear_buttons();
00242     void clear_status_label();
00243     void setStatusLabel(const QString&);
00244     void EnterDigit(int data);
00245     void EnterDecimal();
00246     void EnterStackFunction(int data);
00247     void EnterNegate();
00248     void EnterOpenParen();
00249     void EnterCloseParen();
00250     void EnterRecip();
00251     void EnterInt();
00252     void EnterFactorial();
00253     void EnterSquare();
00254     void EnterNotCmp();
00255     void EnterHyp();
00256     void EnterPercent();
00257     void EnterLogr();
00258     void EnterLogn();
00259     void SetDeg();
00260     void SetGra();
00261     void SetRad();
00262     void SetHex();
00263     void SetOct();
00264     void SetBin();
00265     void SetDec();
00266     void Deg_Selected();
00267     void Rad_Selected();
00268     void Gra_Selected();
00269     void Hex_Selected();
00270     void Dec_Selected();
00271     void Oct_Selected();
00272     void Bin_Selected();
00273     void SetInverse();
00274     void EnterEqual();
00275     void Clear();
00276     void ClearAll();
00277     void RefreshCalculator(void);
00278     void InitializeCalculator(void);
00279     void UpdateDisplay();
00280     void ExecSin();
00281     void ExecCos();
00282     void ExecTan();
00283     void button0();
00284     void button1();
00285     void button2();
00286     void button3();
00287     void button4();
00288     void button5();
00289     void button6();
00290     void button7();
00291     void button8();
00292     void button9();
00293     void buttonA();
00294     void buttonB();
00295     void buttonC();
00296     void buttonD();
00297     void buttonE();
00298     void buttonF();
00299     void base_selected(int number);
00300     void angle_selected(int number);
00301     void Or();
00302     void And();
00303     void Shift();
00304     void Plus();
00305     void Minus();
00306     void Multiply();
00307     void Divide();
00308     void Mod();
00309     void Power();
00310     void EE();
00311     void MR();
00312     void Mplusminus();
00313     void MC();
00314     void exit();
00315     void EEtoggled(bool myboolean);
00316     void pbinvtoggled(bool myboolean);
00317     void pbMRtoggled(bool myboolean);
00318     void pbAtoggled(bool myboolean);
00319     void pbSintoggled(bool myboolean);
00320     void pbplusminustoggled(bool myboolean);
00321     void pbMplusminustoggled(bool myboolean);
00322     void pbBtoggled(bool myboolean);
00323     void pbCostoggled(bool myboolean);
00324     void pbrecitoggled(bool myboolean);
00325     void pbCtoggled(bool myboolean);
00326     void pbTantoggled(bool myboolean);
00327     void pbfactorialtoggled(bool myboolean);
00328     void pbDtoggled(bool myboolean);
00329     void pblogtoggled(bool myboolean);
00330     void pbsquaretoggled(bool myboolean);
00331     void pbEtoggled(bool myboolean);
00332     void pblntoggled(bool myboolean);
00333     void pbpowertoggled(bool myboolean);
00334     void pbFtoggled(bool myboolean);
00335     void pbMCtoggled(bool myboolean);
00336     void pbCleartoggled(bool myboolean);
00337     void pbACtoggled(bool myboolean);
00338     void pb7toggled(bool myboolean);
00339     void pb8toggled(bool myboolean);
00340     void pb9toggled(bool myboolean);
00341     void pbparenopentoggled(bool myboolean);
00342     void pbparenclosetoggled(bool myboolean);
00343     void pbandtoggled(bool myboolean);
00344     void pb4toggled(bool myboolean);
00345     void pb5toggled(bool myboolean);
00346     void pb6toggled(bool myboolean);
00347     void pbXtoggled(bool myboolean);
00348     void pbdivisiontoggled(bool myboolean);
00349     void pbortoggled(bool myboolean);
00350     void pb1toggled(bool myboolean);
00351     void pb2toggled(bool myboolean);
00352     void pb3toggled(bool myboolean);
00353     void pbplustoggled(bool myboolean);
00354     void pbminustoggled(bool myboolean);
00355     void pbshifttoggled(bool myboolean);
00356     void pbperiodtoggled(bool myboolean);
00357     void pb0toggled(bool myboolean);
00358     void pbequaltoggled(bool myboolean);
00359     void pbpercenttoggled(bool myboolean);
00360     void pbnegatetoggled(bool myboolean);
00361     void pbmodtoggled(bool myboolean);
00362     void pbhyptoggled(bool myboolean);
00363     void configclicked();
00364 
00365 public:
00366 
00367      DefStruct kcalcdefaults;
00368 
00369 private:
00370     void updateGeometry();
00371 
00372     QTimer* selection_timer;
00373     QLabel* statusINVLabel;
00374     QLabel* statusHYPLabel;
00375     QLabel* statusERRORLabel;
00376     DLabel*     calc_display;
00377     QRadioButton*   anglebutton[3];
00378     QRadioButton*   basebutton[4];
00379     QPushButton*        pbhyp;
00380     QPushButton*    pbEE;
00381     QPushButton*    pbinv;
00382     QPushButton*    pbMR;
00383     QPushButton*    pbA;
00384     QPushButton*    pbSin;
00385     QPushButton*    pbplusminus;
00386     QPushButton*    pbMplusminus;
00387     QPushButton*    pbB;
00388     QPushButton*    pbCos;
00389     QPushButton*    pbreci;
00390     QPushButton*    pbC;
00391     QPushButton*    pbTan;
00392     QPushButton*    pbfactorial;
00393     QPushButton*    pbD;
00394     QPushButton*    pblog;
00395     QPushButton*    pbsquare;
00396     QPushButton*    pbE;
00397     QPushButton*    pbln;
00398     QPushButton*    pbpower;
00399     QPushButton*    pbF;
00400     QPushButton*    pbMC;
00401     QPushButton*    pbClear;
00402     QPushButton*    pbAC;
00403     QPushButton*    pb7;
00404     QPushButton*    pb8;
00405     QPushButton*    pb9;
00406     QPushButton*    pbparenopen;
00407     QPushButton*    pbparenclose;
00408     QPushButton*    pband;
00409     QPushButton*    pb4;
00410     QPushButton*    pb5;
00411     QPushButton*    pb6;
00412     QPushButton*    pbX;
00413     QPushButton*    pbdivision;
00414     QPushButton*    pbor;
00415     QPushButton*    pb1;
00416     QPushButton*    pb2;
00417     QPushButton*    pb3;
00418     QPushButton*    pbplus;
00419     QPushButton*    pbminus;
00420     QPushButton*    pbshift;
00421     QPushButton*    pbperiod;
00422     QPushButton*    pb0;
00423     QPushButton*    pbequal;
00424     QPushButton*    pbpercent;
00425     QPushButton*    pbnegate;
00426     QPushButton*    pbmod;
00427 
00428     QPtrList<QPushButton> mNumButtonList;
00429     QPtrList<QPushButton> mFunctionButtonList;
00430     QPtrList<QPushButton> mHexButtonList;
00431     QPtrList<QPushButton> mMemButtonList;
00432     QPtrList<QPushButton> mOperationButtonList;
00433 
00434     bool        key_pressed;
00435     KStats      stats;
00436     QListBox            *paper;
00437     QTimer      *status_timer;
00438 
00439     QRect               sheet_range;
00440     QString             sheet_name;
00441     Calculator*         corba;
00442     QWidget *mSmallPage;
00443     QWidget *mLargePage;
00444     int             mInternalSpacing;
00445 };
00446 
00447 #endif  //QTCLAC_H
KDE Home | KDE Accessibility Home | Description of Access Keys