summaryrefslogtreecommitdiffstats
path: root/mathemagics/mathemagics.h
blob: 55995a4956171b5a1a45ee87da4d5a5f7772b3c6 (plain)
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
#ifndef MATHEMAGICS_H
#define MATHEMAGICS_H

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <kapp.h>
#include <tqwidget.h>
#include <tqvaluelist.h>
#include <tqptrlist.h>
#include <tdemainwindow.h>
#include <tdeaction.h>
#include <tqmap.h>
#include <tqguardedptr.h>

#include "stacklevel.h"
#include "optiondialog.h"
#include "kparanoidline.h"

class TDEListAction;
class EditAction;
class ComboAction;
class TQComboBox;
class TQCloseEvent;
class TQPushButton;
class TQVBoxLayout;
class TQScrollView;
class TDEToggleAction;
class MathKeypad;

class Mathemagics : public TDEMainWindow
{
	Q_OBJECT

public:
	/** construtor */
	Mathemagics(TQWidget* parent=0, const char *name=0, WFlags f = 0);
	/** destructor */
	~Mathemagics();

	void updateStack();

protected slots:
	void runFormula(const TQString &);
	bool runCommand(const TQString &);
	void openFile(const TQString &filename);
	void saveFile(const TQString &filename);
	void slotOpen();

	void clearHistory();
	void scrollToBottom();

	void keypadClosing();
	void insertChar(const TQString &);

	void configureToolBars();
	void newToolBarConfig();
	void keyBindings();
	void toggleKeypad(bool);

	void slotEnter();
	void slotAdd();
	void slotSubtract();
	void slotMultiply();
	void slotDivide();
	void slotBackspace();
	void slotKeypadBackspace();

	void slotModulo();
	void slotPercent();
	void slotInverse();
	void slotRaiseE();
	void slotSqrt();
	void slotSquared();
	void slotSine();
	void slotCosine();
	void slotTangent();
	void slotEEX();
	void slotRaiseTen();
	void slotLn();
	void slotFactorial();
	void slotPower();
	void slotNegative();
	void slotAnd();
	void slotOr();
	void slotXOr();
	void slotLsh();
	void slotRsh();
	void slotDup2();
	void slotDrop();

	void slotUpdateStackLevel(int);
	void slotRoll(int);
	void slotRestoreStack();
	void slotRevert();

	void slotPushHighlighted(const TQString&);
	
	void slotConfigure();
	void slotConfigureHide();
	void slotConfigureDestroy();
	void slotUpdateConfiguration();

	void slotBaseChanged(int id);
	void slotAngleChanged(int id);

protected:
	void closeEvent(TQCloseEvent *);
	
private:
	TQPtrList<StackLevel> stackLevels;
	void recreateStackLevels();
	TQScrollView *topLevel;
	TQWidget *boxParent;
	TQVBoxLayout *bigBox;
	EditAction* LineEdit;
	ComboAction* HistoryBox;

	TDEListAction *baseGroup;
	TDEListAction *angGroup;
	TDEListAction *formulae;

	MathKeypad *keypad;

	TQValueList<double> *Stack;
	TQValueList<double> *SavedStack;
	TQStringList entryNums;

	bool parseArgs(unsigned int reqArgs = 0, bool autoEnter = 1, bool save = 1);

	double angConv(const double theDouble);
	double angOut(const double theDouble);
	TQString theAngle();

	int testArgs();
	bool getArgs(unsigned int num);
	TQValueList<double> args;

	double format(TQString theString, bool *ok=0);
	TQString format(double theDouble);

	void saveStack();
	void enter();

	int fact(int n);

	//TQStatusBar *statusBar;
	int dispTime;

	void error();
	void changeStatus(TQString text);
	void changeStatusError(TQString text);
	void changeStatus(double * res, char op);
	void changeStatus(double * res, TQString op, bool prepend = 0);

	void level5Return();
	void level4Return();
	void level3Return();
	void level2Return();
	void level1Return();

	void roll(unsigned int index);
	void rolld(unsigned int index);

	ConfigureDialog * optionDialog;

	//constants
	double pi;

	bool noSave;
	bool enterMode;

	// configuration options
	int numStackLevels;
	bool showPeriod;
	bool fixedPrec;
	int histNum;
	bool histDetail;
	int formatPrec;
	bool toSaveStack;
	bool delDrops;
	int base;
	int angle;
	bool beep;

	TDEToggleAction *keypadAct;
	TDEToggleAction *InvButton;
	TDEToggleAction *HypButton;

	// map names to their formulae
	TQMap<TQString, TQString> formulas;
	TQStringList defFormulas;
	// map names to their help
	TQMap<TQString, TQString> help;

	// variables
	TQMap<TQString, double> variables;
	TQStringList defVariables;
};

class EditAction : public TDEAction
{
  Q_OBJECT

public:
    EditAction( const TQString& text, int accel, const TQObject *receiver, const char *member, TQObject* parent, const char* name );
    ~EditAction();

    virtual int plug( TQWidget *w, int index = -1 );
    virtual void unplug( TQWidget *w );
    TQString text() { return m_combo? m_combo->text() : TQString::null; }
	TQGuardedPtr<KParanoidLine> edit();

public slots:
	void clear();
	void append(TQString);
	void insert(TQString);

signals:
    void plugged();

private:
    TQGuardedPtr<KParanoidLine> m_combo;
    const TQObject *m_receiver;
    const char *m_member;
};

class ComboAction : public TDEAction
{
  Q_OBJECT

public:
    ComboAction( const TQString& text, int accel, const TQObject *receiver, const char *member, TQObject* parent, const char* name );
    ~ComboAction();
    virtual int plug( TQWidget *w, int index = -1 );
    virtual void unplug( TQWidget *w );

	TQGuardedPtr<TQComboBox> combo();

signals:
    void plugged();

private:
    TQGuardedPtr<TQComboBox> m_combo;
    const TQObject *m_receiver;
    const char *m_member;
};

#endif