1 /*
2     SPDX-FileCopyrightText: 2001-2013 Evan Teran <evan.teran@gmail.com>
3     SPDX-FileCopyrightText: 1996-2000 Bernd Johannes Wuebben <wuebben@kde.org>
4 
5     SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #pragma once
9 
10 class Constants;
11 class QButtonGroup;
12 class QLabel;
13 class KToggleAction;
14 class KCalcConstMenu;
15 class KCalcStatusBar;
16 
17 /*
18   Kcalc basically consist of a class for the GUI (here), a class for
19   the display (dlabel.h), and one for the mathematics core
20   (kcalc_core.h).
21 
22   When for example '+' is pressed, one sends the contents of the
23   Display and the '+' to the core via "core.Plus(DISPLAY_AMOUNT)".
24   This only updates the core. To bring the changes to the display,
25   use afterwards "UpdateDisplay(true)".
26 
27   "UpdateDisplay(true)" means that the amount to be displayed should
28   be taken from the core (get the result of some operation that was
29   performed), "UpdateDisplay(false)" has already the information, what
30   to be display (e.g. user is typing in a number).  Note that in the
31   last case the core does not know the number typed in until some
32   operation button is pressed, e.g. "core.Plus(display_number)".
33  */
34 
35 #include "kcalc_button.h"
36 #include "kcalc_const_button.h"
37 #include "kcalc_core.h"
38 
39 #include "ui_colors.h"
40 #include "ui_constants.h"
41 #include "ui_fonts.h"
42 #include "ui_general.h"
43 #include "ui_kcalc.h"
44 
45 #include <array>
46 #include <kxmlguiwindow.h>
47 
48 class General : public QWidget, public Ui::General
49 {
50     Q_OBJECT
51 public:
General(QWidget * parent)52     explicit General(QWidget *parent)
53         : QWidget(parent)
54     {
55         setupUi(this);
56     }
57 };
58 
59 class Fonts : public QWidget, public Ui::Fonts
60 {
61     Q_OBJECT
62 public:
Fonts(QWidget * parent)63     explicit Fonts(QWidget *parent)
64         : QWidget(parent)
65     {
66         setupUi(this);
67     }
68 };
69 
70 class Constants : public QWidget, public Ui::Constants
71 {
72     Q_OBJECT
73 public:
Constants(QWidget * parent)74     explicit Constants(QWidget *parent)
75         : QWidget(parent)
76     {
77         setupUi(this);
78     }
79 };
80 
81 class Colors : public QWidget, public Ui::Colors
82 {
83     Q_OBJECT
84 public:
Colors(QWidget * parent)85     explicit Colors(QWidget *parent)
86         : QWidget(parent)
87     {
88         setupUi(this);
89     }
90 };
91 
92 class KCalculator : public KXmlGuiWindow, private Ui::KCalculator
93 {
94     Q_OBJECT
95 
96 public:
97     explicit KCalculator(QWidget *parent = nullptr);
98     ~KCalculator() override;
99 
100 Q_SIGNALS:
101     void switchMode(ButtonModeFlags, bool);
102     void switchShowAccels(bool);
103 
104 public:
105     enum UpdateFlag { UPDATE_FROM_CORE = 1, UPDATE_STORE_RESULT = 2 };
106 
107     Q_DECLARE_FLAGS(UpdateFlags, UpdateFlag)
108 
109 private:
110     bool eventFilter(QObject *o, QEvent *e) override;
111     bool event(QEvent *e) override;
112     void updateGeometry();
113     void setupMainActions();
114     void setupKeys();
115     void setupNumberKeys();
116     void setupRightKeypad();
117     void setupNumericKeypad();
118     void setupLogicKeys();
119     void setupScientificKeys();
120     void setupStatisticKeys();
121     void setupConstantsKeys();
122     void setupMiscKeys();
123     void keyPressEvent(QKeyEvent *e) override;
124     void keyReleaseEvent(QKeyEvent *e) override;
125     void setPrecision();
126     void setAngle();
127     void setBase();
128 
129     void updateDisplay(UpdateFlags flags);
130     void updateHistoryWithFunction(CalcEngine::Operation);
131     KCalcStatusBar *statusBar();
132 
133     // button sets
134     void showMemButtons(bool toggled);
135     void showStatButtons(bool toggled);
136     void showScienceButtons(bool toggled);
137     void showLogicButtons(bool toggled);
138 
139     KCalcConstMenu *createConstantsMenu();
140 
141 protected Q_SLOTS:
142     void changeButtonNames();
143     void updateSettings();
144     void setColors();
145     void setFonts();
146     void EnterEqual(CalcEngine::Repeat allow_repeat = CalcEngine::REPEAT_ALLOW);
147     void showSettings();
148 
149     // Mode
150     void slotSetSimpleMode();
151     void slotSetScienceMode();
152     void slotSetStatisticMode();
153     void slotSetNumeralMode();
154 
155     void slotHistoryshow(bool toggled);
156     void slotConstantsShow(bool toggled);
157     void slotBitsetshow(bool toggled);
158     void slotAngleSelected(QAbstractButton *button);
159     void slotBaseSelected(QAbstractButton *button);
160     void slotNumberclicked(QAbstractButton *button);
161     void slotEEclicked();
162     void slotShifttoggled(bool myboolean);
163     void slotMemRecallclicked();
164     void slotMemStoreclicked();
165     void slotSinclicked();
166     void slotPlusMinusclicked();
167     void slotMemPlusMinusclicked();
168     void slotCosclicked();
169     void slotReciclicked();
170     void slotTanclicked();
171     void slotFactorialclicked();
172     void slotLogclicked();
173     void slotSquareclicked();
174     void slotCubeclicked();
175     void slotLnclicked();
176     void slotPowerclicked();
177     void slotMemClearclicked();
178     void slotClearclicked();
179     void slotAllClearclicked();
180     void slotParenOpenclicked();
181     void slotParenCloseclicked();
182     void slotANDclicked();
183     void slotMultiplicationclicked();
184     void slotDivisionclicked();
185     void slotORclicked();
186     void slotXORclicked();
187     void slotPlusclicked();
188     void slotMinusclicked();
189     void slotLeftShiftclicked();
190     void slotRightShiftclicked();
191     void slotPeriodclicked();
192     void slotEqualclicked();
193     void slotPercentclicked();
194     void slotNegateclicked();
195     void slotModclicked();
196     void slotStatNumclicked();
197     void slotStatMeanclicked();
198     void slotStatStdDevclicked();
199     void slotStatMedianclicked();
200     void slotStatDataInputclicked();
201     void slotStatClearDataclicked();
202     void slotHyptoggled(bool flag);
203     void slotConstclicked(int);
204     void slotBackspaceclicked();
205 
206     void slotConstantToDisplay(const science_constant &const_chosen);
207     void slotChooseScientificConst0(const science_constant &);
208     void slotChooseScientificConst1(const science_constant &);
209     void slotChooseScientificConst2(const science_constant &);
210     void slotChooseScientificConst3(const science_constant &);
211     void slotChooseScientificConst4(const science_constant &);
212     void slotChooseScientificConst5(const science_constant &);
213 
214     void slotBitsetChanged(quint64);
215     void slotUpdateBitset(const KNumber &);
216 
217     void slotBaseModeAmountChanged(const KNumber &number);
218 
219     void slotPaste();
220 
221 private:
222     enum StatusField { ShiftField = 0, BaseField, AngleField, MemField };
223 
224     enum AngleMode { DegMode = 0, RadMode, GradMode };
225 
226     enum BaseMode { BinMode = 2, OctMode = 8, DecMode = 10, HexMode = 16 };
227 
228 private:
229     bool shift_mode_ = false;
230     bool hyp_mode_ = false;
231     bool update_history_window_ = false;
232     KNumber memory_num_;
233 
234     int angle_mode_; // angle modes for trigonometric values
235 
236     KCalcConstMenu *constants_menu_ = nullptr;
237 
238     Constants *constants_ = nullptr; // this is the dialog for configuring const buttons
239 
240     QButtonGroup *angle_choose_group_ = nullptr;
241     QButtonGroup *base_choose_group_ = nullptr;
242     // num_button_group_: 0-9 = digits, 0xA-0xF = hex-keys
243     QButtonGroup *num_button_group_ = nullptr;
244 
245     QList<QAbstractButton *> logic_buttons_;
246     QList<QAbstractButton *> scientific_buttons_;
247     QList<QAbstractButton *> stat_buttons_;
248     QList<QAbstractButton *> const_buttons_;
249 
250     std::array<QLabel *, 4> base_conversion_labels_;
251 
252     KToggleAction *action_history_show_ = nullptr;
253     KToggleAction *action_bitset_show_ = nullptr;
254     KToggleAction *action_constants_show_ = nullptr;
255 
256     KToggleAction *action_mode_simple_ = nullptr;
257     KToggleAction *action_mode_science_ = nullptr;
258     KToggleAction *action_mode_statistic_ = nullptr;
259     KToggleAction *action_mode_numeral_ = nullptr;
260 
261     QList<QAbstractButton *> function_button_list_;
262     QList<QAbstractButton *> stat_button_list_;
263     QList<QAbstractButton *> mem_button_list_;
264     QList<QAbstractButton *> operation_button_list_;
265 
266     CalcEngine core;
267 };
268 
269 Q_DECLARE_OPERATORS_FOR_FLAGS(KCalculator::UpdateFlags)
270 
271