kspread Library API Documentation

kcalc.h

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