-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
kcalc.h
330 lines (284 loc) · 9.1 KB
/
kcalc.h
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
/*
SPDX-FileCopyrightText: 2001-2013 Evan Teran <evan.teran@gmail.com>
SPDX-FileCopyrightText: 1996-2000 Bernd Johannes Wuebben <wuebben@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
class Constants;
class QButtonGroup;
class QLabel;
class KToggleAction;
class KCalcConstMenu;
class KCalcStatusBar;
/*
* Kcalc consist of a class for the GUI (here), and a few
* implementation classes:
*
* - KNumber: holds a given number, integer or float, it implements
* all operations for a given KNumber (cos, ln, +, & and such).
* - KCalcToken: class to hold "tokens" such as operations (+,-,×,..),
* KNumbers, parentheses or functions (ln, cos, ...) to be processed
* by the engine.
* - KCalcParser: once an input string (such as "5cos(4.6)+1") can be committed
* for calculation, this class converts it to their respective KCalcToken
* objects and puts them into a Queue.
* - CalcEngine: is able to process a given KCalToken Queue to produce a final
* result, based on precedence levels of each operation.
*
* Once the user has finished entering the desired expression to calculate
* (signaling this by clicking "equal"), the string hold by KCalcInputDisplay is
* sent to KCalcParser, the resulting KCalToken Queue is then sent to CalcEngine
* and finally, the result is shown in KCalcDisplay.
*/
#include "kcalc_button.h"
#include "kcalc_const_button.h"
#include "kcalc_core.h"
#include "kcalc_parser.h"
#include "kcalc_token.h"
#include "ui_colors.h"
#include "ui_constants.h"
#include "ui_fonts.h"
#include "ui_general.h"
#include "ui_kcalc.h"
#include <QQueue>
#include <array>
#include <kxmlguiwindow.h>
class General : public QWidget, public Ui::General
{
Q_OBJECT
public:
explicit General(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
}
};
class Fonts : public QWidget, public Ui::Fonts
{
Q_OBJECT
public:
explicit Fonts(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
}
};
class Constants : public QWidget, public Ui::Constants
{
Q_OBJECT
public:
explicit Constants(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
}
};
class Colors : public QWidget, public Ui::Colors
{
Q_OBJECT
public:
explicit Colors(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
}
};
class KCalculator : public KXmlGuiWindow, private Ui::KCalculator
{
Q_OBJECT
public:
explicit KCalculator(QWidget *parent = nullptr);
~KCalculator() override;
Q_SIGNALS:
void switchMode(ButtonModeFlags, bool);
void switchShowAccels(bool);
public:
enum UpdateFlag {
UPDATE_FROM_CORE = 1,
UPDATE_STORE_RESULT = 2,
UPDATE_MATH_ERROR = 4,
UPDATE_SYNTAX_ERROR = 8,
UPDATE_MALFORMED_EXPRESSION = 16,
UPDATE_CLEAR = 32,
};
Q_DECLARE_FLAGS(UpdateFlags, UpdateFlag)
protected:
void resizeEvent(QResizeEvent *event) override;
private:
bool eventFilter(QObject *o, QEvent *e) override;
bool event(QEvent *e) override;
void updateGeometry();
void setupMainActions();
void setupDisplay();
void setupKeys();
void setupNumberKeys();
void setupRightKeypad();
void setupNumericKeypad();
void setupLogicKeys();
void setupScientificKeys();
void setupStatisticKeys();
void setupConstantsKeys();
void setupMiscKeys();
void keyPressEvent(QKeyEvent *e) override;
void keyReleaseEvent(QKeyEvent *e) override;
void setPrecision();
void setAngle();
void setBase();
void setBaseFont(const QFont &font);
const QFont &baseFont() const;
bool isMinimumSize();
void forceResizeEvent();
void setLeftPadLayoutActive(bool active);
void setBitsetLayoutActive(bool active);
void updateDisplay(UpdateFlags flags);
void insertNumericToInputDisplay(KCalcToken::TokenCode token);
void insertFunctionToInputDisplay(KCalcToken::TokenCode token);
void insertToInputDisplay(KCalcToken::TokenCode token);
void insertToInputDisplay(const QString &token);
KCalcStatusBar *statusBar();
// button sets
void showMemButtons(bool toggled);
void showStatButtons(bool toggled);
void showScienceButtons(bool toggled);
void showLogicButtons(bool toggled);
KCalcConstMenu *createConstantsMenu();
protected Q_SLOTS:
void changeButtonNames();
void updateSettings();
void setColors();
void setFonts();
void updateResultDisplay();
void showSettings();
// Mode
void slotSetSimpleMode();
void slotSetScienceMode();
void slotSetStatisticMode();
void slotSetNumeralMode();
void slotHistoryshow(bool toggled);
void slotConstantsShow(bool toggled);
void slotBitsetshow(bool toggled);
void slotAngleSelected(QAbstractButton *button, bool checked);
void slotBaseSelected();
void slotNumberclicked(QAbstractButton *button);
void slotEEclicked();
void slotShifttoggled(bool myboolean);
void slotMemRecallclicked();
void slotMemStoreclicked();
void slotSinclicked();
void slotPlusMinusclicked();
void slotMemPlusMinusclicked();
void slotCosclicked();
void slotReciclicked();
void slotTanclicked();
void slotFactorialclicked();
void slotLogclicked();
void slotSquareclicked();
void slotSqrtclicked();
void slotLnclicked();
void slotPowerclicked();
void slotMemClearclicked();
void slotClearclicked();
void slotAllClearclicked();
void slotParenOpenclicked();
void slotParenCloseclicked();
void slotANDclicked();
void slotMultiplicationclicked();
void slotDivisionclicked();
void slotORclicked();
void slotXORclicked();
void slotPlusclicked();
void slotMinusclicked();
void slotLeftShiftclicked();
void slotRightShiftclicked();
void slotPeriodclicked();
void slotEqualclicked();
void slotPercentclicked();
void slotNegateclicked();
void slotModclicked();
void slotStatNumclicked();
void slotStatMeanclicked();
void slotStatStdDevclicked();
void slotStatMedianclicked();
void slotStatDataInputclicked();
void slotStatClearDataclicked();
void slotHyptoggled(bool flag);
void slotConstclicked(int);
void slotBackspaceclicked();
void slotInputChanged();
void slotClearResult();
void slotConstantToDisplay(const science_constant &const_chosen);
void slotChooseScientificConst0(const science_constant &);
void slotChooseScientificConst1(const science_constant &);
void slotChooseScientificConst2(const science_constant &);
void slotChooseScientificConst3(const science_constant &);
void slotChooseScientificConst4(const science_constant &);
void slotChooseScientificConst5(const science_constant &);
void slotBitsetChanged(quint64);
void slotUpdateBitset(const KNumber &);
void slotBaseModeAmountChanged(const KNumber &number);
void slotClearBaseModeAmount();
void slotPaste();
private:
enum StatusField {
ShiftField = 0,
BaseField,
AngleField,
MemField
};
enum AngleMode {
DegMode = 0,
RadMode,
GradMode
};
enum BaseMode {
BinMode = 2,
OctMode = 8,
DecMode = 10,
HexMode = 16
};
private:
int commit_Input_();
void commit_Result_(bool toHistory = true);
int load_Constants_(const QString &filePath);
bool numeral_system_mode_ = false;
bool shift_mode_ = false;
bool hyp_mode_ = false;
bool update_history_window_ = false;
QQueue<KCalcToken> token_Queue_;
KNumber memory_num_;
int angle_mode_; // angle modes for trigonometric values
int base_mode_;
KCalcParser::ParsingResult m_parsingResult;
bool parsing_failure_;
bool calculation_failure_;
CalcEngine::ResultCode calculation_result_code_;
int input_error_index_;
int calculation_error_token_index_;
void inline handle_Parsing_Error_();
void inline handle_Calculation_Error_();
KCalcConstMenu *constants_menu_ = nullptr;
Constants *constants_ = nullptr; // this is the dialog for configuring const buttons
QButtonGroup *angle_choose_group_ = nullptr;
// num_button_group_: 0-9 = digits, 0xA-0xF = hex-keys
QButtonGroup *num_button_group_ = nullptr;
QList<QAbstractButton *> logic_buttons_;
QList<QAbstractButton *> scientific_buttons_;
QList<QAbstractButton *> stat_buttons_;
QList<QAbstractButton *> const_buttons_;
KToggleAction *action_history_show_ = nullptr;
KToggleAction *action_bitset_show_ = nullptr;
KToggleAction *action_constants_show_ = nullptr;
KToggleAction *action_mode_simple_ = nullptr;
KToggleAction *action_mode_science_ = nullptr;
KToggleAction *action_mode_statistic_ = nullptr;
KToggleAction *action_mode_numeral_ = nullptr;
QList<QAbstractButton *> function_button_list_;
QList<QAbstractButton *> stat_button_list_;
QList<QAbstractButton *> mem_button_list_;
QList<QAbstractButton *> operation_button_list_;
QFont baseFont_;
bool is_still_in_launch_ = true; // necessary for startup at minimum size
CalcEngine core;
KCalcParser parser;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(KCalculator::UpdateFlags)