1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
|
/*
$Id: kcalc.h 466447 2005-10-02 17:54:10Z zander $
KCalc, a scientific calculator for the X window system using the
TQt widget libraries, available at no cost at http://www.troll.no
Copyright (C) 1996 Bernd Johannes Wuebben
[email protected]
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef TQTCALC_H
#define TQTCALC_H
#include <queue>
using std::queue;
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
#include <tqlistbox.h>
#include <tqclipboard.h>
#include <tqptrlist.h>
#include <tqaccel.h>
#include <tqtabdialog.h>
#include <tqwidget.h>
#include <tqtimer.h>
#include <tqdialog.h>
#include <tqpixmap.h>
#include <tqapplication.h>
#include <tqfont.h>
#include <tqlabel.h>
#include <tqbuttongroup.h>
#include <tqcheckbox.h>
#include <tqframe.h>
#include <tqgroupbox.h>
#include <tqlineedit.h>
#include <tqpushbutton.h>
#include <tqradiobutton.h>
#include <tqtooltip.h>
#include <tqstring.h>
#include <tqrect.h>
#include "dlabel.h"
#include "stats.h"
// IMPORTANT this has to come after ../config.h
#include "kcalctype.h"
#define STACK_SIZE 100
#define TEMP_STACK_SIZE 1000 // the number of numbers kept in the temp stack
// which are accessible with the up and down arrow
// key
#define PRECEDENCE_INCR 20
#define FUNC_NULL 0
#define FUNC_OR 1
#define FUNC_XOR 2
#define FUNC_AND 3
#define FUNC_LSH 4
#define FUNC_RSH 5
#define FUNC_ADD 6
#define FUNC_SUBTRACT 7
#define FUNC_MULTIPLY 8
#define FUNC_DIVIDE 9
#define FUNC_MOD 10
#define FUNC_POWER 11
#define FUNC_PWR_ROOT 12
#define FUNC_INTDIV 13
#define DEC_SIZE 19
#define BOH_SIZE 16
#define DSP_SIZE 50 //25
#define DEG2RAD(x) (((2L*pi)/360L)*x)
#define GRA2RAD(x) ((pi/200L)*x)
#define RAD2DEG(x) ((360L/(2L*pi))*x)
#define RAD2GRA(x) ((200L/pi)*x)
#define POS_ZERO 1e-19L /* What we consider zero is */
#define NEG_ZERO -1e-19L /* anything between these two */
typedef CALCAMNT (*Arith)(CALCAMNT, CALCAMNT);
typedef CALCAMNT (*Prcnt)(CALCAMNT, CALCAMNT, CALCAMNT);
typedef CALCAMNT (*Trig)(CALCAMNT);
typedef enum _last_input_type {
DIGIT = 1, OPERATION = 2, RECALL = 3, PASTE = 4
} last_input_type;
typedef enum _num_base {
NB_BINARY = 2, NB_OCTAL = 8, NB_DECIMAL = 10, NB_HEX = 16
} num_base;
typedef enum _angle_type {
ANG_DEGREE = 0, ANG_RADIAN = 1, ANG_GRADIENT = 2
} angle_type;
typedef enum _item_type {
ITEM_FUNCTION, ITEM_AMOUNT
} item_type;
typedef struct _func_data {
int item_function;
int item_precedence;
} func_data;
typedef union _item_data { /* The item data */
CALCAMNT item_amount; /* an amount */
func_data item_func_data; /* or a function */
} item_data; /* called item_data */
typedef struct _item_contents { /* The item contents */
item_type s_item_type; /* a type flag */
item_data s_item_data; /* and data */
} item_contents;
typedef struct stack_item *stack_ptr;
typedef struct stack_item {
/* Contents of an item on the input stack */
stack_ptr prior_item; /* Pointer to prior item */
stack_ptr prior_type; /* Pointer to prior type */
item_contents item_value; /* The value of the item */
} stack_item; /* all called stack_item */
CALCAMNT ExecOr(CALCAMNT left_op, CALCAMNT right_op);
CALCAMNT ExecXor(CALCAMNT left_op, CALCAMNT right_op);
CALCAMNT ExecAnd(CALCAMNT left_op, CALCAMNT right_op);
CALCAMNT ExecLsh(CALCAMNT left_op, CALCAMNT right_op);
CALCAMNT ExecRsh(CALCAMNT left_op, CALCAMNT right_op);
CALCAMNT ExecAdd(CALCAMNT left_op, CALCAMNT right_op);
CALCAMNT ExecSubtract(CALCAMNT left_op, CALCAMNT right_op);
CALCAMNT ExecMultiply(CALCAMNT left_op, CALCAMNT right_op);
CALCAMNT ExecDivide(CALCAMNT left_op, CALCAMNT right_op);
CALCAMNT ExecMod(CALCAMNT left_op, CALCAMNT right_op);
CALCAMNT ExecPower(CALCAMNT left_op, CALCAMNT right_op);
CALCAMNT ExecPwrRoot(CALCAMNT left_op, CALCAMNT right_op);
CALCAMNT ExecIntDiv(CALCAMNT left_op, CALCAMNT right_op);
CALCAMNT ExecAddSubP(CALCAMNT left_op, CALCAMNT right_op, CALCAMNT result);
CALCAMNT ExecMultiplyP(CALCAMNT left_op, CALCAMNT right_op, CALCAMNT result);
CALCAMNT ExecDivideP(CALCAMNT left_op, CALCAMNT right_op, CALCAMNT result);
CALCAMNT ExecPowerP(CALCAMNT left_op, CALCAMNT right_op, CALCAMNT result);
CALCAMNT ExecPwrRootP(CALCAMNT left_op, CALCAMNT right_op, CALCAMNT result);
int UpdateStack(int run_precedence);
CALCAMNT ExecFunction(CALCAMNT left_op, int function, CALCAMNT right_op);
int cvb(char *out_str, long amount, int max_out);
void PrintStack(void);
void InitStack(void);
void PushStack(item_contents *add_item);
item_contents *PopStack(void);
item_contents *TopOfStack(void);
item_contents *TopTypeStack(item_type rqstd_type);
#define DISPLAY_AMOUNT display_data.s_item_data.item_amount
typedef struct _DefStruct{
TQColor forecolor;
TQColor backcolor;
int precision;
int fixedprecision;
int style;
bool fixed;
bool beep;
TQFont font;
}DefStruct;
class Calculator;
class TQtCalculator : public TQDialog
{
Q_OBJECT
TQ_OBJECT
public:
TQtCalculator( Calculator* _corba, TQWidget *tqparent=0, const char *name=0 );
~TQtCalculator();
void keyPressEvent( TQKeyEvent *e );
void keyReleaseEvent( TQKeyEvent *e );
void closeEvent( TQCloseEvent *e );
void readSettings();
void writeSettings();
void set_precision();
void set_style();
void set_display_font();
void temp_stack_next();
void temp_stack_prev();
void ComputeMean();
void ComputeSin();
void ComputeStd();
void ComputeCos();
void ComputeMedean();
void ComputeTan();
void ComputeSum();
void ComputeMul();
void ComputeMin();
void ComputeMax();
void setLabel( const char *_text );
void setValue( double _value );
void setData( const TQRect& _range, const char *_sheet );
void useData();
public slots:
void helpclicked();
void set_colors();
void display_selected();
void invertColors();
void selection_timed_out();
void clear_buttons();
void clear_status_label();
void setStatusLabel(const TQString&);
void EnterDigit(int data);
void EnterDecimal();
void EnterStackFunction(int data);
void EnterNegate();
void EnterOpenParen();
void EnterCloseParen();
void EnterRecip();
void EnterInt();
void EnterFactorial();
void EnterSquare();
void EnterNotCmp();
void EnterHyp();
void EnterPercent();
void EnterLogr();
void EnterLogn();
void SetDeg();
void SetGra();
void SetRad();
void SetHex();
void SetOct();
void SetBin();
void SetDec();
void Deg_Selected();
void Rad_Selected();
void Gra_Selected();
void Hex_Selected();
void Dec_Selected();
void Oct_Selected();
void Bin_Selected();
void SetInverse();
void EnterEqual();
void Clear();
void ClearAll();
void RefreshCalculator(void);
void InitializeCalculator(void);
void UpdateDisplay();
void ExecSin();
void ExecCos();
void ExecTan();
void button0();
void button1();
void button2();
void button3();
void button4();
void button5();
void button6();
void button7();
void button8();
void button9();
void buttonA();
void buttonB();
void buttonC();
void buttonD();
void buttonE();
void buttonF();
void base_selected(int number);
void angle_selected(int number);
void Or();
void And();
void Shift();
void Plus();
void Minus();
void Multiply();
void Divide();
void Mod();
void Power();
void EE();
void MR();
void Mplusminus();
void MC();
void exit();
void EEtoggled(bool myboolean);
void pbinvtoggled(bool myboolean);
void pbMRtoggled(bool myboolean);
void pbAtoggled(bool myboolean);
void pbSintoggled(bool myboolean);
void pbplusminustoggled(bool myboolean);
void pbMplusminustoggled(bool myboolean);
void pbBtoggled(bool myboolean);
void pbCostoggled(bool myboolean);
void pbrecitoggled(bool myboolean);
void pbCtoggled(bool myboolean);
void pbTantoggled(bool myboolean);
void pbfactorialtoggled(bool myboolean);
void pbDtoggled(bool myboolean);
void pblogtoggled(bool myboolean);
void pbsquaretoggled(bool myboolean);
void pbEtoggled(bool myboolean);
void pblntoggled(bool myboolean);
void pbpowertoggled(bool myboolean);
void pbFtoggled(bool myboolean);
void pbMCtoggled(bool myboolean);
void pbCleartoggled(bool myboolean);
void pbACtoggled(bool myboolean);
void pb7toggled(bool myboolean);
void pb8toggled(bool myboolean);
void pb9toggled(bool myboolean);
void pbparenopentoggled(bool myboolean);
void pbparenclosetoggled(bool myboolean);
void pbandtoggled(bool myboolean);
void pb4toggled(bool myboolean);
void pb5toggled(bool myboolean);
void pb6toggled(bool myboolean);
void pbXtoggled(bool myboolean);
void pbdivisiontoggled(bool myboolean);
void pbortoggled(bool myboolean);
void pb1toggled(bool myboolean);
void pb2toggled(bool myboolean);
void pb3toggled(bool myboolean);
void pbplustoggled(bool myboolean);
void pbminustoggled(bool myboolean);
void pbshifttoggled(bool myboolean);
void pbperiodtoggled(bool myboolean);
void pb0toggled(bool myboolean);
void pbequaltoggled(bool myboolean);
void pbpercenttoggled(bool myboolean);
void pbnegatetoggled(bool myboolean);
void pbmodtoggled(bool myboolean);
void pbhyptoggled(bool myboolean);
void configclicked();
public:
DefStruct kcalcdefaults;
private:
void updateGeometry();
TQTimer* selection_timer;
TQLabel* statusINVLabel;
TQLabel* statusHYPLabel;
TQLabel* statusERRORLabel;
DLabel* calc_display;
TQRadioButton* anglebutton[3];
TQRadioButton* basebutton[4];
TQPushButton* pbhyp;
TQPushButton* pbEE;
TQPushButton* pbinv;
TQPushButton* pbMR;
TQPushButton* pbA;
TQPushButton* pbSin;
TQPushButton* pbplusminus;
TQPushButton* pbMplusminus;
TQPushButton* pbB;
TQPushButton* pbCos;
TQPushButton* pbreci;
TQPushButton* pbC;
TQPushButton* pbTan;
TQPushButton* pbfactorial;
TQPushButton* pbD;
TQPushButton* pblog;
TQPushButton* pbsquare;
TQPushButton* pbE;
TQPushButton* pbln;
TQPushButton* pbpower;
TQPushButton* pbF;
TQPushButton* pbMC;
TQPushButton* pbClear;
TQPushButton* pbAC;
TQPushButton* pb7;
TQPushButton* pb8;
TQPushButton* pb9;
TQPushButton* pbparenopen;
TQPushButton* pbparenclose;
TQPushButton* pband;
TQPushButton* pb4;
TQPushButton* pb5;
TQPushButton* pb6;
TQPushButton* pbX;
TQPushButton* pbdivision;
TQPushButton* pbor;
TQPushButton* pb1;
TQPushButton* pb2;
TQPushButton* pb3;
TQPushButton* pbplus;
TQPushButton* pbminus;
TQPushButton* pbshift;
TQPushButton* pbperiod;
TQPushButton* pb0;
TQPushButton* pbequal;
TQPushButton* pbpercent;
TQPushButton* pbnegate;
TQPushButton* pbmod;
TQPtrList<TQPushButton> mNumButtonList;
TQPtrList<TQPushButton> mFunctionButtonList;
TQPtrList<TQPushButton> mHexButtonList;
TQPtrList<TQPushButton> mMemButtonList;
TQPtrList<TQPushButton> mOperationButtonList;
bool key_pressed;
KStats stats;
TQListBox *paper;
TQTimer *status_timer;
TQRect sheet_range;
TQString sheet_name;
Calculator* corba;
TQWidget *mSmallPage;
TQWidget *mLargePage;
int mInternalSpacing;
};
#endif //TQTCLAC_H
|